model = new \app\admin\model\Trylessonorder; $this->view->assign("orderStatusList", $this->model->getOrderStatusList()); $this->view->assign("payTypeList", $this->model->getPayTypeList()); } /** * 默认生成的控制器所继承的父类中有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(['user','trylesson']) ->where($where) ->where('trylessonorder.order_status','IN',[10,20]) ->order($sort, $order) ->paginate($limit); foreach ($list as $row) { $row->getRelation('user')->visible(['firstname','lastname']); $row->getRelation('trylesson')->visible(['name','name_en']); } $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 用户下单 * * @return string * @throws \think\Exception */ public function add() { if (false === $this->request->isPost()) { $trylesson_id = input('trylesson_id',0); $this->assign('trylesson_id',$trylesson_id); return $this->view->fetch(); } // $trylesson_id = input('post.trylesson_id'); $user_id = input('user_id'); $trylesson_info = Db::name('trylesson')->where('id',$trylesson_id)->find(); $time = time(); //套餐订单 $data = [ 'order_no' => createUniqueNo('T',$user_id), 'user_id' => $user_id, 'trylesson_id' => $trylesson_id, 'lesson_ids' => $trylesson_info['lesson_ids'], 'order_amount' => $trylesson_info['price'], 'order_status' => 10, 'paytime' => $time, 'createtime' => $time, 'updatetime' => $time, 'starttime' => $time, 'endtime' => $time + (30 * 86400), 'remark' => input('remark',''), 'seller' => input('seller',''), 'pay_type' => 2, ]; //入库 Db::startTrans(); $order_id = Db::name('trylesson_order')->insertGetId($data); if(!$order_id){ Db::rollback(); $this->error('下单失败'); } Db::commit(); $this->success('下单成功'); } public function selectpagenew() { $user_id = input('user_id',0); $slot_id = input('slot_id',0); $number = input('number',1,'intval'); //试课只能约一人 if($number != 1){ return json(['list' => [], 'total' => 0]); } $info = Db::name('lesson_slot')->where('id',$slot_id)->find(); //可用试课 $try_map = [ 'o.user_id' =>$user_id, 'o.endtime' => ['gt',time()], 'o.order_status' => 10, ]; $tryorder_list = Db::name('trylesson_order')->alias('o') ->join('trylesson','o.trylesson_id = trylesson.id','LEFT') ->field('o.id,o.starttime,o.endtime,trylesson.name,trylesson.name_en') ->where($try_map) ->where('find_in_set(:lesson_ids,o.lesson_ids)', ['lesson_ids' => $info['lesson_id']]) ->order('o.endtime asc')->select(); if(!empty($tryorder_list)){ foreach($tryorder_list as $key => &$val){ $val['time_text'] = date('M d,Y',$val['starttime']).'-'.date('M d,Y',$val['endtime']); $val['name'] = $val['id'].'['.$val['name'].']--'.$val['time_text']; } } return json(['list' => $tryorder_list, 'total' => 0]); } }