Sfoglia il codice sorgente

二个平台兼容

shish 5 anni fa
parent
commit
c6d5707ad7

+ 190 - 189
app/ghs/controllers/AuthController.php

@@ -27,193 +27,194 @@ 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'];
-        $admin = AdminService::getByCondition(['userId' => $userId]);
-        if (empty($admin)) {
-            util::fail('您没有权限访问');
-        }
-        $adminId = $admin['id'];
-        //获取token
-        $token = jwt::getNewToken($adminId);
-        $url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
-        $this->redirect($url);
-    }
-
-    //登陆并拿到token shish 2019.11.23
-    public function actionLogin()
-    {
-        $get = Yii::$app->request->get();
-        $mobile = isset($get['mobile']) ? $get['mobile'] : 0;
-        if (stringUtil::isMobile($mobile) == false) {
-            util::fail('请填写正常的手机号');
-        }
-        $password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
-        if (empty($password)) {
-            util::fail('请输入密码');
-        }
-        $admin = AdminService::getByCondition(['mobile' => $mobile]);
-        if (password_verify($password, $admin['password']) == false) {
-            util::fail('密码错误');
-        }
-        $adminId = $admin['id'];
-        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId]);
-        $merchantId = isset($shopAdmin['merchantId']) ? $shopAdmin['merchantId'] : 0;
-        $shopId = isset($shopAdmin['shopId']) ? $shopAdmin['shopId'] : 0;
-        if (empty($shopId)) {
-            util::fail('您不是管理员');
-        }
-        //管理员关联门店
-        Yii::$app->redis->executeCommand('SET', ['LOGIN_ADMIN_SHOP' . $adminId, $shopId]);
-        //获取token
-        $token = jwt::getNewToken($adminId);
-        util::success(['token' => $token, 'account' => $merchantId, 'shopId' => $shopId]);
-    }
-
-    //静默获取小程序用户信息
-    public function actionMiniInfo()
-    {
-        $code = Yii::$app->request->get('code', '');
-        if (empty($code)) {
-            util::fail('没有CODE信息');
-        }
-        $wxMiniBase = WxOpenClass::getGhsWxInfo();
-        $appId = $wxMiniBase['miniAppId'];
-        $appSecret = $wxMiniBase['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'] : '';
-        $openid = isset($arr['openid']) ? $arr['openid'] : '';
-        if (empty($openid)) {
-            Yii::info(json_encode($arr));
-            util::fail('没有获取到小程序openId');
-        }
-        $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
-        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-        //用户来源
-        $userSource = UserClass::$userSourceId['mini']['name'];
-        $admin = AdminService::getByMiniOpenId($openid);
-        if (empty($admin)) {
-            $adminInfo = ['miniOpenId' => $openid];
-            $admin = AdminService::replaceAdmin($adminInfo, $userSource);
-        }
-        $adminId = $admin['id'];
-        $currentShopId = $admin['currentShopId'] ?? 0;
-        //员工id
-        $shopAdminId = 0;
-        if (!empty($currentShopId)) {
-            $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId]);
-            $shopAdminId = $shopAdmin['id'] ?? 0;
-        }
-        $admin['avatar'] = Yii::$app->params['imgHost'] . '/retail/default-img.png';
-        $token = jwt::getNewToken($adminId);
-
-        util::success(['token' => $token, 'admin' => $admin, 'shopAdminId' => $shopAdminId, 'shopId' => $currentShopId,]);
-    }
-
+	
+	//准备授权 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
+		$isOpen = 2;
+		wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
+		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, 2);
+		if ($data === false) {
+			//微信授权获取code shish 2019.11.24
+			wxUtil::getCode($urlEncode, $merchant, $authScope, 2);
+			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'];
+		$admin = AdminService::getByCondition(['userId' => $userId]);
+		if (empty($admin)) {
+			util::fail('您没有权限访问');
+		}
+		$adminId = $admin['id'];
+		//获取token
+		$token = jwt::getNewToken($adminId);
+		$url = strpos($url, '?') === false ? $url . '?token=' . $token : $url . '&token=' . $token;
+		$this->redirect($url);
+	}
+	
+	//登陆并拿到token shish 2019.11.23
+	public function actionLogin()
+	{
+		$get = Yii::$app->request->get();
+		$mobile = isset($get['mobile']) ? $get['mobile'] : 0;
+		if (stringUtil::isMobile($mobile) == false) {
+			util::fail('请填写正常的手机号');
+		}
+		$password = isset($get['password']) && !empty($get['password']) ? $get['password'] : '';
+		if (empty($password)) {
+			util::fail('请输入密码');
+		}
+		$admin = AdminService::getByCondition(['mobile' => $mobile]);
+		if (password_verify($password, $admin['password']) == false) {
+			util::fail('密码错误');
+		}
+		$adminId = $admin['id'];
+		$shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId]);
+		$merchantId = isset($shopAdmin['merchantId']) ? $shopAdmin['merchantId'] : 0;
+		$shopId = isset($shopAdmin['shopId']) ? $shopAdmin['shopId'] : 0;
+		if (empty($shopId)) {
+			util::fail('您不是管理员');
+		}
+		//管理员关联门店
+		Yii::$app->redis->executeCommand('SET', ['LOGIN_ADMIN_SHOP' . $adminId, $shopId]);
+		//获取token
+		$token = jwt::getNewToken($adminId);
+		util::success(['token' => $token, 'account' => $merchantId, 'shopId' => $shopId]);
+	}
+	
+	//静默获取小程序用户信息
+	public function actionMiniInfo()
+	{
+		$code = Yii::$app->request->get('code', '');
+		if (empty($code)) {
+			util::fail('没有CODE信息');
+		}
+		$wxMiniBase = WxOpenClass::getGhsWxInfo();
+		$appId = $wxMiniBase['miniAppId'];
+		$appSecret = $wxMiniBase['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'] : '';
+		$openid = isset($arr['openid']) ? $arr['openid'] : '';
+		if (empty($openid)) {
+			Yii::info(json_encode($arr));
+			util::fail('没有获取到小程序openId');
+		}
+		$cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
+		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+		//用户来源
+		$userSource = UserClass::$userSourceId['mini']['name'];
+		$admin = AdminService::getByMiniOpenId($openid);
+		if (empty($admin)) {
+			$adminInfo = ['miniOpenId' => $openid];
+			$admin = AdminService::replaceAdmin($adminInfo, $userSource);
+		}
+		$adminId = $admin['id'];
+		$currentShopId = $admin['currentShopId'] ?? 0;
+		//员工id
+		$shopAdminId = 0;
+		if (!empty($currentShopId)) {
+			$shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId]);
+			$shopAdminId = $shopAdmin['id'] ?? 0;
+		}
+		$admin['avatar'] = Yii::$app->params['imgHost'] . '/retail/default-img.png';
+		$token = jwt::getNewToken($adminId);
+		
+		util::success(['token' => $token, 'admin' => $admin, 'shopAdminId' => $shopAdminId, 'shopId' => $currentShopId,]);
+	}
+	
 }

+ 4 - 3
app/hd/controllers/AuthController.php

@@ -53,7 +53,8 @@ class AuthController extends PublicController
 		$authScope = isset($get['authScope']) ? $get['authScope'] : 'snsapi_base';
 		$urlEncode = stringUtil::urlSafeB64Encode($url);
 		//微信授权获取code shish 2019.11.24
-		wxUtil::getCode($urlEncode, $merchant, $authScope);
+		$isOpen = 1;
+		wxUtil::getCode($urlEncode, $merchant, $authScope, $isOpen);
 		util::end();
 	}
 	
@@ -83,10 +84,10 @@ class AuthController extends PublicController
 		if (empty($authScope)) {
 			util::stop('没有授权类型');
 		}
-		$data = wxUtil::getOpenId($code, $merchant);
+		$data = wxUtil::getOpenId($code, $merchant, 1);
 		if ($data === false) {
 			//微信授权获取code shish 2019.11.24
-			wxUtil::getCode($urlEncode, $merchant, $authScope);
+			wxUtil::getCode($urlEncode, $merchant, $authScope, 1);
 			util::end();
 		}
 		$openId = $data['openid'];

+ 48 - 46
app/pt/config/main.php

@@ -1,54 +1,56 @@
 <?php
 $params = array_merge(
-    require(__DIR__ . '/../../../common/config/params.php'),
-    require(__DIR__ . '/../../../common/config/params-local.php'),
-    require(__DIR__ . '/params.php'),
-    require(__DIR__ . '/params-local.php')
+	require(__DIR__ . '/../../../common/config/params.php'),
+	require(__DIR__ . '/../../../common/config/params-local.php'),
+	require(__DIR__ . '/params.php'),
+	require(__DIR__ . '/params-local.php')
 );
 
 return [
-    'id' => 'app-saas',
-    'basePath' => dirname(__DIR__),
-    'controllerNamespace' => 'pt\controllers',
-    'bootstrap' => ['log'],
-    'defaultRoute' => 'main/index',//默认控制器
-    'modules' => [],
-    'components' => [
-	    'user' => [
-		    'identityClass' => 'common\models\xhWxOpenAdmin',
-		    'enableAutoLogin' => true,
-		    'identityCookie' => [
-		    	'name' => 'ptUser', // unique for platform
-		    ],
-		    'loginUrl' => ['main/login'],
-	    ],
-        'log' => [
-            'traceLevel' => YII_DEBUG ? 3 : 0,
-            'targets' => [
-                [
-                    'class' => 'yii\log\FileTarget',
-                    'levels' => ['error', 'warning'],
-                ],
-            ],
-        ],
-        'errorHandler' => [
-            'errorAction' => 'site/error',
-        ],
-        'urlManager' => [
-            'enablePrettyUrl' => true,
-            'showScriptName' => false,
-            'rules' => [
+	'id' => 'app-saas',
+	'basePath' => dirname(__DIR__),
+	'controllerNamespace' => 'pt\controllers',
+	'bootstrap' => ['log'],
+	'defaultRoute' => 'main/index',//默认控制器
+	'modules' => [],
+	'components' => [
+		'user' => [
+			'identityClass' => 'common\models\xhWxOpenAdmin',
+			'enableAutoLogin' => true,
+			'identityCookie' => [
+				'name' => 'ptUser', // unique for platform
+			],
+			'loginUrl' => ['main/login'],
+		],
+		'log' => [
+			'traceLevel' => YII_DEBUG ? 3 : 0,
+			'targets' => [
+				[
+					'class' => 'yii\log\FileTarget',
+					'levels' => ['error', 'warning'],
+				],
+			],
+		],
+		'errorHandler' => [
+			'errorAction' => 'site/error',
+		],
+		'urlManager' => [
+			'enablePrettyUrl' => true,
+			'showScriptName' => false,
+			'rules' => [
 
-				//供货商 授权事件接收URL的重写
-                'wx-open-api/<style:\w+>' => 'wx-open/api',
+				//花店和供货商 授权事件接收URL style 1 花店 2 供货商
+				'wx-open-api/<style:\w+>' => 'wx-open/api',
 
-                //公众号消息与事件接收地址
-                'wx/<appId:\w+>' => 'wx/api',
-                //公众号授权回调通知地址
-                'wx-open-callback/<id:\w+>' => 'wx-open/callback',
-                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
-            ],
-        ],
-    ],
-    'params' => $params,
+				//公众号消息与事件接收地址 style 1 花店 2 供货商
+				'wx/<style:\w+>/<appId:\w+>' => 'wx/api',
+
+				//公众号授权回调通知地址
+				'wx-open-callback/<id:\w+>' => 'wx-open/callback',
+
+				'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
+			],
+		],
+	],
+	'params' => $params,
 ];

+ 1 - 1
app/pt/controllers/TestController.php

@@ -17,7 +17,7 @@ use common\components\miniUtil;
 
 class TestController extends PublicController
 {
-
+	
     //即时配送
     public function actionGetBindAccount()
     {

File diff suppressed because it is too large
+ 558 - 553
app/pt/controllers/WxController.php


+ 5 - 13
app/pt/controllers/WxOpenController.php

@@ -73,7 +73,7 @@ class WxOpenController extends PublicController
 		
 		$code = $get['auth_code'];
 		//使用授权码换取公众号的接口调用凭据和授权信息
-		$authorize = wxUtil::getAuthorizer($code,$open);
+		$authorize = wxUtil::getAuthorizer($code, $open);
 		if (isset($authorize['authorization_info']) == false) {
 			util::stop('未换取公众号的接口调用凭据和授权信息');
 		}
@@ -83,7 +83,7 @@ class WxOpenController extends PublicController
 		$expires_in = $info['expires_in'];//7200
 		$authorize_refresh_token = $info['authorizer_refresh_token'];
 		//获取授权方的公众号帐号基本信息
-		$authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId,$open);
+		$authorizeDetailInfo = wxUtil::getAuthorizerInfo($authorizeAppId, $open);
 		if (isset($authorizeDetailInfo['authorizer_info']) == false) {
 			util::stop('没有获取到公众号帐号基本信息');
 		}
@@ -201,7 +201,7 @@ class WxOpenController extends PublicController
 				} else {
 				
 				}
-				if(empty($wxBaseId)){
+				if (empty($wxBaseId)) {
 					util::stop('没有公众号信息...');
 				}
 				WxBaseClass::updateById($wxBaseId, [
@@ -275,13 +275,13 @@ class WxOpenController extends PublicController
 					xhMerchantService::updateById($merchantId, ['openAppId' => $openAppId]);
 					MerchantExtendService::updateByCondition(['merchantId' => $merchantId], ['openAppId' => $openAppId, 'openAppBind' => 1, 'wxAuth' => 1]);
 				} elseif ($isOpen == 1) {
-					$open = WxOpenClass::getOpen();
+					$open = WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
 					$wxMiniBaseId = isset($open['wxMiniBaseId']) ? $open['wxMiniBaseId'] : 0;
 					$wxBaseId = isset($open['wxBaseId']) ? $open['wxBaseId'] : 0;
 					WxMiniBaseClass::updateById($wxMiniBaseId, ['openAppId' => $openAppId]);
 					WxBaseClass::updateById($wxBaseId, ['openAppId' => $openAppId]);
 				} elseif ($isOpen == 2) {
-					$open = WxOpenClass::getOpen();
+					$open = WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
 					$wxMiniBaseId = isset($open['wxGhsMiniBaseId']) ? $open['wxGhsMiniBaseId'] : 0;
 					$wxBaseId = isset($open['wxGhsBaseId']) ? $open['wxGhsBaseId'] : 0;
 					WxMiniBaseClass::updateById($wxMiniBaseId, ['openAppId' => $openAppId]);
@@ -519,14 +519,6 @@ class WxOpenController extends PublicController
 		Yii::warning("---wx open data end--- \n");
 	}
 	
-	//获取平台信息 shish 2020.4.12
-	public function actionGetWxOpen()
-	{
-		$open = WxOpenService::getOpen();
-		util::success($open);
-	}
-	
-	
 	//平台没有绑定商家公众号时初始化一个商家 shish 2020.2.11
 	public function actionAddMerchant()
 	{

+ 10 - 7
app/pt/widgets/FooterWidget.php

@@ -1,5 +1,8 @@
 <?php
+
 namespace pt\widgets;
+
+use common\components\util;
 use yii\base\Widget;
 use common\components\configDict;
 use common\services\xhWxOpenService;
@@ -7,17 +10,17 @@ use common\services\xhWxOpenService;
 class FooterWidget extends Widget
 {
 	public $message;
-
+	
 	public function init()
 	{
 		parent::init();
 	}
-
-	public function run()
+	
+	public function run($isOpen)
 	{
-		$openId		= configDict::getConfig('openId');
-		$open		= xhWxOpenService::getById($openId);
-		return $this->render('footer',['open'=>$open]);
+		util::stop('取平台信息方式错误');
+		$open = [];
+		return $this->render('footer', ['open' => $open]);
 	}
-
+	
 }

+ 0 - 6
biz-hd/wx/services/WxOpenService.php

@@ -11,12 +11,6 @@ class WxOpenService extends BaseService
 	
 	public static $baseFile = '\bizHd\wx\classes\WxOpenClass';
 	
-	//获取平台基础信息 shish 2020.2.11
-	public static function getOpen()
-	{
-		return WxOpenClass::getOpen();
-	}
-	
 	public static function updateOpen($data)
 	{
 		return WxOpenClass::updateOpen($data);

+ 0 - 27
biz/sj/services/MerchantService.php

@@ -343,33 +343,6 @@ class MerchantService extends BaseService
         }
     }
 
-    //初始化平台的商家 shish 2020.2.11
-    public static function initOpenMerchant()
-    {
-        $open = WxOpenClass::getOpen();
-        if (isset($open['wxBaseId']) && !empty($open['wxBaseId']) && isset($open['wxMiniBaseId']) && !empty($open['wxMiniBaseId'])) {
-            util::stop('已初始化,无需重复操作');
-        }
-        $env = getenv('YII_ENV');
-        switch ($env) {
-            case 'local':
-                $merchantName = '花美灵';
-                break;
-            case 'dev':
-                $merchantName = '花美灵';
-                break;
-            case 'test':
-                $merchantName = '花掌柜';
-                break;
-            case 'production':
-                $merchantName = '花卉宝';
-                break;
-            default:
-                $merchantName = '花卉宝';
-        }
-        echo $merchantName;
-    }
-
     //获取商家的h5商城二维码 shish 2020.4.30
     public static function getH5MallQrCode($id)
     {

File diff suppressed because it is too large
+ 1760 - 1700
common/components/miniUtil.php


+ 74 - 65
common/components/sms.php

@@ -27,69 +27,78 @@ use Yii;
  */
 class sms
 {
-    //短信服务帐号
-    const ACCOUNT = 'N2890342';
-    //短信服务密码
-    const PASSWORD = 'abc178c7';
-
-    //每个用户每天可以申请的短信数量
-    const LIMIT = 15;
-
-    //商家发短信 shish 2019.12.24
-    public static function merchantSend($mobile, $msg, $merchant)
-    {
-        $merchantId = $merchant['id'];
-        $asset = MerchantAssetService::getByMerchantId($merchantId, true);
-        $remainSmsNum = $asset->remainSmsNum;
-        if ($remainSmsNum <= 0) {
-            Yii::info($merchant['merchantName'] . '短信余额不足');
-            return false;
-        }
-        $asset->remainSmsNum = --$remainSmsNum;
-        $asset->save();
-        self::freeSend($mobile, $msg, $merchant);
-    }
-
-    //自由发短,无ip和数量限制 shish 2019.12.24
-    public static function freeSend($mobile, $msg, $merchant = null)
-    {
-        $open = WxOpenService::getById(1);
-        $name = isset($open['name']) ? $open['name'] : '花卉宝';
-        $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
-        $sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】";
-        $msg .= $sign;
-        $sms->send($mobile, $msg);
-    }
-
-    //发短信,有ip和用户数量限制 shish 2020.2.27
-    public static function send($mobile, $msg, $merchant = null)
-    {
-        $open = WxOpenService::getOpen();
-        $name = isset($open['name']) ? $open['name'] : '花卉宝';
-        $sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
-        $sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】";
-        $msg .= $sign;
-
-        //验证是否有权限发短信
-        $uniqueId = isset($merchant['id']) ? $merchant['id'] : 1;
-        $ip = httpUtil::ip();
-
-        $statusKey = 'SMS_STATUS_' . $uniqueId . '_' . $ip;
-        $hasSend = Yii::$app->redis->executeCommand('GET', [$statusKey]);
-        if (!empty($hasSend)) {
-            util::fail('请60秒后再操作');
-        }
-
-        $todayKey = 'SMS_NUM_' . date("Ymd") . '_' . $uniqueId . '_' . $ip;
-        $num = Yii::$app->redis->executeCommand('GET', [$todayKey]);
-        $num = is_numeric($num) ? $num : 0;
-        if ($num > self::LIMIT) {
-            util::fail('您今天申请的短信条数达到上限');
-        }
-
-        Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
-        Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
-        $sms->send($mobile, $msg);
-    }
-
+	//短信服务帐号
+	const ACCOUNT = 'N2890342';
+	//短信服务密码
+	const PASSWORD = 'abc178c7';
+	
+	//每个用户每天可以申请的短信数量
+	const LIMIT = 15;
+	
+	//商家发短信 shish 2019.12.24
+	public static function merchantSend($mobile, $msg, $merchant)
+	{
+		$merchantId = $merchant['id'];
+		$asset = MerchantAssetService::getByMerchantId($merchantId, true);
+		$remainSmsNum = $asset->remainSmsNum;
+		if ($remainSmsNum <= 0) {
+			Yii::info($merchant['merchantName'] . '短信余额不足');
+			return false;
+		}
+		$asset->remainSmsNum = --$remainSmsNum;
+		$asset->save();
+		self::freeSend($mobile, $msg, $merchant);
+	}
+	
+	//自由发短,无ip和数量限制 shish 2019.12.24
+	public static function freeSend($mobile, $msg, $merchant = null)
+	{
+		$open = WxOpenService::getById(1);
+		$name = isset($open['name']) ? $open['name'] : '花卉宝';
+		$sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
+		$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】";
+		$msg .= $sign;
+		$sms->send($mobile, $msg);
+	}
+	
+	//发短信,有ip和用户数量限制 shish 2020.2.27
+	public static function send($mobile, $msg, $merchant, $isOpen = 1)
+	{
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		$name = isset($open['name']) ? $open['name'] : '花卉宝';
+		$sms = new chuanglanSMS(self::ACCOUNT, self::PASSWORD);
+		$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】";
+		$msg .= $sign;
+		
+		//验证是否有权限发短信
+		$uniqueId = isset($merchant['id']) ? $merchant['id'] : 1;
+		$ip = httpUtil::ip();
+		
+		$statusKey = 'SMS_STATUS_' . $uniqueId . '_' . $ip;
+		$hasSend = Yii::$app->redis->executeCommand('GET', [$statusKey]);
+		if (!empty($hasSend)) {
+			util::fail('请60秒后再操作');
+		}
+		
+		$todayKey = 'SMS_NUM_' . date("Ymd") . '_' . $uniqueId . '_' . $ip;
+		$num = Yii::$app->redis->executeCommand('GET', [$todayKey]);
+		$num = is_numeric($num) ? $num : 0;
+		if ($num > self::LIMIT) {
+			util::fail('您今天申请的短信条数达到上限');
+		}
+		
+		Yii::$app->redis->executeCommand('SETEX', [$statusKey, 60, 'hasSend']);
+		Yii::$app->redis->executeCommand('SETEX', [$todayKey, 86400, ++$num]);
+		$sms->send($mobile, $msg);
+	}
+	
 }

+ 52 - 14
common/components/wxUtil.php

@@ -361,14 +361,24 @@ class wxUtil
 	/**
 	 * 微信授权获取code
 	 */
-	public static function getCode($urlEncode, $merchant, $scope)
+	public static function getCode($urlEncode, $merchant, $scope, $isOpen = 1)
 	{
 		$host = Yii::$app->request->getHostInfo();
 		$REDIRECT_URI = $host . '/auth/get-user-info?url=' . $urlEncode . '&authScope=' . $scope;
 		Yii::info($REDIRECT_URI);
 		$appId = $merchant['wxAppId'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
+		
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		
 		$component_appid = $open['appId'];
 		$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" . $appId . "&redirect_uri=" . urlencode($REDIRECT_URI) . "&response_type=code&scope=" . $scope . "&state=1&component_appid={$component_appid}#wechat_redirect";
 		header("Location:" . $url);
@@ -379,11 +389,22 @@ class wxUtil
 	/**
 	 * 获取openId
 	 */
-	public static function getOpenId($code, $merchant)
+	public static function getOpenId($code, $merchant, $isOpen = 1)
 	{
 		$appId = $merchant['wxAppId'];
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
+		
+		
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		
 		$component_appid = $open['appId'];
 		$componentAccessToken = wxUtil::getComponentAccessToken($open);
 		$url = "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid={$appId}&code={$code}&grant_type=authorization_code&component_appid={$component_appid}&component_access_token={$componentAccessToken}";
@@ -646,8 +667,18 @@ class wxUtil
 	public static function getMiniProgramAccessToken($merchant, $isOpen = 0)
 	{
 		$merchantId = isset($merchant['id']) ? $merchant['id'] : 0;
-		$id = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($id);
+		
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		
 		$component_appid = $open['appId'];
 		$componentAccessToken = wxUtil::getComponentAccessToken($open);
 		$appId = $merchant['miniAppId'];
@@ -681,13 +712,11 @@ class wxUtil
 				$uData['miniAccessToken'] = $miniAccessToken;
 				$uData['miniAccessTokenTime'] = date("Y-m-d H:i:s", (time() + $expires_in - 100));
 				if ($isOpen == 1) {
-					$open = WxOpenService::getOpen();
 					$wxMiniBaseId = isset($open['wxMiniBaseId']) ? $open['wxMiniBaseId'] : 0;
 					if (!empty($wxMiniBaseId)) {
 						WxMiniBaseService::updateById($wxMiniBaseId, $uData);
 					}
 				} elseif ($isOpen == 2) {
-					$open = WxOpenService::getOpen();
 					$wxMiniBaseId = isset($open['wxGhsMiniBaseId']) ? $open['wxGhsMiniBaseId'] : 0;
 					if (!empty($wxMiniBaseId)) {
 						WxMiniBaseService::updateById($wxMiniBaseId, $uData);
@@ -1329,6 +1358,17 @@ class wxUtil
 			$apiUrl = str_replace('http', 'https', $apiUrl);
 		}
 		
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		
 		//如果不是https则换成https
 		$has = strpos($imgUrl, 'https');
 		if ($has === false) {
@@ -1337,12 +1377,10 @@ class wxUtil
 		$account = isset($merchant['id']) ? $merchant['id'] : 0;
 		$name = isset($merchant['merchantName']) ? $merchant['merchantName'] : '';
 		if ($isOpen == 1) {
-			$open = WxOpenService::getOpen();
 			$wxBaseId = isset($open['wxBaseId']) ? $open['wxBaseId'] : 0;
 			$wxBase = WxBaseClass::getById($wxBaseId);
 			$name = isset($wxBase['name']) ? $wxBase['name'] : '';
 		} elseif ($isOpen == 2) {
-			$open = WxOpenService::getOpen();
 			$wxBaseId = isset($open['wxGhsBaseId']) ? $open['wxGhsBaseId'] : 0;
 			$wxBase = WxBaseClass::getById($wxBaseId);
 			$name = isset($wxBase['name']) ? $wxBase['name'] : '';
@@ -1631,7 +1669,7 @@ class wxUtil
 	 * 微信开放平台使用授权码换取公众号的接口调用凭据和授权信息
 	 * authorizer_access_token authorizer_refresh_token
 	 */
-	public static function getAuthorizer($code,$open)
+	public static function getAuthorizer($code, $open)
 	{
 		$appId = $open['appId'];
 		$accessToken = self::getComponentAccessToken($open);
@@ -1644,7 +1682,7 @@ class wxUtil
 	}
 	
 	//微信开放平台获取授权方的公众号帐号基本信息 shish 2020.3.11
-	public static function getAuthorizerInfo($authorizeAppId,$open)
+	public static function getAuthorizerInfo($authorizeAppId, $open)
 	{
 		$appId = $open['appId'];
 		$accessToken = self::getComponentAccessToken($open);

+ 20 - 15
common/services/xhCommonService.php

@@ -1,35 +1,40 @@
 <?php
+
 namespace common\services;
 
+use common\components\util;
 use Yii;
 use common\components\configDict;
 use common\components\chuanglanSMS;
 
-class xhCommonService {
-
+class xhCommonService
+{
+	
 	/**
 	 * 发送短信
 	 * @param $mobile
 	 */
-	public static function sendMobileMsg($mobile,$msg,$merchant=null)
+	public static function sendMobileMsg($mobile, $msg, $merchant = null)
 	{
-		$openId			= configDict::getConfig('openId');
-		$open			= xhWxOpenService::getById($openId);
-		$name		= $open['name'];
-		$sms			= new chuanglanSMS('N2890342','abc178c7');
-		$sign			= isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】"; 
-		$msg			.= $sign;  
-		$result			= $sms->send($mobile,$msg);
+		$open = [];
+		if (empty($open)) {
+			util::fail('取平台信息错误');
+		}
+		$name = $open['name'];
+		$sms = new chuanglanSMS('N2890342', 'abc178c7');
+		$sign = isset($merchant) == true ? "【{$merchant['merchantName']}】" : "【{$name}】";
+		$msg .= $sign;
+		$result = $sms->send($mobile, $msg);
 	}
-
+	
 	/**
 	 * 传入最大的照片,输出三种照片:大 中 小
 	 */
 	public static function getImgList($largeImg)
 	{
-		$extend	= substr($largeImg, strrpos($largeImg, '.')+1);
-		$pre	= substr($largeImg,0,strrpos($largeImg, '.'));
-		return ['small'=>$pre.'_50.'.$extend,'medium'=>$pre.'_200.'.$extend,'large'=>$largeImg];
+		$extend = substr($largeImg, strrpos($largeImg, '.') + 1);
+		$pre = substr($largeImg, 0, strrpos($largeImg, '.'));
+		return ['small' => $pre . '_50.' . $extend, 'medium' => $pre . '_200.' . $extend, 'large' => $largeImg];
 	}
-
+	
 }

+ 71 - 65
common/services/xhInitService.php

@@ -1,100 +1,106 @@
 <?php
+
 namespace common\services;
+
 use Yii;
 use common\components\util;
 use common\components\configDict;
 
-class xhInitService {
-
-	public static function clear($myOption='hhb')
+class xhInitService
+{
+	
+	public static function clear($myOption = 'hhb')
 	{
 		Yii::$app->redis->executeCommand('FLUSHDB');
-		$connection		= Yii::$app->db;
-		$result			= Yii::$app->db->createCommand('SHOW TABLES')->queryAll();
-		if(empty($result)){
+		$connection = Yii::$app->db;
+		$result = Yii::$app->db->createCommand('SHOW TABLES')->queryAll();
+		if (empty($result)) {
 			util::stop('没有找到数据库表\n');
 		}
-		foreach($result as $val){
-			$tableName	= array_pop($val);
-			if(in_array($tableName,['xhWxOpen','xhWxOpenAdmin'])){//测试时需要重复执行,xhWxOpen xhWxOpenAdmin 已经有数据则不进行清空
+		foreach ($result as $val) {
+			$tableName = array_pop($val);
+			if (in_array($tableName, ['xhWxOpen', 'xhWxOpenAdmin'])) {//测试时需要重复执行,xhWxOpen xhWxOpenAdmin 已经有数据则不进行清空
 				continue;
 			}
-			$sql		= 'truncate '.$tableName;
+			$sql = 'truncate ' . $tableName;
 			$connection->createCommand($sql)->execute();
 		}
-		$id				= configDict::getConfig('openId');
-		$open			= xhWxOpenService::getById($id);
-		if(empty($open)){
-			switch($myOption){
+		$open = [];
+		if (empty($open)) {
+			util::fail('取平台信息错误');
+		}
+		
+		if (empty($open)) {
+			switch ($myOption) {
 				/**
-				 case 'hhbxs'://花卉宝 线上环境
-				 $data	= [
-				 'appId' => 'wxed3b3da77f382b4f',
-				 'openName' => '花卉宝',
-				 'appSecret' => '38cd1c6f37462e57bd3153e49f9a85d4',
-				 'token' => 'wt11464773309',
-				 'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
-				 'createTime' => date("Y-m-d H:i:s"),
-				 ];
-				 break;
+				 * case 'hhbxs'://花卉宝 线上环境
+				 * $data    = [
+				 * 'appId' => 'wxed3b3da77f382b4f',
+				 * 'openName' => '花卉宝',
+				 * 'appSecret' => '38cd1c6f37462e57bd3153e49f9a85d4',
+				 * 'token' => 'wt11464773309',
+				 * 'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
+				 * 'createTime' => date("Y-m-d H:i:s"),
+				 * ];
+				 * break;
 				 **/
 				case 'hml'://花美灵 测试环境
-					$data	= [
-					'appId' => 'wxe4428cfe08fc74d6',
-					'openName' => '花美灵',
-					'appSecret' => '2228663f0d56eb3e4b79fa96b3861f20',
-					'token' => 'wt11464773308',
-					'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW6',
-					'createTime' => date("Y-m-d H:i:s"),
+					$data = [
+						'appId' => 'wxe4428cfe08fc74d6',
+						'openName' => '花美灵',
+						'appSecret' => '2228663f0d56eb3e4b79fa96b3861f20',
+						'token' => 'wt11464773308',
+						'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW6',
+						'createTime' => date("Y-m-d H:i:s"),
 					];
 					break;
 				case 'zhh'://中花汇 开发环境
-					$data	= [
-					'appId' => 'wxa08c41644219674c',
-					'openName' => '中花汇',
-					'appSecret' => 'aec3f43257d51318538ecdb8bb78a42b',
-					'token' => 'wt11464773309',
-					'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
-					'createTime' => date("Y-m-d H:i:s"),
+					$data = [
+						'appId' => 'wxa08c41644219674c',
+						'openName' => '中花汇',
+						'appSecret' => 'aec3f43257d51318538ecdb8bb78a42b',
+						'token' => 'wt11464773309',
+						'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
+						'createTime' => date("Y-m-d H:i:s"),
 					];
 					break;
 				case 'hhb'://花汇宝 演示环境
-					$data	= [
-					'appId' => 'wx364800c320a0cf53',
-					'openName' => '花汇宝',
-					'appSecret' => '88565e17fa739efc020ed1e2a2a56ade',
-					'token' => 'wt11464773309',
-					'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
-					'createTime' => date("Y-m-d H:i:s"),
+					$data = [
+						'appId' => 'wx364800c320a0cf53',
+						'openName' => '花汇宝',
+						'appSecret' => '88565e17fa739efc020ed1e2a2a56ade',
+						'token' => 'wt11464773309',
+						'aesKey' => 'Gm2BIikJaExAbiyafGoJGFbEsECb4mDEnyEYgl9WXW5',
+						'createTime' => date("Y-m-d H:i:s"),
 					];
 					break;
 			}
-			$historyTime						= date('Y-m-d', strtotime('-30 days'));
-			$data['verifyTicketTime']			= $historyTime;
-			$data['componentAccessTokenTime']	= $historyTime;
-			$data['authorizerAccessTokenTime']	= $historyTime;
-			$data['preAuthCodeTime']			= $historyTime;
+			$historyTime = date('Y-m-d', strtotime('-30 days'));
+			$data['verifyTicketTime'] = $historyTime;
+			$data['componentAccessTokenTime'] = $historyTime;
+			$data['authorizerAccessTokenTime'] = $historyTime;
+			$data['preAuthCodeTime'] = $historyTime;
 			xhWxOpenService::add($data);
-		}else{
-			xhWxOpenService::updateById($id, ['merchantId'=>0]);
+		} else {
+			xhWxOpenService::updateById($id, ['merchantId' => 0]);
 		}
-		$id					= configDict::getConfig('openAdminId');
-		$adminOpen			= xhWxOpenAdminService::getById($id);
-		if(empty($adminOpen)){
+		$id = configDict::getConfig('openAdminId');
+		$adminOpen = xhWxOpenAdminService::getById($id);
+		if (empty($adminOpen)) {
 			$data = [
-			'mobile' => '15280215347',
-			'avatar' => '/platAdmin/admin.jpg',
-			'adminName' => '石少华',
-			'password' => md5('111111'),
-			'province' => '福建',
-			'city' => '厦门',
-			'dist' => '思明区',
-			'address' => '软件园二期望海路31号5楼阿里百川',
-			'createTime' => date("Y-m-d H:i:s"),
+				'mobile' => '15280215347',
+				'avatar' => '/platAdmin/admin.jpg',
+				'adminName' => '石少华',
+				'password' => md5('111111'),
+				'province' => '福建',
+				'city' => '厦门',
+				'dist' => '思明区',
+				'address' => '软件园二期望海路31号5楼阿里百川',
+				'createTime' => date("Y-m-d H:i:s"),
 			];
 			xhWxOpenAdminService::add($data);
 		}
-		$setData	= ['name'=>'零售基础版','manageStyle'=>0,'price'=>'3900','createTime'=>date("Y-m-d H:i:s")];
+		$setData = ['name' => '零售基础版', 'manageStyle' => 0, 'price' => '3900', 'createTime' => date("Y-m-d H:i:s")];
 		xhSetMealService::add($setData);
 	}
 

+ 29 - 18
common/services/xhWxOpenService.php

@@ -1,50 +1,61 @@
 <?php
+
 namespace common\services;
+
 use Yii;
 use common\components\stringUtil;
 use common\components\configDict;
 use common\models\xhWxOpen;
 
-class xhWxOpenService {
-
-	public static function getById($id=0)
+class xhWxOpenService
+{
+	
+	public static function getById($id = 0)
 	{
-		$merchant		= xhWxOpen::getByCondition(['id'=>$id]);
+		$merchant = xhWxOpen::getByCondition(['id' => $id]);
 		return $merchant;
 	}
-
+	
 	public static function updateById($id, $data)
 	{
 		xhWxOpen::updateById($id, $data);
 		self::refresh($id);
 	}
-
+	
 	public static function refresh($id)
 	{
-		$preKey			= configDict::getCacheKey('wxOpen');
-		$cacheKey		= $preKey.$id;
+		$preKey = configDict::getCacheKey('wxOpen');
+		$cacheKey = $preKey . $id;
 		Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
 		self::getById($id);
 	}
-
+	
 	public static function add($data)
 	{
-		$data	= xhWxOpen::add($data);
-		$id		= $data['id'];
+		$data = xhWxOpen::add($data);
+		$id = $data['id'];
 		self::refresh($id);
 		return $data;
 	}
-
+	
 	/**
 	 * 取平台相应的商家
 	 */
-	public static function getMerchant()
+	public static function getMerchant($isOpen)
 	{
-		$wxOpenId			= configDict::getConfig('openId');
-		$wxOpen				= xhWxOpenService::getById($wxOpenId);
-		$merchantId			= $wxOpen['merchantId'];
-		$merchant			= xhMerchantService::getById($merchantId);
+		$open = [];
+		if ($isOpen == 1) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_HD]);
+		}
+		if ($isOpen == 2) {
+			$open = \biz\wx\classes\WxOpenClass::getByCondition(['style' => \biz\wx\classes\WxOpenClass::OPEN_STYLE_GHS]);
+		}
+		if (empty($open)) {
+			util::fail('没有找到平台');
+		}
+		$merchantId = $open['merchantId'];
+		$merchant = xhMerchantService::getById($merchantId);
 		return $merchant;
 	}
-
+	
 }

+ 10 - 4
console/controllers/ShellController.php

@@ -5,6 +5,7 @@ namespace console\controllers;
 use bizHd\goods\services\GoodsService;
 use bizHd\stat\services\StatVisitService;
 use bizHd\promote\services\GuaGuaService;
+use common\components\util;
 use Yii;
 use yii\console\Controller;
 use common\models\xhMerchant;
@@ -17,7 +18,7 @@ use common\components\stringUtil;
  */
 class ShellController extends Controller
 {
-
+	
 	//每天要跑的东西放这里 shish 2019.9.10
 	// 10 0 * * * /usr/local/nginx/html/huahuibao/yii shell/per-day
 	public function actionPerDay()
@@ -46,8 +47,10 @@ class ShellController extends Controller
 	 */
 	public function actionWeekNotice($ip = '')
 	{
-		$openId = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($openId);
+		$open = [];
+		if (empty($open)) {
+			util::stop('取平台信息错误');
+		}
 		$name = $open['name'];
 		$mail = Yii::$app->mailer->compose();
 		$errFile = '/opt/shell/log/week_err_' . date("Ymd") . '.txt';
@@ -74,7 +77,10 @@ class ShellController extends Controller
 	public function actionDayNotice($ip = '')
 	{
 		$openId = configDict::getConfig('openId');
-		$open = xhWxOpenService::getById($openId);
+		$open = [];
+		if (empty($open)) {
+			util::stop('取平台信息错误');
+		}
 		$name = $open['name'];
 		$mail = Yii::$app->mailer->compose();
 		$errFile = '/opt/shell/log/day_err_' . date("Ymd") . '.txt';

Some files were not shown because too many files changed in this diff