MenuController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/5
  6. * Time: 下午5:19
  7. */
  8. namespace backend\controllers;
  9. use backend\base\CommonController;
  10. use backend\server\Menus;
  11. use backend\base\Help;
  12. use yii\helpers\ArrayHelper;
  13. use common\models\SysmenuQ;
  14. use Yii;
  15. class MenuController extends CommonController
  16. {
  17. public $enableCsrfValidation = false;
  18. /*
  19. * 菜单数据显示
  20. * */
  21. public function actionIndex()
  22. {
  23. return $this->render('index');
  24. }
  25. /*
  26. * 获取菜单数据
  27. * */
  28. public function actionIndexfrom()
  29. {
  30. $model = new Menus();
  31. $rows = $model->MenuListSorting();
  32. return Help::JsonData(0, '成功', $rows['count'], $rows['data']);
  33. }
  34. /*
  35. * 获取2级和3级菜单数据
  36. * */
  37. public function actionNavlist()
  38. {
  39. $model = new Menus();
  40. $result = $model->getchildren();
  41. if ($result != false) {
  42. return Help::JsonCode(Help::SUCCESS, '查询成功', $result);
  43. }
  44. return Help::JsonCode(Help::ERROR, '查询失败');
  45. }
  46. /*
  47. * 菜单页面
  48. * */
  49. public function actionCreate()
  50. {
  51. $model = new \backend\server\Menus();
  52. $rows = $model->MenuListSorting();
  53. $arr = [];
  54. //清楚3级目录,
  55. foreach ($rows['data'] as $key => $val) {
  56. if ($val['level'] != 3 && !empty($val['level'])) {
  57. $arr[$key]['name'] = $val['name'];
  58. $arr[$key]['id'] = $val['id'];
  59. }
  60. }
  61. return $this->render('create', ['model' => $arr]);
  62. }
  63. /*
  64. *添加菜单
  65. * */
  66. public function actionCreatefrom()
  67. {
  68. // p(Yii::$app->request->post());
  69. $model = new Menus();
  70. $result = $model->Create();
  71. if ($result === true) {
  72. return Help::JsonCode(Help::SUCCESS, '菜单添加成功');
  73. }
  74. return Help::JsonCode(Help::ERROR, '菜单添加失败', $result);
  75. }
  76. /*
  77. * 删除菜单
  78. * */
  79. public function actionDelmenu()
  80. {
  81. $model = new Menus();
  82. $result = $model->Del();
  83. if ($result === true) {
  84. return Help::JsonCode(Help::SUCCESS, '删除成功');
  85. }
  86. return Help::JsonCode(Help::ERROR, $result);
  87. }
  88. /*
  89. * 修改菜单
  90. * */
  91. public function actionEditfrom()
  92. {
  93. $model = new Menus();
  94. $result = $model->Edit();
  95. if ($result === true) {
  96. return Help::JsonCode(Help::SUCCESS, '菜单添加成功');
  97. }
  98. return Help::JsonCode(Help::ERROR, '菜单添加失败', $result);
  99. }
  100. /*
  101. * 修改菜单页面
  102. * */
  103. public function actionEdit()
  104. {
  105. $model = new \common\models\Sysmenu();
  106. $model->id = Yii::$app->request->get('id');
  107. $result = $model->FindById();
  108. return $this->render('edit', ['model' => $result]);
  109. }
  110. //====================前台菜单======================
  111. /*
  112. * 前端菜单显示页面
  113. * */
  114. public function actionFronthome()
  115. {
  116. return $this->render('fronthome');
  117. }
  118. /*
  119. * 前端菜单-数据
  120. * */
  121. public function actionFronthomeform()
  122. {
  123. $model = new SysmenuQ();
  124. $rows = $model->getList(Yii::$app->request->post());
  125. if ($rows != null) {
  126. return Help::JsonData(0, '成功', $model->Total(), $rows);
  127. }
  128. return Help::JsonCode(Help::ERROR, '暂无数据');
  129. }
  130. /*
  131. * 前端菜单-添加页面
  132. * */
  133. public function actionFrontadd()
  134. {
  135. return $this->render('frontadd');
  136. }
  137. /*
  138. * 前端菜单-添加数据
  139. * */
  140. public function actionFrontaddform()
  141. {
  142. $input = Yii::$app->request->post('data');
  143. $model = new SysmenuQ();
  144. $model->scenario = 'add';
  145. $Auth = $model->Authenticator($input);
  146. if (is_object($Auth)) {
  147. if ($Auth->save() == true) return Help::JsonCode(Help::SUCCESS, '添加成功');
  148. }
  149. return Help::JsonCode(Help::ERROR, '添加失败', $Auth);
  150. }
  151. /*
  152. * 前端菜单-修改页面
  153. * */
  154. public function actionFrontedit()
  155. {
  156. $model = new SysmenuQ();
  157. $row = $model->FindById(Yii::$app->request->get('id'));
  158. if ($row != null) {
  159. return $this->render('frontedit', ['model' => $row]);
  160. }
  161. }
  162. /*
  163. * 前端菜单-修改数据
  164. * */
  165. public function actionFronteditform()
  166. {
  167. $model = new SysmenuQ();
  168. $input = Yii::$app->request->post('data');
  169. $model->Authenticator($input);
  170. $row = $model->FindById($input['id']);
  171. if ($row != null) {
  172. $setAttr = Help::SetAttr($input, $model, $row);
  173. if ($setAttr->update() == true) return Help::JsonCode(Help::SUCCESS, '修改成功');
  174. }
  175. return Help::JsonCode(Help::ERROR, '修改失败');
  176. }
  177. /*
  178. * 前端菜单-删除and禁用数据
  179. * */
  180. public function actionFrontstateform()
  181. {
  182. $model = new SysmenuQ();
  183. $input = Yii::$app->request->post();
  184. $row = $model->FindById($input['id']);
  185. if ($row != null) {
  186. switch ($input['type']) {
  187. case '1':
  188. $row->del = 2;
  189. break;
  190. case '2':
  191. if ($row->status == 2) {
  192. $row->status = 1;
  193. } else if ($row->status == 1) {
  194. $row->status = 2;
  195. }
  196. break;
  197. }
  198. if ($row->update() == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  199. }
  200. return Help::JsonCode(Help::ERROR, '操作失败');
  201. }
  202. /**
  203. * 修改菜单状态
  204. * @author lyy
  205. **/
  206. public function actionMenustatus()
  207. {
  208. $model = new Menus();
  209. $result = $model->EditMenuStatus();
  210. return Help::JsonCode(Help::SUCCESS, '操作成功', $result);
  211. }
  212. /*
  213. * 修改排序
  214. * */
  215. public function actionMenusortedit()
  216. {
  217. $model = new Menus();
  218. $state = $model->SetSortH();
  219. if($state) return Help::JsonCode(Help::SUCCESS, '操作成功');
  220. return Help::JsonCode(Help::ERROR, '操作失败');
  221. // $input = Yii::$app->request->post();
  222. // $find = $model->GetFindById($input['id']);
  223. // if ($find != null) {
  224. // if (!empty($input['sort'])) {
  225. // $find->sort = Yii::$app->request->post('sort');
  226. // }
  227. //
  228. // if (!empty($input['examineid'])) {
  229. // switch ($find->status) {
  230. // case 1:
  231. // $find->status = 2;
  232. // break;
  233. // case 2:
  234. // $find->status = 1;
  235. // break;
  236. // }
  237. // }
  238. //
  239. // if ($find->update(false) == true) return Help::JsonCode(Help::SUCCESS, '操作成功');
  240. // }
  241. // return Help::JsonCode(Help::ERROR, '操作失败');
  242. }
  243. }