|
@@ -43,6 +43,7 @@ use App\Model\ChatGroupsMember;
|
|
|
use App\Model\ChatRecords;
|
|
|
use App\Model\Complaint;
|
|
|
|
|
|
+use App\Tools\buildMenuTree;
|
|
|
#[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class NewsService implements NewsServiceInterface
|
|
|
{
|
|
@@ -686,7 +687,7 @@ class NewsService implements NewsServiceInterface
|
|
|
// return Result::success($data['website_id']);
|
|
|
$category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
|
|
|
$category = array_values(array_unique($category->toArray()));
|
|
|
- $result = [];
|
|
|
+
|
|
|
if ($category) {
|
|
|
$placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
$where = [
|
|
@@ -705,9 +706,18 @@ class NewsService implements NewsServiceInterface
|
|
|
$whereL7[] = ['keyword', 'like', '%' . $v . '%'];
|
|
|
}
|
|
|
// 原始查询
|
|
|
- $result = Article::where($whereL7)
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pageSize'])
|
|
|
+ $result['level7'] = Article::where($whereL7)
|
|
|
+ ->when(!empty($data['imgnum']), function ($query) use ($data) {
|
|
|
+ $query->where('article.imgurl', '!=', '')
|
|
|
+ ->select('article.*')
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['imgnum']);
|
|
|
+ })
|
|
|
+ ->when(!empty($data['textnum']), function ($query) use ($data) {
|
|
|
+ $query->select('article.*')
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['textnum']);
|
|
|
+ })
|
|
|
->orderBy('updated_at', 'desc')
|
|
|
->get()
|
|
|
->map(function ($article) use ($data) {
|
|
@@ -736,48 +746,104 @@ class NewsService implements NewsServiceInterface
|
|
|
//如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
|
|
|
// 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
|
|
|
var_dump($where, 'where-----------------');
|
|
|
- $result = Article::where($where)
|
|
|
- ->whereIn("catid", $category)
|
|
|
- // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
|
|
|
- // ->where('website_category.website_id', $data['website_id'])
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- //$data['level'] == 4 || $data['level'] == 5 查询随机
|
|
|
- ->when($data['level'] == 5, function ($query) {
|
|
|
- $query->inRandomOrder()
|
|
|
- //updated_at最近三十天;
|
|
|
- ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
|
- })
|
|
|
- ->when($data['level'] == 4, function ($query) {
|
|
|
- $query->orderBy("article.updated_at", "desc");
|
|
|
- })
|
|
|
- ->when(!empty($data['level']), function ($query) use ($data) {
|
|
|
- if ($data['level'] != 4 && $data['level'] != 5) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
- ->orderBy("article.updated_at", "desc");
|
|
|
- }
|
|
|
- })
|
|
|
- ->select('article.*')
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->get()
|
|
|
- ->map(function ($article) use ($data) {
|
|
|
- $catid = $article->catid;
|
|
|
- $pinyin = '';
|
|
|
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
- if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
|
|
|
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
- if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
|
|
|
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
|
|
|
+ // 初始化基础查询
|
|
|
+ $query = Article::where($where)
|
|
|
+ ->whereIn("catid", $category)
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ });
|
|
|
+
|
|
|
+ // 处理 level 相关查询条件
|
|
|
+ $query->when($data['level'] == 5, function ($query) {
|
|
|
+ $query->inRandomOrder()
|
|
|
+ ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
|
|
|
+ })->when($data['level'] == 4, function ($query) {
|
|
|
+ $query->orderBy("article.updated_at", "desc");
|
|
|
+ })->when(!empty($data['level']), function ($query) use ($data) {
|
|
|
+ if ($data['level'] != 4 && $data['level'] != 5) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
|
|
|
+ ->orderBy("article.updated_at", "desc");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 初始化结果数组
|
|
|
+ $result = [];
|
|
|
+ // $input = $data['website_id'];
|
|
|
+ // 处理图片新闻查询
|
|
|
+ if (!empty($data['imgnum'])) {
|
|
|
+ // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
|
|
|
+ // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
|
|
|
+ $imgQuery = clone $query;
|
|
|
+ if ($imgQuery->getBindings() === null) {
|
|
|
+ $imgQuery->setBindings([]);
|
|
|
+ }
|
|
|
+ $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
|
|
|
+ ->select('article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.catid')
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['imgnum'])
|
|
|
+ ->get()
|
|
|
+ ->map(function ($article ) use ($data) {
|
|
|
+ $catid = $article->catid;
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
|
|
|
+ $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
|
|
|
+ $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
}
|
|
|
- } else {
|
|
|
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
- }
|
|
|
- $article->pinyin = $pinyin;
|
|
|
- return $article;
|
|
|
- });
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
+ return $article;
|
|
|
+ });
|
|
|
+ // $result['img'] = $this->processArticles($img_article, $input);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理文字新闻查询
|
|
|
+ if (!empty($data['textnum'])) {
|
|
|
+ $textQuery = clone $query;
|
|
|
+ $result['text'] = $textQuery
|
|
|
+ ->select('article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.catid')
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['textnum'])
|
|
|
+ ->get()
|
|
|
+ ->map(function ($article ) use ($data) {
|
|
|
+ $catid = $article->catid;
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
|
|
|
+ $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
|
|
|
+ $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
+ }
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
+ return $article;
|
|
|
+ });
|
|
|
+ // $result['text'] = $this->processArticles($text_article, $input);
|
|
|
+ }
|
|
|
+
|
|
|
if (empty($result) || count($result) == 0) {
|
|
|
return Result::error("暂无头条新闻");
|
|
|
}
|
|
@@ -863,37 +929,36 @@ class NewsService implements NewsServiceInterface
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- ->where(function ($query) use ($data) {
|
|
|
- $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
|
|
|
- ->orWhereNull("ignore_ids");
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'article.id',
|
|
|
- 'article.title',
|
|
|
- 'article.imgurl',
|
|
|
- 'article.author',
|
|
|
- 'article.updated_at',
|
|
|
- 'article.introduce',
|
|
|
- 'article.islink',
|
|
|
- 'article.linkurl',
|
|
|
- 'article.copyfrom',
|
|
|
- 'article.catid'
|
|
|
- )
|
|
|
- ->orderBy("updated_at", "desc")
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->get()
|
|
|
- ->map(function ($article) use ($data) {
|
|
|
- $catid = $article->catid ?? 0;
|
|
|
- $pinyin = '';
|
|
|
- $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
- $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
- if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
|
|
|
- $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
- $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
|
|
|
- }
|
|
|
- $article->pinyin = $pinyin;
|
|
|
- return $article;
|
|
|
+ ->where(function ($query) use ($data) {
|
|
|
+ $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
|
|
|
+ ->orWhereNull("ignore_ids");
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'article.id',
|
|
|
+ 'article.title',
|
|
|
+ 'article.imgurl',
|
|
|
+ 'article.author',
|
|
|
+ 'article.updated_at',
|
|
|
+ 'article.introduce',
|
|
|
+ 'article.islink',
|
|
|
+ 'article.linkurl',
|
|
|
+ 'article.copyfrom',
|
|
|
+ 'article.catid')
|
|
|
+ ->orderBy("updated_at", "desc")
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get()
|
|
|
+ ->map(function ($article ) use ($data) {
|
|
|
+ $catid = $article->catid ?? 0;
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
|
|
|
+ if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
|
|
|
+ $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
|
|
|
+ $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
|
|
|
+ }
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
+ return $article;
|
|
|
});
|
|
|
|
|
|
$count = Article::where(function ($query) use ($where) {
|
|
@@ -1748,36 +1813,259 @@ class NewsService implements NewsServiceInterface
|
|
|
}, $data);
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ // 封装处理商品的路由问题
|
|
|
+ function processGoods($goods, $data) {
|
|
|
+ return $goods->map(function ($good) use ($data) {
|
|
|
+ $catid = $good->catid ?? 0;
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
|
|
|
+ if (!empty($category->pid) && $category->pid != 0) {
|
|
|
+ $level = json_decode($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 = $category->aLIas_pinyin ?? '';
|
|
|
+ }
|
|
|
+ if(isset($good->city_id) &&!empty($good->city_id)){
|
|
|
+ $city = District::where('id', $good->city_id)->first(['name']);
|
|
|
+ $good->city_name = $city->name ?? '';
|
|
|
+ }
|
|
|
+ // 解析imgurl JSON并取第一条数据
|
|
|
+ $imgUrls = json_decode($good->imgurl, true);
|
|
|
+ $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
|
|
|
+ $good->pinyin = $pinyin;
|
|
|
+ return $good;
|
|
|
+ });
|
|
|
+ }
|
|
|
/**
|
|
|
- *获取头条类新闻模块-合集(暂时用不到)
|
|
|
+ * 获取商品模块
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
- */
|
|
|
- public function getWebsiteAllArticlett(array $data): array
|
|
|
+ * */
|
|
|
+ public function getWebsiteshop(array $data): array
|
|
|
{
|
|
|
$input['id'] = $data['id'];
|
|
|
$input['website_id'] = $data['website_id'];
|
|
|
- $data = json_decode($input['id'], true);
|
|
|
- // 使用 array_map 处理每个元素
|
|
|
+ // return Result::success($input);
|
|
|
+ $data = json_decode($input['id'] ?? '', true) ?? [];
|
|
|
$result = array_map(function ($item) use ($input) {
|
|
|
- list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
|
|
|
- $website = [
|
|
|
- 'website_id' => $input['website_id']
|
|
|
- ];
|
|
|
- $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
|
|
|
- $category = array_values(array_unique($category->toArray()));
|
|
|
- $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
|
|
|
- $where = [
|
|
|
- 'status' => 1,
|
|
|
- ];
|
|
|
-
|
|
|
- return $category;
|
|
|
- }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
|
|
|
-
|
|
|
+ // 检查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();
|
|
|
+ $all_goods = $this->processGoods($all_goods, $input);
|
|
|
+ }
|
|
|
+ return $all_goods;
|
|
|
+ }, $data);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取商品分类
|
|
|
+ * @param array $data
|
|
|
+ * @return 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')
|
|
|
+ ->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(['aLIas_pinyin'])
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ }else{
|
|
|
+ $pinyin = $item->aLIas_pinyin;
|
|
|
+ }
|
|
|
+ $item->aLIas_pinyin = $pinyin;
|
|
|
+ return $item;
|
|
|
+ });
|
|
|
+ $goods = Good::where('website_id', $data['website_id'])
|
|
|
+ ->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();
|
|
|
+ $goods = $this->processGoods($goods, $data);
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error("栏目查询失败", 0);
|
|
|
+ }
|
|
|
+ if(empty($goods)){
|
|
|
+ return Result::error("商品查询失败", 0);
|
|
|
+ }
|
|
|
+ // 调用Tool中的buildMenuTree方法构建菜单树
|
|
|
+ $cat_tree = Result::buildMenuTree($category);
|
|
|
+ $result = [
|
|
|
+ 'category' => $cat_tree,
|
|
|
+ 'goods' => $goods,
|
|
|
+ ];
|
|
|
+ // $resul['goods'] = $goods;
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /*
|
|
|
+ * 获取商品列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function getWebsiteshopList(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $where = [
|
|
|
+ 'status' => 2,
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ if((empty($data['catid']) ||!isset($data['catid'])) && (empty($data['keyword']) ||!isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
|
|
|
+ $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid',$data['id'])->orderBy('sort')->first(['category_id']);
|
|
|
+ $data['catid'] = $category->category_id ?? 0;
|
|
|
+ }
|
|
|
+ if(isset($data['keyword']) &&!empty($data['keyword'])){
|
|
|
+ array_push($where, ['name', 'like', '%'. $data['keyword'].'%']);
|
|
|
+ }
|
|
|
+ if(isset($data['type_id']) && !empty($data['type_id'])){
|
|
|
+ array_push($where, ['type_id', $data['type_id']]);
|
|
|
+ }
|
|
|
+ $query = Good::where($where)
|
|
|
+ ->when(isset($data['catid']) &&!empty($data['catid']), function ($query) use ($data) {
|
|
|
+ $query->where(function($q) use ($data) {
|
|
|
+ $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '". intval($data['catid']). "') = 1")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"". intval($data['catid']). "\"') = 1");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
|
|
|
+ $query->where(function($q) use ($data) {
|
|
|
+ $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '". intval($data['city_id']). "') = 1")
|
|
|
+ ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"". intval($data['city_id']). "\"') = 1");
|
|
|
+ });
|
|
|
+ })
|
|
|
+ ->select('good.id', 'good.name', 'good.imgurl', 'good.description', 'good.updated_at',
|
|
|
+ 'good.catid','good.type_id','good.website_id','good.cat_arr_id','good.created_at','good.city_id')
|
|
|
+ ->latest('updated_at');
|
|
|
+ // 获取 type_id 为 1 的数据
|
|
|
+ $result['type1'] = $this->processGoods(
|
|
|
+ $query->clone()
|
|
|
+ ->where('type_id', 1)
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ // 获取 type_id 为 2 的数据
|
|
|
+ $result['type2'] = $this->processGoods(
|
|
|
+ $query->clone()
|
|
|
+ ->where('type_id', 2)
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get(),
|
|
|
+ $data
|
|
|
+ );
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取商品详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ * */
|
|
|
+ public function getWebsiteshopInfo(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'good.status' => 2,
|
|
|
+ 'good.website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ $goods = Good::where($where)
|
|
|
+ ->where('good.id', $data['id'])
|
|
|
+ ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
|
|
|
+ ->select('good.*','website_category.alias','website_category.category_id')
|
|
|
+ ->first();
|
|
|
+ if(empty($goods)){
|
|
|
+ return Result::error("查询失败", 0);
|
|
|
+ }
|
|
|
+ $goods->imgurl = json_decode($goods->imgurl, true);
|
|
|
+ return Result::success($goods);
|
|
|
+ }
|
|
|
/**
|
|
|
+ * 封装处理文章的路由问题
|
|
|
+ * */
|
|
|
+ function processArticles($articles, $data) {
|
|
|
+ if (!is_array($data)) {
|
|
|
+ // 可以根据实际情况进行日志记录或抛出异常
|
|
|
+ // 这里简单输出错误信息
|
|
|
+ echo "Error: \$data is not an array in processArticles. It is of type ". gettype($data). PHP_EOL;
|
|
|
+ return $articles;
|
|
|
+ }
|
|
|
+ return $articles->map(function ($article) use ($data) {
|
|
|
+ $catid = $article->cat_arr_id?? '';
|
|
|
+ $level = json_decode($catid, true);
|
|
|
+ $pinyin = '';
|
|
|
+ $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
|
|
|
+ if (!empty($category->pid) && $category->pid!= 0) {
|
|
|
+ $pinyin = WebsiteCategory::whereIn('category_id', $level)
|
|
|
+ ->orderByRaw('FIELD(category_id, '. implode(',', $level). ')')
|
|
|
+ ->get(['aLIas_pinyin'])
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ } else {
|
|
|
+ $pinyin = $category->aLIas_pinyin ?? '';
|
|
|
+ }
|
|
|
+ $article->pinyin = $pinyin;
|
|
|
+ return $article;
|
|
|
+ });
|
|
|
+ } /**
|
|
|
* 验证导航名称是否重复
|
|
|
* @return void
|
|
|
*/
|