小说推广数据系统

SunnyOrderSupply.php 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Log;
  4. use App\Models\SunnyTask;
  5. use App\Services\HttpService;
  6. use App\Services\SunService;
  7. use Illuminate\Console\Command;
  8. class SunnyOrderSupply extends Command
  9. {
  10. protected $signature = 'SunnyOrderSupply';
  11. protected $description = '阳光书城订单抓取补充-解决书城订单不及时问题';
  12. public function handle()
  13. {
  14. \DB::connection()->disableQueryLog();
  15. $this->info(date('m-d H:i:s') . ' 开始整理');
  16. $this->supply();
  17. $this->info(date('m-d H:i:s') . ' 整理结束');
  18. }
  19. private function supply()
  20. {
  21. try {
  22. $sTime = date('Y-m-d', strtotime('-7 days')) . ' 00:00:00';
  23. $eTime = date('Y-m-d H:i:s');
  24. $this->info('起始时间:'.$sTime);
  25. $this->info('截止时间:'.$eTime);
  26. $params = [
  27. 'vip_id' => SunService::VIP_ID,
  28. 'start_time' => $sTime,
  29. 'end_time' => $eTime,
  30. ];
  31. # 签名
  32. $params = SunService::sign($params);
  33. $requestUri = SunService::API_BASE_URL . SunService::ORDER_LIST;
  34. # 获取响应数据
  35. $response = HttpService::httpPost($requestUri, $params);
  36. $this->info($response);
  37. if($response === false)
  38. Log::logError('阳光订单数据获取失败' . $requestUri, $params, 'SunnyOrderSupply');
  39. $responseData = json_decode($response, true);
  40. if(isset($responseData['error_code']) && $responseData['error_code']==0) {
  41. # 记录任务信息
  42. $taskId = isset($responseData['data']['task_id']) ? $responseData['data']['task_id'] : null;
  43. if(empty($taskId)) {
  44. Log::logError('账号列表获取任务失败', $responseData, 'SunnyOrderSupply');
  45. $this->info('获取账号列表任务设置失败');
  46. return false;
  47. }
  48. $result = SunnyTask::setTask($taskId, SunnyTask::ORDER_TYPE);
  49. if(!$result) {
  50. Log::logError('订单列表获取任务创建失败', [
  51. 'task_id' => $taskId,
  52. 'type' => SunnyTask::ORDER_TYPE
  53. ], 'SunnyOrderSupply');
  54. return false;
  55. }
  56. } else {
  57. Log::logError('订单列表获取任务获取失败', $responseData, 'SunnyOrderSupply');
  58. return false;
  59. }
  60. } catch (\Exception $e) {
  61. Log::logError('阳光书城订单抓取补充脚本发生异常', [
  62. 'line' => $e->getLine(),
  63. 'msg' => $e->getMessage()
  64. ], 'SunnyOrderSupply-Exception');
  65. }
  66. }
  67. }