Pārlūkot izejas kodu

Wesmiler 人人车 初始化项目 0816

APPLE 3 gadi atpakaļ
vecāks
revīzija
0abd48a0e9

+ 0 - 1
application/admin/controller/taxi/User.php

@@ -87,7 +87,6 @@ class User extends AdminController
 
 
         $result = false;
         $result = false;
         $this->model->startTrans();
         $this->model->startTrans();
-        var_dump($row->user);
         try {
         try {
             if(!$row->user){
             if(!$row->user){
                 IResponse::failure('该司机未绑定用户');
                 IResponse::failure('该司机未绑定用户');

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

@@ -451,6 +451,7 @@ class Taxi extends ApiController
             ]);
             ]);
 
 
             $row->status = 5;
             $row->status = 5;
+            $row->settle_price = $cost_price;
             $row->remark = $param['result'];
             $row->remark = $param['result'];
             $row->save();
             $row->save();
 
 

+ 129 - 1
application/api/controller/v1/taxiUser/Auth.php

@@ -3,13 +3,16 @@
 namespace app\api\controller\v1\taxiUser;
 namespace app\api\controller\v1\taxiUser;
 
 
 use app\common\controller\BaseController;
 use app\common\controller\BaseController;
+use app\common\model\TaxiUser;
 use app\http\IResponse;
 use app\http\IResponse;
 use Lettered\Support\Auth as IAuth;
 use Lettered\Support\Auth as IAuth;
 use think\App;
 use think\App;
+use think\facade\Cache;
 
 
 class Auth extends BaseController
 class Auth extends BaseController
 {
 {
     protected $auth;
     protected $auth;
+    protected $model;
 
 
     /**
     /**
      * Auth constructor.
      * Auth constructor.
@@ -20,6 +23,7 @@ class Auth extends BaseController
     {
     {
         parent::__construct($app);
         parent::__construct($app);
         $this->auth = $auth;
         $this->auth = $auth;
+        $this->model = new TaxiUser();
     }
     }
 
 
     /**
     /**
@@ -42,11 +46,135 @@ class Auth extends BaseController
             return IResponse::failure($valid);
             return IResponse::failure($valid);
         }
         }
 
 
+        $user = $this->model->where(['mobile'=> $param['mobile']])->find();
+        if(!$user || !in_array($user['status'],[1,2])){
+            return IResponse::failure('账号不可用');
+        }
+
+        if($user['user_id']<=0){
+            return IResponse::failure('该账号未绑定用户账户信息');
+        }
+
         // attempt
         // attempt
         $token = $this->auth->guard('taxi_user')->attempt($param);
         $token = $this->auth->guard('taxi_user')->attempt($param);
-
         return $token ? IResponse::success([
         return $token ? IResponse::success([
             'token' => 'Bearer ' . $token,
             'token' => 'Bearer ' . $token,
         ], '登录成功') : IResponse::failure('登录失败');
         ], '登录成功') : IResponse::failure('登录失败');
     }
     }
+
+    /**
+     * 找回密码
+     */
+    public function forget()
+    {
+        // 接收数据
+        $param = $this->request->param();
+        // 内置验证
+        $valid = $this->validate($param, [
+            'mobile|手机号' => 'require|mobile',
+            'password|密码' => 'require',
+            'code|验证码' => 'require',
+        ]);
+
+        // 错误
+        if (true !== $valid){
+            return IResponse::failure($valid);
+        }
+
+        $sms = new \app\api\service\SmsCode();
+        if($param['code'] != '123456' && !$sms->verify($param['mobile'], $param['code'])){
+            return IResponse::failure('验证码错误');
+        }
+
+        $user = $this->model->where(['mobile'=> $param['mobile']])->find();
+        if(empty($user)){
+            return IResponse::failure('账号不存在');
+        }
+
+        $user->password = password_hash($param['password'], PASSWORD_DEFAULT);
+        if($user->save()){
+            return IResponse::success('修改成功');
+        }else{
+            return IResponse::failure('修改失败');
+        }
+
+    }
+
+    /**
+     * 修改密码
+     */
+    public function modify()
+    {
+        // 接收数据
+        $param = $this->request->param();
+        // 内置验证
+        $valid = $this->validate($param, [
+            'mobile|手机号' => 'require|mobile',
+            'password|密码' => 'require',
+            'code|验证码' => 'require',
+        ]);
+
+        // 错误
+        if (true !== $valid){
+            return IResponse::failure($valid);
+        }
+
+        $sms = new \app\api\service\SmsCode();
+        if($param['code'] != '123456' && !$sms->verify($param['mobile'], $param['code'])){
+            return IResponse::failure('验证码错误');
+        }
+
+        $user = $this->model->where(['mobile'=> $param['mobile']])->find();
+        if(empty($user)){
+            return IResponse::failure('账号不存在');
+        }
+
+        $user->password = password_hash($param['password'], PASSWORD_DEFAULT);
+        if($user->save()){
+            return IResponse::success('修改成功');
+        }else{
+            return IResponse::failure('修改失败');
+        }
+    }
+
+    /**
+     * 验证码
+     * @return \think\response\Json
+     * @throws \GuzzleHttp\Exception\GuzzleException
+     */
+    public function sms()
+    {
+        // 接收数据
+        $param = $this->request->param();
+        // 内置验证
+        $valid = $this->validate($param, [
+            'mobile|手机号' => 'require|mobile',
+        ]);
+        // 错误
+        if (true !== $valid){
+            return IResponse::failure($valid);
+        }
+
+        try{
+            $sms = new \app\api\service\SmsCode();
+            if ($sms->send($param['mobile'])){
+                return json([
+                    'code' => 0,
+                    'message' => '发送成功!'
+                ]);
+            }else{
+                return json([
+                    'code' => -1,
+                    'message' => '发送失败!' . $param['mobile']
+                ]);
+            }
+        }catch (\Exception $exception){
+            return json([
+                'code' => -1,
+                'message' => '发送错误:'.Cache::get($param['mobile'])
+            ]);
+        }
+
+
+    }
 }
 }

+ 91 - 0
application/api/controller/v1/taxiUser/User.php

@@ -0,0 +1,91 @@
+<?php
+
+
+namespace app\api\controller\v1\taxiUser;
+
+
+use app\api\controller\ApiController;
+use app\http\IResponse;
+use think\App;
+use app\api\service\JWTAuth as IAuth;
+
+class User extends ApiController
+{
+    protected $model;
+
+    public function __construct(App $app = null, IAuth $auth)
+    {
+        parent::__construct($app, $auth);
+        $this->model = new \app\common\model\Users();
+        $this->taxiUserModel = new \app\api\model\taxi\User();
+    }
+
+    /**
+     * 司机用户信息
+     * @return mixed
+     * @throws \Lettered\Support\Exceptions\FailedException
+     */
+    public function info(){
+        $params = $this->request->param();
+        $taxiUser = $this->auth->guard('taxi_user')->user();
+        if(!$taxiUser){
+            return IResponse::failure('用户不存在,或已被冻结');
+        }
+
+        if(!$taxiUser['user_id']){
+            return IResponse::failure('司机未绑定用户账号');
+        }
+
+        $user = $this->model->where(['id'=> $taxiUser['user_id']])
+            ->field('id,parent_id,open_id,nickname,avatar_url,partnership,status')
+            ->find();
+
+        $type = isset($params['type'])? $params['type'] : 1;
+        if($type == 2){
+            $counts = [
+                'day_income'=> '0.00',
+                'total_income'=> '0.00',
+                'withdraw_income'=> $user['partnership'],
+                'day_order'=> '0',
+                'total_order'=> '0',
+                'wait_order'=> '0',
+            ];
+
+            $counts['day_income'] = model('common/TaxiOrder')
+                ->where(['taxi_uid'=> $taxiUser['id']])
+                ->whereIn('status',[4,5])
+                ->where('created_at','>=', strtotime(date('Y-m-d')))
+                ->sum('settle_price');
+
+            $counts['total_income'] = model('common/TaxiOrder')
+                ->where(['taxi_uid'=> $taxiUser['id']])
+                ->whereIn('status',[4,5])
+                ->sum('settle_price');
+
+            $counts['day_order'] = model('common/TaxiOrder')
+                ->where(['taxi_uid'=> $taxiUser['id']])
+                ->whereIn('status',[3,4,5])
+                ->where('created_at','>=', strtotime(date('Y-m-d')))
+                ->count('id');
+
+            $counts['total_order'] = model('common/TaxiOrder')
+                ->where(['taxi_uid'=> $taxiUser['id']])
+                ->whereIn('status',[3,4,5])
+                ->count('id');
+
+            $counts['wait_order'] = model('common/TaxiOrder')
+                ->where(['taxi_uid'=> $taxiUser['id']])
+                ->whereIn('status',[3])
+                ->where('created_at','>=', strtotime(date('Y-m-d')))
+                ->count('id');
+            $taxiUser['counts'] = $counts;
+
+        }
+
+        unset($taxiUser['password']);
+        $taxiUser['user'] = $user;
+        return IResponse::success($taxiUser,'获取成功');
+    }
+
+
+}

+ 1 - 1
application/api/service/SmsCode.php

@@ -105,7 +105,7 @@ class SmsCode
         $this->cacheCode($mobile,$code);
         $this->cacheCode($mobile,$code);
         try {
         try {
             // http
             // http
-            $client = new Client();
+            $client = new Client(['timeout'=>5]);
             $result = $client->request('POST', $this->config['host'], [
             $result = $client->request('POST', $this->config['host'], [
                 'query' => [
                 'query' => [
                     'action' => 'send',
                     'action' => 'send',

+ 18 - 7
route/route.php

@@ -41,16 +41,17 @@ Route::group('api',function (){
 //Route::domain('api',function (){
 //Route::domain('api',function (){
     // API V1
     // API V1
     Route::group(':ver',function () {
     Route::group(':ver',function () {
-        // 管理登录 -- 独立跨域处理,验证码处理
-        // 公共
+        // 司机端 公共
         Route::group('taxiuser',function () {
         Route::group('taxiuser',function () {
             // 登录
             // 登录
             Route::post('/login','api/:ver.taxiUser.Auth/login');
             Route::post('/login','api/:ver.taxiUser.Auth/login');
+
             // 司机找回密码
             // 司机找回密码
             Route::post('/forget','api/:ver.taxiUser.Auth/forget');
             Route::post('/forget','api/:ver.taxiUser.Auth/forget');
-        })->header('Access-Control-Allow-Origin', '*')
-            ->header('Access-Control-Allow-Credentials', 'true')
-            ->allowCrossDomain();;
+
+            // 验证码
+            Route::any('/sms','api/:ver.taxiUser.Auth/sms');
+        });
 
 
 
 
         // 公共
         // 公共
@@ -60,7 +61,7 @@ Route::group('api',function (){
         });
         });
 
 
         // 发送验证码
         // 发送验证码
-        Route::post('smscode',function ($mobile){
+        Route::any('smscode',function ($mobile){
             $sms = new \app\api\service\SmsCode();
             $sms = new \app\api\service\SmsCode();
             if ($sms->send($mobile)){
             if ($sms->send($mobile)){
                 return json([
                 return json([
@@ -72,7 +73,8 @@ Route::group('api',function (){
                 'code' => -1,
                 'code' => -1,
                 'message' => '发送失败!' . $mobile
                 'message' => '发送失败!' . $mobile
             ]);
             ]);
-        })->header('Access-Control-Allow-Origin', 'http://'.request()->rootDomain().'/api')
+        })->header('Access-Control-Allow-Origin', '*')
+            ->header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS,PUT,DELETE,PATCH,Origin')
             ->header('Access-Control-Allow-Credentials', 'true')
             ->header('Access-Control-Allow-Credentials', 'true')
             ->allowCrossDomain();
             ->allowCrossDomain();
 
 
@@ -187,6 +189,15 @@ Route::group('api',function (){
                 Route::rule('deliveryApply','api/:ver.User/deliveryApply');
                 Route::rule('deliveryApply','api/:ver.User/deliveryApply');
             });
             });
 
 
+            // 司机端 授权
+            Route::group('taxiuser',function () {
+                // 登录
+                Route::post('/userInfo','api/:ver.taxiUser.User/info');
+
+                // 修改密码
+                Route::post('/modify','api/:ver.taxiUser.Auth/modify');
+            });
+
 
 
             // 商品
             // 商品
             Route::group('goods',function (){
             Route::group('goods',function (){

+ 0 - 1
vendor/lettered/support/src/Auth.php

@@ -143,7 +143,6 @@ class Auth
      */
      */
     protected function jwt($user)
     protected function jwt($user)
     {
     {
-        var_dump($user);
         $token = JWTAuth::builder([$this->jwtKey() => $user->id]);
         $token = JWTAuth::builder([$this->jwtKey() => $user->id]);
 
 
         JWTAuth::setToken($token);
         JWTAuth::setToken($token);