123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace App\Services;
- use App\Models\Sys\SysCustomer;
- use App\Models\JxTransformRecord;
- use App\Support\EmailQueue;
- use App\Support\Log;
- class TransformService
- {
- public static function getTransformList($params, $page, $pageSize)
- {
- // 获取订单列表
- list($orderList, $total) = JxTransformRecord::getTransformList($params, $page, $pageSize);
- if(!$total) return [[], 0];
- // 获取当前页面客户信息
- $customerList = SysCustomer::select('id', 'name')
- ->whereIn('id', $orderList->pluck('customer_id'))
- ->where('enable', 1)
- ->get();
- foreach($orderList as $order) {
- // 所属客户信息补充
- $customerInfo = $customerList->where('id', $order->customer_id)->first();
- $order->customer_name = $customerInfo->name ?? '';
- // 所属平台信息补充
- $order->platform_name = JxTransformRecord::PLATFORM_LIST[$order->platform] ?? '未知';
- }
- return [$orderList, $total];
- }
- public static function uploadKwai($uploadTransformList, $transformType)
- {
- try{
- $uploadTransformList = json_decode($uploadTransformList, 1);
- # 定义返回数据结构
- $result = [
- 'stat' => ['success' => 0, 'fail' => 0, 'total' => count($uploadTransformList)],
- 'data' => []
- ];
- foreach($uploadTransformList as $value) {
- if(in_array($value['task_id'], ['1054157749954837', '1054157535090288', '1054157125538975'])) {
- $transformType = 84;
- }
- # 回传链接
- $callbackUrl = $value['callback_url'] ?? '';
- if(empty($callbackUrl)) {
- $result['stat']['fail']++;
- $result['data'][] = [
- 'id' => $value['id'],
- 'msg' => '回传链接为空'
- ];
- continue;
- }
- # 行为数据ID
- $id = $value['id'] ?? '';
- if(empty($id)) {
- $result['stat']['fail']++;
- $result['data'][] = [
- 'id' => $value['id'],
- 'msg' => '行为数据ID为空'
- ];
- continue;
- }
- # 回传结果
- $reportActionType = $value['report_action_type'] ?? '';
- if(!is_numeric($reportActionType) || $reportActionType != 0) {
- $result['stat']['fail']++;
- $result['data'][] = [
- 'id' => $value['id'],
- 'msg' => '回传状态错误,必须是未回传行为才可以回传'
- ];
- continue;
- }
- # 执行回传
- $uploadRstJson = HttpService::httpGet($callbackUrl . '&event_type=' . $transformType . '&event_time=' . time() . rand(100, 999) );
- $uploadRst = json_decode($uploadRstJson, 1);
- Log::info('回传结果', [$uploadRstJson], 'UploadKwai');
- $uploadStatus = $uploadRst['result'] ?? 0;
- if($uploadStatus != 1) {
- $result['stat']['fail']++;
- $result['data'][] = [
- 'id' => $value['id'],
- 'msg' => '回传失败' . $uploadRstJson
- ];
- continue;
- } else {
- # 修改回传状态
- JxTransformRecord::where('id', $id)->update(['report_action_type' => 2, 'report_order_status' => 1]);
- $result['stat']['success']++;
- }
- }
- }catch(\Exception $e) {
- EmailQueue::rPush('上传数据失败', json_encode([
- 'type' => $transformType,
- 'data' => $uploadTransformList,
- 'error' => $e->getMessage()]), ['xiaohua.hou@kuxuan-inc.com'], '聚星');
- return [[], 1087];
- }
- return [$result, 0];
- }
- }
|