Beispiel #1
0
 public static function setNewCoupon($data)
 {
     $data['exp_date'] = strtotime($data['exp_date']);
     $data['set_percent'] = (int) $data['set_percent'];
     if ($data['exp_date'] > time() && $data['set_percent'] <= 100) {
         $model = new Coupons();
         $model->coupon_token = md5($data['exp_date'] . $data['set_percent'] . time());
         $model->coupon_expire_time = $data['exp_date'];
         $model->coupon_percent = $data['set_percent'];
         $model->insert();
     }
 }
 public function actionIndex()
 {
     $data = Coupons::find()->where(['>', 'coupon_expire_time', time()]);
     $get = Yii::$app->request->get();
     if (!empty($get)) {
         Coupons::setNewCoupon($get);
         $this->redirect('/coupon');
     }
     $dataProvider = new ActiveDataProvider(['query' => $data]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }