Example #1
0
 public function actionIndex()
 {
     if (isset($_POST['TblActivationTotal'])) {
         // 查询此 id 是否存在
         $start = Yii::app()->db->createCommand()->select('total')->from('tbl_activation_total')->where('id=:id', array(':id' => $_POST['TblActivationTotal']['id']))->queryScalar();
         if ($start) {
             // 如果存在,追加激活码
             $model = TblActivationTotal::model()->findByPk($_POST['TblActivationTotal']['id']);
             $model->total += $_POST['TblActivationTotal']['total'];
             $model->tips = $_POST['TblActivationTotal']['tips'];
         } else {
             // 新增加
             $start = 0;
             $model = new TblActivationTotal();
             $model->attributes = $_POST['TblActivationTotal'];
             $model->create_time = time();
         }
         if ($model->save()) {
             //                生成验证码
             $this->createActivation($model->id, $start, $_POST['TblActivationTotal']['total']);
             echo json_encode(array('status' => 1, 'msg' => '创建激活码成功'));
         } else {
             echo json_encode(array('status' => 0, 'error' => '出现未知错误。'));
         }
         Yii::app()->end();
     }
     $model = new TblActivationTotal();
     $this->render('index', array('model' => $model));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return TblActivationTotal the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = TblActivationTotal::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }