123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- <?php
- namespace App\Console\Repair;
- use App\Log;
- use App\Models\DjOrder;
- use App\Service\CapacityService;
- use App\Service\DjOrderService;
- use App\Service\Order\FanQieService;
- use App\Support\EmailQueue;
- use Illuminate\Console\Command;
- class SyncHistoryOrder extends Command
- {
- protected $signature = 'SyncHistoryOrder {type} {date?}';
- protected $description = '获取第三方平台历史订单';
- protected $page = 1;
- protected $limit = 100;
- protected $date;
- public function handle() {
- $type = $this->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'], '猎羽');
- }
- }
- }
|