/**
  * 助力数据
  * GET api/activity/luckybag/{luckybagId}/vote 
  */
 public function actionRestlist()
 {
     $this->checkRestAuth();
     $luckybag = Luckybag::model()->findByPk($_GET['luckybagId']);
     if ($luckybag == null || $luckybag->nickname == null) {
         $this->sendResponse(404, 'not found');
     }
     $criteria = new CDbCriteria();
     $take = 100;
     $criteria->compare('luckybag_id', $luckybag->id);
     $criteria->limit = $take;
     $criteria->offset = 0;
     $criteria->order = 'created_time DESC';
     $result = LuckybagVote::model()->findAll($criteria);
     $json = new JsonData();
     $json->limit = $take;
     $json->total = (int) LuckybagVote::model()->count($criteria);
     $json->result = $this->JSONArrayMapper($result);
     echo CJSON::encode($json);
 }
Example #2
0
 public function actionRestexchange()
 {
     $this->checkRestAuth();
     //判断是否全部填写
     if (!isset($_POST['bag'])) {
         return $this->sendResponse(400, 'missed required properties');
     }
     // 查询是否已经生成
     $luckybag = Luckybag::model()->findByPk($_GET['luckybagId']);
     if ($luckybag == null) {
         return $this->sendResponse(404, 'not found');
     }
     if ($luckybag->exchange == 1) {
         return $this->sendResponse(400, 'exchanged');
     }
     $luckybag->exchange = 1;
     $luckybag->exchange_bag = $_POST['bag'];
     if (!$luckybag->save()) {
         return $this->sendResponse(500, 'faild to save luckybag');
     }
     echo CJSON::encode($this->JSONMapper($luckybag));
 }