Lessonslot.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. use app\common\library\Email;
  6. /**
  7. * 每日课时
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Lessonslot extends Backend
  12. {
  13. protected $noNeedLogin = ['vue_index'];
  14. /**
  15. * Lessonslot模型对象
  16. * @var \app\admin\model\Lessonslot
  17. */
  18. protected $model = null;
  19. public function _initialize()
  20. {
  21. parent::_initialize();
  22. $this->model = new \app\admin\model\Lessonslot;
  23. $this->view->assign("statusList", $this->model->getStatusList());
  24. $this->view->assign("noticeStatusList", $this->model->getNoticeStatusList());
  25. $this->view->assign("isShowList", $this->model->getIsShowList());
  26. }
  27. /**
  28. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  29. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  30. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  31. */
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //当前是否为关联查询
  38. $this->relationSearch = true;
  39. //设置过滤方法
  40. $this->request->filter(['strip_tags', 'trim']);
  41. if ($this->request->isAjax()) {
  42. //如果发送的来源是Selectpage,则转发到Selectpage
  43. if ($this->request->request('keyField')) {
  44. return $this->selectpage();
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $list = $this->model
  48. ->with(['coach','lesson','danceroom'])
  49. ->where($where)
  50. ->order($sort, $order)
  51. ->paginate($limit);
  52. foreach ($list as $row) {
  53. $row->getRelation('coach')->visible(['nickname']);
  54. $row->getRelation('lesson')->visible(['name','name_en']);
  55. $row->getRelation('danceroom')->visible(['name','name_en']);
  56. }
  57. $result = array("total" => $list->total(), "rows" => $list->items());
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. /**
  63. * 取消
  64. */
  65. public function cancel(){
  66. $id = input('id');
  67. $info = Db::name('lesson_slot')->where('id',$id)->where('status',0)->find();
  68. if(!$info){
  69. $this->error('请刷新重试');
  70. }
  71. if($this->request->isPost()){
  72. $remark = input('remark','');
  73. $cancel_reason = input('cancel_reason','');
  74. $cancel_time = strtotime(input('cancel_time',''));
  75. Db::startTrans();
  76. $update = [
  77. 'status' => 30,
  78. 'remark' => $remark,
  79. 'cancel_reason' => $cancel_reason,
  80. 'cancel_time' => $cancel_time
  81. ];
  82. $rs1 = Db::name('lesson_slot')->where('id',$id)->where('status',0)->update($update);
  83. if($rs1 === false){
  84. Db::rollback();
  85. $this->error('取消失败,请刷新重试');
  86. }
  87. $lesson_info = Db::name('lesson')->where('id',$info['lesson_id'])->find();
  88. //找到所有的已报名订单
  89. $lesson_order_list = Db::name('lesson_order')->where('slot_id',$id)->where('order_status',10)->lock(true)->select();
  90. if(!empty($lesson_order_list)){
  91. foreach($lesson_order_list as $lesson_order){
  92. //套餐给加回去
  93. if($lesson_order['paytype'] == 1){
  94. $package_order = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->lock(true)->find();
  95. $update = [
  96. 'remain' => bcadd($package_order['remain'],$lesson_order['usernumber_hours'],1),
  97. 'updatetime' => time(),
  98. ];
  99. $rs_remain = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->update($update);
  100. if($rs_remain === false){
  101. Db::rollback();
  102. $this->error('取消失败');
  103. }
  104. }
  105. //试课给改回去
  106. if($lesson_order['paytype'] == 4){
  107. $update = [
  108. 'order_status' => 10,
  109. 'updatetime' => time(),
  110. 'lesson_order_id' => 0,
  111. ];
  112. $rs_remain = Db::name('trylesson_order')->where('id',$lesson_order['trylesson_order_id'])->update($update);
  113. if($rs_remain === false){
  114. Db::rollback();
  115. $this->error('取消失败');
  116. }
  117. }
  118. //现金支付不给退,线下处理
  119. //取消预约单
  120. $update = [
  121. 'order_status' => 30,
  122. 'cancel_time' => $cancel_time,
  123. 'cancel_reason' => $cancel_reason,
  124. ];
  125. if($lesson_order['paytype'] == 1 || $lesson_order['paytype'] == 4){
  126. $update['order_status'] = 40;
  127. }
  128. $rs = Db::name('lesson_order')->where('id',$lesson_order['id'])->update($update);
  129. if($rs === false){
  130. Db::rollback();
  131. $this->error('取消失败');
  132. }
  133. }
  134. }
  135. Db::commit();
  136. $this->success('取消完成');
  137. }
  138. $this->view->assign('row',$info);
  139. return $this->view->fetch();
  140. }
  141. /**
  142. * 复制本周的课程表
  143. */
  144. public function copyweek(){
  145. exit;
  146. $starttime = strtotime('this week Monday'); // 获取本周一的时间戳
  147. $endtime = $starttime + 86400*7;
  148. $list = Db::name('lesson_slot')->where('is_show',1)->where('starttime','BETWEEN',[$starttime,$endtime])->order('starttime asc')->select();
  149. if(empty($list)){
  150. $this->error('本周还没有课程表');
  151. }
  152. foreach($list as $key => &$val){
  153. unset($val['id']);
  154. $val['starttime'] = $val['starttime'] + 86400*7;
  155. $val['endtime'] = $val['endtime'] + 86400*7;
  156. $val['status'] = 0;
  157. $val['notice_status'] = 0;
  158. $val['finishtime'] = 0;
  159. $val['cancel_reason'] = '';
  160. $val['cancel_time'] = 0;
  161. }
  162. Db::name('lesson_slot')->insertAll($list);
  163. $this->success('已复制到下周');
  164. }
  165. /**
  166. * 查看
  167. */
  168. public function vue_index()
  169. {
  170. $where = [];
  171. $coach_id = input('coach_id','');
  172. $lesson_id = input('lesson_id','');
  173. $danceroom_id = input('danceroom_id',0);
  174. $starttime = input('starttime',date('Y-m-d'),'strtotime');//默认看今天
  175. $endtime = input('endtime',date('Y-m-d 23:59:59'),'strtotime');
  176. if(!empty($coach_id)){
  177. $where['coach_id'] = ['IN',$coach_id];
  178. }
  179. if(!empty($lesson_id)){
  180. $where['lesson_id'] = ['IN',$lesson_id];
  181. }
  182. if(!empty($danceroom_id)){
  183. $where['danceroom_id'] = $danceroom_id;
  184. }
  185. $where['starttime'] = ['BETWEEN',[$starttime,$endtime]];
  186. $list = Db::name('lesson_slot')->alias('slot')
  187. ->where($where)
  188. ->order('id desc')
  189. ->select();
  190. return json($list);
  191. }
  192. }