123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- use app\common\library\Email;
- class Lessonslot extends Backend
- {
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Lessonslot;
- $this->view->assign("statusList", $this->model->getStatusList());
- $this->view->assign("noticeStatusList", $this->model->getNoticeStatusList());
- }
-
-
- public function index()
- {
-
- $this->relationSearch = true;
-
- $this->request->filter(['strip_tags', 'trim']);
- if ($this->request->isAjax()) {
-
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['coach','lesson'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
-
- $row->getRelation('coach')->visible(['nickname']);
- $row->getRelation('lesson')->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
- ];
- $rs1 = Db::name('lesson_slot')->where('id',$id)->where('status',0)->update($update);
- if($rs1 === false){
- Db::rollback();
- $this->error('取消失败,请刷新重试');
- }
-
- $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' => $package_order['remain'] + $lesson_order['usernumber'],
- '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('取消失败');
- }
- }
-
-
- $update = [
- 'order_status' => 30,
- 'cancel_time' => $cancel_time,
- 'cancel_reason' => $cancel_reason,
- ];
- if($lesson_order['paytype'] == 1){
- $update['order_status'] = 40;
- }
- $rs = Db::name('lesson_order')->where('id',$lesson_order['id'])->update($update);
- if($rs === false){
- Db::rollback();
- $this->error('取消失败');
- }
-
- $user_info = Db::name('user')->where('id',$lesson_order['user_id'])->find();
- if($user_info['notice_email'] == 1 && !empty($user_info['email'])){
- $obj = new Email();
- $result = $obj
- ->to($user_info['email'])
- ->subject('Elin Dance Studio 订单取消!')
- ->message('Hi,'.$user_info['firstname']. ' ' .$user_info['lastname'].',您预约的'.date('Y-m-d H:i',$info['starttime']).'的课程已被取消,原因:'.$cancel_reason.'!')
- ->send();
- }
- }
- }
- Db::commit();
- $this->success('取消完成');
- }
- $this->view->assign('row',$info);
- return $this->view->fetch();
- }
- }
|