UpdateGoods.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace app\command;
  3. use app\extra\dyLife\data\BaseData;
  4. use app\model\saas\SaasGoods;
  5. use app\model\saas\SaasStore;
  6. use Symfony\Component\Console\Command\Command;
  7. use Symfony\Component\Console\Input\InputInterface;
  8. use Symfony\Component\Console\Output\OutputInterface;
  9. class UpdateGoods extends Command
  10. {
  11. protected static string $defaultName = 'update:all';
  12. protected static string $defaultDescription = '统一生成Model';
  13. protected function execute(InputInterface $input, OutputInterface $output): int
  14. {
  15. try {
  16. $nextPage = 1;
  17. while (is_numeric($nextPage)) {
  18. $resp = (new SaasGoods)->where("status",1)->with(['skuSpecs'])->page($nextPage,10)->select();
  19. if ($resp->isEmpty()) {
  20. $output->writeln("没有任务啦==".getDateFull());
  21. $nextPage = null;
  22. return true;
  23. }
  24. foreach ($resp as $param) {
  25. $store = (new SaasStore)->where("poi_id",$param['poi_id'])->findOrEmpty();
  26. // 获取attr_key_value_map参数
  27. $valMap = (new BaseData)->config([
  28. "appid" => sConf("wechat.appid"),
  29. "secret" => sConf("wechat.secret"),
  30. "account" => sConf("wechat.shop_id"),
  31. ])->token()->getStoreCategoryTemplate($param['category_id'],$param['product_type']);
  32. $data = (new BaseData)->config([
  33. "appid" => sConf("wechat.mini_appid"),
  34. "secret" => sConf("wechat.mini_secret"),
  35. ])->token()->createGoodsData($param->toArray(),[],$store->toArray(),$valMap,"edit");
  36. echo getDateFull()."====修改返回信息\n";
  37. echo json_encode($data)."\n";
  38. }
  39. $nextPage = $nextPage+1;
  40. $output->writeln("进入下一页=={$nextPage}==".getDateFull());
  41. }
  42. } catch (\Throwable $throwable) {
  43. echo getDateFull()."==报错啦===".$throwable->getFile()."\n";
  44. echo getDateFull()."==报错啦===".$throwable->getLine()."\n";
  45. echo getDateFull()."==报错啦===".$throwable->getMessage()."\n";
  46. }
  47. return self::SUCCESS;
  48. }
  49. }