YzGoodsDiscountSeeder.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. use app\backend\modules\member\models\MemberLevel;
  10. class YzGoodsDiscountSeeder extends Seeder
  11. {
  12. protected $oldTable = 'sz_yi_goods';
  13. protected $newTable = 'yz_goods_discount';
  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_share 已经有数据了跳过\n";
  24. return;
  25. }
  26. $list = \Illuminate\Support\Facades\DB::table($this->oldTable)->get();
  27. $memberLevels = MemberLevel::getMemberLevelList();
  28. if ($list) {
  29. foreach ($list as $v) {
  30. $discounts = json_decode($v['discounts'], true);
  31. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  32. 'goods_id' => $v['id'],
  33. 'level_discount_type' => $v['discounttype'],
  34. 'discount_method' => $v['discountway'],
  35. 'level_id' => 0,
  36. 'discount_value' => $discounts['default'],
  37. ]);
  38. foreach ($memberLevels as $m) {
  39. if ($discounts['level' . $m['id']]) {
  40. \Illuminate\Support\Facades\DB::table($this->newTable)->insert([
  41. 'goods_id' => $v['id'],
  42. 'level_discount_type' => $v['discounttype'],
  43. 'discount_method' => $v['discountway'],
  44. 'level_id' => $m['id'],
  45. 'discount_value' => $discounts['level' . $m['id']],
  46. ]);
  47. }
  48. }
  49. }
  50. }
  51. }
  52. }