SyncPlan.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\command;
  3. use app\extra\dyMini\PlanLive;
  4. use app\model\saas\SaasLivePlan;
  5. use Symfony\Component\Console\Command\Command;
  6. use Symfony\Component\Console\Input\InputInterface;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. class SyncPlan extends Command
  9. {
  10. protected static string $defaultName = 'sync:plan';
  11. protected static string $defaultDescription = '查询定向佣金计划带货汇总数据';
  12. protected function execute(InputInterface $input, OutputInterface $output): int
  13. {
  14. try {
  15. $output->writeln("开始更计划带货数据信息====>" . getDateFull());
  16. $nextPage = 1;
  17. while (is_numeric($nextPage)) {
  18. $resp = (new SaasLivePlan)->where(["status" => 1])->page($nextPage, 10)->select();
  19. if ($resp->isEmpty()) {
  20. $output->writeln("没有任务啦==".getDateFull());
  21. $nextPage = null;
  22. return true;
  23. }
  24. foreach ($resp as $item) {
  25. $output->writeln("计划ID=={$item['plan_id']}==".getDateFull());
  26. $planData = (new PlanLive)->config([
  27. "appid" => sConf("wechat.mini_appid"),
  28. "secret" => sConf("wechat.mini_secret"),
  29. ])->token()->getPlanData([intval($item['plan_id'])]);
  30. if (isset($planData['data'][$item['plan_id']])) {
  31. echo getDateFull()."更新数据成功\n";
  32. (new SaasLivePlan)->where("id",$item['id'])->save([
  33. "order_money" => $planData['data'][$item['plan_id']]['gmv']??0,
  34. "done_money" => $planData['data'][$item['plan_id']]['used_gmv']??0
  35. ]);
  36. } else {
  37. echo getDateFull()."没有查询到数据\n";
  38. }
  39. }
  40. $nextPage = $nextPage+1;
  41. $output->writeln("进入下一页=={$nextPage}==".getDateFull());
  42. }
  43. } catch (\Throwable $throwable) {
  44. echo getDateFull()."===查询计划数据报错\n";
  45. echo $throwable->getFile()."\n";
  46. echo $throwable->getLine()."\n";
  47. }
  48. return self::SUCCESS;
  49. }
  50. }