123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2023/4/7
- * Time: 11:22
- */
- namespace App\Service;
- use App\Log;
- use App\Models\CustomerDetails;
- use App\RedisModel;
- use App\Support\EmailQueue;
- class JiuZhouService
- {
- // 酷炫 猎豆 星橙
- public static $sysGroupIdList = ['2', '3', '51'];
- public static function orderList($params, $retry = 0)
- {
- $url = config('jiuzhou.request_url.order');
- $url .= '?'.http_build_query($params);
- $response = HttpService::httpGet($url);
- if($response === false && $retry <5) { // 发起重试
- $retry++;
- return JiuZhouService::orderList($params, $retry);
- }
- $responseData = json_decode($response, 1);
- Log::logInfo('九州订单', [
- 'params' => $params,
- 'response' => $responseData
- ], 'JiuZhouOrderList');
- if(isset($responseData['code']) && $responseData['code'] != 0) {
- EmailQueue::rPush('获取九州平台下的订单信息返回错误', $responseData['message'], ['song.shen@kuxuan-inc.com'],
- '猎羽');
- Log::logError('获取九州平台下的订单信息返回错误', ['response' => $responseData], 'JiuZhouApi');
- return [[], 0];
- }
- $data = $responseData['list'] ?? [];
- $count= $responseData['total_num'] ?? 0;
- return [$data, $count];
- }
- public static function getMsgTypeByCorpid($corpid) {
- foreach(self::$sysGroupIdList as $sysGroupId) {
- $corpList = RedisModel::get('Playlet::userCorpList-' . $sysGroupId);
- $corpList = !empty($corpList) ? json_decode($corpList, 1) : [];
- if(in_array($corpid, $corpList)) {
- if (2 == $sysGroupId) {
- return 'TPkuxuan';
- } else if(3 == $sysGroupId) {
- return 'TPliedou';
- } else if (51 == $sysGroupId) {
- return 'TPxingcheng';
- }
- }
- }
- return '';
- }
- # 获取九州平台需要的透传参数
- public static function getMsgId($corpid, $externalUserId, $userId = null, $retry = 3) {
- $query = CustomerDetails::suffix($corpid)->where('corpid', $corpid)
- ->where('external_userid', $externalUserId);
- if (empty($userId)) {
- $dataId = $query->orderBy('createtime', 'desc')->first(['id']);
- } else {
- $dataId = $query->where('user_id', $userId)->first(['id']);
- }
- $dataId = $dataId->id ?? null;
- # 当查询客户数据项ID为空时
- if(empty($dataId)) {
- if ($retry-- > 0) {
- sleep(1);
- return self::getMsgId($corpid, $externalUserId, $userId, $retry);
- } else {
- EmailQueue::rPush('获取九州短剧透传参数异常', json_encode([
- 'corpid' => $corpid,
- 'external_user_id' => $externalUserId,
- 'user_id' => $userId
- ], 256), 'song.shen@kuxuan-inc.com', '猎羽');
- }
- }
- $suffix = get_hash_code($corpid, 50);
- return $suffix.'|'.$dataId;
- }
- }
|