SaleCategory.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 商品分类管理
  7. */
  8. namespace app\popupshop\controller;
  9. use app\common\controller\Manage;
  10. use app\popupshop\model\Sale;
  11. use app\popupshop\model\SaleCategory as Category;
  12. use think\facade\Request;
  13. use app\popupshop\model\Item;
  14. class SaleCategory extends Manage{
  15. public function initialize()
  16. {
  17. parent::initialize();
  18. $this->assign('pathMaps', [['name'=>'库存分类','url'=>'javascript:;']]);
  19. }
  20. /**
  21. * 列表
  22. */
  23. public function index(){
  24. $view['lists'] = Category::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
  25. return view('index',$view);
  26. }
  27. /**
  28. * 添加
  29. */
  30. public function add(){
  31. if(request()->isAjax()){
  32. $data = [
  33. 'member_miniapp_id' => $this->member_miniapp_id,
  34. 'title' => input('post.title/s'),
  35. 'name' => input('post.name/s'),
  36. 'picture' => input('post.picture/s'),
  37. ];
  38. $validate = $this->validate($data,'Category.cate');
  39. if(true !== $validate){
  40. return enjson(0,$validate);
  41. }
  42. $result = Category::edit($data);
  43. if($result){
  44. return enjson(200,'操作成功',['url'=>url('popupshop/saleCategory/index')]);
  45. }else{
  46. return enjson(0);
  47. }
  48. }else{
  49. return view();
  50. }
  51. }
  52. //编辑
  53. public function edit(){
  54. if(request()->isAjax()){
  55. $data = [
  56. 'id' => input('post.id/d'),
  57. 'title' => input('post.title/s'),
  58. 'name' => input('post.name/s'),
  59. 'picture' => input('post.picture/s'),
  60. ];
  61. $validate = $this->validate($data,'Category.cate');
  62. if(true !== $validate){
  63. return enjson(0,$validate);
  64. }
  65. $result = Category::edit($data);
  66. if($result){
  67. return enjson(200,'操作成功',['url'=>url('popupshop/saleCategory/index')]);
  68. }else{
  69. return enjson(0);
  70. }
  71. }else{
  72. $id = Request::param('id/d');
  73. $view['info'] = Category::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->find();
  74. return view('edit',$view);
  75. }
  76. }
  77. /**
  78. * 排序
  79. */
  80. public function sort(){
  81. if(request()->isAjax()){
  82. $data = [
  83. 'sort' => input('post.sort/d'),
  84. 'id' => input('post.id/d'),
  85. ];
  86. $validate = $this->validate($data,'Category.sort');
  87. if(true !== $validate){
  88. return enjson(0,$validate);
  89. }
  90. $result = Category::where(['id' => $data['id']])->update(['sort'=>$data['sort']]);
  91. if($result){
  92. return enjson(200);
  93. }else{
  94. return enjson(0);
  95. }
  96. }
  97. }
  98. //删除
  99. public function delete(){
  100. $id = Request::param('id/d');
  101. $goods = Item::where(['category_id' => $id])->find();
  102. if($goods){
  103. return enjson(403,'删除失败,栏目中还包含商品');
  104. }
  105. $result = Category::destroy(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id]);
  106. if($result){
  107. return enjson(200);
  108. }else{
  109. return enjson(403);
  110. }
  111. }
  112. }