dyjh %!s(int64=6) %!d(string=hai) anos
pai
achega
8da1cf3140
Modificáronse 1 ficheiros con 54 adicións e 28 borrados
  1. 54 28
      app/Http/Controllers/Admin/Album/ProductController.php

+ 54 - 28
app/Http/Controllers/Admin/Album/ProductController.php

xqd xqd xqd xqd xqd
@@ -30,7 +30,7 @@ class ProductController extends Controller
         $query = $this->repository->pushCriteria(new ProductWhere($search,$this->getStoreId()));
 
         if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
-        $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
+            $query = $query->pushCriteria(new OrderBy($request['sort_field'],$request['sort_field_by']));
         }else{
             $query = $query->pushCriteria(new OrderBy('id','DESC'));
         }
@@ -51,32 +51,61 @@ class ProductController extends Controller
         return view('admin.album.product.index',compact('list'));
     }
 
-
-    function check(Request $request) {
+    /**
+     * @param Request $request
+     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+     */
+    function check(Request $request)
+    {
         $request = $request->all();
         $search['keyword'] = $request->input('keyword');
         $orderby = array();
-        if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
+        if (isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
             $orderby[$request['sort_field']] = $request['sort_field_by'];
         }
-        $list = $this->repository->search($search,$orderby);
-        return view('admin.album.product.check',compact('list'));
+        $list = $this->repository->search($search, $orderby);
+        return view('admin.album.product.check', compact('list'));
     }
 
+    /**
+     * @param Request $request
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function getSecondCategory(Request $request)
+    {
+        $cat_id = $request->input('cat_id');
+        if (!$cat_id) {
+            return response()->json(['message' => '参数不合法', 'code' => 1]);
+        }
+        $cat = AlbumCatModel::where([
+            ['parent_id',$cat_id],['store_id',$this->getStoreId()]
+        ])->orderByDesc('sort')->get()->toArray();
+        if (empty($cat)) {
+            $cat[] = [
+                'name' => '请先添加二级分类!',
+                'id'   => 0
+            ];
+        }
+        // print_r($cat);die;
+        return response()->json([
+            'data' => $cat,
+            'code' => 0
+        ]);
+    }
 
     /**
      * 添加
-     * 
+     *
      */
     public function create(Request $request)
     {
-        if($request->method() == 'POST') {
+        if ($request->method() == 'POST') {
             return $this->_createSave();
         }
         $cat = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id',0]])->get();
-        $style = AlbumProductStyleModel::Where('store_id',$this->getStoreId())->get();
-        $data['cat_id']=null;
-        return view('admin.album.product.edit',compact('data','cat','style'));
+
+        $data['cat_id'] = null;
+        return view('admin.album.product.edit', compact('data', 'cat', 'style'));
     }
 
     /**
@@ -119,28 +148,25 @@ class ProductController extends Controller
             return $this->showWarning('添加失败',$url);
         }
     }
-    
+
     /**
-     * 
+     *
      * 修改
-     * 
-     * 
+     *
+     *
      */
-    public function update(Request $request) {
-        if($request->method() == 'POST') {
+    public function update(Request $request)
+    {
+        if ($request->method() == 'POST') {
             return $this->_updateSave();
         }
         $cat = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id',0]])->get();
-        $style = AlbumProductStyleModel::Where('store_id',$this->getStoreId())->get();
         $data = $this->repository->find($request->get('id'));
-
-
-            $data['install_img'] = json_decode($data['install_img']);
-            $data['specifications_img'] = json_decode($data['specifications_img']);
-            $data['detail'] = json_decode($data['detail']);
-
-
-        return view('admin.album.product.edit',compact('data','cat','style'));
+        $parent = AlbumCatModel::where([['store_id',$this->getStoreId()],['parent_id',0],['id',$data->cat_id]])->get();
+        $data['install_img'] = json_decode($data['install_img']);
+        $data['specifications_img'] = json_decode($data['specifications_img']);
+        $data['detail'] = json_decode($data['detail']);
+        return view('admin.album.product.edit', compact('data', 'cat', 'parent'));
     }
 
     /**
@@ -172,7 +198,7 @@ class ProductController extends Controller
         }
         if(!empty($data['detail_pic']))
             $data['detail_pic'] = $this->formatImgUrl($data['detail_pic']);
-       // dd($data);
+        // dd($data);
         $ok = $this->repository->update(request('id'),$data);
         if($ok) {
             $url[] = array('url'=>U( 'Album/Product/index'),'title'=>'返回列表');
@@ -202,7 +228,7 @@ class ProductController extends Controller
             return $this->showWarning('操作失败');
         }
     }
-    
+
     /**
      * 删除
      */