Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Card::find()->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'use_start_at' => $this->use_start_at, 'use_out_at' => $this->use_out_at, 'validity_time' => $this->validity_time, 'rate' => $this->rate, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Esempio n. 2
0
 public static function getCard()
 {
     $models = Card::find()->asArray()->all();
     return $models;
 }
Esempio n. 3
0
/* @var $model common\models\base\activity\Code */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="code-form">

    <?php 
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'coupon_id')->dropDownList(ArrayHelper::map(Card::find()->asArray()->all(), 'id', 'title'));
?>


    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>

    <?php 
ActiveForm::end();
?>

</div>
Esempio n. 4
0
 /**
  * Updates an existing Code model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(\App::$app->request->post())) {
         $id = \App::$app->request->post()['Code']['coupon_id'];
         $card = Card::find($id)->asArray()->one();
         $model->coupon_id = \App::$app->request->post()['Code']['coupon_id'];
         $model->validity_time = $card['validity_time'];
         $model->use_end_time = $card['use_out_at'];
         $model->use_at = $card['use_start_at'];
         $model->name = \App::$app->request->post()['Code']['name'];
         $model->rate = $card['rate'];
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $model->validity_time = date('Y-m-d', $model->validity_time);
         $model->use_end_time = date('Y-m-d', $model->use_end_time);
         return $this->render('update', ['model' => $model]);
     }
 }
Esempio n. 5
0
 /**
  * Auther:langxi
  * $member_id:用户id、$coupon_id:加息劵id
  * (仅)用户使用加息劵,使用时间,结束时间,能否使用加息劵判断。
  */
 public static function useRaise($member_id, $coupon_id)
 {
     //判断加息是否达到每日加息最大值,若达到则提示用户,加息劵不可使用
     $Raise = (new \yii\db\Query())->select(['sum(rate)'])->from(['activity_raise_card'])->where(['member_id' => $member_id, 'status' => 1])->createCommand();
     $TotalRaise = $Raise->queryAll();
     $max_raise = self::getRaise();
     if ($TotalRaise['0']['sum(rate)'] > $max_raise) {
         throw new ErrorException('今日加息已达到最大值,请明日再用', 7001);
     } else {
         $card = Card::find()->where(['id' => $coupon_id])->asArray()->one();
         $validity_time = $card['validity_time'];
         $Raise = RaiseCard::find()->where(['member_id' => $member_id, 'id' => $coupon_id])->asArray()->one();
         $raise_id = $Raise['id'];
         $Raise = RaiseCard::findOne($raise_id);
         $Raise->use_at = time();
         $Raise->use_end_time = time() + $validity_time * 3600 * 24;
         $Raise->status = '1';
         $Raise = $Raise->save();
         if (!$Raise) {
             throw new ErrorException('加息劵使用失败', 5002);
         }
     }
 }
Esempio n. 6
0
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="card-index">

    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a(Yii::t('app', '创建'), ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', ['attribute' => 'use_start_at', 'format' => ['date', 'php:Y-m-d']], ['attribute' => 'use_out_at', 'format' => ['date', 'php:Y-m-d']], 'validity_time', ['attribute' => 'rate', 'value' => function ($model) {
    return $model->rate * 100;
}], ['attribute' => 'status', 'format' => 'html', 'value' => function ($model) {
    if ($model->status === \common\models\base\activity\Card::STATUS_ACTIVE) {
        $class = 'label-success';
    } else {
        $class = 'label-danger';
    }
    return '<span class="label ' . $class . '">' . $model->statusLabel . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status', \common\models\base\activity\Card::labels(), ['class' => 'form-control', 'prompt' => '请筛选'])], ['class' => 'yii\\grid\\ActionColumn', 'header' => '操作', 'buttons' => ['delete' => function ($url, $model, $key) {
    return Html::a('<span class="glyphicon glyphicon-trash"></span>', $url, ['title' => '删除', 'data' => ['confirm' => '你确定要删除吗?', 'method' => 'post']]);
}]]]]);
?>

</div>
Esempio n. 7
0
    $children = Setting::find()->where(['parent_id' => $parent->id])->orderBy(['sort_order' => SORT_ASC, 'id' => SORT_ASC])->all();
    foreach ($children as $child) {
        $str .= '<div class="form-group field-blogcatalog-parent_id"><label class="col-lg-2 control-label" for="blogcatalog-parent_id">' . Yii::t('app', $child->code) . '</label><div class="col-lg-3">';
        if ($child->type == 'text') {
            $str .= Html::textInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]);
        } elseif ($child->type == 'password') {
            $str .= Html::passwordInput("Setting[{$child->code}]", $child->value, ["class" => "form-control"]);
        } elseif ($child->type == 'select') {
            $options = [];
            $arrayOptions = explode(',', $child->store_range);
            foreach ($arrayOptions as $option) {
                $options[$option] = Yii::t('app', $option);
            }
            $str .= Html::dropDownList("Setting[{$child->code}]", $child->value, $options, ["class" => "form-control"]);
        } elseif ($child->type == 'checkrate') {
            $str .= Html::dropDownList("Setting[{$child->code}]", $child->value, ArrayHelper::map(Card::find()->asArray()->all(), 'id', 'title'), ["class" => "form-control"]);
        } elseif ($child->type == 'input') {
            $directoryAsset = 'http://testwww.huoqiwang.com/upload/';
            $str .= '<input type="file" name="Setting[img]" value="' . $child->value . '"/>' . '<img style="width:100px;height:100px" src="' . $directoryAsset . $child->value . '"."/>';
        }
        $str .= '</div></div>';
    }
    $item['content'] = $str;
    array_push($items, $item);
}
?>

<style>
.tab-pane {padding-top: 20px;}
</style>
Esempio n. 8
0
 /**
  * Auther:langxi
  * $member_id:用户id、$coupon_id:加息劵id
  * (仅)用户使用加息劵,使用时间,结束时间,能否使用加息劵判断。
  */
 public static function useRaise($member_id, $coupon_id)
 {
     if (!$member_id || !is_numeric($member_id) || !is_int($member_id) || !$coupon_id || !is_numeric($coupon_id) || !is_int($coupon_id)) {
         $result = array('errorNum' => '1', 'errorMsg' => '参数错误', 'data' => null);
         return $result;
     }
     $is_user = Info::find()->where(['member_id' => $member_id])->asArray()->one();
     if (!$is_user) {
         $result = array('errorNum' => '1', 'errorMsg' => '参数错误', 'data' => null);
         return $result;
     }
     $is_coupon = RaiseCard::find()->where(['id' => $coupon_id, 'member_id' => $member_id])->asArray()->one();
     if (!$is_coupon) {
         $result = array('errorNum' => '1', 'errorMsg' => '参数错误', 'data' => null);
         return $result;
     }
     //判断加息是否达到每日加息最大值,若达到则提示用户,加息劵不可使用
     $Raise = (new \yii\db\Query())->select(['sum(rate)'])->from(['activity_raise_card'])->where(['member_id' => $member_id, 'status' => 1])->createCommand();
     $TotalRaise = $Raise->queryAll();
     $max_raise = self::getRaise();
     if ($TotalRaise['0']['sum(rate)'] > $max_raise) {
         $result = array('errorNum' => '1', 'errorMsg' => '今日加息已达到最大值,请明日再用', 'data' => null);
         return $result;
     } else {
         $card = Card::find()->where(['id' => $coupon_id])->asArray()->one();
         $validity_time = $card['validity_time'];
         $Raise = RaiseCard::find()->where(['member_id' => $member_id, 'id' => $coupon_id])->asArray()->one();
         $raise_id = $Raise['id'];
         $Raise = RaiseCard::findOne($raise_id);
         $Raise->use_at = time();
         $Raise->use_end_time = time() + $validity_time * 3600 * 24;
         $Raise->status = '1';
         $Raise = $Raise->save();
         if (!$Raise) {
             $result = array('errorNum' => '1', 'errorMsg' => '加息劵使用失败', 'data' => null);
             return $result;
         } else {
             $result = array('errorNum' => '0', 'errorMsg' => 'success', 'data' => null);
             return $result;
         }
     }
 }
Esempio n. 9
0
 /**
  * Finds the Card model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Card the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Card::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }