链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.2 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\LanzuGoods;
  5. use App\Models\LanzuStore;
  6. class SetGoodsMarketId extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:SetGoodsMarketId';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 根据商品表中storeid设置市场id';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $goods = LanzuGoods::all();
  37. $no_store_ids = [];
  38. foreach($goods as $key => $item){
  39. $store = LanzuStore::find($item->store_id);
  40. if($store){
  41. $item->market_id = $store->market_id;
  42. $item->save();
  43. print_r($item->id.'\r\n');
  44. }else{
  45. $no_store_ids[] = $item->store_id;
  46. break;
  47. }
  48. }
  49. var_dump($no_store_ids);
  50. return 0;
  51. }
  52. }