123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace app\admin\controller;
- use app\common\controller\Backend;
- use think\Db;
- use Exception;
- use think\exception\DbException;
- use think\exception\PDOException;
- use think\exception\ValidateException;
- class Trylessonorder extends Backend
- {
-
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\Trylessonorder;
- $this->view->assign("orderStatusList", $this->model->getOrderStatusList());
- $this->view->assign("payTypeList", $this->model->getPayTypeList());
- }
-
-
- 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(['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();
- }
-
- 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('下单成功');
- }
- }
|