Cate.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\ais\controller\shop;
  9. use app\ais\controller\Common;
  10. use app\ais\model\AisShopCate;
  11. use app\ais\model\AisShop;
  12. use app\ais\model\AisStore;
  13. class Cate extends Common{
  14. public function initialize() {
  15. parent::initialize();
  16. $this->assign('pathMaps',[['name'=>'宝贝专题','url'=>url("ais/shopCate/index")]]);
  17. }
  18. /**
  19. * 列表
  20. */
  21. public function index(){
  22. $condition = [];
  23. $condition[] = ['member_miniapp_id','=',$this->member_miniapp_id];
  24. $view['lists'] = AisShopCate::where($condition)->order('sort desc,id desc')->paginate(20);
  25. return view()->assign($view);
  26. }
  27. //编辑
  28. public function edit(){
  29. if(request()->isAjax()){
  30. $data = [
  31. 'id' => $this->request->param('id/d',0),
  32. 'types' => $this->request->param('types/d',0),
  33. 'show_type' => $this->request->param('show_type/d',0),
  34. 'title' => $this->request->param('title/s'),
  35. 'content' => $this->request->param('content/s'),
  36. 'picture' => $this->request->param('picture/s'),
  37. 'member_miniapp_id' => $this->member_miniapp_id,
  38. ];
  39. $validate = $this->validate($data,'Category.save');
  40. if(true !== $validate){
  41. return enjson(0,$validate);
  42. }
  43. $result = AisShopCate::edit($data);
  44. if($result){
  45. return enjson(200,'操作成功');
  46. }else{
  47. return enjson(0,'操作失败');
  48. }
  49. }else{
  50. $view['info'] = AisShopCate::where(['id' => $this->request->param('id/d'),'member_miniapp_id' => $this->member_miniapp_id])->find();
  51. return view()->assign($view);
  52. }
  53. }
  54. /**
  55. * 排序
  56. */
  57. public function sort(){
  58. if(request()->isAjax()){
  59. $data = [
  60. 'sort' => $this->request->param('sort/d'),
  61. 'id' => $this->request->param('id/d'),
  62. ];
  63. $validate = $this->validate($data,'Category.sort');
  64. if(true !== $validate){
  65. return enjson(0,$validate);
  66. }
  67. $result = AisShopCate::update(['sort'=>$data['sort'],'id' => $data['id']]);
  68. if($result){
  69. return enjson(200,'操作成功');
  70. }else{
  71. return enjson(0,'操作失败');
  72. }
  73. }
  74. }
  75. //删除
  76. public function delete(int $id){
  77. $goods = AisShop::where(['category_id' => $id])->find();
  78. if($goods){
  79. return enjson(403,'删除失败,请查看是否包含商品');
  80. }
  81. $result = AisShopCate::destroy(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id]);
  82. if($result){
  83. return enjson(200,'操作成功');
  84. }else{
  85. return enjson(403,'删除失败,请查看是否包含商品');
  86. }
  87. }
  88. }