| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use Yii;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%user_coupon}}".
- *
- * @property int $id
- * @property int $store_id
- * @property int $user_id 用户id
- * @property int $coupon_id 优惠券id
- * @property int $coupon_auto_send_id 自动发放id
- * @property int $begin_time 有效期开始时间
- * @property int $end_time 有效期结束时间
- * @property int $is_expire 是否已过期:0=未过期,1=已过期
- * @property int $is_use 是否已使用:0=未使用,1=已使用
- * @property int $is_delete 是否删除
- * @property int $created_at 添加时间
- * @property int|null $type 领取类型 0--平台发放 1--自动发放 2--领券中心领取
- * @property int $integral 兑换支付积分数量
- * @property float $price 兑换支付价格
- * @property int|null $updated_at 更新时间
- * @property int $give_user_id
- * @property int $voucher_code_id 支付宝赠送卡券id
- */
- class UserCoupon extends \yii\db\ActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%user_coupon}}';
- }
- const IS_DELETE_YES = 1;//已删除
- const IS_DELETE_NO = 0;//未删除
- const IS_USE_NO = 0;//未使用
- const IS_USE_YES = 1;//已使用
- const IS_EXPIRE_NO = 0;//未过期
- const IS_EXPIRE_YES = 1;//已过期
- const TYPE_STORE = 0;//平台发放
- const TYPE_AUTO = 1;//自动发放
- const TYPE_GET = 2;//领券中心领取
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['updated_at', 'created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'
- ]
- ]
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['store_id', 'user_id', 'coupon_id'], 'required'],
- [['store_id', 'user_id', 'coupon_id', 'coupon_auto_send_id', 'begin_time', 'end_time', 'is_expire', 'is_use', 'is_delete', 'created_at', 'type', 'integral', 'updated_at', 'give_user_id', 'voucher_code_id'], 'integer'],
- [['price'], 'number'],
- [['alipay_open_id'], 'safe'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'store_id' => 'Store ID',
- 'user_id' => '用户id',
- 'alipay_open_id' => 'alipay_open_id',
- 'coupon_id' => '优惠券id',
- 'coupon_auto_send_id' => '自动发放id',
- 'begin_time' => '有效期开始时间',
- 'end_time' => '有效期结束时间',
- 'is_expire' => '是否已过期:0=未过期,1=已过期',
- 'is_use' => '是否已使用:0=未使用,1=已使用',
- 'is_delete' => '是否删除',
- 'created_at' => '添加时间',
- 'type' => '领取类型 0--平台发放 1--自动发放 2--领券中心领取 3--saas福利中心 4--转赠',
- 'integral' => '兑换支付积分数量',
- 'price' => '兑换支付价格',
- 'updated_at' => '更新时间',
- 'voucher_code_id' => "支付宝赠送卡券id"
- ];
- }
- public function afterSave($insert, $changedAttributes)
- {
- parent::afterSave($insert, $changedAttributes);
- if($insert){
- (new \app\utils\OrderUtil())->couponTimeout($this->id);
- }
- }
- public function getCoupon()
- {
- return $this->hasOne(Coupon::className(), ['id' => 'coupon_id']);
- }
- public function getUser()
- {
- return $this->hasOne(User::className(), ['id'=>'user_id']);
- }
- }
|