YzGoodsShareSeeder.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 YzGoodsShareSeeder extends Seeder
  10. {
  11. protected $oldTable = 'sz_yi_goods';
  12. protected $newTable = 'yz_goods_share';
  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. 'need_follow'=> $v['needfollow'],
  31. 'no_follow_message'=> $v['followtip'],
  32. 'follow_message'=> $v['followurl'],
  33. 'share_title'=> $v['share_title'],
  34. 'share_thumb'=> $v['share_icon'],
  35. 'share_desc'=> $v['description'],
  36. ]);
  37. }
  38. }
  39. }
  40. }