trainlogic.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-10-29 16:16:29
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-24 15:11:29
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\trainmodel;
  10. use app\index\model\trainsignusermodel;
  11. class trainlogic
  12. {
  13. /**
  14. * 新增培训
  15. * 20211224
  16. * wj
  17. */
  18. public function newinfo($info)
  19. {
  20. $fillField = ['name', 'maxpersion'];
  21. foreach ($fillField as $key => $value) {
  22. if (!isset($info[$value]) || empty($info[$value])) {
  23. return backarr(0, "请求失败");
  24. }
  25. }
  26. $m_t = new trainmodel();
  27. if (!isset($info['createtime']) || empty($info['createtime'])) {
  28. $info['createtime'] = date('Y-m-d H:i:s', time());
  29. }
  30. $id = $m_t->insertData($info);
  31. if (!$id) {
  32. return backarr(0, "操作失败");
  33. }
  34. return backarr(1, "操作成功", ['id' => $id]);
  35. }
  36. /**
  37. * 改详细信息
  38. * 20211224
  39. * wj
  40. */
  41. public function updateinfo($arr)
  42. {
  43. if (!isset($arr['id']) || empty($arr['id'])) {
  44. return backarr(0, "请求失败");
  45. }
  46. $m_t = new trainmodel();
  47. $id = $arr['id'];
  48. $where = ['id' => $id];
  49. $tinfo = $m_t->getInfo($where);
  50. if (empty($tinfo)) {
  51. return backarr(0, "无数据");
  52. }
  53. $updateField = ['name', 'disstr', 'starttime', 'endtime', 'maxpersion'];
  54. $updateData = [];
  55. foreach ($updateField as $key => $value) {
  56. if (isset($arr[$value]) && !empty($arr[$value]) && $tinfo[$value] != $arr[$value]) {
  57. $updateData[$value] = $arr[$value];
  58. }
  59. }
  60. if (isset($updateField['starttime']) && isset($updateField['endtime'])) {
  61. if (strtotime($updateField['starttime']) > strtotime($updateField['endtime'])) {
  62. return backarr(0, "时间段错误");
  63. }
  64. }
  65. if (empty($updateData)) {
  66. return backarr(0, "无修改数据");
  67. }
  68. $row = $m_t->updateinfo($where, $updateData);
  69. if (!$row) {
  70. return backarr(0, "操作失败");
  71. }
  72. return backarr(1, "操作成功", ['id' => $id]);
  73. }
  74. /**
  75. * 获取信息根据id
  76. * 20211224
  77. * wj
  78. */
  79. public function getinfobyid($arr)
  80. {
  81. if (!isset($arr['id']) || empty($arr['id'])) {
  82. return backarr(0, "请求失败");
  83. }
  84. $id = $arr['id'];
  85. $m_t = new trainmodel();
  86. $where = ['id' => $id];
  87. $cinfo = $m_t->getInfo($where);
  88. if (empty($cinfo)) {
  89. return backarr(0, "无数据");
  90. }
  91. return backarr(1, "操作成功", $cinfo);
  92. }
  93. /**
  94. * 修改isactive根据id
  95. * 20211224
  96. * wj
  97. */
  98. public function updateisactivebyid($arr)
  99. {
  100. if (!isset($arr['id']) || empty($arr['id']) || !isset($arr['isactive']) || !in_array($arr['isactive'], [0, 1])) {
  101. return backarr(0, "请求失败");
  102. }
  103. $id = $arr['id'];
  104. $isactive = $arr['isactive'];
  105. $m_t = new trainmodel();
  106. $where = ['id' => $id];
  107. $cinfo = $m_t->getInfo($where);
  108. if (empty($cinfo)) {
  109. return backarr(0, "无数据");
  110. }
  111. $updateData = [];
  112. if ($isactive != $cinfo['isactive']) {
  113. $updateData['isactive'] = $isactive;
  114. }
  115. if (empty($updateData)) {
  116. return backarr(0, "无修改数据", ['id' => $id]);
  117. }
  118. $row = $m_t->updateinfo($where, $updateData);
  119. if (!$row) {
  120. return backarr(0, "操作失败");
  121. }
  122. return backarr(1, "操作成功", ['id' => $id, 'isactive' => $isactive]);
  123. }
  124. /***
  125. * 获取列表 按时间倒序
  126. * 20211224
  127. * wj
  128. */
  129. public function getlistbywhere($arr)
  130. {
  131. $m_t = new trainmodel();
  132. $where = [];
  133. if (isset($arr['name']) && !empty($arr['name'])) {
  134. $where['name'] = ['like', '%' . $arr['name'] . '%'];
  135. }
  136. if (isset($arr['isactive']) && is_numeric($arr['isactive']) && in_array($arr['isactive'], [0, 1])) {
  137. $where['isactive'] = $arr['isactive'];
  138. }
  139. if (isset($arr['worktype']) && !empty($arr['worktype'])) {
  140. $where['worktype'] = ['like', '%' . $arr['worktype'] . '%'];
  141. }
  142. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  143. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  144. $count = $m_t->getList($where, 'count');
  145. if ($count <= 0) {
  146. return backarr(0, "无数据");
  147. }
  148. $list = $m_t->getList($where, '*', $page, $size);
  149. if (isset($arr['userid']) && !empty($arr['userid'])) {
  150. $userid = $arr['userid'];
  151. $m_tu = new trainsignusermodel();
  152. foreach ($list as $key => $value) {
  153. $list[$key]['userid'] = $userid;
  154. $where = ['tid' => $value['id'], 'userid' => $userid, 'status' => 1];
  155. $tuinfo = $m_tu->getInfo($where);
  156. if (empty($tuinfo)) {
  157. $list[$key]['status'] = 0;
  158. } else {
  159. $list[$key]['status'] = 1;
  160. }
  161. }
  162. }
  163. return backarr(1, "查询成功", $list);
  164. }
  165. }