YzsaleSeeder.php 1.4 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 Illuminate\Database\Seeder;
  9. class YzSaleSeeder extends Seeder
  10. {
  11. protected $oldTable = 'sz_yi_goods';
  12. protected $newTable = 'yz_goods_sale';
  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_sale 已经有数据了跳过\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. 'max_point_deduct'=> $v['deduct'] * 100,
  31. 'max_balance_deduct'=> $v['deduct2'] * 100,
  32. 'is_sendfree'=> $v['issendfree'],
  33. 'ed_num'=> $v['ednum'],
  34. 'ed_money'=> $v['edmoney'],
  35. 'ed_areas'=> $v['edareas'],
  36. 'point'=> $v['credit'] * 100,
  37. 'bonus'=> $v['redprice'] * 100
  38. ]);
  39. }
  40. }
  41. }
  42. }