Exemplo n.º 1
0
 /**
  * 金币解锁照片
  *
  * @param int $user_id
  * @param int $goddess_id
  * @param int $token
  * @param int $image_id
  *
  */
 public function actionGoldUnlockPhoto()
 {
     // 参数检查
     if (!isset($_REQUEST['user_id']) || !isset($_REQUEST['token']) || !isset($_REQUEST['goddess_id']) || !isset($_REQUEST['image_id'])) {
         $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'));
     $image_id = trim(Yii::app()->request->getParam('image_id'));
     $now = date("Y-m-d H:i:s");
     if (!is_numeric($user_id)) {
         $this->_return('MSG_ERR_FAIL_PARAM');
     }
     //用户不存在 返回错误
     if ($user_id < 1) {
         $this->_return('MSG_ERR_NO_USER');
     }
     if (!Goddess::model()->isExitsGoddess($goddess_id)) {
         //不存在此女神
         $this->_return("MSG_ERR_NO_EXIST_GODDESS");
     }
     //验证token
     if (Token::model()->verifyToken($user_id, $token, $GLOBALS['__APPID'])) {
         //金币解锁照片
         $res = Goddess::model()->GoldUnlockPhoto($user_id, $goddess_id, $image_id);
         switch ($res) {
             case -1:
                 $this->_return('MSG_ERR_NO_FOUND_IMG');
             case -2:
                 $this->_return('MSG_ERR_FAIL_UNLOCKED');
             case -3:
                 $this->_return('MSG_ERR_NO_GOLD');
             default:
                 break;
         }
         $memo = $res['log']['gold'];
         //记录日志 金币解锁照片
         Log::model()->_photo_log($user_id, $goddess_id, $image_id, 'GOLD_UNLOCK_IMG', date('Y-m-d H:i:s'), $memo);
     } else {
         $this->_return('MSG_ERR_TOKEN');
     }
     // 发送返回值
     $this->_return('MSG_SUCCESS', $res['result']);
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 /**
  * 保存用户女神消息到消息队列
  *
  * @param unknown $user_id
  * @param unknown $msg
  * @param number $level
  * @param number $send_time
  * @return unknown
  */
 public function insertUserGoddessMess($user_id, $goddess_id, $msg, $type, $level = 0, $send_time = 0)
 {
     $con_message = Yii::app()->db_message;
     $message_transaction = Yii::app()->db_message->beginTransaction();
     try {
         //极光ID
         $registration_arr = User::model()->findRegJpush($user_id);
         if ($registration_arr) {
             $registration_id = $registration_arr['registration_id'];
             $mess_id = $msg['mess_id'];
             $time = strtotime($send_time);
             //查询女神信息
             $info = Goddess::model()->getGoddessInfo($goddess_id);
             $content = sprintf($msg['content'], $info['nickname']);
             $content = $msg['content'];
             //获得某用户某女神  未关注  图片ID列表 随机图片ID
             $photoinfo = Photo::model()->getNoFollowPhotoInfo($user_id, $goddess_id, $level);
             if ($photoinfo) {
                 $msgcontent['image'] = $photoinfo['url'];
                 //$type 2-audio  3-media 时 url 有
                 if ($msg['type'] == 2 || $msg['type'] == 3) {
                     $msgcontent['url'] = Yii::app()->params['img_url_base'] . $msg['url'];
                     $msg_id = $msg['msg_id'];
                 } else {
                     $msgcontent['url'] = '';
                     $msg_id = $photoinfo['photo_id'];
                 }
                 //保存消息到队列
                 // 创建消息队列
                 $con_message->createCommand()->insert('message_queue', array('user_id' => $user_id, 'send_time' => $time, 'msg_text' => $content, 'msg_type' => $msg['type'], 'msg_image' => $photoinfo['url'], 'msg_url' => $msgcontent['url'], 'msg_id' => $msg_id, 'msg_goddess_id' => $goddess_id, 'type' => $type, 'status' => 0));
                 //记录推送消息
                 $res = Yii::app()->db_message->getLastInsertID();
             } else {
                 //没有获得随机推送照片
                 $res = -3;
             }
             $message_transaction->commit();
         } else {
             //未查到用户极光ID  不能发送
             $res = -1;
             $message_transaction->commit();
         }
     } catch (Exception $e) {
         error_log($e);
         //SQL错误
         return $res = -2;
     }
     return $res;
 }
Exemplo n.º 4
0
 /**
  * 获取所有未关注女神ID列表
  * @param int $user_id
  * @return multitype:
  */
 public function getNoFollowIds($user_id)
 {
     //获取用户所有女神id
     $goddess_list = Goddess::model()->goddessList();
     //获取用户所有关注的女神id
     $data = Follow::model()->followedList($user_id);
     //去重
     $id_list = array_diff_assoc($goddess_list, $data);
     return $id_list;
 }