UserClass.php 23 KB

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