|
@@ -544,23 +544,23 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
|
|
|
|
$depart = Department::where('pid',0)->orderBy('id','asc')->get();
|
|
|
- // if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
- // $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
|
|
|
- // if(empty($departments)){
|
|
|
- // $result['message']="未查询到与此相关职能部门";
|
|
|
- // }else{
|
|
|
- // $count = Department::where('name','like',"%{$data['keyword']}%")->count();
|
|
|
- // $m = [
|
|
|
- // 'department'=>$depart,
|
|
|
- // 'type'=>$departments,
|
|
|
- // 'count'=>$count
|
|
|
- // ];
|
|
|
- // }
|
|
|
+ if(isset($data['keyword']) && !empty($data['keyword'])){
|
|
|
+ $departments= Department::where('name', 'like', '%' . $data['keyword'] . '%')->get();
|
|
|
+ if(empty($departments)){
|
|
|
+ $result['message']="未查询到与此相关职能部门";
|
|
|
+ }else{
|
|
|
+ $count = Department::where('name','like',"%{$data['keyword']}%")->count();
|
|
|
+ $m = [
|
|
|
+ 'department'=>$depart,
|
|
|
+ 'type'=>$departments,
|
|
|
+ 'count'=>$count
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
- // $result['sele'] = $m;
|
|
|
- // return Result::success($result['sele']);
|
|
|
+ $result['sele'] = $m;
|
|
|
+ return Result::success($result['sele']);
|
|
|
|
|
|
- // }
|
|
|
+ }
|
|
|
$result=$depart;
|
|
|
return Result::success($result);
|
|
|
}
|
|
@@ -627,46 +627,42 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
|
|
|
public function getWebsiteModelCategory(array $data): array
|
|
|
{
|
|
|
- $website_id = [
|
|
|
- 'website_category.website_id' => $data['website_id'],
|
|
|
- ];
|
|
|
- $placeid = $data['placeid'] - 1;
|
|
|
- $pid = [
|
|
|
- 'website_category.pid' => $data['pid'],
|
|
|
- ];
|
|
|
- var_dump("=======", $pid);
|
|
|
- $num = $data['num'];
|
|
|
// return Result::success($data);
|
|
|
- $result = WebsiteCategory::where($website_id)
|
|
|
- ->leftJoin("category", 'website_category.category_id', 'category.id')
|
|
|
- ->select('website_category.*', 'category.is_url', 'category.web_url')
|
|
|
- ->where($pid)
|
|
|
- // ->with(['children' => function ($query) use ($data) {
|
|
|
- // $query->where('website_category.website_id', $data['website_id']);
|
|
|
- // }])
|
|
|
- ->orderBy('website_category.sort')
|
|
|
-
|
|
|
- ->offset($placeid)
|
|
|
- ->limit($num)
|
|
|
- ->get();
|
|
|
- foreach ($result as $k => $v) {
|
|
|
- $child[$k]['children_countent'] = WebsiteCategory::where($website_id)
|
|
|
- ->where('website_category.pid', $v['category_id'])
|
|
|
- ->count();
|
|
|
- if (!empty($child[$k]['children_countent'])) {
|
|
|
- $result[$k]['children_count'] = $child[$k]['children_countent'];
|
|
|
- } else {
|
|
|
- $result[$k]['children_count'] = 0;
|
|
|
- }
|
|
|
+ $website_id=[
|
|
|
+ 'website_id' => $data['website_id']
|
|
|
+ ];
|
|
|
+ // 初始化 $pid 数组
|
|
|
+ // $pid = [];
|
|
|
+ // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
|
|
|
+ $pid = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', '!=', 0)
|
|
|
+ ->pluck('pid');
|
|
|
+ $pid = array_values(array_unique($pid->toArray()));
|
|
|
+
|
|
|
+ // 构建查询语句
|
|
|
+ $query = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', $data['pid'])
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['num'])
|
|
|
+ ->orderBy('sort');
|
|
|
+
|
|
|
+ // 如果 $pid 数组不为空,添加 CASE WHEN 条件
|
|
|
+ if (!empty($pid)) {
|
|
|
+ $placeholders = implode(',', array_fill(0, count($pid), '?'));
|
|
|
+ $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
|
|
|
+ } else {
|
|
|
+ // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
|
|
|
+ $query->select('website_category.*', DB::raw('0 as children_count'));
|
|
|
}
|
|
|
- // return Result::success($result);
|
|
|
+
|
|
|
+ // 执行查询
|
|
|
+ $result = $query->get();
|
|
|
if(!empty($result)){
|
|
|
return Result::success($result);
|
|
|
}else{
|
|
|
return Result::error("本网站暂无栏目",0);
|
|
|
}
|
|
|
-
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取友情链接
|
|
@@ -1519,16 +1515,15 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
if (empty($website)) {
|
|
|
return Result::error("暂无该网站", 0);
|
|
|
}
|
|
|
- $result = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['category_id'])->select('category_id', 'alias')->first();
|
|
|
- // return Result::success($category);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("暂无此导航", 0);
|
|
|
+ $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['category_id'])->first();
|
|
|
+ if (empty($category)) {
|
|
|
+ return Result::error("暂无此导航",0);
|
|
|
}
|
|
|
- // department_id
|
|
|
- } else {
|
|
|
- return Result::error("参数错误", 0);
|
|
|
+ $category['children_count'] = WebsiteCategory::where('website_id',$data['website_id'])->where('pid',$data['category_id'])->count();
|
|
|
+ return Result::success($category);
|
|
|
+ }else{
|
|
|
+ return Result::error("参数错误",0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
}
|
|
|
|
|
|
//20250212 网站标识
|