/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $condition = array('condition' => 'status=:status', 'params' => array(':status' => 1), 'order' => 'name'); $levels = Level::model()->findAll($condition); $option_levels = array(); foreach ($levels as $level) { $option_levels[$level->level_id] = $level->name; } // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Type'])) { $model->attributes = $_POST['Type']; if ($model->save()) { $this->redirect(array('index', 'id' => $model->type_id)); } } $this->render('update', array('model' => $model, 'option_levels' => $option_levels)); }
/** * 金币买体力 * * @param unknown $user_id */ public function gold_buy_vit($user_id) { try { $con_characters = Yii::app()->db_characters; $trans_characters = $con_characters->beginTransaction(); //获取用户基本信息 $player = Characters::model()->getCharactersInfo($user_id); $lv = Level::model()->exp2Level($player['exp']); $level = Level::model()->getLevelRow($lv); if ($level['max_vit'] <= $player['vit']) { return -3; } //金币数 if ($player['gold'] >= $level['buy_vit']) { //金币购买体力 $param['gold'] = $player['gold'] - $level['buy_vit']; } else { return -2; } $param['vit'] = $level['max_vit']; //更新 加体力,扣金币 Characters::model()->updateCharacters($user_id, $param); //解锁女神 加金币日志 $gold_params = array('user_id' => $user_id, 'type' => 9, 'value' => -$level['buy_vit'], 'gold' => $player['gold'] - $level['buy_vit'], 'create_ts' => date("Y-m-d H:i:s")); Gold::model()->createGold($user_id, $gold_params); // 提交事务 $trans_characters->commit(); //获取角色信息 $info = Characters::model()->getCharactersInfo($user_id); $user_info = array('point' => (int) $info['point'], 'exp' => (int) $info['exp'], 'vit' => (int) $info['vit'], 'vit_time' => (int) $info['vit_time'], 'level' => (int) $info['level'], 'gold' => (int) $info['gold'], 'flowers' => (int) $info['flowers']); $return['log']['gold'] = -$level['buy_vit']; $return['log']['gold_after'] = $gold_params['gold']; $return['result'] = $user_info; } catch (Exception $e) { error_log($e); $trans_characters->rollback(); return -1; } return $return; }
/** * 关注女神 * * @param string $user_id * @param string $token * @param int $goddess_id * @param int $follow 1:关注 0:取消关注 2:用户取消关注 * * */ public function actionFollowGoddess() { // 参数检查 if (!isset($_REQUEST['user_id']) || !isset($_REQUEST['token']) || !isset($_REQUEST['goddess_id']) || !isset($_REQUEST['follow'])) { $this->_return('MSG_ERR_LESS_PARAM'); } $now = date("Y-m-d H:i:s"); $user_id = trim(Yii::app()->request->getParam('user_id')); $token = trim(Yii::app()->request->getParam('token')); $goddess_id = trim(Yii::app()->request->getParam('goddess_id')); $follow = trim(Yii::app()->request->getParam('follow')); if (!is_numeric($goddess_id) || !is_numeric($follow)) { $this->_return('MSG_ERR_FAIL_PARAM'); } if ($follow != 0 && $follow != 1 && $follow != 2) { $this->_return('MSG_ERR_FAIL_PARAM'); } if (!is_numeric($user_id)) { $this->_return('MSG_ERR_FAIL_PARAM'); } //用户不存在 返回错误 if ($user_id < 1) { $this->_return('MSG_ERR_NO_USER'); } //验证token if (!Token::model()->verifyToken($user_id, $token, $GLOBALS['__APPID'])) { //token 错误 $this->_return('MSG_ERR_TOKEN'); } //查询是否有此女神 if (!Goddess::model()->isExitsGoddess($goddess_id)) { $this->_return('MSG_ERR_NO_EXIST_GODDESS'); } //如果已经相同 则成功 $rw = Follow::model()->getFollowRow($user_id, $goddess_id); if (isset($rw['followed']) && $follow == $rw['followed']) { $this->_return('MSG_SUCCESS'); } //用户关注赞+1,女神照片赞+1,女神赞总数+1 $characters_transaction = Yii::app()->db_characters->beginTransaction(); $heroine_transaction = Yii::app()->db_heroine->beginTransaction(); try { //关注女神 Characters::model()->followGoddess($user_id, $goddess_id, $follow); $followerCount = Goddess::model()->getFollowerCount($goddess_id); if ($follow == 1) { $followerCount = $followerCount + 1; $arr = array('follower_count' => $followerCount); if ($rw['followed'] != 2) { //关注魅力值+10 $glamorousCount = Goddess::model()->getGlamorousCount($goddess_id); $glamorousCount = $glamorousCount + Yii::app()->params['follow_glamorous']; $arr = array('follower_count' => $followerCount, 'glamorous' => $glamorousCount); //关注加好感值 $liking = $rw['liking'] + (int) Yii::app()->params['follow_liking']; Follow::model()->updateFollowRow($user_id, $goddess_id, array('liking' => $liking)); //关注加经验 //获取用户基本信息 $player = Characters::model()->getCharactersInfo($user_id); //获取等级信息 $liking = Liking::model()->getLikingRow($player['level']); //加经验值 $params = array('exp' => $player['exp'] + (int) Yii::app()->params['follow_exp']); //加经验更新等级 $lv = Level::model()->exp2Level($params['exp']); if (!empty($lv) && strcmp($lv, $player['level']) != 0) { $param['level'] = $lv; } Characters::model()->updateCharacters($user_id, $params); } } if ($follow == 0) { $followerCount = max($followerCount - 1, 0); $arr = array('follower_count' => $followerCount); } //增加关注度 Goddess::model()->updateHeroineInfo($goddess_id, $arr); $characters_transaction->commit(); $heroine_transaction->commit(); //关注女神 Log::model()->_goddess_log($user_id, $goddess_id, 'DS_FOLLOW', date('Y-m-d H:i:s'), ''); } catch (Exception $e) { error_log($e); $characters_transaction->rollback(); $heroine_transaction->rollback(); $this->_return('MSG_ERR_UNKOWN'); } $this->_return('MSG_SUCCESS'); }
public function getLevel($player) { $cpoints = $this->getPositionAndPointOfUser($player->id); $points = $cpoints['current_points']; $criteria_max = new CDbCriteria(); $criteria_max->select = 't.*'; $criteria_max->order = 't.level DESC'; $criteria_max->limit = 1; $max = Level::model()->find($criteria_max); $max_point = $max->points_needed; $max_level = $max->level; $criteria_min = new CDbCriteria(); $criteria_min->select = 't.*'; $criteria_min->order = 't.level ASC'; $criteria_min->limit = 1; $min = Level::model()->find($criteria_min); $min_point = $min->points_needed; $min_level = $min->level; $next_min = Level::model()->findByPk($min_level + 1); if ($points >= $max_point) { return array('level' => $max_level, 'begin' => $max_point, 'next' => null); } else { if ($points == 0) { return array('level' => $min_level, 'begin' => $min_point, 'next' => $next_min->points_needed); } } $next = Yii::app()->db->createCommand()->select('t.*, MIN(t.level) AS begin')->from('tbl_level t')->where("points_needed > '" . $points . "'")->queryRow(); $begin_level = $next['begin'] - 1; $begin = Level::model()->findByPk($begin_level); return array('level' => $begin_level, 'begin' => $begin->points_needed, 'next' => $next['points_needed'], 'points' => $points); }
echo $form->labelEx($model, 'email'); ?> <?php echo $form->textField($model, 'email', array('size' => 50, 'maxlength' => 50)); ?> <?php echo $form->error($model, 'email'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'level_id'); ?> <?php echo $form->dropDownList($model, 'level_id', CHtml::listData(Level::model()->findAll(), 'id', 'level'), array('prompt' => 'Please Choose')); ?> <?php echo $form->error($model, 'level_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'avatar'); ?> <?php echo $form->fileField($model, 'avatar', array('size' => 30, 'maxlength' => 30)); ?> <?php echo $form->error($model, 'avatar');
/** * 给女神送礼 * @param unknown $user_id * @param unknown $goddess_id * @param unknown $gift_id * @param unknown $number */ public function giveGift($user_id, $goddess_id, $gift_id, $number) { try { $characters_transaction = Yii::app()->db_characters->beginTransaction(); $heroine_transaction = Yii::app()->db_heroine->beginTransaction(); //是否关注女神 if (!Follow::model()->isExitsFollow($user_id, $goddess_id)) { return -3; } //获取礼物信息 $gift_info = Gift::model()->getGiftInfo($gift_id); if ($gift_info) { //获取角色信息 $characters = Characters::model()->getCharactersInfo($user_id); if ($gift_info['is_give'] == 1) { $flowers_counts = $characters['flowers']; if ($number > $flowers_counts) { //赠送鲜花数超过已有鲜花数 $number = $number - $flowers_counts; $temp_num = $flowers_counts; } else { $temp_num = $number; } if ($temp_num != 0) { $characters['flowers'] = $characters['flowers'] - $temp_num; //角色加 经验 积分 $params = array('exp' => $characters['exp'] + $temp_num * $gift_info['add_exp'], 'point' => $characters['point'] + $temp_num * $gift_info['add_point'], 'flowers' => $characters['flowers']); //更新等级 $lv = Level::model()->exp2Level($params['exp']); if (!empty($lv) && strcmp($lv, $characters['level']) != 0) { $params['level'] = $lv; } Characters::model()->updateCharacters($user_id, $params); //女神好感 $follow = Follow::model()->getFollowRow($user_id, $goddess_id); //好感度 $liking_val = $follow['liking'] + $temp_num * $gift_info['add_liking']; //增加女神对角色的好感度 Follow::model()->updateFollow(date('Y-m-d H:i:s'), $user_id, $goddess_id, null, null, $liking_val); //增加魅力值 $glamorousCount = Goddess::model()->getGlamorousCount($goddess_id); $glamorous = array('glamorous' => (int) $glamorousCount + $temp_num * (int) $gift_info['add_glamorous']); Goddess::model()->updateHeroineInfo($goddess_id, $glamorous); //增加用户送礼物给女神记录 $this->createHeroineGift($user_id, $goddess_id, $gift_id, $temp_num); // 提交事务 $characters_transaction->commit(); $heroine_transaction->commit(); $res['log'] = ''; $res['log']['gold'] = 0; $res['result'] = array('point' => (int) $params['point'], 'exp' => (int) $params['exp'], 'vit' => (int) $characters['vit'], 'vit_time' => (int) $characters['vit_time'], 'level' => (int) $lv, 'gold' => (int) $characters['gold'], 'flowers' => (int) $characters['flowers'], 'goddess_id' => (int) $goddess_id, 'liking' => $liking_val); return $res; } } $total = $gift_info['gold'] * $number; //扣金币 if ($total > $characters['gold']) { return -4; } //角色加金币 经验 积分 $params = array('gold' => (int) $characters['gold'] - (int) $total, 'exp' => (int) $characters['exp'] + $number * $gift_info['add_exp'], 'point' => (int) $characters['point'] + $number * $gift_info['add_point']); //更新等级 $lv = Level::model()->exp2Level($params['exp']); if (!empty($lv) && strcmp($lv, $characters['level']) != 0) { $params['level'] = $lv; } Characters::model()->updateCharacters($user_id, $params); //女神好感 $follow = Follow::model()->getFollowRow($user_id, $goddess_id); //好感度 $liking_val = $follow['liking'] + $number * $gift_info['add_liking']; //增加女神对角色的好感度 Follow::model()->updateFollow(date('Y-m-d H:i:s'), $user_id, $goddess_id, null, null, $liking_val); //增加魅力值 $glamorousCount = Goddess::model()->getGlamorousCount($goddess_id); $glamorous = array('glamorous' => (int) $glamorousCount + $number * (int) $gift_info['add_glamorous']); Goddess::model()->updateHeroineInfo($goddess_id, $glamorous); //增加用户送礼物给女神记录 $this->createHeroineGift($user_id, $goddess_id, $gift_id, $number); // 提交事务 $characters_transaction->commit(); $heroine_transaction->commit(); $res['log']['gold'] = -$total; $res['log']['gold_after'] = (int) $characters['gold'] - (int) $total; $res['result'] = array('point' => (int) $params['point'], 'exp' => (int) $params['exp'], 'vit' => (int) $characters['vit'], 'vit_time' => (int) $characters['vit_time'], 'level' => (int) $lv, 'gold' => (int) $params['gold'], 'flowers' => (int) $characters['flowers'], 'goddess_id' => (int) $goddess_id, 'liking' => (int) $liking_val); } else { return -2; } } catch (Exception $e) { error_log($e); $characters_transaction->rollback(); $heroine_transaction->rollback(); //更新失败 return -1; } return $res; }
public function getLevel($id) { if (empty($id)) { return NULL; } $level = Level::model()->getScaler('name', '`id`=:t1 ', array(':t1' => $id)); return !empty($level) ? $level : NULL; }
<ul class="breadcrumb" style="background-color:#F8F8F8;"> <li><a href="<?php echo Yii::app()->createUrl('site/admin'); ?> "><span class="fa fa-dashboard"></span> Dashboard</a></li> <li><a href="<?php echo Yii::app()->createUrl('user/admin'); ?> "><span class="fa fa-user"></span> User</a></li> <li class="active"><span class="fa fa-cog"></span> Manage</li> </ul><hr> <?php if (Yii::app()->user->getState('level') == 1) { ?> <a href="<?php echo Yii::app()->createUrl('user/create'); ?> " class="btn btn-default"><span class="fa fa-plus"></span> Create</a> <?php $this->widget('booster.widgets.TbGridView', array('id' => 'user-grid', 'type' => 'striped bordered', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('id', 'username', 'password', array('name' => 'level_id', 'value' => '$data->level->level', 'filter' => CHtml::listData(Level::model()->findAll(array('order' => 'id')), 'id', 'level')), 'last_login', array('class' => 'booster.widgets.TbButtonColumn', 'htmlOptions' => array('style' => 'width:80px;'))))); } if (Yii::app()->user->getState('level') != 1) { ?> Anda tidak dapat mengakses halaman ini. Kembali ke <a href="<?php echo Yii::app()->createUrl('site/admin'); ?> ">Beranda</a> <?php }
/** * 用户等级信息 * */ public function actionLevelInfo() { $info = Level::model()->wholeLevelAround(); if (!is_array($info)) { $this->_return('MSG_ERR_UNKOWN'); } $this->_return('MSG_SUCCESS', $info); }
public function actionGetLevels() { $data = Level::model()->findAll(); ResponseHelper::JsonReturnSuccess($data); }
<?php $form = $this->beginWidget('booster.widgets.TbActiveForm', array('id' => 'user-form', 'enableAjaxValidation' => false)); ?> <?php echo $form->errorSummary($model); ?> <?php echo $form->textFieldGroup($model, 'username', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5', 'maxlength' => 64)))); ?> <?php echo $form->passwordFieldGroup($model, 'password', array('widgetOptions' => array('htmlOptions' => array('class' => 'span5', 'maxlength' => 128)))); ?> <?php echo $form->dropDownListGroup($model, 'level_id', array('wrapperHtmlOptions' => array('class' => 'col-sm-5'), 'widgetOptions' => array('data' => CHtml::listData(Level::model()->findAll(array('order' => 'level ASC')), 'id', 'level'), 'htmlOptions' => array('empty' => 'Choose')))); ?> <div class="form-actions"> <?php $this->widget('booster.widgets.TbButton', array('buttonType' => 'submit', 'context' => 'primary', 'label' => $model->isNewRecord ? 'Create' : 'Save')); ?> </div> <?php $this->endWidget();
/** * 每日玫瑰领取 * @param $user_id * @return bool */ public function everyRose($user_id) { $data = $this->getCharactersInfo($user_id); try { if (isset($data['level'])) { $level_info = Level::model()->getLevelRow($data['level']); $now = date("Y-m-d"); $last_get_time = date("Y-m-d", $data['flowers_ts']); if ($now == $last_get_time) { return false; } $param = array('flowers_ts' => time()); if ($data['flowers'] < $level_info['max_follower']) { //拥有数量小于最大值 if ($now != $last_get_time) { //今天第一次登陆(只在第一次登陆的时候领取, 如果第一次登陆没有领取, 以后登陆也不再有领取机会) $param['flowers'] = $level_info['max_follower']; } } $this->updateCharacters($user_id, $param); } } catch (Exception $e) { error_log($e); return false; } }
/** * API: 2.1.3.16 API_I_016 * 收体力 * @param int $user_id * @param string $token * @param string $message_id */ public function actionReceipt() { // 参数检查 if (!isset($_REQUEST['user_id']) || !isset($_REQUEST['token']) || !isset($_REQUEST['message_id'])) { $this->_return('MSG_ERR_LESS_PARAM'); } $user_id = trim(Yii::app()->request->getParam('user_id')); $token = trim(Yii::app()->request->getParam('token')); $message_id = trim(Yii::app()->request->getParam('message_id')); $now = date('Y-m-d H:i:s'); if (!is_numeric($user_id)) { $this->_return('MSG_ERR_FAIL_PARAM'); } if (!FriendVit::model()->getUserMess($user_id, $message_id)) { $this->_return('MSG_ERR_FAIL_PARAM'); } //用户不存在 返回错误 if ($user_id < 1) { $this->_return('MSG_ERR_NO_USER'); } //验证token if (!Token::model()->verifyToken($user_id, $token, $GLOBALS['__APPID'])) { $this->_return('MSG_ERR_TOKEN'); //#token 错误 } //查询今天收体力的数量是否已经超过上线 $num = FriendVit::model()->getEveryAcceptVitNum($user_id); if ($num >= Yii::app()->params['every_accept_vit_upper_limit']) { $this->_return('MSG_ERR_EVERY_ACCEPT_VIT'); //# } //获取用户游戏角色信息 $player = Characters::model()->getCharactersInfo($user_id); if (!is_array($player) || !isset($player['vit'])) { //未找到用户游戏角色信息 $this->_return('MSG_ERR_NO_FOUND_P_INFO'); } $level = Level::model()->exp2Level($player['exp']); $level_info = Level::model()->getLevelRow($level); if (isset($level_info['vit_per_giving'])) { $update_vit = $level_info['vit_per_giving']; } //最后插入的体力值 增加的+原有的 $vit = $update_vit + $player['vit']; if ($vit > $level_info['max_vit']) { $vit = $level_info['max_vit']; } if ($player['vit'] == $level_info['max_vit']) { //体力已满不能收体力 $this->_return('MSG_ERR_FULL_VIT'); } $characters_transaction = Yii::app()->db_characters->beginTransaction(); $vit_transaction = Yii::app()->db_friend_vit->beginTransaction(); $result = array(); try { //更新体力值 Characters::model()->updatePlayerInfo($user_id, array('vit' => $vit)); FriendVit::model()->updateVitStatus($user_id, $message_id); //返回参数 $result['point'] = $player['point']; $result['exp'] = $player['exp']; $result['vit'] = $vit; $result['vit_time'] = $player['vit_time']; $result['level'] = $level; $result['gold'] = $player['gold']; $result['flowers'] = $player['flowers']; $characters_transaction->commit(); $vit_transaction->commit(); } catch (Exception $e) { error_log($e); $characters_transaction->rollback(); $vit_transaction->rollback(); } //收体力日志 $this->_return('MSG_SUCCESS', $result); }
<?php /* @var $this UserController */ /* @var $model User */ $this->breadcrumbs = array('Profile' => array('index'), $model->username); $this->menu = array(array('label' => 'List User', 'url' => array('index')), array('label' => 'Create User', 'url' => array('create')), array('label' => 'Update User', 'url' => array('update', 'id' => $model->id)), array('label' => 'Delete User', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => 'Manage User', 'url' => array('admin'))); ?> <h1>View User <?php echo $model->username; ?> </h1> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('username', 'email', 'joinDate', array('label' => 'Level', 'type' => 'raw', 'value' => Level::model()->with('users')->findByPk($model->level_id)->level), array('label' => 'avatar', 'type' => 'raw', 'value' => CHtml::image(Yii::app()->baseUrl . '/avatar/' . $model->avatar)))));
<?php echo CHtml::activeDropDownList($staff_model, 'dept_id', Dept::model()->getListData('id', 'name', Lang::t('--Select Department--'), '`status`=:t1', array(':t1' => Dept::STATUS_OPEN)), array('class' => 'form-control')); ?> <?php echo CHtml::error($staff_model, 'dept_id'); ?> </div> </div> </div> <div class="form-group"> <?php echo CHtml::activeLabelEx($staff_model, 'level_id', array('class' => 'col-md-2 control-label', 'label' => Lang::t('Staff Role'))); ?> <div class="col-md-4"> <?php echo CHtml::activeDropDownList($staff_model, 'level_id', Level::model()->getListData('id', 'name', Lang::t('--Select Level--'), ""), array('class' => 'form-control')); ?> <?php echo CHtml::error($staff_model, 'level_id'); ?> </div> </div> <div id="person" class="panel-collapse collapse in"> <div class="panel-body"> <div class="form-group"> <div class="col-sm-7"> <?php $this->renderPartial('application.views.person._image_field', array('model' => $model, 'htmlOptions' => array('field_class' => 'col-md-8'))); ?> </div> </div>
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Level the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Level::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
echo $form->error($model, 'password'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'email'); echo $form->textField($model, 'email', array('size' => 50, 'maxlength' => 50)); echo $form->error($model, 'email'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'email'); echo $form->dropDownList($model, 'level_id', CHtml::listData(Level::model()->findAll(), 'id', 'level')); echo $form->error($model, 'level_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'joinDate'); echo $form->textField($model, 'joinDate'); echo $form->error($model, 'joinDate'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'avatar');