企微短剧业务系统

SyncHistoryOrder.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. namespace App\Console\Repair;
  3. use App\Log;
  4. use App\Models\DjOrder;
  5. use App\Service\CapacityService;
  6. use App\Service\DjOrderService;
  7. use App\Service\Order\FanQieService;
  8. use App\Support\EmailQueue;
  9. use Illuminate\Console\Command;
  10. class SyncHistoryOrder extends Command
  11. {
  12. protected $signature = 'SyncHistoryOrder {type} {date?}';
  13. protected $description = '获取第三方平台历史订单';
  14. protected $page = 1;
  15. protected $limit = 100;
  16. protected $date;
  17. public function handle() {
  18. $type = $this->argument('type');
  19. $this->date = $this->argument('date');
  20. try {
  21. switch ($type) {
  22. case 1: # 柚子(没有主动拉取订单数据的接口)
  23. break;
  24. case 2: # 嘉书
  25. break;
  26. case 3: # 迈步
  27. break;
  28. case 4: # 点众阳光(订单中没有ua信息)
  29. break;
  30. case 5: # 花生
  31. // $this->syncPeanutHistoryOrder();
  32. break;
  33. case 6: # 容量
  34. // $this->syncCapacityHistoryOrder();
  35. break;
  36. case 7: # 九州(订单中没有ua信息)
  37. // $this->syncJiuZhouHistroyOrder();
  38. break;
  39. case 8: # 映客(同触摸,信息已经保存好了,直接更新即可)
  40. // $this->syncYingKeHistoryOrder();
  41. // 'update dj_order set `os`=`pay_type` where `order_source`=8';
  42. break;
  43. case 9: # 触摸(不用跑,已经把信息保存起来了,执行一条sql更新即可)
  44. // $this->syncChuMoHistoryOrder();
  45. // 'update dj_order set `os`=`pay_type` where `order_source`=9';
  46. break;
  47. case 10: # 番茄(订单中没有ua信息)
  48. // $this->syncFanQieHistoryOrder();
  49. break;
  50. default:
  51. $this->error('type参数异常');
  52. break;
  53. }
  54. } catch (\Exception $e) {
  55. $this->error($e->getFile().'('.$e->getLine().'):'.$e->getMessage());
  56. }
  57. }
  58. public function syncCapacityHistoryOrder() {
  59. if(!empty($this->date)) {
  60. $accountConfig = config('capacity.account');
  61. foreach($accountConfig as $item) {
  62. $appId = $item['app_id'];
  63. $appSecret = $item['app_secret'];
  64. $sysGroupId = $item['sys_group_id'];
  65. $platformId = $item['platform_id'];
  66. $this->capacityOrderList($appId, $appSecret, $this->date, $sysGroupId, $platformId);
  67. }
  68. } else {
  69. $date = '2024-02-01';
  70. while($date <= '2024-05-28') {
  71. $accountConfig = config('capacity.account');
  72. foreach($accountConfig as $item) {
  73. $appId = $item['app_id'];
  74. $appSecret = $item['app_secret'];
  75. $sysGroupId = $item['sys_group_id'];
  76. $platformId = $item['platform_id'];
  77. $this->capacityOrderList($appId, $appSecret, $date, $sysGroupId, $platformId);
  78. }
  79. $date = date('Y-m-d', strtotime($date . ' +1 days'));
  80. }
  81. }
  82. }
  83. public function capacityOrderList($appId, $appSecret, $date, $sysGroupId, $platformId)
  84. {
  85. try {
  86. $this->page = 1;
  87. $orderId = 0;
  88. do{
  89. $params['timestamp'] = time();
  90. $params['method'] = 'order.list';
  91. $params['param'] = [
  92. 'date' => $date,
  93. 'pageNum' => $this->page,
  94. 'pageSize' => $this->limit
  95. ];
  96. $params['appId'] = $appId;
  97. $secret = $appSecret;
  98. $params['signature'] = CapacityService::createSign($params['param'], $secret, $params['timestamp']);
  99. list($orderList, $count) = CapacityService::orderList($params);
  100. $this->info('处理日期 '.$date.' 的数据,第 '.$this->page.' 页,共获取数据 '.$count.' 条');
  101. if(empty($orderList)) {
  102. // EmailQueue::rPush('获取容量平台下的订单结果为空', '', ['song.shen@kuxuan-inc.com'],'猎羽');
  103. }
  104. # 订单信息入库
  105. foreach ($orderList as $order) {
  106. $order['sys_group_id'] = $sysGroupId;
  107. $order['platform_id'] = $platformId;
  108. $order['order_source'] = 6;
  109. $userAgent = $order['userAgent'] ?? '';
  110. # 从userAgent中提取设备信息
  111. $deviceType = CapacityService::getDeviceType($userAgent);
  112. $order = CapacityService::dealPayInfo($order);
  113. if(1 == $order['order_pay_type'] && 1 != $deviceType) {
  114. Log::logError('容量平台订单设备信息异常', ['order_id' => $order['id']], 'SyncHistoryOrderException');
  115. }
  116. $orderInfo = DjOrder::query()
  117. ->where('order_id', strval($order['id']))
  118. ->where('order_source', $order['order_source'])
  119. ->first();
  120. if(empty($orderInfo)) {
  121. Log::logError('容量平台订单信息不存在', ['order_id' => $order['id']], 'SyncHistoryOrderException');
  122. continue;
  123. }
  124. $orderInfo->os = $deviceType;
  125. $orderInfo->user_agent = $userAgent;
  126. $orderInfo->save();
  127. }
  128. $this->page++;
  129. sleep(1);
  130. } while($this->page <= ceil($count / $this->limit));
  131. } catch (\Exception $e) {
  132. Log::logError('容量平台订单获取过程发生异常', [
  133. 'file' => $e->getFile(),
  134. 'line' => $e->getLine(),
  135. 'msg' => $e->getMessage(),
  136. 'trace' => $e->getTraceAsString(),
  137. 'order_id' => $orderId,
  138. ], 'CapacityOrderList-Exception');
  139. EmailQueue::rPush('容量平台订单获取过程发生异常', json_encode([
  140. 'file' => $e->getFile(),
  141. 'line' => $e->getLine(),
  142. 'msg' => $e->getMessage(),
  143. 'order_id' => $orderId,
  144. ]), ['song.shen@kuxuan-inc.com'], '猎羽');
  145. }
  146. }
  147. }