Browse Source

商品删除

sunhao 5 years ago
parent
commit
6f7a31195f

+ 27 - 3
app/Http/Controllers/Admin/GoodsController.php

41
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
41
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
42
             if($stime) $query->where('createTime', '>=', $stime);
42
             if($stime) $query->where('createTime', '>=', $stime);
43
             if($etime) $query->where('createTime', '<=', $etime);
43
             if($etime) $query->where('createTime', '<=', $etime);
44
-        })->count();
44
+        })->where('is_del', '<', 2)->count();
45
         if ($count > 1) {
45
         if ($count > 1) {
46
             // 总页数
46
             // 总页数
47
             $pages = ceil($count/$pageSize);
47
             $pages = ceil($count/$pageSize);
55
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
55
             if($cate_name) $query->where('goodsCategoryName', '=', $cate_name);
56
             if($stime) $query->where('createTime', '>=', $stime);
56
             if($stime) $query->where('createTime', '>=', $stime);
57
             if($etime) $query->where('createTime', '<=', $etime);
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
         $result = json_decode(json_encode($result),true);
59
         $result = json_decode(json_encode($result),true);
60
 
60
 
61
         foreach($result as $k=>&$v){
61
         foreach($result as $k=>&$v){
342
      * @param Request $request
342
      * @param Request $request
343
      * @return \Illuminate\Http\RedirectResponse
343
      * @return \Illuminate\Http\RedirectResponse
344
      */
344
      */
345
-    public function delete($id)
345
+    public function down($id)
346
     {
346
     {
347
         $goods = Goods::find($id);
347
         $goods = Goods::find($id);
348
         $goods->is_del = 1;
348
         $goods->is_del = 1;
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
     public function searchSkus(Request $request){
413
     public function searchSkus(Request $request){

+ 2 - 1
app/Http/routes.php

220
         Route::post('goods/store',    'Admin\GoodsController@store');
220
         Route::post('goods/store',    'Admin\GoodsController@store');
221
         Route::get('goods/edit/{id}', 'Admin\GoodsController@edit');
221
         Route::get('goods/edit/{id}', 'Admin\GoodsController@edit');
222
         Route::post('goods/update',   'Admin\GoodsController@update');
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
         Route::get('goods/up/{id}',   'Admin\GoodsController@up');
225
         Route::get('goods/up/{id}',   'Admin\GoodsController@up');
225
         Route::get('goods/searchSkus',   'Admin\GoodsController@searchSkus');
226
         Route::get('goods/searchSkus',   'Admin\GoodsController@searchSkus');
226
 
227
 

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

61
                             <a style="text-decoration:none" onClick='sku_edit("规格管理","{{$a['id']}}")' href="javascript:;" title="规格管理"><span class="btn btn-primary radius">规格管理</span></a>
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
                              @if($a['is_del']==0)
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
                              @elseif($a['is_del']==1)
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>
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
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
                         </td>
69
                         </td>
69
                     </tr>
70
                     </tr>
70
                 @endforeach
71
                 @endforeach
105
             location.href='index?page='+num + '&name='+name + '&cate_name='+cate_name;
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
             layer.confirm('确认要下架吗?',function(index){                
110
             layer.confirm('确认要下架吗?',function(index){                
110
                 $.ajax({
111
                 $.ajax({
111
                     type: 'GET',
112
                     type: 'GET',
112
-                    url: '/admin/goods/delete/'+id,
113
+                    url: '/admin/goods/down/'+id,
113
                     dataType: 'json',
114
                     dataType: 'json',
114
                     success: function(data){
115
                     success: function(data){
115
                         if(data == 1){
116
                         if(data == 1){
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
         $("#page").paging({ 
156
         $("#page").paging({ 
140
             pageNo:{{$page}},
157
             pageNo:{{$page}},
141
             totalPage: {{$pages}},
158
             totalPage: {{$pages}},