Esempio n. 1
0
 public function run()
 {
     Yii::trace(get_class($this) . '.run()');
     $controller = parent::run();
     $json = isset($this->request->json) ? $this->request->json : false;
     if ($json) {
         $offset = isset($json->offset) ? $json->offset : 0;
         $pageSize = isset($json->pageSize) ? $json->pageSize : 10;
         $keyword = isset($json->keyword) ? $json->keyword : false;
         $result = DreamNovel::model()->getNovelSearch($keyword, $offset, $pageSize);
         $ls_count = $result['count'];
         if ($keyword) {
             $is_query = DreamNovelQuery::model()->find('query=:query', array(':query' => $keyword));
             if ($is_query) {
                 $ls_count = $is_query->counts;
                 $is_query->results = $ls_count;
                 $is_query->counts = $ls_count + 1;
                 $is_query->save(false);
             } else {
                 $new_query = new DreamNovelQuery();
                 $new_query->query = $keyword;
                 $new_query->results = $result['count'];
                 $new_query->counts = 1;
                 $new_query->save(false);
             }
         }
         $this->response->counts = $ls_count;
         return $this->response->novel_list = $result['data'];
     }
     return $this->response->code = 500;
 }
Esempio n. 2
0
 public function getRecommendNovel($gender, $category)
 {
     $criteria = new CDbCriteria();
     //优先分类获取
     if ($category) {
         $category_id = json_decode($category, true);
     } else {
         $category_id = array();
         $criteria->condition = 'gender =:gender';
         $criteria->params = array(':gender' => $gender);
         $category_info = $this->findAll($criteria);
         foreach ($category_info as $category_info_item) {
             $category_id[] = $category_info_item->id;
         }
     }
     return DreamNovel::model()->getNovelDetail($category_id, 'recommend', 1);
 }
Esempio n. 3
0
 public function run()
 {
     Yii::trace(get_class($this) . '.run()');
     $controller = parent::run();
     $json = isset($this->request->json) ? $this->request->json : false;
     if ($json) {
         $offset = isset($json->offset) ? $json->offset : 0;
         $pageSize = isset($json->pageSize) ? $json->pageSize : 10;
         $sort = isset($json->sort) ? $json->sort : false;
         $sort_type = isset($json->sort_type) ? $json->sort_type : false;
         $category_id = isset($json->category_id) ? $json->category_id : false;
         $this->response->category = DreamNovelCategory::model()->getCategoryList();
         $result = DreamNovel::model()->getNovelDetail($category_id, $sort, $sort_type, $offset, $pageSize);
         $this->response->counts = $result['count'];
         return $this->response->novel_list = $result['data'];
     }
     return $this->response->code = 500;
 }
Esempio n. 4
0
 public function run()
 {
     Yii::trace(get_class($this) . '.run()');
     $controller = parent::run();
     $json = isset($this->request->json) ? $this->request->json : false;
     if ($json) {
         $uid = isset($json->uid) ? $json->uid : false;
         $task_id = isset($json->task_id) ? $json->task_id : false;
         if ($uid && $task_id) {
             //task finish
             $today = date('Y-m-d');
             $task_is_daily = DreamNovelTask::model()->checkDaily($task_id);
             if ($task_is_daily) {
                 $taskRecord = DreamNovelUserTask::model()->find('uid=:uid and task_id =:task_id and date =:date', array(':uid' => $uid, ':task_id' => $task_id, ':date' => $today));
                 if ($taskRecord) {
                     $this->response->code = 250;
                 } else {
                     $taskRecord = new DreamNovelUserTask();
                     $taskRecord->uid = $uid;
                     $taskRecord->task_id = $task_id;
                     $taskRecord->task_detail = 0;
                     $taskRecord->date = $today;
                     $taskRecord->setIsNewRecord(true);
                     if ($taskRecord->save(false)) {
                         $status = DreamNovelUserInfo::model()->updateCoin($uid, $task_id, 'plus');
                         if ($status) {
                             $this->response->code = 200;
                         }
                     } else {
                         $this->response->code = 404;
                     }
                 }
             } else {
                 $novel_id = isset($json->novel_id) ? $json->novel_id : false;
                 if ($novel_id) {
                     $novel_info = DreamNovel::model()->find('id =:id', array(':id' => $novel_id));
                     if ($novel_info) {
                         $taskRecord = DreamNovelUserTask::model()->find('uid=:uid and task_id =:task_id and task_detail =:task_detail', array(':uid' => $uid, ':task_id' => $task_id, ':task_detail' => $novel_id));
                         if ($taskRecord) {
                             $this->response->download = Util::getHost() . $novel_info->download;
                         } else {
                             $user_coin = DreamNovelUserInfo::model()->getCoin($uid);
                             if ($user_coin >= $novel_info->price) {
                                 $taskRecord = new DreamNovelUserTask();
                                 $taskRecord->uid = $uid;
                                 $taskRecord->task_id = $task_id;
                                 $taskRecord->task_detail = $novel_id;
                                 $taskRecord->date = $today;
                                 $taskRecord->setIsNewRecord(true);
                                 if ($taskRecord->save(false)) {
                                     $status = DreamNovelUserInfo::model()->updateCoin($uid, $novel_info->price, 'minus');
                                     if ($status) {
                                         $this->response->download = Util::getHost() . $novel_info->download;
                                         $ls_novel_hot = $novel_info->hot;
                                         $novel_info->hot = $ls_novel_hot + 1;
                                         $novel_info->save(false);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             return $this->response->coin = DreamNovelUserInfo::model()->getCoin($uid);
         } else {
             $this->response->coin = DreamNovelUserInfo::model()->getCoin($uid);
             $this->response->category = DreamNovelCategory::model()->getCategoryList();
             return $this->response->task_list = DreamNovelTask::model()->getTaskList();
         }
     }
     return $this->response->code = 500;
 }