| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /**
- * 厦门云联储网络科技有限公司
- * https://www.baokuaiyun.com
- * Copyright (c) 2023 爆块云 All rights reserved.
- */
- namespace app\models;
- use app\constants\OptionSetting;
- use app\modules\alliance\models\CurrencyForm;
- use app\plugins\scanCodePay\models\Order as ScanCodePayOrder;
- use app\plugins\scanCodePay\models\Order as ScanOrder;
- use yii\db\ActiveRecord;
- use yii\behaviors\TimestampBehavior;
- use Yii;
- use yii\helpers\Json;
- /**
- * This is the model class for table "{{%red_packet}}".
- *
- * @property integer $id
- * @property integer $store_id
- * @property integer $user_id
- * @property integer $saas_id
- * @property integer $currency_id
- * @property float $amount
- * @property double $remaining_amount
- * @property integer $remaining_count
- * @property integer $total
- * @property integer $type
- * @property integer $status
- * @property string $image_url
- * @property string $name
- * @property integer $is_delete
- * @property integer $created_at
- * @property integer $updated_at
- */
- class RedPacket extends \yii\db\ActiveRecord
- {
- const TYPE_NORMAL = 1; // 普通红包
- const TYPE_RANDOM = 2; // 手气红包
- const STATUS_ACTIVE = 1; // 有效
- const STATUS_EMPTY = 2; // 已抢完
- const STATUS_EXPIRED = 3; // 已过期
- const STATUS_FAIL = 4; // 已作废
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%red_packet}}';
- }
- public function behaviors()
- {
- return [
- [
- 'class' => TimestampBehavior::class,
- 'attributes' => [
- ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
- ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
- ]
- ]
- ];
- }
- public function rules()
- {
- return [
- [['user_id', 'amount', 'total'], 'required'],
- [['user_id', 'total', 'type','status','id','created_at', 'updated_at','remaining_count','store_id','currency_id','is_delete'], 'integer'],
- [['amount'], 'number', 'min' => 0.01],
- [[ 'remaining_amount'], 'number'],
- [[ 'image_url','name'], 'string'],
- ['total', 'integer', 'min' => 1],
- ['type', 'in', 'range' => [self::TYPE_NORMAL, self::TYPE_RANDOM]],
- ['status', 'default', 'value' => self::STATUS_ACTIVE],
- ];
- }
- public function getRecords()
- {
- return $this->hasMany(RedPacketRecord::class, ['packet_id' => 'id']);
- }
- public static function getStatusText($status)
- {
- $text = [
- self::STATUS_ACTIVE => '有效',
- self::STATUS_EMPTY => '已抢完',
- self::STATUS_EXPIRED => '已过期',
- self::STATUS_FAIL => '已作废',
- ];
- return $text[$status];
- }
- }
|