Lessonslot.php 6.7 KB

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