YzNoticeSeeder.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/3/9
  6. * Time: 上午9:54
  7. */
  8. use app\common\models\Member;
  9. use Illuminate\Database\Seeder;
  10. class YzNoticeSeeder extends Seeder
  11. {
  12. protected $oldTable = 'sz_yi_goods';
  13. protected $newTable = 'yz_goods_notices';
  14. public function run()
  15. {
  16. return;
  17. if (!Schema::hasTable($this->oldTable)) {
  18. echo $this->oldTable." 不存在 跳过\n";
  19. return;
  20. }
  21. $newList = \Illuminate\Support\Facades\DB::table($this->newTable)->get();
  22. if($newList->isNotEmpty()){
  23. echo "yz_goods_notices 已经有数据了跳过\n";
  24. return ;
  25. }
  26. $list = DB::table($this->oldTable)->get();
  27. if($list) {
  28. foreach ($list as $v) {
  29. $uid = \app\frontend\modules\member\models\McMappingFansModel::getUId($v['noticeopenid']);
  30. $noticetype = explode(",", $v['noticetype']);
  31. foreach ($noticetype as $item) {
  32. DB::table($this->newTable)->insert([
  33. 'goods_id'=> $v['id'],
  34. 'uid'=> $uid,
  35. 'type'=> $item,
  36. ]);
  37. }
  38. }
  39. }
  40. }
  41. }