| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace backend\modules\mall\controllers;
- use backend\controllers\MallController;
- use common\enums\StatusEnum;
- use common\models\backend\Menu;
- use common\models\mall\Optimize;
- use common\models\mall\OptimizeDetail;
- use Yii;
- class OptimizeController extends MallController
- {
- /**
- * 获取优化列表
- * @return mixed|string|null
- */
- public function actionList()
- {
- if (Yii::$app->request->isAjax && Yii::$app->request->isGet) {
- // 检查提交的参数
- $get = Yii::$app->request->get();
- $res = Yii::$app->services->validate->validate($get, [
- [['page', 'limit', 'examine_status'], 'integer'],
- [['member_name'], 'string'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- if (!empty($get['member_name'])) {
- $where[] = ['=', 'member_name', $get['member_name']];
- }
- if (isset($get['examine_status'])) {
- $where[] = ['=', 'examine_status', $get['examine_status']];
- }
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'created_at desc';
- $with = ['detail'];
- $params = array('where' => $where, 'with' => $with, 'order' => $order, 'limit' => $get['limit']);
- $list = Optimize::listPage($params, false, true);
- if (empty($list)) {
- return $this->error(Optimize::getStaticError());
- }
- return $this->success('获取成功', $list);
- }
- return $this->render($this->action->id);
- }
- /**
- * 提交优化建议
- * @return mixed|void|null
- */
- public function actionEdit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- // 检查提交的参数
- $post = $request->post('form');
- $res = Yii::$app->services->validate->validate($post, [
- [['mobile'], 'integer'],
- [['category','backend_path','optimize','title'], 'string'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $post['mall_id'] = $this->mall_id;
- $post['member_id'] = $this->admin->id;
- $post['member_name'] = $this->admin->account;
- $post['ip'] = $request->userIP;
- $post['optimize'] = htmlspecialchars($post['optimize']);
- $res = Optimize::setData($post, $this->mall);
- if ($res == false) {
- return $this->error(Optimize::getStaticError());
- }
- return $this->success('提交成功');
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 工单回复
- * @return mixed|string|null
- */
- public function actionReply()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isGet) {
- // 检查提交的参数
- $get = $request->get();
- $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer'],]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $config = Yii::$app->services->setting->mall->get($this->mall_id, 'basic');
- empty($config['logo']) && $config['logo'] = Yii::$app->request->hostInfo.'/resources/img/admin/mall-logo.png';
- $data['config'] = $config;
- // 获取工单信息
- $select = "id,title,mobile,category,backend_path_str,examine_status";
- $optimize = Optimize::find()->select($select)->where(['id' => $get['id'], 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if (empty($optimize)) return $this->error('查无此建议');
- $data['optimize'] = $optimize;
- $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- $where[] = ['=', 'optimize_id', $get['id']];
- $where[] = ['=', 'status', StatusEnum::ENABLED];
- $order = 'created_at asc';
- $select = "id,optimize_id,member_id,member_name,optimize,created_at";
- $params = array('where' => $where, 'select' => $select, 'order' => $order, 'limit' => 50);
- $list = OptimizeDetail::lists($params, true);
- // 正则获取所有图片并且排序
- $preview_imgs = [];
- $pattern = "/[img|IMG].*?src=['|\"](.*?(?:[.gif|.jpg]))['|\"].*?[\/]?>/";// 表达式
- foreach ($list as &$item) {
- $item['optimize'] = htmlspecialchars_decode($item['optimize']);
- preg_match_all($pattern, $item['optimize'],$match);
- if(!empty($match[1])) $preview_imgs = array_merge($preview_imgs, $match[1]);
- }
- $data['preview_imgs'] = $preview_imgs;
- $data['list'] = $list;
- return $this->success('获取成功', $data);
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 获取所有的菜单
- * @return mixed|void|null
- */
- public function actionGetBackendMenu()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isGet) {
- $select = 'id,pid,title,url,is_addon';
- $cond = [['>=', 'cate_id', 2], ['=', 'status', StatusEnum::ENABLED]];
- $list = Menu::getMenus($cond, [], true, $select);
- if ($list) {
- foreach ($list as &$item) {
- if ($item['is_addon'] == 1 && $item['pid'] == 0) {
- $item['pid'] = 927;
- }
- }
- $data = Menu::getTreeMenu($list);
- }
- return $this->success('获取成功', $data);
- }
- }
- /**
- * 回复
- * @return mixed|string|null
- */
- public function actionResubmit()
- {
- $request = Yii::$app->request;
- if ($request->isAjax && $request->isPost) {
- // 检查提交的参数
- $post = $request->post('form');
- $res = Yii::$app->services->validate->validate($post, [
- [['optimize_id','optimize'], 'required'],
- [['optimize_id'], 'integer'],
- [['optimize'], 'string'],
- ]);
- if ($res === false) {
- return $this->error(Yii::$app->services->validate->getErrorMessage());
- }
- $post['mall_id'] = $this->mall_id;
- $post['member_id'] = $this->admin->id;
- $post['member_name'] = $this->admin->account;
- $post['ip'] = $request->userIP;
- $post['optimize'] = htmlspecialchars($post['optimize']);
- $res = OptimizeDetail::resubmit($post);
- if ($res == false) {
- return $this->error(OptimizeDetail::getStaticError());
- }
- return $this->success('提交成功');
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 重新发送
- *
- * @return mixed
- */
- public function actionSend(int $id)
- {
- return Optimize::reSend($id, $this->mall)
- ? $this->success('发送成功')
- : $this->error(Optimize::getStaticError());
- }
- }
|