Quellcode durchsuchen

授权公众号不正确

shish vor 6 Jahren
Ursprung
Commit
f91922c7b4

+ 30 - 70
app/www/controllers/WxOpenController.php

@@ -3,6 +3,7 @@
 namespace www\controllers;
 
 use biz\merchant\classes\MerchantClass;
+use biz\weixin\services\WxOpenService;
 use common\services\xhMerchantExtendService;
 use common\services\xhTMessageService;
 use Yii;
@@ -33,7 +34,12 @@ class WxOpenController extends PublicController
 	{
 		$id = 1;
 		$merchantId = Yii::$app->request->get('id', 0);
-		$open = xhWxOpenService::getById($id);
+		$open = WxOpenService::getOpen();
+		if (isset($open['merchantId']) && empty($open['merchantId'])) {
+			if (!empty($merchantId)) {
+				util::stop('请先将开放平台关联公众号');
+			}
+		}
 		$pre = wxUtil::getPreAuthCode($open);
 		$appId = $open['appId'];
 		$oData = [];
@@ -110,15 +116,19 @@ class WxOpenController extends PublicController
 		$qrCodeUrl = $authorize_info['qrcode_url'];
 		$business_info = $authorize_info['business_info'];
 		$open_pay = $business_info['open_pay'];
-		$merchant = xhMerchantService::getByAppId($authorizeAppId);
 		$wxAccessTokenTime = date("Y-m-d H:i:s", (time() + $expires_in - 100));//安全起见,将过期时间设置得比微信里还短100秒
-		$one = MerchantClass::getOne();
-		if (!empty($one) && empty($id)) {
-			util::stop('平台已经有初始化的公众号了');
+		
+		//开放平台还没有关联公众号,先将开放平台关联公众号
+		$open = WxOpenService::getOpen();
+		if (isset($open['merchantId']) && empty($open['merchantId'])) {
+			WxOpenService::updateById(1, ['merchantId' => $id]);
 		}
-		if (!empty($merchant)) {
-			util::stop('此公众号或小程序已经授权过了');
+		
+		$merchant = xhMerchantService::getByAppId($authorizeAppId);
+		if (isset($merchant['id']) && $merchant['id'] != $id) {
+			util::stop('授权的公众号不正确');
 		}
+		
 		//小程序
 		if (isset($authorize_info['MiniProgramInfo']) && !empty($authorize_info['MiniProgramInfo'])) {
 			$merchant = xhMerchantService::getByCondition(['miniAppId' => $authorizeAppId]);
@@ -131,72 +141,22 @@ class WxOpenController extends PublicController
 			Yii::info('小程序信息更新成功:' . json_encode($authorize_info));
 			util::stop("小程序信息更新成功");
 		}
-
-		if (empty($one)) {
-			
-			//引导生成商家
-			$date = date("Y-m-d H:i:s");
-			$trainDemo = configDict::getConfig('trainDemo');
-			//$logo = xhMerchantService::logoSave($head_img, $authorizeAppId);
-			$logo = '';
-			$appData['logo'] = $logo;
-			//保存公众号二维码
-			//$wxQrCodeUrl = xhMerchantService::qrCodeSave($qrCodeUrl, $authorizeAppId);
-			$wxQrCodeUrl = '';
-			$appData['wxQrcodeUrl'] = $wxQrCodeUrl;
-			$appData['wxAppId'] = $authorizeAppId;
-			$appData['wxUserName'] = $user_name;
-			$appData['wxAliasName'] = $alias;
-			$appData['wxAccessToken'] = $authorize_access_token;
-			$appData['wxAccessTokenTime'] = $wxAccessTokenTime;
-			$appData['wxRefreshToken'] = $authorize_refresh_token;
-			$appData['accountStyle'] = 0;//认证服务号
-			$appData['status'] = 0;//待审核
-			$appData['createTime'] = $date;
-			$appData['updateTime'] = $date;
-			$appData['shopLat'] = (string)0;
-			$appData['shopLong'] = (string)0;
-			$appData['shopPrecision'] = (string)0;
-			$appData['account'] = $trainDemo['platform']['account'];
-			$appData['adminId'] = 0;
-			$appData['wxToken'] = stringUtil::buildWxToken(0);
-			$appData['shopPhotoList'] = '';
-			$appData['merchantName'] = $nick_name;
-			$appData['shopProvince'] = '福建';
-			$appData['shopCity'] = '厦门';
-			$appData['shopDist'] = '思明区';
-			$appData['alipayAccount'] = 'shish@zhhinc.com';
-			$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;
-		}
-
-		//待完善 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);
 		
+		$upData = [];
+		$appData['wxUserName'] = $user_name;
+		$appData['wxAliasName'] = $alias;
+		$upData['logo'] = xhMerchantService::logoSave($head_img, $authorizeAppId);//公众号logo
+		$upData['wxQrcodeUrl'] = xhMerchantService::qrCodeSave($qrCodeUrl, $authorizeAppId);//公众号二维码
+		$upData['wxAppId'] = $authorizeAppId;
+		$upData['wxAccessToken'] = $authorize_access_token;
+		$upData['wxAccessTokenTime'] = $accessTokenTime;
+		$upData['wxRefreshToken'] = $authorize_refresh_token;
+		$upData['status'] = 1;//审核通过
+		xhMerchantService::updateById($id, $upData);
+
 		echo 'ok';
 	}
-	
+
 	public function actionResult()
 	{
 		$get = Yii::$app->request->get();

+ 161 - 40
biz/merchant/classes/MerchantClass.php

@@ -2,50 +2,171 @@
 
 namespace biz\merchant\classes;
 
+use biz\admin\classes\AdminRoleClass;
+use biz\goods\classes\GoodsSettingClass;
 use common\components\business;
+use common\components\stringUtil;
 use Yii;
 use biz\base\classes\BaseClass;
 
 class MerchantClass extends BaseClass
 {
-
-    public static $baseFile = '\biz\merchant\models\Merchant';
-
-    //常用链接
-    public static $commonUrl = [
-        1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
-        2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
-        3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
-    ];
-
-    //商家信息组合 shish 2019.12.20
-    public static function groupMerchantBaseInfo($list)
-    {
-        return $list;
-    }
-
-    public static function getMerchantByIds($ids)
-    {
-        return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
-    }
-
-    public static function getMerchantById($id)
-    {
-        $merchant = self::getById($id);
-        if (empty($merchant)) {
-            return $merchant;
-        }
-        $list = self::groupBaseInfo([$merchant]);
-        return current($list);
-    }
-
-    public static function groupBaseInfo($list)
-    {
-        foreach ($list as $key => $val) {
-            $list[$key] = business::formatMerchantLogo($list[$key]);
-            $list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
-        }
-        return $list;
-    }
-
+	
+	public static $baseFile = '\biz\merchant\models\Merchant';
+	
+	//常用链接
+	public static $commonUrl = [
+		1 => ['id' => 1, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '商城'],
+		2 => ['id' => 2, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '申请会员'],
+		3 => ['id' => 3, 'url' => '/mall/index?account=12358', 'img' => 'http://a.huahb.com/images/avatar.jpg', 'sign' => 'mall', 'name' => '点我付款'],
+	];
+	
+	//商家信息组合 shish 2019.12.20
+	public static function groupMerchantBaseInfo($list)
+	{
+		return $list;
+	}
+	
+	public static function getMerchantByIds($ids)
+	{
+		return self::getAllByCondition(['id' => ['in', $ids]], null, '*', 'id');
+	}
+	
+	public static function getMerchantById($id)
+	{
+		$merchant = self::getById($id);
+		if (empty($merchant)) {
+			return $merchant;
+		}
+		$list = self::groupBaseInfo([$merchant]);
+		return current($list);
+	}
+	
+	public static function groupBaseInfo($list)
+	{
+		foreach ($list as $key => $val) {
+			$list[$key] = business::formatMerchantLogo($list[$key]);
+			$list[$key]['address'] = '福建省厦门市思明区上湖社1017号';
+		}
+		return $list;
+	}
+	
+	//创建商家信息 shish 2020.2.11
+	public static function generateMerchant($data)
+	{
+		//生成商家
+		$date = date("Y-m-d H:i:s");
+		$time = time();
+		$data['accountStyle'] = 0;//认证服务号
+		$data['status'] = 0;//待审核
+		$data['createTime'] = $date;
+		$data['updateTime'] = $date;
+		$data['shopLat'] = (string)0;
+		$data['shopLong'] = (string)0;
+		$data['shopPrecision'] = (string)0;
+		$data['adminId'] = 0;
+		$data['wxToken'] = stringUtil::buildWxToken(0);
+		$data['shopPhotoList'] = isset($data['shopPhotoList']) ? $data['shopPhotoList'] : '';
+		$data['merchantName'] = isset($data['merchantName']) ? $data['merchantName'] : '';
+		$data['shopProvince'] = isset($data['shopProvince']) ? $data['shopProvince'] : '';
+		$data['shopCity'] = isset($data['shopCity']) ? $data['shopCity'] : '';
+		$data['shopDist'] = isset($data['shopDist']) ? $data['shopDist'] : '';
+		$data['alipayAccount'] = isset($data['alipayAccount']) ? $data['alipayAccount'] : '';
+		$data['alipayAccountName'] = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
+		//默认设置为代理商
+		$data['agentLevel'] = 1;
+		$merchant = self::add($data);
+		$merchantId = $merchant['id'];
+		//生成商家资产
+		$assetData = [
+			'balance' => 0,
+			'totalVisit' => 0,
+			'totalUser' => 0,
+			'totalMember' => 0,
+			'totalFans' => 0,
+			'totalWeixinFans' => 0,
+			'totalIntegral' => 0,
+			'totalPoint' => 0,
+			'totalGoods' => 0,
+			'totalRecharge' => 0,
+			'totalOrder' => 0,
+			'totalDeal' => 0,
+			'merchantId' => $merchantId,
+			'totalIncome' => 0,
+			'totalExpend' => 0,
+			'createTime' => $date,
+			'updateTime' => $date,
+		];
+		//商家资产表
+		MerchantAssetClass::add($assetData);
+		
+		//生成商家拓展信息
+		$extendData = [
+			'merchantId' => $merchantId,
+			'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
+			'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
+			'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
+			'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
+			'wxMenuInit' => 0,
+			'wxTMessageInit' => 0,
+			'payment' => 0,//支付功能关闭
+			'recharge' => 0,//充值功能关闭
+			'giveCoupon' => 1,//默认赠送代金劵
+			'giveCouponPrice' => 5,//代金劵金额5元
+			'couponMeetPrice' => 180,//满足金额
+			'couponValidity' => 30,//代金劵有效期30天
+			'alipayAccount' => isset($data['alipayAccount']) ? $data['alipayAccount'] : '',//提现的支付宝帐号
+			'alipayAccountName' => isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '',//提现支付宝帐号姓名
+			'gradeList' => '1_2000_9I2_5000_88I3_10000_85I4_20000_8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
+			'createTime' => $date,
+			'updateTime' => $date,
+		];
+		MerchantExtendClass::add($extendData);
+		
+		//商家商品统一配置
+		$setData = [
+			'merchantId' => $merchantId,
+			'riseType' => 0,
+			'riseAmount' => 0,
+			'addTime' => time(),
+		];
+		GoodsSettingClass::add($setData);
+		
+		//创建门店
+		$shopData = ['shopName' => $merchant['merchantName'], 'merchantName' => $merchant['merchantName'], 'merchantId' => $merchantId, 'addTime' => $time, 'createTime' => $date, 'updateTime' => $date];
+		$shopReturn = ShopClass::addShop($shopData);
+		$shopId = $shopReturn['id'];
+		//设置商家默认门店
+		MerchantClass::updateByCondition(['merchantId' => $merchantId], ['defaultShopId' => $shopId]);
+		
+		//创建管理员角色
+		$hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId, 'roleName' => '老板']);
+		if (empty($hasRole)) {
+			AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
+			$roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
+			$roleId = $roleReturn['id'];
+		}
+		
+		//创建管理员
+		$mobile = $data['mobile'];
+		$admin = AdminClass::getByCondition(['merchantId' => $merchantId, 'mobile' => $mobile]);
+		if (empty($admin)) {
+			$adminData = [
+				'mobile' => 15280215347,
+				'adminName' => '石少华',
+				'password' => password_hash('123456', PASSWORD_BCRYPT),
+				'confirmPassword' => password_hash('123456', PASSWORD_BCRYPT),
+				'merchantId' => $merchantId,
+				'roleId' => $roleId,
+				'defaultShopId' => $shopId,
+				'currentShopId' => $shopId,
+				'super' => 1,
+				'addTime' => $time,
+			];
+			AdminClass::addAdmin($adminData);
+		}
+		
+		return $merchant;
+	}
+	
 }

+ 1 - 43
biz/merchant/services/MerchantService.php

@@ -144,19 +144,14 @@ class MerchantService extends BaseService
 	public static function openShopInit($data)
 	{
 		$merchantId = $data['merchantId'];
-		$platform = $data['platform'];
 		$merchant = MerchantClass::getMerchantById($merchantId);
 		if (empty($merchant)) {
 			return false;
 		}
-		$time = time();
-		$date = date("Y-m-d H:i:s");
 		$connection = Yii::$app->db;//事务处理
 		$transaction = $connection->beginTransaction();
 		try {
 			
-			//商品、分类、首页幻灯片、门店图片
-			
 			//初始化微信菜单
 			xhWxMenuService::applyInit($merchant);
 			
@@ -165,45 +160,9 @@ class MerchantService extends BaseService
 			$totalNum = isset($return['total']) ? $return['total'] : 0;
 			MerchantAssetClass::updateByCondition(['merchantId' => $merchantId], ['totalFans' => $totalNum, 'totalUser' => $totalNum]);
 			
-			//创建门店
-			$shopData = ['shopName' => $merchant['merchantName'], 'merchantName' => $merchant['merchantName'], 'merchantId' => $merchantId, 'addTime' => $time, 'createTime' => $date, 'updateTime' => $date];
-			$shopReturn = ShopClass::addShop($shopData);
-			$shopId = $shopReturn['id'];
-			
-			//设置商家默认门店
-			MerchantClass::updateByCondition(['merchantId' => $merchantId], ['defaultShopId' => $shopId]);
-			
-			//创建管理员角色
-			$hasRole = AdminRoleClass::getByCondition(['merchantId' => $merchantId, 'roleName' => '老板']);
-			if (empty($hasRole)) {
-				AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
-				$roleReturn = AdminRoleClass::addAdminRole(['roleName' => '老板', 'merchantId' => $merchantId, 'auth' => '*']);
-				$roleId = $roleReturn['id'];
-			}
-			
-			if ($platform == 1) {
-				//平台使用的公众号创建指定管理员
-				$admin = AdminClass::getByCondition(['merchantId' => $merchantId, 'mobile' => 15280215347]);
-				if (empty($admin)) {
-					$adminData = [
-						'mobile' => 15280215347,
-						'adminName' => '石少华',
-						'password' => password_hash('123456', PASSWORD_BCRYPT),
-						'confirmPassword' => password_hash('123456', PASSWORD_BCRYPT),
-						'merchantId' => $merchantId,
-						'roleId' => $roleId,
-						'defaultShopId' => $shopId,
-						'currentShopId' => $shopId,
-						'super' => 1,
-						'addTime' => $time,
-					];
-					AdminClass::addAdmin($adminData);
-				}
-			}
-			
 			//模板消息
 			xhTMessageService::init($merchant);
-			
+
 			$transaction->commit();
 			return true;
 			
@@ -211,7 +170,6 @@ class MerchantService extends BaseService
 			$transaction->rollBack();
 			return false;
 		}
-
 	}
 
 }

+ 9 - 2
biz/saas/services/ApplyService.php

@@ -8,6 +8,7 @@ use biz\saas\classes\ApplyClass;
 use biz\user\services\UserService;
 use common\components\stringUtil;
 use common\components\util;
+use common\services\xhMerchantService;
 
 class ApplyService extends BaseService
 {
@@ -48,7 +49,13 @@ class ApplyService extends BaseService
 	//审核通过
 	public static function pass($id)
 	{
-	
+		$appData['merchantName'] = $nick_name;
+		$appData['shopProvince'] = '福建';
+		$appData['shopCity'] = '厦门';
+		$appData['shopDist'] = '思明区';
+		$appData['alipayAccount'] = 'shish@zhhinc.com';
+		$appData['alipayAccountName'] = '石少华';
+		xhMerchantService::applyCreateMerchant($appData);
 	}
-	
+
 }

+ 6 - 0
biz/weixin/services/WxOpenService.php

@@ -10,5 +10,11 @@ use Yii;
 class WxOpenService extends BaseService
 {
 	public static $baseFile = '\biz\weixin\classes\WxOpenClass';
+	
+	//获取当前开放平台信息 shish 2020.2.11
+	public static function getOpen()
+	{
+		return WxOpenClass::getById(1);
+	}
 
 }

+ 2 - 71
common/services/xhMerchantService.php

@@ -31,6 +31,7 @@ class xhMerchantService
 	 */
 	public static function qrCodeSave($url, $wxAppId)
 	{
+		return '';
 		$directory = configDict::getConfig('imgSavePath', 'wxMpQrcode');
 		$path = Yii::getAlias('@webroot') . '/../../images';
 		$pre = '/' . $directory . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
@@ -56,6 +57,7 @@ class xhMerchantService
 	 */
 	public static function logoSave($url, $wxAppId)
 	{
+		return '';
 		$directory = configDict::getConfig('imgSavePath', 'wxMpAvatar');
 		$path = Yii::getAlias('@webroot') . '/../../images';
 		$pre = '/' . $directory . '/' . date('Y') . '/' . date('m') . '/' . date("d") . '/';
@@ -91,77 +93,6 @@ class xhMerchantService
 		return ['small' => $pre . '_50.' . $extend, 'medium' => $pre . '_200.' . $extend, 'large' => $largeImg];
 	}
 	
-	/**
-	 * 申请时创建商家
-	 */
-	public static function applyCreateMerchant($data)
-	{
-		//生成商家
-		$date = date("Y-m-d H:i:s");
-		$alipayAccount = $data['alipayAccount'];//支付宝帐号
-		$alipayAccountName = isset($data['alipayAccountName']) ? $data['alipayAccountName'] : '';
-		unset($data['alipayAccount']);
-		$merchant = self::add($data);
-		$merchantId = $merchant['id'];
-		//生成商家资产
-		$assetData = [
-			'balance' => 0,
-			'totalVisit' => 0,
-			'totalUser' => 0,
-			'totalMember' => 0,
-			'totalFans' => 0,
-			'totalWeixinFans' => 0,
-			'totalIntegral' => 0,
-			'totalPoint' => 0,
-			'totalGoods' => 0,
-			'totalRecharge' => 0,
-			'totalOrder' => 0,
-			'totalDeal' => 0,
-			'merchantId' => $merchantId,
-			'totalIncome' => 0,
-			'totalExpend' => 0,
-			'createTime' => $date,
-			'updateTime' => $date,
-		];
-		xhMerchantAssetService::add($assetData);//商家资产表 
-		
-		//生成商家拓展信息
-		$extendData = [
-			'merchantId' => $merchantId,
-			'wxAppId' => isset($data['wxAppId']) ? $data['wxAppId'] : '',
-			'webTitle' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'webKeyword' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'webDescription' => isset($data['merchantName']) ? $data['merchantName'] : '',
-			'wxMenuInit' => 0,
-			'wxTMessageInit' => 0,
-			'payment' => 0,//支付功能关闭
-			'recharge' => 0,//充值功能关闭
-			'giveCoupon' => 1,//默认赠送代金劵
-			'giveCouponPrice' => 5,//代金劵金额5元
-			'couponMeetPrice' => 180,//满足金额
-			'couponValidity' => 30,//代金劵有效期30天
-			'alipayAccount' => $alipayAccount,//提现的支付宝帐号
-			'alipayAccountName' => $alipayAccountName,//提现支付宝帐号姓名
-			'gradeList' => '1_2000_9I2_5000_88I3_10000_85I4_20000_8',//1 级会员需要满 2000 积分 购物享9折;2 级会员需要满 5000 积分 购物享88折
-			'createTime' => $date,
-			'updateTime' => $date,
-		];
-		xhMerchantExtendService::add($extendData);
-
-		$setData = [
-			'merchantId' => $merchantId,
-			'riseType' => 0,
-			'riseAmount' => 0,
-			'addTime' => time(),
-		];
-		xhGoodsSettingService::add($setData, $merchantId);
-
-		//首页广告
-		//xhRecommendService::add($recommendData, $merchantId);
-
-		return $merchant;
-	}
-	
 	/**
 	 * 商家接入审核通过
 	 */