model = new \app\api\model\user\MotorAgent(); } /** * 显示资源列表 * * @return \think\Response */ public function index() { // } /** * 显示创建资源表单页. * * @return \think\Response */ public function create() { // } /** * 保存新建的资源 * * @param \think\Request $request * @return \think\Response * @throws \Lettered\Support\Exceptions\FailedException * @throws \think\exception\PDOException */ public function save(Request $request) { $params = input(); $validate = validate('\app\api\validate\user\MotorAgent'); if (!$validate->scene('save')->check($params)) { return $this->ApiJson(-1, $validate->getError()); } $params['user_id'] = $this->auth->user()['id']; $params['account'] = $params['mobile']; $result = false; $this->model->startTrans(); try { $result = $this->model::create($params, true); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return $this->ApiJson(0, '成功', $result); } return $this->ApiJson(-1, '失败'); } /** * 显示指定的资源 * * @return \think\Response * @throws \Lettered\Support\Exceptions\FailedException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function read() { $user = $this->auth->user(); $row = $this->model->field('created_at,updated_at', true) ->where('user_id', $user['id']) ->find(); if ($row) { $row->price = sys_config('agent_cost', 'agent'); if ($row['status'] >= 40) { $Seller = new Seller(); $TaxiOrder = new TaxiOrder(); // 商户数量 $row->total_fee = $Seller->where(['area_id' => $row['area_id']])->count(); // 订单数据 // 摩的订单,技能订单,商品订单,配送订单 $taxi_order = $TaxiOrder->whereIn('area_id', $row['area_id'])->whereNotIn('status', [1])->column('price', 'id'); $row->total_order = count($taxi_order); $row->total_store = array_sum($taxi_order); } return $this->ApiJson(0, '成功', $row); } return $this->ApiJson(-1, '失败'); } /** * 显示编辑资源表单页. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update(Request $request, $id) { // } /** * 删除指定资源 * * @param int $id * @return \think\Response */ public function delete($id) { // } public function placeOrder() { $user = $this->auth->user(); $UserPaymentOrder = new UserPaymentOrder(); $row = $UserPaymentOrder->where('user_id', $user['id']) ->where('type', 20) ->find(); if ($row && $row['status'] == 2) { return $this->ApiJson(-1,'已支付费用'); } $result = false; $this->model->startTrans(); try { if (!$row) { // 下订单 $row = $UserPaymentOrder::create([ 'user_id' => $user['id'], 'order_no' => get_order_no(), 'price' => sys_config('agent_cost', 'agent'), 'type' => 20 ],true); } // 创建对应支付记录 $trade_no = get_order_no(); $result = model('common/OrderPaylog')->storeBy([ 'out_trade_no' => $trade_no, 'total_price' => sys_config('agent_cost', 'agent'), 'order_idx' => $row['id'], 'ascription' => 'motor_agent' // 归属订单 ]); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); } if ($result) { return $this->ApiJson(0,'成功', [ 'type' => 'wx', 'success' => "ok!", 'trade_no' => $trade_no ]); } return $this->ApiJson(-1,'失败'); } }