shish hace 6 años
padre
commit
5d38151b7a
Se han modificado 1 ficheros con 31 adiciones y 39 borrados
  1. 31 39
      app/www/controllers/WxOpenController.php

+ 31 - 39
app/www/controllers/WxOpenController.php

@@ -44,7 +44,7 @@ class WxOpenController extends PublicController
 		$authType = Yii::$app->request->get('authType', 3);
 		echo "<a href='https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid={$appId}&pre_auth_code={$pre}&redirect_uri={$url}&auth_type={$authType}'>授权</a>";
 	}
-
+	
 	public function actionCheckMerchantName()
 	{
 		$get = Yii::$app->request->get();
@@ -112,12 +112,12 @@ class WxOpenController extends PublicController
 		$open_pay = $business_info['open_pay'];
 		$merchant = xhMerchantService::getByAppId($authorizeAppId);
 		$wxAccessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
-		if (!empty($merchant)) {
-			util::stop('此公众号或小程序已经授权过了');
-		}
 		$one = MerchantClass::getOne();
 		if (!empty($one) && empty($id)) {
-			util::stop('平台公众号已经创建过了,不能重复创建');
+			util::stop('平台已经有初始化的公众号了');
+		}
+		if (!empty($merchant)) {
+			util::stop('此公众号或小程序已经授权过了');
 		}
 		//小程序
 		if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
@@ -131,13 +131,8 @@ class WxOpenController extends PublicController
 			Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
 			util::stop("小程序信息更新成功");
 		}
-		
-		$merchant = xhMerchantService::getByAppId($authorizeAppId);
-		
-		if (empty($merchant)) {
-			util::stop('这个商家没有生成过基本信息。appid:' . $authorizeAppId);
-		}
-		if (empty($merchant)) {
+
+		if (empty($one)) {
 			
 			//引导生成商家
 			$date = date("Y-m-d H:i:s");
@@ -174,35 +169,32 @@ class WxOpenController extends PublicController
 			$appData['alipayAccountName'] = '石少华';
 			$appData['agentLevel'] = 1;//默认设置为代理商
 			$merchant = xhMerchantService::applyCreateMerchant($appData);
-			$merchantId = $merchant['id'];
-			
-			$wxOpenId = configDict::getConfig('openId');
-			$open = xhWxOpenService::getById($wxOpenId);
-			$platform = 0;
-			if (isset($open['merchantId']) && empty($open['merchantId'])) {
-				xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
-				$platform = 1;
-			}
-			
-			$data = ['merchantId' => $merchantId, 'platform' => $platform];
-			$producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
-			$msg = serialize($data);
-			$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
-			
-		} else {
-			
-			$cData = [];
-			$cData['wxAccessToken'] = $authorize_access_token;
-			$cData['wxAccessTokenTime'] = $accessTokenTime;
-			$cData['wxRefreshToken'] = $authorize_refresh_token;
-			//审核通过
-			$cData['status'] = 1;
-			$merchantId = $merchant['id'];
-			xhMerchantService::updateById($merchantId, $cData);
-			
 		}
-		echo 'ok';
+		$merchantId = $merchant['id'];
+		$wxOpenId = configDict::getConfig('openId');
+		$open = xhWxOpenService::getById($wxOpenId);
+		$platform = 0;
+		if (isset($open['merchantId']) && empty($open['merchantId'])) {
+			xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
+			$platform = 1;
+		}
+
+		//待完善 shish 2020.2.11
+		$data = ['merchantId' => $merchantId, 'platform' => $platform];
+		$producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
+		$msg = serialize($data);
+		$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
+
+		$cData = [];
+		$cData['wxAccessToken'] = $authorize_access_token;
+		$cData['wxAccessTokenTime'] = $accessTokenTime;
+		$cData['wxRefreshToken'] = $authorize_refresh_token;
+		//审核通过
+		$cData['status'] = 1;
+		$merchantId = $merchant['id'];
+		xhMerchantService::updateById($merchantId, $cData);
 		
+		echo 'ok';
 	}
 	
 	public function actionResult()