企微短剧业务系统

ThirdPlatformService.php 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/6/27
  6. * Time: 14:35
  7. */
  8. namespace App\Service;
  9. use App\Log;
  10. use App\Models\Customer;
  11. use App\Models\CustomerDetails;
  12. use App\RedisModel;
  13. use App\Support\EmailQueue;
  14. class ThirdPlatformService
  15. {
  16. // 修改客户标签
  17. public static function updateCustomerTag($params)
  18. {
  19. try{
  20. // $customerInfo = Customer::suffix($params['corpid'])
  21. // ->where('corpid', $params['corpid'])
  22. // ->where('enable', 1)
  23. // ->where('unionid', $params['unionid'])
  24. // ->first();
  25. //
  26. // if(empty($customerInfo)) {
  27. // Log::logError('updateCustomerTag', [
  28. // 'params' => $params,
  29. // 'errmsg' => '查询客户信息为空',
  30. // ], 'thirdPlatform');
  31. // return ['查询客户信息为空', 1102];
  32. // }
  33. // 查询客户是否在系统中
  34. $customerDetails = CustomerDetails::suffix($params['corpid'])
  35. ->where('corpid', $params['corpid'])
  36. ->where('remark_mobiles', 'like' , '%' . $params['phone'] . '%')
  37. ->where('enable', 1)
  38. ->get();
  39. if($customerDetails->isEmpty()) {
  40. Log::logError('updateCustomerTag', [
  41. 'params' => $params,
  42. 'errmsg' => '查询客户信息为空',
  43. ], 'thirdPlatform');
  44. return ['查询客户信息为空', 5002];
  45. }
  46. // 根据传递的标签名称获取对应的标签id
  47. $addTagIdList = CustomerTagService::getTagIdListByTagName($params['corpid'], $params['add_tag']);
  48. if(empty($addTagIdList)) {
  49. Log::logError('updateCustomerTag', [
  50. 'params' => $params,
  51. 'errmsg' => '查询标签结果异常',
  52. ], 'thirdPlatform');
  53. return ['查询标签结果异常', 5003];
  54. }
  55. foreach($customerDetails as $customerInfo) {
  56. $redisData = json_encode([
  57. 'corpid' => $customerInfo->corpid,
  58. 'user_id' => $customerInfo->user_id,
  59. 'external_userid' => $customerInfo->external_userid,
  60. 'tag_id_list' => $addTagIdList,
  61. ]);
  62. RedisModel::lPush(CustomerTagService::CUSTOMER_TAG_UNIONID, $redisData);
  63. }
  64. return ['提交成功', 0];
  65. } catch (\Exception $exception) {
  66. // 日志记录
  67. Log::logError('updateCustomerTag', [
  68. 'params' => $params,
  69. 'file' => $exception->getFile(),
  70. 'line' => $exception->getLine(),
  71. 'message' => $exception->getMessage(),
  72. 'trace' => $exception->getTraceAsString(),
  73. ], 'thirdPlatform');
  74. // 报警
  75. EmailQueue::rPush('第三方调用修改客户标签异常', json_encode([
  76. 'params' => $params,
  77. 'line' => $exception->getLine(),
  78. 'message' => $exception->getFile(),
  79. 'trace' => $exception->getTraceAsString(),
  80. ]), ['song.shen@kuxuan-inc.com'], '');
  81. return ['系统异常,请稍后重试', 400];
  82. }
  83. }
  84. }