|
@@ -1457,62 +1457,60 @@ class NewsService implements NewsServiceInterface
|
|
|
* */
|
|
|
public function getWebsiteshop(array $data): array
|
|
|
{
|
|
|
- $input['id'] = $data['id'];
|
|
|
- $input['website_id'] = $data['website_id'];
|
|
|
- $catid = $data['catid'];
|
|
|
- $data = json_decode($input['id'] ?? '', true) ?? [];
|
|
|
- $result['goods'] = array_map(function ($item) use ($input) {
|
|
|
+ $input['id'] = $data['id'];
|
|
|
+ $input['website_id'] = $data['website_id'];
|
|
|
+ $catid = $data['catid'];
|
|
|
+ $data = json_decode($input['id'] ?? '', true) ?? [];
|
|
|
+ $result['goods'] = array_map(function ($item) use ($input) {
|
|
|
// 检查parent元素是否存在且不是undefined
|
|
|
- if (isset($item['level']) && $item['level'] != 'undefined' && $item['level']!= "") {
|
|
|
- list($Levelid, $goodStart,$goodNum) = explode(',', $item['level']);
|
|
|
- $website = $input['website_id'];
|
|
|
- $query = Good::where('good.status', 2)
|
|
|
- ->where('good.website_id', $website);
|
|
|
- switch ($Levelid) {
|
|
|
- case 1:
|
|
|
- case 2:
|
|
|
- case 3:
|
|
|
- $goods = $query->where(function($q) use ($Levelid) {
|
|
|
- $q->whereRaw("JSON_CONTAINS(good.level, '". intval($Levelid). "') = 0")
|
|
|
- ->orWhereRaw("JSON_CONTAINS(good.level, '\"". intval($Levelid). "\"') = 0");
|
|
|
- });
|
|
|
- break;
|
|
|
- case 4:
|
|
|
- $goods = $query;
|
|
|
- break;
|
|
|
- case 5:
|
|
|
- $goods = $query->where('type_id',1);
|
|
|
- break;
|
|
|
- case 6:
|
|
|
- $goods = $query->where('type_id',2);
|
|
|
-
|
|
|
- break;
|
|
|
- default:
|
|
|
- return [];
|
|
|
- }
|
|
|
- $all_goods = $goods
|
|
|
- ->select('good.id', 'good.name', 'good.imgurl', 'good.description',
|
|
|
- 'good.updated_at', 'good.catid','good.type_id','good.price','good.level',
|
|
|
- 'good.website_id')
|
|
|
- ->orderBy('updated_at','desc')
|
|
|
- ->offset($goodStart)
|
|
|
- ->limit($goodNum)
|
|
|
- ->get();
|
|
|
- $web['website_id'] = $website;
|
|
|
- $all_goods = $this->processGoods($all_goods, $web);
|
|
|
-
|
|
|
- }
|
|
|
- return $all_goods;
|
|
|
- }, $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')
|
|
|
+ if (isset($item['level']) && $item['level'] != 'undefined' && $item['level']!= "") {
|
|
|
+ list($Levelid, $goodStart,$goodNum) = explode(',', $item['level']);
|
|
|
+ $website = $input['website_id'];
|
|
|
+ $query = Good::where('good.status', 2)
|
|
|
+ ->where('good.website_id', $website);
|
|
|
+ switch ($Levelid) {
|
|
|
+ case 1:
|
|
|
+ case 2:
|
|
|
+ case 3:
|
|
|
+ $goods = $query->where(function($q) use ($Levelid) {
|
|
|
+ $q->whereRaw("JSON_CONTAINS(good.level, '". intval($Levelid). "') = 0")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(good.level, '\"". intval($Levelid). "\"') = 0");
|
|
|
+ });
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ $goods = $query;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ $goods = $query->where('type_id',1);
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ $goods = $query->where('type_id',2);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $all_goods = $goods
|
|
|
+ ->select('good.id', 'good.name', 'good.imgurl', 'good.description',
|
|
|
+ 'good.updated_at', 'good.catid','good.type_id','good.price','good.level',
|
|
|
+ 'good.website_id')
|
|
|
+ ->orderBy('updated_at','desc')
|
|
|
+ ->offset($goodStart)
|
|
|
+ ->limit($goodNum)
|
|
|
+ ->get();
|
|
|
+ $web['website_id'] = $website;
|
|
|
+ $all_goods = $this->processGoods($all_goods, $web);
|
|
|
+ }
|
|
|
+ return $all_goods;
|
|
|
+ }, $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();
|
|
@@ -1525,72 +1523,69 @@ class NewsService implements NewsServiceInterface
|
|
|
* */
|
|
|
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 ?? '';
|
|
|
- }
|
|
|
- $goods[0]['pinyin'] = $pinyin;
|
|
|
- }
|
|
|
- $result = [
|
|
|
- 'category' => $cat_tree,
|
|
|
- 'goods' => $goods,
|
|
|
- ];
|
|
|
+ $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 ?? '';
|
|
|
+ }
|
|
|
+ $goods[0]['pinyin'] = $pinyin;
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ 'category' => $cat_tree,
|
|
|
+ 'goods' => $goods,
|
|
|
+ ];
|
|
|
// $resul['goods'] = $goods;
|
|
|
- if(empty($result)){
|
|
|
- return Result::error("查询失败", 0);
|
|
|
- }
|
|
|
- return Result::success($result);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
/*
|
|
|
* 获取商品列表
|