Coupon.php 861 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. /**
  6. * 优惠券
  7. * Class Goods
  8. *
  9. * @package App\Http\Models
  10. * @mixin \Eloquent
  11. */
  12. class Coupon extends Model
  13. {
  14. use SoftDeletes;
  15. protected $table = 'coupon';
  16. protected $primaryKey = 'id';
  17. protected $dates = ['deleted_at'];
  18. // 筛选类型
  19. function scopeType($query, $type)
  20. {
  21. return $query->where('type', $type);
  22. }
  23. function getAmountAttribute($value)
  24. {
  25. return $value / 100;
  26. }
  27. function setAmountAttribute($value)
  28. {
  29. $this->attributes['amount'] = $value * 100;
  30. }
  31. function getDiscountAttribute($value)
  32. {
  33. return $value * 10;
  34. }
  35. function setDiscountAttribute($value)
  36. {
  37. $this->attributes['discount'] = $value / 10;
  38. }
  39. }