TeamReferralCodeUsage.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @property int $id 主键ID
  10. * @property string $code 使用的邀请码
  11. * @property int $code_owner_id 邀请码所有者用户ID
  12. * @property int $user_id 使用邀请码的用户ID
  13. * @property string $ip_address 使用时的IP地址
  14. * @property string $user_agent 使用时的用户代理
  15. * @property int $status 状态:0=失败,1=成功,2=已撤销
  16. * @property string $result 使用结果描述
  17. * @property string $remark 备注
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class PromotionReferralCodeUsage extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'promotion_referral_code_usages';
  30. /**
  31. * 状态常量
  32. */
  33. const STATUS_FAILED = 0;
  34. const STATUS_SUCCESS = 1;
  35. const STATUS_REVOKED = 2;
  36. // attrlist start
  37. protected $fillable = [
  38. 'id',
  39. 'code',
  40. 'code_owner_id',
  41. 'user_id',
  42. 'ip_address',
  43. 'user_agent',
  44. 'status',
  45. 'result',
  46. 'remark',
  47. ];
  48. // attrlist end
  49. /**
  50. * 获取邀请码信息
  51. *
  52. * @return BelongsTo
  53. */
  54. public function referralCode()
  55. {
  56. return $this->belongsTo(PromotionReferralCode::class, 'code', 'code');
  57. }
  58. /**
  59. * 获取邀请码所有者信息
  60. *
  61. * @return BelongsTo
  62. */
  63. public function codeOwner()
  64. {
  65. return $this->belongsTo('App\Models\User', 'code_owner_id');
  66. }
  67. /**
  68. * 获取使用者信息
  69. *
  70. * @return BelongsTo
  71. */
  72. public function user()
  73. {
  74. return $this->belongsTo('App\Models\User', 'user_id');
  75. }
  76. /**
  77. * 判断使用是否成功
  78. *
  79. * @return bool
  80. */
  81. public function isSuccess(): bool
  82. {
  83. return $this->status == self::STATUS_SUCCESS;
  84. }
  85. /**
  86. * 判断使用是否已撤销
  87. *
  88. * @return bool
  89. */
  90. public function isRevoked(): bool
  91. {
  92. return $this->status == self::STATUS_REVOKED;
  93. }
  94. }