BookSchedulingServer.php 7.2 KB

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