瀏覽代碼

商品删除

sunhao 5 年之前
父節點
當前提交
6f7a31195f
共有 3 個文件被更改,包括 49 次插入7 次删除
  1. 27 3
      app/Http/Controllers/Admin/GoodsController.php
  2. 2 1
      app/Http/routes.php
  3. 20 3
      resources/views/goods/index.blade.php

+ 27 - 3
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
-        })->count();
44
+        })->where('is_del', '<', 2)->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
-        })->orderBy('id', 'desc')->offset($offset)->limit($pageSize)->get();
58
+        })->where('is_del', '<', 2)->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){
@@ -342,7 +342,7 @@ class GoodsController extends Controller
342 342
      * @param Request $request
343 343
      * @return \Illuminate\Http\RedirectResponse
344 344
      */
345
-    public function delete($id)
345
+    public function down($id)
346 346
     {
347 347
         $goods = Goods::find($id);
348 348
         $goods->is_del = 1;
@@ -384,6 +384,30 @@ class GoodsController extends Controller
384 384
     }
385 385
 
386 386
     /**
387
+     * 下架操作
388
+     * @param Request $request
389
+     * @return \Illuminate\Http\RedirectResponse
390
+     */
391
+    public function delete($id)
392
+    {
393
+        $goods = Goods::find($id);
394
+        $goods->is_del = 2;
395
+        if ($goods ->save()){
396
+            #记录操作日志
397
+            $self_id = session('admin_id');
398
+            $self_name = session('real_name');            
399
+            $context = "删除商品";
400
+            $type = 0; 
401
+            $tables = 'goods';
402
+            $data_id = $id;
403
+            Oplog::addLog($self_id, $self_name, $context, $type, $tables, $data_id);
404
+            exit('1');
405
+        }
406
+        exit('0');
407
+    }
408
+
409
+
410
+    /**
387 411
      * 搜索商品
388 412
      */
389 413
     public function searchSkus(Request $request){

+ 2 - 1
app/Http/routes.php

@@ -220,7 +220,8 @@ Route::group(['prefix' => 'admin'], function(){
220 220
         Route::post('goods/store',    'Admin\GoodsController@store');
221 221
         Route::get('goods/edit/{id}', 'Admin\GoodsController@edit');
222 222
         Route::post('goods/update',   'Admin\GoodsController@update');
223
-        Route::get('goods/delete/{id}',   'Admin\GoodsController@delete');
223
+        Route::get('goods/down/{id}',   'Admin\GoodsController@down'); //下架
224
+        Route::get('goods/delete/{id}',   'Admin\GoodsController@delete'); //删除
224 225
         Route::get('goods/up/{id}',   'Admin\GoodsController@up');
225 226
         Route::get('goods/searchSkus',   'Admin\GoodsController@searchSkus');
226 227
 

+ 20 - 3
resources/views/goods/index.blade.php

@@ -61,10 +61,11 @@
61 61
                             <a style="text-decoration:none" onClick='sku_edit("规格管理","{{$a['id']}}")' href="javascript:;" title="规格管理"><span class="btn btn-primary radius">规格管理</span></a>
62 62
                              
63 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>
64
+                             <a style="text-decoration:none" class="ml-5" onClick="admin_down(this, '{{$a["id"]}}')" href="javascript:;" title="下架"><span class="btn btn-danger radius">下架</span></a>
65 65
                              @elseif($a['is_del']==1)
66 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 67
                              @endif
68
+                             <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>
68 69
                         </td>
69 70
                     </tr>
70 71
                 @endforeach
@@ -105,11 +106,11 @@
105 106
             location.href='index?page='+num + '&name='+name + '&cate_name='+cate_name;
106 107
         }
107 108
         /*管理员-下架*/
108
-        function admin_del(obj,id){
109
+        function admin_down(obj,id){
109 110
             layer.confirm('确认要下架吗?',function(index){                
110 111
                 $.ajax({
111 112
                     type: 'GET',
112
-                    url: '/admin/goods/delete/'+id,
113
+                    url: '/admin/goods/down/'+id,
113 114
                     dataType: 'json',
114 115
                     success: function(data){
115 116
                         if(data == 1){
@@ -136,6 +137,22 @@
136 137
             });
137 138
         }  
138 139
 
140
+        /*管理员-删除*/
141
+        function admin_del(obj,id){
142
+            layer.confirm('确认要删除吗?',function(index){                
143
+                $.ajax({
144
+                    type: 'GET',
145
+                    url: '/admin/goods/delete/'+id,
146
+                    dataType: 'json',
147
+                    success: function(data){
148
+                        if(data == 1){
149
+                            location.reload();
150
+                        }
151
+                    }
152
+                });
153
+            });
154
+        }
155
+
139 156
         $("#page").paging({ 
140 157
             pageNo:{{$page}},
141 158
             totalPage: {{$pages}},