BookServer.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace app\admin\server\life;
  3. use app\admin\model\LifeBook;
  4. class BookServer
  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/14
  14. */
  15. public static function getBookList(int $page, int $limit, string $keywords)
  16. {
  17. [$list, $count] = LifeBook::getBookList($page, $limit, $keywords);
  18. if (!empty($list)){
  19. foreach ($list as $k => $v){
  20. $list[$k]['life_book_create_time'] = date('Y-m-d H:i:s',$v['life_book_create_time']);
  21. if (!empty($v['life_book_update_time'])){
  22. $list[$k]['life_book_update_time'] = date('Y-m-d H:i:s',$v['life_book_update_time']);
  23. }
  24. }
  25. }
  26. return compact('list', 'page', 'limit', 'count');
  27. }
  28. /**
  29. * Notes:修改书院课程
  30. * @param string $life_book_name
  31. * @param int $life_book_id
  32. * @return int
  33. * User: ZQ
  34. * Date: 2022/10/14
  35. */
  36. public static function updateBook($life_book_id, $life_book_name, $life_book_title, $life_book_time, $life_book_category_id, $life_book_teacher_id, $life_book_num, $life_book_status, $lift_book_img, $life_book_type, $life_book_long, $life_book_week, $admin_id)
  37. {
  38. LifeBook::affairBegin();
  39. try {
  40. $where = [];
  41. $where['life_book_id'] = $life_book_id;
  42. $data = [];
  43. $data['life_book_name'] = $life_book_name;
  44. $data['life_book_title'] = $life_book_title;
  45. $data['life_book_time'] = is_array($life_book_time) ? implode('~', $life_book_time) : $life_book_time;
  46. $data['life_book_category_id'] = $life_book_category_id;
  47. $data['life_book_teacher_id'] = $life_book_teacher_id;
  48. $data['life_book_num'] = $life_book_num;
  49. $data['life_book_long'] = $life_book_long;
  50. $data['life_book_type'] = $life_book_type;
  51. $data['life_book_img'] = $lift_book_img;
  52. $data['life_book_status'] = $life_book_status;
  53. $data['life_book_week'] = is_array($life_book_week) ? implode(',', $life_book_week) : $life_book_week;
  54. $data['life_book_update_time'] = time();
  55. $result = LifeBook::where($where)->update($data);
  56. if ($result !== false){
  57. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '修改万悦书院课程-编号: ' . $life_book_id;
  58. plog('life-life_book-update', '悦活-万悦书院-修改书院课程', $msg);
  59. LifeBook::affairCommit();
  60. return true;
  61. }
  62. throw new \Exception('操作失败!');
  63. }catch (\Exception $exception){
  64. LifeBook::affairRollback();
  65. throw new \Exception($exception->getMessage(), 500);
  66. }
  67. }
  68. /**
  69. * Notes:删除书院课程
  70. * @param int $life_book_id
  71. * @return int
  72. * User: ZQ
  73. * Date: 2022/10/14
  74. */
  75. public static function delBook($life_book_id,$admin_id)
  76. {
  77. LifeBook::affairBegin();
  78. try {
  79. $where = [];
  80. $where['life_book_id'] = $life_book_id;
  81. $data['life_book_is_del'] = 1;
  82. $result = LifeBook::where($where)->update($data);
  83. if (!empty($result)){
  84. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除万悦书院课程-编号: ' . $life_book_id;
  85. plog('life-life_book-delete', '悦活-万悦书院-删除书院课程', $msg);
  86. LifeBook::affairCommit();
  87. return true;
  88. }else{
  89. return false;
  90. }
  91. }catch (\Exception $exception){
  92. LifeBook::affairRollback();
  93. throw new \Exception($exception->getMessage(), 500);
  94. }
  95. }
  96. /**
  97. * Notes: 添加书院课程
  98. * @param string $life_book_name
  99. * @param array $life_book_rules
  100. * @return int
  101. * User: ZQ
  102. * Date: 2022/10/14
  103. */
  104. public static function insertBook($life_book_name, $life_book_title, $life_book_time, $life_book_category_id, $life_book_teacher_id, $life_book_num, $life_book_status, $lift_book_img, $life_book_type, $life_book_long, $life_book_week, $admin_id)
  105. {
  106. LifeBook::affairBegin();
  107. try {
  108. $data = [];
  109. $data['life_book_name'] = $life_book_name;
  110. $data['life_book_title'] = $life_book_title;
  111. $data['life_book_time'] = is_array($life_book_time) ? implode('~', $life_book_time) : $life_book_time;
  112. $data['life_book_category_id'] = $life_book_category_id;
  113. $data['life_book_teacher_id'] = $life_book_teacher_id;
  114. $data['life_book_num'] = $life_book_num;
  115. $data['life_book_long'] = $life_book_long;
  116. $data['life_book_type'] = $life_book_type;
  117. $data['life_book_img'] = $lift_book_img;
  118. $data['life_book_week'] = is_array($life_book_week) ? implode(',', $life_book_week) : $life_book_week;
  119. $data['life_book_status'] = $life_book_status;
  120. $data['life_book_create_time'] = time();
  121. $result = LifeBook::insertGetId($data);
  122. if (!empty($result)){
  123. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加万悦书院课程-编号: ' . $result;
  124. plog('life-life_book-create', '悦活-万悦书院-添加书院课程', $msg);
  125. LifeBook::affairCommit();
  126. return $result;
  127. }
  128. throw new \Exception('操作失败!');
  129. }catch (\Exception $exception){
  130. LifeBook::affairRollback();
  131. throw new \Exception($exception->getMessage(), 500);
  132. }
  133. }
  134. /**
  135. * Notes:查询书院课程
  136. * @param int $life_book_id
  137. * @return int
  138. * User: ZQ
  139. * Date: 2022/10/14
  140. */
  141. public static function bookInfo($life_book_id)
  142. {
  143. $where = [];
  144. $where['life_book_id'] = $life_book_id;
  145. $result = LifeBook::where($where)
  146. ->leftJoin('category','category_id','=','life_book.life_book_category_id')
  147. ->leftJoin('teacher','teacher_id','=','life_book.life_book_teacher_id')
  148. ->first(['life_book.*','category.category_name','teacher.teacher_name']);
  149. if (!empty($result)){
  150. $result['life_book_create_time'] = date('Y-m-d H:i:s',$result['life_book_create_time']);
  151. if (!empty($result['life_book_update_time'])){
  152. $result['life_book_update_time'] = date('Y-m-d H:i:s',$result['life_book_update_time']);
  153. }
  154. }
  155. return $result;
  156. }
  157. /**
  158. * Notes:修改书院课程状态
  159. * @param string $life_book_name
  160. * @param int $life_book_status
  161. * @return int
  162. * User: ZQ
  163. * Date: 2022/9/15
  164. */
  165. public static function updateStatus($life_book_id, $life_book_status)
  166. {
  167. LifeBook::affairBegin();
  168. try {
  169. $where = [];
  170. $where['life_book_id'] = $life_book_id;
  171. $data = [];
  172. $data['life_book_status'] = $life_book_status;
  173. $result = LifeBook::where($where)->update($data);
  174. if ($result !== false){
  175. LifeBook::affairCommit();
  176. return true;
  177. }
  178. throw new \Exception('操作失败!');
  179. }catch (\Exception $exception){
  180. LifeBook::affairRollback();
  181. throw new \Exception($exception->getMessage(), 500);
  182. }
  183. }
  184. }