예제 #1
0
 public function actionScore()
 {
     $key = 'IJe9J4TyksBFSq6x';
     $user = Yii::app()->request->getParam('username', false);
     $imei = Yii::app()->request->getParam('sn', false);
     $package_name = Yii::app()->request->getParam('pk', false);
     $score = Yii::app()->request->getParam('score', 0);
     $sign = Yii::app()->request->getParam('sg', false);
     $unique_key = md5($user . ',' . $imei . ',' . $package_name . ',' . $score . ',' . $key);
     if ($sign == $unique_key) {
         if ($user && $score && $package_name) {
             $user_task = DreamNovelUserTask::model()->find('uid =:uid and task_id =:task_id and task_detail =:task_detail', array(':uid' => $user, ':task_id' => 4, ':task_detail' => $package_name));
             if (!$user_task) {
                 $user_task = new DreamNovelUserTask();
                 $user_task->uid = $user;
                 $user_task->task_id = 4;
                 $user_task->task_detail = $package_name;
                 $user_task->date = date('Y-m-d H:i:s');
                 $user_task->setIsNewRecord(true);
                 if ($user_task->save(false)) {
                     $user_info = DreamNovelUserInfo::model()->find('uid =:uid', array(':uid' => $user));
                     if ($user_info) {
                         $user_info->coin = $user_info->coin + $score;
                         $user_info->save(false);
                     }
                 }
             }
         }
     }
 }
예제 #2
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;
 }