Kirin 3 سال پیش
والد
کامیت
05b38ec918
2فایلهای تغییر یافته به همراه137 افزوده شده و 93 حذف شده
  1. 13 1
      app/admin/controller/company/Goods.php
  2. 124 92
      app/admin/view/company/goods/index.php

+ 13 - 1
app/admin/controller/company/Goods.php

@@ -8,7 +8,7 @@ use app\models\system\SystemStore;
 use app\models\system\SystemStoreStock;
 use app\models\system\SystemStoreStockBill;
 use app\admin\model\store\{StoreCategory as CategoryModel, StoreProduct as ProductModel, StoreProductAttrValue};
-use crmeb\services\{JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form};
+use crmeb\services\{FormBuilder, JsonService, JsonService as Json, UtilService as Util, FormBuilder as Form};
 use crmeb\traits\CurdControllerTrait;
 use think\facade\Route as Url;
 
@@ -106,11 +106,23 @@ class Goods extends AuthController
         return $this->fetch();
     }
 
+    public function edit_stock($bar_code)
+    {
+        $f = [];
+        $f[] = Form::hidden('bar_code', $bar_code);
+        $f[] = Form::radio('type', '增减', 1)->setOptions([['value' => 1, 'label' => '增加'], ['value' => 2, 'label' => '减少']]);
+        $f[] = Form::number('in_stock', '数量', 0)->step(1)->min(1);
+        $form = Form::make_post_form('添加用户通知', $f, Url::buildUrl('save'));
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
     public function save()
     {
         $where = Util::getMore([
             ['bar_code', 20],
             ['in_stock', 0],
+            ['type', 1]
         ]);
         if (!$this->adminInfo['store_id']) return app('json')->fail('门店铺货用通道');
         if ($where['in_stock'] < 1) return app('json')->fail('补货数量不能少于1');

+ 124 - 92
app/admin/view/company/goods/index.php

@@ -2,7 +2,7 @@
 {block name="content"}
 <div class="layui-fluid" style="background: #fff;margin-top: -10px;">
 
-    <div class="layui-row layui-col-space15"  id="app">
+    <div class="layui-row layui-col-space15" id="app">
         <div class="layui-col-md12">
             <div class="layui-card">
                 <div class="layui-card-body">
@@ -34,13 +34,15 @@
                                 <label class="layui-form-label">商品名称</label>
                                 <div class="layui-input-block">
                                     <input type="text" name="key" class="layui-input" placeholder="请输入商品名称,关键字,编号">
-                          
+
                                 </div>
                             </div>
                             <div class="layui-inline">
                                 <div class="layui-input-inline">
-                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
-                                        <i class="layui-icon layui-icon-search"></i>搜索</button>
+                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search"
+                                            lay-filter="search">
+                                        <i class="layui-icon layui-icon-search"></i>搜索
+                                    </button>
                                 </div>
                             </div>
                         </div>
@@ -54,11 +56,12 @@
                 <div class="layui-card-body">
                     <div class="alert alert-info" role="alert">
                         列表[虚拟销量],[库存],[排序]可进行快速修改,双击或者单击进入编辑模式,失去焦点可进行自动保存
-                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
+                        <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span
+                                    aria-hidden="true">&times;</span></button>
                     </div>
                     <div class="layui-btn-container" lay-submit="addKc" lay-filter="addKc">
 
-                        <button class="layui-btn layui-btn-sm" >增加库存</button>
+                        <button class="layui-btn layui-btn-sm">增减库存</button>
 
                     </div>
                     <table class="layui-hide" id="List" lay-filter="List"></table>
@@ -69,11 +72,12 @@
                     <!--商品名称-->
                     <script type="text/html" id="store_name">
                         <h4>{{d.store_name}}</h4>
-                        <p>价格:<font color="red">{{d.price}}</font> </p>
+                        <p>价格:<font color="red">{{d.price}}</font></p>
                     </script>
                     <!--操作-->
                     <script type="text/html" id="act">
-                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span class="caret"></span></button>
+                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span
+                                    class="caret"></span></button>
                         <ul class="layui-nav-child layui-anim layui-anim-upbit">
                             <li>
                                 <a href="javascript:void(0);" lay-event='edit'>
@@ -93,52 +97,57 @@
     //实例化form
     layList.form.render();
     //加载列表
-    layList.tableList('List',"{:Url('product_ist')}",function (){
-        var join=new Array();
-        join=[
-                    {field: 'id', title: 'ID', sort: true,event:'id',width:'6%'},
-                    {field: 'store', title: '门店', width:'10%'},
-                    {field: 'image', title: '商品图片',templet:'#image',width:'10%'},
-                    {field: 'store_name', title: '商品名称',templet:'#store_name'},
-                    {field: 'in_stock', title: '库存',width:'8%'},
-                    {field: 'repair_sales', title: '待补货',width:'8%'},
-                    {field: 'store_sales', title: '销量',width:'8%'},
-                    {field: 'status', title: '状态',templet:"#checkboxstatus",width:'8%'},
-                    {field: 'right', title: '操作',align:'center',toolbar:'#act',width:'14%'},
-                ];
-        
+    layList.tableList('List', "{:Url('product_ist')}", function () {
+        var join = new Array();
+        join = [
+            {field: 'id', title: 'ID', sort: true, event: 'id', width: '6%'},
+            {field: 'store', title: '门店', width: '10%'},
+            {field: 'image', title: '商品图片', templet: '#image', width: '10%'},
+            {field: 'store_name', title: '商品名称', templet: '#store_name'},
+            {field: 'in_stock', title: '库存', width: '8%'},
+            {field: 'repair_sales', title: '待补货', width: '8%'},
+            {field: 'store_sales', title: '销量', width: '8%'},
+            {field: 'status', title: '状态', templet: "#checkboxstatus", width: '8%'},
+            {field: 'right', title: '操作', align: 'center', toolbar: '#act', width: '14%'},
+        ];
+
         return join;
     })
     //excel下载
-    layList.search('export',function(where){
+    layList.search('export', function (where) {
         where.excel = 1;
-        location.href=layList.U({c:'store.store_product',a:'product_ist',q:where});
+        location.href = layList.U({c: 'store.store_product', a: 'product_ist', q: where});
     })
     //点击弹窗增加库存
-    layList.search('addKc',function(where){
-        layer.prompt({title: '请输入条形码', formType: 0}, function(pass, index){
+    layList.search('addKc', function (where) {
+        layer.prompt({title: '请输入条形码', formType: 0}, function (pass, index) {
             layer.close(index);
-			$eb.axios.post('{:Url("store.Placeorder/getBarCode")}' + (pass ? '?bar_code=' + pass : '')).then(function (res) {
-			    const data = res.data.data;
-			    layer.open({
-			      content: '确认是否为商品'+`${data.store_name}[${data.suk}]¥${data.price}`
-			      ,btn: ['确定','取消'],
-				  yes:function(index){
-					  layer.close(index);
-						layer.prompt({title: '请输入数量', formType: 0}, function(text, index){
-						    layer.close(index);
-                            layList.baseGet(layList.Url({c:'company.goods',a:'save',p:{bar_code:pass,in_stock:text}}),function (res) {
-                                layList.msg(res.msg, function () {
-                                    //layList.reload();
-                                });
-                            });
-						});
-					}
-			    });
-			}).catch(function (err) {
-			    console.log(err);
-			})
-          
+            $eb.axios.post('{:Url("store.Placeorder/getBarCode")}' + (pass ? '?bar_code=' + pass : '')).then(function (res) {
+                const data = res.data.data;
+                layer.open({
+                    content: '确认是否为商品' + `${data.store_name}[${data.suk}]¥${data.price}`
+                    , btn: ['确定', '取消'],
+                    yes: function (index) {
+                        layer.close(index);
+                        $eb.createModalFrame('增减库存 - '.data.store_name,'{:Url('edit_stock')}',{h:550,w:720})
+                        // layer.prompt({title: '请输入数量', formType: 0}, function (text, index) {
+                        //     layer.close(index);
+                        //     layList.baseGet(layList.Url({
+                        //         c: 'company.goods',
+                        //         a: 'save',
+                        //         p: {bar_code: pass, in_stock: text}
+                        //     }), function (res) {
+                        //         layList.msg(res.msg, function () {
+                        //             //layList.reload();
+                        //         });
+                        //     });
+                        // });
+                    }
+                });
+            }).catch(function (err) {
+                console.log(err);
+            })
+
         });
 
 
@@ -149,61 +158,71 @@
     $(document).click(function (e) {
         $('.layui-nav-child').hide();
     })
-    function dropdown(that){
+
+    function dropdown(that) {
         var oEvent = arguments.callee.caller.arguments[0] || event;
         oEvent.stopPropagation();
         var offset = $(that).offset();
-        var top=offset.top-$(window).scrollTop();
+        var top = offset.top - $(window).scrollTop();
         var index = $(that).parents('tr').data('index');
         $('.layui-nav-child').each(function (key) {
             if (key != index) {
                 $(this).hide();
             }
         })
-        if($(document).height() < top+$(that).next('ul').height()){
+        if ($(document).height() < top + $(that).next('ul').height()) {
             $(that).next('ul').css({
                 'padding': 10,
-                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
+                'top': -($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height() / 2),
                 'min-width': 'inherit',
                 'position': 'absolute'
             }).toggle();
-        }else{
+        } else {
             $(that).next('ul').css({
                 'padding': 10,
-                'top':$(that).parent('td').height() / 2 + $(that).height(),
+                'top': $(that).parent('td').height() / 2 + $(that).height(),
                 'min-width': 'inherit',
                 'position': 'absolute'
             }).toggle();
         }
     }
+
     //快速编辑
     layList.edit(function (obj) {
-        var id=obj.data.id,value=obj.value;
+        var id = obj.data.id, value = obj.value;
         switch (obj.field) {
             case 'price':
-                action.set_product('price',id,value);
+                action.set_product('price', id, value);
                 break;
             case 'stock':
-                action.set_product('stock',id,value);
+                action.set_product('stock', id, value);
                 break;
             case 'sort':
-                action.set_product('sort',id,value);
+                action.set_product('sort', id, value);
                 break;
             case 'ficti':
-                action.set_product('ficti',id,value);
+                action.set_product('ficti', id, value);
                 break;
         }
     });
     //上下加商品
-    layList.switch('is_show',function (odj,value) {
-        if(odj.elem.checked==true){
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_show',p:{is_show:1,id:value}}),function (res) {
+    layList.switch('is_show', function (odj, value) {
+        if (odj.elem.checked == true) {
+            layList.baseGet(layList.Url({
+                c: 'store.store_product',
+                a: 'set_show',
+                p: {is_show: 1, id: value}
+            }), function (res) {
                 layList.msg(res.msg, function () {
                     layList.reload();
                 });
             });
-        }else{
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_show',p:{is_show:0,id:value}}),function (res) {
+        } else {
+            layList.baseGet(layList.Url({
+                c: 'store.store_product',
+                a: 'set_show',
+                p: {is_show: 0, id: value}
+            }), function (res) {
                 layList.msg(res.msg, function () {
                     layList.reload();
                 });
@@ -211,75 +230,88 @@
         }
     });
     //点击事件绑定
-    layList.tool(function (event,data,obj) {
+    layList.tool(function (event, data, obj) {
         switch (event) {
             case 'delstor':
-                var url=layList.U({c:'store.store_product',a:'delete',q:{id:data.id}});
-                if(data.is_del) var code = {title:"操作提示",text:"确定恢复商品操作吗?",type:'info',confirm:'是的,恢复该商品'};
-                else var code = {title:"操作提示",text:"确定将该商品移入回收站吗?",type:'info',confirm:'是的,移入回收站'};
-                $eb.$swal('delete',function(){
-                    $eb.axios.get(url).then(function(res){
-                        if(res.status == 200 && res.data.code == 200) {
-                            $eb.$swal('success',res.data.msg);
+                var url = layList.U({c: 'store.store_product', a: 'delete', q: {id: data.id}});
+                if (data.is_del) var code = {title: "操作提示", text: "确定恢复商品操作吗?", type: 'info', confirm: '是的,恢复该商品'};
+                else var code = {title: "操作提示", text: "确定将该商品移入回收站吗?", type: 'info', confirm: '是的,移入回收站'};
+                $eb.$swal('delete', function () {
+                    $eb.axios.get(url).then(function (res) {
+                        if (res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success', res.data.msg);
                             obj.del();
                             location.reload();
-                        }else
+                        } else
                             return Promise.reject(res.data.msg || '删除失败')
-                    }).catch(function(err){
-                        $eb.$swal('error',err);
+                    }).catch(function (err) {
+                        $eb.$swal('error', err);
                     });
-                },code)
+                }, code)
                 break;
             case 'open_image':
                 $eb.openImage(data.image);
                 break;
             case 'edit':
-                $eb.createModalFrame(data.store_name,layList.U({a:'bill_view',q:{product_id:data.product_id,store_id:data.store_id}}),{h:600,w:1000})
+                $eb.createModalFrame(data.store_name, layList.U({
+                    a: 'bill_view',
+                    q: {product_id: data.product_id, store_id: data.store_id}
+                }), {h: 600, w: 1000})
                 break;
             case 'attr':
-                $eb.createModalFrame(data.store_name+'-属性',layList.U({a:'attr',q:{id:data.id}}),{h:600,w:800})
+                $eb.createModalFrame(data.store_name + '-属性', layList.U({a: 'attr', q: {id: data.id}}), {
+                    h: 600,
+                    w: 800
+                })
                 break;
         }
     })
     //排序
     layList.sort(function (obj) {
         var type = obj.type;
-        switch (obj.field){
+        switch (obj.field) {
             case 'id':
-                layList.reload({order: layList.order(type,'id')},true,null,obj);
+                layList.reload({order: layList.order(type, 'id')}, true, null, obj);
                 break;
             case 'sales':
-                layList.reload({order: layList.order(type,'sales')},true,null,obj);
+                layList.reload({order: layList.order(type, 'sales')}, true, null, obj);
                 break;
         }
     });
     //查询
-    layList.search('search',function(where){
-        layList.reload(where,true);
+    layList.search('search', function (where) {
+        layList.reload(where, true);
     });
     //自定义方法
-    var action={
-        set_product:function(field,id,value){
-            layList.baseGet(layList.Url({c:'store.store_product',a:'set_product',q:{field:field,id:id,value:value}}),function (res) {
+    var action = {
+        set_product: function (field, id, value) {
+            layList.baseGet(layList.Url({
+                c: 'store.store_product',
+                a: 'set_product',
+                q: {field: field, id: id, value: value}
+            }), function (res) {
                 layList.msg(res.msg);
             });
         },
-        show:function(){
-            var ids=layList.getCheckData().getIds('id');
-            if(ids.length){
-                layList.basePost(layList.Url({c:'store.store_product',a:'product_show'}),{ids:ids},function (res) {
+        show: function () {
+            var ids = layList.getCheckData().getIds('id');
+            if (ids.length) {
+                layList.basePost(layList.Url({
+                    c: 'store.store_product',
+                    a: 'product_show'
+                }), {ids: ids}, function (res) {
                     layList.msg(res.msg);
                     layList.reload();
                 });
-            }else{
+            } else {
                 layList.msg('请选择要上架的商品');
             }
         }
     };
     //多选事件绑定
     $('.layui-btn-container').find('button').each(function () {
-        var type=$(this).data('type');
-        $(this).on('click',function(){
+        var type = $(this).data('type');
+        $(this).on('click', function () {
             action[type] && action[type]();
         })
     });