diff --git a/app/admin/controller/Api.php b/app/admin/controller/Api.php index e824a51..15299a7 100644 --- a/app/admin/controller/Api.php +++ b/app/admin/controller/Api.php @@ -1245,6 +1245,21 @@ class Api extends BaseController return table_assign(0, '', $result); } + public function changestatus(){ + $data = get_params(); + if($data){ + $where['product_id'] = $data['product_id']; + $d['is_show'] = $data['is_show']; + $res = Db::connect('shop')->table('eb_store_product')->where($where)->update($d); + if($res){ + return to_assign(200, '操作成功'); + }else{ + return to_assign(0, '操作失败'); + } + } + return to_assign(0, '操作失败'); + } + } diff --git a/app/admin/controller/product/Product.php b/app/admin/controller/product/Product.php index 589e41e..3d26cc4 100644 --- a/app/admin/controller/product/Product.php +++ b/app/admin/controller/product/Product.php @@ -85,7 +85,7 @@ class Product extends BaseController // request()->isAjax() // Ajax 前端获取数据 $params= get_params(); - +// halt($params); $where = self::auth(); if (isset($params['keywords']) && !empty($params['keywords'])){ @@ -93,6 +93,7 @@ class Product extends BaseController $where['keyword'] = $where['store_name'] = $params['keywords']; } + $page = empty($params['page'])?1:$params['page']; $limit = empty($params['limit'])?10:$params['limit']; @@ -108,17 +109,25 @@ class Product extends BaseController $where['is_show'] = empty($params['state'])?'':$params['state']; $where['temp_id'] = empty($params['shipping_tem'])?'':$params['shipping_tem']; $where['labels'] = empty($params['tag'])?'':$params['tag']; - $where['type'] = empty($params['type'])?'':$params['type'];//实体商品:0 虚拟商品:1 + $where['type'] = empty($params['type'])?'1':$params['type']; // $where['status'] = 0;//管理、审核、通过 - +// if(isset($params['type']) && !empty($params['type'])){ +// if($params['type'] == 1){ +// $where['is_show'] = 1; +// } +// if($params['type'] == 2){ +// $where['is_show'] = 0; +// } +// } // $where['is_ficti'] = 1;//是否虚拟销量 // $where['product_id'] = 0; // ['order','sort'] // soft //软删除 // $params['mer_id'] = $this->mer_id; - if (!empty($params['mer_id'])) { - $mer_id = get_params('mer_id'); + if (!empty($params['mer_id']) || !empty($this->mer_id)) { +// $mer_id = get_params('mer_id'); + $mer_id = $this->mer_id; $where = array_merge($where, $this->switchType($where['type'],$mer_id,0)); } $mer_id = isset($params['mer_id'])?$params['mer_id']:NULL; diff --git a/app/admin/view/product/product/index.html b/app/admin/view/product/product/index.html index 9bcaadf..50e0884 100644 --- a/app/admin/view/product/product/index.html +++ b/app/admin/view/product/product/index.html @@ -38,7 +38,7 @@
- +
@@ -262,6 +262,22 @@ align: 'center', width:150, },{ + field: 'is_show', + title: '商品状态', + align: 'center', + width:150, + escape:true, + templet: function (d) + { + if (d.is_show == 1) { + return '' + } else if (d.is_show == 0) { + return '' + } + // var html = d.is_show ? '上架显示' : '平台关闭'; + // return html; + }, + },{ field: 'is_good', title: '推荐级别', align: 'center', @@ -281,16 +297,6 @@ var html = d.is_used ? '显示' : '隐藏'; return html; }, - },{ - field: 'is_show', - title: '商品状态', - align: 'center', - width:150, - templet: function (d) - { - var html = d.is_show ? '上架显示' : '平台关闭'; - return html; - }, },{ field: 'keyword', title: '标签', @@ -355,7 +361,7 @@ var $ = layui.$, active = { reload: function(){ - let dataRload = getformdata();; + let dataRload = getformdata(); //执行重载 table.reload('article', { page: { @@ -432,7 +438,33 @@ active[type] ? active[type].call(this, othis) : ''; }); - }); + //监听指定开关 + form.on('switch(switchTest)', function (data) { //根据lay-filter进行监听 + console.log(this.checked ? "1" : "0"); + var is_show = this.checked ? "1" : "0"; //锁定状态赋值为1,未锁定赋值为2,根据数据库中的值 + console.log(data.elem.attributes['userId'].nodeValue); //获取修改数据的参数条件 + $.ajax({ + url: '/admin/api/changestatus', + type: 'post', + data: { + 'product_id': data.elem.attributes['userId'].nodeValue, + 'is_show': is_show + }, + success: function (res) { + if(res.code==200){ + layer.msg('操作成功'); + }else{ + layer.msg('操作失败'); + } + setTimeout(function () { + location.reload(); + }, 1000); + }, + dataType: 'json' + }); + form.render(); + }); + }); // 获取表单所有参数