No Description

CustomerService.php 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\RedisModel;
  5. class CustomerService
  6. {
  7. /**
  8. * 获取外部联系人信息
  9. * */
  10. public static function updateExternalInfo($corpid, $userId, $externalUserid, $state, $changeType)
  11. {
  12. $flag = true;
  13. $nextCursor = null;
  14. try {
  15. while($flag) {
  16. # 获取外部联系人详情
  17. $externalUserData = ExternalContactService::getExternalContactDetail($corpid, $externalUserid, $nextCursor);
  18. if(empty($externalUserData)) {
  19. if($externalUserData === false) {
  20. Log::logError('外部联系人详情获取失败', [
  21. 'corpid' => $corpid,
  22. 'user_id' => $userId,
  23. 'external_userid' => $externalUserid,
  24. 'state' => $state,
  25. 'change_type' => $changeType,
  26. 'nextCursor' => $nextCursor
  27. ], 'UpdateExternalContact');
  28. }
  29. $flag = false;
  30. continue;
  31. }
  32. # 更新外部联系人信息至数据库
  33. $customerId = 0;
  34. ExternalContactService::updateExternalContacts($externalUserData, $corpid, $userId, $state, $changeType, $customerId);
  35. if($customerId) {
  36. // $followInfo = [
  37. // 'createtime' => time(),
  38. // 'userid' => $userId,
  39. // ];
  40. // TagService::autoMarkCustomerAddDateTag($corpid, $customerId, $followInfo);
  41. # 设置自动标签
  42. $tagNameList = [date('Y年m月')];
  43. $redisArr = [
  44. 'corpid' => $corpid, 'user_id' => $userId, 'external_userid' => $externalUserid,
  45. 'tag_group_name' => '自动标签', 'tag_name_list' => $tagNameList, 'type' => 2
  46. ];
  47. RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_MARK_RDS, json_encode($redisArr, 1));
  48. }
  49. # 翻页查询外部联系人所有的关联员工
  50. if(isset($externalUserData['next_cursor']) && !empty($externalUserData['next_cursor'])) {
  51. $nextCursor = $externalUserData['next_cursor'];
  52. } else {
  53. $flag = false;
  54. }
  55. }
  56. } catch (\Exception $e) {
  57. Log::logError('获取外部联系人详情', [
  58. 'line' => $e->getLine(),
  59. 'msg' => $e->getMessage(),
  60. 'corpid' => $corpid,
  61. 'user_id' => $userId,
  62. 'external_userid' => $externalUserid,
  63. 'state' => $state,
  64. 'change_type' => $changeType,
  65. 'nextCursor' => $nextCursor
  66. ], 'UpdateExternalContact-Exception');
  67. $flag = false;
  68. return false;
  69. }
  70. return true;
  71. }
  72. }