90 lines
2.5 KiB
PHP
90 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace common\modules\vip\vo;
|
|
|
|
use common\modules\vip\VipUtil;
|
|
use common\services\GameConfigServices;
|
|
use common\services\ResultStatusServices;
|
|
use common\services\StatusException;
|
|
use yii\behaviors\TimestampBehavior;
|
|
use yii\db\ActiveRecord;
|
|
|
|
/**
|
|
*
|
|
* CREATE TABLE `vip` (
|
|
* `id` int(11) NOT NULL AUTO_INCREMENT,
|
|
* `user_id` int(11) NOT NULL,
|
|
* `level` int(11) NOT NULL,
|
|
* `exp` int(11) NOT NULL,
|
|
* `is_get_fix_gift` int(11) NOT NULL,
|
|
* `is_get_week_gift` int(11) NOT NULL,
|
|
* `last_get_week_gift_time` int(11) NOT NULL,
|
|
* `created_at` int(11) NOT NULL,
|
|
* `updated_at` int(11) NOT NULL,
|
|
* PRIMARY KEY (`id`),
|
|
* KEY `user_id` (`user_id`),
|
|
* KEY `level` (`level`)
|
|
* ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8
|
|
*/
|
|
|
|
/**
|
|
* vip
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int $level //vip等级
|
|
* @property int $exp //充值钻石数量
|
|
* @property int $is_get_fix_gift //是否获取固定奖励
|
|
* @property int $is_get_week_gift //是否获取周奖励
|
|
* @property int $last_get_week_gift_time //上次领取周奖励时间
|
|
* @property int $created_at
|
|
* @property int $updated_at
|
|
*/
|
|
class Vip 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'],
|
|
|
|
['level', 'default', 'value' => 0],
|
|
['level', 'number', 'min' => 0, 'max' => GameConfigServices::getMaxVipLevel()],
|
|
|
|
['exp', 'default', 'value' => 0],
|
|
|
|
['is_get_fix_gift', 'default', 'value' => VipUtil::NOT_GET_GIFT],
|
|
['is_get_fix_gift', 'in', 'range' => VipUtil::GET_GIFT_LIST],
|
|
|
|
['is_get_week_gift', 'default', 'value' => VipUtil::NOT_GET_GIFT],
|
|
['is_get_week_gift', 'in', 'range' => VipUtil::GET_GIFT_LIST],
|
|
|
|
['last_get_week_gift_time', 'default', 'value' => 0],
|
|
|
|
['created_at', 'default', 'value' => 0],
|
|
['updated_at', 'default', 'value' => 0],
|
|
];
|
|
}
|
|
|
|
public static function findByUserID($userID)
|
|
{
|
|
$data = self::findOne(['user_id' => $userID]);
|
|
if (empty($data)) {
|
|
$data = new Vip();
|
|
$data->user_id = $userID;
|
|
if (!$data->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
}
|