企微短剧业务系统

JiuZhouService.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2023/4/7
  6. * Time: 11:22
  7. */
  8. namespace App\Service;
  9. use App\Log;
  10. use App\Models\CustomerDetails;
  11. use App\RedisModel;
  12. use App\Support\EmailQueue;
  13. class JiuZhouService
  14. {
  15. // 酷炫 猎豆 星橙
  16. public static $sysGroupIdList = ['2', '3', '51'];
  17. public static function orderList($params, $retry = 0)
  18. {
  19. $url = config('jiuzhou.request_url.order');
  20. $url .= '?'.http_build_query($params);
  21. $response = HttpService::httpGet($url);
  22. if($response === false && $retry <5) { // 发起重试
  23. $retry++;
  24. return JiuZhouService::orderList($params, $retry);
  25. }
  26. $responseData = json_decode($response, 1);
  27. Log::logInfo('九州订单', [
  28. 'params' => $params,
  29. 'response' => $responseData
  30. ], 'JiuZhouOrderList');
  31. if(isset($responseData['code']) && $responseData['code'] != 0) {
  32. EmailQueue::rPush('获取九州平台下的订单信息返回错误', $responseData['message'], ['song.shen@kuxuan-inc.com'],
  33. '猎羽');
  34. Log::logError('获取九州平台下的订单信息返回错误', ['response' => $responseData], 'JiuZhouApi');
  35. return [[], 0];
  36. }
  37. $data = $responseData['list'] ?? [];
  38. $count= $responseData['total_num'] ?? 0;
  39. return [$data, $count];
  40. }
  41. public static function getMsgTypeByCorpid($corpid) {
  42. foreach(self::$sysGroupIdList as $sysGroupId) {
  43. $corpList = RedisModel::get('Playlet::userCorpList-' . $sysGroupId);
  44. $corpList = !empty($corpList) ? json_decode($corpList, 1) : [];
  45. if(in_array($corpid, $corpList)) {
  46. if (2 == $sysGroupId) {
  47. return 'TPkuxuan';
  48. } else if(3 == $sysGroupId) {
  49. return 'TPliedou';
  50. } else if (51 == $sysGroupId) {
  51. return 'TPxingcheng';
  52. }
  53. }
  54. }
  55. return '';
  56. }
  57. # 获取九州平台需要的透传参数
  58. public static function getMsgId($corpid, $externalUserId, $userId = null, $retry = 3) {
  59. $query = CustomerDetails::suffix($corpid)->where('corpid', $corpid)
  60. ->where('external_userid', $externalUserId);
  61. if (empty($userId)) {
  62. $dataId = $query->orderBy('createtime', 'desc')->first(['id']);
  63. } else {
  64. $dataId = $query->where('user_id', $userId)->first(['id']);
  65. }
  66. $dataId = $dataId->id ?? null;
  67. # 当查询客户数据项ID为空时
  68. if(empty($dataId)) {
  69. if ($retry-- > 0) {
  70. sleep(1);
  71. return self::getMsgId($corpid, $externalUserId, $userId, $retry);
  72. } else {
  73. EmailQueue::rPush('获取九州短剧透传参数异常', json_encode([
  74. 'corpid' => $corpid,
  75. 'external_user_id' => $externalUserId,
  76. 'user_id' => $userId
  77. ], 256), 'song.shen@kuxuan-inc.com', '猎羽');
  78. }
  79. }
  80. $suffix = get_hash_code($corpid, 50);
  81. return $suffix.'|'.$dataId;
  82. }
  83. }