1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Console\Commands;
- use App\Log;
- use App\Models\SunnyTask;
- use App\Services\HttpService;
- use App\Services\SunService;
- use Illuminate\Console\Command;
- class SunnyOrderSupply extends Command
- {
- protected $signature = 'SunnyOrderSupply';
- protected $description = '阳光书城订单抓取补充-解决书城订单不及时问题';
- public function handle()
- {
- \DB::connection()->disableQueryLog();
- $this->info(date('m-d H:i:s') . ' 开始整理');
- $this->supply();
- $this->info(date('m-d H:i:s') . ' 整理结束');
- }
- private function supply()
- {
- try {
- $sTime = date('Y-m-d', strtotime('-7 days')) . ' 00:00:00';
- $eTime = date('Y-m-d H:i:s');
- $this->info('起始时间:'.$sTime);
- $this->info('截止时间:'.$eTime);
- $params = [
- 'vip_id' => SunService::VIP_ID,
- 'start_time' => $sTime,
- 'end_time' => $eTime,
- ];
- # 签名
- $params = SunService::sign($params);
- $requestUri = SunService::API_BASE_URL . SunService::ORDER_LIST;
- # 获取响应数据
- $response = HttpService::httpPost($requestUri, $params);
- $this->info($response);
- if($response === false)
- Log::logError('阳光订单数据获取失败' . $requestUri, $params, 'SunnyOrderSupply');
- $responseData = json_decode($response, true);
- if(isset($responseData['error_code']) && $responseData['error_code']==0) {
- # 记录任务信息
- $taskId = isset($responseData['data']['task_id']) ? $responseData['data']['task_id'] : null;
- if(empty($taskId)) {
- Log::logError('账号列表获取任务失败', $responseData, 'SunnyOrderSupply');
- $this->info('获取账号列表任务设置失败');
- return false;
- }
- $result = SunnyTask::setTask($taskId, SunnyTask::ORDER_TYPE);
- if(!$result) {
- Log::logError('订单列表获取任务创建失败', [
- 'task_id' => $taskId,
- 'type' => SunnyTask::ORDER_TYPE
- ], 'SunnyOrderSupply');
- return false;
- }
- } else {
- Log::logError('订单列表获取任务获取失败', $responseData, 'SunnyOrderSupply');
- return false;
- }
- } catch (\Exception $e) {
- Log::logError('阳光书城订单抓取补充脚本发生异常', [
- 'line' => $e->getLine(),
- 'msg' => $e->getMessage()
- ], 'SunnyOrderSupply-Exception');
- }
- }
- }
|