Browse Source

Wesmiler 人人车 初始化项目 0816

APPLE 3 years ago
parent
commit
bca9f24ec1

+ 123 - 5
application/api/controller/v1/taxiUser/Order.php

@@ -5,6 +5,8 @@ namespace app\api\controller\v1\taxiUser;
 
 
 
 
 use app\api\controller\ApiController;
 use app\api\controller\ApiController;
+use app\common\model\Taxi;
+use app\common\model\TaxiServiceCategory;
 use app\common\model\Users;
 use app\common\model\Users;
 use app\http\IResponse;
 use app\http\IResponse;
 use EasyWeChat\Factory;
 use EasyWeChat\Factory;
@@ -25,6 +27,11 @@ class Order extends ApiController
         $this->taxiUserModel = new \app\api\model\taxi\User();
         $this->taxiUserModel = new \app\api\model\taxi\User();
     }
     }
 
 
+    /**
+     * 接单大厅订单列表
+     * @return mixed|\think\response\Json
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
     public function index()
     public function index()
     {
     {
         // 1. 传入用户位置
         // 1. 传入用户位置
@@ -42,12 +49,18 @@ class Order extends ApiController
         ]);
         ]);
         // 错误
         // 错误
         if (true !== $valid){
         if (true !== $valid){
-            return $this->ApiJson(-1,$valid);
+            return IResponse::failure($valid);
         }
         }
 
 
-        $limit = 20;
+        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
         $taxiUser = $this->auth->guard('taxi_user')->user();
         $taxiUser = $this->auth->guard('taxi_user')->user();
-//        $carType =
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        $categoryIds = Taxi::where(['taxi_user_id'=> $taxiUser['id']])->column('category_id');
+
+        $categoryIds = array_unique($categoryIds);
 
 
         // 经纬度升序
         // 经纬度升序
         $lists = $this->model
         $lists = $this->model
@@ -61,11 +74,116 @@ class Order extends ApiController
                 ), 2) AS distance")
                 ), 2) AS distance")
             ->having('distance < 10')
             ->having('distance < 10')
             ->where(['status' => 2])
             ->where(['status' => 2])
-            ->where(['status' => 2])
+            ->where(function($query) use($categoryIds){
+                if($categoryIds){
+                    $query->whereIn('category_id', $categoryIds);
+                }
+            })
             ->order(['distance' => 'ASC'])
             ->order(['distance' => 'ASC'])
             ->limit((($param['page'] - 1) * $limit) . "," . $limit)
             ->limit((($param['page'] - 1) * $limit) . "," . $limit)
             ->select();
             ->select();
 
 
-        return $this->ApiJson(0,'', $lists);
+        return IResponse::success($lists,'获取成功');
+    }
+
+    /**
+     * 我的订单
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function myOrder()
+    {
+        // 1. 传入用户位置
+        $param = $this->request->param();
+        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
+
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        // 经纬度升序
+        $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 mixed|\think\response\Json
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function waitOrder()
+    {
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        $info = model('common/TaxiOrder')->with(['paylog','user','taxi','taxiUser'])
+            ->where(['taxi_uid' => $taxiUser['id']])
+            ->whereIn('status',[2,3])
+            ->order('created_at','desc')
+            ->find();
+        if($info){
+            return IResponse::success(!is_null($info)? $info : [],'获取成功');
+        }else{
+            return IResponse::failure('获取失败');
+        }
+
+    }
+
+    /**
+     * 接单
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function receive()
+    {
+        $param = $this->request->param();
+        $id = isset($param['id'])? $param['id'] : 0;
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        $info = model('common/TaxiOrder')
+            ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
+            ->order('created_at','desc')
+            ->find();
+        if(empty($info)){
+            return IResponse::failure('订单不存在,或已处理');
+        }
+
+    }
+
+    /**
+     * 已送达
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function delivered()
+    {
+        $param = $this->request->param();
+        $id = isset($param['id'])? $param['id'] : 0;
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        $info = model('common/TaxiOrder')
+            ->where(['taxi_uid' => $taxiUser['id'],'id'=> $id, 'status'=>3])
+            ->order('created_at','desc')
+            ->find();
+        if(empty($info)){
+            return IResponse::failure('订单不存在,或已处理');
+        }
+
+
+
     }
     }
 }
 }

+ 56 - 4
application/api/controller/v1/taxiUser/User.php

@@ -5,6 +5,7 @@ namespace app\api\controller\v1\taxiUser;
 
 
 
 
 use app\api\controller\ApiController;
 use app\api\controller\ApiController;
+use app\api\model\taxi\MotorRecord;
 use app\common\model\Users;
 use app\common\model\Users;
 use app\http\IResponse;
 use app\http\IResponse;
 use EasyWeChat\Factory;
 use EasyWeChat\Factory;
@@ -119,7 +120,7 @@ class User extends ApiController
         ]);
         ]);
         // 错误返回
         // 错误返回
         if(true !== $valid){
         if(true !== $valid){
-            return $this->ApiJson(-1, $valid);
+            return IResponse::failure($valid);
         }
         }
         $taxiUser = $this->auth->guard('taxi_user')->user();
         $taxiUser = $this->auth->guard('taxi_user')->user();
         if(!$taxiUser){
         if(!$taxiUser){
@@ -157,7 +158,7 @@ class User extends ApiController
         // 写入数据
         // 写入数据
         Db::startTrans();
         Db::startTrans();
         try {
         try {
-            $params['status'] = 10;
+            $params['status'] = 20;
             $ret = model('common/TaxiUsersWithdraw')::create($params,true);
             $ret = model('common/TaxiUsersWithdraw')::create($params,true);
 
 
             $Users = new Users();
             $Users = new Users();
@@ -173,6 +174,57 @@ class User extends ApiController
     }
     }
 
 
     /**
     /**
+     * 提现记录
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function withdrawLog()
+    {
+        // 1. 传入用户位置
+        $param = $this->request->param();
+        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
+
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        // 经纬度升序
+        $lists = model('common/TaxiUsersWithdraw')
+            ->where(['taxi_uid' => $taxiUser['id']])
+            ->order(['created_at' => 'desc'])
+            ->limit((($param['page'] - 1) * $limit) . "," . $limit)
+            ->select();
+
+        return IResponse::success($lists,'获取成功');
+    }
+
+    /**
+     * 提现记录
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function accountLog()
+    {
+        // 1. 传入用户位置
+        $param = $this->request->param();
+        $limit = isset($param['pageSize'])? $param['pageSize'] : 20;
+
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        // 经纬度升序
+        $lists = MotorRecord::where(['user_id' => $taxiUser['user_id']])
+            ->order(['created_at' => 'desc'])
+            ->limit((($param['page'] - 1) * $limit) . "," . $limit)
+            ->select();
+
+        return IResponse::success($lists,'获取成功');
+    }
+
+    /**
      * 文件上传
      * 文件上传
      * @return \think\response\Json
      * @return \think\response\Json
      */
      */
@@ -187,14 +239,14 @@ class User extends ApiController
         ]);
         ]);
         // 错误返回
         // 错误返回
         if(true !== $valid){
         if(true !== $valid){
-            return $this->ApiJson(-1, $valid);
+            return IResponse::failure($valid);
         };
         };
 
 
         // 上传
         // 上传
         $upload = new Upload(config('upload.'));
         $upload = new Upload(config('upload.'));
         $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
         $ret = $upload->setPath( '/' . $params['action'])->upload($this->request->file('file'));
 
 
-        return $this->ApiJson(0,'', ['path'=> $ret,'url'=>get_annex_url($ret)]);
+        return IResponse::success(['path'=> $ret,'url'=>get_annex_url($ret)],'上传成功');
     }
     }
 
 
 }
 }

+ 9 - 0
application/api/model/taxi/MotorRecord.php

@@ -20,6 +20,15 @@ class MotorRecord extends BaseModel
     }
     }
 
 
     /**
     /**
+     * @param $value
+     * @return false|string
+     */
+    public function getCreatedAtAttr($value)
+    {
+        return ['val'=>$value,'text'=>date('m.d H:i', $value)];
+    }
+
+    /**
      * @desc 资金变动日志
      * @desc 资金变动日志
      * @param Model $user 用户
      * @param Model $user 用户
      * @param string $field 字段
      * @param string $field 字段

+ 9 - 0
application/common/model/TaxiOrder.php

@@ -29,6 +29,15 @@ class TaxiOrder extends BaseModel
     }
     }
 
 
     /**
     /**
+     * @param $value
+     * @return false|string
+     */
+    public function getCreatedAtAttr($value)
+    {
+        return ['val'=>$value,'text'=>date('m.d H:i', $value)];
+    }
+
+    /**
      * 关联车俩
      * 关联车俩
      * @return \think\model\relation\BelongsTo
      * @return \think\model\relation\BelongsTo
      */
      */

+ 10 - 1
application/common/model/TaxiUsersWithdraw.php

@@ -36,8 +36,17 @@ class TaxiUsersWithdraw extends BaseModel
      * 关联用户
      * 关联用户
      * @return \think\model\relation\BelongsTo
      * @return \think\model\relation\BelongsTo
      */
      */
-    public function taxiuser()
+    public function taxiUser()
     {
     {
         return $this->belongsTo('TaxiUser','taxi_uid','id');
         return $this->belongsTo('TaxiUser','taxi_uid','id');
     }
     }
+
+    /**
+     * @param $value
+     * @return false|string
+     */
+    public function getCreatedAtAttr($value)
+    {
+        return ['val'=>$value,'text'=>date('m.d H:i', $value)];
+    }
 }
 }

+ 16 - 2
route/route.php

@@ -202,12 +202,26 @@ Route::group('api',function (){
             Route::group('taxiuser',function () {
             Route::group('taxiuser',function () {
                 // 登录
                 // 登录
                 Route::post('/userInfo','api/:ver.taxiUser.User/info');
                 Route::post('/userInfo','api/:ver.taxiUser.User/info');
-
                 // 修改密码
                 // 修改密码
                 Route::post('/modify','api/:ver.taxiUser.Auth/modify');
                 Route::post('/modify','api/:ver.taxiUser.Auth/modify');
 
 
-                // 修改密码
+
+                // 提现记录
+                Route::post('/withdrawLog','api/:ver.taxiUser.User/withdrawLog');
+                // 提现
                 Route::post('/withdraw','api/:ver.taxiUser.User/withdraw');
                 Route::post('/withdraw','api/:ver.taxiUser.User/withdraw');
+                // 资产明细
+                Route::post('/accountLog','api/:ver.taxiUser.User/accountLog');
+
+                // 订单大厅
+                Route::post('/order','api/:ver.taxiUser.Order/index');
+                // 我的订单
+                Route::post('/myOrder','api/:ver.taxiUser.Order/myOrder');
+                // 等待服务订单
+                Route::post('/waitOrder','api/:ver.taxiUser.Order/waitOrder');
+                // 确认订单
+                Route::post('/delivered','api/:ver.taxiUser.Order/delivered');
+
 
 
             });
             });