Explorar el Código

平台公众号已经创建过了

shish hace 6 años
padre
commit
6c52829c0a

+ 1 - 1
app/www/config/main.php

@@ -41,7 +41,7 @@ return [
 				//公众号消息与事件接收地址
 				'wx/<appId:\w+>' => 'wx/api',
 				//公众号授权回调通知地址
-				'wx-open-callback/<merchantId:\w+>' => 'wx-open/callback',
+				'wx-open-callback/<id:\w+>' => 'wx-open/callback',
 				'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
 			],
 		],

+ 11 - 6
app/www/controllers/WxOpenController.php

@@ -2,6 +2,7 @@
 
 namespace www\controllers;
 
+use biz\merchant\classes\MerchantClass;
 use common\services\xhMerchantExtendService;
 use common\services\xhTMessageService;
 use Yii;
@@ -68,7 +69,7 @@ class WxOpenController extends PublicController
 		}
 		util::fail();
 	}
-
+	
 	//创建平台使用的公众号
 	public function actionCallback()
 	{
@@ -76,6 +77,7 @@ class WxOpenController extends PublicController
 		if (isset($get['auth_code']) == false) {
 			util::stop('公众号授权回调未成功');
 		}
+		$id = isset($get['id']) ? $get['id'] : 0;
 		$code = $get['auth_code'];
 		//使用授权码换取公众号的接口调用凭据和授权信息
 		$authorize = wxUtil::getAuthorizer($code);
@@ -113,7 +115,10 @@ class WxOpenController extends PublicController
 		if (!empty($merchant)) {
 			util::stop('此公众号或小程序已经授权过了');
 		}
-		
+		$one = MerchantClass::getOne();
+		if (!empty($one) && empty($id)) {
+			util::stop('平台公众号已经创建过了,不能重复创建');
+		}
 		//小程序
 		if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
 			$merchant = xhMerchantService::getByCondition(['miniAppId' => $authorizeAppId]);
@@ -126,7 +131,7 @@ class WxOpenController extends PublicController
 			Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
 			util::stop("小程序信息更新成功");
 		}
-		
+
 		$merchant = xhMerchantService::getByAppId($authorizeAppId);
 		Yii::info('appId:' . $authorizeAppId);
 		$set = xhSetMealService::getRandOne();
@@ -182,12 +187,12 @@ class WxOpenController extends PublicController
 				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 = [];
@@ -203,7 +208,7 @@ class WxOpenController extends PublicController
 		echo 'ok';
 		
 	}
-
+	
 	public function actionResult()
 	{
 		$get = Yii::$app->request->get();

+ 9 - 2
biz/base/classes/BaseClass.php

@@ -28,7 +28,7 @@ class BaseClass
 		$return = $model->getList($select, $where, $page, $pageSize, $order, $with);
 		return $return;
 	}
-
+	
 	//查询指定条数 shish 2019.11.30
 	public static function getLimitList($select, $where, $limit = 10, $order = '', $with = '')
 	{
@@ -113,6 +113,13 @@ class BaseClass
 		return $model->getById($id, $returnObject);
 	}
 	
+	//随机取一个 shish 2020.2.10
+	public static function getOne($returnObject = false, $order = false)
+	{
+		$model = Yii::createObject(['class' => static::$baseFile]);
+		return $model->getOne($returnObject, $order);
+	}
+	
 	/**
 	 *根据条件查出一条记录
 	 */
@@ -162,5 +169,5 @@ class BaseClass
 		$model = Yii::createObject(['class' => static::$baseFile]);
 		return $model->counters($counters, $condition, $params);
 	}
-
+	
 }

+ 19 - 9
biz/base/models/Base.php

@@ -164,7 +164,17 @@ class Base extends ActiveRecord
 		}
 		return $returnObject == true ? $query->one() : $query->asArray()->one();
 	}
-	
+
+	//随机取一个 shish 2020.2.10
+	public function getOne($returnObject = false, $order = false)
+	{
+		$query = $this->conditionQuery([]);
+		if (isset($order)) {
+			$query->orderBy($order);
+		}
+		return $returnObject == true ? $query->one() : $query->asArray()->one();
+	}
+
 	/**
 	 * 支持查询条件包括
 	 * ['name'=>'john','id>'=>3,'id<'=>10,'id'=>['in',[10,11,12]],'age'=>['between',[20,30]],'name'=>['like','Jack']];
@@ -314,7 +324,7 @@ class Base extends ActiveRecord
 		$list = $query->offset($offset)->limit($limit)->asArray()->all();
 		return $list;
 	}
-
+	
 	/**
 	 * 计数器+1-1
 	 * $counters = ['num' => 1] 1数量+1 -1数量-1
@@ -324,11 +334,11 @@ class Base extends ActiveRecord
 	{
 		return self::updateAllCounters($counters, $condition, $params);
 	}
-
-    // 获取图书的作者
-    public function getAuthor()
-    {
-        //同样第一个参数指定关联的子表模型类名
-        return $this->hasOne(Author::className(), ['id' => 'author_id']);
-    }
+	
+	// 获取图书的作者
+	public function getAuthor()
+	{
+		//同样第一个参数指定关联的子表模型类名
+		return $this->hasOne(Author::className(), ['id' => 'author_id']);
+	}
 }