Material.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller\common;
  10. use app\admin\controller\Auth;
  11. use mall\response\Response;
  12. use think\facade\Request;
  13. use think\facade\View;
  14. use app\admin\service\common\Material as MaterialService;
  15. class Material extends Auth {
  16. /**
  17. * 图库中心
  18. * @return string
  19. */
  20. public function index(){
  21. return View::fetch("",[
  22. "type"=>Request::param("type","image","trim"),
  23. "callback"=>Request::param("callback","handle","trim")
  24. ]);
  25. }
  26. /**
  27. * 获取附件分类
  28. * @return \think\response\Json
  29. * @throws \think\db\exception\DataNotFoundException
  30. * @throws \think\db\exception\DbException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function get_cat(){
  34. return Response::returnArray("ok",1,MaterialService::getCategory(Request::param("type","image","trim")));
  35. }
  36. /**
  37. * 获取列表数据
  38. * @return \think\response\Json
  39. * @throws \think\db\exception\DbException
  40. */
  41. public function get_list(){
  42. return Response::returnArray("ok",1,MaterialService::getList(Request::param()));
  43. }
  44. /**
  45. * 添加分类
  46. * @return \think\response\Json
  47. */
  48. public function create_category(){
  49. try {
  50. MaterialService::createCategory(Request::param());
  51. return Response::returnArray("添加成功");
  52. }catch (\Exception $ex){
  53. return Response::returnArray($ex->getMessage(),0);
  54. }
  55. }
  56. /**
  57. * 删除分类和清空分类下的附件
  58. * @return \think\response\Json
  59. */
  60. public function delete_category(){
  61. try {
  62. MaterialService::deleteCategory(Request::param("id","0","intval"));
  63. return Response::returnArray("删除成功");
  64. }catch (\Exception $ex){
  65. return Response::returnArray($ex->getMessage(),0);
  66. }
  67. }
  68. /**
  69. * 删除附件
  70. * @return \think\response\Json
  71. */
  72. public function delete(){
  73. try{
  74. MaterialService::delete(Request::param("id","","strip_tags"));
  75. return Response::returnArray("删除成功");
  76. }catch (\Exception $ex){
  77. return Response::returnArray($ex->getMessage(),0);
  78. }
  79. }
  80. }