UserClass.php 19 KB

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