Pārlūkot izejas kodu

平台公众号模板消息

shish 6 gadi atpakaļ
vecāks
revīzija
22232cc360

+ 3 - 3
biz/message/services/InformAdminService.php

@@ -20,7 +20,7 @@ class InformAdminService extends BaseService
 	
 	public static $baseFile = '\biz\message\classes\InformAdminClass';
 	
-	//通知员 shish 2020.1.1
+	//通知管理员 shish 2020.1.1
 	public static function addInform($merchantId, $shopId, $type, $params)
 	{
 		$adminShopList = AdminShopService::getNoticeAdminList($shopId);
@@ -31,12 +31,12 @@ class InformAdminService extends BaseService
 		if (getenv('YII_ENV') == 'local') {
 			return false;
 		}
-		$TMList = xhTMessageService::getList($merchantId);
+		$TMList = TMessageService::getOpenList();
 		foreach ($adminShopList as $adminKey => $adminShop) {
 			InformAdminClass::addInform($params, $adminShop, $type, $TMList);
 		}
 	}
-	
+
 	//消费通知内容 shish 2020.1.1
 	//['messageType'=>'inform','informWay'=>'miniProgram','userType'=>'admin','adminShopId'=>913,'mobile'=>'15280215347','tMessage'=>'','content'=>'','briefContent'=>'','isOpen'=>1]
 	public static function consumeInformQueue($data)

+ 13 - 1
biz/message/services/TMessageService.php

@@ -16,7 +16,19 @@ class TMessageService extends BaseService
 	//商家宝贝售出提醒 shish 2019.9.11
 	public static function adminGoodsSold($data)
 	{
-		//发送到MQ
 	}
 
+	//获取平台公众号的模板消息列表 shish 2020.4.28
+	public static function getOpenList()
+	{
+		$tm = TMessageClass::getAllByCondition(['merchantId' => 0]);
+		$list = [];
+		if (!empty($tm)) {
+			foreach ($tm as $val) {
+				$list[$val['shortTemplateId']] = $val['templateId'];
+			}
+		}
+		return $list;
+	}
+	
 }

+ 2 - 2
common/components/wxUtil.php

@@ -513,9 +513,9 @@ class wxUtil
 	 * @param unknown $template_id_short
 	 * @return unknown
 	 */
-	public static function tMessageCreate($merchant, $shortTemplateId)
+	public static function tMessageCreate($merchant, $shortTemplateId, $isOpen = 0)
 	{
-		$accessToken = self::getAuthorizerAccessToken($merchant);
+		$accessToken = self::getAuthorizerAccessToken($merchant, $isOpen);
 		$url = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token={$accessToken}";
 		$post = array('template_id_short' => $shortTemplateId);
 		$curl = new curl\Curl();

+ 3 - 3
common/services/xhTMessageService.php

@@ -39,7 +39,7 @@ class xhTMessageService
 	{
 		xhTMessage::deleteByCondition(['merchantId' => $merchantId]);
 	}
-
+	
 	public static function delTMessage($merchant)
 	{
 		$merchantId = $merchant['id'];
@@ -138,7 +138,7 @@ class xhTMessageService
 	}
 	
 	//补充缺失的模板 shish 2020.2.9
-	public static function supplement($merchant)
+	public static function supplement($merchant, $isOpen)
 	{
 		$merchantId = $merchant['id'];
 		$tMessageList = configDict::getConfig('tMessage');
@@ -155,7 +155,7 @@ class xhTMessageService
 			return ['code' => 'A0001', 'msg' => '没有模板需要添加'];
 		}
 		foreach ($addData as $tKey => $tVal) {
-			$wxReturn = wxUtil::tMessageCreate($merchant, $tVal);
+			$wxReturn = wxUtil::tMessageCreate($merchant, $tVal, $isOpen);
 			if (isset($wxReturn['errcode']) && $wxReturn['errcode'] == 0) {
 				$templateId = $wxReturn['template_id'];
 				$data = [

+ 17 - 27
console/controllers/InitController.php

@@ -4,6 +4,7 @@ namespace console\controllers;
 
 use biz\merchant\services\MerchantService;
 use biz\user\services\UserService;
+use biz\wx\services\WxOpenService;
 use common\services\xhAdminService;
 use common\services\xhMerchantAssetService;
 use common\services\xhMerchantExtendService;
@@ -21,7 +22,7 @@ use common\services\xhInitService;
  */
 class InitController extends Controller
 {
-
+	
 	//开店初始化 shish 2020.2.8
 	public function actionRabbit()
 	{
@@ -30,7 +31,7 @@ class InitController extends Controller
 		$msg = serialize($data);
 		$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
 	}
-
+	
 	//哪些东西开店时需要初始化!!!!!
 	public function actionFirstInit()
 	{
@@ -54,18 +55,26 @@ class InitController extends Controller
 	{
 		echo 'ok';
 	}
-
-	//接入一个商家需要的操作 shish 2019.9.7 yii init/join-one 12358
-	public function actionJoinOne($id)
+	
+	//接入一个商家需要的操作 shish 2019.9.7
+	//  yii init/join-one 12358 更新某个商家公众号
+	//  yii init/join-one 更新平台公众号
+	public function actionJoinOne($id = 0)
 	{
 		//初始化微信菜单
-		$merchant = xhMerchantService::getById($id);
+		if ($id == 0) {
+			$isOpen = 1;
+			$merchant = WxOpenService::getWxInfo();
+		} else {
+			$isOpen = 0;
+			$merchant = xhMerchantService::getById($id);
+		}
 		//xhWxMenuService::applyInit($merchant);
 		//模板消息
-		$r = xhTMessageService::supplement($merchant);
+		$r = xhTMessageService::supplement($merchant, $isOpen);
 		print_r($r);
 	}
-
+	
 	//yii init/sub
 	public function actionSub()
 	{
@@ -253,23 +262,4 @@ TRUNCATE xhUserByDay;";
 		echo "初始化完成!\n";
 	}
 	
-	/**
-	 * 模板消息补充增加
-	 * ./yii init/t-m-supplement
-	 */
-	public function actionTMSupplement()
-	{
-		//服务号
-		$allMerchant = xhMerchant::getAllByCondition(['status' => 1]);
-		if (empty($allMerchant)) {
-			echo "没有商家需要初始化模板消息";
-			Yii::$app->end();
-		}
-		foreach ($allMerchant as $val) {
-			$merchantId = $val['id'];
-			$merchant = xhMerchantService::getById($merchantId);
-			xhTMessageService::supplement($merchant);
-		}
-	}
-	
 }