|
@@ -41,14 +41,16 @@ class CmsSubjectController extends BaseController
|
|
|
$data = $fractal->createData($resource)->toArray();
|
|
|
$data['extra'] = [
|
|
|
'filters' => [
|
|
|
- 'id'
|
|
|
+ 'id',
|
|
|
+ 'city_id',
|
|
|
+ 'is_open',
|
|
|
+ 'used_mall'
|
|
|
],
|
|
|
'columns' => [
|
|
|
'id',
|
|
|
- 'city_id',
|
|
|
'city_name',
|
|
|
+ 'used_mall',
|
|
|
'title',
|
|
|
- 'show_type',
|
|
|
'is_open',
|
|
|
'product_count',
|
|
|
]
|
|
@@ -63,10 +65,8 @@ class CmsSubjectController extends BaseController
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
'product_id' => 'required',
|
|
|
'sort' => 'required',
|
|
|
- 'city_id' => 'required|integer',
|
|
|
- 'city_name' => 'required|string',
|
|
|
'title' => 'required|string',
|
|
|
- 'show_type' => ['required', Rule::in(0,1,2)],
|
|
|
+ 'show_type' => ['required', Rule::in(0,1,2,3)],
|
|
|
'is_open' => ['required', Rule::in(0,1)],
|
|
|
]);
|
|
|
if ($validator->fails()) {
|
|
@@ -84,10 +84,8 @@ class CmsSubjectController extends BaseController
|
|
|
'id' => 'required|exists:cms_subject',
|
|
|
'product_id' => 'required',
|
|
|
'sort' => 'required',
|
|
|
- 'city_id' => 'required|integer',
|
|
|
- 'city_name' => 'required|string',
|
|
|
'title' => 'required|string',
|
|
|
- 'show_type' => ['required', Rule::in(0,1,2)],
|
|
|
+ 'show_type' => ['required', Rule::in(0,1,2,3)],
|
|
|
'is_open' => ['required', Rule::in(0,1)],
|
|
|
]);
|
|
|
|
|
@@ -106,48 +104,22 @@ class CmsSubjectController extends BaseController
|
|
|
'id' => 'required|integer',
|
|
|
]);
|
|
|
|
|
|
- if($validator->fails()) {
|
|
|
-
|
|
|
+ if ($validator->fails()) {
|
|
|
return $this->response->error($validator->errors()->first(), 500);
|
|
|
}
|
|
|
- $getSubject = $this->cmsSubjectRepository->index($request->all());
|
|
|
-
|
|
|
- if (count($getSubject)>0) {
|
|
|
- foreach ($getSubject as $k => $v) {
|
|
|
- $product = CmsSubjectProduct::select('subject_id','product_id','sort')->where('subject_id',$v['id'])->orderBy('sort','asc')->get();
|
|
|
- $num = $product->toArray();
|
|
|
- $product_arr = array_column($num,'product_id');
|
|
|
- $getSubject[$k]->product_id = implode(',',$product_arr);
|
|
|
- $sort_arry = array_column($num,'sort');
|
|
|
- $getSubject[$k]->sort = implode(',',$sort_arry);
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if(!$getSubject){
|
|
|
- return $this->response->error($validator->errors()->first(), 500);
|
|
|
- }
|
|
|
+ $getSubject = $this->cmsSubjectRepository->detail($request->all());
|
|
|
|
|
|
- $fractal = new Manager();
|
|
|
- $resource = new Collection($getSubject, new CmsSubjectViewTransformer());
|
|
|
- $resource->setPaginator(new IlluminatePaginatorAdapter($getSubject));
|
|
|
- $data = $fractal->createData($resource)->toArray();
|
|
|
- $data['extra'] = [
|
|
|
- 'filters' => [
|
|
|
- 'id'
|
|
|
- ],
|
|
|
- 'columns' => [
|
|
|
- 'id',
|
|
|
- 'city_id',
|
|
|
- 'city_name',
|
|
|
- 'title',
|
|
|
- 'show_type',
|
|
|
- 'is_open',
|
|
|
- 'product_id',
|
|
|
- 'sort',
|
|
|
- ]
|
|
|
- ];
|
|
|
- return $data;
|
|
|
+ if (count($getSubject->toArray()) > 0) {
|
|
|
+ $product = CmsSubjectProduct::select('subject_id', 'product_id', 'sort')->where('subject_id', $getSubject->id)->orderBy('sort', 'asc')->get();
|
|
|
+ $num = $product->toArray();
|
|
|
+ $product_arr = array_column($num, 'product_id');
|
|
|
+ $getSubject->product_id = implode(',', $product_arr);
|
|
|
+ $sort_arry = array_column($num, 'sort');
|
|
|
+ $getSubject->sort = implode(',', $sort_arry);
|
|
|
+ }
|
|
|
|
|
|
+ return $this->response->item($getSubject, new CmsSubjectViewTransformer());
|
|
|
}
|
|
|
|
|
|
|