YzGoodsDispatchSeeder.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/9
  6. * Time: 上午9:54
  7. */
  8. use Illuminate\Database\Seeder;
  9. class YzGoodsDispatchSeeder extends Seeder
  10. {
  11. protected $oldTable = 'sz_yi_goods';
  12. protected $newTable = 'yz_goods_dispatch';
  13. public function run()
  14. {
  15. return;
  16. if (!Schema::hasTable($this->oldTable)) {
  17. echo $this->oldTable." 不存在 跳过\n";
  18. return;
  19. }
  20. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  21. if($newList->isNotEmpty()){
  22. echo "yz_goods_share 已经有数据了跳过\n";
  23. return ;
  24. }
  25. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  26. if($list) {
  27. foreach ($list as $v) {
  28. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  29. 'goods_id'=> $v['id'],
  30. 'dispatch_type'=> $v['dispatchtype'],
  31. 'dispatch_price'=> $v['dispatchprice'],
  32. 'dispatch_id'=> $v['dispatchid'],
  33. 'is_cod'=> $v['cash'],
  34. ]);
  35. }
  36. }
  37. }
  38. }