CouponsUserBag.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. class CouponsUserBag extends Model
  6. {
  7. //
  8. use ModelHelpers;
  9. protected $table = "coupons_user_bags";
  10. protected $guarded = [];
  11. const TYPE_ADMIN_GIVE = 1;
  12. const TYPE_INVITE_NEW_GIVE = 2;
  13. public static $typeMaps = [
  14. self::TYPE_ADMIN_GIVE => '后台管理员赠送',
  15. self::TYPE_INVITE_NEW_GIVE => '邀请新用户赠送',
  16. ];
  17. const STATUS_OK = 1;
  18. const STATUS_NO = 0;
  19. const STATUS_USED = 2;
  20. public static $statusMaps = [
  21. self::STATUS_OK=>'启用',
  22. self::STATUS_NO=>'停用',
  23. self::STATUS_USED=>'已使用',
  24. ];
  25. const VALID_TYPE_ABSOLUTELY = 1;
  26. const VALID_TYPE_RELATIVE = 2;
  27. public static $validTypeMaps = [
  28. self::VALID_TYPE_ABSOLUTELY => '绝对时效',
  29. self::VALID_TYPE_RELATIVE => '相对时效',
  30. ];
  31. const ORDER_TYPE_NORMAL = 1;
  32. const ORDER_TYPE_RENT = 2;
  33. const ORDER_TYPE_ALL = 3;
  34. public static $orderTypeMaps = [
  35. self::ORDER_TYPE_NORMAL => '仅普通订单可用',
  36. self::ORDER_TYPE_RENT => '仅日租订单可用',
  37. self::ORDER_TYPE_ALL => '所有订单可用',
  38. ];
  39. public function getCouponsDataAttribute($value)
  40. {
  41. return json_decode($value,true);
  42. }
  43. public function setCouponsDataAttribute($value)
  44. {
  45. $this->attributes['coupons_data'] = json_encode($value);
  46. }
  47. public function users(){
  48. return $this->belongsTo(User::class,'user_id','id');
  49. }
  50. public function coupons(){
  51. return $this->belongsTo(Coupon::class,'coupon_id','id');
  52. }
  53. }