FilescateController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace app\admin\controller;
  3. use think\exception\ValidateException;
  4. use app\model\FilesCate;
  5. class FilescateController extends Base
  6. {
  7. function index()
  8. {
  9. $weid = weid();
  10. $query = FilesCate::where(['weid' => $weid]);
  11. $list = $query->order('sort asc')->select()->toArray();
  12. $data['data'] = _generateListTree($list, 0, ['id', 'pid']);
  13. return $this->json($data);
  14. }
  15. function listUpdate()
  16. {
  17. $data = only('id,status,sort');
  18. if (!$data['id']) throw new ValidateException('参数错误');
  19. FilesCate::update($data);
  20. return $this->json(['msg' => '操作成功']);
  21. }
  22. public function update()
  23. {
  24. $id = $this->request->post('id');
  25. $data = input('post.');
  26. if (empty($id)) {
  27. $data['weid'] = weid();
  28. try {
  29. $res = FilesCate::create($data);
  30. if ($res->id && empty($data['sort'])) {
  31. FilesCate::update(['sort' => $res->id, 'id' => $res->id]);
  32. }
  33. } catch (\Exception $e) {
  34. throw new ValidateException($e->getMessage());
  35. }
  36. return $this->json(['msg' => '添加成功', 'data' => $res->id]);
  37. } else {
  38. try {
  39. FilesCate::update($data);
  40. } catch (\Exception $e) {
  41. throw new ValidateException($e->getMessage());
  42. }
  43. return $this->json(['msg' => '修改成功']);
  44. }
  45. }
  46. function getInfo()
  47. {
  48. $id = $this->request->post('id', '', 'serach_in');
  49. if (!$id) throw new ValidateException('参数错误');
  50. $data = FilesCate::find($id);
  51. if ($data) {
  52. $data = $data->toArray();
  53. $data['pic'] = toimg($data['pic']);
  54. }
  55. return $this->json(['data' => $data]);
  56. }
  57. function delete()
  58. {
  59. return $this->del(new FilesCate());
  60. }
  61. }