model = new \app\api\model\taxi\User(); } /** * @desc desc * @return \think\response\Json * @throws \Lettered\Support\Exceptions\FailedException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/14 0014 */ public function save() { $params = input(); $validate = validate('\app\api\validate\taxi\User'); if (!$validate->scene('save')->check($params)) { return $this->ApiJson(-1, $validate->getError()); } $user = $this->auth->user(); $row = $this->model->field('id') ->where('user_id', $user['id']) ->find(); if ($row) { return $this->ApiJson(-1, '您已申请'); } $result = false; $this->model->startTrans(); try { $params['user_id'] = $user['id']; $result = $this->model::create($params, true); $this->model->commit(); } catch(Exception $e) { $this->model->rollback(); p($e->getTraceAsString(), 1); return $this->ApiJson(-1, $e->getMessage()); } if ($result) { return $this->ApiJson(0, '成功', $result); } return $this->ApiJson(-1, '失败'); } /** * @desc desc * @return \think\response\Json * @throws \Lettered\Support\Exceptions\FailedException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException * @author weichuanbao<654745815@qq.com> * @date 2021/12/7 0007 */ 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('driver_cost', 'driver'); return $this->ApiJson(0, '成功', $row); } return $this->ApiJson(-1, '失败'); } /** * @desc desc * @return \think\response\Json * @throws \think\exception\PDOException * @author weichuanbao<654745815@qq.com> * @date 2021/12/14 0014 */ public function placeOrder() { $user = $this->auth->user(); $UserPaymentOrder = new UserPaymentOrder(); $row = $UserPaymentOrder->where('user_id', $user['id']) ->where('type', 10) ->find(); if ($row && $row['status'] == 2) { return $this->ApiJson(-1,'已支付费用'); } $result = false; $this->model->startTrans(); try { if (!$row) { // 下订单 $row = $UserPaymentOrder::create([ 'user_id' => $this->auth->user()['id'], 'order_no' => get_order_no(), 'price' => sys_config('driver_cost', 'driver'), ],true); } // 创建对应支付记录 $trade_no = get_order_no(); $result = model('common/OrderPaylog')->storeBy([ 'out_trade_no' => $trade_no, 'total_price' => sys_config('driver_cost', 'driver'), 'order_idx' => $row['id'], 'ascription' => 'motor_driver' // 归属订单 ]); $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,'失败'); } }