You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Model\v3;
  3. use App\Model\Model;
  4. class Coupon extends Model
  5. {
  6. const DISCOUNT_TYPE_CASH = 1;
  7. const DISCOUNT_TYPE_RATE = 2;
  8. protected $table = 'lanzu_coupon';
  9. protected $appends = [
  10. 'full_amount_text',
  11. 'discounts_text',
  12. 'time_text',
  13. 'effective_time_text'
  14. ];
  15. protected $casts = [
  16. 'activity_available' => 'array',
  17. 'tags' => 'array'
  18. ];
  19. public function getFullAmountTextAttribute()
  20. {
  21. return '满'.$this->attributes['full_amount'].'可用';
  22. }
  23. public function getDiscountsTextAttribute()
  24. {
  25. if($this->attributes['discount_type'] == 1){
  26. return '¥'.$this->attributes['discounts'];
  27. }elseif($this->attributes['discount_type'] == 2){
  28. return floatval($this->attributes['discounts'])."";
  29. }
  30. }
  31. public function getTimeTextAttribute()
  32. {
  33. return date("Y-m-d H:i:s",$this->attributes['usable_start_time']). ' - ' .date("Y-m-d H:i:s",$this->attributes['usable_end_time']);
  34. }
  35. public function getEffectiveTimeTextAttribute()
  36. {
  37. return '有效期:'.date("Y-m-d",$this->attributes['usable_start_time']). ' - ' .date("Y-m-d",$this->attributes['usable_end_time']);
  38. }
  39. }