shish пре 6 година
родитељ
комит
305eabbcfb

+ 14 - 55
app/www/controllers/WxOpenController.php

@@ -70,10 +70,8 @@ class WxOpenController extends PublicController
 		}
 		util::fail();
 	}
-	
-	/**
-	 * 创建第一个商家
-	 */
+
+	//创建平台使用的公众号
 	public function actionCallbackCreateFirstMerchant()
 	{
 		$get = Yii::$app->request->get();
@@ -148,7 +146,7 @@ class WxOpenController extends PublicController
 		$appData['shopProvince'] = '福建';
 		$appData['shopCity'] = '厦门';
 		$appData['shopDist'] = '思明区';
-		$appData['alipayAccount'] = 'shishaohua8879@sina.com';
+		$appData['alipayAccount'] = 'shish@zhhinc.com';
 		$appData['alipayAccountName'] = '石少华';
 		$appData['agentLevel'] = 1;//默认设置为代理商
 		$merchant = xhMerchantService::applyCreateMerchant($appData);
@@ -156,11 +154,17 @@ class WxOpenController extends PublicController
 		$merchantId = $merchant['id'];
 		xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
 
-		xhWxMenuService::applyInit($merchant);//初始化微信菜单
+		//商品、分类、首页幻灯片、门店图片
+		//创建门店
+		//创建管理员
+		//客户信息初始化
+		//初始化微信菜单
+		xhWxMenuService::applyInit($merchant);
 
 		echo 'ok';
+
 	}
-	
+
 	public function actionCallback()
 	{
 		$get = Yii::$app->request->get();
@@ -250,55 +254,10 @@ class WxOpenController extends PublicController
 			$merchantId = $merchant['id'];
 			xhMerchantService::updateById($merchantId, $cData);
 		}
-		echo $authorizeAppId . ' ';
-		exit('ok');
-		$price = $set['price'];
-		$now = time();
-		$apply = xhApplyOrderService::getByMerchantId($merchantId);
-		if (empty($apply)) {
-			return $this->renderPartial('hint', ['msg' => '没有申请记录']);
-		}
-		$orderId = $apply['id'];
-		$price = $apply['actPrice'];
-		$openMerchant = xhWxOpenService::getMerchant();
-		$openMerchantAccount = $openMerchant['id'];
-		$account = $merchant['id'];
-		//将新生成的商家account加密传到后台绑定管理员,密钥有效期5分钟
-		$newAccount = urlencode(stringUtil::authcode($account, 'ENCODE', 300));
-		if ($apply['payStatus'] == 1) {
-			if (empty($merchant['adminId'])) {
-				$this->redirect(Yii::$app->params['adminUrl'] . '/admin/generate?account=' . $openMerchantAccount . '&newAccount=' . $newAccount);
-				util::end();
-			}
-			return $this->renderPartial('hint', ['msg' => '恭喜!您已申请成功。']);
-		}
-		if ($price > 0) {
-			$this->redirect(Yii::$app->params['openUrl'] . '/pay/apply?orderId=' . $apply['id']);
-			util::end();
-		} else {
-			$inviteCode = $order['inviteCode'];
-			$now = time();
-			if (!empty($inviteCode)) {
-				$invite = xhInviteService::getByCode($inviteCode);
-				if (empty($invite)) {
-					return $this->renderPartial('hint', ['msg' => '邀请码不存在']);
-				}
-				if ($invite['takeStatus'] == 1) {//邀请码未使用,并且没有过期
-					return $this->renderPartial('hint', ['msg' => '邀请码已经使用,请联系客服']);
-				}
-				$inviteDeadline = $invite['deadline'];
-				if ($now > $inviteDeadline) {
-					return $this->renderPartial('hint', ['msg' => '邀请码已经过期,请联系客服']);
-				}
-				xhInviteService::updateByCode($inviteCode, ['takeStatus' => 1, 'inviteUseTo' => 0, 'targetId' => $orderId, 'invitedMerchantId' => $merchantId]);
-			}
-			$updateData = ['inviteCodeStatus' => 1, 'payStatus' => 1, 'payWay' => 0, 'invitedMerchantId' => $merchantId];
-			xhApplyOrderService::updateById($orderId, $updateData);
-			$this->redirect(Yii::$app->params['adminUrl'] . '/admin/generate?account=' . $openMerchantAccount . '&newAccount=' . $newAccount);
-			util::end();
-		}
+		echo $authorizeAppId . ' ok';
+
 	}
-	
+
 	public function actionResult()
 	{
 		$get = Yii::$app->request->get();

+ 21 - 2
biz/message/services/TMessageService.php

@@ -1,17 +1,36 @@
 <?php
+
 namespace biz\message\services;
+
 use biz\base\services\BaseService;
+use biz\message\classes\TMessageClass;
+use common\components\wxUtil;
 use Yii;
 use linslin\yii2\curl;
+
 class TMessageService extends BaseService
 {
-
+	
 	public static $baseFile = '\biz\message\classes\TMessageClass';
-
+	
 	//商家宝贝售出提醒 shish 2019.9.11
 	public static function adminGoodsSold($data)
 	{
 		//发送到MQ
 	}
 
+	//删除模板消息 shish 2020.2.7
+	public static function delTMessage($merchant)
+	{
+		$merchantId = $merchant['id'];
+		$list = TMessageClass::getAllByCondition(['merchantId' => $merchantId]);
+		if (!empty($list)) {
+			foreach ($list as $key => $val) {
+				$templateId = $val['templateId'];
+				wxUtil::delTMessage($merchant, $templateId);
+			}
+			TMessageClass::deleteByCondition(['merchantId' => $merchantId]);
+		}
+	}
+
 }

+ 2 - 8
common/components/wxUtil.php

@@ -157,9 +157,6 @@ class wxUtil
 	
 	/**
 	 * 提交自定义菜单到微信平台
-	 * @param $merchant
-	 * @param $menu
-	 * @return mixed
 	 */
 	public function userMenuToWeiXin($menu)
 	{
@@ -169,12 +166,9 @@ class wxUtil
 		$response = $curl->setOption(CURLOPT_POSTFIELDS, $jsonData)->post($url);
 		return $response;
 	}
-	
+
 	/**
 	 * 上传图片多媒体文件
-	 * @param unknown_type $type
-	 * @param unknown_type $access_token
-	 * @param unknown_type $data
 	 */
 	public static function uploadImgMedia($merchant, $fullFile)
 	{
@@ -547,7 +541,7 @@ class wxUtil
 	 * @param unknown $templateId
 	 * @return unknown
 	 */
-	public function delTMessage($merchant, $templateId)
+	public static function delTMessage($merchant, $templateId)
 	{
 		$accessToken = self::getAuthorizerAccessToken($merchant);
 		$url = "https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token={$accessToken}";

+ 4 - 3
common/services/xhWxMenuService.php

@@ -2,6 +2,7 @@
 
 namespace common\services;
 
+use biz\message\services\TMessageService;
 use biz\weixin\services\WxOpenService;
 use Yii;
 use common\components\wxUtil;
@@ -17,13 +18,13 @@ class xhWxMenuService
     public static function applyInit($merchant)
     {
         $merchantId = $merchant['id'];
-        //删除之前存在的菜单
-        self::delMenuList($merchantId);
+        //删除之前的模板消息
+        TMessageService::delTMessage($merchant);
         $menuOption = configDict::getConfig('wxMenuOption');
         $mDomain = Yii::$app->params['mDomain'];
         $wDomain = Yii::$app->params['wDomain'];
         $bDomain = Yii::$app->params['bDomain'];
-        //默认使用https方式
+        //强制使用https方式
         if (strpos($mDomain, 'https') === false) {
             $mDomain = str_replace('http', 'https', $mDomain);
             $wDomain = str_replace('http', 'https', $wDomain);