| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace addons\CardSecret\backend\controllers;
- use addons\CardSecret\common\listeners\OrderFinishListener;
- use addons\CardSecret\common\listeners\OrderPaidListener;
- use addons\CardSecret\common\models\Cate;
- use common\enums\StatusEnum;
- use Yii;
- use yii\db\Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\CardSecret\backend\controllers
- */
- class CateController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isGet) {
- $get = Yii::$app->request->get();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($get,[
- [['id','keyword'], 'safe'],
- [['limit'],'default','value' => '15'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $where = [];
- if(!empty($get['keyword'])) $where[] = ['like', 'name', $get['keyword']];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['>=', 'status', StatusEnum::DISABLED];
- $order = 'sort,created_at desc';
- $params = array('where' => $where, 'order'=>$order, 'limit' => $get['limit']);
- $list = Cate::listPage($params, false, true);
- $this->success('获取成功', $list);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 等级编辑
- * @Author: ltm
- * @DateTime: 2021/10/21 0021 11:29
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return mixed|string|void
- */
- public function actionEdit()
- {
- try {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- // 提交等级内容
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['name','id','status'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params = Cate::exceptNullVal($params);
- if(!empty($params['id'])) $params['updated_at'] = time();//更新
- $params['create_at'] = time();
- if(!$params['name']) unset($params['name']);
- $params['mall_id'] = $this->mall_id;
- if(isset($params['status']) && !in_array($params['status'],[StatusEnum::DISABLED,StatusEnum::ENABLED,StatusEnum::DELETE])) throw new Exception("参数错误");;
- $res = Cate::setData($params);
- if ($res === false) throw new Exception(Cate::getStaticError());
- return $this->success('操作成功');
- }
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage(), []);
- }
- return $this->render($this->action->id);
- }
- //测试使用,测试完进行删除
- public function actionTestpaid()
- {
- $add['id'] = 8130;
- $d = "发放";
- var_dump(preg_match("/^[0-9a-zA-Z]{0,50}$/",$d));die;
- $res = OrderFinishListener::async_handle($add);
- }
- }
|