shish 5 gadi atpakaļ
vecāks
revīzija
eca22696e7

+ 2 - 3
app-mall/controllers/AuthController.php

@@ -137,7 +137,6 @@ class AuthController extends PublicController
 			util::fail('没有CODE信息');
 		}
 		$merchant = $this->merchant;
-		$account = $this->merchantId;
 		$appId = $merchant['miniAppId'];
 		$appSecret = $merchant['miniAppSecret'];
 		if (empty($appSecret)) {
@@ -156,9 +155,9 @@ class AuthController extends PublicController
 		}
 		$unionId = isset($arr['unionid']) && !empty($arr['unionid']) ? $arr['unionid'] : '';
 
-		$userInfo = ['miniOpenId' => $miniOpenId, 'merchantId' => $account, 'unionId' => $unionId];
+		$userInfo = ['miniOpenId' => $miniOpenId,'unionId' => $unionId];
 		$userSource = UserClass::$userSourceId['mini']['name'];
-		$user = UserService::replaceUser($userInfo, $userSource, $account);
+		$user = UserService::replaceUser($userInfo, $userSource);
 
 		$cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
 		Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);

+ 43 - 70
app-mall/controllers/BaseController.php

@@ -2,8 +2,6 @@
 
 namespace mall\controllers;
 
-use bizMall\stat\services\StatVisitService;
-use Yii;
 use bizMall\merchant\services\MerchantExtendService;
 use bizMall\merchant\services\MerchantService;
 use bizMall\user\services\UserService;
@@ -11,77 +9,52 @@ use common\components\httpUtil;
 use common\components\jwt;
 use common\components\util;
 
-/**
- * Created by PhpStorm.
- * User: shish <shish@zhhinc.com>
- * Date: 2019/11/18 0018
- * Time: 14:58
- */
 class BaseController extends PublicController
 {
-	
-	public $validate = true;
-	public $withoutLogin = [];//不需要登陆可以访问的方法
-	public $userId = 0, $user, $shopId;
-	public $merchantId, $merchant, $merchantExtend;
-	public $isWx;
-	
-	public function beforeAction($action)
-	{
-		//token验证
-		$userId = jwt::getLoginId();
-		$header = httpUtil::getHeader();
-		$merchantId = isset($header['account']) ? $header['account'] : 0;
-		$shopId = isset($header['shopId']) ? $header['shopId'] : 0;
-		if (empty($merchantId)) {
-			util::fail('商家无效');
-		}
-		$merchant = MerchantService::getMerchantById($merchantId);
-		if (empty($merchant)) {
-			util::fail('商家信息无效');
-		}
-		$this->merchantId = $merchantId;
-		$this->merchant = $merchant;
-		$this->shopId = $shopId;
-		$this->merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
-		$this->isWx = util::isWx();
 
-		//收集访问量
-		StatVisitService::gatherVisit($merchantId);
-		
-		//本地环境没有token时模拟一个可以用的帐号
-		if (getenv('YII_ENV') == 'local') {
-			$one = UserService::getByCondition(['merchantId'=>$merchantId]);
-			if (!empty($one)) {
-				$userId = $one['id'];
-			}
-		}
+    public $validate = true;
+    public $withoutLogin = [];//不需要登陆可以访问的方法
+    public $userId = 0, $user, $shopId;
+    public $merchantId, $merchant, $merchantExtend;
+    public $isWx;
 
-		if (empty($userId)) {
-			$this->validate = false;
-		} else {
-			$this->validate = true;
-			$this->userId = $userId;
-			$userInfo = UserService::getUserInfo($userId);
-			$this->user = $userInfo;
+    public function beforeAction($action)
+    {
+        //token验证
+        $userId = jwt::getLoginId();
+        $header = httpUtil::getHeader();
+        $merchantId = isset($header['account']) ? $header['account'] : 0;
+        $shopId = isset($header['shopId']) ? $header['shopId'] : 0;
+        if (empty($merchantId)) {
+            util::fail('商家无效');
+        }
+        $merchant = MerchantService::getMerchantById($merchantId);
+        if (empty($merchant)) {
+            util::fail('商家信息无效');
+        }
+        $this->merchantId = $merchantId;
+        $this->merchant = $merchant;
+        $this->shopId = $shopId;
+        $this->merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
+        $this->isWx = util::isWx();
+
+        if (empty($userId)) {
+            $this->validate = false;
+        } else {
+            $this->validate = true;
+            $this->userId = $userId;
+            $userInfo = UserService::getUserInfo($userId);
+            $this->user = $userInfo;
+        }
+        //游客可以访问的方法
+        if (in_array($action->id, $this->withoutLogin)) {
+            $this->validate = true;
+        }
+
+        if ($this->validate == false) {
+            util::notLogin();
+        }
+        return parent::beforeAction($action);
+    }
 
-			//更新用户访问时间
-			UserService::updateVisitTime($merchantId, $userId);
-			
-			//客户短时间访问二家商家的商城,登陆信息一致性问题
-			if ($userInfo['merchantId'] != $merchantId) {
-				util::logout();
-			}
-		}
-		//游客可以访问的方法
-		if (in_array($action->id, $this->withoutLogin)) {
-			$this->validate = true;
-		}
-		
-		if ($this->validate == false) {
-			util::notLogin();
-		}
-		return parent::beforeAction($action);
-	}
-	
 }

+ 3 - 3
app-mall/controllers/MapController.php

@@ -8,9 +8,9 @@ use Yii;
 
 class MapController extends BaseController
 {
-	
+
 	public $withoutLogin = ['suggestion'];
-	
+
 	//腾讯地图关键词输入提醒 shish 2020.1.21
 	public function actionSuggestion()
 	{
@@ -19,5 +19,5 @@ class MapController extends BaseController
 		$result = mapUtil::suggestion($region, $keyword);
 		util::success($result);
 	}
-	
+
 }

+ 1 - 1
app-mall/controllers/NoticeController.php

@@ -8,7 +8,7 @@ use common\services\xhUserAssetService;
 use common\services\xhUserService;
 use common\components\util;
 use common\services\xhOrderService;
-use common\components\configDict;
+use common\components\dict;
 use common\services\xhMerchantService;
 use common\services\xhPayToolService;
 

+ 6 - 11
app-mall/controllers/OrderController.php

@@ -2,8 +2,6 @@
 
 namespace mall\controllers;
 
-use bizMall\goods\services\CategoryService;
-use bizMall\goods\services\GoodsCategoryService;
 use bizMall\goods\services\GoodsService;
 use bizMall\merchant\services\ExpressService;
 use bizMall\merchant\services\MerchantExtendService;
@@ -13,15 +11,12 @@ use bizMall\order\services\OrderGoodsService;
 use bizMall\order\services\OrderService;
 use bizMall\promote\services\CouponService;
 use bizMall\saas\services\RegionService;
-use bizMall\user\services\UserAssetService;
 use bizMall\user\services\UserService;
-use common\components\configDict;
+use common\components\dict;
 use common\components\httpUtil;
-use common\components\miniUtil;
 use common\components\stringUtil;
 use common\services\xhPayToolService;
 use Yii;
-use yii\web\Controller;
 use common\components\util;
 
 class OrderController extends BaseController
@@ -162,7 +157,7 @@ class OrderController extends BaseController
         UserService::validPayPassword($payPassword, $user);
         //支付前验证订单有效性
         OrderService::checkBeforePay($order, $this->userId);
-        $typeList = configDict::getConfig('capitalType');
+        $typeList = dict::getConfig('capitalType');
         $capitalType = $typeList['xhOrder']['id'];
         $totalFee = $order['prePrice'];
         $sourceType = 0;
@@ -201,7 +196,7 @@ class OrderController extends BaseController
         } else {
             $openId = $this->user['openId'];
         }
-        $typeList = configDict::getConfig('capitalType');
+        $typeList = dict::getConfig('capitalType');
         $capitalType = $typeList['xhOrder']['id'];
         //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
         $wxPayType = 0;
@@ -319,7 +314,7 @@ class OrderController extends BaseController
             if (empty($openId)) {
                 util::fail('没有找到客户的openId');
             }
-            $typeList = configDict::getConfig('capitalType');
+            $typeList = dict::getConfig('capitalType');
             $capitalType = $typeList['xhOrder']['id'];
             //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调
             $wxPayType = 0;
@@ -396,7 +391,7 @@ class OrderController extends BaseController
             $body = '';//商品描述,可空
             $timeout_express = "1m";//超时时间
 
-            $typeList = configDict::getConfig('capitalType');
+            $typeList = dict::getConfig('capitalType');
             $capitalType = $typeList['xhOrder']['id'];
             $passbackParams = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&merchantId=' . $merchantId;//将流水类型、优惠卷传过去
             $passbackParams = urlencode($passbackParams);
@@ -422,7 +417,7 @@ class OrderController extends BaseController
             $payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
             $user = UserService::getUserInfo($this->userId, false);
             UserService::validPayPassword($payPassword, $user);
-            $typeList = configDict::getConfig('capitalType');
+            $typeList = dict::getConfig('capitalType');
             $capitalType = $typeList['xhOrder']['id'];
             $callbackParams = [];
             $respond = xhPayToolService::balancePay($callbackParams, $orderSn, $actPrice, $capitalType, $couponId);

+ 3 - 3
app-mall/controllers/PayController.php

@@ -24,7 +24,7 @@ use common\services\xhActiveService;
 use common\services\xhActiveTicketClassService;
 use common\components\util;
 use common\components\stringUtil;
-use common\components\configDict;
+use common\components\dict;
 
 class PayController extends BaseController
 {
@@ -48,7 +48,7 @@ class PayController extends BaseController
 		$calcDistance = util::getDistance($lat1, $lng1, $lat2, $lng2);//防止别人改动,PHP计算的距离会比腾讯js算的小,但能保证有一定准确性
 		$post['sendDistance'] = $post['sendDistance'] >= $calcDistance ? $post['sendDistance'] : $calcDistance;//二地距离
 		$sendDistance = $post['sendDistance'];
-		$freight = configDict::getConfig('freight');
+		$freight = dict::getConfig('freight');
 		$firstDistance = $freight['firstDistance'];
 		$firstPrice = $freight['firstPrice'];
 		$nextDistance = $freight['nextDistance'];
@@ -245,7 +245,7 @@ class PayController extends BaseController
 				util::fail('非法用户');
 			}
 			$openId = $user['openId'];
-			$typeList = configDict::getConfig('capitalType');
+			$typeList = dict::getConfig('capitalType');
 			$capitalType = $typeList['xhOrder']['id'];
 			$attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId;//将流水类型、优惠卷传过去
 			$weixin = Yii::getAlias("@vendor/weixin");

+ 3 - 3
app-mall/controllers/PaymentController.php

@@ -3,7 +3,7 @@ namespace mall\controllers;
 
 use common\components\util;
 
-use common\components\configDict;
+use common\components\dict;
 use common\services\xhOrderService;
 
 class PaymentController extends MobileendController
@@ -30,8 +30,8 @@ class PaymentController extends MobileendController
         $now					= time();
         $expireTime				= $now + 300*100;//订单5分钟后过期  ************************
 
-        $payAdd['payWay']		= configDict::getConfig('payWay','wxPay');
-        $payAdd['payStyle']		= configDict::getConfig('payStyle','wxPay');
+        $payAdd['payWay']		= dict::getConfig('payWay','wxPay');
+        $payAdd['payStyle']		= dict::getConfig('payStyle','wxPay');
         $payAdd['payStatus']	= 0;
         $payAdd['userId']		= 0; //订单所有者(默认为0,未定) $this->userId
         $payAdd['merchantId']	= $this->merchantId;

+ 20 - 19
app-mall/controllers/PublicController.php

@@ -2,7 +2,7 @@
 
 namespace mall\controllers;
 
-use bizMall\merchant\services\MerchantService;
+use bizHd\wx\classes\WxOpenClass;
 use common\components\baseController;
 use common\components\httpUtil;
 
@@ -11,22 +11,23 @@ use common\components\httpUtil;
  */
 class PublicController extends baseController
 {
-	
-	public $webTitle = '花卉宝';
-	public $webDescription = '花卉宝';
-	public $webKeyword = '花卉宝';
-	public $version;//公共静态文件版本号
-	public $merchant, $merchantId;
-	
-	public function beforeAction($action)
-	{
-		$this->version = '1.0.0';
-		$header = httpUtil::getHeader();
-		$account = isset($header['account']) ? $header['account'] : 0;
-		if (!empty($account)) {
-			$this->merchantId = $account;
-			$this->merchant = MerchantService::getMerchantById($account);
-		}
-		return parent::beforeAction($action);
-	}
+
+    public $webTitle = '花卉宝';
+    public $webDescription = '花卉宝';
+    public $webKeyword = '花卉宝';
+    public $version;//公共静态文件版本号
+    public $merchant, $merchantId;
+
+    public function beforeAction($action)
+    {
+        $this->version = '1.0.0';
+        $header = httpUtil::getHeader();
+        $account = isset($header['account']) ? $header['account'] : 0;
+
+        $this->merchantId = $account;
+        $this->merchant = WxOpenClass::getMallWxInfo();
+
+        return parent::beforeAction($action);
+    }
+
 }

+ 1 - 2
app-mall/controllers/RechargeController.php

@@ -8,7 +8,6 @@ use common\components\stringUtil;
 use common\components\util;
 use common\services\xhRechargeService;
 use Yii;
-use yii\web\Controller;
 
 class RechargeController extends BaseController
 {
@@ -57,7 +56,7 @@ class RechargeController extends BaseController
 			util::fail('没有找到用户信息 wx');
 		}
 
-		$typeList = configDict::getConfig('capitalType');
+		$typeList = dict::getConfig('capitalType');
 		$capitalType = $typeList['xhRecharge']['id'];
 		$attach = 'capitalType=' . $capitalType;//将流水类型、代金劵传过去
 		$wx = Yii::getAlias("@vendor/weixin");

+ 1 - 1
biz-mall/admin/classes/AdminClass.php

@@ -231,7 +231,7 @@ class AdminClass extends BaseClass
 		if (isset($originalAdmin['avatar']) == false || empty($originalAdmin['avatar'])) {
 			if (isset($getAdminInfo['headImgUrl']) && !empty($getAdminInfo['headImgUrl'])) {
 				$imgUrl = $getAdminInfo['headImgUrl'];
-				$name = ImageService::generateAvatar($merchantId, $imgUrl);
+				$name = ImageService::generateAvatar(0, $imgUrl);
 				if (!empty($name)) {
 					$data['avatar'] = $name;
 				}

+ 6 - 4
biz-mall/merchant/models/Merchant.php

@@ -1,13 +1,15 @@
 <?php
+
 namespace bizMall\merchant\models;
+
 use bizMall\base\models\Base;
 
 class Merchant extends Base
 {
 
-	public static function tableName()
-	{
-		return 'xhMerchant';
-	}
+    public static function tableName()
+    {
+        return 'xhSj';
+    }
 
 }

+ 1 - 1
biz-mall/merchant/models/MerchantAsset.php

@@ -7,7 +7,7 @@ class MerchantAsset extends Base
 
 	public static function tableName()
 	{
-		return 'xhMerchantAsset';
+		return 'xhSjAsset';
 	}
 
 }

+ 1 - 1
biz-mall/merchant/models/MerchantCapital.php

@@ -7,7 +7,7 @@ class MerchantCapital extends Base
 
 	public static function tableName()
 	{
-		return 'xhMerchantCapital';
+		return 'xhSjCapital';
 	}
 
 }

+ 2 - 4
biz-mall/merchant/models/MerchantExtend.php

@@ -6,12 +6,10 @@ use bizMall\base\models\Base;
 
 class MerchantExtend extends Base
 {
-	/**
-	 * @inheritdoc
-	 */
+
 	public static function tableName()
 	{
-		return 'xhMerchantExtend';
+		return 'xhSjExtend';
 	}
 	
 }

+ 1 - 1
biz-mall/merchant/models/MerchantInit.php

@@ -7,7 +7,7 @@ class MerchantInit extends Base
 
 	public static function tableName()
 	{
-		return 'xhMerchantInit';
+		return 'xhSjInit';
 	}
 
 }

+ 1 - 1
biz-mall/merchant/models/MerchantRemark.php

@@ -7,7 +7,7 @@ class MerchantRemark extends Base
 
 	public static function tableName()
 	{
-		return 'xhMerchantRemark';
+		return 'xhSjRemark';
 	}
 
 }

+ 1 - 12
biz-mall/merchant/services/MerchantAssetService.php

@@ -22,18 +22,7 @@ class MerchantAssetService extends BaseService
 	{
 		MerchantAssetClass::addUser($merchantId, $subscribe);
 	}
-	
-	//减少粉丝数 shish 2019.9.7
-	public static function reduceFans($merchantId)
-	{
-		MerchantAssetClass::reduceFans($merchantId);
-	}
-	
-	//会员数+1
-	public static function addMemberNum($merchantId)
-	{
-		MerchantAssetClass::addMemberNum($merchantId);
-	}
+
 	
 	//根据商家id批量取商家资产 shish 2019.12.20
 	public static function getAssetByMerchantIds($ids)

+ 1 - 1
biz-mall/user/classes/UserCapitalClass.php

@@ -7,7 +7,7 @@ use bizMall\merchant\services\MerchantService;
 use bizMall\message\classes\ChatClass;
 use bizMall\user\services\UserIntegralService;
 use common\components\business;
-use common\components\configDict;
+use common\components\dict;
 use common\components\util;
 use common\services\ImageService;
 use common\services\xhMerchantExtendService;

+ 563 - 580
biz-mall/user/classes/UserClass.php

@@ -8,7 +8,7 @@ use bizMall\merchant\services\MerchantService;
 use bizMall\message\classes\ChatClass;
 use bizMall\user\services\UserIntegralService;
 use common\components\business;
-use common\components\configDict;
+use common\components\dict;
 use common\components\util;
 use common\components\wxUtil;
 use common\services\ImageService;
@@ -21,584 +21,567 @@ use bizMall\base\classes\BaseClass;
 
 class UserClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizMall\user\models\User';
-	
-	//用户和收入的来源
-	public static $sourceType = [
-		2 => '朋友圈',
-		1 => '门店',
-		0 => '公众号',
-		3 => '淘宝',
-	];
-	
-	//用户来源分类
-	public static $userSource = [
-		0 => ['name' => 'official', 'title' => '公众号'],
-		1 => ['name' => 'alipay', 'title' => '支付宝'],
-		2 => ['name' => 'mini', 'title' => '小程序'],
-		3 => ['name' => 'friend', 'title' => '朋友圈'],
-		4 => ['name' => 'meituan', 'title' => '美团'],
-		5 => ['name' => 'system', 'title' => '系统'],
-	];
-	
-	//用户来源分类ID
-	public static $userSourceId = [
-		'official' => ['id' => 0, 'name' => 'official'],
-		'alipay' => ['id' => 1, 'name' => 'alipay'],
-		'mini' => ['id' => 2, 'name' => 'mini'],
-		'friend' => ['id' => 3, 'name' => 'friend'],
-		'meituan' => ['id' => 4, 'name' => 'meituan'],
-		'system' => ['id' => 5, 'name' => 'system'],
-	];
-	
-	//组合客户基本和资产信息
-	public static function groupUserBaseInfo($list, $sensitive = true)
-	{
-		//取客户资产
-		$ids = array_column($list, 'id');
-		$ids = array_unique($ids);
-		$asset = UserAssetClass::getByUserIds($ids, 'userId');
-		
-		$merchantIdList = array_column($list, 'merchantId');
-		$merchantIdList = array_filter(array_unique($merchantIdList));
-		$merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
-		
-		foreach ($list as $key => $val) {
-			$userId = $val['id'];
-			//访问时间
-			$visitTime = date("m-d H:i", $val['visitTime']);
-			if (date("m-d") == date("m-d", $val['visitTime'])) {
-				$visitTime = '今天 ' . date("H:i", $val['visitTime']);
-			}
-			$list[$key]['visitTimeFormat'] = $visitTime;
-			$list[$key]['userAsset'] = isset($asset[$userId]) ? $asset[$userId] : [];
-			//客户发来新消息数
-			$list[$key]['unReadNum'] = ChatClass::getUnreadNum($userId);
-			$list[$key] = business::formatUserAvatar($list[$key]);
-			$merchantId = $val['merchantId'];
-			$list[$key]['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
-			//敏感信息不要输出
-			if ($sensitive) {
-				unset($list[$key]['password']);
-				unset($list[$key]['payPassword']);
-			}
-		}
-		return $list;
-	}
-	
-	//获取客户基本和资产信息 shish 2019.11.30
-	public static function getUserInfo($id, $sensitive = true)
-	{
-		$list = self::getByIds([$id]);
-		$data = self::groupUserBaseInfo($list, $sensitive);
-		return current($data);
-	}
-	
-	//根据手机号查询客户 shish 2019.12.1
-	public static function getByMobile($mobile, $merchantId)
-	{
-		return self::getByCondition(['merchantId' => $merchantId, 'mobile' => $mobile]);
-	}
-	
-	public static function generateUser($getUserInfo, $merchantId)
-	{
-		$date = date("Y-m-d H:i:s");
-		$time = time();
-		//替换掉微信名称不支持的图片
-		$userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
-		$getUserInfo['userName'] = $userName;
-		$getUserInfo['nickName'] = $userName;
-		$getUserInfo['realName'] = isset($getUserInfo['realName']) && !empty($getUserInfo['realName']) ? $getUserInfo['realName'] : '';
-		$getUserInfo['sex'] = isset($getUserInfo['sex']) ? $getUserInfo['sex'] : 0;//未知
-		$getUserInfo['identity'] = 0;
-		$subscribe = isset($getUserInfo['subscribe']) ? $getUserInfo['subscribe'] : 0;
-		$getUserInfo['subscribe'] = $subscribe;
-		$getUserInfo['merchantId'] = $merchantId;
-		$getUserInfo['status'] = 0;
-		//默认没有完整用户信息
-		$isFull = isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl']) ? 1 : 0;
-		$getUserInfo['isFull'] = $isFull;
-		$getUserInfo['createTime'] = $date;
-		$getUserInfo['avatar'] = '';
-		$getUserInfo['password'] = '';
-		$getUserInfo['payPassword'] = '';
-		$getUserInfo['mobile'] = isset($getUserInfo['mobile']) ? $getUserInfo['mobile'] : '';
-		$getUserInfo['addTime'] = $time;
-		$getUserInfo['visitTime'] = $time;
-		$getUserInfo['source'] = isset($getUserInfo['source']) ? $getUserInfo['source'] : 0;
-		$getUserInfo['hasSubscribe'] = 0;
-		//生成用户基础信息
-		$user = self::add($getUserInfo);
-		$userId = $user['id'];
-		if (empty($user['userName'])) {
-			self::updateById($userId, ['userName' => $userId, 'nickName' => $userId]);
-		}
-		
-		$assetData = ['userId' => $userId, 'merchantId' => $merchantId, 'createTime' => $date];
-		//生成用户资产信息
-		UserAssetClass::add($assetData);
-		
-		//保存头像
-		if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
-			if (empty($preUser) || (isset($preUser['avatar']) && empty($preUser['avatar']))) {
-				$imgUrl = $getUserInfo['headImgUrl'];
-				$currentImg = ImageService::generateAvatar($merchantId, $imgUrl);
-				if (!empty($currentImg)) {
-					self::updateById($userId, ['avatar' => $currentImg]);
-				}
-			}
-		}
-		//客户数粉丝数增加
-		MerchantAssetClass::addUser($merchantId, $subscribe, true);
-		return $user;
-	}
-	
-	public static function updateUser($originalUser, $getUserInfo, $merchantId)
-	{
-		$data = [];
-		$assetData = [];
-		$userId = $originalUser['id'];
-		//替换掉微信不支持的图片
-		$userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
-		if (!empty($userName)) {
-			$data['userName'] = $userName;
-			$data['nickName'] = $userName;
-		}
-		if (isset($getUserInfo['openId']) && !empty($getUserInfo['openId'])) {
-			$openId = $getUserInfo['openId'];
-			$data['openId'] = $openId;
-		}
-		if (isset($getUserInfo['miniOpenId']) && !empty($getUserInfo['miniOpenId'])) {
-			$data['miniOpenId'] = $getUserInfo['miniOpenId'];
-		}
-		if (isset($getUserInfo['unionId']) && !empty($getUserInfo['unionId'])) {
-			$data['unionId'] = $getUserInfo['unionId'];
-		}
-		if (isset($getUserInfo['sex'])) {
-			$data['sex'] = $getUserInfo['sex'];
-		}
-		if (isset($getUserInfo['subscribe'])) {
-			$data['subscribe'] = $getUserInfo['subscribe'];
-		}
-		if (isset($getUserInfo['subscribeTime'])) {
-			$data['subscribeTime'] = $getUserInfo['subscribeTime'];
-		}
-		$data['merchantId'] = $merchantId;
-		if (isset($getUserInfo['alipayId']) && !empty($getUserInfo['alipayId'])) {
-			$data['alipayId'] = $getUserInfo['alipayId'];
-		}
-		if (isset($getUserInfo['isFull'])) {
-			$data['isFull'] = $getUserInfo['isFull'];
-		}
-		if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
-			$data['isFull'] = 1;
-		}
-		//更新头像
-		if (isset($originalUser['avatar']) == false || empty($originalUser['avatar'])) {
-			if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
-				$imgUrl = $getUserInfo['headImgUrl'];
-				$name = ImageService::generateAvatar($merchantId, $imgUrl);
-				if (!empty($name)) {
-					$data['avatar'] = $name;
-				}
-			}
-		}
-		//增加粉丝数
-		if (isset($originalUser['subscribe']) && $originalUser['subscribe'] == 0 && isset($getUserInfo['subscribe']) && $getUserInfo['subscribe'] == 1) {
-			MerchantAssetClass::addUser($merchantId, 1, false);
-		}
-		self::updateById($userId, $data);
-		if (!empty($assetData)) {
-			UserAssetClass::updateByUserId($userId, $assetData);
-		}
-		$user = self::getById($userId);
-		return $user;
-	}
-	
-	public static function getByMiniOpenId($miniOpenId)
-	{
-		return self::getByCondition(['miniOpenId' => $miniOpenId]);
-	}
-	
-	public static function getByAlipayId($alipayId, $merchantId)
-	{
-		return self::getByCondition(['merchantId' => $merchantId, 'alipayId' => $alipayId]);
-	}
-	
-	public static function getByOpenId($openId, $merchantId)
-	{
-		return self::getByCondition(['merchantId' => $merchantId, 'openId' => $openId]);
-	}
-	
-	public static function getByUnionId($unionId)
-	{
-		return self::getByCondition(['unionId' => $unionId]);
-	}
-	
-	//合并用户
-	public static function mergeUser($delUser, $retainUser)
-	{
-		$connection = Yii::$app->db;//事务处理
-		$transaction = $connection->beginTransaction();
-		try {
-			
-			$delUserId = $delUser['id'];
-			$retainUserId = $retainUser['id'];
-			
-			$userName = $retainUser['userName'];
-			$merchantId = $retainUser['merchantId'];
-			
-			//合并记录
-			$return = UserMergeClass::add([
-				'delUserId' => $delUserId,
-				'merchantId' => $merchantId,
-				'retainUserId' => $retainUserId,
-				'addTime' => time(),
-				'createTime' => date("Y-m-d H:i:s")
-			]);
-			$targetId = $return['id'];
-			
-			$typeList = configDict::getConfig('capitalType');
-			$capitalType = $typeList['xhMergeUser']['id'];
-			$now = time();
-			$date = date("Y-m-d H:i:s");
-			
-			//数据迁移
-			$updateData = [];
-			$updateKey = [
-				'mobile',
-				'password',
-				'payPassword',
-				'subscribe',
-				'hasSubscribe',
-				'subscribeTime',
-				'alipayId',
-				'openId',
-				'miniOpenId',
-				'unionId',
-			];
-			foreach ($updateKey as $key) {
-				if (isset($delUser[$key]) && !empty($delUser[$key])) {
-					$updateData[$key] = $delUser[$key];
-				}
-			}
-			if (!empty($updateData)) {
-				$updateData['visitTime'] = time();
-				self::updateById($retainUserId, $updateData);
-			}
-			
-			//资产累加
-			$addData = [];
-			$delUserAsset = UserAssetClass::getByUserId($delUserId);
-			$retainUserAsset = UserAssetClass::getByUserId($retainUserId);
-			if (!empty($delUserAsset)) {
-				//累计消费
-				$delTotalExpend = isset($delUserAsset['totalExpend']) ? $delUserAsset['totalExpend'] : 0;
-				if (!empty($delTotalExpend)) {
-					$addData['totalExpend'] = $retainUserAsset['totalExpend'] + $delTotalExpend;
-					//变化记录要增加
-				}
-				//累计收入
-				$delTotalIncome = isset($delUserAsset['totalIncome']) ? $delUserAsset['totalIncome'] : 0;
-				if (!empty($delTotalIncome)) {
-					$addData['totalIncome'] = $retainUserAsset['totalIncome'] + $delTotalIncome;
-					//变化记录要增加
-				}
-				//累计充值
-				$delTotalRecharge = isset($delUserAsset['totalRecharge']) ? $delUserAsset['totalRecharge'] : 0;
-				if (!empty($delTotalRecharge)) {
-					$addData['totalRecharge'] = $retainUserAsset['totalRecharge'] + $delTotalRecharge;
-					//变化记录要增加
-				}
-				//累计购买数量
-				$delTotalBuyNum = isset($delUserAsset['totalBuyNum']) ? $delUserAsset['totalBuyNum'] : 0;
-				if (!empty($delTotalBuyNum)) {
-					$addData['totalBuyNum'] = $retainUserAsset['totalBuyNum'] + $delTotalBuyNum;
-					//变化记录要增加
-				}
-				//余额
-				$delBalance = isset($delUserAsset['balance']) ? $delUserAsset['balance'] : 0;
-				if (!empty($delBalance)) {
-					$addData['balance'] = $retainUserAsset['balance'] + $delBalance;
-					//变化记录要增加
-					$userCapitalData = [
-						'relateId' => $targetId,
-						'balance' => $addData['balance'],
-						'totalIncome' => $retainUserAsset['totalIncome'] + $delBalance,
-						'totalExpend' => $retainUserAsset['totalExpend'],
-						'amount' => $delBalance,
-						'io' => 1,
-						'payWay' => 0,
-						'event' => '帐号合并',
-						'merchantId' => $merchantId,
-						'userId' => $retainUserId,
-						'alipayId' => '',
-						'userName' => $userName,
-						'operateId' => 0,
-						'createTime' => $date,
-						'addTime' => $now,
-						'capitalType' => $capitalType,
-					];
-					xhUserCapitalService::add($userCapitalData);//用户资金流水增加
-				}
-				
-				//成长值
-				$delGrowth = isset($delUserAsset['growth']) ? $delUserAsset['growth'] : 0;
-				if (!empty($delGrowth)) {
-					$addData['growth'] = $retainUserAsset['growth'] + $delGrowth;
-					//注意会员等级要进行重新计算!!!!!还有积分变化记录要增加
-					$growthData = [
-						'userId' => $retainUserId,
-						'userName' => $userName,
-						'merchantId' => $merchantId,
-						'relateId' => $targetId,
-						'integral' => $addData['growth'],
-						'num' => $delGrowth,
-						'io' => 1,
-						'payWay' => 0,
-						'alipayId' => '',
-						'event' => '帐号合并',
-						'operatorId' => 0,
-						'createTime' => $date,
-						'capitalType' => $capitalType,
-						'addTime' => $now,
-					];
-					UserGrowthClass::add($growthData);
-					//成长值增加升级
-					$preLevel = $retainUserAsset['member'];
-					$preGrowth = $retainUserAsset['growth'];
-					$merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId);
-					UserIntegralService::increaseToUpgrade($preGrowth, $addData['growth'], $preLevel, $retainUserId, $merchantId, $merchantExtend);
-				}
-				if (!empty($addData)) {
-					UserAssetClass::updateByUserId($retainUserId, $addData);
-				}
-			}
-			
-			//删除用户
-			$clearData = ['openId' => '', 'miniOpenId' => '', 'unionId' => '', 'alipayId' => '', 'merchantId' => 0, 'mobile' => ''];
-			self::updateById($delUserId, $clearData);
-			UserAssetClass::updateByUserId($delUserId, ['merchantId' => 0]);
-			//如果有支付宝信息则清除支付宝用户
-			UserAlipayClass::updateByUserId($delUserId, ['alipayId' => '', 'alipayAccount' => '', 'merchantId' => 0]);
-			
-			//合并帐号减少客户数 shish 2020.5.13
-			MerchantAssetClass::mergeToReduceUser($merchantId);
-			
-			$transaction->commit();
-			
-			return self::getById($retainUserId);
-			
-		} catch (Exception $e) {
-			$transaction->rollBack();
-			Yii::info("合并userid $delUserId $retainUserId 时事务回滚,原因:" . $e->getMessage());
-			return [];
-		}
-		
-	}
-	
-	//找出相同unionId的用户
-	public static function getSameUnionId($unionId)
-	{
-		return self::getAllByCondition(['unionId' => $unionId], 'addTime desc', '*', 'id');
-	}
-	
-	public static function valid($info, $merchantId)
-	{
-		if (empty($info)) {
-			util::fail('找不到客户');
-		}
-		if ($info['merchantId'] != $merchantId) {
-			util::fail('这个客户您没有权限操作');
-		}
-	}
-	
-	//根据消费次数和有没领优惠券来判断是不是新人
-	public static function newUser($userInfo)
-	{
-		$asset = isset($userInfo['userAsset']) ? $userInfo['userAsset'] : [];
-		$totalBuyNum = isset($asset['totalBuyNum']) ? $asset['totalBuyNum'] : 0;
-		if ($totalBuyNum > 0) {
-			return false;
-		}
-		$getCouponNum = isset($asset['getCouponNum']) ? $asset['getCouponNum'] : 0;
-		if ($getCouponNum) {
-			return false;
-		}
-		return true;
-	}
-	
-	public static function getUserByIds($ids)
-	{
-		$info = self::getByIds($ids, null, 'id');
-		if (empty($info)) {
-			return [];
-		}
-		$data = self::groupUserBaseInfo($info);
-		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['miniOpenId'])) {
-			$info['miniOpenId'] = $info['miniOpenId'];
-		}
-		if (isset($info['nickName'])) {
-			$info['userName'] = $info['nickName'];
-			$info['nickName'] = $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);
-		$unionId = isset($userInfo['unionId']) && !empty($userInfo['unionId']) ? $userInfo['unionId'] : '';
-		$unionUser = [];
-		if (!empty($unionId)) {
-			$unionUser = self::getByUnionId($unionId);
-		}
-		$userSource = self::$userSourceId;
-		switch ($source) {
-			case $userSource['mini']['name']:
-				$sourceId = $userSource['mini']['id'];
-				$miniOpenId = $userInfo['miniOpenId'];
-				$user = self::getByMiniOpenId($miniOpenId);
-				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;
-			case $userSource['system']['name']:
-				$sourceId = $userSource['system']['id'];
-				$mobile = isset($userInfo['mobile']) && !empty($userInfo['mobile']) ? $userInfo['mobile'] : '';
-				$user = [];
-				if (!empty($mobile)) {
-					$user = self::getByCondition(['merchantId' => $merchantId, 'mobile' => $mobile]);
-				}
-				break;
-			default:
-				throw new \Exception('未知来源的用户');
-		}
-		
-		//支付宝暂时获取不到很多客户信息不进行更新
-		if ($source == $userSource['alipay']['name']) {
-			if (!empty($user)) {
-				return $user;
-			}
-		}
-		if (empty($user)) {
-			if (!empty($unionUser)) {
-				//1、在小程序端已经授权用户信息和unionId之后,关注公众号时走这里
-				//2、关注了公众号或者H5已经授权时,并首次访问小程序
-				$user = self::updateUser($unionUser, $userInfo, $merchantId);
-			} else {
-				$userInfo['sourceType'] = $sourceId;
-				$userInfo['merchantId'] = $merchantId;
-				$user = self::generateUser($userInfo, $merchantId);
-			}
-		} else {
-			if (!empty($unionUser)) {
-				if (isset($unionUser['id']) && isset($user['id']) && $user['id'] != $unionUser['id']) {
-					//合并相同客户
-					$user = self::mergeUser($unionUser, $user);
-				}
-			}
-			$user = self::updateUser($user, $userInfo, $merchantId);
-		}
-		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'] = isset($val['nickname']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $val['nickname']) : '';
-				$val['merchantId'] = $merchantId;
-				self::replaceUser($val, $source, $merchantId);
-			}
-		}
-		return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
-	}
+
+    public static $baseFile = '\bizMall\user\models\User';
+
+    //用户和收入的来源
+    public static $sourceType = [
+        2 => '朋友圈',
+        1 => '门店',
+        0 => '公众号',
+        3 => '淘宝',
+    ];
+
+    //用户来源分类
+    public static $userSource = [
+        0 => ['name' => 'official', 'title' => '公众号'],
+        1 => ['name' => 'alipay', 'title' => '支付宝'],
+        2 => ['name' => 'mini', 'title' => '小程序'],
+        3 => ['name' => 'friend', 'title' => '朋友圈'],
+        4 => ['name' => 'meituan', 'title' => '美团'],
+        5 => ['name' => 'system', 'title' => '系统'],
+    ];
+
+    //用户来源分类ID
+    public static $userSourceId = [
+        'official' => ['id' => 0, 'name' => 'official'],
+        'alipay' => ['id' => 1, 'name' => 'alipay'],
+        'mini' => ['id' => 2, 'name' => 'mini'],
+        'friend' => ['id' => 3, 'name' => 'friend'],
+        'meituan' => ['id' => 4, 'name' => 'meituan'],
+        'system' => ['id' => 5, 'name' => 'system'],
+    ];
+
+    //组合客户基本和资产信息
+    public static function groupUserBaseInfo($list, $sensitive = true)
+    {
+        //取客户资产
+        $ids = array_column($list, 'id');
+        $ids = array_unique($ids);
+        $asset = UserAssetClass::getByUserIds($ids, 'userId');
+
+        $merchantIdList = array_column($list, 'merchantId');
+        $merchantIdList = array_filter(array_unique($merchantIdList));
+        $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
+
+        foreach ($list as $key => $val) {
+            $userId = $val['id'];
+            //访问时间
+            $visitTime = date("m-d H:i", $val['visitTime']);
+            if (date("m-d") == date("m-d", $val['visitTime'])) {
+                $visitTime = '今天 ' . date("H:i", $val['visitTime']);
+            }
+            $list[$key]['visitTimeFormat'] = $visitTime;
+            $list[$key]['userAsset'] = isset($asset[$userId]) ? $asset[$userId] : [];
+            //客户发来新消息数
+            $list[$key]['unReadNum'] = ChatClass::getUnreadNum($userId);
+            $list[$key] = business::formatUserAvatar($list[$key]);
+            $merchantId = $val['merchantId'];
+            $list[$key]['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
+            //敏感信息不要输出
+            if ($sensitive) {
+                unset($list[$key]['password']);
+                unset($list[$key]['payPassword']);
+            }
+        }
+        return $list;
+    }
+
+    //获取客户基本和资产信息 shish 2019.11.30
+    public static function getUserInfo($id, $sensitive = true)
+    {
+        $list = self::getByIds([$id]);
+        $data = self::groupUserBaseInfo($list, $sensitive);
+        return current($data);
+    }
+
+    //根据手机号查询客户 shish 2019.12.1
+    public static function getByMobile($mobile, $merchantId)
+    {
+        return self::getByCondition(['merchantId' => $merchantId, 'mobile' => $mobile]);
+    }
+
+    public static function generateUser($getUserInfo)
+    {
+        $date = date("Y-m-d H:i:s");
+        $time = time();
+        //替换掉微信名称不支持的图片
+        $userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
+        $getUserInfo['userName'] = $userName;
+        $getUserInfo['nickName'] = $userName;
+        $getUserInfo['realName'] = isset($getUserInfo['realName']) && !empty($getUserInfo['realName']) ? $getUserInfo['realName'] : '';
+        $getUserInfo['sex'] = isset($getUserInfo['sex']) ? $getUserInfo['sex'] : 0;//未知
+        $getUserInfo['identity'] = 0;
+        $subscribe = isset($getUserInfo['subscribe']) ? $getUserInfo['subscribe'] : 0;
+        $getUserInfo['subscribe'] = $subscribe;
+        $getUserInfo['status'] = 0;
+        //默认没有完整用户信息
+        $isFull = isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl']) ? 1 : 0;
+        $getUserInfo['isFull'] = $isFull;
+        $getUserInfo['createTime'] = $date;
+        $getUserInfo['avatar'] = '';
+        $getUserInfo['password'] = '';
+        $getUserInfo['payPassword'] = '';
+        $getUserInfo['mobile'] = isset($getUserInfo['mobile']) ? $getUserInfo['mobile'] : '';
+        $getUserInfo['addTime'] = $time;
+        $getUserInfo['visitTime'] = $time;
+        $getUserInfo['source'] = isset($getUserInfo['source']) ? $getUserInfo['source'] : 0;
+        $getUserInfo['hasSubscribe'] = 0;
+        //生成用户基础信息
+        $user = self::add($getUserInfo);
+        $userId = $user['id'];
+        if (empty($user['userName'])) {
+            self::updateById($userId, ['userName' => $userId, 'nickName' => $userId]);
+        }
+
+        //保存头像
+        if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
+            if (empty($preUser) || (isset($preUser['avatar']) && empty($preUser['avatar']))) {
+                $imgUrl = $getUserInfo['headImgUrl'];
+                $currentImg = ImageService::generateAvatar(0, $imgUrl);
+                if (!empty($currentImg)) {
+                    self::updateById($userId, ['avatar' => $currentImg]);
+                }
+            }
+        }
+
+        return $user;
+    }
+
+    public static function updateUser($originalUser, $getUserInfo)
+    {
+        $data = [];
+        $assetData = [];
+        $userId = $originalUser['id'];
+        //替换掉微信不支持的图片
+        $userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
+        if (!empty($userName)) {
+            $data['userName'] = $userName;
+            $data['nickName'] = $userName;
+        }
+        if (isset($getUserInfo['openId']) && !empty($getUserInfo['openId'])) {
+            $openId = $getUserInfo['openId'];
+            $data['openId'] = $openId;
+        }
+        if (isset($getUserInfo['miniOpenId']) && !empty($getUserInfo['miniOpenId'])) {
+            $data['miniOpenId'] = $getUserInfo['miniOpenId'];
+        }
+        if (isset($getUserInfo['unionId']) && !empty($getUserInfo['unionId'])) {
+            $data['unionId'] = $getUserInfo['unionId'];
+        }
+        if (isset($getUserInfo['sex'])) {
+            $data['sex'] = $getUserInfo['sex'];
+        }
+        if (isset($getUserInfo['subscribe'])) {
+            $data['subscribe'] = $getUserInfo['subscribe'];
+        }
+        if (isset($getUserInfo['subscribeTime'])) {
+            $data['subscribeTime'] = $getUserInfo['subscribeTime'];
+        }
+        if (isset($getUserInfo['alipayId']) && !empty($getUserInfo['alipayId'])) {
+            $data['alipayId'] = $getUserInfo['alipayId'];
+        }
+        if (isset($getUserInfo['isFull'])) {
+            $data['isFull'] = $getUserInfo['isFull'];
+        }
+        if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
+            $data['isFull'] = 1;
+        }
+        //更新头像
+        if (isset($originalUser['avatar']) == false || empty($originalUser['avatar'])) {
+            if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
+                $imgUrl = $getUserInfo['headImgUrl'];
+                $name = ImageService::generateAvatar($imgUrl);
+                if (!empty($name)) {
+                    $data['avatar'] = $name;
+                }
+            }
+        }
+        //增加粉丝数
+        if (isset($originalUser['subscribe']) && $originalUser['subscribe'] == 0 && isset($getUserInfo['subscribe']) && $getUserInfo['subscribe'] == 1) {
+            MerchantAssetClass::addUser(1, false);
+        }
+        self::updateById($userId, $data);
+        if (!empty($assetData)) {
+            UserAssetClass::updateByUserId($userId, $assetData);
+        }
+        $user = self::getById($userId);
+        return $user;
+    }
+
+    public static function getByMiniOpenId($miniOpenId)
+    {
+        return self::getByCondition(['miniOpenId' => $miniOpenId]);
+    }
+
+    public static function getByAlipayId($alipayId)
+    {
+        return self::getByCondition(['alipayId' => $alipayId]);
+    }
+
+    public static function getByOpenId($openId)
+    {
+        return self::getByCondition(['openId' => $openId]);
+    }
+
+    public static function getByUnionId($unionId)
+    {
+        return self::getByCondition(['unionId' => $unionId]);
+    }
+
+    //合并用户
+    public static function mergeUser($delUser, $retainUser)
+    {
+        $connection = Yii::$app->db;//事务处理
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $delUserId = $delUser['id'];
+            $retainUserId = $retainUser['id'];
+
+            $userName = $retainUser['userName'];
+            $merchantId = $retainUser['merchantId'];
+
+            //合并记录
+            $return = UserMergeClass::add([
+                'delUserId' => $delUserId,
+                'merchantId' => $merchantId,
+                'retainUserId' => $retainUserId,
+                'addTime' => time(),
+                'createTime' => date("Y-m-d H:i:s")
+            ]);
+            $targetId = $return['id'];
+
+            $typeList = dict::getConfig('capitalType');
+            $capitalType = $typeList['xhMergeUser']['id'];
+            $now = time();
+            $date = date("Y-m-d H:i:s");
+
+            //数据迁移
+            $updateData = [];
+            $updateKey = [
+                'mobile',
+                'password',
+                'payPassword',
+                'subscribe',
+                'hasSubscribe',
+                'subscribeTime',
+                'alipayId',
+                'openId',
+                'miniOpenId',
+                'unionId',
+            ];
+            foreach ($updateKey as $key) {
+                if (isset($delUser[$key]) && !empty($delUser[$key])) {
+                    $updateData[$key] = $delUser[$key];
+                }
+            }
+            if (!empty($updateData)) {
+                $updateData['visitTime'] = time();
+                self::updateById($retainUserId, $updateData);
+            }
+
+            //资产累加
+            $addData = [];
+            $delUserAsset = UserAssetClass::getByUserId($delUserId);
+            $retainUserAsset = UserAssetClass::getByUserId($retainUserId);
+            if (!empty($delUserAsset)) {
+                //累计消费
+                $delTotalExpend = isset($delUserAsset['totalExpend']) ? $delUserAsset['totalExpend'] : 0;
+                if (!empty($delTotalExpend)) {
+                    $addData['totalExpend'] = $retainUserAsset['totalExpend'] + $delTotalExpend;
+                    //变化记录要增加
+                }
+                //累计收入
+                $delTotalIncome = isset($delUserAsset['totalIncome']) ? $delUserAsset['totalIncome'] : 0;
+                if (!empty($delTotalIncome)) {
+                    $addData['totalIncome'] = $retainUserAsset['totalIncome'] + $delTotalIncome;
+                    //变化记录要增加
+                }
+                //累计充值
+                $delTotalRecharge = isset($delUserAsset['totalRecharge']) ? $delUserAsset['totalRecharge'] : 0;
+                if (!empty($delTotalRecharge)) {
+                    $addData['totalRecharge'] = $retainUserAsset['totalRecharge'] + $delTotalRecharge;
+                    //变化记录要增加
+                }
+                //累计购买数量
+                $delTotalBuyNum = isset($delUserAsset['totalBuyNum']) ? $delUserAsset['totalBuyNum'] : 0;
+                if (!empty($delTotalBuyNum)) {
+                    $addData['totalBuyNum'] = $retainUserAsset['totalBuyNum'] + $delTotalBuyNum;
+                    //变化记录要增加
+                }
+                //余额
+                $delBalance = isset($delUserAsset['balance']) ? $delUserAsset['balance'] : 0;
+                if (!empty($delBalance)) {
+                    $addData['balance'] = $retainUserAsset['balance'] + $delBalance;
+                    //变化记录要增加
+                    $userCapitalData = [
+                        'relateId' => $targetId,
+                        'balance' => $addData['balance'],
+                        'totalIncome' => $retainUserAsset['totalIncome'] + $delBalance,
+                        'totalExpend' => $retainUserAsset['totalExpend'],
+                        'amount' => $delBalance,
+                        'io' => 1,
+                        'payWay' => 0,
+                        'event' => '帐号合并',
+                        'merchantId' => $merchantId,
+                        'userId' => $retainUserId,
+                        'alipayId' => '',
+                        'userName' => $userName,
+                        'operateId' => 0,
+                        'createTime' => $date,
+                        'addTime' => $now,
+                        'capitalType' => $capitalType,
+                    ];
+                    xhUserCapitalService::add($userCapitalData);//用户资金流水增加
+                }
+
+                //成长值
+                $delGrowth = isset($delUserAsset['growth']) ? $delUserAsset['growth'] : 0;
+                if (!empty($delGrowth)) {
+                    $addData['growth'] = $retainUserAsset['growth'] + $delGrowth;
+                    //注意会员等级要进行重新计算!!!!!还有积分变化记录要增加
+                    $growthData = [
+                        'userId' => $retainUserId,
+                        'userName' => $userName,
+                        'merchantId' => $merchantId,
+                        'relateId' => $targetId,
+                        'integral' => $addData['growth'],
+                        'num' => $delGrowth,
+                        'io' => 1,
+                        'payWay' => 0,
+                        'alipayId' => '',
+                        'event' => '帐号合并',
+                        'operatorId' => 0,
+                        'createTime' => $date,
+                        'capitalType' => $capitalType,
+                        'addTime' => $now,
+                    ];
+                    UserGrowthClass::add($growthData);
+                    //成长值增加升级
+                    $preLevel = $retainUserAsset['member'];
+                    $preGrowth = $retainUserAsset['growth'];
+                    $merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId);
+                    UserIntegralService::increaseToUpgrade($preGrowth, $addData['growth'], $preLevel, $retainUserId, $merchantId, $merchantExtend);
+                }
+                if (!empty($addData)) {
+                    UserAssetClass::updateByUserId($retainUserId, $addData);
+                }
+            }
+
+            //删除用户
+            $clearData = ['openId' => '', 'miniOpenId' => '', 'unionId' => '', 'alipayId' => '', 'merchantId' => 0, 'mobile' => ''];
+            self::updateById($delUserId, $clearData);
+            UserAssetClass::updateByUserId($delUserId, ['merchantId' => 0]);
+            //如果有支付宝信息则清除支付宝用户
+            UserAlipayClass::updateByUserId($delUserId, ['alipayId' => '', 'alipayAccount' => '', 'merchantId' => 0]);
+
+            //合并帐号减少客户数 shish 2020.5.13
+            MerchantAssetClass::mergeToReduceUser($merchantId);
+
+            $transaction->commit();
+
+            return self::getById($retainUserId);
+
+        } catch (Exception $e) {
+            $transaction->rollBack();
+            Yii::info("合并userid $delUserId $retainUserId 时事务回滚,原因:" . $e->getMessage());
+            return [];
+        }
+
+    }
+
+    //找出相同unionId的用户
+    public static function getSameUnionId($unionId)
+    {
+        return self::getAllByCondition(['unionId' => $unionId], 'addTime desc', '*', 'id');
+    }
+
+    public static function valid($info, $merchantId)
+    {
+        if (empty($info)) {
+            util::fail('找不到客户');
+        }
+        if ($info['merchantId'] != $merchantId) {
+            util::fail('这个客户您没有权限操作');
+        }
+    }
+
+    //根据消费次数和有没领优惠券来判断是不是新人
+    public static function newUser($userInfo)
+    {
+        $asset = isset($userInfo['userAsset']) ? $userInfo['userAsset'] : [];
+        $totalBuyNum = isset($asset['totalBuyNum']) ? $asset['totalBuyNum'] : 0;
+        if ($totalBuyNum > 0) {
+            return false;
+        }
+        $getCouponNum = isset($asset['getCouponNum']) ? $asset['getCouponNum'] : 0;
+        if ($getCouponNum) {
+            return false;
+        }
+        return true;
+    }
+
+    public static function getUserByIds($ids)
+    {
+        $info = self::getByIds($ids, null, 'id');
+        if (empty($info)) {
+            return [];
+        }
+        $data = self::groupUserBaseInfo($info);
+        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['miniOpenId'])) {
+            $info['miniOpenId'] = $info['miniOpenId'];
+        }
+        if (isset($info['nickName'])) {
+            $info['userName'] = $info['nickName'];
+            $info['nickName'] = $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)
+    {
+        $userInfo = self::switchUserInfo($userInfo, $source);
+        $unionId = isset($userInfo['unionId']) && !empty($userInfo['unionId']) ? $userInfo['unionId'] : '';
+        $unionUser = [];
+        if (!empty($unionId)) {
+            $unionUser = self::getByUnionId($unionId);
+        }
+        $userSource = self::$userSourceId;
+        switch ($source) {
+            case $userSource['mini']['name']:
+                $sourceId = $userSource['mini']['id'];
+                $miniOpenId = $userInfo['miniOpenId'];
+                $user = self::getByMiniOpenId($miniOpenId);
+                break;
+            case $userSource['alipay']['name']:
+                $sourceId = $userSource['alipay']['id'];
+                $alipayId = $userInfo['alipayId'];
+                $user = self::getByAlipayId($alipayId);
+                break;
+            case $userSource['official']['name']:
+                $sourceId = $userSource['official']['id'];
+                //后台添加的客户没有openId
+                $openId = isset($userInfo['openId']) ? $userInfo['openId'] : '';
+                $user = [];
+                if (!empty($openId)) {
+                    $user = self::getByOpenId($openId);
+                }
+                break;
+            case $userSource['system']['name']:
+                $sourceId = $userSource['system']['id'];
+                $mobile = isset($userInfo['mobile']) && !empty($userInfo['mobile']) ? $userInfo['mobile'] : '';
+                $user = [];
+                if (!empty($mobile)) {
+                    $user = self::getByCondition(['mobile' => $mobile]);
+                }
+                break;
+            default:
+                throw new \Exception('未知来源的用户');
+        }
+        //支付宝暂时获取不到很多客户信息不进行更新
+        if ($source == $userSource['alipay']['name']) {
+            if (!empty($user)) {
+                return $user;
+            }
+        }
+        if (empty($user)) {
+            if (!empty($unionUser)) {
+                //1、在小程序端已经授权用户信息和unionId之后,关注公众号时走这里
+                //2、关注了公众号或者H5已经授权时,并首次访问小程序
+                $user = self::updateUser($unionUser, $userInfo);
+            } else {
+                $userInfo['sourceType'] = $sourceId;
+                $user = self::generateUser($userInfo);
+            }
+        }
+        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'] = isset($val['nickname']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $val['nickname']) : '';
+                $val['merchantId'] = $merchantId;
+                self::replaceUser($val, $source, $merchantId);
+            }
+        }
+        return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
+    }
 
 }

+ 1 - 1
biz-mall/user/classes/UserGrowthClass.php

@@ -7,7 +7,7 @@ use bizMall\merchant\services\MerchantService;
 use bizMall\message\classes\ChatClass;
 use bizMall\user\services\UserIntegralService;
 use common\components\business;
-use common\components\configDict;
+use common\components\dict;
 use common\components\util;
 use common\services\ImageService;
 use common\services\xhMerchantExtendService;

+ 1 - 1
biz-mall/user/classes/UserUpgradeClass.php

@@ -8,7 +8,7 @@ use bizMall\merchant\services\MerchantService;
 use bizMall\message\classes\ChatClass;
 use bizMall\user\services\UserIntegralService;
 use common\components\business;
-use common\components\configDict;
+use common\components\dict;
 use common\components\util;
 use common\components\wxUtil;
 use common\services\ImageService;

+ 3 - 8
biz-mall/user/services/UserService.php

@@ -59,9 +59,9 @@ class UserService extends BaseService
 	}
 	
 	//添加更新客户 shish 2020.2.7
-	public static function replaceUser($userInfo, $source, $merchantId)
+	public static function replaceUser($userInfo, $source)
 	{
-		return UserClass::replaceUser($userInfo, $source, $merchantId);
+		return UserClass::replaceUser($userInfo, $source);
 	}
 	
 	public static function getByOpenId($openId, $merchantId)
@@ -117,7 +117,7 @@ class UserService extends BaseService
 			foreach ($user_info_list as $val) {
 				$headImgUrl = $val['headimgurl'];
 				$openId = $val['openid'];
-				$img = ImageService::generateAvatar($merchantId, $headImgUrl);
+				$img = ImageService::generateAvatar(0, $headImgUrl);
 				if (!empty($img)) {
 					UserClass::updateByCondition(['openId' => $openId], ['avatar' => $img]);
 				}
@@ -170,17 +170,12 @@ class UserService extends BaseService
 		$userAsset = UserAssetClass::getByUserId($userId);
 		$user['mobile'] = $mobile;
 		CouponAssetClass::giveCoupon($user, $merchant, $userAsset);
-		
-		//增加会员数
-		MerchantAssetService::addMemberNum($merchantId);
 	}
 	
 	//取消关注 shish 2019.9.8
 	public static function unFocus($userId, $merchantId)
 	{
 		self::updateById($userId, ['subscribe' => 0, 'hasSubscribe' => 1]);
-		//商家粉丝减少
-		MerchantAssetClass::reduceFans($merchantId);
 	}
 	
 	//关注公众号的后续 shish 2020.5.5

+ 10 - 0
sql.sql

@@ -1696,3 +1696,13 @@ ALTER TABLE `xhOrder` CHANGE `receiveLat` `lat` VARCHAR(20) COLLATE utf8mb4_unic
 ALTER TABLE xhWxGzh ADD `auth` TINYINT NOT NULL DEFAULT 2 COMMENT '1已授权 2未授权' AFTER `openAppId`;
 ALTER TABLE xhWxMini CHANGE miniAuth `auth` TINYINT NOT NULL DEFAULT 1 COMMENT '1未授权 2已授权';
 ALTER TABLE xhWxGzh MODIFY `auth` TINYINT NOT NULL DEFAULT 1 COMMENT '1未授权 2已授权';
+
+TRUNCATE `xhUser`;
+TRUNCATE `xhUserAlipay`;
+TRUNCATE `xhUserAsset`;
+TRUNCATE `xhUserMerge`;
+TRUNCATE `xhUserPast`;
+TRUNCATE `xhUserTag`;
+TRUNCATE `xhUserTagClass`;
+TRUNCATE `xhUserUpgrade`;
+ALTER TABLE xhUser DROP COLUMN `merchantId`;