|
@@ -1898,66 +1898,52 @@ class NewsService implements NewsServiceInterface
|
|
* */
|
|
* */
|
|
public function getWebsiteshopCat(array $data): array
|
|
public function getWebsiteshopCat(array $data): array
|
|
{
|
|
{
|
|
- $website = $data['website_id'];
|
|
|
|
- $category = WebsiteCategory::where('website_id', $website)
|
|
|
|
- ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
|
|
|
|
- ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
|
|
|
|
- ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id')
|
|
|
|
- ->orderBy('sort')
|
|
|
|
- ->get();
|
|
|
|
-
|
|
|
|
- $cat = $category->map(function ($item) use ($website) {
|
|
|
|
- $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
|
|
|
|
- $pid = $item->pid ?? 0;
|
|
|
|
- if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
|
|
|
|
- $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
|
|
|
|
- ->where('website_id', $website)
|
|
|
|
- ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
|
|
|
|
- ->get(['aLIas_pinyin'])
|
|
|
|
- ->pluck('aLIas_pinyin')
|
|
|
|
- ->implode('/');
|
|
|
|
- } else {
|
|
|
|
- $pinyin = $item->aLIas_pinyin ?? '';
|
|
|
|
- }
|
|
|
|
- $item->pinyin = $pinyin;
|
|
|
|
- });
|
|
|
|
- if (empty($category)) {
|
|
|
|
- return Result::error("栏目查询失败", 0);
|
|
|
|
- }
|
|
|
|
- $cat_tree = Result::buildMenuTree($category);
|
|
|
|
- $web['website_id'] = $website;
|
|
|
|
- $goods = Good::where('website_id', $website)
|
|
|
|
- ->where('status', 2)
|
|
|
|
- ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
|
|
|
|
- ->latest('updated_at')
|
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
|
- ->limit($data['pageSize'])
|
|
|
|
- ->get();
|
|
|
|
-
|
|
|
|
- if ($goods->isEmpty()) {
|
|
|
|
- return Result::error("商品查询失败", 0);
|
|
|
|
- }
|
|
|
|
- if ($goods->count() > 1) {
|
|
|
|
- $goods = $this->processGoods($goods, $web);
|
|
|
|
- } else {
|
|
|
|
- $catid = $goods[0]['catid'] ?? 0;
|
|
|
|
- $good_category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
|
|
|
|
- if (!empty($good_category->pid) && $good_category->pid != 0) {
|
|
|
|
- $level = json_decode($good_category->category_arr_id);
|
|
|
|
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
|
|
|
|
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
|
|
|
|
- ->get(['aLIas_pinyin'])
|
|
|
|
- ->pluck('aLIas_pinyin')
|
|
|
|
- ->implode('/');
|
|
|
|
- } else {
|
|
|
|
- $pinyin = $good_category->aLIas_pinyin ?? '';
|
|
|
|
|
|
+ $website = $data['website_id'];
|
|
|
|
+ $category = WebsiteCategory::where('website_id', $website)
|
|
|
|
+ ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
|
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
|
|
|
|
+ ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id')
|
|
|
|
+ ->orderBy('sort')
|
|
|
|
+ ->get();
|
|
|
|
+ $cat = $category->map(function ($item) use ($website) {
|
|
|
|
+ $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
|
|
|
|
+ $pid = $item->pid?? 0;
|
|
|
|
+ if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
|
|
|
|
+ $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
|
|
|
|
+ ->where('website_id', $website)
|
|
|
|
+ ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
|
|
|
|
+ ->get(['aLIas_pinyin'])
|
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
|
+ ->implode('/');
|
|
|
|
+ }else{
|
|
|
|
+ $pinyin = $item->aLIas_pinyin ?? '';
|
|
|
|
+ }
|
|
|
|
+ $item->pinyin = $pinyin;
|
|
|
|
+ });
|
|
|
|
+ if(empty($category)){
|
|
|
|
+ return Result::error("栏目查询失败", 0);
|
|
|
|
+ }
|
|
|
|
+ $cat_tree = Result::buildMenuTree($category);
|
|
|
|
+ $web['website_id'] = $website;
|
|
|
|
+ $goods = Good::where('website_id', $website)
|
|
|
|
+ ->where('status', 2)
|
|
|
|
+ ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
|
|
|
|
+ ->latest('updated_at')
|
|
|
|
+ ->offset(($data['page']-1)*$data['pageSize'])
|
|
|
|
+ ->limit($data['pageSize'])
|
|
|
|
+ ->get();
|
|
|
|
+ if(!empty($goods)){
|
|
|
|
+ if($goods->count() > 1 && !empty($goods)){
|
|
|
|
+ $goods = $this->processGoods($goods, $web);
|
|
}
|
|
}
|
|
- $goods[0]['pinyin'] = $pinyin;
|
|
|
|
|
|
+ }else{
|
|
|
|
+ $goods = [];
|
|
}
|
|
}
|
|
- $result = [
|
|
|
|
- 'category' => $cat_tree,
|
|
|
|
- 'goods' => $goods,
|
|
|
|
- ];
|
|
|
|
|
|
+
|
|
|
|
+ $result = [
|
|
|
|
+ 'category' => $cat_tree,
|
|
|
|
+ 'goods' => $goods,
|
|
|
|
+ ];
|
|
// $resul['goods'] = $goods;
|
|
// $resul['goods'] = $goods;
|
|
if (empty($result)) {
|
|
if (empty($result)) {
|
|
return Result::error("查询失败", 0);
|
|
return Result::error("查询失败", 0);
|