Coupon.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace addons\TinyShop\common\models\marketing;
  3. use yii\db\ActiveQuery;
  4. use yii\base\InvalidConfigException;
  5. use common\traits\HasOneMerchant;
  6. use common\traits\HasOneMember;
  7. use addons\TinyShop\common\enums\MarketingEnum;
  8. use addons\TinyShop\common\models\product\Product;
  9. use yii\db\ActiveRecord;
  10. /**
  11. * This is the model class for table "{{%addon_tiny_shop_marketing_coupon}}".
  12. *
  13. * @property int $id 优惠券id
  14. * @property int|null $member_id 领用人
  15. * @property int|null $merchant_id 店铺Id
  16. * @property int $coupon_type_id 优惠券类型id
  17. * @property float|null $discount 活动金额
  18. * @property int|null $discount_type 活动金额类型
  19. * @property string $title 优惠券名称
  20. * @property string|null $code 优惠券编码
  21. * @property int|null $map_id 创建关联ID
  22. * @property int|null $map_type 创建关联类型
  23. * @property int|null $use_order_id 优惠券使用订单id
  24. * @property float|null $at_least 满多少元使用 0代表无限制
  25. * @property int|null $state 优惠券状态 0未领用 1已领用(未使用) 2已使用 3已过期
  26. * @property int|null $get_type 获取方式
  27. * @property int|null $single_type 单品卷
  28. * @property int|null $is_read 浏览状态
  29. * @property int|null $fetch_time 领取时间
  30. * @property int|null $use_time 使用时间
  31. * @property int|null $start_time 有效期开始时间
  32. * @property int|null $end_time 有效期结束时间
  33. * @property int|null $status 状态
  34. */
  35. class Coupon extends ActiveRecord
  36. {
  37. use HasOneMerchant, HasOneMember;
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public static function tableName()
  42. {
  43. return '{{%addon_tiny_shop_marketing_coupon}}';
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [
  52. [
  53. 'member_id',
  54. 'merchant_id',
  55. 'coupon_type_id',
  56. 'discount_type',
  57. 'map_id',
  58. 'map_type',
  59. 'use_order_id',
  60. 'state',
  61. 'get_type',
  62. 'single_type',
  63. 'is_read',
  64. 'fetch_time',
  65. 'use_time',
  66. 'start_time',
  67. 'end_time',
  68. 'status',
  69. ],
  70. 'integer',
  71. ],
  72. [['discount', 'at_least'], 'number'],
  73. [['title'], 'string', 'max' => 50],
  74. [['code'], 'string', 'max' => 100],
  75. ];
  76. }
  77. /**
  78. * {@inheritdoc}
  79. */
  80. public function attributeLabels()
  81. {
  82. return [
  83. 'id' => '优惠券id',
  84. 'member_id' => '领用人',
  85. 'merchant_id' => '店铺Id',
  86. 'coupon_type_id' => '优惠券类型id',
  87. 'discount' => '活动金额',
  88. 'discount_type' => '活动金额类型',
  89. 'title' => '优惠券名称',
  90. 'code' => '优惠券编码',
  91. 'map_id' => '创建关联ID',
  92. 'map_type' => '创建关联类型',
  93. 'use_order_id' => '优惠券使用订单id',
  94. 'at_least' => '满多少元使用',
  95. 'state' => '优惠券状态',
  96. 'get_type' => '获取方式',
  97. 'single_type' => '单品卷',
  98. 'is_read' => '浏览状态',
  99. 'fetch_time' => '领取时间',
  100. 'use_time' => '使用时间',
  101. 'start_time' => '有效期开始时间',
  102. 'end_time' => '有效期结束时间',
  103. 'status' => '状态',
  104. ];
  105. }
  106. /**
  107. * @return ActiveQuery
  108. */
  109. public function getCouponType()
  110. {
  111. return $this->hasOne(CouponType::class, ['id' => 'coupon_type_id']);
  112. }
  113. /**
  114. * 关联商品
  115. *
  116. * @return ActiveQuery
  117. */
  118. public function getProduct()
  119. {
  120. return $this->hasMany(MarketingProduct::class, ['marketing_id' => 'coupon_type_id'])
  121. ->select(['id', 'marketing_id', 'marketing_type', 'product_id'])
  122. ->andWhere(['in', 'marketing_type', [MarketingEnum::COUPON_IN, MarketingEnum::COUPON_NOT_IN]]);
  123. }
  124. /**
  125. * 关联分类
  126. *
  127. * @return ActiveQuery
  128. */
  129. public function getCate()
  130. {
  131. return $this->hasMany(MarketingCate::class, ['marketing_id' => 'coupon_type_id'])
  132. ->select(['id', 'marketing_id', 'marketing_type', 'cate_id'])
  133. ->andWhere(['in', 'marketing_type', [MarketingEnum::COUPON_IN, MarketingEnum::COUPON_NOT_IN]]);
  134. }
  135. }
粤ICP备19079148号