BookCourseServer.php 6.5 KB

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