|
@@ -1919,9 +1919,9 @@ class NewsService implements NewsServiceInterface
|
|
{
|
|
{
|
|
$input['id'] = $data['id'];
|
|
$input['id'] = $data['id'];
|
|
$input['website_id'] = $data['website_id'];
|
|
$input['website_id'] = $data['website_id'];
|
|
- // return Result::success($input);
|
|
|
|
|
|
+ $catid = $data['catid'];
|
|
$data = json_decode($input['id'] ?? '', true) ?? [];
|
|
$data = json_decode($input['id'] ?? '', true) ?? [];
|
|
- $result = array_map(function ($item) use ($input) {
|
|
|
|
|
|
+ $result['goods'] = array_map(function ($item) use ($input) {
|
|
// 检查parent元素是否存在且不是undefined
|
|
// 检查parent元素是否存在且不是undefined
|
|
if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
|
|
if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
|
|
list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
|
|
list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
|
|
@@ -1967,10 +1967,23 @@ class NewsService implements NewsServiceInterface
|
|
->offset($goodStart)
|
|
->offset($goodStart)
|
|
->limit($goodNum)
|
|
->limit($goodNum)
|
|
->get();
|
|
->get();
|
|
- $all_goods = $this->processGoods($all_goods, $input);
|
|
|
|
|
|
+ $all_goods = $this->processGoods($all_goods, $website);
|
|
|
|
+
|
|
}
|
|
}
|
|
return $all_goods;
|
|
return $all_goods;
|
|
}, $data);
|
|
}, $data);
|
|
|
|
+ $website = $input['website_id'];
|
|
|
|
+ $result['article'] = Article::where(function ($query) use ($website) {
|
|
|
|
+ $query->where(function ($subQuery) use ($website) {
|
|
|
|
+ $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
|
|
|
|
+ })->orWhereNull("ignore_ids");
|
|
|
|
+ })
|
|
|
|
+ ->where('catid', $catid)
|
|
|
|
+ ->where('article.status', 1)
|
|
|
|
+ ->leftJoin('article_data', 'article_data.article_id', 'article.catid')
|
|
|
|
+ ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl','article_data.content')
|
|
|
|
+ ->orderBy('article.updated_at', 'desc')
|
|
|
|
+ ->first();
|
|
return Result::success($result);
|
|
return Result::success($result);
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -1980,43 +1993,61 @@ class NewsService implements NewsServiceInterface
|
|
* */
|
|
* */
|
|
public function getWebsiteshopCat(array $data): array
|
|
public function getWebsiteshopCat(array $data): array
|
|
{
|
|
{
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
|
- ->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')
|
|
|
|
|
|
+ $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')
|
|
->orderBy('sort')
|
|
- ->get()
|
|
|
|
- ->map(function ($item) use ($data) {
|
|
|
|
- $pinyin = [];
|
|
|
|
- $level = json_decode($item->category_arr_id);
|
|
|
|
- // 递归获取所有父级栏目的拼音
|
|
|
|
- if ($item->pid != 0) {
|
|
|
|
- $pinyin = WebsiteCategory::whereIn('category_id', $level)
|
|
|
|
- ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
|
|
|
|
|
|
+ ->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'])
|
|
->get(['aLIas_pinyin'])
|
|
->pluck('aLIas_pinyin')
|
|
->pluck('aLIas_pinyin')
|
|
->implode('/');
|
|
->implode('/');
|
|
- } else {
|
|
|
|
- $pinyin = $item->aLIas_pinyin;
|
|
|
|
|
|
+ }else{
|
|
|
|
+ $pinyin = $item->aLIas_pinyin ?? '';
|
|
}
|
|
}
|
|
- $item->aLIas_pinyin = $pinyin;
|
|
|
|
- return $item;
|
|
|
|
- });
|
|
|
|
- $goods = Good::where('website_id', $data['website_id'])
|
|
|
|
|
|
+ $item->pinyin = $pinyin;
|
|
|
|
+ })
|
|
|
|
+ ;
|
|
|
|
+ if(empty($category)){
|
|
|
|
+ return Result::error("栏目查询失败", 0);
|
|
|
|
+ }
|
|
|
|
+ // $cat_tree = $this->processGoods($cat, $website);
|
|
|
|
+ $goods = Good::where('website_id', $website)
|
|
->where('status', 2)
|
|
->where('status', 2)
|
|
->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
|
|
->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
|
|
->latest('updated_at')
|
|
->latest('updated_at')
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
->offset(($data['page'] - 1) * $data['pageSize'])
|
|
->limit($data['pageSize'])
|
|
->limit($data['pageSize'])
|
|
->get();
|
|
->get();
|
|
- $goods = $this->processGoods($goods, $data);
|
|
|
|
- if (empty($category)) {
|
|
|
|
- return Result::error("栏目查询失败", 0);
|
|
|
|
- }
|
|
|
|
- if (empty($goods)) {
|
|
|
|
|
|
+ if($goods->isEmpty()){
|
|
return Result::error("商品查询失败", 0);
|
|
return Result::error("商品查询失败", 0);
|
|
}
|
|
}
|
|
- // 调用Tool中的buildMenuTree方法构建菜单树
|
|
|
|
|
|
+ if(count($goods) > 1){
|
|
|
|
+ $goods = $this->processGoods($goods, $website);
|
|
|
|
+ }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 ?? '';
|
|
|
|
+ }
|
|
|
|
+ $goods[0]['pinyin'] = $pinyin;
|
|
|
|
+ }
|
|
$cat_tree = Result::buildMenuTree($category);
|
|
$cat_tree = Result::buildMenuTree($category);
|
|
$result = [
|
|
$result = [
|
|
'category' => $cat_tree,
|
|
'category' => $cat_tree,
|