81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年6月30日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\modules\admin\controllers;
|
|
|
|
use app\models\Coupon;
|
|
use app\models\Store;
|
|
use app\modules\admin\behaviors\LoginBehavior;
|
|
use app\modules\admin\models\coupon\CouponActionForm;
|
|
use app\modules\admin\models\coupon\CouponEditForm;
|
|
use app\modules\admin\models\coupon\CouponListForm;
|
|
|
|
class CouponController extends Controller
|
|
{
|
|
public function behaviors()
|
|
{
|
|
return array_merge(parent::behaviors(), [
|
|
'login' => [
|
|
'class' => LoginBehavior::className(),
|
|
],
|
|
]);
|
|
}
|
|
|
|
//卡券列表
|
|
public function actionIndex()
|
|
{
|
|
if(\Yii::$app->request->isAjax){
|
|
$form = new CouponListForm();
|
|
$form->attributes = \Yii::$app->request->get();
|
|
$data = $form->search();
|
|
return $this->responseHandler($data);
|
|
}
|
|
return $this->render('index');
|
|
}
|
|
|
|
//创建卡券
|
|
public function actionEdit($id = 0)
|
|
{
|
|
$model = Coupon::findOne([
|
|
'id' => $id,
|
|
'is_delete' => 0
|
|
]);
|
|
if($model == null)
|
|
$model = new Coupon();
|
|
if(\Yii::$app->request->post()){
|
|
$form = new CouponEditForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$form->model = $model;
|
|
$data = $form->edit();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$store = Store::find()->where(['is_delete' => 0,'status' => 1])->select('id as value,name')->asArray()->all();
|
|
return $this->render('edit',[
|
|
'model' => $model,
|
|
'store' => json_encode($store),
|
|
]);
|
|
}
|
|
|
|
//删除卡券
|
|
public function actionDelete()
|
|
{
|
|
if(!\Yii::$app->request->isPost){
|
|
$data = $this->invaildRequest();
|
|
return $this->responseHandler($data);
|
|
}
|
|
$form = new CouponActionForm();
|
|
$form->attributes = \Yii::$app->request->post();
|
|
$data = $form->delete();
|
|
return $this->responseHandler($data);
|
|
}
|
|
|
|
|
|
} |