|
@@ -91,6 +91,52 @@ class CategoryController extends Curd
|
|
|
return json_success('success', $tree->getTree());
|
|
|
}
|
|
|
|
|
|
+ public function goodsCategory(Request $request)
|
|
|
+ {
|
|
|
+ [$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
|
+ $format = 'tree';
|
|
|
+ $order = $request->get('order', 'desc');
|
|
|
+ $field = $field ?? 'category_sort';
|
|
|
+ $where['category_status'] = 'ACTIVED';
|
|
|
+ $where['category_super_id'] = ['in','31,154,5,181,30,70,42'];
|
|
|
+ $query = $this->doSelect($where, $field, $order);
|
|
|
+ return $this->doFormatForGoods($query, $format, 1000);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 执行真正查询,并返回格式化数据
|
|
|
+ * @param $query
|
|
|
+ * @param $format
|
|
|
+ * @param $limit
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
+ protected function doFormatForGoods($query, $format, $limit): Response
|
|
|
+ {
|
|
|
+ $methods = [
|
|
|
+ 'select' => 'formatSelect',
|
|
|
+ 'tree' => 'formatTree',
|
|
|
+ 'table_tree' => 'formatTableTree',
|
|
|
+ 'normal' => 'formatNormal',
|
|
|
+ ];
|
|
|
+ $paginator = $query->paginate($limit);
|
|
|
+ $total = $paginator->total();
|
|
|
+ $items = $paginator->items();
|
|
|
+ if (method_exists($this, "afterQuery")) {
|
|
|
+ $items = call_user_func([$this, "afterQuery"], $items);
|
|
|
+ }
|
|
|
+ $super = SysCategory::whereIn('category_id', ['31','154','5','181','30','70','42']);
|
|
|
+ $superPaginator = $super->paginate($limit);
|
|
|
+ $superTotal = $superPaginator->total();
|
|
|
+ $superItems = $superPaginator->items();
|
|
|
+
|
|
|
+ $items = array_merge($items,$superItems);
|
|
|
+ $total = $total + $superTotal;
|
|
|
+
|
|
|
+ $format_function = $methods[$format] ?? 'formatNormal';
|
|
|
+ return call_user_func([$this, $format_function], $items, $total);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* @Desc 分类详情
|
|
|
* @Author Gorden
|