| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace addons\Mch\client\controllers;
- use addons\Store\common\models\StoreNotice;
- use common\enums\StatusEnum;
- use Yii;
- /**
- *
- * @Author bing
- * @DateTime 2021-08-16 13:12:44
- * @copyright: Copyright (c) 2020 广东七件事集团
- */
- class NoticeController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * @Author bing
- * @DateTime 2021-08-20 14:49:55
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @return void
- */
- public function actionIndex(){
- if (Yii::$app->request->isAjax) {
- $params = [
- 'where'=>[
- ['mall_id'=>$this->mall_id],
- ['store_id'=>$this->store_id],
- ['status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]],
- ],
- 'order'=>'id desc'
- ];
- $list = StoreNotice::listPage($params);
- if($list === false) return $this->error(StoreNotice::getStaticError());
- return $this->success('ok',$list);
- }
- return $this->render($this->action->id);
- }
- public function actionEdit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $id = Yii::$app->request->get('id', '');
- $data = StoreNotice::getOne([['id'=>$id],['mall_id'=>$this->mall_id],['store_id'=>$this->store_id]],true);
- return $this->success('操作成功', ['data'=>$data]);
- }
- try {
- if ($request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['title', 'content'], 'required'],
- [['id'], 'safe'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['store_id'] = $this->store_id;
- $res = StoreNotice::setData($params);
- if ($res === false) return $this->error(StoreNotice::getStaticError());
- return $this->success('操作成功');
- }
- } catch (\Exception $e) {
- return $this->error($e->getMessage(), []);
- }
- }
- }
- /**
- * 删除
- * @param null $keyword
- * @param int $is_recycle
- * @return mixed|void
- */
- public function actionDel()
- {
- $request = Yii::$app->request;
- if ($request->isAjax) {
- if ($request->isGet) {
- $params = Yii::$app->request->get();
- $params['status'] = StatusEnum::DELETE;
- $params['mall_id'] = $this->mall_id;
- $params['store_id'] = $this->store_id;
- $res = StoreNotice::setData($params);
- if ($res === false) return $this->error(StoreNotice::getStaticError());
- return $this->success('操作成功');
- }
- }
- }
- public function actionSwitchStatus()
- {
- if (\Yii::$app->request->isAjax) {
- if (\Yii::$app->request->isPost) {
- $params = \Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['id'], 'required'],
- [['status'], 'integer']
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $params['mall_id'] = $this->mall_id;
- $params['store_id'] = $this->store_id;
- $res = StoreNotice::setData($params);
- if ($res === false) return $this->error(StoreNotice::getStaticError());
- return $this->success('操作成功');
- }
- }
- return $this->error();
- }
- }
|