123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace App\Service;
- use App\Log;
- use App\RedisModel;
- class CustomerService
- {
- /**
- * 获取外部联系人信息
- * */
- public static function updateExternalInfo($corpid, $userId, $externalUserid, $state, $changeType)
- {
- $flag = true;
- $nextCursor = null;
- try {
- while($flag) {
- # 获取外部联系人详情
- $externalUserData = ExternalContactService::getExternalContactDetail($corpid, $externalUserid, $nextCursor);
- if(empty($externalUserData)) {
- if($externalUserData === false) {
- Log::logError('外部联系人详情获取失败', [
- 'corpid' => $corpid,
- 'user_id' => $userId,
- 'external_userid' => $externalUserid,
- 'state' => $state,
- 'change_type' => $changeType,
- 'nextCursor' => $nextCursor
- ], 'UpdateExternalContact');
- }
- $flag = false;
- continue;
- }
- # 更新外部联系人信息至数据库
- $customerId = 0;
- ExternalContactService::updateExternalContacts($externalUserData, $corpid, $userId, $state, $changeType, $customerId);
- if($customerId) {
- // $followInfo = [
- // 'createtime' => time(),
- // 'userid' => $userId,
- // ];
- // TagService::autoMarkCustomerAddDateTag($corpid, $customerId, $followInfo);
- # 设置自动标签
- $tagNameList = [date('Y年m月')];
- $redisArr = [
- 'corpid' => $corpid, 'user_id' => $userId, 'external_userid' => $externalUserid,
- 'tag_group_name' => '自动标签', 'tag_name_list' => $tagNameList, 'type' => 2
- ];
- RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_MARK_RDS, json_encode($redisArr, 1));
- }
- # 翻页查询外部联系人所有的关联员工
- if(isset($externalUserData['next_cursor']) && !empty($externalUserData['next_cursor'])) {
- $nextCursor = $externalUserData['next_cursor'];
- } else {
- $flag = false;
- }
- }
- } catch (\Exception $e) {
- Log::logError('获取外部联系人详情', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage(),
- 'corpid' => $corpid,
- 'user_id' => $userId,
- 'external_userid' => $externalUserid,
- 'state' => $state,
- 'change_type' => $changeType,
- 'nextCursor' => $nextCursor
- ], 'UpdateExternalContact-Exception');
- $flag = false;
- return false;
- }
- return true;
- }
- }
|