Browse Source

商品下架

sunhao 5 years ago
parent
commit
996e376246

+ 53 - 7
app/Http/Controllers/Admin/GoodsController.php

@@ -41,7 +41,7 @@ class GoodsController extends Controller
41 41
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
42 42
             if($stime) $query->where('createTime', '>=', $stime);
43 43
             if($etime) $query->where('createTime', '<=', $etime);
44
-        })->where('is_del',0)->count();
44
+        })->count();
45 45
         if ($count > 1) {
46 46
             // 总页数
47 47
             $pages = ceil($count/$pageSize);
@@ -55,7 +55,7 @@ class GoodsController extends Controller
55 55
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
56 56
             if($stime) $query->where('createTime', '>=', $stime);
57 57
             if($etime) $query->where('createTime', '<=', $etime);
58
-        })->where('is_del',0)->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
58
+        })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
59 59
         $result = json_decode(json_encode($result),true);
60 60
 
61 61
         foreach($result as $k=>&$v){
@@ -316,7 +316,7 @@ class GoodsController extends Controller
316 316
     }
317 317
 
318 318
     /**
319
-     * 分组管理-进行删除操作
319
+     * 下架操作
320 320
      * @param Request $request
321 321
      * @return \Illuminate\Http\RedirectResponse
322 322
      */
@@ -328,7 +328,30 @@ class GoodsController extends Controller
328 328
             #记录操作日志
329 329
             $self_id = session('admin_id');
330 330
             $self_name = session('real_name');            
331
-            $context = "删除商品";
331
+            $context = "下架商品";
332
+            $type = 0; 
333
+            $tables = 'goods';
334
+            $data_id = $id;
335
+            Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
336
+            exit('1');
337
+        }
338
+        exit('0');
339
+    }
340
+
341
+    /**
342
+     * 上架操作
343
+     * @param Request $request
344
+     * @return \Illuminate\Http\RedirectResponse
345
+     */
346
+    public function up($id)
347
+    {
348
+        $goods = Goods::find($id);
349
+        $goods->is_del = 0;
350
+        if ($goods ->save()){
351
+            #记录操作日志
352
+            $self_id = session('admin_id');
353
+            $self_name = session('real_name');            
354
+            $context = "上架商品";
332 355
             $type = 0; 
333 356
             $tables = 'goods';
334 357
             $data_id = $id;
@@ -355,7 +378,7 @@ class GoodsController extends Controller
355 378
      */
356 379
     public function skuList(Request $request){
357 380
         $goods_id = $request->input('goods_id');
358
-        $result = GoodsSkus::where('goodsCode', $goods_id)->where('is_del', 0)->orderBy('id', 'desc')->get();
381
+        $result = GoodsSkus::where('goodsCode', $goods_id)->orderBy('id', 'desc')->get();
359 382
         return view('/goods/skulist', ['result'=>$result, 'goods_id' => $goods_id]);
360 383
     }
361 384
 
@@ -530,7 +553,7 @@ class GoodsController extends Controller
530 553
     }
531 554
 
532 555
     /**
533
-     * 进行删除操作
556
+     * 进行下架操作
534 557
      * @param Request $request
535 558
      * @return \Illuminate\Http\RedirectResponse
536 559
      */
@@ -542,7 +565,30 @@ class GoodsController extends Controller
542 565
             #记录操作日志
543 566
             $self_id = session('admin_id');
544 567
             $self_name = session('real_name');            
545
-            $context = "删除sku";
568
+            $context = "下架sku";
569
+            $type = 0; 
570
+            $tables = 'goods_skus';
571
+            $data_id = $id;
572
+            Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
573
+            exit('1');
574
+        }
575
+        exit('0');
576
+    }
577
+
578
+    /**
579
+     * 进行上架操作
580
+     * @param Request $request
581
+     * @return \Illuminate\Http\RedirectResponse
582
+     */
583
+    public function skuUp($id)
584
+    {
585
+        $goods = GoodsSkus::find($id);
586
+        $goods->is_del = 0;
587
+        if ($goods ->save()){
588
+            #记录操作日志
589
+            $self_id = session('admin_id');
590
+            $self_name = session('real_name');            
591
+            $context = "上架sku";
546 592
             $type = 0; 
547 593
             $tables = 'goods_skus';
548 594
             $data_id = $id;

+ 2 - 0
app/Http/routes.php

@@ -180,6 +180,7 @@ Route::group(['prefix' => 'admin'], function(){
180 180
         Route::get('goods/edit/{id}', 'Admin\GoodsController@edit');
181 181
         Route::post('goods/update',   'Admin\GoodsController@update');
182 182
         Route::get('goods/delete/{id}',   'Admin\GoodsController@delete');
183
+        Route::get('goods/up/{id}',   'Admin\GoodsController@up');
183 184
         Route::get('goods/searchSkus',   'Admin\GoodsController@searchSkus');
184 185
 
185 186
         Route::get('goods/skulist',   'Admin\GoodsController@skuList');
@@ -188,6 +189,7 @@ Route::group(['prefix' => 'admin'], function(){
188 189
         Route::get('goods/skuedit/{id}', 'Admin\GoodsController@skuEdit');
189 190
         Route::post('goods/skuupdate',   'Admin\GoodsController@skuUpdate');
190 191
         Route::get('goods/skudelete/{id}',   'Admin\GoodsController@skuDel');
192
+        Route::get('goods/skuup/{id}',   'Admin\GoodsController@skuUp');
191 193
 
192 194
         Route::get('template/index',   'Admin\TemplateController@index');
193 195
         Route::get('template/create',    'Admin\TemplateController@create');

+ 28 - 6
resources/views/goods/index.blade.php

@@ -33,7 +33,8 @@
33 33
                     <th width="8%">商品货号</th>
34 34
                     <th width="25%">商品规格</th>
35 35
                     <th width="15%">商品描述</th>
36
-                    <th width="10%">创建时间</th>
36
+                    <th width="5%">上架状态</th>
37
+                    <th width="8%">创建时间</th>
37 38
                     <th width="10%">操作</th>
38 39
                 </tr>
39 40
                 </thead>
@@ -53,11 +54,17 @@
53 54
                             @endforeach
54 55
                         </td>
55 56
                         <td class="text-c">{{$a['description']}}</td>
57
+                        <td class="text-c">@if($a['is_del']==1) 下架 @else 上架 @endif</td>
56 58
                         <td class="text-c">{{$a['createTime']}}</td>
57 59
                         <td class="f-14 product-brand-manage">
58 60
                             <a style="text-decoration:none" onClick='admin_edit("编辑","{{$a['id']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑</span></a>
59 61
                             <a style="text-decoration:none" onClick='sku_edit("规格管理","{{$a['id']}}")' href="javascript:;" title="规格管理"><span class="btn btn-primary radius">规格管理</span></a>
60
-                             <a style="text-decoration:none" class="ml-5" onClick="admin_del(this, '{{$a["id"]}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a>
62
+                             
63
+                             @if($a['is_del']==0)
64
+                             <a style="text-decoration:none" class="ml-5" onClick="admin_del(this, '{{$a["id"]}}')" href="javascript:;" title="下架"><span class="btn btn-danger radius">下架</span></a>
65
+                             @elseif($a['is_del']==1)
66
+                             <a style="text-decoration:none" class="ml-5" onClick="admin_up(this, '{{$a['id']}}')" href="javascript:;" title="上架"><span class="btn btn-success radius">上架</span></a>
67
+                             @endif
61 68
                         </td>
62 69
                     </tr>
63 70
                 @endforeach
@@ -97,23 +104,38 @@
97 104
             var cate_name = $('#cate_name').val();
98 105
             location.href='index?page='+num + '&name='+name + '&cate_name='+cate_name;
99 106
         }
100
-        /*管理员-删除*/
107
+        /*管理员-下架*/
101 108
         function admin_del(obj,id){
102
-            layer.confirm('确认要删除吗?',function(index){                
109
+            layer.confirm('确认要下架吗?',function(index){                
103 110
                 $.ajax({
104 111
                     type: 'GET',
105 112
                     url: '/admin/goods/delete/'+id,
106 113
                     dataType: 'json',
107 114
                     success: function(data){
108 115
                         if(data == 1){
109
-                            $(obj).parents("tr").remove();
110
-                           layer.msg('已删除!',{icon:1,time:1000});
116
+                            location.reload();
111 117
                         }
112 118
                     }
113 119
                 });
114 120
             });
115 121
         }
116 122
 
123
+        /**/
124
+        function admin_up(obj,id){
125
+            layer.confirm('确认要上架吗?',function(index){                
126
+                $.ajax({
127
+                    type: 'GET',
128
+                    url: '/admin/goods/up/'+id,
129
+                    dataType: 'json',
130
+                    success: function(data){
131
+                        if(data == 1){
132
+                            location.reload();
133
+                        }
134
+                    }
135
+                });
136
+            });
137
+        }  
138
+
117 139
         $("#page").paging({ 
118 140
             pageNo:{{$page}},
119 141
             totalPage: {{$pages}},

+ 33 - 11
resources/views/goods/skulist.blade.php

@@ -13,14 +13,15 @@
13 13
                 <thead>
14 14
                 <tr class="text-c">
15 15
                     {{--<th width="25"><input type="checkbox" name="" value=""></th>--}}
16
-                    <th width="10%">ID</th>
17
-                    <th width="10%">sku编码</th>
16
+                    <th width="5%">ID</th>
17
+                    <th width="7%">sku编码</th>
18 18
                     <th width="10%">规格</th>
19
-                    <th width="10%">价格</th>
20
-                    <th width="10%">吊牌价</th>
21
-                    <th width="10%">参考成本</th>
22
-                    <th width="10%">是否称重</th>
23
-                    <th width="10%">库存</th>
19
+                    <th width="7%">价格</th>
20
+                    <th width="7%">吊牌价</th>
21
+                    <th width="7%">参考成本</th>
22
+                    <th width="7%">是否称重</th>
23
+                    <th width="7%">库存</th>
24
+                    <th width="7%">是否启用</th>
24 25
                     <th width="10%">创建时间</th>
25 26
                     <th width="10%">操作</th>
26 27
                 </tr>
@@ -38,9 +39,15 @@
38 39
                         <td class="text-c">{{$a['referenceCost']}}</td>
39 40
                         <td class="text-c">@if($a['is_weigh']==1) 是 @else 否@endif</td>
40 41
                         <td class="text-c">{{$a['quantity']}}</td>
42
+                        <td class="text-c">@if($a['is_del']==1) 禁用 @else 启用 @endif</td>
41 43
                         <td class="text-c">{{$a['createTime']}}</td>
42 44
                         <td class="f-14 product-brand-manage"><a style="text-decoration:none" onClick='admin_edit("编辑","{{$a['id']}}","{{$a['goodsCode']}}")' href="javascript:;" title="编辑"><span class="btn btn-primary radius">编辑</span></a>
43
-                         <a style="text-decoration:none" class="ml-5" onClick="admin_del(this, '{{$a['id']}}')" href="javascript:;" title="删除"><span class="btn btn-danger radius">删除</span></a></td>
45
+                         @if($a['is_del']==0)
46
+                         <a style="text-decoration:none" class="ml-5" onClick="admin_del(this, '{{$a['id']}}')" href="javascript:;" title="禁用"><span class="btn btn-danger radius">禁用</span></a>
47
+                         @elseif($a['is_del']==1)
48
+                         <a style="text-decoration:none" class="ml-5" onClick="admin_up(this, '{{$a['id']}}')" href="javascript:;" title="启用"><span class="btn btn-success radius">启用</span></a>
49
+                         @endif
50
+                        </td>
44 51
                     </tr>
45 52
                 @endforeach
46 53
                 @endif
@@ -71,15 +78,30 @@
71 78
         }
72 79
         /*删除*/
73 80
         function admin_del(obj,id){
74
-            layer.confirm('确认要删除吗?',function(index){                
81
+            layer.confirm('确认要禁用吗?',function(index){                
75 82
                 $.ajax({
76 83
                     type: 'GET',
77 84
                     url: '/admin/goods/skudelete/'+id,
78 85
                     dataType: 'json',
79 86
                     success: function(data){
80 87
                         if(data == 1){
81
-                            $(obj).parents("tr").remove();
82
-                           layer.msg('已删除!',{icon:1,time:1000});
88
+                            location.reload();
89
+                        }
90
+                    }
91
+                });
92
+            });
93
+        } 
94
+
95
+        /*启用*/
96
+        function admin_up(obj,id){
97
+            layer.confirm('确认要启用吗?',function(index){                
98
+                $.ajax({
99
+                    type: 'GET',
100
+                    url: '/admin/goods/skuup/'+id,
101
+                    dataType: 'json',
102
+                    success: function(data){
103
+                        if(data == 1){
104
+                            location.reload();
83 105
                         }
84 106
                     }
85 107
                 });