Category.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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\shop\controller\goods;
  20. use app\common\basics\ShopBase;
  21. use app\common\server\JsonServer;
  22. use think\exception\ValidateException;
  23. use think\facade\View;
  24. use app\shop\logic\goods\CategoryLogic;
  25. use app\shop\validate\goods\GoodsCategoryValidate;
  26. /**
  27. * 店铺商品分类
  28. * Class Category
  29. */
  30. class Category extends ShopBase
  31. {
  32. /**
  33. * 列表
  34. */
  35. public function lists(){
  36. if($this->request->isAjax()) {
  37. $get = $this->request->get();
  38. $get['shop_id'] = $this->shop_id;
  39. $data = CategoryLogic::lists($get);
  40. return JsonServer::success('获取列表成功', $data);
  41. }
  42. return view();
  43. }
  44. /**
  45. * 添加
  46. */
  47. public function add(){
  48. if($this->request->isAjax()) {
  49. $post = $this->request->post();
  50. $post['del'] = 0;
  51. $post['shop_id'] = $this->shop_id;
  52. try {
  53. validate(GoodsCategoryValidate::class)->scene('add')->check($post);
  54. } catch (ValidateException $e) {
  55. return JsonServer::error($e->getError());
  56. }
  57. $res = CategoryLogic::add($post);
  58. if($res) {
  59. return JsonServer::success('分类添加成功');
  60. }else{
  61. return JsonServer::error('分类添加失败');
  62. }
  63. }
  64. return view();
  65. }
  66. /**
  67. * 删除
  68. */
  69. public function del(){
  70. $post = $this->request->post();
  71. try {
  72. validate(GoodsCategoryValidate::class)->scene('del')->check($post);
  73. } catch (ValidateException $e) {
  74. return JsonServer::error($e->getError());
  75. }
  76. $res = CategoryLogic::del($post);
  77. if($res) {
  78. return JsonServer::success('删除分类成功');
  79. }else{
  80. return JsonServer::error('删除分类失败');
  81. }
  82. }
  83. /**
  84. * 编辑
  85. */
  86. public function edit(){
  87. if ($this->request->isAjax()) {
  88. $post = $this->request->post();
  89. $post['del'] = 0;
  90. $post['shop_id'] = $this->shop_id;
  91. try {
  92. validate(GoodsCategoryValidate::class)->scene('edit')->check($post);
  93. } catch (ValidateException $e) {
  94. return JsonServer::error($e->getError());
  95. }
  96. $res = CategoryLogic::edit($post);
  97. if($res) {
  98. return JsonServer::success('编辑分类成功');
  99. }else{
  100. return JsonServer::error('编辑分类失败');
  101. }
  102. }
  103. $id = $this->request->get('id');
  104. $detail = CategoryLogic::getCategory($id);
  105. return view('edit', ['detail' => $detail]);
  106. }
  107. /**
  108. * 修改显示状态
  109. */
  110. public function switchStatus(){
  111. $post = $this->request->post();
  112. $res = CategoryLogic::switchStatus($post);
  113. if($res) {
  114. return JsonServer::success('修改成功');
  115. }else{
  116. return JsonServer::error('修改失败');
  117. }
  118. }
  119. }