BottommenuController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\BottomMenu;
  5. use app\model\BottomMenuOriginal;
  6. use app\model\BottomMenuType;
  7. use app\model\DiyPage;
  8. class BottommenuController extends Base
  9. {
  10. function index()
  11. {
  12. $weid = weid();
  13. $keyword = input('post.keyword', '', 'serach_in');
  14. $tid = input('post.tid', '', 'serach_in');
  15. $tid = str_ireplace('aaa', '', $tid);
  16. $path = input('post.path', '', 'serach_in');
  17. if ($path == '/bottommenu/index') {
  18. $mo = 'bottom';
  19. }
  20. if ($path == '/bottommenu/technical') {
  21. $mo = 'technical';
  22. }
  23. if ($path == '/bottommenu/store') {
  24. $mo = 'store';
  25. }
  26. if ($path == '/clientmenu/member') {
  27. $mo = 'member';
  28. }
  29. $query = BottomMenu::where(['weid' => $weid, 'tid' => (int) $tid, 'module' => $mo]);
  30. if (!empty($keyword)) {
  31. $query->where('title', 'like', '%' . $keyword . '%');
  32. }
  33. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  34. if (empty($datalist)) {
  35. BottomMenu::datainitial($mo, $tid);
  36. $datalist = $query->order('sort asc,id asc')->select()->toArray();
  37. }
  38. foreach ($datalist as &$vo) {
  39. $vo['hump'] = yesno($vo['hump']);
  40. $vo['is_index'] = yesno($vo['is_index']);
  41. $vo['icon'] = toimg($vo['icon']);
  42. $vo['iconactive'] = toimg($vo['iconactive']);
  43. }
  44. $data['MenuType'] = BottomMenuType::getpagearray();
  45. $data['data'] = $datalist;
  46. return $this->json($data);
  47. }
  48. function listUpdate()
  49. {
  50. $data = only('id,is_submitaudit,is_index,hump,status,sort');
  51. if (!$data['id']) throw new ValidateException('参数错误');
  52. BottomMenu::update($data);
  53. return $this->json(['msg' => '操作成功']);
  54. }
  55. public function update()
  56. {
  57. $id = $this->request->post('id');
  58. $data = input('post.');
  59. $data['tid'] = (int) str_ireplace('aaa', '', $data['tid']);
  60. if (empty($id)) {
  61. $data['weid'] = weid();
  62. $data['module'] = 'bottom';
  63. if ($data['path'] == '/clientmenu/member') {
  64. $data['module'] = 'member';
  65. }
  66. if ($data['path'] == '/bottommenu/technical') {
  67. $data['module'] = 'technical';
  68. }
  69. if ($data['path'] == '/bottommenu/store') {
  70. $data['module'] = 'store';
  71. }
  72. if (empty($data['icon'])) {
  73. $Original = BottomMenuOriginal::where('url', $data['url'])->find();
  74. if ($Original) {
  75. $data['icon'] = $Original->icon;
  76. }
  77. }
  78. if (empty($data['iconactive'])) {
  79. $Original = BottomMenuOriginal::where('url', $data['url'])->find();
  80. if ($Original) {
  81. $data['iconactive'] = $Original->iconactive;
  82. }
  83. }
  84. try {
  85. $res = BottomMenu::create($data);
  86. if ($res->id && empty($data['sort'])) {
  87. BottomMenu::update(['sort' => $res->id, 'id' => $res->id]);
  88. }
  89. } catch (\Exception $e) {
  90. throw new ValidateException($e->getMessage());
  91. }
  92. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  93. } else {
  94. try {
  95. BottomMenu::update($data);
  96. } catch (\Exception $e) {
  97. throw new ValidateException($e->getMessage());
  98. }
  99. return $this->json(['msg' => '修改成功']);
  100. }
  101. }
  102. function getInfo()
  103. {
  104. $id = $this->request->post('id', '', 'serach_in');
  105. if (!$id) throw new ValidateException('参数错误');
  106. $data = BottomMenu::field('*')->find($id)->toArray();
  107. return $this->json(['data' => $data]);
  108. }
  109. function delete()
  110. {
  111. return $this->del(new BottomMenu());
  112. }
  113. function getField()
  114. {
  115. $data['urlarray'] = BottomMenuOriginal::getpagearray();
  116. $diypagearray = DiyPage::getpagearray();
  117. if (!empty($diypagearray)) {
  118. $data['urlarray'] = array_merge($data['urlarray'], $diypagearray);
  119. }
  120. return $this->json(['data' => $data]);
  121. }
  122. }