示例#1
0
 /**	
  * 获取礼物信息
  * @param int    $type          // 礼物类型
  */
 public function actionGetGiftInfo()
 {
     // 参数检查
     if (!isset($_REQUEST['type'])) {
         $this->_return('MSG_ERR_LESS_PARAM');
     }
     $type = trim(Yii::app()->request->getParam('type'));
     $now = date("Y-m-d H:i:s");
     if (!is_numeric($type)) {
         $this->_return('MSG_ERR_FAIL_PARAM');
     }
     $data = Gift::model()->schedule($type);
     $result = array();
     if (is_array($data) && !empty($data)) {
         foreach ($data as $k => $v) {
             $temp = array();
             $temp['id'] = (int) $v['gift_id'];
             $temp['url'] = Yii::app()->params['img_url_base'] . $v['url'];
             $temp['name'] = $v['name'];
             $temp['type'] = (int) $v['type'];
             $temp['liking'] = (int) $v['add_liking'];
             $temp['exp'] = (int) $v['add_exp'];
             $temp['point'] = (int) $v['add_point'];
             $temp['vit'] = (int) $v['minus_vit'];
             $temp['level'] = (int) $v['lv'];
             $temp['gold'] = (int) $v['gold'];
             $result[] = $temp;
         }
     }
     $this->_return('MSG_SUCCESS', $result);
 }
示例#2
0
 /**
  * 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 the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Gift::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#3
0
 /**
  * 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);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Giver'])) {
         $_POST['Giver']['phone'] = $this->cleanPhoneNumber($_POST['Giver']['phone']);
         $model->attributes = $_POST['Giver'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('update', array('model' => $model, 'giftModel' => Gift::model()));
 }
示例#4
0
 public function actionConfirm()
 {
     //Check for user action (if the user has already filled in his details or not)
     if (isset($_SESSION) && isset($_SESSION['userRegisterVal']) && $_SESSION['userRegisterVal']['email'] != '') {
         $this->layout = "homeinner";
         $modelUser = new Users();
         //for getting lastly saved value of Gift model
         $userGiftId = $_SESSION['giftId'];
         if (isset($userGiftId) && $userGiftId != '') {
             Yii::app()->user->setFlash('successmessage', 'You have been registered properly.. Please check your mailbox');
         } else {
             Yii::app()->user->setFlash('failuremessage', 'Please fill the form properly again');
         }
         //for getting lastly saved value of Gift model by current user
         $giftLastValue = Gift::model()->findByAttributes(array('id' => $userGiftId));
         //for getting lastly saved value of Gift model by current user
         //destroying session here..
         session_destroy();
         //create new session to keep current gift id for fbshare
         session_start();
         $_SESSION['giftId'] = $userGiftId;
         //render page to view page....
         $this->render('finalconfirmed', array('modelUser' => $modelUser, 'maxIdGift' => $userGiftId, 'giftLastValue' => $giftLastValue));
     } else {
         //Redirect to home page
         $this->redirect('../index.php', '');
     }
 }
示例#5
0
 /**
  * 给女神送礼
  * @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;
 }
示例#6
0
 /**
  * 礼物发送页面
  */
 public function actionCreate()
 {
     //添加补充信息
     $this->accessOptions = array(0 => '公开赠送', 1 => '私下赠送(不让其他人知道是你送的)', 2 => '匿名赠送(不让接收礼物的人知道是你送的)');
     $model = new GiftUser();
     //礼物的种类
     $criteria = new CDbCriteria();
     $criteria->condition = "status=:status";
     $criteria->params = array(':status' => 1);
     //取得数据总数,分页显示
     $total = Gift::model()->count($criteria);
     $pages = new CPagination($total);
     $pages->pageSize = self::PAGE_SIZE;
     $pages->applyLimit($criteria);
     //获取数据集
     $gifts = Gift::model()->findAll($criteria);
     if (isset($_POST['GiftUser'])) {
         //传递数据格式为fuid =  1,2,4
         /*
         $friend_str = $_POST['fri_ids'];
         $friend_ids = explode(',',$friend_str) ;
         */
         $friend_ids = $_POST['friend_ids'];
         if (empty($friend_ids)) {
             //请选择好友
             throw new CHttpException(404, '请选择好友.');
         }
         $gift_ids = $_POST['gift_ids'];
         if (empty($gift_ids)) {
             //请选择礼物的种类
             throw new CHttpException(404, '先选择礼物.');
         }
         //先对某个用户发送礼物
         foreach ($friend_ids as $toUserid) {
             //发送各种礼物
             foreach ($gift_ids as $giftid) {
                 $model = new GiftUser();
                 $model->attributes = $_POST['GiftUser'];
                 $model->toUserid = $toUserid;
                 $model->giftid = $giftid;
                 $model->save();
             }
         }
         //跳转到发送页
         $this->redirect(array('send'));
     }
     $data = array('gifts' => $gifts, 'model' => $model, 'pages' => $pages);
     $this->render('create', $data);
 }
示例#7
0
 public function actionEditUser($id)
 {
     $this->layout = "admindashboard";
     //for editing users starts here
     $model = $this->loadModelUser($id);
     //for getting values from gift model
     $Gift = Gift::model()->findByAttributes(array('user_id' => $model->id));
     // for getting values from gift model
     //Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['Users'])) {
         $model->attributes = $_POST['Users'];
         $model->status = $_POST['status'];
         $Gift->custom_msg = $_POST['custom_msg'];
         $model->date_modified = date('Y-m-d H:i:s');
         if ($model->save()) {
             $Gift->save();
             $this->redirect(array('userList'));
         }
     }
     $this->render('edituser', array('model' => $model, 'Gift' => $Gift));
     //for editing users ends here
 }
示例#8
0
 /**
  * 给女神送礼物
  *
  * @param int    $user_id
  * @param string $token
  * @param int    $goddess_id
  * @param int    $gift_id
  *
  */
 public function actionGiftGiving()
 {
     // 参数检查
     if (!isset($_REQUEST['user_id']) || !isset($_REQUEST['token']) || !isset($_REQUEST['goddess_id']) || !isset($_REQUEST['gift_id']) || !isset($_REQUEST['gift_num'])) {
         $this->_return('MSG_ERR_LESS_PARAM');
     }
     $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'));
     $gift_id = trim(Yii::app()->request->getParam('gift_id'));
     $number = trim(Yii::app()->request->getParam('gift_num'));
     //判断女神id 和 礼品id 数据类型
     if (!is_numeric($goddess_id) || !is_numeric($gift_id)) {
         $this->_return('MSG_ERR_FAIL_PARAM');
     }
     if (!is_numeric($user_id)) {
         $this->_return('MSG_ERR_FAIL_PARAM');
     }
     if ($number <= 0) {
         $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'])) {
         //送礼物
         $res = Gift::model()->giveGift($user_id, $goddess_id, $gift_id, $number);
         switch ($res) {
             case -1:
                 $this->_return('MSG_ERR_UNKOWN');
             case -2:
                 $this->_return('MSG_ERR_NO_GIFT');
             case -3:
                 $this->_return('MSG_ERR_NO_FOLLOW');
             case -4:
                 $this->_return('MSG_ERR_NO_GOLD');
             default:
                 break;
         }
         if (isset($res['log']['gold_after']) && isset($res['log']['gold'])) {
             //道具购买
             Log::model()->_gold_log($user_id, $res['log']['gold'], $res['log']['gold_after'], 'GOLD_BUY_ITEM', date('Y-m-d H:i:s'), '');
         }
         //送礼物日志
         Log::model()->_gift_log($user_id, $goddess_id, $gift_id, $number, $res['log']['gold'], 'DS_TRIBUTE_GIFT', date('Y-m-d H:i:s'), '');
         //成功
         $this->_return('MSG_SUCCESS', $res['result']);
     } else {
         //token 错误
         $this->_return('MSG_ERR_TOKEN');
     }
 }