StarTask.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\command;
  3. use app\extra\tools\XcJob;
  4. use Symfony\Component\Console\Command\Command;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Output\OutputInterface;
  7. class StarTask extends Command
  8. {
  9. protected static string $defaultName = 'star:task';
  10. protected static string $defaultDescription = '星川任务';
  11. protected function execute(InputInterface $input, OutputInterface $output): int
  12. {
  13. try {
  14. $nextPage = 1;$done = 0;
  15. while (is_numeric($nextPage)) {
  16. [$state,$resp] = (new XcJob)->token()->getTaskList($nextPage);
  17. if (!$state) {
  18. $nextPage = null;
  19. return self::SUCCESS;
  20. }
  21. if (!$resp['has_more']) {
  22. $nextPage = null;
  23. return self::SUCCESS;
  24. }
  25. $model = (new \app\model\star\StarTask);
  26. foreach ($resp['list'] as $key => $val)
  27. {
  28. $task = $model->where("job_id",$val['demand_info']['id'])->findOrEmpty();
  29. if ($task->isEmpty()) { // 新增
  30. $task->insertGetId([
  31. "job_id" => $val['demand_info']['id'],
  32. "project_id" => $val['project_info']['project_id'],
  33. "project_name" => $val['project_info']['project_name'],
  34. "shop_name" => $val['project_info']['shop_name'],
  35. "product_name" => $val['project_info']['product_name'],
  36. "cover" => $val['demand_info']['qc_ecom_product_info']['cover']??'',
  37. "detail_url" => $val['demand_info']['qc_ecom_product_info']['detail_url']??'',
  38. "product_id" => $val['demand_info']['qc_ecom_product_info']['product_id']??'',
  39. "expiration_time" => $val['challenge_info']['expiration_time'],
  40. "expiration_time_end" => $val['challenge_info']['expiration_time_end'],
  41. ]);
  42. $output->writeln("{$val['demand_info']['id']}===入库成功!~==>".getDateFull());
  43. } else {
  44. // 更新
  45. $output->writeln("{$val['demand_info']['id']}===已存在,不入库!~==>".getDateFull());
  46. }
  47. }
  48. $nextPage = $nextPage+1;
  49. $output->writeln("===当前页码{$nextPage}==>".getDateFull());
  50. }
  51. return self::SUCCESS;
  52. } catch (\Throwable $throwable) {
  53. echo getDateFull()."==报错啦===".$throwable->getFile()."\n";
  54. echo getDateFull()."==报错啦===".$throwable->getLine()."\n";
  55. echo getDateFull()."==报错啦===".$throwable->getMessage()."\n";
  56. return self::SUCCESS;
  57. }
  58. }
  59. }