0], ['user_id', 'exist', 'targetClass' => '\common\models\User', 'targetAttribute' => 'id'], ['config_id', 'default', 'value' => ''], ['feed', 'default', 'value' => 0], ['is_out', 'default', 'value' => 0], ['last_update_time', 'default', 'value' => 0], ['created_at', 'default', 'value' => 0], ['updated_at', 'default', 'value' => 0], ]; } /** * @param $id * @return EnjoyPet */ public static function findByID($id) { return self::findOne(['id' => $id]); } /** * @param $userID * @return EnjoyPet[] */ public static function findListByUserID($userID) { return self::findAll(['user_id' => $userID]); } /** * @param $userID * @return static */ public static function findOutByUserID($userID) { return self::findOne(['user_id' => $userID, 'is_out' => 1]); } public static function findOneByUserID($userID, $configID) { return self::findOne(['user_id' => $userID, 'config_id' => $configID]); } public function updateFeed() { if ($this->is_out == 1) { $dis = time() - $this->last_update_time; $period = intval(GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_FEED_EXPEND_PERIOD)); $expendPoint = intval(GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_FEED_EXPEND_POINT)); if ($expendPoint <= 0) return; $point = intval($expendPoint * floatval($dis) / $period); if ($point > 0) { $this->feed -= $point; if ($this->feed < 0) $this->feed = 0; $this->last_update_time = time(); } } else { $this->last_update_time = time(); } } /** * 生成要发送给客户的数据 * @return array */ public function genClientData() { return $this->toArray(); } }