TeacherServer.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeTeacher;
  4. class TeacherServer
  5. {
  6. /**
  7. * Notes:获取教师列表
  8. * @param string $keywords
  9. * @param int $page
  10. * @param int $limit
  11. * @return array
  12. * User: ZQ
  13. * Date: 2022/10/25
  14. */
  15. public static function getTeacherList(int $page, int $limit, string $keywords)
  16. {
  17. [$list, $count] = LifeTeacher::getTeacherList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['teacher_create_time'] = date('Y-m-d H:i:s',$v['teacher_create_time']);
  21. if (!empty($v['teacher_update_time'])){
  22. $list[$k]['teacher_update_time'] = date('Y-m-d H:i:s',$v['teacher_update_time']);
  23. }
  24. }
  25. }
  26. return compact('list', 'page', 'limit', 'count');
  27. }
  28. /**
  29. * Notes:获取所有教师
  30. * @return array
  31. * User: ZQ
  32. * Date: 2022/10/25
  33. */
  34. public static function getTeacherAll()
  35. {
  36. return LifeTeacher::getTeacherAll();
  37. }
  38. /**
  39. * Notes:修改教师
  40. * @param string $teacher_name
  41. * @param int $teacher_id
  42. * @return int
  43. * User: ZQ
  44. * Date: 2022/10/25
  45. */
  46. public static function updateTeacher($teacher_id, $teacher_name, $teacher_img, $teacher_title, $teacher_positional, $admin_id)
  47. {
  48. LifeTeacher::affairBegin();
  49. try {
  50. $where = [];
  51. $where['teacher_id'] = $teacher_id;
  52. $data = [];
  53. $data['teacher_name'] = $teacher_name;
  54. $data['teacher_img'] = $teacher_img;
  55. $data['teacher_title'] = $teacher_title;
  56. $data['teacher_positional'] = $teacher_positional;
  57. $data['teacher_update_time'] = time();
  58. $result = LifeTeacher::where($where)->update($data);
  59. if ($result !== false){
  60. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改教师-编号: ' . $teacher_id;
  61. plog('life-teacher-update', '悦活-教师-修改教师', $msg);
  62. LifeTeacher::affairCommit();
  63. return true;
  64. }
  65. throw new \Exception('操作失败!');
  66. }catch (\Exception $exception){
  67. LifeTeacher::affairRollback();
  68. throw new \Exception($exception->getMessage(), 500);
  69. }
  70. }
  71. /**
  72. * Notes:删除教师
  73. * @param int $teacher_id
  74. * @return int
  75. * User: ZQ
  76. * Date: 2022/10/25
  77. */
  78. public static function delTeacher($teacher_id,$admin_id)
  79. {
  80. LifeTeacher::affairBegin();
  81. try {
  82. $where = [];
  83. $where['teacher_id'] = $teacher_id;
  84. $data['teacher_is_del'] = 1;
  85. $result = LifeTeacher::where($where)->update($data);
  86. if (!empty($result)){
  87. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除教师-编号: ' . $teacher_id;
  88. plog('life-teacher-delete', '悦活-教师-删除教师', $msg);
  89. LifeTeacher::affairCommit();
  90. return true;
  91. }else{
  92. return false;
  93. }
  94. }catch (\Exception $exception){
  95. LifeTeacher::affairRollback();
  96. throw new \Exception($exception->getMessage(), 500);
  97. }
  98. }
  99. /**
  100. * Notes: 添加教师
  101. * @param string $teacher_name
  102. * @param array $teacher_rules
  103. * @return int
  104. * User: ZQ
  105. * Date: 2022/10/25
  106. */
  107. public static function insertTeacher($teacher_name, $teacher_img, $teacher_title, $teacher_positional, $admin_id)
  108. {
  109. LifeTeacher::affairBegin();
  110. try {
  111. $data = [];
  112. $data['teacher_name'] = $teacher_name;
  113. $data['teacher_img'] = $teacher_img;
  114. $data['teacher_title'] = $teacher_title;
  115. $data['teacher_create_time'] = time();
  116. $data['teacher_positional'] = $teacher_positional;
  117. $result = LifeTeacher::insertGetId($data);
  118. if (!empty($result)){
  119. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加教师-编号: ' . $result;
  120. plog('life-teacher-create', '悦活-教师-添加教师', $msg);
  121. LifeTeacher::affairCommit();
  122. return $result;
  123. }
  124. throw new \Exception('操作失败!');
  125. }catch (\Exception $exception){
  126. LifeTeacher::affairRollback();
  127. throw new \Exception($exception->getMessage(), 500);
  128. }
  129. }
  130. /**
  131. * Notes:查询教师
  132. * @param int $teacher_id
  133. * @return int
  134. * User: ZQ
  135. * Date: 2022/10/25
  136. */
  137. public static function teacherInfo($teacher_id)
  138. {
  139. $where = [];
  140. $where['teacher_id'] = $teacher_id;
  141. $result = LifeTeacher::where($where)->first();
  142. if (!empty($result)){
  143. $result['teacher_create_time'] = date('Y-m-d H:i:s',$result['teacher_create_time']);
  144. if (!empty($result['teacher_update_time'])){
  145. $result['teacher_update_time'] = date('Y-m-d H:i:s',$result['teacher_update_time']);
  146. }
  147. }
  148. return $result;
  149. }
  150. /**
  151. * Notes:修改教师状态
  152. * @param string $teacher_name
  153. * @param int $teacher_status
  154. * @return int
  155. * User: ZQ
  156. * Date: 2022/9/15
  157. */
  158. public static function updateStatus($teacher_id, $teacher_status)
  159. {
  160. LifeTeacher::affairBegin();
  161. try {
  162. $where = [];
  163. $where['teacher_id'] = $teacher_id;
  164. $data = [];
  165. $data['teacher_status'] = $teacher_status;
  166. $result = LifeTeacher::where($where)->update($data);
  167. if ($result !== false){
  168. LifeTeacher::affairCommit();
  169. return true;
  170. }
  171. throw new \Exception('操作失败!');
  172. }catch (\Exception $exception){
  173. LifeTeacher::affairRollback();
  174. throw new \Exception($exception->getMessage(), 500);
  175. }
  176. }
  177. }