12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/6/27
- * Time: 14:35
- */
- namespace App\Service;
- use App\Log;
- use App\Models\Customer;
- use App\Models\CustomerDetails;
- use App\RedisModel;
- use App\Support\EmailQueue;
- class ThirdPlatformService
- {
- // 修改客户标签
- public static function updateCustomerTag($params)
- {
- try{
- // $customerInfo = Customer::suffix($params['corpid'])
- // ->where('corpid', $params['corpid'])
- // ->where('enable', 1)
- // ->where('unionid', $params['unionid'])
- // ->first();
- //
- // if(empty($customerInfo)) {
- // Log::logError('updateCustomerTag', [
- // 'params' => $params,
- // 'errmsg' => '查询客户信息为空',
- // ], 'thirdPlatform');
- // return ['查询客户信息为空', 1102];
- // }
- // 查询客户是否在系统中
- $customerDetails = CustomerDetails::suffix($params['corpid'])
- ->where('corpid', $params['corpid'])
- ->where('remark_mobiles', 'like' , '%' . $params['phone'] . '%')
- ->where('enable', 1)
- ->get();
- if($customerDetails->isEmpty()) {
- Log::logError('updateCustomerTag', [
- 'params' => $params,
- 'errmsg' => '查询客户信息为空',
- ], 'thirdPlatform');
- return ['查询客户信息为空', 5002];
- }
- // 根据传递的标签名称获取对应的标签id
- $addTagIdList = CustomerTagService::getTagIdListByTagName($params['corpid'], $params['add_tag']);
- if(empty($addTagIdList)) {
- Log::logError('updateCustomerTag', [
- 'params' => $params,
- 'errmsg' => '查询标签结果异常',
- ], 'thirdPlatform');
- return ['查询标签结果异常', 5003];
- }
- foreach($customerDetails as $customerInfo) {
- $redisData = json_encode([
- 'corpid' => $customerInfo->corpid,
- 'user_id' => $customerInfo->user_id,
- 'external_userid' => $customerInfo->external_userid,
- 'tag_id_list' => $addTagIdList,
- ]);
- RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_UNIONID, $redisData);
- }
- return ['提交成功', 0];
- } catch (\Exception $exception) {
- // 日志记录
- Log::logError('updateCustomerTag', [
- 'params' => $params,
- 'file' => $exception->getFile(),
- 'line' => $exception->getLine(),
- 'message' => $exception->getMessage(),
- 'trace' => $exception->getTraceAsString(),
- ], 'thirdPlatform');
- // 报警
- EmailQueue::rPush('第三方调用修改客户标签异常', json_encode([
- 'params' => $params,
- 'line' => $exception->getLine(),
- 'message' => $exception->getFile(),
- 'trace' => $exception->getTraceAsString(),
- ]), ['song.shen@kuxuan-inc.com'], '');
- return ['系统异常,请稍后重试', 400];
- }
- }
- }
|