Esempio n. 1
0
 public function actionCommentApi()
 {
     $img_id = $_POST['img_id'];
     $body = $_POST['body'];
     $image = Image::model()->findByPk($img_id);
     $user = User::model()->findByPk($this->usr_id);
     $ex_gold = $user->gold;
     $ex_exp = $user->exp;
     $ex_lv = $user->lv;
     /*
             $comment = array(
        'usr_id' => $this->usr_id,
        'name' => $user->name,
        'body' => $body,
        'create_time' => time(),
             );
     */
     if (isset($_POST['reply_id'])) {
         $image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'reply_id:' . $_POST['reply_id'] . ',' . 'reply_name:' . $_POST['reply_name'] . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments;
         //PMail::create($_POST['reply_id'], $user, $user->name.'在'.$image->img_id.'回复了你');
     } else {
         $image->comments = 'usr_id:' . $this->usr_id . ',' . 'name:' . $user->name . ',' . 'body:' . $body . ',' . 'create_time:' . time() . ';' . $image->comments;
     }
     if ($image->saveAttributes(array('comments'))) {
         $animal = Animal::model()->findByPk($image->aid);
         $animal->t_rq += 5;
         $animal->d_rq += 5;
         $animal->w_rq += 5;
         $animal->m_rq += 5;
         $animal->saveAttributes(array('t_rq', 'd_rq', 'w_rq', 'm_rq'));
         $session = Yii::app()->session;
         if (isset($session['comment_count'])) {
             $session['comment_count'] += 1;
         } else {
             $session['comment_count'] = 1;
         }
         if ($session['comment_count'] <= 15) {
             $user->comment();
         }
         if (isset($_POST['reply_id'])) {
             Talk::model()->sendMsg(NPC_IMAGE_USRID, $_POST['reply_id'], "[" . $image->img_id . "]" . $user->name . "回复了你:" . $body);
         } else {
             Talk::model()->sendMsg(NPC_IMAGE_USRID, $animal->master_id, "[" . $image->img_id . "]" . $user->name . "评论了你:" . $body);
         }
         $this->echoJsonData(array('exp' => $user->exp - $ex_exp, 'gold' => $user->gold - $ex_gold, 'lv' => $user->lv - $ex_lv));
     }
 }
Esempio n. 2
0
 public function actionModifyInfoApi($aid, $name, $gender, $age, $type)
 {
     $pattern = '/^[a-zA-Z0-9\\x{30A0}-\\x{30FF}\\x{3040}-\\x{309F}\\x{4E00}-\\x{9FBF}]+$/u';
     //$namelen = (strlen($name)+mb_strlen($name,"UTF8"))/2;
     $namelen = mb_strlen($name, "UTF8");
     if ($namelen > 8) {
         throw new PException('宠物昵称超过最大长度');
     }
     if (!preg_match($pattern, $name)) {
         throw new PException('宠物昵称含有特殊字符');
     }
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $animal = Animal::model()->findByPk($aid);
         $animal->name = $name;
         $animal->age = $age;
         $animal->type = $type;
         $animal->gender = $gender;
         $animal->saveAttributes(array('name', 'age', 'type', 'gender'));
         $transaction->commit();
         $this->echoJsonData(array('isSuccess' => true));
     } catch (Exception $e) {
         $transaction->rollback();
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * ANIMAL FINDALL
  */
 public function actionAnimalFindAll()
 {
     $dadosPost = Yii::app()->request->rawBody;
     $parametros = CJSON::decode($dadosPost, true);
     $condition = " 1=1 ";
     $params = array();
     $criteria = new CDbCriteria();
     $criteria->condition = $condition;
     $criteria->params = $params;
     $criteria->together = true;
     $criteria->order = 'id asc';
     $animais = Animal::model()->findAll($criteria);
     $jsons = array();
     foreach ($animais as $key => $animal) {
         $dados = array();
         $dados['id'] = $animal->id;
         $dados['nome'] = $animal->nome;
         $dados['nascimento'] = strftime('%d%m%Y', strtotime($animal->nascimento));
         $dados['nascimentonome'] = strftime('%d de %b, %Y', strtotime($animal->nascimento));
         $dados['registro'] = $animal->registro;
         $dados['dna'] = $animal->dna;
         $dados['pelagem'] = $animal->pelagem;
         $dados['video'] = $animal->video;
         $dados['descricao'] = $animal->descricao;
         $dados['pai'] = $animal->pai;
         $dados['nomepai'] = isset($animal->Pai) ? $animal->Pai->nome : '';
         $dados['mae'] = $animal->mae;
         $dados['nomemae'] = isset($animal->Mae) ? $animal->Mae->nome : '';
         $dados['sexo'] = $animal->sexo;
         $dados['nomeraca'] = isset($animal->Raca) ? $animal->Raca->nome : '';
         $dados['raca'] = $animal->raca;
         $dados['pagina'] = $animal->pagina;
         $dados['paginanome'] = isset($animal->Pagina) ? $animal->Pagina->nome : '';
         $dados['show'] = true;
         $dados['qtdimagem'] = count($animal->Imagemanimal);
         if (count($animal->Imagemanimal) > 0) {
             foreach ($animal->Imagemanimal as $key => $imagem) {
                 $dados[$imagem->descricao] = $imagem->url;
             }
         }
         $count = 1;
         while ($count <= 8) {
             if (!isset($dados['imagem' . $count]) || $dados['imagem' . $count] == "") {
                 $dados['imagem' . $count] = Yii::app()->baseUrl . "/assets/images/simbolo/thumbnail-default.jpg";
             }
             $count++;
         }
         $jsons[] = $dados;
     }
     header('Content-type: application/json; charset=utf-8');
     echo CJSON::encode($jsons);
     Yii::app()->end();
 }