shish 6 роки тому
батько
коміт
be643d0095

+ 2 - 2
app/business/controllers/TestController.php

@@ -97,11 +97,11 @@ class TestController extends BaseController
 	public function actionNotice()
 	{
 		$data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
-		$producer = Yii::$app->rabbitmq->getProducer('producerInform');
+		$producer = Yii::$app->rabbitmq->getProducer('informProducer');
 		echo '<pre>';
 		print_r($data);
 		$msg = serialize($data);
-		$r = $producer->publish($msg, 'exInform', 'routeInform');
+		$r = $producer->publish($msg, 'informExchange', 'informRoute');
 	}
 	
 }

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

@@ -154,12 +154,10 @@ class WxOpenController extends PublicController
 		$merchantId = $merchant['id'];
 		xhWxOpenService::updateById($wxOpenId, ['merchantId' => $merchantId]);
 
-		//商品、分类、首页幻灯片、门店图片
-		//创建门店
-		//创建管理员
-		//客户信息初始化
-		//初始化微信菜单
-		xhWxMenuService::applyInit($merchant);
+		$data = ['merchantId'=>$merchantId,'platform'=>1];
+		$producer = Yii::$app->rabbitmq->getProducer('openShopInitProducer');
+		$msg = serialize($data);
+		$producer->publish($msg, 'openShopInitExchange', 'openShopInitRoute');
 
 		echo 'ok';
 

+ 8 - 2
biz/admin/classes/AdminRoleClass.php

@@ -38,9 +38,9 @@ class AdminRoleClass extends BaseClass
 	//获取商家角色列表 shish 2019.12.10
 	public static function getRoleList($merchantId)
 	{
-		return self::getList('*',['merchantId' => $merchantId],'addTime DESC');
+		return self::getList('*', ['merchantId' => $merchantId], 'addTime DESC');
 	}
-
+	
 	//获取商家所有的角色名称 shish 2019.12.10
 	public static function getNameList($merchantId)
 	{
@@ -72,5 +72,11 @@ class AdminRoleClass extends BaseClass
 		$id = $role['id'];
 		return self::deleteById($id);
 	}
+	
+	//创建管理员角色 shish 2020.2.8
+	public static function addAdminRole($data)
+	{
+		return self::add($data);
+	}
 
 }

+ 6 - 0
biz/merchant/classes/AdminClass.php

@@ -18,4 +18,10 @@ class AdminClass extends BaseClass
 		'wx84d95afcb7b594eb' => ['oTFbYvsjwgVwXggwtlM2ESAKwuN8', 'oTFbYvqP6qwdCCkdFB9GYnlzDIUg'],
 	];
 
+	//创建管理员 shish
+	public static function addAdmin($data)
+	{
+		return self::add($data);
+	}
+
 }

+ 6 - 0
biz/merchant/classes/ShopClass.php

@@ -22,4 +22,10 @@ class ShopClass extends BaseClass
 		return isset($merchant['defaultShopId']) && !empty($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
 	}
 
+	//创建门店 shish 2020.2.8
+	public static function addShop($data)
+	{
+		return self::add($data);
+	}
+	
 }

+ 185 - 119
biz/merchant/services/MerchantService.php

@@ -2,135 +2,201 @@
 
 namespace biz\merchant\services;
 
+use biz\admin\classes\AdminRoleClass;
 use biz\auth\services\AuthService;
 use biz\base\services\BaseService;
+use biz\merchant\classes\AdminClass;
+use biz\merchant\classes\MerchantAssetClass;
 use biz\merchant\classes\MerchantClass;
+use biz\merchant\classes\ShopClass;
 use biz\saas\services\SetAuthService;
 use biz\saas\services\SetMealService;
+use biz\user\services\UserService;
 use common\components\business;
 use common\components\util;
+use common\services\xhWxMenuService;
 use Yii;
 
 class MerchantService extends BaseService
 {
-
-    public static $baseFile = '\biz\merchant\classes\MerchantClass';
-
-    //商家在业务端的权限 shish 2019.11.25
-    public static function getAuthIdList($merchantId, $endId)
-    {
-        $merchant = self::getById($merchantId);
-        $setId = $merchant['setId'];
-        if (empty($setId)) {
-            util::fail('没有找到商家的套餐');
-        }
-
-        //业务端总共有哪些权限
-        $idList = AuthService::getListId($endId);
-
-        //套餐在业务端有哪些权限
-        $setIdList = SetAuthService::getAuthIdList($setId, $endId);
-
-        //有*号表示有所有的权限
-        $commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
-
-        return $commonIdList;
-
-    }
-
-    //获取默认门店
-    public static function getDefaultShopId($merchant)
-    {
-        $defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
-        return $defaultShopId;
-    }
-
-    //商家基本信息,去除敏感信息 shish 2019.12.8
-    public static function getInfo($merchant, $extend)
-    {
-        $delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
-        foreach ($delete as $del) {
-            unset($merchant[$del]);
-        }
-        $deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
-        foreach ($deleteExtend as $delExtend) {
-            unset($extend[$delExtend]);
-        }
-
-        //设置计算方式
-        $freight = $extend['freight'];
-        $freightList = explode('_', $freight);
-        $extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
-        $extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
-        $merchant['extend'] = $extend;
-        $merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
-        return $merchant;
-    }
-
-    //常用链接 shish 2019.12.19
-    public static function getCommonUrlList()
-    {
-        $list = MerchantClass::$commonUrl;
-        return array_values($list);
-    }
-
-    //取指定常用链接 shish 2019.12.28
-    public static function getCommonUrl($id)
-    {
-        $list = MerchantClass::$commonUrl;
-        return isset($list[$id]) ? $list[$id] : [];
-    }
-
-    //取平台下的商家 shish 2019.12.20
-    public static function getSaasMerchant($where)
-    {
-        $data = MerchantClass::getList('*', $where, 'addTime DESC');
-        $list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
-        if (empty($list)) {
-            return $data;
-        }
-
-        //管理员
-        $adminIdList = array_column($list, 'adminId');
-        $admin = AdminService::getAdminByIds($adminIdList, null, 'id');
-        //商家资产
-        $merchantIdList = array_column($list, 'id');
-        $asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
-        //套餐
-        $setIdList = array_column($list, 'setId');
-        $set = SetMealService::getSetByIds($setIdList);
-        //拓展
-        $ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
-        foreach ($list as $key => $val) {
-            $adminId = $val['adminId'];
-            $merchantId = $val['id'];
-            $setId = $val['setId'];
-            $val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
-            $val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
-            $val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
-            $val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
-            $list[$key] = business::formatMerchantLogo($val);
-        }
-        $data['list'] = $list;
-        return $data;
-    }
-
-    //根据id批量取商家 shish 2019.12.20
-    public static function getMerchantByIds($ids)
-    {
-        return MerchantClass::getMerchantByIds($ids);
-    }
-
-    //获取商家 shish 2019.12.30
-    public static function getMerchantById($id)
-    {
-        return MerchantClass::getMerchantById($id);
-    }
-
-    public static function getCurrentSetId($id)
-    {
-        return MerchantClass::getCurrentSetId($id);
-    }
-
+	
+	public static $baseFile = '\biz\merchant\classes\MerchantClass';
+	
+	//商家在业务端的权限 shish 2019.11.25
+	public static function getAuthIdList($merchantId, $endId)
+	{
+		$merchant = self::getById($merchantId);
+		$setId = $merchant['setId'];
+		if (empty($setId)) {
+			util::fail('没有找到商家的套餐');
+		}
+		
+		//业务端总共有哪些权限
+		$idList = AuthService::getListId($endId);
+		
+		//套餐在业务端有哪些权限
+		$setIdList = SetAuthService::getAuthIdList($setId, $endId);
+		
+		//有*号表示有所有的权限
+		$commonIdList = in_array('*', $setIdList) ? $idList : array_intersect($idList, $setIdList);
+		
+		return $commonIdList;
+		
+	}
+	
+	//获取默认门店
+	public static function getDefaultShopId($merchant)
+	{
+		$defaultShopId = isset($merchant['defaultShopId']) ? $merchant['defaultShopId'] : 0;
+		return $defaultShopId;
+	}
+	
+	//商家基本信息,去除敏感信息 shish 2019.12.8
+	public static function getInfo($merchant, $extend)
+	{
+		$delete = ['miniAppId', 'miniAppSecret', 'wxAppId', 'wxAppSecret', 'openAppId', 'wxToken', 'wxJsApiTicket', 'wxAccessToken', 'wxRefreshToken'];
+		foreach ($delete as $del) {
+			unset($merchant[$del]);
+		}
+		$deleteExtend = ['miniAppId', 'miniAccessToken', 'miniRefreshToken', 'wxPayKey', 'wxPayMerchantId', 'wxAppId'];
+		foreach ($deleteExtend as $delExtend) {
+			unset($extend[$delExtend]);
+		}
+		
+		//设置计算方式
+		$freight = $extend['freight'];
+		$freightList = explode('_', $freight);
+		$extend['freightFirst'] = isset($freightList[0]) && is_numeric($freightList[0]) ? $freightList[0] : 5;
+		$extend['freightAdd'] = isset($freightList[1]) && is_numeric($freightList[1]) ? $freightList[1] : 2;
+		$merchant['extend'] = $extend;
+		$merchant['logoUrl'] = 'http://a.huahb.com/images/avatar.jpg';
+		return $merchant;
+	}
+	
+	//常用链接 shish 2019.12.19
+	public static function getCommonUrlList()
+	{
+		$list = MerchantClass::$commonUrl;
+		return array_values($list);
+	}
+	
+	//取指定常用链接 shish 2019.12.28
+	public static function getCommonUrl($id)
+	{
+		$list = MerchantClass::$commonUrl;
+		return isset($list[$id]) ? $list[$id] : [];
+	}
+	
+	//取平台下的商家 shish 2019.12.20
+	public static function getSaasMerchant($where)
+	{
+		$data = MerchantClass::getList('*', $where, 'addTime DESC');
+		$list = isset($data['list']) && !empty($data['list']) ? $data['list'] : [];
+		if (empty($list)) {
+			return $data;
+		}
+		
+		//管理员
+		$adminIdList = array_column($list, 'adminId');
+		$admin = AdminService::getAdminByIds($adminIdList, null, 'id');
+		//商家资产
+		$merchantIdList = array_column($list, 'id');
+		$asset = MerchantAssetService::getAssetByMerchantIds($merchantIdList);
+		//套餐
+		$setIdList = array_column($list, 'setId');
+		$set = SetMealService::getSetByIds($setIdList);
+		//拓展
+		$ext = MerchantExtendService::getExtendByMerchantIds($merchantIdList);
+		foreach ($list as $key => $val) {
+			$adminId = $val['adminId'];
+			$merchantId = $val['id'];
+			$setId = $val['setId'];
+			$val['adminName'] = isset($admin[$adminId]['adminName']) ? $admin[$adminId]['adminName'] : '';
+			$val['merchantAsset'] = isset($asset[$merchantId]) ? $asset[$merchantId] : [];
+			$val['setMealName'] = isset($set[$setId]) ? $set[$setId]['name'] : '';
+			$val['extend'] = isset($ext[$merchantId]) ? $ext[$merchantId] : [];
+			$list[$key] = business::formatMerchantLogo($val);
+		}
+		$data['list'] = $list;
+		return $data;
+	}
+	
+	//根据id批量取商家 shish 2019.12.20
+	public static function getMerchantByIds($ids)
+	{
+		return MerchantClass::getMerchantByIds($ids);
+	}
+	
+	//获取商家 shish 2019.12.30
+	public static function getMerchantById($id)
+	{
+		return MerchantClass::getMerchantById($id);
+	}
+	
+	public static function getCurrentSetId($id)
+	{
+		return MerchantClass::getCurrentSetId($id);
+	}
+	
+	//开店公众号授权之后初始化 shish 2020.2.7
+	public static function authInit($data)
+	{
+		$merchantId = $data['merchantId'];
+		$platform = $data['platform'];
+		$merchant = MerchantClass::getMerchantById($merchantId);
+		if (empty($merchant)) {
+		
+		}
+		$time = time();
+		$date = date("Y-m-d H:i:s");
+		$connection = Yii::$app->db;//事务处理
+		$transaction = $connection->beginTransaction();
+		try {
+			//平台使用的公众号
+			if ($platform == 1) {
+	
+			}
+
+			xhWxMenuService::applyInit($merchant);
+
+			//商品、分类、首页幻灯片、门店图片
+
+			//创建管理员
+
+			//初始化微信菜单
+			xhWxMenuService::applyInit($merchant);
+			//微信客户初始化
+			$return = UserService::syncWxAllUser($merchantId);
+			$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'];
+
+			//创建管理员角色
+			AdminRoleClass::addAdminRole(['roleName' => '店员', 'merchantId' => $merchantId, 'auth' => '*']);
+			$roleReturn = AdminRoleClass::addAdminRole(['roleName' => '店长', 'merchantId' => $merchantId, 'auth' => '*']);
+			$roleId = $roleReturn['id'];
+
+			//创建管理员
+			$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);
+		} catch (Exception $e) {
+			$transaction->rollBack();
+		}
+	}
 
 }

+ 1 - 1
biz/merchant/services/ShopService.php

@@ -64,5 +64,5 @@ class ShopService extends BaseService
 	{
 		return ShopClass::getDefaultShopId($merchant);
 	}
-	
+
 }

+ 2 - 2
biz/message/classes/InformAdminClass.php

@@ -29,10 +29,10 @@ class InformAdminClass extends BaseClass
 		}
 		$data = ['messageType' => 'inform', 'informWay' => 'wx', 'userType' => 'admin', 'id' => 6, 'mobile' => '15280215347'];
 		$data = array_merge($data, $respond);
-		$producer = Yii::$app->rabbitmq->getProducer('producerInform');
+		$producer = Yii::$app->rabbitmq->getProducer('informProducer');
 		$msg = serialize($data);
 		Yii::info('消息通知:' . $msg);
-		$producer->publish($msg, 'exInform', 'routeInform');
+		$producer->publish($msg, 'informExchange', 'informRoute');
 	}
 	
 	//送到通知 shish 2020.1.31

+ 144 - 0
biz/user/classes/UserClass.php

@@ -3,12 +3,14 @@
 namespace biz\user\classes;
 
 use biz\merchant\classes\MerchantAssetClass;
+use biz\merchant\classes\MerchantClass;
 use biz\merchant\services\MerchantService;
 use biz\message\classes\ChatClass;
 use biz\user\services\UserIntegralService;
 use common\components\business;
 use common\components\configDict;
 use common\components\util;
+use common\components\wxUtil;
 use common\services\ImageService;
 use common\services\xhMerchantExtendService;
 use common\services\xhUserCapitalService;
@@ -433,4 +435,146 @@ class UserClass extends BaseClass
 		return $data;
 	}
 	
+	//将微信和小程序获取的用户信息转成可以保存的用户信息
+	public static function switchUserInfo($info, $source)
+	{
+		$openId = '';
+		if (isset($info['openid']) && !empty($info['openid'])) {
+			$openId = $info['openid'];
+			unset($info['openId']);
+		}
+		if (isset($info['openId']) && !empty($info['openId'])) {
+			$openId = $info['openId'];
+			unset($info['openId']);
+		}
+		if (!empty($openId)) {
+			$userSource = self::$userSourceId;
+			switch ($source) {
+				case $userSource['mini']['name']:
+					$info['miniOpenId'] = $openId;
+					break;
+				case $userSource['official']['name']:
+					$info['openId'] = $openId;
+					break;
+				default:
+				
+			}
+		}
+		if (isset($info['nickname'])) {
+			$info['userName'] = $info['nickname'];
+		}
+		if (isset($info['nickName'])) {
+			$info['userName'] = $info['nickName'];
+		}
+		if (isset($info['unionid'])) {
+			$info['unionId'] = $info['unionid'];
+		}
+		if (isset($info['unionId'])) {
+			$info['unionId'] = $info['unionId'];
+		}
+		if (isset($info['headimgurl'])) {
+			$info['headImgUrl'] = $info['headimgurl'];
+		}
+		if (isset($info['avatarUrl'])) {
+			$info['headImgUrl'] = $info['avatarUrl'];
+		}
+		if (isset($info['subscribe_time'])) {
+			$info['subscribeTime'] = $info['subscribe_time'];
+		}
+		if (isset($info['subscribe'])) {
+			$info['subscribe'] = $info['subscribe'];
+		}
+		return $info;
+	}
+	
+	//创建以及更新用户 shish 2020.2.7
+	public static function replaceUser($userInfo, $source, $merchantId)
+	{
+		$userInfo = self::switchUserInfo($userInfo, $source);
+		$userSource = self::$userSourceId;
+		switch ($source) {
+			case $userSource['mini']['name']:
+				$sourceId = $userSource['mini']['id'];
+				$miniOpenId = $userInfo['miniOpenId'];
+				$user = self::getByMiniOpenId($miniOpenId, $merchantId);
+				break;
+			case $userSource['alipay']['name']:
+				$sourceId = $userSource['alipay']['id'];
+				$alipayId = $userInfo['alipayId'];
+				$user = self::getByAlipayId($alipayId, $merchantId);
+				break;
+			case $userSource['official']['name']:
+				$sourceId = $userSource['official']['id'];
+				//老客添加没有openId
+				$openId = isset($userInfo['openId']) ? $userInfo['openId'] : '';
+				$user = [];
+				if (!empty($openId)) {
+					$user = self::getByOpenId($openId, $merchantId);
+				}
+				break;
+			default:
+				throw new \Exception('未知来源的用户');
+		}
+		if (empty($user)) {
+			$userInfo['source'] = $sourceId;
+			$userInfo['merchantId'] = $merchantId;
+			$user = self::generateUser($userInfo, $merchantId);
+		} else {
+			//支付宝付款时不需要每次更新用户信息
+			if ($source != $userSource['alipay']['name']) {
+				$user = self::updateUser($user, $userInfo, $merchantId);
+			}
+		}
+		
+		//存在相同unionid则进行合并
+		$unionId = isset($userInfo['unionId']) ? $userInfo['unionId'] : '';
+		if (!empty($unionId)) {
+			$same = self::getSameUnionId($merchantId, $unionId);
+			if (count($same) == 2) {
+				$delUser = $same[0];
+				$retainUser = $same[1];
+				$user = self::mergeUser($delUser, $retainUser);
+			}
+		}
+		return $user;
+	}
+	
+	//拉取粉丝 shish 2020.2.7
+	public static function syncWxUser($merchantId, $nextOpenId = '')
+	{
+		$merchant = MerchantClass::getMerchantById($merchantId);
+		//一次拉取调用最多拉取10000个关注者的OpenID
+		$result = wxUtil::getSubscribeUserList($merchant, $nextOpenId);
+		$total = isset($result['total']) ? $result['total'] : 0;
+		$next_openid = isset($result['next_openid']) ? $result['next_openid'] : '';
+		$count = isset($result['count']) ? $result['count'] : 0;
+		$openIdList = isset($result['data']['openid']) ? $result['data']['openid'] : [];
+		$currentTotal = count($openIdList);
+		if ($count == 0 || $currentTotal == 0) {
+			return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
+		}
+		$currentTotalPage = $currentTotal > 100 ? ceil($currentTotal / 100) : 1;
+		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
+		$source = $userSource['name'];
+		for ($m = 1; $m <= $currentTotalPage; $m++) {
+			$offset = ($m - 1) * 100;
+			$subIdList = array_slice($openIdList, $offset, 100);
+			$info = wxUtil::batchGetUserInfo($merchant, $subIdList);
+			if (empty($info) || isset($info['user_info_list']) == false || empty($info['user_info_list'])) {
+				continue;
+			}
+			$user_info_list = $info['user_info_list'];
+			foreach ($user_info_list as $val) {
+				$val['isFull'] = 1;
+				$val['unionId'] = $val['unionid'];
+				$val['headImgUrl'] = $val['headimgurl'];
+				$val['openId'] = $val['openid'];
+				$val['nickName'] = $val['nickname'];
+				$val['merchantId'] = $merchantId;
+				self::replaceUser($val, $source, $merchantId);
+			}
+		}
+		return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
+	}
+	
 }

+ 11 - 149
biz/user/services/UserService.php

@@ -54,60 +54,10 @@ class UserService extends BaseService
 		return UserClass::getByMobile($mobile, $merchantId);
 	}
 	
-	/**
-	 * 创建以及更新用户
-	 * @author shish
-	 * @time 20190507
-	 */
+	//添加更新客户 shish 2020.2.7
 	public static function replaceUser($userInfo, $source, $merchantId)
 	{
-		$userInfo = self::switchUserInfo($userInfo, $source);
-		$userSource = UserClass::$userSourceId;
-		switch ($source) {
-			case $userSource['mini']['name']:
-				$sourceId = $userSource['mini']['id'];
-				$miniOpenId = $userInfo['miniOpenId'];
-				$user = UserClass::getByMiniOpenId($miniOpenId, $merchantId);
-				break;
-			case $userSource['alipay']['name']:
-				$sourceId = $userSource['alipay']['id'];
-				$alipayId = $userInfo['alipayId'];
-				$user = UserClass::getByAlipayId($alipayId, $merchantId);
-				break;
-			case $userSource['official']['name']:
-				$sourceId = $userSource['official']['id'];
-				//老客添加没有openId
-				$openId = isset($userInfo['openId']) ? $userInfo['openId'] : '';
-				$user = [];
-				if (!empty($openId)) {
-					$user = self::getByOpenId($openId, $merchantId);
-				}
-				break;
-			default:
-				throw new \Exception('未知来源的用户');
-		}
-		if (empty($user)) {
-			$userInfo['source'] = $sourceId;
-			$userInfo['merchantId'] = $merchantId;
-			$user = UserClass::generateUser($userInfo, $merchantId);
-		} else {
-			//支付宝付款时不需要每次更新用户信息
-			if ($source != $userSource['alipay']['name']) {
-				$user = UserClass::updateUser($user, $userInfo, $merchantId);
-			}
-		}
-		
-		//存在相同unionid则进行合并
-		$unionId = isset($userInfo['unionId']) ? $userInfo['unionId'] : '';
-		if (!empty($unionId)) {
-			$same = UserClass::getSameUnionId($merchantId, $unionId);
-			if (count($same) == 2) {
-				$delUser = $same[0];
-				$retainUser = $same[1];
-				$user = UserClass::mergeUser($delUser, $retainUser);
-			}
-		}
-		return $user;
+		return UserClass::replaceUser($userInfo, $source, $merchantId);
 	}
 	
 	public static function getByOpenId($openId, $merchantId)
@@ -120,49 +70,15 @@ class UserService extends BaseService
 		return UserClass::getByMiniOpenId($miniOpenId, $merchantId);
 	}
 	
-	/**
-	 * 同步微信用户信息
-	 * @author shish <shish@zhhinc.com>
-	 * @time 2019.5.11
-	 */
-	public static function syncWeixinUser($merchantId, $nextOpenId = '')
+	//同步微信用户 shish 2020.2.8
+	public static function syncWxAllUser($merchantId)
 	{
-		set_time_limit(0);
-		$merchant = xhMerchantService::getById($merchantId);
-		//一次拉取调用最多拉取10000个关注者的OpenID
-		$result = wxUtil::getSubscribeUserList($merchant, $nextOpenId);
-		$total = isset($result['total']) ? $result['total'] : 0;
-		$next_openid = isset($result['next_openid']) ? $result['next_openid'] : '';
-		$count = isset($result['count']) ? $result['count'] : 0;
-		$openIdList = isset($result['data']['openid']) ? $result['data']['openid'] : [];
-		if ($count == 0) {
-			return ['code' => 'A0001', 'msg' => '完成更新', 'data' => ['total' => $total]];
-		}
-		$total = count($openIdList);
-		$totalPage = $total > 100 ? ceil($total / 100) : 1;
-		
-		$userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
-		$source = $userSource['name'];
-		
-		for ($m = 1; $m <= $totalPage; $m++) {
-			$offset = ($m - 1) * 100;
-			$subIdList = array_slice($openIdList, $offset, 100);
-			$info = wxUtil::batchGetUserInfo($merchant, $subIdList);
-			if (empty($info) || isset($info['user_info_list']) == false || empty($info['user_info_list'])) {
-				continue;
-			}
-			$user_info_list = $info['user_info_list'];
-			foreach ($user_info_list as $val) {
-				$val['isFull'] = 1;
-				$val['unionId'] = $val['unionid'];
-				$val['headImgUrl'] = $val['headimgurl'];
-				$val['openId'] = $val['openid'];
-				$val['nickName'] = $val['nickname'];
-				$val['merchantId'] = $merchantId;
-				self::replaceUser($val, $source, $merchantId);
-			}
+		$return = UserClass::syncWxUser($merchantId);
+		while (isset($return['count']) && $return['count'] > 0 && isset($return['nextOpenId']) && !empty($return['nextOpenId'])) {
+			$nextOpenId = $return['nextOpenId'];
+			$return = UserClass::syncWxUser($merchantId, $nextOpenId);
 		}
-		return ['code' => 'A0001', 'msg' => '完成更新', 'data' => ['total' => $total]];
+		return ['total' => $return['total']];
 	}
 
 	//更新微信头像 shish 2020.1.12
@@ -198,7 +114,7 @@ class UserService extends BaseService
 		}
 		echo "更新成功\n";
 	}
-
+	
 	/**
 	 * 更新用户的访问时间
 	 */
@@ -220,60 +136,6 @@ class UserService extends BaseService
 		}
 	}
 	
-	/**
-	 * 将微信和小程序获取的用户信息转成可以保存的用户信息
-	 */
-	public static function switchUserInfo($info, $source)
-	{
-		$openId = '';
-		if (isset($info['openid']) && !empty($info['openid'])) {
-			$openId = $info['openid'];
-			unset($info['openId']);
-		}
-		if (isset($info['openId']) && !empty($info['openId'])) {
-			$openId = $info['openId'];
-			unset($info['openId']);
-		}
-		if (!empty($openId)) {
-			$userSource = UserClass::$userSourceId;
-			switch ($source) {
-				case $userSource['mini']['name']:
-					$info['miniOpenId'] = $openId;
-					break;
-				case $userSource['official']['name']:
-					$info['openId'] = $openId;
-					break;
-				default:
-					throw new \Exception('未知来源的用户');
-			}
-		}
-		
-		if (isset($info['nickname'])) {
-			$info['userName'] = $info['nickname'];
-		}
-		if (isset($info['nickName'])) {
-			$info['userName'] = $info['nickName'];
-		}
-		if (isset($info['unionid'])) {
-			$info['unionId'] = $info['unionid'];
-		}
-		if (isset($info['unionId'])) {
-			$info['unionId'] = $info['unionId'];
-		}
-		if (isset($info['headimgurl'])) {
-			$info['headImgUrl'] = $info['headimgurl'];
-		}
-		if (isset($info['avatarUrl'])) {
-			$info['headImgUrl'] = $info['avatarUrl'];
-		}
-		if (isset($info['subscribe_time'])) {
-			$info['subscribeTime'] = $info['subscribe_time'];
-		}
-		if (isset($info['subscribe'])) {
-			$info['subscribe'] = $info['subscribe'];
-		}
-		return $info;
-	}
 	
 	//升级成为会员,并更新用户相关信息 shish 2019.9.7
 	public static function upgradeToMember($userId, $merchantId, $data = [])
@@ -343,7 +205,7 @@ class UserService extends BaseService
 		$originalInfo['realName'] = $realName;
 		$originalInfo['userName'] = $realName;
 		
-		$user = UserService::replaceUser($originalInfo, $source, $merchantId);
+		$user = UserClass::replaceUser($originalInfo, $source, $merchantId);
 		
 		$extend = MerchantExtendService::getByMerchantId($merchantId);
 		

+ 10 - 22
common/components/rabbitmq/consumer/openShopInitConsumer.php

@@ -8,38 +8,26 @@
 
 namespace common\components\rabbitmq\consumer;
 
-use biz\message\services\InformAdminService;
-use biz\message\services\InformUserService;
+
+use biz\merchant\services\MerchantService;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 
 class openShopInitConsumer implements ConsumerInterface
 {
 	
-	/**
-	 * ConsumerInterface::MSG_ACK - Acknowledge message (mark as processed) and drop it from the queue
-	 * ConsumerInterface::MSG_REJECT - Reject and drop message from the queue
-	 * ConsumerInterface::MSG_REQUEUE - Reject and requeue message in RabbitMQ
-	 */
+	//开店初始化
 	public function execute(AMQPMessage $msg)
 	{
 		$data = unserialize($msg->body);
-		print_r($data);
-//		return ConsumerInterface::MSG_ACK;
-		$userType = $data['userType'];
-		if ($userType == 'user') {
-			$return = InformUserService::consumeInformQueue($data);
-			if ($return) {
-				return ConsumerInterface::MSG_ACK;
-			}
-		}
-		if ($userType == 'admin') {
-			$return = InformAdminService::consumeInformQueue($data);
-			if ($return) {
-				return ConsumerInterface::MSG_ACK;
-			}
+		$merchantId = isset($data['merchantId']) ? $data['merchantId'] : 0;
+		$platform = isset($data['platform']) ? $data['platform'] : 0;
+		$return = MerchantService::authInit(['merchantId'=>$merchantId,'platform'=>$platform]);
+		if (empty($merchantId)) {
+			return ConsumerInterface::MSG_ACK;
 		}
+		return ConsumerInterface::MSG_ACK;
 		return ConsumerInterface::MSG_REQUEUE;
 	}
-	
+
 }

+ 1 - 1
console/controllers/InitController.php

@@ -228,7 +228,7 @@ TRUNCATE xhUserByDay;";
 	public function actionPullUser()
 	{
 		$merchantId = 12359;
-		$return = UserService::syncWeixinUser($merchantId);
+		$return = UserService::syncWxAllUser($merchantId);
 		$total = isset($return['data']['total']) ? $return['data']['total'] : 0;
 		xhMerchantAssetService::updateByMerchantId($merchantId, ['totalFans' => $total]);
 	}