Example #1
0
 public function cardInfo($params = array())
 {
     extract($params);
     if (isset($type_id)) {
         $num = isset($num) && $num > 0 ? $num : 1;
         $result = Card::model()->getCards($type_id, $num);
         if ($result) {
             $ret = $this->notice('OK', 0, '成功', $result);
         } else {
             $ret = $this->notice('OK', 0, '成功', []);
         }
     } else {
         $ret = $this->notice('ERR', 301, '缺少参数', []);
     }
     return $ret;
 }
Example #2
0
 public function actionCreate()
 {
     $model = new ConsumerLog();
     $model->unsetAttributes();
     if ($_POST['ConsumerLog']) {
         $model->attributes = $_POST['ConsumerLog'];
         if ($model->validate()) {
             $model->setAttribute('fee', $model->price / $model->total);
             if ($model->save() && Card::model()->updateByPk($model->card_id, ['used_num' => $model->used + 1])) {
                 Yii::app()->user->setFlash('ConsumerLog', '提交成功');
             }
         }
     }
     $stores = Store::model()->getName();
     $this->render('create', ['model' => $model, 'stores' => $stores]);
 }
Example #3
0
 public function checkCard($attribute, $params)
 {
     if ($this->flag < 2) {
         if ($this->flag_content) {
             $obj = Card::model()->find(array('condition' => 'card_num=:num and is_sale =:sale', 'params' => array(':num' => $this->flag_content, ':sale' => '1')));
             if ($obj) {
                 if (strtotime($obj->start_time) > time()) {
                     $this->addError($attribute, '使用时间未开始');
                     return false;
                 }
                 if (strtotime($obj->end_time) < time()) {
                     $this->addError($attribute, '有效时间已过');
                     return false;
                 }
                 if ($obj->total_num > $obj->used_num) {
                     //ok
                     $this->total = $obj->total_num;
                     $this->used = $obj->used_num;
                     $this->price = $obj->price;
                     $this->card_id = $obj->card_id;
                     return true;
                 } else {
                     $this->addError($attribute, '次数已用完');
                 }
             } else {
                 $this->addError($attribute, '卡号不存在');
             }
         } else {
             $this->addError($attribute, '卡号不能为空');
         }
     } else {
         if ($this->flag == 2) {
             return true;
         } else {
             $this->addError($attribute, '卡号不存在');
         }
     }
 }
Example #4
0
 /**
  * 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 Card the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Card::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #5
0
 public function actionDeleteCard()
 {
     $id = $this->_get("id");
     if ($id) {
         if (Card::model()->deleteByPk($id)) {
             Yii::app()->user->setFlash('Card', '删除成功');
             $this->redirect(array('card/card'));
         }
     } else {
         $this->redirect(array('card/card'));
     }
 }