PromotionReferralCodeUsage.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Module\Promotion\Models;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use UCore\ModelCore;
  5. /**
  6. * 邀请码使用记录
  7. *
  8. * field start
  9. * field end
  10. */
  11. class PromotionReferralCodeUsage extends ModelCore
  12. {
  13. /**
  14. * 与模型关联的表名
  15. *
  16. * @var string
  17. */
  18. protected $table = 'promotion_referral_code_usages';
  19. /**
  20. * 状态常量
  21. */
  22. const STATUS_FAILED = 0;
  23. const STATUS_SUCCESS = 1;
  24. const STATUS_REVOKED = 2;
  25. // attrlist start
  26. protected $fillable = [
  27. ];
  28. // attrlist end
  29. /**
  30. * 获取邀请码信息
  31. *
  32. * @return BelongsTo
  33. */
  34. public function referralCode()
  35. {
  36. return $this->belongsTo(PromotionReferralCode::class, 'code', 'code');
  37. }
  38. /**
  39. * 获取邀请码所有者信息
  40. *
  41. * @return BelongsTo
  42. */
  43. public function codeOwner()
  44. {
  45. return $this->belongsTo('App\Models\User', 'code_owner_id');
  46. }
  47. /**
  48. * 获取使用者信息
  49. *
  50. * @return BelongsTo
  51. */
  52. public function user()
  53. {
  54. return $this->belongsTo('App\Models\User', 'user_id');
  55. }
  56. /**
  57. * 判断使用是否成功
  58. *
  59. * @return bool
  60. */
  61. public function isSuccess(): bool
  62. {
  63. return $this->status == self::STATUS_SUCCESS;
  64. }
  65. /**
  66. * 判断使用是否已撤销
  67. *
  68. * @return bool
  69. */
  70. public function isRevoked(): bool
  71. {
  72. return $this->status == self::STATUS_REVOKED;
  73. }
  74. }