68 lines
1.5 KiB
PHP
68 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace common\modules\levelgift\vo;
|
|
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
/**
|
|
*
|
|
CREATE TABLE `level_gift` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`user_id` int(11) NOT NULL,
|
|
`gift_id` int(11) NOT NULL COMMENT '礼包配置表ID',
|
|
`created_at` int(11) DEFAULT NULL,
|
|
`updated_at` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
KEY `user_id` (`user_id`),
|
|
KEY `gift_id` (`gift_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='已领取的等级礼包'
|
|
*/
|
|
|
|
/**
|
|
* 已领取的等级礼包
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $gift_id 礼包配置表ID
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*/
|
|
class LevelGift extends ActiveRecord
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return [
|
|
TimestampBehavior::className(),
|
|
];
|
|
}
|
|
|
|
public function rules()
|
|
{
|
|
return [
|
|
['id', 'default', 'value' => 0],
|
|
|
|
['user_id', 'required'],
|
|
['user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'],
|
|
|
|
['gift_id', 'default', 'value' => 0],
|
|
|
|
['created_at', 'default', 'value' => 0],
|
|
['updated_at', 'default', 'value' => 0],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param $userID
|
|
* @return static[]
|
|
*/
|
|
public static function findAllByUserID($userID)
|
|
{
|
|
return self::findAll(['user_id' => $userID]);
|
|
}
|
|
|
|
public static function findByUserIDAndGiftID($userID, $giftID)
|
|
{
|
|
return self::findOne(['user_id' => $userID, 'gift_id' => $giftID]);
|
|
}
|
|
}
|