| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 | 
							- <?php
 
- /**
 
-  * @copyright   Copyright (c) 2017 https://www.sapixx.com All rights reserved.
 
-  * @license     Licensed (http://www.apache.org/licenses/LICENSE-2.0).
 
-  * @author      pillar<ltmn@qq.com>
 
-  * 商品分类管理
 
-  */
 
- namespace app\bestbao\controller;
 
- use app\bestbao\model\BestbaoAskCategory;
 
- use app\bestbao\model\BestbaoAsk;
 
- use think\facade\Request;
 
- class AskCategory extends Common{
 
-     public function initialize(){
 
-         parent::initialize();
 
-         $this->assign('pathMaps',[['name'=>'产品分类','url'=>'javascript:;']]);
 
-     }
 
-     /**
 
-      * 列表
 
-      */
 
-     public function index(){
 
-         $view['lists'] = BestbaoAskCategory::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20); 
 
-         return view()->assign($view);
 
-     }
 
-     
 
-     /**
 
-      * 添加
 
-      */
 
-     public function add(){
 
-         if(request()->isAjax()){
 
-             $data = [
 
-                 'title'             => $this->request->param('title/s'),
 
-                 'sort'              => $this->request->param('sort/d'),
 
-                 'picture'           => $this->request->param('picture/s'),
 
-                 'member_miniapp_id' => $this->member_miniapp_id,
 
-             ];
 
-             $validate = $this->validate($data,'Category.edit');
 
-             if(true !== $validate){
 
-                 return json(['code'=>0,'msg'=>$validate]);
 
-             }
 
-             $result =  BestbaoAskCategory::edit($data);
 
-             if($result){
 
-                 return enjson(200,'操作成功',['url'=>url('askCategory/index')]);
 
-             }else{
 
-                 return enjson(0);
 
-             }
 
-         }else{
 
-             return view();
 
-         }
 
-     }
 
-     //编辑
 
-     public function edit(){
 
-         if(request()->isAjax()){
 
-             $data = [
 
-                 'id'      => $this->request->param('id/s'),
 
-                 'title'   => $this->request->param('title/s'),
 
-                 'sort'    => $this->request->param('sort/d'),
 
-                 'picture' => $this->request->param('picture/s'),
 
-             ];
 
-             $validate = $this->validate($data,'Category.edit');
 
-             if(true !== $validate){
 
-                 return json(['code'=>0,'msg'=>$validate]);
 
-             }
 
-             $result =  BestbaoAskCategory::edit($data);
 
-             if($result){
 
-                 return enjson(200,'操作成功',['url'=>url('askCategory/index')]);
 
-             }else{
 
-                 return enjson(0);
 
-             }
 
-         }else{
 
-             $view['info'] = BestbaoAskCategory::where(['id' => $this->request->param('id/d'),'member_miniapp_id' => $this->member_miniapp_id])->find();
 
-             return view()->assign($view);
 
-         }
 
-     }
 
-     /**
 
-      * 排序
 
-      */
 
-     public function sort(){
 
-         if(request()->isAjax()){
 
-             $data = [
 
-                 'sort' => $this->request->param('sort/d'),
 
-                 'id'   => $this->request->param('id/d'),
 
-             ];
 
-             $validate = $this->validate($data,'Category.sort');
 
-             if(true !== $validate){
 
-                 return json(['code'=>0,'msg'=>$validate]);
 
-             }
 
-             $result = BestbaoAskCategory::update(['sort'=>$data['sort']],['id' => $data['id']]);
 
-             if($result){
 
-                 return enjson(200);
 
-             }else{
 
-                 return enjson(0);
 
-             }
 
-         }
 
-     }
 
-     //删除
 
-     public function delete(int $id){
 
-         $goods = BestbaoAsk::where(['category_id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->find();
 
-         if($goods){
 
-             return enjson(403,'删除失败,栏目中还包含资源');
 
-         }
 
-         $result = BestbaoAskCategory::destroy($id);
 
-         if($result){
 
-             return enjson(200);
 
-         }else{
 
-             return enjson(403,'删除失败');
 
-         } 
 
-     }
 
- }
 
 
  |