model = new \app\admin\model\Lessonslot; $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("noticeStatusList", $this->model->getNoticeStatusList()); $this->view->assign("isShowList", $this->model->getIsShowList()); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //当前是否为关联查询 $this->relationSearch = true; //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model ->with(['coach','lesson','danceroom']) ->where($where) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->getRelation('coach')->visible(['nickname']); $row->getRelation('lesson')->visible(['name','name_en']); $row->getRelation('danceroom')->visible(['name','name_en']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 取消 */ public function cancel(){ $id = input('id'); $info = Db::name('lesson_slot')->where('id',$id)->where('status',0)->find(); if(!$info){ $this->error('请刷新重试'); } if($this->request->isPost()){ $remark = input('remark',''); $cancel_reason = input('cancel_reason',''); $cancel_time = strtotime(input('cancel_time','')); Db::startTrans(); $update = [ 'status' => 30, 'remark' => $remark, 'cancel_reason' => $cancel_reason, 'cancel_time' => $cancel_time, 'bookednum' => 0, ]; $rs1 = Db::name('lesson_slot')->where('id',$id)->where('status',0)->update($update); if($rs1 === false){ Db::rollback(); $this->error('取消失败,请刷新重试'); } $lesson_info = Db::name('lesson')->where('id',$info['lesson_id'])->find(); //找到所有的已报名订单 $lesson_order_list = Db::name('lesson_order')->where('slot_id',$id)->where('order_status',10)->lock(true)->select(); if(!empty($lesson_order_list)){ foreach($lesson_order_list as $lesson_order){ //套餐给加回去 if($lesson_order['paytype'] == 1){ $package_order = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->lock(true)->find(); $update = [ 'remain' => bcadd($package_order['remain'],$lesson_order['usernumber_hours'],1), 'updatetime' => time(), ]; $rs_remain = Db::name('package_order')->where('id',$lesson_order['package_order_id'])->update($update); if($rs_remain === false){ Db::rollback(); $this->error('取消失败'); } } //试课给改回去 if($lesson_order['paytype'] == 4){ $update = [ 'order_status' => 10, 'updatetime' => time(), 'lesson_order_id' => 0, ]; $rs_remain = Db::name('trylesson_order')->where('id',$lesson_order['trylesson_order_id'])->update($update); if($rs_remain === false){ Db::rollback(); $this->error('取消失败'); } } //现金支付不给退,线下处理 //取消预约单 $update = [ 'order_status' => 30, 'cancel_time' => $cancel_time, 'cancel_reason' => $cancel_reason, ]; if($lesson_order['paytype'] == 1 || $lesson_order['paytype'] == 4){ $update['order_status'] = 40; } $rs = Db::name('lesson_order')->where('id',$lesson_order['id'])->update($update); if($rs === false){ Db::rollback(); $this->error('取消失败'); } } } Db::commit(); $this->success('取消完成'); } $this->view->assign('row',$info); return $this->view->fetch(); } /** * 复制本周的课程表 */ public function copyweek(){ exit; $starttime = strtotime('this week Monday'); // 获取本周一的时间戳 $endtime = $starttime + 86400*7; $list = Db::name('lesson_slot')->where('is_show',1)->where('starttime','BETWEEN',[$starttime,$endtime])->order('starttime asc')->select(); if(empty($list)){ $this->error('本周还没有课程表'); } foreach($list as $key => &$val){ unset($val['id']); $val['starttime'] = $val['starttime'] + 86400*7; $val['endtime'] = $val['endtime'] + 86400*7; $val['status'] = 0; $val['notice_status'] = 0; $val['finishtime'] = 0; $val['cancel_reason'] = ''; $val['cancel_time'] = 0; } Db::name('lesson_slot')->insertAll($list); $this->success('已复制到下周'); } /** * 查看 */ public function vue_index() { $where = []; $coach_id = input('coach_id',''); $lesson_id = input('lesson_id',''); $danceroom_id = input('danceroom_id',0); $bookstatus = input('bookstatus',0); $starttime = input('starttime',0);//默认看今天 $endtime = input('endtime',0); if(empty($starttime) || empty($endtime)){ $starttime = strtotime(date('Y-m-d')); $endtime = $starttime + 86399; } if(!empty($coach_id)){ $where['coach_ids'] = ['IN',$coach_id]; } if(!empty($lesson_id)){ $where['lesson_id'] = ['IN',$lesson_id]; } if(!empty($danceroom_id)){ $where['danceroom_id'] = $danceroom_id; } $where['starttime'] = ['BETWEEN',[$starttime,$endtime]]; $wherenew = ''; if(!empty($bookstatus)){ if($bookstatus == 1){ $wherenew = 'bookednum = 0'; } if($bookstatus == 2){ $wherenew = 'bookednum != 0 and bookednum < num_max'; } if($bookstatus == 3){ $wherenew = 'bookednum = num_max'; } } $field = [ 'slot.id','slot.starttime','slot.endtime','slot.num_max','slot.bookednum','coach_ids', 'coach.nickname as Staff','coach.bgcolor', 'lesson.name_en as title', 'danceroom.name_en as Location', ]; $list = Db::name('lesson_slot')->alias('slot') ->join('coach','slot.coach_ids = coach.id','LEFT') ->join('lesson','slot.lesson_id = lesson.id','LEFT') ->join('danceroom','slot.danceroom_id = danceroom.id','LEFT') ->field($field) ->where($where) ->where($wherenew) ->order('id desc') ->select(); if(!empty($list)){ foreach($list as $key => $val){ $val['resourceId'] = $val['coach_ids']; $val['start'] = date('Y-m-d H:i',$val['starttime']); $val['end'] = date('Y-m-d H:i',$val['endtime']); //无人约 $val['backgroundColor'] = '#ffffff'; $val['borderColor'] = $val['bgcolor']; $val['textColor'] = '#333333'; //有人约 if($val['bookednum'] > 0){ $val['backgroundColor'] = $val['bgcolor']; $val['borderColor'] = $val['bgcolor']; $val['textColor'] = '#ffffff'; } //详情 $val['extendedProps'] = [ 'Session' => $val['title'], 'time' => date('D, M d Y, H:i',$val['starttime']).' - '.date('H:i',$val['endtime']), 'Staff' => $val['Staff'], 'Location' => $val['Location'], 'Participar' => $val['bookednum'].'/'.$val['num_max'].' participants', 'id' => $val['id'], ]; $list[$key] = $val; } } $this->result($list,1,'success','json'); } //教练表头 public function vue_staff() { $coach_id = input('coach_id',''); //教练列表 $coach_map = []; if(!empty($coach_id)){ $coach_map['coach_ids'] = ['IN',$coach_id]; } $coach_list = Db::name('coach')->where($coach_map)->order('id desc')->select(); $result = []; if(!empty($coach_list)){ foreach($coach_list as $ckey => $cval){ $result[] = [ 'id' => $cval['id'], 'title' => $cval['nickname'], 'extendedProps' => [ 'name' => $cval['nickname'], 'avatar' => localpath_to_netpath($cval['avatar']), ], ]; } } $this->result($result,1,'success','json'); } //课程新增 public function slot_add(){ $field = ['starttime','hours','num_min','num_max','waitnum_max','coach_ids','lesson_id','danceroom_id','address','remark','is_show']; $require = ['starttime','hours','num_min','num_max','waitnum_max','coach_ids','lesson_id','danceroom_id','is_show']; $data = request_post_hub($field,$require); $data['endtime'] = $data['starttime'] + ($data['hours'] * 3600); $id = Db::name('lesson_slot')->insertGetId($data); $this->result($id,1,'添加完成','json'); } //课程详情 public function slot_info(){ $id = input('id',0); $info = Db::name('lesson_slot')->where('id',$id)->find(); $this->result($info,1,'success','json'); } //课程编辑 public function slot_edit(){ $id = input('id',0); $field = ['starttime','hours','num_min','num_max','waitnum_max','coach_ids','lesson_id','danceroom_id','address','remark','is_show']; $require = ['starttime','hours','num_min','num_max','waitnum_max','coach_ids','lesson_id','danceroom_id','is_show']; $data = request_post_hub($field,$require); $data['endtime'] = $data['starttime'] + ($data['hours'] * 3600); Db::name('lesson_slot')->where('id',$id)->update($data); $this->result('',1,'修改完成','json'); } }