BottommenutypeController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\BottomMenuType;
  5. class BottommenutypeController extends Base
  6. {
  7. public function update()
  8. {
  9. $id = $this->request->post('id');
  10. $data = input('post.');
  11. if (empty($id)) {
  12. $data['weid'] = weid();
  13. try {
  14. $res = BottomMenuType::create($data);
  15. if ($res->id && empty($data['sort'])) {
  16. BottomMenuType::update(['sort' => $res->id, 'id' => $res->id]);
  17. }
  18. } catch (\Exception $e) {
  19. throw new ValidateException($e->getMessage());
  20. }
  21. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  22. } else {
  23. try {
  24. BottomMenuType::update($data);
  25. } catch (\Exception $e) {
  26. throw new ValidateException($e->getMessage());
  27. }
  28. return $this->json(['msg' => '修改成功']);
  29. }
  30. }
  31. function getpclist()
  32. {
  33. $BottomMenu = BottomMenuType::getpagearray();
  34. $alldata[0]['val'] = '0';
  35. $alldata[0]['key'] = '默认';
  36. if (!empty($BottomMenu)) {
  37. $data = array_merge($alldata, $BottomMenu);
  38. } else {
  39. $data = $alldata;
  40. }
  41. return $this->json(['data' => $data]);
  42. }
  43. function delete()
  44. {
  45. $idx = $this->request->post('id', '', 'serach_in');
  46. $idx = str_ireplace('aaa', '', $idx);
  47. if (!$idx) throw new ValidateException('参数错误');
  48. if (!is_array($idx)) {
  49. $idx = explode(',', $idx);
  50. }
  51. BottomMenuType::destroy(['id' => $idx], true);
  52. return $this->json(['msg' => '操作成功']);
  53. }
  54. }