hy-farm/common/modules/treasurebox/vo/TreasureBox.php
2026-05-07 20:10:54 +08:00

86 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace common\modules\treasurebox\vo;
use common\modules\treasurebox\TreasureBoxUtil;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
*
CREATE TABLE `treasure_box` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`item_id` varchar(45) NOT NULL COMMENT '宝箱物品ID',
`name` varchar(45) NOT NULL,
`end_open_time` int(11) NOT NULL COMMENT '开启时间0未计时',
`is_get_gift` int(11) DEFAULT NULL COMMENT '是否领取奖励',
`created_at` int(11) DEFAULT NULL,
`updated_at` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='宝箱'
*/
/**
* 宝箱
* @property int $id
* @property int $user_id
* @property int $item_id //宝箱物品ID
* @property string $name
* @property int $end_open_time //开启时间0未计时
* @property int $is_get_gift //是否领取奖励
* @property int $created_at
* @property int $updated_at
*/
class TreasureBox 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'],
['item_id', 'default', 'value' => ''],
['name', 'default', 'value' => ''],
['end_open_time', 'default', 'value' => 0],
['is_get_gift', 'default', 'value' => TreasureBoxUtil::NOT_GET_GIFT],
['is_get_gift', 'in', 'range' => TreasureBoxUtil::GET_GIFT_LIST],
['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]);
}
/**
* @param $id
* @return static
*/
public static function findByID($id)
{
return self::findOne(['id' => $id]);
}
}