shish 5 лет назад
Родитель
Сommit
37ec5b803a

+ 151 - 144
app-mall/controllers/AuthController.php

@@ -2,6 +2,7 @@
 
 namespace mall\controllers;
 
+use biz\shop\classes\ShopClass;
 use bizMall\merchant\services\MerchantService;
 use bizMall\user\classes\UserClass;
 use bizMall\user\services\UserService;
@@ -21,150 +22,156 @@ use yii\helpers\Json;
  */
 class AuthController extends PublicController
 {
-	
-	//准备授权 shish 2019.11.19
-	public function actionPrepare()
-	{
-		$get = Yii::$app->request->get();
-		$url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
-		if (empty($url)) {
-			util::fail('没有网址');
-		}
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::fail('没有商家帐号');
-		}
-		$merchant = MerchantService::getById($account);
-		if (empty($merchant)) {
-			util::fail('商家无效');
-		}
-		/**
-		 * authScope 参数的说明
-		 * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
-		 * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
-		 * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
-		 * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
-		 */
-		$authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
-		$urlEncode = stringUtil::urlSafeB64Encode($url);
-		//微信授权获取code shish 2019.11.24
-		wxUtil::getCode($urlEncode, $merchant, $authScope);
-		util::end();
-	}
-	
-	//微信授权获取用户信息 shish 2019.11.20
-	public function actionGetUserInfo()
-	{
-		$get = Yii::$app->request->get();
-		$code = isset($get['code']) ? $get['code'] : '';
-		if (empty($code)) {
-			util::fail('没有获取用户code');
-		}
-		if (isset($get['state']) && $get['state'] == 'authdeny') {
-			util::fail('auth fail');
-		}
-		$urlEncode = $get['url'];
-		$url = stringUtil::urlSafeBase64Decode($urlEncode);
-		$account = httpUtil::getAccount($url);
-		if (empty($account)) {
-			util::stop('商店ID无效。');
-		}
-		$merchant = xhMerchantService::getByAccount($account);
-		if (empty($merchant)) {
-			util::stop('商店无效');
-		}
-		$merchantId = $merchant['id'];
-		$authScope = isset($get['authScope']) ? $get['authScope'] : '';
-		if (empty($authScope)) {
-			util::stop('没有授权类型');
-		}
-		$data = wxUtil::getOpenId($code, $merchant);
-		if ($data === false) {
-			//微信授权获取code shish 2019.11.24
-			wxUtil::getCode($urlEncode, $merchant, $authScope);
-			util::end();
-		}
-		$openId = $data['openid'];
-		$access_token = $data['access_token'];
-		$user = UserService::getByOpenId($openId, $merchantId);
-		//用户来源
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		if (empty($user)) {
-			//$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
-			$originalInfo = [];
-			$originalInfo['openId'] = $openId;
-			$originalInfo['merchantId'] = $merchantId;
-			
-			//没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
-			if ($authScope == 'snsapi_userinfo') {
-				$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-				$originalInfo = array_merge($baseInfo, $originalInfo);
-				$originalInfo['isFull'] = 1;
-				$originalInfo['unionId'] = $baseInfo['unionid'];
-				$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-				$originalInfo['nickName'] = $baseInfo['nickName'];
-			}
-			$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-		} else {
-			if ($user['isFull'] == 0) {
-				if ($authScope == 'snsapi_userinfo') {
-					$baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
-					$originalInfo = $baseInfo;
-					$originalInfo['isFull'] = 1;
-					$originalInfo['unionId'] = $baseInfo['unionid'];
-					$originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
-					$originalInfo['openId'] = $baseInfo['openid'];
-					$originalInfo['nickName'] = $baseInfo['nickName'];
-					$originalInfo['merchantId'] = $merchantId;
-					$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-				}
-			}
-		}
-		//这个的基类没有设置统一的全局变量,这里进行设置一次
-		$userId = $user['id'];
-		//获取token
-		$token = jwt::getNewToken($userId);
-		$url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
-		$this->redirect($url);
-	}
-	
-	//静默获取小程序用户信息
-	public function actionMiniInfo()
-	{
-		$code = Yii::$app->request->get('code', '');
-		if (empty($code)) {
-			util::fail('没有CODE信息');
-		}
-		$merchant = $this->merchant;
-		$appId = $merchant['miniAppId'];
-		$appSecret = $merchant['miniAppSecret'];
-		if (empty($appSecret)) {
-			util::fail('没有找到小程序的密钥');
-		}
-		$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-		
-		$curl = new curl\Curl();
-		$result = $curl->get($url);
-		$arr = Json::decode($result);
-		$sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-		$miniOpenId = isset($arr['openid']) ? $arr['openid'] : '';
-		if (empty($miniOpenId)) {
-			Yii::info(json_encode($arr));
-			util::fail('没有获取到小程序openId');
-		}
-		$unionId = isset($arr['unionid']) && !empty($arr['unionid']) ? $arr['unionid'] : '';
 
-		$userInfo = ['miniOpenId' => $miniOpenId,'unionId' => $unionId];
-		$userSource = UserClass::$userSourceId['mini']['name'];
-		$user = UserService::replaceUser($userInfo, $userSource);
+    //准备授权 shish 2019.11.19
+    public function actionPrepare()
+    {
+        $get = Yii::$app->request->get();
+        $url = isset($get['url']) && !empty($get['url']) ? $get['url'] : '';
+        if (empty($url)) {
+            util::fail('没有网址');
+        }
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::fail('没有商家帐号');
+        }
+        $sj = MerchantService::getById($account);
+        if (empty($sj)) {
+            util::fail('商家无效');
+        }
+        /**
+         * authScope 参数的说明
+         * 1.用户通过公众号菜单打开网页,因为已经关注过了公众号,已经生成过用户信息,所以只要使用snsapi_base静默方式拿到openid就可以
+         * 2.为了保证付款页的访问速度,暂时只要通过snsapi_base静默方式拿到openid先生成可以用的用户信息即可
+         * 3.其它情况需要获取用户完整信息的,使用snsapi_userinfo让用户授权获取信息即可
+         * 4.snsapi_base静默方式使用的场景更多,所以参数authScope默认使用snsapi_base
+         */
+        $authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
+        $urlEncode = stringUtil::urlSafeB64Encode($url);
+        //微信授权获取code shish 2019.11.24
+        wxUtil::getCode($urlEncode, $sj, $authScope);
+        util::end();
+    }
+
+    //微信授权获取用户信息 shish 2019.11.20
+    public function actionGetUserInfo()
+    {
+        $get = Yii::$app->request->get();
+        $code = isset($get['code']) ? $get['code'] : '';
+        if (empty($code)) {
+            util::fail('没有获取用户code');
+        }
+        if (isset($get['state']) && $get['state'] == 'authdeny') {
+            util::fail('auth fail');
+        }
+        $urlEncode = $get['url'];
+        $url = stringUtil::urlSafeBase64Decode($urlEncode);
+        $account = httpUtil::getAccount($url);
+        if (empty($account)) {
+            util::stop('商店ID无效。');
+        }
+        $sj = xhMerchantService::getByAccount($account);
+        if (empty($sj)) {
+            util::stop('商店无效');
+        }
+        $sjId = $sj['id'];
+        $authScope = isset($get['authScope']) ? $get['authScope'] : '';
+        if (empty($authScope)) {
+            util::stop('没有授权类型');
+        }
+        $data = wxUtil::getOpenId($code, $sj);
+        if ($data === false) {
+            //微信授权获取code shish 2019.11.24
+            wxUtil::getCode($urlEncode, $sj, $authScope);
+            util::end();
+        }
+        $openId = $data['openid'];
+        $access_token = $data['access_token'];
+        $user = UserService::getByOpenId($openId, $sjId);
+        //用户来源
+        $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
+        $source = $userSource['name'];
+        if (empty($user)) {
+            //$authScope 默认是 snsapi_base 公众号菜单打开网页(已经关注公众号,有完整信息)、打开付款页(有些客户只付款,没有后续可以不用登记完整信息),只需要获取openid
+            $originalInfo = [];
+            $originalInfo['openId'] = $openId;
+            $originalInfo['merchantId'] = $sjId;
+
+            //没有关注公众号,需要获取用户完整信息的情况,则通过弹框授权
+            if ($authScope == 'snsapi_userinfo') {
+                $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                $originalInfo = array_merge($baseInfo, $originalInfo);
+                $originalInfo['isFull'] = 1;
+                $originalInfo['unionId'] = $baseInfo['unionid'];
+                $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                $originalInfo['nickName'] = $baseInfo['nickName'];
+            }
+            $user = UserClass::replaceUser($originalInfo, $source, $sjId);
+        } else {
+            if ($user['isFull'] == 0) {
+                if ($authScope == 'snsapi_userinfo') {
+                    $baseInfo = wxUtil::authGetUserInfo($openId, $access_token);
+                    $originalInfo = $baseInfo;
+                    $originalInfo['isFull'] = 1;
+                    $originalInfo['unionId'] = $baseInfo['unionid'];
+                    $originalInfo['headImgUrl'] = $baseInfo['headimgurl'];
+                    $originalInfo['openId'] = $baseInfo['openid'];
+                    $originalInfo['nickName'] = $baseInfo['nickName'];
+                    $originalInfo['merchantId'] = $sjId;
+                    $user = UserClass::replaceUser($originalInfo, $source, $sjId);
+                }
+            }
+        }
+        //这个的基类没有设置统一的全局变量,这里进行设置一次
+        $userId = $user['id'];
+        //获取token
+        $token = jwt::getNewToken($userId);
+        $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
+        $this->redirect($url);
+    }
+
+    //静默获取小程序用户信息
+    public function actionMiniInfo()
+    {
+        $code = Yii::$app->request->get('code', '');
+        if (empty($code)) {
+            util::fail('没有CODE信息');
+        }
+        $sjWx = $this->sjWx;
+        $appId = $sjWx['miniAppId'];
+        $appSecret = $sjWx['miniAppSecret'];
+        if (empty($appSecret)) {
+            util::fail('没有找到小程序的密钥');
+        }
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+
+        $curl = new curl\Curl();
+        $result = $curl->get($url);
+        $arr = Json::decode($result);
+        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+        $miniOpenId = isset($arr['openid']) ? $arr['openid'] : '';
+        if (empty($miniOpenId)) {
+            Yii::info(json_encode($arr));
+            util::fail('没有获取到小程序openId');
+        }
+        $unionId = isset($arr['unionid']) && !empty($arr['unionid']) ? $arr['unionid'] : '';
+
+        $userInfo = ['miniOpenId' => $miniOpenId, 'unionId' => $unionId];
+        $userSource = UserClass::$userSourceId['mini']['name'];
+
+        $shopId = $this->shopId;
+        $sjId = 0;
+        if (!empty($shopId)) {
+            $shop = ShopClass::getById($shopId);
+            $sjId = $shop['merchantId'] ?? 0;
+        }
+        $user = UserClass::replaceUser($userInfo, $userSource, $sjId);
+        $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
+        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+        $userId = $user['id'];
+        $token = jwt::getNewToken($userId);
+        //update = 1 表示要求启动时更新(如果需要马上应用最新版本,可以使用 wx.getUpdateManager API 进行处理。)
+        util::success(['token' => $token, 'user' => $user, 'update' => 0]);
+    }
 
-		$cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
-		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-		$userId = $user['id'];
-		$token = jwt::getNewToken($userId);
-		//update = 1 表示要求启动时更新(如果需要马上应用最新版本,可以使用 wx.getUpdateManager API 进行处理。)
-		util::success(['token' => $token, 'user' => $user, 'update' => 0]);
-	}
-	
 }

+ 27 - 14
app-mall/controllers/BaseController.php

@@ -2,6 +2,8 @@
 
 namespace mall\controllers;
 
+use biz\shop\classes\ShopClass;
+use bizHd\custom\classes\CustomClass;
 use bizMall\merchant\services\MerchantExtendService;
 use bizMall\merchant\services\MerchantService;
 use bizMall\user\services\UserService;
@@ -13,29 +15,35 @@ class BaseController extends PublicController
 {
 
     public $validate = true;
-    public $withoutLogin = [];//不需要登陆可以访问的方法
+    public $guestAccessAction = [];
     public $userId = 0, $user, $shopId;
-    public $merchantId, $merchant, $merchantExtend;
+    public $sjId, $sj, $sjExtend, $customId = 0;
     public $isWx;
 
     public function beforeAction($action)
     {
-        //token验证
         $userId = jwt::getLoginId();
         $header = httpUtil::getHeader();
-        $merchantId = isset($header['account']) ? $header['account'] : 0;
-        $shopId = isset($header['shopId']) ? $header['shopId'] : 0;
-        if (empty($merchantId)) {
-            util::fail('商家无效');
+        $shopId = isset($header['account']) ? $header['account'] : 0;
+        if (empty($shopId)) {
+            util::fail('没有找到门店');
         }
-        $merchant = MerchantService::getMerchantById($merchantId);
-        if (empty($merchant)) {
-            util::fail('商家信息无效');
+        $shop = ShopClass::getById($shopId);
+        if (empty($shop)) {
+            util::fail('没有找到门店哦');
         }
-        $this->merchantId = $merchantId;
-        $this->merchant = $merchant;
+        $sjId = $shop['merchantId'] ?? 0;
+        if (empty($sjId)) {
+            util::fail('没有找到商家哦');
+        }
+        $sj = MerchantService::getMerchantById($sjId);
+        if (empty($sj)) {
+            util::fail('没有找到商家');
+        }
+        $this->sjId = $sjId;
+        $this->sj = $sj;
         $this->shopId = $shopId;
-        $this->merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
+        $this->sjExtend = MerchantExtendService::getByMerchantId($sjId);
         $this->isWx = util::isWx();
 
         if (empty($userId)) {
@@ -44,10 +52,15 @@ class BaseController extends PublicController
             $this->validate = true;
             $this->userId = $userId;
             $userInfo = UserService::getUserInfo($userId);
+            if (empty($userInfo)) {
+                util::fail('没有用户信息');
+            }
             $this->user = $userInfo;
+            $customId = CustomClass::getCurrentCustomId($sjId, $userInfo);
+            $this->customId = $customId;
         }
         //游客可以访问的方法
-        if (in_array($action->id, $this->withoutLogin)) {
+        if (in_array($action->id, $this->guestAccessAction)) {
             $this->validate = true;
         }
 

+ 3 - 3
app-mall/controllers/CategoryController.php

@@ -14,7 +14,7 @@ class CategoryController extends BaseController
 	//获取分类 shish 2019.12.2
 	public function actionList()
 	{
-		$return = CategoryService::getEnableList($this->merchantId);
+		$return = CategoryService::getEnableList($this->sjId);
 		util::success($return);
 	}
 	
@@ -23,9 +23,9 @@ class CategoryController extends BaseController
 	{
 		$categoryId = Yii::$app->request->get('categoryId');
 		//没有分类默认取商家第一个分类
-		$categoryId = !empty($categoryId) ? $categoryId : CategoryService::getTopCategoryId($this->merchantId);
+		$categoryId = !empty($categoryId) ? $categoryId : CategoryService::getTopCategoryId($this->sjId);
 		$where = [];
-		$where['merchantId'] = $this->merchantId;
+		$where['merchantId'] = $this->sjId;
 		$where['cId'] = $categoryId;
 		$where['delStatus'] = 0;
 		$data = GoodsCategoryService::getGoodsList($where);

+ 6 - 6
app-mall/controllers/ChatController.php

@@ -32,8 +32,8 @@ class ChatController extends BaseController
 	public function actionBegin()
 	{
 		//新增最近联系人
-		ChatService::addRecentlyUser($this->merchantId, $this->userId);
-		util::success(['merchant' => $this->merchant, 'user' => $this->user]);
+		ChatService::addRecentlyUser($this->sjId, $this->userId);
+		util::success(['merchant' => $this->sj, 'user' => $this->user]);
 	}
 
 	//发消息给老板 shish 2019.12.28
@@ -70,7 +70,7 @@ class ChatController extends BaseController
 				//商品
 				$id = $post['goodsId'];
 				$info = GoodsService::getGoodsInfo($id);
-				GoodsService::valid($info, $this->merchantId);
+				GoodsService::valid($info, $this->sjId);
 				$arr['goodsName'] = $info['goodsName'];
 				$arr['img'] = isset($info['smallImgList'][0]) ? $info['smallImgList'][0] : '';
 				$arr['price'] = isset($info['price']) ? $info['price'] : 300;
@@ -78,8 +78,8 @@ class ChatController extends BaseController
 		}
 		$data[] = $arr;
 		
-		$id = 'merchantChat_' . $this->merchantId;
-		$merchantId = $this->merchantId;
+		$id = 'merchantChat_' . $this->sjId;
+		$sjId = $this->sjId;
 		$userId = $this->userId;
 		$chatOnline = Gateway::getClientIdByUid($id);
 		if ($chatOnline) {
@@ -88,7 +88,7 @@ class ChatController extends BaseController
 			util::success($data);
 		}
 		//有打开后台但没打开聊天框,通知有新消息
-		$consoleId = 'merchantConsole_' . $this->merchantId;
+		$consoleId = 'merchantConsole_' . $this->sjId;
 		$consoleOnline = Gateway::getClientIdByUid($consoleId);
 		if ($consoleOnline) {
 			$data = ['type' => 'newMessage', 'status' => 1];

+ 2 - 2
app-mall/controllers/ExpressController.php

@@ -21,8 +21,8 @@ class ExpressController extends BaseController
 		if (empty($lng) || empty($lat)) {
 			util::fail('经度或纬度不能为空');
 		}
-		$shopId = ShopService::getDefaultShopId($this->merchant);
-		$respond = ExpressService::getUserDistance($lng, $lat, $shopId, $this->merchantExtend);
+		$shopId = ShopService::getDefaultShopId($this->sj);
+		$respond = ExpressService::getUserDistance($lng, $lat, $shopId, $this->sjExtend);
 		util::success($respond);
 	}
 

+ 2 - 2
app-mall/controllers/GoodsController.php

@@ -18,8 +18,8 @@ class GoodsController extends BaseController
 	{
 		$id = Yii::$app->request->get('id', 0);
 		$info = GoodsService::getGoodsInfo($id);
-		GoodsService::valid($info, $this->merchantId);
-		$setting = GoodsSettingService::getByCondition(['merchantId' => $this->merchantId]);
+		GoodsService::valid($info, $this->sjId);
+		$setting = GoodsSettingService::getByCondition(['merchantId' => $this->sjId]);
 		$commonIntro = isset($setting['goodsIntroduce']) ? $setting['goodsIntroduce'] : '';
 		$info['commonIntro'] = $commonIntro;
 		util::success($info);

+ 1 - 1
app-mall/controllers/InformUserController.php

@@ -34,7 +34,7 @@ class InformUserController extends BaseController
 		} else {
 			util::fail('发送失败');
 		}
-		sms::send($mobile, $msg, $this->merchant);
+		sms::send($mobile, $msg, $this->sj);
 		util::complete('已发送');
 	}
 

+ 1 - 1
app-mall/controllers/InviteController.php

@@ -24,7 +24,7 @@ class InviteController extends BaseController
 	public function actionProfile()
 	{
 		$stat = InviteStatService::getStat($this->userId);
-		$asset = InviteAssetService::getAsset($this->merchantId);
+		$asset = InviteAssetService::getAsset($this->sjId);
 		util::success(['stat' => $stat, 'asset' => $asset]);
 	}
 	

+ 2 - 2
app-mall/controllers/MainController.php

@@ -15,7 +15,7 @@ class MainController extends BaseController
 	//首页 shish 2019.12.2
 	public function actionIndex()
 	{
-		$where = ['merchantId' => $this->merchantId, 'type' => 0, 'status' => 1, 'delStatus' => 0];
+		$where = ['merchantId' => $this->sjId, 'type' => 0, 'status' => 1, 'delStatus' => 0];
 		$adRespond = AdService::getAdList($where);
 		$ad = [];
 		if (isset($adRespond['list']) && !empty($adRespond['list'])) {
@@ -23,7 +23,7 @@ class MainController extends BaseController
 				$ad[] = ['adImg' => $single['adImgUrl'], 'url' => ''];
 			}
 		}
-		$category = CategoryService::getTopThreeCategory($this->merchantId);
+		$category = CategoryService::getTopThreeCategory($this->sjId);
 		$categoryList = !empty($category) ? GoodsCategoryService::getAppointCategoryList($category) : [];
 		$data = ['ad' => $ad, 'category' => $categoryList, 'columnStyle' => rand(1, 2)];
 		util::success($data);

+ 1 - 1
app-mall/controllers/MapController.php

@@ -9,7 +9,7 @@ use Yii;
 class MapController extends BaseController
 {
 
-	public $withoutLogin = ['suggestion'];
+	public $guestAccessAction = ['suggestion'];
 
 	//腾讯地图关键词输入提醒 shish 2020.1.21
 	public function actionSuggestion()

+ 8 - 8
app-mall/controllers/MerchantController.php

@@ -15,22 +15,22 @@ class MerchantController extends BaseController
 	//当前用户获取门店信息
 	public function actionGetShopInfo()
 	{
-		$merchant = $this->merchant;
-		$merchant['defaultShop'] = ShopService::getDefaultShopInfo($merchant);
-		util::success($merchant);
+		$sj = $this->sj;
+		$sj['defaultShop'] = ShopService::getDefaultShopInfo($sj);
+		util::success($sj);
 	}
 	
 	//当前用户获取商家信息
 	public function actionGetInfo()
 	{
-		$merchant = MerchantService::getInfo($this->merchant, $this->merchantExtend);
-		util::success($merchant);
+		$sj = MerchantService::getInfo($this->sj, $this->sjExtend);
+		util::success($sj);
 	}
 
 	//客户的会员等级 shish 2020.1.2
 	public function actionUserGrade()
 	{
-		$list = MerchantExtendService::getGradeList($this->merchantExtend, 'asc', false);
+		$list = MerchantExtendService::getGradeList($this->sjExtend, 'asc', false);
 		util::success($list);
 	}
 	
@@ -38,8 +38,8 @@ class MerchantController extends BaseController
 	public function actionGetDeadline()
 	{
 		$id = Yii::$app->request->get('merchantId');
-		$merchant = MerchantService::getById($id);
-		$deadline = $merchant['setDeadline'];
+		$sj = MerchantService::getById($id);
+		$deadline = $sj['setDeadline'];
 		$date = date("Y-m-d H:i", $deadline);
 		util::success(['date' => $date]);
 	}

+ 2 - 2
app-mall/controllers/NoticeController.php

@@ -66,8 +66,8 @@ class NoticeController extends PublicController
 			util::end();
 		}
 		$orderId = $pay['id'];//商户订单号
-		$merchantId = isset($pay['merchantId']) ? $pay['merchantId'] : 0;
-		$extend = MerchantExtendService::getByMerchantId($merchantId);
+		$sjId = isset($pay['merchantId']) ? $pay['merchantId'] : 0;
+		$extend = MerchantExtendService::getByMerchantId($sjId);
 		$config = [
 			//应用ID,您的APPID。
 			'app_id' => $extend['alipayPId'],

+ 28 - 28
app-mall/controllers/OrderController.php

@@ -22,7 +22,7 @@ use common\components\util;
 class OrderController extends BaseController
 {
 
-    public $withoutLogin = ['order-relate', 'fast-pay'];
+    public $guestAccessAction = ['order-relate', 'fast-pay'];
 
     //商城下单操作 shish 2019.12.3
     public function actionCreateOrder()
@@ -53,7 +53,7 @@ class OrderController extends BaseController
         $post['bookMobile'] = $bookMobile;
 
         $post['payWay'] = $this->isWx == true ? 0 : 1;
-        $defaultShopId = MerchantService::getDefaultShopId($this->merchant);
+        $defaultShopId = MerchantService::getDefaultShopId($this->sj);
         if (empty($defaultShopId)) {
             util::fail('没有找到门店');
         }
@@ -64,11 +64,11 @@ class OrderController extends BaseController
         if ($freightType == 0 && $needSend == 1) {
             $lat = $post['latitude'];//收货人纬度
             $lng = $post['longitude'];//收货人经度
-            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->merchantExtend);
+            $respond = ExpressService::getUserDistance($lng, $lat, $defaultShopId, $this->sjExtend);
             $sendCost = isset($respond['fee']) ? $respond['fee'] : 0;
         }
         $post['sendCost'] = $sendCost;
-        $post['merchantId'] = $this->merchantId;
+        $post['merchantId'] = $this->sjId;
         $post['shopId'] = $defaultShopId;
 
         //计算总金额
@@ -113,7 +113,7 @@ class OrderController extends BaseController
             'orderId' => $orderId,
             'goodsId' => $goodsId,
             'userId' => $this->userId,
-            'merchantId' => $this->merchantId,
+            'merchantId' => $this->sjId,
             'title' => $goodsInfo['goodsName'],
             'cover' => isset($goodsInfo['shortImgList']) && !empty($goodsInfo['shortImgList']) ? current($goodsInfo['shortImgList']) : '',
             'unitPrice' => $unitPrice,
@@ -130,10 +130,10 @@ class OrderController extends BaseController
     public function actionOrderRelate()
     {
         $regionTree = RegionService::tree();
-        $shop = ShopService::getDefaultShop($this->merchant);
-        $freight = MerchantExtendService::getFreight($this->merchantExtend);
+        $shop = ShopService::getDefaultShop($this->sj);
+        $freight = MerchantExtendService::getFreight($this->sjExtend);
         $mapKey = 'OFWBZ-2NTHP-EHNDD-LKWQY-GANM7-PXBJH';
-        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->merchant];
+        $out = ['freight' => $freight, 'shop' => $shop, 'region' => $regionTree, 'txMapKey' => $mapKey, 'merchant' => $this->sj];
         util::success($out);
     }
 
@@ -222,20 +222,20 @@ class OrderController extends BaseController
         $input->SetTrade_type("JSAPI");
 
         //花卉宝代为申请的微信支付
-        $merchantExtend = $this->merchantExtend;
-        if ($merchantExtend['wxPayApply'] == 1) {
+        $sjExtend = $this->sjExtend;
+        if ($sjExtend['wxPayApply'] == 1) {
             $input->SetSub_openid($openId);
         } else {
             $input->SetOpenid($openId);
         }
         //小程序使用miniAppId
         if (httpUtil::isMiniProgram()) {
-            $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+            $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
         }
 
-        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+        $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
         $tools = new \JsApiPay();
-        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+        $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
         $newParams = json_decode($jsApiParameters, true);
         //已请求微信不能修改价格
         $updateData = [];
@@ -253,10 +253,10 @@ class OrderController extends BaseController
         ini_set('date.timezone', 'Asia/Shanghai');
         $post = Yii::$app->request->post();
         $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
-        $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->merchant);
+        $shopId = !empty($this->shopId) ? $this->shopId : ShopService::getDefaultShopId($this->sj);
         //验证门店是否有效
         $shopInfo = ShopService::getById($shopId);
-        ShopService::valid($shopInfo, $this->merchantId);
+        ShopService::valid($shopInfo, $this->sjId);
         $post['shopId'] = $shopId;
         //默认门店订单
         $store = isset($post['store']) ? $post['store'] : 1;
@@ -284,7 +284,7 @@ class OrderController extends BaseController
         $post['discountAmount'] = $discountData['discountAmount'];
         $post['actPrice'] = $actPrice;
         $post['payStyle'] = 0;
-        $post['merchantId'] = $this->merchantId;
+        $post['merchantId'] = $this->sjId;
         $now = time();
         $expireTime = $now + 300;//订单5分钟后过期
         $post['createTime'] = date("Y-m-d H:i:s", $now);
@@ -300,7 +300,7 @@ class OrderController extends BaseController
         $order = OrderService::addOrder($post);
         $orderId = $order['id'];
         $orderSn = $order['orderSn'];
-        $merchantId = $this->merchantId;
+        $sjId = $this->sjId;
         if ($payWay == 0) {
             $orderId = $order['id'];
             $name = '购买商品';
@@ -337,25 +337,25 @@ class OrderController extends BaseController
             $input->SetTrade_type("JSAPI");
 
             //花卉宝代为申请的微信支付
-            $merchantExtend = $this->merchantExtend;
-            if ($merchantExtend['wxPayApply'] == 1) {
+            $sjExtend = $this->sjExtend;
+            if ($sjExtend['wxPayApply'] == 1) {
                 $input->SetSub_openid($openId);
             } else {
                 $input->SetOpenid($openId);
             }
             //小程序使用miniAppId
             if (httpUtil::isMiniProgram()) {
-                $merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+                $sjExtend['wxAppId'] = $sjExtend['miniAppId'];
             }
-            Yii::info('支付发起使用小程序信息' . json_encode($merchantExtend));
-            $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend);
+            Yii::info('支付发起使用小程序信息' . json_encode($sjExtend));
+            $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend);
             $tools = new \JsApiPay();
-            $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend);
+            $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend);
             $newParams = json_decode($jsApiParameters, true);
             $newParams['orderId'] = $orderId;
             util::success($newParams);
         } elseif ($payWay == 1) {
-            $extend = MerchantExtendService::getByMerchantId($merchantId);
+            $extend = MerchantExtendService::getByMerchantId($sjId);
             if (isset($extend['alipayInit']) == false || $extend['alipayInit'] == 0) {
                 util::fail('支付宝付款即将开通...');
             }
@@ -393,7 +393,7 @@ class OrderController extends BaseController
 
             $typeList = dict::getConfig('capitalType');
             $capitalType = $typeList['xhOrder']['id'];
-            $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
+            $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $sjId;//将流水类型、优惠卷传过去
             $passbackParams = urlencode($passbackParams);
 
             $payRequestBuilder = new \AlipayTradeWapPayContentBuilder();
@@ -405,7 +405,7 @@ class OrderController extends BaseController
             //在异步通知时将该参数原样返回
             $payRequestBuilder->setPassbackParams($passbackParams);
             //同步通知
-            $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$merchantId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
+            $returnUrl = Yii::$app->params['mallDomain'] . "/#/pages/callback/success?account={$sjId}&shopId={$shopId}&orderSn={$orderSn}&totalPrice={$totalFee}&pageStatus=3&payDiscountPrice=0&payDiscountType=0";
             //异步通知
             $notifyUrl = Yii::$app->params['mallHost'] . "/notice/alipay-callback";
             $payResponse = new \AlipayTradeService($config);
@@ -442,7 +442,7 @@ class OrderController extends BaseController
         $post = Yii::$app->request->post();
         $id = $post['id'];
         $order = OrderService::getById($id);
-        OrderService::valid($order, $this->merchantId);
+        OrderService::valid($order, $this->sjId);
         if ($order['grade'] > 0) {
             util::fail('您已经评过了');
         }
@@ -462,7 +462,7 @@ class OrderController extends BaseController
         if (!empty($orderSn)) {
             $detail = OrderService::getOrderBySn($orderSn);
         }
-        OrderService::valid($detail, $this->merchantId);
+        OrderService::valid($detail, $this->sjId);
         util::success($detail);
     }
 

+ 18 - 18
app-mall/controllers/PayController.php

@@ -29,7 +29,7 @@ use common\components\dict;
 class PayController extends BaseController
 {
 
-	public $withoutLogin = ['get-params'];
+	public $guestAccessAction = ['get-params'];
 
 	
 
@@ -43,8 +43,8 @@ class PayController extends BaseController
 		$post['payWay'] = $this->isWx == true ? 0 : 1;
 		$lat2 = $post['receiveLat'];//收货人纬度
 		$lng2 = $post['long'];//收货人经度
-		$lat1 = $this->merchant['shopLat'];//花店纬度
-		$lng1 = $this->merchant['shopLong'];//花店经度
+		$lat1 = $this->sj['shopLat'];//花店纬度
+		$lng1 = $this->sj['shopLong'];//花店经度
 		$calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
 		$post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
 		$sendDistance = $post['sendDistance'];
@@ -60,7 +60,7 @@ class PayController extends BaseController
 			$addPrice = intval($subDistance / $nextDistance) * $nextPrice;
 			$post['sendCost'] = $firstPrice + $addPrice;
 		}
-		if (empty($this->merchantExtend['payment'])) {
+		if (empty($this->sjExtend['payment'])) {
 			util::fail('支付功能未开通,暂时无法购买哦~');
 		}
 		$couponAmount = 0;
@@ -78,9 +78,9 @@ class PayController extends BaseController
 		}
 		//不要将代金劵保存到订单表,付款成功后再保存进去!!!
 		unset($post['couponId']);
-		$post['merchantId'] = $this->merchantId;
+		$post['merchantId'] = $this->sjId;
 		//店铺id
-		$post['shopId'] = $this->merchant['defaultShopId'];
+		$post['shopId'] = $this->sj['defaultShopId'];
 		$order = xhOrderService::add($post);//创建订单
 		if ($order == false) {
 			util::fail('创建订单失败');
@@ -124,7 +124,7 @@ class PayController extends BaseController
 				'orderId' => $orderId,
 				'goodsId' => $goodsId,
 				'userId' => $userId,
-				'merchantId' => $this->merchantId,
+				'merchantId' => $this->sjId,
 				'title' => $goods['goodsName'],
 				'cover' => $goods['cover'],
 				'unitPrice' => $price,
@@ -148,7 +148,7 @@ class PayController extends BaseController
 		$userAsset = xhUserAssetService::getByUserId($userId);
 		$level = $userAsset['member'];
 		if ($level > 0) {
-			$gradeList = xhMerchantExtendService::getGradeList($this->merchantExtend);
+			$gradeList = xhMerchantExtendService::getGradeList($this->sjExtend);
 			$discount = $gradeList[$level]['discount'];
 			$discount = strlen($discount) == 1 ? $discount * 10 : $discount;
 			$totalFee = number_format($discount * $totalFee / 100, 2);
@@ -167,7 +167,7 @@ class PayController extends BaseController
 		//来源 0自建商城 1门店 2微信朋友圈 3淘宝
 		$sourceType = isset($post['sourceType']) ? $post['sourceType'] : 0;
 		$shopInfo = xhShop::find()->where(['id' => $shopId])->one();
-		if (empty($shopInfo) || $shopInfo->merchantId != $this->merchantId) {
+		if (empty($shopInfo) || $shopInfo->sjId != $this->sjId) {
 			util::fail('门店无效');
 		}
 		
@@ -177,9 +177,9 @@ class PayController extends BaseController
 		
 		$userAsset = xhUserAssetService::getByUserId($this->userId);
 		$level = isset($userAsset['member']) ? $userAsset['member'] : 0;
-		$merchantExtend = xhMerchantExtendService::getByMerchantId($this->merchantId);
-		$memberIntegral = xhMerchantExtendService::getGradeList($merchantExtend, 'desc');
-		Yii::info(json_encode($merchantExtend));
+		$sjExtend = xhMerchantExtendService::getByMerchantId($this->sjId);
+		$memberIntegral = xhMerchantExtendService::getGradeList($sjExtend, 'desc');
+		Yii::info(json_encode($sjExtend));
 		Yii::info(json_encode($memberIntegral));
 		//$discount = isset($memberIntegral[$level]['discount']) ? $memberIntegral[$level]['discount'] : $memberIntegral[$level]['discount'];
 		$discount = 0;
@@ -201,7 +201,7 @@ class PayController extends BaseController
 		}
 		$post['actPrice'] = $actPrice;
 		$post['payStyle'] = 0;
-		$post['merchantId'] = $this->merchantId;
+		$post['merchantId'] = $this->sjId;
 		$now = time();
 		$expireTime = $now + 1800;//订单30分钟后过期
 		$post['createTime'] = date("Y-m-d H:i:s", $now);
@@ -229,7 +229,7 @@ class PayController extends BaseController
 			$post['modPriceStatus'] = 1;//微信已经提交不能再修改价格
 		}
 		$post['sourceType'] = $sourceType;
-		$post['id'] = stringUtil::generateOrderNo($this->merchantId, $this->userId);
+		$post['id'] = stringUtil::generateOrderNo($this->sjId, $this->userId);
 		$payment = xhOrderService::add($post);
 		$orderId = $payment['id'];
 
@@ -241,7 +241,7 @@ class PayController extends BaseController
 		if ($this->isWx) {
 			$userId = $post['userId'];
 			$user = xhUserService::getById($userId);
-			if ($user['merchantId'] != $this->merchantId) {
+			if ($user['merchantId'] != $this->sjId) {
 				util::fail('非法用户');
 			}
 			$openId = $user['openId'];
@@ -263,7 +263,7 @@ class PayController extends BaseController
 			
 			
 			//服务商 代设置微信支付,要添加的参数设置
-			if ($this->merchantExtend['wxPayApply'] == 1) {
+			if ($this->sjExtend['wxPayApply'] == 1) {
 				//$input->SetOpenid($openId);
 				$input->SetSub_openid($openId);
 				//自设置 微信支付
@@ -271,9 +271,9 @@ class PayController extends BaseController
 				$input->SetOpenid($openId);
 			}
 			
-			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->merchantExtend);
+			$wxOrder = \WxPayApi::unifiedOrder($input, 6, $this->sjExtend);
 			$tools = new \JsApiPay();
-			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->merchantExtend);
+			$jsApiParameters = $tools->GetJsApiParameters($wxOrder, $this->sjExtend);
 			$newParams = json_decode($jsApiParameters, true);
 			$newParams['orderId'] = $orderId;
 			util::success($newParams);

+ 2 - 2
app-mall/controllers/PaymentController.php

@@ -34,7 +34,7 @@ class PaymentController extends MobileendController
         $payAdd['payStyle']		= dict::getConfig('payStyle','wxPay');
         $payAdd['payStatus']	= 0;
         $payAdd['userId']		= 0; //订单所有者(默认为0,未定) $this->userId
-        $payAdd['merchantId']	= $this->merchantId;
+        $payAdd['merchantId']	= $this->sjId;
         $payAdd['createTime']	= date("Y-m-d H:i:s", $now);
         $payAdd['deadline']		= $expireTime;
         xhOrderService::formatPost($payAdd, $post);
@@ -42,7 +42,7 @@ class PaymentController extends MobileendController
         $payAdd['actPrice']		= $amount;
         $order = xhOrderService::add($payAdd);
         $payId = $order['id'];
-		return $this->renderPartial('orderGenerate', ['payId'=>$payId, 'goodName'=>$post['orderName'], 'price'=>$post['price'], 'logo'=>$this->merchant['logo']]);
+		return $this->renderPartial('orderGenerate', ['payId'=>$payId, 'goodName'=>$post['orderName'], 'price'=>$post['price'], 'logo'=>$this->sj['logo']]);
 	}
 
 }

+ 4 - 6
app-mall/controllers/PublicController.php

@@ -15,18 +15,16 @@ class PublicController extends baseController
     public $webTitle = '花卉宝';
     public $webDescription = '花卉宝';
     public $webKeyword = '花卉宝';
-    public $version;//公共静态文件版本号
-    public $merchant, $merchantId;
+    public $version;
+    public $sjWx, $shopId = 0;
 
     public function beforeAction($action)
     {
         $this->version = '1.0.0';
         $header = httpUtil::getHeader();
         $account = isset($header['account']) ? $header['account'] : 0;
-
-        $this->merchantId = $account;
-        $this->merchant = WxOpenClass::getMallWxInfo();
-
+        $this->shopId = $account;
+        $this->sjWx = WxOpenClass::getMallWxInfo();
         return parent::beforeAction($action);
     }
 

+ 6 - 6
app-mall/controllers/RechargeController.php

@@ -16,9 +16,9 @@ class RechargeController extends BaseController
 	public function actionLaunch()
 	{
 		$rechargeAmount = Yii::$app->request->get('amount', 1);
-		$account = $this->merchantId;
-		$merchant = $this->merchant;
-		$extend = $this->merchantExtend;
+		$account = $this->sjId;
+		$sj = $this->sj;
+		$extend = $this->sjExtend;
 		$user = $this->user;
 		ini_set('date.timezone', 'Asia/Shanghai');
 		if ($rechargeAmount <= 0) {
@@ -29,7 +29,7 @@ class RechargeController extends BaseController
 		$rechargeData['userId'] = $userId;
 		$rechargeData['actPrice'] = $rechargeAmount;
 		$rechargeData['payStyle'] = 0;
-		$rechargeData['merchantId'] = $merchant['id'];
+		$rechargeData['merchantId'] = $sj['id'];
 		$now = time();
 		$expireTime = $now + 300;//订单5分钟后过期
 		$rechargeData['createTime'] = date("Y-m-d H:i:s", $now);
@@ -41,7 +41,7 @@ class RechargeController extends BaseController
 		$orderId = $payment['id'];
 		$orderSn = $payment['orderSn'];
 		
-		UserService::updateVisitTime($merchantId, $userId);
+		UserService::updateVisitTime($sjId, $userId);
 
 		$totalFee = $rechargeAmount;
 		$name = '充值' . $totalFee . '元';
@@ -82,7 +82,7 @@ class RechargeController extends BaseController
 		}
 		//小程序使用miniAppId
 		if(httpUtil::isMiniProgram()){
-			$merchantExtend['wxAppId'] = $merchantExtend['miniAppId'];
+			$sjExtend['wxAppId'] = $sjExtend['miniAppId'];
 		}
 
 		$wxOrder = \WxPayApi::unifiedOrder($input, 6, $extend);

+ 3 - 3
app-mall/controllers/ShopController.php

@@ -20,9 +20,9 @@ class ShopController extends BaseController
 	public function actionDetail()
 	{
 		$introUserId = Yii::$app->request->get('introUserId');
-		$merchant = $this->merchant;
-		$shop = ShopService::getDefaultShop($merchant);
-		$ad = AdService::getValidAdList($this->merchantId);
+		$sj = $this->sj;
+		$shop = ShopService::getDefaultShop($sj);
+		$ad = AdService::getValidAdList($this->sjId);
 		
 		//新人专享礼物
 		$newUserGift = [];

+ 1 - 1
app-mall/controllers/UploadController.php

@@ -8,7 +8,7 @@ use common\components\util;
 class UploadController extends BaseController
 {
 	
-	public $withoutLogin = [];
+	public $guestAccessAction = [];
 	
 	//上传图片接口
 	public function actionSaveImg()

+ 174 - 175
app-mall/controllers/UserController.php

@@ -2,6 +2,7 @@
 
 namespace mall\controllers;
 
+use bizHd\custom\classes\CustomClass;
 use bizMall\merchant\services\MerchantExtendService;
 use bizMall\message\services\SmsService;
 use bizMall\user\classes\UserClass;
@@ -14,179 +15,177 @@ use yii\helpers\Json;
 
 class UserController extends BaseController
 {
-	
-	//获取登陆客户的资产 shish 2019.11.22
-	public function actionAsset()
-	{
-		$asset = UserAssetService::getByUserId($this->userId);
-		util::success($asset);
-	}
-	
-	//获取登陆客户的优惠情况  shish 2019.12.3
-	public function actionDiscount()
-	{
-		$discount = UserAssetService::getDiscount($this->userId);
-		util::success($discount);
-	}
-	
-	//小程序用户完整信息 shish 2019.12.12
-	public function actionMiniFullInfo()
-	{
-		$post = Yii::$app->request->post();
-		$iv = isset($post['iv']) ? $post['iv'] : '';
-		$encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
-		$appId = $this->merchant['miniAppId'];
-		$merchantId = $this->merchantId;
-		$miniOpenId = $this->user['miniOpenId'];
-		if (empty($miniOpenId)) {
-			util::fail('mini_open_id empty');
-		}
-		$cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
-		$sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-		$wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
-		require_once($wxMiniSecret . '/wxBizDataCrypt.php');
-		$pc = new \WXBizDataCrypt($appId, $sessionKey);
-		$errCode = $pc->decryptData($encryptedData, $iv, $result);
-		if ($errCode != 0) {
-			Yii::info($result . ' ' . $errCode);
-			util::fail('获取用户信息失败');
-		}
-		Yii::info('小程序获取用户信息:' . $result);
-		$originalInfo = Json::decode($result);
-		$source = UserClass::$userSourceId['mini']['name'];
-		$user = UserService::replaceUser($originalInfo, $source, $merchantId);
-		$userId = $user['id'];
-		$userInfo = UserService::getUserInfo($userId);
-		util::success($userInfo);
-	}
-	
-	//小程序用户手机号
-	public function actionMiniMobile()
-	{
-		$post = Yii::$app->request->post();
-		$iv = $post['iv'];
-		$encryptedData = $post['encryptedData'];
-		$merchantId = $this->merchantId;
-		$merchant = $this->merchant;
-		$appId = $merchant['miniAppId'];
-		$miniOpenId = $this->user['miniOpenId'];
-		$user = $this->user;
-		if (!empty($user) && !empty($user['mobile'])) {
-			$userId = $user['id'];
-			util::success(['mobile' => $user['mobile']]);
-		}
-		$cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
-		$sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-		if (empty($sessionKey)) {
-			util::fail('系统错误,sesstion empty');
-		}
-		$wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
-		require_once($wxMiniSecret . '/wxBizDataCrypt.php');
-		
-		$pc = new \WXBizDataCrypt($appId, $sessionKey);
-		$errCode = $pc->decryptData($encryptedData, $iv, $result);
-		if ($errCode != 0) {
-			util::fail('解密失败');
-		}
-		$arr = Json::decode($result);
-		$mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
-		if (empty($mobile)) {
-			util::fail('没有获取手机号,请重试');
-		}
-		$userId = $user['id'];
-		UserService::becomeMember($user, $merchant, ['mobile' => $mobile]);
-		util::success(['mobile' => $mobile]);
-	}
-	
-	//密码修改
-	public function actionPassword()
-	{
-		$post = Yii::$app->request->post();
-		$old = isset($post['old']) ? $post['old'] : '';
-		$new = isset($post['new']) ? $post['new'] : '';
-		$confirm = isset($post['confirm']) ? $post['confirm'] : '';
-		if (empty($new)) {
-			util::fail('请输入新密码');
-		}
-		if ($new != $confirm) {
-			util::fail('二次密码不一致');
-		}
-		$userId = $this->userId;
-		$user = UserService::getUserInfo($userId, false);
-		if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
-			if (empty($old)) {
-				util::fail('请填写旧密码');
-			}
-			if (password_verify($old, $user['payPassword']) == false) {
-				util::fail('旧密码错误');
-			}
-		}
-		UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
-		util::complete('修改成功');
-	}
-	
-	//申请会员 shish 2019.12.18
-	public function actionApplyMember()
-	{
-		$post = Yii::$app->request->post();
-		$mobile = isset($post['mobile']) ? $post['mobile'] : 0;
-		if (stringUtil::isMobile($mobile) == false) {
-			util::fail('请输入手机号');
-		}
-		$userId = $this->userId;
-		$asset = UserAssetService::getByUserId($userId);
-		if (isset($asset['member']) && $asset['member'] != -1) {
-			util::fail('已经是会员了');
-		}
-		$code = isset($post['code']) ? $post['code'] : '';
-		$cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
-		if (empty($cacheCode) || $cacheCode != $code) {
-			util::fail('验证码错误');
-		}
-		$update = [];
-		if (isset($post['realName']) && !empty($post['realName'])) {
-			$update['realName'] = $post['realName'];
-		}
-		if (isset($post['birthday']) && !empty($post['birthday'])) {
-			$update['birthday'] = $post['birthday'];
-		}
-		$user = UserService::getByCondition(['merchantId' => $this->merchantId, 'mobile' => $mobile]);
-		if ($userId == $user['id']) {
-			util::fail('手机号已验证');
-		}
-		if (!empty($user)) {
-			util::fail('手机号已经注册过了');
-		}
-		$update['mobile'] = $mobile;
-		UserService::becomeMember($this->user, $this->merchant, $update);
-		util::complete('注册成功');
-	}
-	
-	//用户基本信息和资产 shish 2019.12.19
-	public function actionMyProfile()
-	{
-		$user = UserService::getUserInfo($this->userId);
-		$growth = $user['userAsset']['growth'];
-		$extend = $this->merchantExtend;
-		$grade = MerchantExtendService::getGradeList($extend, 'asc');
-		//下个等级的积分
-		$nextLevelGrowth = 0;
-		foreach ($grade as $val) {
-			$currentGrowth = $val['growth'];
-			if ($currentGrowth > $growth) {
-				$nextLevelGrowth = $currentGrowth;
-				break;
-			}
-		}
-		$user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
-		util::success($user);
-	}
-	
-	//登陆客户的信息 shish 2020.3.12
-	public function actionLoginDetail()
-	{
-		$user = $this->user;
-		util::success($user);
-	}
-	
+
+    //获取登陆客户的资产 shish 2019.11.22
+    public function actionAsset()
+    {
+        $asset = UserAssetService::getByUserId($this->userId);
+        util::success($asset);
+    }
+
+    //获取登陆客户的优惠情况  shish 2019.12.3
+    public function actionDiscount()
+    {
+        $discount = UserAssetService::getDiscount($this->userId);
+        util::success($discount);
+    }
+
+    //小程序用户完整信息 shish 2019.12.12
+    public function actionMiniFullInfo()
+    {
+        $post = Yii::$app->request->post();
+        $iv = isset($post['iv']) ? $post['iv'] : '';
+        $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
+        $appId = $this->sj['miniAppId'];
+        $sjId = $this->sjId;
+        $miniOpenId = $this->user['miniOpenId'];
+        if (empty($miniOpenId)) {
+            util::fail('mini_open_id empty');
+        }
+        $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
+        $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
+        require_once($wxMiniSecret . '/wxBizDataCrypt.php');
+        $pc = new \WXBizDataCrypt($appId, $sessionKey);
+        $errCode = $pc->decryptData($encryptedData, $iv, $result);
+        if ($errCode != 0) {
+            Yii::info($result . ' ' . $errCode);
+            util::fail('获取用户信息失败');
+        }
+        Yii::info('小程序获取用户信息:' . $result);
+        $originalInfo = Json::decode($result);
+        $source = UserClass::$userSourceId['mini']['name'];
+        $user = UserClass::replaceUser($originalInfo, $source, $sjId);
+        $userId = $user['id'];
+        $userInfo = UserService::getUserInfo($userId);
+        util::success($userInfo);
+    }
+
+    //小程序用户手机号
+    public function actionMiniMobile()
+    {
+        $post = Yii::$app->request->post();
+        $iv = $post['iv'];
+        $encryptedData = $post['encryptedData'];
+        $sjWx = $this->sjWx;
+        $appId = $sjWx['miniAppId'];
+        $user = $this->user;
+        $miniOpenId = $user['miniOpenId'];
+        $customId = $this->customId;
+        $info = CustomClass::getCustomInfo($customId);
+        if (isset($info['mobile']) && !empty($info['mobile'])) {
+            util::success(['mobile' => $info['mobile']]);
+        }
+        $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
+        $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+        if (empty($sessionKey)) {
+            util::fail('系统错误,session empty');
+        }
+        $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
+        require_once($wxMiniSecret . '/wxBizDataCrypt.php');
+        $pc = new \WXBizDataCrypt($appId, $sessionKey);
+        $errCode = $pc->decryptData($encryptedData, $iv, $result);
+        if ($errCode != 0) {
+            util::fail('解密失败');
+        }
+        $arr = Json::decode($result);
+        $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
+        if (empty($mobile)) {
+            util::fail('没有取到手机号,请重试');
+        }
+        CustomClass::updateCustomInfo($info, ['mobile' => $mobile]);
+        util::success(['mobile' => $mobile]);
+    }
+
+    //密码修改
+    public function actionPassword()
+    {
+        $post = Yii::$app->request->post();
+        $old = isset($post['old']) ? $post['old'] : '';
+        $new = isset($post['new']) ? $post['new'] : '';
+        $confirm = isset($post['confirm']) ? $post['confirm'] : '';
+        if (empty($new)) {
+            util::fail('请输入新密码');
+        }
+        if ($new != $confirm) {
+            util::fail('二次密码不一致');
+        }
+        $userId = $this->userId;
+        $user = UserService::getUserInfo($userId, false);
+        if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
+            if (empty($old)) {
+                util::fail('请填写旧密码');
+            }
+            if (password_verify($old, $user['payPassword']) == false) {
+                util::fail('旧密码错误');
+            }
+        }
+        UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
+        util::complete('修改成功');
+    }
+
+    //申请会员 shish 2019.12.18
+    public function actionApplyMember()
+    {
+        $post = Yii::$app->request->post();
+        $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
+        if (stringUtil::isMobile($mobile) == false) {
+            util::fail('请输入手机号');
+        }
+        $userId = $this->userId;
+        $asset = UserAssetService::getByUserId($userId);
+        if (isset($asset['member']) && $asset['member'] != -1) {
+            util::fail('已经是会员了');
+        }
+        $code = isset($post['code']) ? $post['code'] : '';
+        $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
+        if (empty($cacheCode) || $cacheCode != $code) {
+            util::fail('验证码错误');
+        }
+        $update = [];
+        if (isset($post['realName']) && !empty($post['realName'])) {
+            $update['realName'] = $post['realName'];
+        }
+        if (isset($post['birthday']) && !empty($post['birthday'])) {
+            $update['birthday'] = $post['birthday'];
+        }
+        $user = UserService::getByCondition(['merchantId' => $this->sjId, 'mobile' => $mobile]);
+        if ($userId == $user['id']) {
+            util::fail('手机号已验证');
+        }
+        if (!empty($user)) {
+            util::fail('手机号已经注册过了');
+        }
+        $update['mobile'] = $mobile;
+        UserService::becomeMember($this->user, $this->sj, $update);
+        util::complete('注册成功');
+    }
+
+    //用户基本信息和资产 shish 2019.12.19
+    public function actionMyProfile()
+    {
+        $user = UserService::getUserInfo($this->userId);
+        $growth = $user['userAsset']['growth'];
+        $extend = $this->sjExtend;
+        $grade = MerchantExtendService::getGradeList($extend, 'asc');
+        //下个等级的积分
+        $nextLevelGrowth = 0;
+        foreach ($grade as $val) {
+            $currentGrowth = $val['growth'];
+            if ($currentGrowth > $growth) {
+                $nextLevelGrowth = $currentGrowth;
+                break;
+            }
+        }
+        $user['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
+        util::success($user);
+    }
+
+    //登陆客户的信息 shish 2020.3.12
+    public function actionLoginDetail()
+    {
+        $user = $this->user;
+        util::success($user);
+    }
+
 }

+ 2 - 2
app-mall/controllers/WxShareController.php

@@ -14,8 +14,8 @@ class WxShareController extends BaseController
 	{
 		$url = Yii::$app->request->post('url');
 		$jsSDK = new jsSDK();//微信分享
-		$merchant = $this->merchant;
-		$return = $jsSDK->GetSignPackage($merchant, $url);
+		$sj = $this->sj;
+		$return = $jsSDK->GetSignPackage($sj, $url);
 		util::success($return);
 	}
 

+ 128 - 94
biz-hd/custom/classes/CustomClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\custom\classes;
 
 use bizHd\admin\classes\AdminClass;
+use bizMall\user\classes\UserClass;
 use common\components\stringUtil;
 use common\components\util;
 use Yii;
@@ -10,98 +11,131 @@ use bizHd\base\classes\BaseClass;
 
 class CustomClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizHd\custom\models\Custom';
-	
-	//创建获取客户信息 shish 2021.3.19
-	public static function replaceCustom($sjId, $admin)
-	{
-		$adminId = $admin['id'];
-		$cacheKey = "custom_info_{$sjId}_{$adminId}";
-		$id = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
-		if (!empty($id)) {
-			$info = self::getCustomInfo($id);
-			if (!empty($info)) {
-				return $info;
-			}
-		}
-		$name = $admin['adminName'] ?? '';
-		$mobile = $admin['mobile'] ?? '';
-		$py = stringUtil::getSpelling($name);
-		$visitTime = date("Y-m-d H:i:s");
-		$data = [
-			'adminId' => $adminId,
-			'sjId' => $sjId,
-			'name' => $name,
-			'py' => $py,
-			'mobile' => $mobile,
-			'visitTime' => $visitTime,
-		];
-		$info = self::addCustom($data);
-		$id = $info['id'] ?? 0;
-		Yii::$app->redis->executeCommand('SET', [$cacheKey, $id]);
-		return $info;
-	}
-	
-	//获取客户信息
-	public static function getCustom($data)
-	{
-		$custom = self::getByCondition($data);
-		if (empty($custom)) {
-			$custom = self::add($data);
-		}
-		return $custom;
-	}
-	
-	//获取客户信息 shish 2021.2.1
-	public static function getCustomInfo($id)
-	{
-		$custom = self::getById($id);
-		if (empty($custom)) {
-			return $custom;
-		}
-		$list = self::groupBaseInfo([$custom]);
-		return current($list);
-	}
-	
-	//获取客户信息 shish 2021.3.19
-	public static function getCustomByIds($ids)
-	{
-		$list = self::getByIds($ids);
-		$list = self::groupBaseInfo($list);
-		return $list;
-	}
-	
-	public static function valid($info, $sjId)
-	{
-		if (isset($info['sjId']) && $info['sjId'] == $sjId) {
-			return true;
-		}
-		util::fail('客户信息无效');
-	}
-	
-	//整合基本信息 shish 2021.1.31
-	public static function groupBaseInfo($list)
-	{
-		if (empty($list)) {
-			return $list;
-		}
-		
-		$adminIds = array_column($list, 'adminId');
-		$adminInfo = AdminClass::getByIds($adminIds, null, 'id');
-		
-		foreach ($list as $key => $val) {
-			$adminId = $val['adminId'];
-			$subscribe = $adminInfo[$adminId]['subscribe'] ?? 0;
-			$list[$key]['subscribe'] = $subscribe;
-		}
-		return $list;
-	}
-	
-	//添加客户 shish 2021.2.28
-	public static function addCustom($data)
-	{
-		return self::add($data);
-	}
-	
+
+    public static $baseFile = '\bizHd\custom\models\Custom';
+
+    public static function getCustomCacheKey($sjId, $userId)
+    {
+        return 'hd_custom_key_' . $sjId . '_' . $userId;
+    }
+
+    public static function getCurrentCustomId($sjId, $user)
+    {
+        $userId = $user['id'];
+        $key = self::getCustomCacheKey($sjId, $userId);
+        $currentId = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (!empty($currentId)) {
+            return $currentId;
+        }
+        $info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
+        if (!empty($info)) {
+            return $info['id'];
+        }
+        return 0;
+    }
+
+    //创建获取客户信息 shish 2021.3.19
+    public static function replaceCustom($sjId, $user)
+    {
+        $userId = $user['id'];
+        $name = $user['userName'] ?? '';
+        $mobile = $user['mobile'] ?? '';
+        $key = self::getCustomCacheKey($sjId, $userId);
+        $currentId = Yii::$app->redis->executeCommand('GET', [$key]);
+        if (!empty($currentId)) {
+            return $currentId;
+        }
+        $info = self::getByCondition(['sjId' => $sjId, 'userId' => $userId]);
+        if (empty($info)) {
+            $py = stringUtil::getSpelling($name);
+            $visitTime = date("Y-m-d H:i:s");
+            $data = [
+                'userId' => $userId,
+                'sjId' => $sjId,
+                'name' => $name,
+                'py' => $py,
+                'mobile' => $mobile,
+                'visitTime' => $visitTime,
+            ];
+            $info = self::addCustom($data);
+        }
+        $id = $info['id'];
+        Yii::$app->redis->executeCommand('SET', [$key, $id]);
+        return $id;
+    }
+
+    //获取客户信息
+    public static function getCustom($data)
+    {
+        $custom = self::getByCondition($data);
+        if (empty($custom)) {
+            $custom = self::add($data);
+        }
+        return $custom;
+    }
+
+    //获取客户信息 shish 2021.2.1
+    public static function getCustomInfo($id)
+    {
+        $custom = self::getById($id);
+        if (empty($custom)) {
+            return $custom;
+        }
+        $list = self::groupBaseInfo([$custom]);
+        return current($list);
+    }
+
+    //获取客户信息 shish 2021.3.19
+    public static function getCustomByIds($ids)
+    {
+        $list = self::getByIds($ids);
+        $list = self::groupBaseInfo($list);
+        return $list;
+    }
+
+    public static function valid($info, $sjId)
+    {
+        if (isset($info['sjId']) && $info['sjId'] == $sjId) {
+            return true;
+        }
+        util::fail('客户信息无效');
+    }
+
+    //整合基本信息 shish 2021.1.31
+    public static function groupBaseInfo($list)
+    {
+        if (empty($list)) {
+            return $list;
+        }
+        $userIds = array_column($list, 'adminId');
+        $userInfo = AdminClass::getByIds($userIds, null, 'id');
+        foreach ($list as $key => $val) {
+            $userId = $val['adminId'];
+            $subscribe = $userInfo[$userId]['subscribe'] ?? 0;
+            $list[$key]['subscribe'] = $subscribe;
+        }
+        return $list;
+    }
+
+    //添加客户 shish 2021.2.28
+    public static function addCustom($data)
+    {
+        return self::add($data);
+    }
+
+    //更新客户信息 shish 2021.3.23
+    public static function updateCustomInfo($custom, $data)
+    {
+        $userId = $custom['userId'];
+        $userData = [];
+        if (isset($data['mobile']) && !empty($data['mobile'])) {
+            $userData['mobile'] = $data['mobile'];
+        }
+        if (!empty($userData)) {
+            UserClass::updateById($userId, $userData);
+        }
+        $id = $custom['id'];
+        self::updateById($id, $data);
+    }
+
 }

+ 6 - 1
biz-mall/user/classes/UserClass.php

@@ -2,6 +2,7 @@
 
 namespace bizMall\user\classes;
 
+use bizHd\custom\classes\CustomClass;
 use bizMall\merchant\classes\MerchantAssetClass;
 use bizMall\merchant\classes\MerchantClass;
 use bizMall\merchant\services\MerchantService;
@@ -486,7 +487,7 @@ class UserClass extends BaseClass
     }
 
     //创建以及更新用户 shish 2020.2.7
-    public static function replaceUser($userInfo, $source)
+    public static function replaceUser($userInfo, $source, $sjId)
     {
         $userInfo = self::switchUserInfo($userInfo, $source);
         $unionId = isset($userInfo['unionId']) && !empty($userInfo['unionId']) ? $userInfo['unionId'] : '';
@@ -542,6 +543,10 @@ class UserClass extends BaseClass
                 $user = self::generateUser($userInfo);
             }
         }
+        if (!empty($sjId)) {
+            //创建客户信息
+            CustomClass::replaceCustom($sjId, $user);
+        }
         return $user;
     }
 

+ 1 - 7
biz-mall/user/services/UserService.php

@@ -57,13 +57,7 @@ class UserService extends BaseService
 	{
 		return UserClass::getByMobile($mobile, $merchantId);
 	}
-	
-	//添加更新客户 shish 2020.2.7
-	public static function replaceUser($userInfo, $source)
-	{
-		return UserClass::replaceUser($userInfo, $source);
-	}
-	
+
 	public static function getByOpenId($openId, $merchantId)
 	{
 		return UserClass::getByOpenId($openId, $merchantId);

+ 3 - 1
sql.sql

@@ -1705,4 +1705,6 @@ TRUNCATE `xhUserPast`;
 TRUNCATE `xhUserTag`;
 TRUNCATE `xhUserTagClass`;
 TRUNCATE `xhUserUpgrade`;
-ALTER TABLE xhUser DROP COLUMN `merchantId`;
+ALTER TABLE xhUser DROP COLUMN `merchantId`;
+ALTER TABLE xhCustom CHANGE `adminId` `userId` INT(11) NOT NULL DEFAULT '0' COMMENT '用户id';
+ALTER TABLE xhCustom ADD UNIQUE INDEX custom(`sjId`,`userId`);