OptimizeController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace backend\modules\mall\controllers;
  3. use backend\controllers\MallController;
  4. use common\enums\StatusEnum;
  5. use common\models\backend\Menu;
  6. use common\models\mall\Optimize;
  7. use common\models\mall\OptimizeDetail;
  8. use Yii;
  9. class OptimizeController extends MallController
  10. {
  11. /**
  12. * 获取优化列表
  13. * @return mixed|string|null
  14. */
  15. public function actionList()
  16. {
  17. if (Yii::$app->request->isAjax && Yii::$app->request->isGet) {
  18. // 检查提交的参数
  19. $get = Yii::$app->request->get();
  20. $res = Yii::$app->services->validate->validate($get, [
  21. [['page', 'limit', 'examine_status'], 'integer'],
  22. [['member_name'], 'string'],
  23. ]);
  24. if ($res === false) {
  25. return $this->error(Yii::$app->services->validate->getErrorMessage());
  26. }
  27. $where = [];
  28. $where[] = ['=', 'mall_id', $this->mall_id];
  29. if (!empty($get['member_name'])) {
  30. $where[] = ['=', 'member_name', $get['member_name']];
  31. }
  32. if (isset($get['examine_status'])) {
  33. $where[] = ['=', 'examine_status', $get['examine_status']];
  34. }
  35. $where[] = ['=', 'status', StatusEnum::ENABLED];
  36. $order = 'created_at desc';
  37. $with = ['detail'];
  38. $params = array('where' => $where, 'with' => $with, 'order' => $order, 'limit' => $get['limit']);
  39. $list = Optimize::listPage($params, false, true);
  40. if (empty($list)) {
  41. return $this->error(Optimize::getStaticError());
  42. }
  43. return $this->success('获取成功', $list);
  44. }
  45. return $this->render($this->action->id);
  46. }
  47. /**
  48. * 提交优化建议
  49. * @return mixed|void|null
  50. */
  51. public function actionEdit()
  52. {
  53. $request = Yii::$app->request;
  54. if ($request->isAjax && $request->isPost) {
  55. // 检查提交的参数
  56. $post = $request->post('form');
  57. $res = Yii::$app->services->validate->validate($post, [
  58. [['mobile'], 'integer'],
  59. [['category','backend_path','optimize','title'], 'string'],
  60. ]);
  61. if ($res === false) {
  62. return $this->error(Yii::$app->services->validate->getErrorMessage());
  63. }
  64. $post['mall_id'] = $this->mall_id;
  65. $post['member_id'] = $this->admin->id;
  66. $post['member_name'] = $this->admin->account;
  67. $post['ip'] = $request->userIP;
  68. $post['optimize'] = htmlspecialchars($post['optimize']);
  69. $res = Optimize::setData($post, $this->mall);
  70. if ($res == false) {
  71. return $this->error(Optimize::getStaticError());
  72. }
  73. return $this->success('提交成功');
  74. } else {
  75. return $this->render($this->action->id);
  76. }
  77. }
  78. /**
  79. * 工单回复
  80. * @return mixed|string|null
  81. */
  82. public function actionReply()
  83. {
  84. $request = Yii::$app->request;
  85. if ($request->isAjax && $request->isGet) {
  86. // 检查提交的参数
  87. $get = $request->get();
  88. $res = Yii::$app->services->validate->validate($get, [[['id'], 'required'], [['id'], 'integer'],]);
  89. if ($res === false) {
  90. return $this->error(Yii::$app->services->validate->getErrorMessage());
  91. }
  92. $config = Yii::$app->services->setting->mall->get($this->mall_id, 'basic');
  93. empty($config['logo']) && $config['logo'] = Yii::$app->request->hostInfo.'/resources/img/admin/mall-logo.png';
  94. $data['config'] = $config;
  95. // 获取工单信息
  96. $select = "id,title,mobile,category,backend_path_str,examine_status";
  97. $optimize = Optimize::find()->select($select)->where(['id' => $get['id'], 'mall_id' => $this->mall_id, 'status' => StatusEnum::ENABLED])->asArray()->one();
  98. if (empty($optimize)) return $this->error('查无此建议');
  99. $data['optimize'] = $optimize;
  100. $where = [];
  101. $where[] = ['=', 'mall_id', $this->mall_id];
  102. $where[] = ['=', 'optimize_id', $get['id']];
  103. $where[] = ['=', 'status', StatusEnum::ENABLED];
  104. $order = 'created_at asc';
  105. $select = "id,optimize_id,member_id,member_name,optimize,created_at";
  106. $params = array('where' => $where, 'select' => $select, 'order' => $order, 'limit' => 50);
  107. $list = OptimizeDetail::lists($params, true);
  108. // 正则获取所有图片并且排序
  109. $preview_imgs = [];
  110. $pattern = "/[img|IMG].*?src=['|\"](.*?(?:[.gif|.jpg]))['|\"].*?[\/]?>/";// 表达式
  111. foreach ($list as &$item) {
  112. $item['optimize'] = htmlspecialchars_decode($item['optimize']);
  113. preg_match_all($pattern, $item['optimize'],$match);
  114. if(!empty($match[1])) $preview_imgs = array_merge($preview_imgs, $match[1]);
  115. }
  116. $data['preview_imgs'] = $preview_imgs;
  117. $data['list'] = $list;
  118. return $this->success('获取成功', $data);
  119. } else {
  120. return $this->render($this->action->id);
  121. }
  122. }
  123. /**
  124. * 获取所有的菜单
  125. * @return mixed|void|null
  126. */
  127. public function actionGetBackendMenu()
  128. {
  129. $request = Yii::$app->request;
  130. if ($request->isAjax && $request->isGet) {
  131. $select = 'id,pid,title,url,is_addon';
  132. $cond = [['>=', 'cate_id', 2], ['=', 'status', StatusEnum::ENABLED]];
  133. $list = Menu::getMenus($cond, [], true, $select);
  134. if ($list) {
  135. foreach ($list as &$item) {
  136. if ($item['is_addon'] == 1 && $item['pid'] == 0) {
  137. $item['pid'] = 927;
  138. }
  139. }
  140. $data = Menu::getTreeMenu($list);
  141. }
  142. return $this->success('获取成功', $data);
  143. }
  144. }
  145. /**
  146. * 回复
  147. * @return mixed|string|null
  148. */
  149. public function actionResubmit()
  150. {
  151. $request = Yii::$app->request;
  152. if ($request->isAjax && $request->isPost) {
  153. // 检查提交的参数
  154. $post = $request->post('form');
  155. $res = Yii::$app->services->validate->validate($post, [
  156. [['optimize_id','optimize'], 'required'],
  157. [['optimize_id'], 'integer'],
  158. [['optimize'], 'string'],
  159. ]);
  160. if ($res === false) {
  161. return $this->error(Yii::$app->services->validate->getErrorMessage());
  162. }
  163. $post['mall_id'] = $this->mall_id;
  164. $post['member_id'] = $this->admin->id;
  165. $post['member_name'] = $this->admin->account;
  166. $post['ip'] = $request->userIP;
  167. $post['optimize'] = htmlspecialchars($post['optimize']);
  168. $res = OptimizeDetail::resubmit($post);
  169. if ($res == false) {
  170. return $this->error(OptimizeDetail::getStaticError());
  171. }
  172. return $this->success('提交成功');
  173. } else {
  174. return $this->render($this->action->id);
  175. }
  176. }
  177. /**
  178. * 重新发送
  179. *
  180. * @return mixed
  181. */
  182. public function actionSend(int $id)
  183. {
  184. return Optimize::reSend($id, $this->mall)
  185. ? $this->success('发送成功')
  186. : $this->error(Optimize::getStaticError());
  187. }
  188. }