argument('type'); $this->date = $this->argument('date'); try { switch ($type) { case 1: # 柚子(没有主动拉取订单数据的接口) break; case 2: # 嘉书 break; case 3: # 迈步 break; case 4: # 点众阳光(订单中没有ua信息) break; case 5: # 花生 // $this->syncPeanutHistoryOrder(); break; case 6: # 容量 // $this->syncCapacityHistoryOrder(); break; case 7: # 九州(订单中没有ua信息) // $this->syncJiuZhouHistroyOrder(); break; case 8: # 映客(同触摸,信息已经保存好了,直接更新即可) // $this->syncYingKeHistoryOrder(); // 'update dj_order set `os`=`pay_type` where `order_source`=8'; break; case 9: # 触摸(不用跑,已经把信息保存起来了,执行一条sql更新即可) // $this->syncChuMoHistoryOrder(); // 'update dj_order set `os`=`pay_type` where `order_source`=9'; break; case 10: # 番茄(订单中没有ua信息) // $this->syncFanQieHistoryOrder(); break; default: $this->error('type参数异常'); break; } } catch (\Exception $e) { $this->error($e->getFile().'('.$e->getLine().'):'.$e->getMessage()); } } public function syncCapacityHistoryOrder() { if(!empty($this->date)) { $accountConfig = config('capacity.account'); foreach($accountConfig as $item) { $appId = $item['app_id']; $appSecret = $item['app_secret']; $sysGroupId = $item['sys_group_id']; $platformId = $item['platform_id']; $this->capacityOrderList($appId, $appSecret, $this->date, $sysGroupId, $platformId); } } else { $date = '2024-02-01'; while($date <= '2024-05-28') { $accountConfig = config('capacity.account'); foreach($accountConfig as $item) { $appId = $item['app_id']; $appSecret = $item['app_secret']; $sysGroupId = $item['sys_group_id']; $platformId = $item['platform_id']; $this->capacityOrderList($appId, $appSecret, $date, $sysGroupId, $platformId); } $date = date('Y-m-d', strtotime($date . ' +1 days')); } } } public function capacityOrderList($appId, $appSecret, $date, $sysGroupId, $platformId) { try { $this->page = 1; $orderId = 0; do{ $params['timestamp'] = time(); $params['method'] = 'order.list'; $params['param'] = [ 'date' => $date, 'pageNum' => $this->page, 'pageSize' => $this->limit ]; $params['appId'] = $appId; $secret = $appSecret; $params['signature'] = CapacityService::createSign($params['param'], $secret, $params['timestamp']); list($orderList, $count) = CapacityService::orderList($params); $this->info('处理日期 '.$date.' 的数据,第 '.$this->page.' 页,共获取数据 '.$count.' 条'); if(empty($orderList)) { // EmailQueue::rPush('获取容量平台下的订单结果为空', '', ['song.shen@kuxuan-inc.com'],'猎羽'); } # 订单信息入库 foreach ($orderList as $order) { $order['sys_group_id'] = $sysGroupId; $order['platform_id'] = $platformId; $order['order_source'] = 6; $userAgent = $order['userAgent'] ?? ''; # 从userAgent中提取设备信息 $deviceType = CapacityService::getDeviceType($userAgent); $order = CapacityService::dealPayInfo($order); if(1 == $order['order_pay_type'] && 1 != $deviceType) { Log::logError('容量平台订单设备信息异常', ['order_id' => $order['id']], 'SyncHistoryOrderException'); } $orderInfo = DjOrder::query() ->where('order_id', strval($order['id'])) ->where('order_source', $order['order_source']) ->first(); if(empty($orderInfo)) { Log::logError('容量平台订单信息不存在', ['order_id' => $order['id']], 'SyncHistoryOrderException'); continue; } $orderInfo->os = $deviceType; $orderInfo->user_agent = $userAgent; $orderInfo->save(); } $this->page++; sleep(1); } while($this->page <= ceil($count / $this->limit)); } catch (\Exception $e) { Log::logError('容量平台订单获取过程发生异常', [ 'file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'trace' => $e->getTraceAsString(), 'order_id' => $orderId, ], 'CapacityOrderList-Exception'); EmailQueue::rPush('容量平台订单获取过程发生异常', json_encode([ 'file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'order_id' => $orderId, ]), ['song.shen@kuxuan-inc.com'], '猎羽'); } } }