Просмотр исходного кода

Wesmiler 人人车 初始化项目 0816

APPLE 3 лет назад
Родитель
Сommit
c0cd80fec7

+ 3 - 1
application/api/controller/v1/Taxi.php

@@ -175,8 +175,10 @@ class Taxi extends ApiController
             'count'=> isset($datas['count'])? $datas['count'] : 0,
             'mobile'=> isset($datas['mobile'])? $datas['mobile'] : '',
             'depart'=> isset($datas['depart'])? $datas['depart'] : '',
-            'depart_point'=> isset($datas['depart_point'])? $datas['depart_point'] : '',
             'arrive'=> isset($datas['arrive'])? $datas['arrive'] : '',
+            'depart_lat'=> isset($datas['depart_lat'])? $datas['depart_lat'] : 0,
+            'depart_lng'=> isset($datas['depart_lng'])? $datas['depart_lng'] : 0,
+            'lat'=> isset($datas['lat'])? $datas['lat'] : 0,
             'lat'=> isset($datas['lat'])? $datas['lat'] : 0,
             'lng'=> isset($datas['lng'])? $datas['lng'] : 0,
             'km'=> isset($datas['km'])? $datas['km'] : '',

+ 93 - 37
application/api/controller/v1/taxiUser/Order.php

@@ -38,46 +38,46 @@ class Order extends ApiController
         $param = $this->request->param();
         // 数据校验
         $valid = $this->validate($param, [
-            'lng' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
-            'lat' => ['require','regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
+            'lng' => ['require', 'regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
+            'lat' => ['require', 'regex|-?((0|1?[0-7]?[0-9]?)(([.][0-9]{1,4})?)|180(([.][0]{1,4})?))'],
             'page' => 'require',
-        ],[
+        ], [
             'lng.require' => '缺少经度参数',
             'lng.regex' => '经度参数有误',
             'lat.require' => '缺少维度参数',
             'lat.regex' => '维度参数有误'
         ]);
         // 错误
-        if (true !== $valid){
+        if (true !== $valid) {
             return IResponse::failure($valid);
         }
 
-        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
+        $limit = isset($param['pageSize']) ? $param['pageSize'] : 20;
         $taxiUser = $this->auth->guard('taxi_user')->user();
-        if(!$taxiUser){
+        if (!$taxiUser) {
             return IResponse::failure('用户不存在,或已被冻结');
         }
 
-        $categoryIds = Taxi::where(['taxi_user_id'=> $taxiUser['id']])->column('category_id');
+        $categoryIds = Taxi::where(['taxi_user_id' => $taxiUser['id']])->column('category_id');
 
         $categoryIds = array_unique($categoryIds);
 
         // 经纬度升序
         $lists = $this->model
             ->fieldRaw("* , TRUNCATE(( 6371 * acos (  
-                    cos ( radians(".$param['lat'].") )  
+                    cos ( radians(" . $param['lat'] . ") )  
                     * cos( radians( lat ) )  
-                    * cos( radians( lng ) - radians(".$param['lng'].") )  
-                    + sin ( radians(".$param['lat'].") )  
+                    * cos( radians( lng ) - radians(" . $param['lng'] . ") )  
+                    + sin ( radians(" . $param['lat'] . ") )  
                     * sin( radians( lat ) )  
                     )  
                 ), 2) AS distance")
             ->having('distance < 10')
             ->where(['status' => 2])
-            ->where('lat','>',0)
-            ->where('lng','>',0)
-            ->where(function($query) use($categoryIds){
-                if($categoryIds){
+            ->where('lat', '>', 0)
+            ->where('lng', '>', 0)
+            ->where(function ($query) use ($categoryIds) {
+                if ($categoryIds) {
                     $query->whereIn('category_id', $categoryIds);
                 }
             })
@@ -85,7 +85,8 @@ class Order extends ApiController
             ->limit((($param['page'] - 1) * $limit) . "," . $limit)
             ->select();
 
-        return IResponse::success($lists,'获取成功');
+        $count = $lists->count();
+        return IResponse::success(['list' => $lists, 'total' => $count], '获取成功');
     }
 
     /**
@@ -97,21 +98,21 @@ class Order extends ApiController
     {
         // 1. 传入用户位置
         $param = $this->request->param();
-        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
+        $limit = isset($param['pageSize']) ? $param['pageSize'] : 20;
 
         $taxiUser = $this->auth->guard('taxi_user')->user();
-        if(!$taxiUser){
+        if (!$taxiUser) {
             return IResponse::failure('用户不存在,或已被冻结');
         }
 
         // 经纬度升序
-        $lists = $this->model->with(['paylog','user','taxi','taxiUser'])
+        $lists = $this->model->with(['paylog', 'user', 'taxi', 'taxiUser'])
             ->where(['taxi_uid' => $taxiUser['id']])
             ->order(['created_at' => 'desc'])
             ->limit((($param['page'] - 1) * $limit) . "," . $limit)
             ->select();
 
-        return IResponse::success($lists,'获取成功');
+        return IResponse::success($lists, '获取成功');
     }
 
     /**
@@ -122,18 +123,18 @@ class Order extends ApiController
     public function waitOrder()
     {
         $taxiUser = $this->auth->guard('taxi_user')->user();
-        if(!$taxiUser){
+        if (!$taxiUser) {
             return IResponse::failure('用户不存在,或已被冻结');
         }
 
-        $info = model('common/TaxiOrder')->with(['paylog','user','taxi','taxiUser'])
+        $info = model('common/TaxiOrder')->with(['paylog', 'user', 'taxi', 'taxiUser'])
             ->where(['taxi_uid' => $taxiUser['id']])
-            ->whereIn('status',[2,3])
-            ->order('created_at','desc')
+            ->whereIn('status', [2, 3])
+            ->order('created_at', 'desc')
             ->find();
-        if($info){
-            return IResponse::success(!is_null($info)? $info : [],'获取成功');
-        }else{
+        if ($info) {
+            return IResponse::success(!is_null($info) ? $info : [], '获取成功');
+        } else {
             return IResponse::failure('获取失败');
         }
 
@@ -147,20 +148,57 @@ class Order extends ApiController
     public function receive()
     {
         $param = $this->request->param();
-        $id = isset($param['id'])? $param['id'] : 0;
+        $id = isset($param['id']) ? $param['id'] : 0;
         $taxiUser = $this->auth->guard('taxi_user')->user();
-        if(!$taxiUser){
+        if (!$taxiUser) {
             return IResponse::failure('用户不存在,或已被冻结');
         }
 
         $info = model('common/TaxiOrder')
-            ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
-            ->order('created_at','desc')
+            ->where(['id' => $id, 'status' => 2])
+            ->where('deleted_at', '<=', 0)
+            ->order('created_at', 'desc')
             ->find();
-        if(empty($info)){
+        if (empty($info)) {
             return IResponse::failure('订单不存在,或已处理');
         }
 
+        if (empty($info['category_id'])) {
+            return IResponse::failure('车型参数错误或不匹配');
+        }
+
+        $taxi = Taxi::where(['taxi_user_id' => $taxiUser['id'], 'category_id' => $info['category_id']])
+            ->where('status', '>', 0)
+            ->order('status', 'asc')
+            ->order('created_at', 'desc')
+            ->find();
+        if (empty($taxi)) {
+            return IResponse::failure('车型参数错误或您的车型不匹配');
+        }
+
+        if ($taxi['status'] != 1) {
+            return IResponse::failure('您的车辆当前不可再接单,请先完成订单或联系客服');
+        }
+
+        // 写入数据
+        Db::startTrans();
+        $info['status'] = 3;
+        $info['served'] = 1;
+        $info['taxi_id'] = $taxi['id'];
+        $info['taxi_uid'] = $taxiUser['id'];
+        $info['settle_price'] = $info['price'];
+        if (!$info->save()) {
+            Db::rollback();
+            return IResponse::failure('接单失败');
+        }
+
+        if (!Taxi::where(['taxi_user_id' => $taxiUser['id'], 'id' => $taxi['id']])->update(['status' => 2])) {
+            Db::rollback();
+            return IResponse::failure('接单失败');
+        }
+
+        Db::commit();
+        return IResponse::success('接单成功,请尽快前往客户所在地接驾');
     }
 
     /**
@@ -171,21 +209,39 @@ class Order extends ApiController
     public function delivered()
     {
         $param = $this->request->param();
-        $id = isset($param['id'])? $param['id'] : 0;
+        $id = isset($param['id']) ? $param['id'] : 0;
         $taxiUser = $this->auth->guard('taxi_user')->user();
-        if(!$taxiUser){
+        if (!$taxiUser) {
             return IResponse::failure('用户不存在,或已被冻结');
         }
 
         $info = model('common/TaxiOrder')
-            ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
-            ->order('created_at','desc')
+            ->where(['taxi_uid' => $taxiUser['id'], 'id' => $id, 'status' => 3])
+            ->order('created_at', 'desc')
             ->find();
-        if(empty($info)){
+        if (empty($info)) {
             return IResponse::failure('订单不存在,或已处理');
         }
+        if ($info['taxi_uid'] <= 0 || $info['taxi_id'] <= 0) {
+            return IResponse::failure('参数错误');
+        }
 
-
+        // 写入数据
+        Db::startTrans();
+        try {
+            $info['status'] = 3;
+            $info['status'] = 3;
+            $ret = model('common/TaxiUsersWithdraw')::create($params, true);
+
+            $Users = new Users();
+            $Users->changePartnership($user['id'], $ret['amount'], '资产提现', 20);
+            Db::commit();
+
+            return IResponse::success('提现申请成功,请等候审核');
+        } catch (Exception $e) {
+            Db::rollback();
+            return IResponse::failure('提现失败,请稍后重试');
+        }
 
     }
 }

+ 2 - 0
route/route.php

@@ -219,6 +219,8 @@ Route::group('api',function (){
                 Route::post('/myOrder','api/:ver.taxiUser.Order/myOrder');
                 // 等待服务订单
                 Route::post('/waitOrder','api/:ver.taxiUser.Order/waitOrder');
+                // 接单
+                Route::post('/receive','api/:ver.taxiUser.Order/receive');
                 // 确认订单
                 Route::post('/delivered','api/:ver.taxiUser.Order/delivered');