77 lines
1.8 KiB
PHP
77 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace common\modules\card\vo;
|
|
|
|
use common\modules\card\CardUtil;
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
/**
|
|
*
|
|
CREATE TABLE `card` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`user_id` int(11) NOT NULL,
|
|
`item_id` int(11) NOT NULL,
|
|
`count` int(11) NOT NULL,
|
|
`last_get_gift_time` int(11) NOT NULL,
|
|
`created_at` int(11) DEFAULT NULL,
|
|
`updated_at` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`id`),
|
|
UNIQUE KEY `user_id_item_id` (`user_id`,`item_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='周卡,月卡'
|
|
*/
|
|
|
|
/**
|
|
* 周卡,月卡
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property string $item_id //周卡、月卡物品ID
|
|
* @property int $count //剩余次数
|
|
* @property int $last_get_gift_time //上次领取奖励时间
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*/
|
|
class Card 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' => ''],
|
|
|
|
['count', 'default', 'value' => 0],
|
|
|
|
['last_get_gift_time', 'default', 'value' => 0],
|
|
|
|
['created_at', 'default', 'value' => 0],
|
|
['updated_at', 'default', 'value' => 0],
|
|
];
|
|
}
|
|
|
|
public static function findByUserIDAndItemID($userID, $itemID)
|
|
{
|
|
return self::findOne(['user_id' => $userID, 'item_id' => $itemID]);
|
|
}
|
|
|
|
/**
|
|
* @param $userID
|
|
* @return static[]
|
|
*/
|
|
public static function findByUserID($userID)
|
|
{
|
|
return self::findAll(['user_id' => $userID]);
|
|
}
|
|
}
|