ShopCate.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\allwin\controller;
  9. use app\allwin\model\AllwinShopCate;
  10. use app\allwin\model\AllwinShop;
  11. use app\allwin\model\AllwinStore;
  12. class ShopCate extends Common{
  13. public function initialize() {
  14. parent::initialize();
  15. $this->assign('pathMaps',[['name'=>'宝贝专题','url'=>url("allwin/shopCate/index")]]);
  16. }
  17. /**
  18. * 列表
  19. */
  20. public function index(){
  21. $condition = [];
  22. $condition[] = ['member_miniapp_id','=',$this->member_miniapp_id];
  23. $view['lists'] = AllwinShopCate::where($condition)->order('sort desc,id desc')->paginate(20);
  24. return view()->assign($view);
  25. }
  26. /**
  27. * 添加
  28. */
  29. public function add(){
  30. if(request()->isAjax()){
  31. $data = [
  32. 'title' => $this->request->param('title/s'),
  33. 'content' => $this->request->param('content/s'),
  34. 'picture' => $this->request->param('picture/s'),
  35. 'types' => $this->request->param('types/d'),
  36. 'member_miniapp_id' => $this->member_miniapp_id,
  37. ];
  38. $validate = $this->validate($data,'Category.save');
  39. if(true !== $validate){
  40. return enjson(0,$validate);
  41. }
  42. $result = AllwinShopCate::edit($data);
  43. if($result){
  44. return enjson(200,'操作成功',['url' => url('allwin/shopcate/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' => $this->request->param('id/s'),
  57. 'title' => $this->request->param('title/s'),
  58. 'content' => $this->request->param('content/s'),
  59. 'types' => $this->request->param('types/d'),
  60. 'picture' => $this->request->param('picture/s'),
  61. ];
  62. $validate = $this->validate($data,'Category.edit');
  63. if(true !== $validate){
  64. return enjson(0,$validate);
  65. }
  66. $result = AllwinShopCate::edit($data);
  67. if($result){
  68. return enjson(200,'操作成功');
  69. }else{
  70. return enjson(0,'操作失败');
  71. }
  72. }else{
  73. $view['info'] = AllwinShopCate::where(['id' => $this->request->param('id/d'),'member_miniapp_id' => $this->member_miniapp_id])->find();
  74. if(empty($view['info'])){
  75. $this->error("404 NOT FOUND");
  76. }
  77. return view('edit',$view);
  78. }
  79. }
  80. /**
  81. * 排序
  82. */
  83. public function sort(){
  84. if(request()->isAjax()){
  85. $data = [
  86. 'sort' => $this->request->param('sort/d'),
  87. 'id' => $this->request->param('id/d'),
  88. ];
  89. $validate = $this->validate($data,'Category.sort');
  90. if(true !== $validate){
  91. return enjson(0,$validate);
  92. }
  93. $result = AllwinShopCate::update(['sort'=>$data['sort'],'id' => $data['id']]);
  94. if($result){
  95. return enjson(200,'操作成功');
  96. }else{
  97. return enjson(0,'操作失败');
  98. }
  99. }
  100. }
  101. //删除
  102. public function delete(int $id){
  103. $goods = AllwinShop::where(['category_id' => $id])->find();
  104. if($goods){
  105. return enjson(403,'删除失败,请查看是否包含商品');
  106. }
  107. $result = AllwinShopCate::destroy(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id]);
  108. if($result){
  109. return enjson(200,'操作成功');
  110. }else{
  111. return enjson(403,'删除失败,请查看是否包含商品');
  112. }
  113. }
  114. }