| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace app\api\controller\v1\taxi;
- use app\api\controller\ApiController;
- use app\api\model\taxi\UserPaymentOrder;
- use think\App;
- use app\api\service\JWTAuth as IAuth;
- use think\Exception;
- class User extends ApiController
- {
- protected $model;
- public function __construct(App $app = null, IAuth $auth)
- {
- parent::__construct($app, $auth);
- $this->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, '您已申请');
- }
- if($this->model->where(['mobile'=>$params['mobile']])->find()){
- return $this->ApiJson(-1, '手机号码已存在,请更换或联系客服');
- }
- $result = false;
- $this->model->startTrans();
- try {
- $params['user_id'] = $user['id'];
- if($params['password']){
- $params['password'] = password_hash($params['password'],PASSWORD_DEFAULT);
- }
- $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,'失败');
- }
- }
|