MiniTask.php 5.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\command;
  3. use app\extra\tools\XcJob;
  4. use app\model\blue\BlueTask;
  5. use Symfony\Component\Console\Command\Command;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. class MiniTask extends Command
  9. {
  10. protected static string $defaultName = 'min:task';
  11. protected static string $defaultDescription = '小程序星川任务';
  12. protected function execute(InputInterface $input, OutputInterface $output): int
  13. {
  14. try {
  15. $nextPage = 1;$done = 0;
  16. $output->writeln("===小程序星川任务开始==={$nextPage}==>".getDateFull());
  17. while (is_numeric($nextPage)) {
  18. [$state,$resp] = (new XcJob)->token()->getTaskList($nextPage);
  19. if (!$state) {
  20. $nextPage = null;
  21. $output->writeln("===获取全部任务失败==>".getDateFull());
  22. return self::SUCCESS;
  23. }
  24. if (!$resp['has_more']) {
  25. $nextPage = null;
  26. $output->writeln("===没有更多啦==>".getDateFull());
  27. return self::SUCCESS;
  28. }
  29. $model = (new BlueTask);
  30. foreach ($resp['list'] as $key => $val)
  31. {
  32. $data = (new XcJob)->token()->getTaskDetail($val['demand_info']['id']); // 获取任务详情
  33. if ($data['base_resp']['status_code'] <> 0)
  34. {
  35. $nextPage = null;
  36. $output->writeln("===获取任务详情失败==>".getDateFull());
  37. return self::SUCCESS;
  38. }
  39. $task = [
  40. "expiration_time_end" => date("Y-m-d H:i:s",$data['task_detail_info']['task_base_info']['expiration_time_end']),
  41. "title" => $data['task_detail_info']['task_base_info']['demand_name']??'',
  42. "product_cover_url" => $data['task_detail_info']['object_field_info']['object_product_info']['product_cover_url']??'',
  43. "product_name" => $data['task_detail_info']['object_field_info']['object_product_info']['product_name']??'',
  44. "shop_name" => $data['task_detail_info']['object_field_info']['object_product_info']['shop_name']??'',
  45. "product_id" => $data['task_detail_info']['object_field_info']['object_product_info']['external_product_id']??'',
  46. "product_link" => $data['task_detail_info']['object_field_info']['object_product_info']['product_link']??'',
  47. "product_price" => $data['task_detail_info']['component_info']['ecom_info']['ecoms'][0]['price']?$data['task_detail_info']['component_info']['ecom_info']['ecoms'][0]['price']*100:'0',
  48. "auto" => 2,
  49. "job_id" => $val['demand_info']['id'],
  50. "category" => "douyin",
  51. "category_detail" => $data['task_detail_info']['task_base_info']['second_class_category_name']??'',
  52. "product_selling_point" => $data['task_detail_info']['object_field_info']['object_product_info']['product_selling_point_detail']??'',
  53. "target_audience" => $data['task_detail_info']['object_field_info']['object_product_info']['target_audience_desc']??'',
  54. "creative_material_types" => $data['task_detail_info']['star_qc_unite_info']['creative_material_types']?json_encode($data['task_detail_info']['star_qc_unite_info']['creative_material_types']):[],
  55. "content" => $data['task_detail_info']['task_base_info']['other']?nl2br($data['task_detail_info']['task_base_info']['other']):'',
  56. "total_budget" => $data['task_detail_info']['project_detail_info']['base_project_info']['total_budget']??0, // 0不上限
  57. ];
  58. $taskData = $model->where("product_id",$task['product_id'])->findOrEmpty();
  59. if ($taskData->isEmpty()) { // 新增
  60. $taskData->insertGetId($task);
  61. $output->writeln("{$val['demand_info']['id']}===入库成功!~==>".getDateFull());
  62. } else {
  63. // 更新
  64. $output->writeln("{$val['demand_info']['id']}===已存在,不入库!~==>".getDateFull());
  65. }
  66. }
  67. $nextPage = $nextPage+1;
  68. $output->writeln("===当前页码{$nextPage}==>".getDateFull());
  69. }
  70. return self::SUCCESS;
  71. } catch (\Throwable $throwable) {
  72. echo getDateFull()."==报错啦===".$throwable->getFile()."\n";
  73. echo getDateFull()."==报错啦===".$throwable->getLine()."\n";
  74. echo getDateFull()."==报错啦===".$throwable->getMessage()."\n";
  75. return self::SUCCESS;
  76. }
  77. }
  78. }