Category.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop开源商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | gitee下载:https://gitee.com/likeshop_gitee
  7. // | github下载:https://github.com/likeshop-github
  8. // | 访问官网:https://www.likeshop.cn
  9. // | 访问社区:https://home.likeshop.cn
  10. // | 访问手册:http://doc.likeshop.cn
  11. // | 微信公众号:likeshop技术社区
  12. // | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用,未经许可不能去除前后端官方版权标识
  13. // | likeshop系列产品收费版本务必购买商业授权,购买去版权授权后,方可去除前后端官方版权标识
  14. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  15. // | likeshop团队版权所有并拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshop.cn.team
  18. // +----------------------------------------------------------------------
  19. namespace app\admin\controller\shop;
  20. use app\admin\logic\shop\CategoryLogic;
  21. use app\common\basics\AdminBase;
  22. use app\common\server\JsonServer;
  23. /**
  24. * 主营类目
  25. * Class Category
  26. * @package app\admin\controller\shop
  27. */
  28. class Category extends AdminBase
  29. {
  30. /**
  31. * NOTE: 主营类目列表
  32. * @author: 张无忌
  33. */
  34. public function lists()
  35. {
  36. if ($this->request->isAjax()) {
  37. $get = $this->request->get();
  38. $lists = CategoryLogic::lists($get);
  39. return JsonServer::success('获取成功', $lists);
  40. }
  41. return view();
  42. }
  43. /**
  44. * NOTE: 新增主营类目
  45. * @author: 张无忌
  46. */
  47. public function add()
  48. {
  49. if ($this->request->isAjax()) {
  50. $post = $this->request->post();
  51. if(!isset($post['image']) || empty($post['image'])) {
  52. return JsonServer::error('类目图标不能为空');
  53. }
  54. $res = CategoryLogic::add($post);
  55. if ($res === false) {
  56. $error = CategoryLogic::getError() ?: '新增失败';
  57. return JsonServer::error($error);
  58. }
  59. return JsonServer::success('新增成功');
  60. }
  61. return view();
  62. }
  63. /**
  64. * NOTE: 编辑主营类目
  65. * @author: 张无忌
  66. */
  67. public function edit()
  68. {
  69. if ($this->request->isAjax()) {
  70. $post = $this->request->post();
  71. if(!isset($post['image']) || empty($post['image'])) {
  72. return JsonServer::error('类目图标不能为空');
  73. }
  74. $res = CategoryLogic::edit($post);
  75. if ($res === false) {
  76. $error = CategoryLogic::getError() ?: '编辑失败';
  77. return JsonServer::error($error);
  78. }
  79. return JsonServer::success('编辑成功');
  80. }
  81. $id = $this->request->get('id');
  82. return view('', [
  83. 'detail' => CategoryLogic::detail($id)
  84. ]);
  85. }
  86. /**
  87. * NOTE: 删除主营类目
  88. * @author: 张无忌
  89. */
  90. public function del()
  91. {
  92. if ($this->request->isAjax()) {
  93. $id = $this->request->post('id');
  94. $res = CategoryLogic::del($id);
  95. if ($res === false) {
  96. $error = CategoryLogic::getError() ?: '删除失败';
  97. return JsonServer::error($error);
  98. }
  99. return JsonServer::success('删除成功');
  100. }
  101. return JsonServer::error('请求异常');
  102. }
  103. }