Commit d48516946555c5774d338b5db1c7ac84a01c9355

Authored by 曹明
1 parent cf6f0119
Exists in master

1. 用户登录集成

app-wx/config/main.php
@@ -12,7 +12,7 @@ return [ @@ -12,7 +12,7 @@ return [
12 'runtimePath' => Yii::getAlias('@rootRuntime').'/app-wx/', 12 'runtimePath' => Yii::getAlias('@rootRuntime').'/app-wx/',
13 'bootstrap' => ['log'], 13 'bootstrap' => ['log'],
14 'controllerNamespace' => 'app\wx\controllers', 14 'controllerNamespace' => 'app\wx\controllers',
15 - 'defaultRoute' => 'order', 15 + 'defaultRoute' => 'user',
16 'modules' => [ 16 'modules' => [
17 'order' => [ 17 'order' => [
18 'class' => 'app\wx\modules\order\Module', 18 'class' => 'app\wx\modules\order\Module',
app-wx/controllers/BaseController.php
@@ -175,24 +175,13 @@ class BaseController extends AppController @@ -175,24 +175,13 @@ class BaseController extends AppController
175 $appUser = Yii::$app->getUser(); 175 $appUser = Yii::$app->getUser();
176 if(YII_ENV_DEV && $appUser->isGuest){ 176 if(YII_ENV_DEV && $appUser->isGuest){
177 $uid = Yii::$app->params['testUID']; // 请在各自的config/params-local.php里配置 177 $uid = Yii::$app->params['testUID']; // 请在各自的config/params-local.php里配置
178 - $appUser->login(0);  
179 - $this->goHome(); 178 + header("Location: " . Yii::$app->params["baseUrl"] . "/user#login" );exit;
180 return ; 179 return ;
181 } 180 }
182 //test和 prod 环境,进行微信登陆 181 //test和 prod 环境,进行微信登陆
183 if ($appUser->isGuest){ 182 if ($appUser->isGuest){
184 - $this->handleOAuthRedirect();  
185 - } else {  
186 - $path = $this->request->get('jumppath');  
187 - $model= $this->request->get('jumpmodel');  
188 - $paramOne= $this->request->get('paramOne');  
189 - if (!empty($path) && !empty($model)) {  
190 - $locationUrl = Yii::$app->params["baseUrl"]."/".$model."#".$path;  
191 - if (!empty($paramOne)) {  
192 - $locationUrl .= "/".urldecode($paramOne);  
193 - }  
194 - header("Location: $locationUrl");exit;  
195 - } 183 + header("Location: " . Yii::$app->params["baseUrl"] . "/user#login" );exit;
  184 + return ;
196 } 185 }
197 186
198 } 187 }
app-wx/exts/User.php
@@ -72,7 +72,7 @@ class User extends AppUser @@ -72,7 +72,7 @@ class User extends AppUser
72 if ($id === null) { 72 if ($id === null) {
73 $identity = null; 73 $identity = null;
74 } else { 74 } else {
75 - $class = 'app\wx\models\Engineer'; 75 + $class = 'domain\user\models\User';
76 $identity = $class::findIdentity($id); 76 $identity = $class::findIdentity($id);
77 } 77 }
78 78
app-wx/models/User.php
@@ -4,16 +4,13 @@ namespace app\wx\models; @@ -4,16 +4,13 @@ namespace app\wx\models;
4 4
5 use Yii; 5 use Yii;
6 use yii\log\Logger; 6 use yii\log\Logger;
7 -use yii\base\Exception;  
8 -use common\models\EngineerProfile as EngineerProfileModel;  
9 -use common\models\Address as AddressModel;  
10 -use domain\finance\models\EngineerWallet as EngineerWalletModel; 7 +use domain\user\models\User as UserModel;
11 8
12 /** 9 /**
13 * Class User 10 * Class User
14 * @package app\wx\models 11 * @package app\wx\models
15 */ 12 */
16 -class User 13 +class User extends UserModel
17 { 14 {
18 15
19 public function register() 16 public function register()
app-wx/modules/order/controllers/BaseController.php
@@ -19,6 +19,6 @@ class BaseController extends AppBaseController @@ -19,6 +19,6 @@ class BaseController extends AppBaseController
19 public function init() 19 public function init()
20 { 20 {
21 parent::init(); // TODO: Change the autogenerated stub 21 parent::init(); // TODO: Change the autogenerated stub
22 - 22 + $this->handleMallAccessCtrl();
23 } 23 }
24 } 24 }
25 \ No newline at end of file 25 \ No newline at end of file
app-wx/modules/user/controllers/BaseController.php
@@ -19,6 +19,6 @@ class BaseController extends AppBaseController @@ -19,6 +19,6 @@ class BaseController extends AppBaseController
19 public function init() 19 public function init()
20 { 20 {
21 parent::init(); // TODO: Change the autogenerated stub 21 parent::init(); // TODO: Change the autogenerated stub
22 - 22 + //$this->handleMallAccessCtrl();
23 } 23 }
24 } 24 }
25 \ No newline at end of file 25 \ No newline at end of file
app-wx/modules/user/controllers/LoginController.php
@@ -6,6 +6,8 @@ use common\helpers\ImageManager; @@ -6,6 +6,8 @@ use common\helpers\ImageManager;
6 use common\helpers\ImageUtils; 6 use common\helpers\ImageUtils;
7 use common\helpers\Utils; 7 use common\helpers\Utils;
8 use common\models\EngineerProfile; 8 use common\models\EngineerProfile;
  9 +use app\wx\models\User;
  10 +use common\helpers\Log as AppLog;
9 use domain\toutiao\TtDefaultImageRepository; 11 use domain\toutiao\TtDefaultImageRepository;
10 use domain\toutiao\TtNewsImageRepository; 12 use domain\toutiao\TtNewsImageRepository;
11 use domain\toutiao\TtNewsRepository; 13 use domain\toutiao\TtNewsRepository;
@@ -105,9 +107,30 @@ class LoginController extends BaseController @@ -105,9 +107,30 @@ class LoginController extends BaseController
105 // 校验验证码 107 // 校验验证码
106 // 检查车厂名称是否注册了 108 // 检查车厂名称是否注册了
107 // 检查手机号码是否注册了 109 // 检查手机号码是否注册了
108 - echo $mobile.'_'.$code;  
109 $e->success = true; 110 $e->success = true;
110 - 111 + $userInfo = \domain\user\models\User::findOne(1);
  112 + $this->processLogin($userInfo);
111 return $this->renderJson($e); 113 return $this->renderJson($e);
112 } 114 }
  115 +
  116 +
  117 + /**
  118 + * 处理用户登录逻辑
  119 + * @param User $userEntity
  120 + * @return bool|void
  121 + */
  122 + protected function processLogin($userEntity)
  123 + {
  124 + if(!($userEntity instanceof User)) {
  125 + AppLog::debug("processLogin: 返回 UserEntity 失败");
  126 + return false;
  127 + }
  128 + /**
  129 + * 登陆时间为7000秒,目前微信API的access token 的 expires_in 为 7200秒
  130 + */
  131 + if(Yii::$app->getUser()->login($userEntity, 7000)) {
  132 + return true;
  133 + }
  134 + return false;
  135 + }
113 } 136 }
114 \ No newline at end of file 137 \ No newline at end of file
domain/order/models/RepairFinishImages.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 维修订单故障图片
  10 + * This is the model class for table "{{%gk_repair_finish_images}}".
  11 + */
  12 +class RepairFinishImages extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_repair_finish_images}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/order/models/RepairOrder.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 维修订单
  10 + * This is the model class for table "{{%gk_repair_order}}".
  11 + */
  12 +class RepairOrder extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_repair_order}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/order/models/RepairOrderImages.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 维修订单故障图片
  10 + * This is the model class for table "{{%gk_repair_images}}".
  11 + */
  12 +class RepairOrderImages extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_repair_images}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/order/models/RepairOrderRate.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 维修订单评价
  10 + * This is the model class for table "{{%gk_repair_order_rate}}".
  11 + */
  12 +class RepairOrderRate extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_repair_order_rate}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/order/models/RepairOrderRepairPlan.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 维修方案
  10 + * This is the model class for table "{{%gk_repair_order_repair_plan}}".
  11 + */
  12 +class RepairOrderRepairPlan extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_repair_order_repair_plan}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/user/models/PhoneCode.php 0 → 100644
@@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +
  8 +/**
  9 + * 手机验证码
  10 + * This is the model class for table "{{%gk_phone_code}}".
  11 + */
  12 +class PhoneCode extends ActiveRecord
  13 +{
  14 + /**
  15 + * @inheritdoc
  16 + */
  17 + public static function tableName()
  18 + {
  19 + return '{{%gk_phone_code}}';
  20 + }
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function behaviors()
  26 + {
  27 + return [
  28 + 'time' => [
  29 + 'class' => TimestampBehavior::className(),
  30 + 'createdAtAttribute' => 'created_at',
  31 + 'updatedAtAttribute' => 'updated_at',
  32 + ]
  33 + ];
  34 + }
  35 +}
0 \ No newline at end of file 36 \ No newline at end of file
domain/user/models/User.php 0 → 100644
@@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
  1 +<?php
  2 +
  3 +namespace domain\user\models;
  4 +
  5 +use yii\db\ActiveRecord;
  6 +use yii\behaviors\TimestampBehavior;
  7 +use yii\web\IdentityInterface;
  8 +
  9 +/**
  10 + * 用户
  11 + * This is the model class for table "{{%gk_user}}".
  12 + */
  13 +class User extends ActiveRecord implements IdentityInterface
  14 +{
  15 + /**
  16 + * @inheritdoc
  17 + */
  18 + public static function tableName()
  19 + {
  20 + return '{{%gk_user}}';
  21 + }
  22 +
  23 + /**
  24 + * @return array
  25 + */
  26 + public function behaviors()
  27 + {
  28 + return [
  29 + 'time' => [
  30 + 'class' => TimestampBehavior::className(),
  31 + 'createdAtAttribute' => 'created_at',
  32 + 'updatedAtAttribute' => 'updated_at',
  33 + ]
  34 + ];
  35 + }
  36 +
  37 +
  38 + /** @inheritdoc */
  39 + public static function findIdentity($id)
  40 + {
  41 + return static::findOne($id);
  42 + }
  43 +
  44 + /** @inheritdoc */
  45 + public static function findIdentityByAccessToken($token, $type = null)
  46 + {
  47 + throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
  48 + }
  49 +
  50 + /** @inheritdoc */
  51 + public function getId()
  52 + {
  53 + return $this->getAttribute('id');
  54 + }
  55 +
  56 + /** @inheritdoc */
  57 + public function getAuthKey()
  58 + {
  59 + return $this->getAttribute('auth_key');
  60 + }
  61 +
  62 + /** @inheritdoc */
  63 + public function validateAuthKey($authKey)
  64 + {
  65 + return $this->getAttribute('auth_key') == $authKey;
  66 + }
  67 +}
0 \ No newline at end of file 68 \ No newline at end of file