UserClass.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. <?php
  2. namespace biz\user\classes;
  3. use biz\merchant\classes\MerchantAssetClass;
  4. use biz\merchant\classes\MerchantClass;
  5. use biz\merchant\services\MerchantService;
  6. use biz\message\classes\ChatClass;
  7. use biz\user\services\UserIntegralService;
  8. use common\components\business;
  9. use common\components\configDict;
  10. use common\components\util;
  11. use common\components\wxUtil;
  12. use common\services\ImageService;
  13. use common\services\xhMerchantExtendService;
  14. use common\services\xhUserCapitalService;
  15. use common\services\xhUserIntegralService;
  16. use common\services\xhUserMergeService;
  17. use Yii;
  18. use biz\base\classes\BaseClass;
  19. class UserClass extends BaseClass
  20. {
  21. public static $baseFile = '\biz\user\models\User';
  22. //用户和收入的来源
  23. public static $sourceType = [
  24. 2 => '朋友圈',
  25. 1 => '门店',
  26. 0 => '公众号',
  27. 3 => '淘宝',
  28. ];
  29. //用户来源分类
  30. public static $userSource = [
  31. 0 => ['name' => 'official', 'title' => '公众号'],
  32. 1 => ['name' => 'alipay', 'title' => '支付宝'],
  33. 2 => ['name' => 'mini', 'title' => '小程序'],
  34. ];
  35. //用户来源分类ID
  36. public static $userSourceId = [
  37. 'official' => ['id' => 0, 'name' => 'official'],
  38. 'alipay' => ['id' => 1, 'name' => 'alipay'],
  39. 'mini' => ['id' => 2, 'name' => 'mini'],
  40. ];
  41. //组合客户基本和资产信息
  42. public static function groupUserBaseInfo($list)
  43. {
  44. //取客户资产
  45. $ids = array_column($list, 'id');
  46. $ids = array_unique($ids);
  47. $asset = UserAssetClass::getByUserIds($ids, 'userId');
  48. $merchantIdList = array_column($list, 'merchantId');
  49. $merchantIdList = array_filter(array_unique($merchantIdList));
  50. $merchantList = MerchantService::getByIds($merchantIdList, null, 'id');
  51. foreach ($list as $key => $val) {
  52. $userId = $val['id'];
  53. //访问时间
  54. $visitTime = date("m-d H:i", $val['visitTime']);
  55. if (date("m-d") == date("m-d", $val['visitTime'])) {
  56. $visitTime = '今天 ' . date("H:i", $val['visitTime']);
  57. }
  58. $list[$key]['visitTimeFormat'] = $visitTime;
  59. $list[$key]['userAsset'] = isset($asset[$userId]) ? $asset[$userId] : [];
  60. //客户发来新消息数
  61. $list[$key]['unReadNum'] = ChatClass::getUnreadNum($userId);
  62. $list[$key] = business::formatUserAvatar($list[$key]);
  63. $merchantId = $val['merchantId'];
  64. $list[$key]['merchantName'] = isset($merchantList[$merchantId]['merchantName']) ? $merchantList[$merchantId]['merchantName'] : '';
  65. }
  66. return $list;
  67. }
  68. //获取客户基本和资产信息 shish 2019.11.30
  69. public static function getUserInfo($id)
  70. {
  71. $list = self::getByIds([$id]);
  72. $data = self::groupUserBaseInfo($list);
  73. return current($data);
  74. }
  75. //根据手机号查询客户 shish 2019.12.1
  76. public static function getByMobile($mobile, $merchantId)
  77. {
  78. return self::getByCondition(['merchantId' => $merchantId, 'mobile' => $mobile]);
  79. }
  80. public static function generateUser($getUserInfo, $merchantId)
  81. {
  82. //替换掉微信不支持的图片
  83. $date = date("Y-m-d H:i:s");
  84. $time = time();
  85. $getUserInfo['userName'] = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
  86. $getUserInfo['realName'] = isset($getUserInfo['realName']) && !empty($getUserInfo['realName']) ? $getUserInfo['realName'] : '';
  87. $getUserInfo['sex'] = isset($getUserInfo['sex']) ? $getUserInfo['sex'] : 0;//未知
  88. $getUserInfo['identity'] = 0;
  89. $subscribe = isset($getUserInfo['subscribe']) ? $getUserInfo['subscribe'] : 0;
  90. $getUserInfo['subscribe'] = $subscribe;
  91. $getUserInfo['merchantId'] = $merchantId;
  92. $getUserInfo['status'] = 0;
  93. //默认没有完整用户信息
  94. $isFull = isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl']) ? 1 : 0;
  95. $getUserInfo['isFull'] = $isFull;
  96. $getUserInfo['createTime'] = $date;
  97. $getUserInfo['avatar'] = '';
  98. $getUserInfo['password'] = '';
  99. $getUserInfo['payPassword'] = '';
  100. $getUserInfo['mobile'] = isset($getUserInfo['mobile']) ? $getUserInfo['mobile'] : 0;
  101. $getUserInfo['addTime'] = $time;
  102. $getUserInfo['visitTime'] = $time;
  103. $getUserInfo['source'] = isset($getUserInfo['source']) ? $getUserInfo['source'] : 0;
  104. $getUserInfo['hasSubscribe'] = 0;
  105. //生成用户基础信息
  106. $user = self::add($getUserInfo);
  107. $userId = $user['id'];
  108. if (empty($user['userName'])) {
  109. self::updateById($userId, ['userName' => $userId]);
  110. }
  111. $assetData = ['userId' => $userId, 'merchantId' => $merchantId, 'createTime' => $date];
  112. //生成用户资产信息
  113. UserAssetClass::add($assetData);
  114. //保存头像
  115. if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
  116. if (empty($preUser) || (isset($preUser['avatar']) && empty($preUser['avatar']))) {
  117. $imgUrl = $getUserInfo['headImgUrl'];
  118. $name = ImageService::generateAvatar($merchantId, $imgUrl);
  119. self::updateById($userId, ['avatar' => $name]);
  120. }
  121. }
  122. //商家客户粉丝 +1
  123. $type = $subscribe == 1 ? 3 : 1;
  124. MerchantAssetClass::addUserNum($merchantId, $type);
  125. return $user;
  126. }
  127. public static function updateUser($originalUser, $getUserInfo, $merchantId)
  128. {
  129. $data = [];
  130. $assetData = [];
  131. $userId = $originalUser['id'];
  132. //替换掉微信不支持的图片
  133. $userName = isset($getUserInfo['userName']) ? preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $getUserInfo['userName']) : '';
  134. if (!empty($userName)) {
  135. $data['userName'] = $userName;
  136. }
  137. if (isset($getUserInfo['openId']) && !empty($getUserInfo['openId'])) {
  138. $openId = $getUserInfo['openId'];
  139. $data['openId'] = $openId;
  140. }
  141. if (isset($getUserInfo['miniOpenId']) && !empty($getUserInfo['miniOpenId'])) {
  142. $data['miniOpenId'] = $getUserInfo['miniOpenId'];
  143. }
  144. if (isset($getUserInfo['unionId']) && !empty($getUserInfo['unionId'])) {
  145. $data['unionId'] = $getUserInfo['unionId'];
  146. }
  147. if (isset($getUserInfo['sex'])) {
  148. $data['sex'] = $getUserInfo['sex'];
  149. }
  150. if (isset($getUserInfo['subscribe'])) {
  151. $data['subscribe'] = $getUserInfo['subscribe'];
  152. }
  153. if (isset($getUserInfo['subscribeTime'])) {
  154. $data['subscribeTime'] = $getUserInfo['subscribeTime'];
  155. }
  156. $data['merchantId'] = $merchantId;
  157. if (isset($getUserInfo['alipayId']) && !empty($getUserInfo['alipayId'])) {
  158. $data['alipayId'] = $getUserInfo['alipayId'];
  159. }
  160. if (isset($getUserInfo['isFull'])) {
  161. $data['isFull'] = $getUserInfo['isFull'];
  162. }
  163. if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
  164. $data['isFull'] = 1;
  165. }
  166. /**更新头像**/
  167. if (isset($originalUser['avatar']) == false || empty($originalUser['avatar'])) {
  168. if (isset($getUserInfo['headImgUrl']) && !empty($getUserInfo['headImgUrl'])) {
  169. $imgUrl = $getUserInfo['headImgUrl'];
  170. $name = ImageService::generateAvatar($merchantId, $imgUrl);
  171. $data['avatar'] = $name;
  172. }
  173. }
  174. /**商家增加粉丝**/
  175. if (isset($originalUser['subscribe']) && $originalUser['subscribe'] == 0 && isset($getUserInfo['subscribe']) && $getUserInfo['subscribe'] == 1) {
  176. MerchantAssetClass::addUserNum($merchantId, 2);
  177. }
  178. //更新访问时间
  179. self::updateById($userId, $data);
  180. if (!empty($assetData)) {
  181. UserAssetClass::updateByUserId($userId, $assetData);
  182. }
  183. $user = self::getById($userId);
  184. return $user;
  185. }
  186. public static function getByMiniOpenId($miniOpenId, $merchantId)
  187. {
  188. return self::getByCondition(['merchantId' => $merchantId, 'miniOpenId' => $miniOpenId]);
  189. }
  190. public static function getByAlipayId($alipayId, $merchantId)
  191. {
  192. return self::getByCondition(['merchantId' => $merchantId, 'alipayId' => $alipayId]);
  193. }
  194. public static function getByOpenId($openId, $merchantId)
  195. {
  196. return self::getByCondition(['merchantId' => $merchantId, 'openId' => $openId]);
  197. }
  198. public static function getByUnionId($unionId, $merchantId)
  199. {
  200. return self::getByCondition(['merchantId' => $merchantId, 'unionId' => $unionId]);
  201. }
  202. /**
  203. * 合并用户
  204. */
  205. public static function mergeUser($delUser, $retainUser)
  206. {
  207. $connection = Yii::$app->db;//事务处理
  208. $transaction = $connection->beginTransaction();
  209. try {
  210. $delUserId = $delUser['id'];
  211. $retainUserId = $retainUser['id'];
  212. $userName = $retainUser['userName'];
  213. $merchantId = $retainUser['merchantId'];
  214. //合并记录
  215. $return = UserMergeClass::add(['delUserId' => $delUserId, 'merchantId' => $merchantId, 'retainUserId' => $retainUserId, 'addTime' => time(), 'createTime' => date("Y-m-d H:i:s")]);
  216. $targetId = $return['id'];
  217. $typeList = configDict::getConfig('capitalType');
  218. $capitalType = $typeList['xhMergeUser']['id'];
  219. $now = time();
  220. $date = date("Y-m-d H:i:s");
  221. //数据迁移
  222. $updateData = [];
  223. $updateKey = [
  224. 'mobile',
  225. 'password',
  226. 'payPassword',
  227. 'subscribe',
  228. 'hasSubscribe',
  229. 'subscribeTime',
  230. 'alipayId',
  231. 'openId',
  232. 'miniOpenId',
  233. 'unionId',
  234. ];
  235. foreach ($updateKey as $key) {
  236. if (isset($delUser[$key]) && !empty($delUser[$key])) {
  237. $updateData[$key] = $delUser[$key];
  238. }
  239. }
  240. if (!empty($updateData)) {
  241. $updateData['visitTime'] = time();
  242. self::updateById($retainUserId, $updateData);
  243. }
  244. //资产累加
  245. $addData = [];
  246. $delUserAsset = UserAssetClass::getByUserId($delUserId);
  247. $retainUserAsset = UserAssetClass::getByUserId($retainUserId);
  248. if (!empty($delUserAsset)) {
  249. //累计消费
  250. $delTotalExpend = isset($delUserAsset['totalExpend']) ? $delUserAsset['totalExpend'] : 0;
  251. if (!empty($delTotalExpend)) {
  252. $addData['totalExpend'] = $retainUserAsset['totalExpend'] + $delTotalExpend;
  253. //变化记录要增加
  254. }
  255. //累计收入
  256. $delTotalIncome = isset($delUserAsset['totalIncome']) ? $delUserAsset['totalIncome'] : 0;
  257. if (!empty($delTotalIncome)) {
  258. $addData['totalIncome'] = $retainUserAsset['totalIncome'] + $delTotalIncome;
  259. //变化记录要增加
  260. }
  261. //累计充值
  262. $delTotalRecharge = isset($delUserAsset['totalRecharge']) ? $delUserAsset['totalRecharge'] : 0;
  263. if (!empty($delTotalRecharge)) {
  264. $addData['totalRecharge'] = $retainUserAsset['totalRecharge'] + $delTotalRecharge;
  265. //变化记录要增加
  266. }
  267. //累计购买数量
  268. $delTotalBuyNum = isset($delUserAsset['totalBuyNum']) ? $delUserAsset['totalBuyNum'] : 0;
  269. if (!empty($delTotalBuyNum)) {
  270. $addData['totalBuyNum'] = $retainUserAsset['totalBuyNum'] + $delTotalBuyNum;
  271. //变化记录要增加
  272. }
  273. //余额
  274. $delBalance = isset($delUserAsset['balance']) ? $delUserAsset['balance'] : 0;
  275. if (!empty($delBalance)) {
  276. $addData['balance'] = $retainUserAsset['balance'] + $delBalance;
  277. //变化记录要增加
  278. $userCapitalData = [
  279. 'relateId' => $targetId,
  280. 'balance' => $addData['balance'],
  281. 'totalIncome' => $retainUserAsset['totalIncome'] + $delBalance,
  282. 'totalExpend' => $retainUserAsset['totalExpend'],
  283. 'amount' => $delBalance,
  284. 'io' => 1,
  285. 'payWay' => 0,
  286. 'event' => '帐号合并',
  287. 'merchantId' => $merchantId,
  288. 'userId' => $retainUserId,
  289. 'alipayId' => '',
  290. 'userName' => $userName,
  291. 'operateId' => 0,
  292. 'createTime' => $date,
  293. 'addTime' => $now,
  294. 'capitalType' => $capitalType,
  295. ];
  296. xhUserCapitalService::add($userCapitalData);//用户资金流水增加
  297. }
  298. //成长值
  299. $delGrowth = isset($delUserAsset['growth']) ? $delUserAsset['growth'] : 0;
  300. if (!empty($delGrowth)) {
  301. $addData['growth'] = $retainUserAsset['growth'] + $delGrowth;
  302. //注意会员等级要进行重新计算!!!!!还有积分变化记录要增加
  303. $growthData = [
  304. 'userId' => $retainUserId,
  305. 'userName' => $userName,
  306. 'merchantId' => $merchantId,
  307. 'relateId' => $targetId,
  308. 'integral' => $addData['growth'],
  309. 'num' => $delGrowth,
  310. 'io' => 1,
  311. 'payWay' => 0,
  312. 'alipayId' => '',
  313. 'event' => '帐号合并',
  314. 'operatorId' => 0,
  315. 'createTime' => $date,
  316. 'capitalType' => $capitalType,
  317. 'addTime' => $now,
  318. ];
  319. UserGrowthClass::add($growthData);
  320. //成长值增加升级
  321. $preLevel = $retainUserAsset['member'];
  322. $preGrowth = $retainUserAsset['growth'];
  323. $merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId);
  324. UserIntegralService::increaseToUpgrade($preGrowth, $addData['growth'], $preLevel, $retainUserId, $merchantId, $merchantExtend);
  325. }
  326. if (!empty($addData)) {
  327. UserAssetClass::updateByUserId($retainUserId, $addData);
  328. }
  329. }
  330. //删除用户
  331. $clearData = ['openId' => '', 'miniOpenId' => '', 'unionId' => '', 'alipayId' => '', 'merchantId' => 0];
  332. self::updateById($delUserId, $clearData);
  333. UserAssetClass::updateByUserId($delUserId, ['merchantId' => 0]);
  334. //清除支付宝用户
  335. $clearAlipayData = ['alipayId' => '', 'alipayAccount' => '', 'merchantId' => 0];
  336. UserAlipayClass::updateByUserId($delUserId, $clearAlipayData);
  337. $transaction->commit();
  338. return self::getById($retainUserId);
  339. } catch (Exception $e) {
  340. $transaction->rollBack();
  341. Yii::info("合并userid $delUserId $retainUserId 时事务回滚,原因:" . $e->getMessage());
  342. return [];
  343. }
  344. }
  345. //找出相同unionId的用户
  346. public static function getSameUnionId($merchantId, $unionId)
  347. {
  348. return self::getAllByCondition(['merchantId' => $merchantId, 'unionId' => $unionId], 'addTime desc', '*');
  349. }
  350. public static function valid($info, $merchantId)
  351. {
  352. if (empty($info)) {
  353. util::fail('找不到客户');
  354. }
  355. if ($info['merchantId'] != $merchantId) {
  356. util::fail('这个客户您没有权限操作');
  357. }
  358. }
  359. //根据消费次数和有没领优惠券来判断是不是新人
  360. public static function newUser($userInfo)
  361. {
  362. $asset = isset($userInfo['userAsset']) ? $userInfo['userAsset'] : [];
  363. $totalBuyNum = isset($asset['totalBuyNum']) ? $asset['totalBuyNum'] : 0;
  364. if ($totalBuyNum > 0) {
  365. return false;
  366. }
  367. $getCouponNum = isset($asset['getCouponNum']) ? $asset['getCouponNum'] : 0;
  368. if ($getCouponNum) {
  369. return false;
  370. }
  371. return true;
  372. }
  373. public static function getUserByIds($ids)
  374. {
  375. $info = self::getByIds($ids, null, 'id');
  376. if (empty($info)) {
  377. return [];
  378. }
  379. $data = self::groupUserBaseInfo($info);
  380. return $data;
  381. }
  382. //将微信和小程序获取的用户信息转成可以保存的用户信息
  383. public static function switchUserInfo($info, $source)
  384. {
  385. $openId = '';
  386. if (isset($info['openid']) && !empty($info['openid'])) {
  387. $openId = $info['openid'];
  388. unset($info['openId']);
  389. }
  390. if (isset($info['openId']) && !empty($info['openId'])) {
  391. $openId = $info['openId'];
  392. unset($info['openId']);
  393. }
  394. if (!empty($openId)) {
  395. $userSource = self::$userSourceId;
  396. switch ($source) {
  397. case $userSource['mini']['name']:
  398. $info['miniOpenId'] = $openId;
  399. break;
  400. case $userSource['official']['name']:
  401. $info['openId'] = $openId;
  402. break;
  403. default:
  404. }
  405. }
  406. if (isset($info['nickname'])) {
  407. $info['userName'] = $info['nickname'];
  408. }
  409. if (isset($info['nickName'])) {
  410. $info['userName'] = $info['nickName'];
  411. }
  412. if (isset($info['unionid'])) {
  413. $info['unionId'] = $info['unionid'];
  414. }
  415. if (isset($info['unionId'])) {
  416. $info['unionId'] = $info['unionId'];
  417. }
  418. if (isset($info['headimgurl'])) {
  419. $info['headImgUrl'] = $info['headimgurl'];
  420. }
  421. if (isset($info['avatarUrl'])) {
  422. $info['headImgUrl'] = $info['avatarUrl'];
  423. }
  424. if (isset($info['subscribe_time'])) {
  425. $info['subscribeTime'] = $info['subscribe_time'];
  426. }
  427. if (isset($info['subscribe'])) {
  428. $info['subscribe'] = $info['subscribe'];
  429. }
  430. return $info;
  431. }
  432. //创建以及更新用户 shish 2020.2.7
  433. public static function replaceUser($userInfo, $source, $merchantId)
  434. {
  435. $userInfo = self::switchUserInfo($userInfo, $source);
  436. $userSource = self::$userSourceId;
  437. switch ($source) {
  438. case $userSource['mini']['name']:
  439. $sourceId = $userSource['mini']['id'];
  440. $miniOpenId = $userInfo['miniOpenId'];
  441. $user = self::getByMiniOpenId($miniOpenId, $merchantId);
  442. break;
  443. case $userSource['alipay']['name']:
  444. $sourceId = $userSource['alipay']['id'];
  445. $alipayId = $userInfo['alipayId'];
  446. $user = self::getByAlipayId($alipayId, $merchantId);
  447. break;
  448. case $userSource['official']['name']:
  449. $sourceId = $userSource['official']['id'];
  450. //老客添加没有openId
  451. $openId = isset($userInfo['openId']) ? $userInfo['openId'] : '';
  452. $user = [];
  453. if (!empty($openId)) {
  454. $user = self::getByOpenId($openId, $merchantId);
  455. }
  456. break;
  457. default:
  458. throw new \Exception('未知来源的用户');
  459. }
  460. if (empty($user)) {
  461. $userInfo['source'] = $sourceId;
  462. $userInfo['merchantId'] = $merchantId;
  463. $user = self::generateUser($userInfo, $merchantId);
  464. } else {
  465. //支付宝付款时不需要每次更新用户信息
  466. if ($source != $userSource['alipay']['name']) {
  467. $user = self::updateUser($user, $userInfo, $merchantId);
  468. }
  469. }
  470. //存在相同unionid则进行合并
  471. $unionId = isset($userInfo['unionId']) ? $userInfo['unionId'] : '';
  472. if (!empty($unionId)) {
  473. $same = self::getSameUnionId($merchantId, $unionId);
  474. if (count($same) == 2) {
  475. $delUser = $same[0];
  476. $retainUser = $same[1];
  477. $user = self::mergeUser($delUser, $retainUser);
  478. }
  479. }
  480. return $user;
  481. }
  482. //拉取粉丝 shish 2020.2.7
  483. public static function syncWxUser($merchantId, $nextOpenId = '')
  484. {
  485. $merchant = MerchantClass::getMerchantById($merchantId);
  486. //一次拉取调用最多拉取10000个关注者的OpenID
  487. $result = wxUtil::getSubscribeUserList($merchant, $nextOpenId);
  488. $total = isset($result['total']) ? $result['total'] : 0;
  489. $next_openid = isset($result['next_openid']) ? $result['next_openid'] : '';
  490. $count = isset($result['count']) ? $result['count'] : 0;
  491. $openIdList = isset($result['data']['openid']) ? $result['data']['openid'] : [];
  492. $currentTotal = count($openIdList);
  493. if ($count == 0 || $currentTotal == 0) {
  494. return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
  495. }
  496. $currentTotalPage = $currentTotal > 100 ? ceil($currentTotal / 100) : 1;
  497. $userSource = Yii::$app->dict->getValue('userSourceGetId', 'official');
  498. $source = $userSource['name'];
  499. for ($m = 1; $m <= $currentTotalPage; $m++) {
  500. $offset = ($m - 1) * 100;
  501. $subIdList = array_slice($openIdList, $offset, 100);
  502. $info = wxUtil::batchGetUserInfo($merchant, $subIdList);
  503. if (empty($info) || isset($info['user_info_list']) == false || empty($info['user_info_list'])) {
  504. continue;
  505. }
  506. $user_info_list = $info['user_info_list'];
  507. foreach ($user_info_list as $val) {
  508. $val['isFull'] = 1;
  509. $val['unionId'] = $val['unionid'];
  510. $val['headImgUrl'] = $val['headimgurl'];
  511. $val['openId'] = $val['openid'];
  512. $val['nickName'] = $val['nickname'];
  513. $val['merchantId'] = $merchantId;
  514. self::replaceUser($val, $source, $merchantId);
  515. }
  516. }
  517. return ['total' => $total, 'count' => $count, 'nextOpenId' => $next_openid];
  518. }
  519. }