updateCoupon.php 881 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Coupon;
  4. use Illuminate\Console\Command;
  5. use Log;
  6. class updateCoupon extends Command {
  7. protected $signature = 'updateCoupon';
  8. protected $description = '修改原版Coupon至新版';
  9. public function __construct() {
  10. parent::__construct();
  11. }
  12. public function handle() {
  13. Log::info('----------------------------【优惠券转换】开始----------------------------');
  14. $coupons = Coupon::withTrashed()->get();
  15. foreach($coupons as $coupon){
  16. if($coupon->amount){
  17. $coupon->value = $coupon->amount / 100;
  18. }elseif($coupon->discount){
  19. $coupon->value = $coupon->discount * 100;
  20. }
  21. if($coupon->rule === 0){
  22. $coupon->rule = null;
  23. }else{
  24. $coupon->rule /= 100;
  25. }
  26. $coupon->save();
  27. }
  28. Log::info('----------------------------【优惠券转换】结束----------------------------');
  29. }
  30. }