123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?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\BestbaoCategory;
- use app\bestbao\model\BestbaoProduct;
- use think\facade\Request;
- class Product extends Common{
- public function initialize(){
- parent::initialize();
- $this->assign('pathMaps',[['name'=>'产品管理','url'=>'javascript:;']]);
- }
- /**
- * 列表
- */
- public function index(){
- $view['lists'] = BestbaoProduct::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
- return view()->assign($view);
- }
-
- /**
- * 添加
- */
- public function create(){
- if(request()->isAjax()){
- $data = [
- 'code' => $this->request->param('code/s'),
- 'category_id' => $this->request->param('category_id/d'),
- 'title' => $this->request->param('title/s'),
- 'note' => $this->request->param('note/s'),
- 'images' => $this->request->param('images/s'),
- 'member_miniapp_id' => $this->member_miniapp_id,
- ];
- $validate = $this->validate($data,'Product.edit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- $result = BestbaoProduct::edit($data);
- if($result){
- return enjson(200,'操作成功',['url'=>url('product/index')]);
- }else{
- return enjson(0);
- }
- }else{
- $view['category'] = BestbaoCategory::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
- return view()->assign($view);
- }
- }
- //编辑
- public function edit(){
- if(request()->isAjax()){
- $data = [
- 'id' => $this->request->param('id/s'),
- 'code' => $this->request->param('code/s'),
- 'category_id' => $this->request->param('category_id/d'),
- 'title' => $this->request->param('title/s'),
- 'note' => $this->request->param('note/s'),
- 'images' => $this->request->param('images/s'),
- ];
- $validate = $this->validate($data,'product.edit');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- $result = BestbaoProduct::edit($data);
- if($result){
- return enjson(200,'操作成功',['url'=>url('product/index')]);
- }else{
- return enjson(0);
- }
- }else{
- $view['info'] = BestbaoProduct::where(['id' => Request::param('id/d'),'member_miniapp_id' => $this->member_miniapp_id])->find();
- $view['category'] = BestbaoCategory::where(['member_miniapp_id' => $this->member_miniapp_id])->order('sort desc,id desc')->paginate(20);
- 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,'product.sort');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- $result = BestbaoProduct::update(['sort'=>$data['sort']],['id' => $data['id']]);
- if($result){
- return enjson(200);
- }else{
- return enjson(0);
- }
- }
- }
- //删除
- public function delete(int $id){
- $result = BestbaoProduct::destroy($id);
- if($result){
- return enjson(200);
- }else{
- return enjson(403,'删除失败');
- }
- }
- }
|