|
@@ -518,14 +518,22 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
|
|
|
$where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
|
|
|
// return Result::success($where);
|
|
|
- $result = AdPlace::where($where)
|
|
|
+ $result = AdPlace::where($where)
|
|
|
->leftJoin("ad", function ($join) use ($now) {
|
|
|
$join->on("ad.pid", "=", "ad_place.id")
|
|
|
->where('ad.status', 1)
|
|
|
->where('ad.fromtime', '<=', $now)
|
|
|
->where('ad.totime', '>=', $now);
|
|
|
})
|
|
|
- ->select("ad_place.*", 'ad.*', "ad_place.id as ad_place_id", "ad.name as ad_name")
|
|
|
+ ->select(
|
|
|
+ 'ad_place.name as place_name',
|
|
|
+ 'ad_place.thumb',
|
|
|
+ 'ad_place.ad_tag',
|
|
|
+ 'ad.name as ad_name',
|
|
|
+ 'ad.image_src',
|
|
|
+ 'ad.image_url',
|
|
|
+ 'ad.image_alt'
|
|
|
+ )
|
|
|
->get()->all();
|
|
|
if (empty($result)) {
|
|
|
return Result::error("此广告位不存在!", 0);
|
|
@@ -2081,59 +2089,59 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
- * 获取父级/子级栏目
|
|
|
+ * 获取父级/子级栏目------路由
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
* */
|
|
|
public function getWebsiteParentCategory(array $data): array
|
|
|
{
|
|
|
+ // return Result::success($data);
|
|
|
if (isset($data['website_id']) && !empty($data['website_id'])) {
|
|
|
$website = Website::where('id', $data['website_id'])->where('status', 1)->first();
|
|
|
}
|
|
|
if (empty($website)) {
|
|
|
return Result::error("暂无该网站", 0);
|
|
|
}
|
|
|
- if ($data['id'] == 0) {
|
|
|
- // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
|
|
|
- // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
- ->where('pid', 0)
|
|
|
- ->select('alias_pinyin', 'category_id', 'alias')
|
|
|
- ->get() // 添加 get() 方法获取结果集合
|
|
|
- ->map(function ($item) {
|
|
|
- return [
|
|
|
- 'path' => "/{$item->alias_pinyin}/",
|
|
|
- 'name' => $item->alias,
|
|
|
- 'cid' => $item->category_id,
|
|
|
- ];
|
|
|
- })
|
|
|
- ->values()
|
|
|
- ->all();
|
|
|
- } else {
|
|
|
- // 不使用 with 方法,直接查询父级栏目需要的字段
|
|
|
- $category = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
- ->where('pid', '!=', 0)
|
|
|
- ->get();
|
|
|
- $category = $category->map(function ($item) {
|
|
|
- $alias = $item->alias;
|
|
|
- $category_id = $item->category_id;
|
|
|
- $alias_pinyin = $item->aLIas_pinyin;
|
|
|
- // 根据 pid 查找父级栏目
|
|
|
- $parent = WebsiteCategory::where('website_id', $item->website_id)
|
|
|
- ->where('category_id', $item->pid)
|
|
|
- ->first();
|
|
|
- $parentAlias = $parent ? $parent->aLIas_pinyin : '';
|
|
|
- return [
|
|
|
- 'path' => "/{$parentAlias}/{$alias_pinyin}/",
|
|
|
- 'name' => $alias ? "{$alias}" : null,
|
|
|
- 'cid' => $category_id ? "{$category_id}" : null,
|
|
|
- ];
|
|
|
- })->values()->all();
|
|
|
- }
|
|
|
+ // 在 Hyperf 中,查询构建器(Builder)没有 `map` 方法,`map` 方法是集合(Collection)的方法。
|
|
|
+ // 因此,需要先调用 `get()` 方法获取查询结果集合,再使用 `map` 方法进行处理。
|
|
|
+ $category['parent'] = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->where('pid', 0)
|
|
|
+ ->selectRaw("category_id as cid, alias as name, CONCAT('/', '', aLIas_pinyin, '/') as path")
|
|
|
+ ->get() // 添加 get() 方法获取结果集合
|
|
|
+ ->all();
|
|
|
+ // 提前查询所有父级栏目,避免在 map 中多次查询
|
|
|
+ // 提前查询所有父级栏目信息并以 category_id 作为键存储
|
|
|
+ $parentCategories = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->where('pid', 0)
|
|
|
+ ->select('category_id', 'aLIas_pinyin')
|
|
|
+ ->get()
|
|
|
+ ->keyBy('category_id');
|
|
|
+
|
|
|
+ // 直接查询子栏目信息
|
|
|
+ $child = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->where('pid', '!=', 0)
|
|
|
+ ->select('alias', 'category_id', 'aLIas_pinyin', 'pid')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ // 使用集合的 map 方法处理子栏目信息
|
|
|
+ $category['child'] = $child->map(function ($item) use ($parentCategories) {
|
|
|
+ $alias = $item->alias;
|
|
|
+ $category_id = $item->category_id;
|
|
|
+ $alias_pinyin = $item->aLIas_pinyin;
|
|
|
+ $parent = $parentCategories->get($item->pid);
|
|
|
+ $parentAlias = $parent ? $parent->aLIas_pinyin : '';
|
|
|
+ $result = [
|
|
|
+ 'name' => $alias,
|
|
|
+ 'cid' => $category_id
|
|
|
+ ];
|
|
|
+ if (!empty($alias_pinyin) && !empty($parentAlias)) {
|
|
|
+ $result['path'] = "/{$parentAlias}/{$alias_pinyin}/";
|
|
|
+ }
|
|
|
+ return $result;
|
|
|
+ })->values()->all();
|
|
|
if (empty($category)) {
|
|
|
return Result::error("暂无此导航", 0);
|
|
|
}
|
|
|
- // $result = [];
|
|
|
return Result::success($category);
|
|
|
}
|
|
|
/**
|
|
@@ -2170,6 +2178,25 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 路由匹配
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getWebsiteRoute(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('id', $data['website_id'])->where('status', 1)->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("暂无该网站", 0);
|
|
|
+ }
|
|
|
+ // return Result::success($data);
|
|
|
+ $result = WebsiteCategory::where('website_id', $data['website_id'])->where('aLIas_pinyin', $data['pinyin'])->first(['category_id']);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无此导航", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result['category_id']);
|
|
|
+ }
|
|
|
+
|
|
|
//20250212 网站标识
|
|
|
public function addWebsiteGroup(array $data): array
|
|
|
{
|