limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("code", "asc")->get(); $count = District::where($where)->count(); $result = [ 'rows' => $rep, 'count' => $count ]; } else { $result = District::where($data)->orderBy("code", "asc")->get(); } return $result ? Result::success($result) : Result::error("没有查到数据"); } /** * @param array $data * @return array */ public function getUserLevelList(array $data): array { $where = []; if (isset($data['keyWord'])) { $where = [ ['name', 'like', '%' . $data['keyWord'] . '%'], ]; } $result = []; if (isset($data['pageSize'])) { $rep = UserLevel::where($where)->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("id", "asc")->get(); $count = UserLevel::where($where)->count(); $result = [ 'rows' => $rep, 'count' => $count, ]; } else { $result = UserLevel::orderBy("id", "asc")->get(); } return $result ? Result::success($result) : Result::error("没有查到数据"); } /** * 添加用户等级 * @param array $data * @return array */ public function addUserLevel(array $data): array { LevelUser::insertGetId($data); return Result::success([]); } /** * 更新等级 * @param array $data * @return array */ public function updateUserLevel(array $data): array { $result = LevelUser::where(['id' => $data['id']])->update($data); if ($result) { return Result::success($result); } return Result::error("更新失败"); } /** * 删除等级 * @param array $data * @return array */ public function delUserLevel(array $data): array { $result = LevelUser::where(['id' => $data['id']])->delete(); if ($result) { return Result::success($result); } return Result::error("删除失败"); } /** * 查询投诉举报信息 * @param array $data * @return array */ public function getLetterOfComplaint(array $data = []): array { var_dump("===="); $where = []; if (isset($data['user_id']) && !empty($data['user_id'])) { array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]); } if (isset($data['nature']) && !empty($data['nature'])) { array_push($where, ['letter_of_complaint.nature', '=', $data['nature']]); } if (isset($data['nature_level0']) && !empty($data['nature_level0'])) { array_push($where, ['letter_of_complaint.nature_level0', '=', $data['nature_level0']]); } if (isset($data['status']) && !empty($data['status'])) { array_push($where, ['letter_of_complaint.status', '=', $data['status']]); } $result = []; if (isset($data['pageSize'])) { $rep = LetterOfComplaint::where($where) ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id") ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id") ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id") ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id") ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id") ->select( "letter_of_complaint.*", "type_a.type_name as nature_name", "type_b.type_name as nature_name1", "type_c.type_name as nature_name0", "type_d.type_name as status_name", "type_e.type_name as nature_name3" ) ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("letter_of_complaint.id", "desc")->get(); $count = LetterOfComplaint::where($where)->count(); if ($rep) { foreach ($rep as $val) { if ($val['judgment']) { $val['judgment'] = json_decode($val['judgment']); } if ($val['audio_and_video']) { $val['audio_and_video'] = json_decode($val['audio_and_video']); } if ($val['contract']) { $val['contract'] = json_decode($val['contract']); } if ($val['qualifications']) { $val['qualifications'] = json_decode($val['qualifications']); } } } $result = [ 'rows' => $rep, 'count' => $count, ]; } else { $result = LetterOfComplaint::where($where) ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id") ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id") ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id") ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id") ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id") ->select( "letter_of_complaint.*", "type_a.type_name as nature_name", "type_b.type_name as nature_name1", "type_c.type_name as nature_name0", "type_d.type_name as status_name", "type_e.type_name as nature_name3" ) ->orderBy("letter_of_complaint.id", "desc")->get(); } return $result ? Result::success($result) : Result::error("没有查到数据"); } /** * 添加投诉举报信息 * @param array $data * @return array */ public function addLetterOfComplaint(array $data): array { $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : ''; $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : ''; $data['contract'] = $data['contract'] ? json_encode($data['contract']) : ''; $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : ''; unset($data['id']); $result = LetterOfComplaint::insertGetId($data); if (empty($result)) { return Result::error("创建失败", 0); } else { return Result::success(["id" => $result]); } } /** * 用户端更新投诉举报 * @param array $data * @return array */ public function userUpLetterOfComplaint(array $data): array { $data['judgment'] = $data['judgment'] ? json_encode($data['judgment']) : ''; $data['audio_and_video'] = $data['audio_and_video'] ? json_encode($data['audio_and_video']) : ''; $data['contract'] = $data['contract'] ? json_encode($data['contract']) : ''; $data['qualifications'] = $data['qualifications'] ? json_encode($data['qualifications']) : ''; $result = LetterOfComplaint::where(['id' => $data['id']])->update($data); if (empty($result)) { return Result::error("创建失败", 0); } else { return Result::success(["id" => $result]); } } /** * 管理后台更新投诉举报信息 * @param array $data * @return array */ public function upLetterOfComplaint(array $data): array { var_dump("admin:", $data); $where = [ 'id' => $data['id'], ]; $filtered_array = array_filter($data, function ($value) { return $value !== "" && $value !== null && $value !== false && !is_array($value) || !empty($value); }); $filtered_array['judgment'] = isset($filtered_array['judgment']) ? json_encode($filtered_array['judgment']) : ''; $filtered_array['audio_and_video'] = isset($filtered_array['audio_and_video']) ? json_encode($filtered_array['audio_and_video']) : ''; $filtered_array['contract'] = isset($filtered_array['contract']) ? json_encode($filtered_array['contract']) : ''; $filtered_array['qualifications'] = isset($filtered_array['qualifications']) ? json_encode($filtered_array['qualifications']) : ''; unset($filtered_array['nature_name']); unset($filtered_array['type_name']); unset($filtered_array['nature_level_name']); unset($filtered_array['status_name']); unset($filtered_array['is_admin']); unset($filtered_array['type_level_name']); $result = LetterOfComplaint::where($where)->update($filtered_array); if ($result) { return Result::success($result); } return Result::error("更新失败", 0); } /** * 查询投诉举报记录 * @param array $data * @return array */ public function getLetterOfComplaintInfo(array $data): array { $where = [ 'letter_of_complaint.id' => $data['id'], ]; if (isset($data['user_id']) && !empty($data['user_id'])) { array_push($where, ['letter_of_complaint.user_id', '=', $data['user_id']]); } $result = LetterOfComplaint::where($where) ->leftJoin("letter_type as type_a", "letter_of_complaint.nature", "type_a.id") ->leftJoin("letter_type as type_c", "letter_of_complaint.nature_level0", "type_c.id") ->leftJoin("letter_type as type_b", "letter_of_complaint.nature_level1", "type_b.id") ->leftJoin("letter_type as type_e", "letter_of_complaint.nature_level3", "type_e.id") ->leftJoin("letter_type as type_d", "letter_of_complaint.status", "type_d.id") ->select( "letter_of_complaint.*", "type_a.type_name as nature_name", "type_b.type_name as nature_name1", "type_c.type_name as nature_name0", "type_d.type_name as status_name", "type_e.type_name as nature_name3" ) ->first(); return Result::success($result); } /** * 删除投诉举报信息 * @param array $data * @return array */ public function delLetterOfComplaint(array $data): array { $result = LetterOfComplaint::when($data, function ($query) use ($data) { if (isset($data['id']) && !empty($data['id'])) { $query->where(['id' => $data['id']]); } if (isset($data['user_id']) && !empty($data['user_id'])) { $query->where(['user_id' => $data['user_id']]); } })->delete(); if (empty($result)) { return Result::error("删除失败", 0); } else { return Result::success(); } } /** * 获取举报信息类型 * @param array $data * @return array */ public function getLetterType(array $data): array { $where = []; if (isset($data['type'])) { array_push($where, ['type', '=', $data['type']]); } if (isset($data['pid']) && $data['pid'] > 0) { array_push($where, ['pid', '=', $data['pid']]); } $result = LetterType::where($where)->orderBy('sort', 'asc')->get(); return $result ? Result::success($result) : Result::error("没有查到数据"); } /** * 更新举报类型 * @param array $data * @return array */ public function upLetterType(array $data): array { return []; } /** * 添加举报类型 * @param array $data * @return array */ public function addLetterType(array $data): array { $result = LetterType::insertGetId($data); if (empty($result)) { return Result::error("创建失败", 0); } else { return Result::success(["id" => $result]); } } /** * 删除举报类型 * @param array $data * @return array */ public function delLetterType(array $data): array { $result = LetterType::where('id', $data['id'])->delete(); if (empty($result)) { return Result::error("删除失败", 0); } else { return Result::success(); } } /** * 检测是否已经被接案 * @param array $data * @return array */ public function checkMeasure(array $data): array { $where = [ 'id' => $data['id'], ]; $letterOfComplaintInfo = LetterOfComplaint::where($where)->first(); var_dump("查询数据:", $letterOfComplaintInfo['admin_id'], $data['user_id']); //操作人和当前登陆用户id 相等说明是当前人接收的案件 if (($letterOfComplaintInfo['admin_id'] == $data['user_id']) || empty($letterOfComplaintInfo['admin_id'])) { return Result::success(); } else { return Result::error("您不能处理其他人已经接过的案件", 0); } } /** * 后台获取职能部门 * @param array $data * @return array */ public function getZhinengbumenList(array $data): array { // 获取分页参数,默认每页 10 条记录 $page = isset($data['page']) ? (int) $data['page'] : 1; $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10; // 查询数据并分页 $query = Department::query(); // 可以在这里添加更多的查询条件 if (isset($data['search'])) { $query->where('name', 'like', '%' . $data['search'] . '%'); } // 执行分页查询 $result = $query->paginate($perPage, ['*'], 'page', $page); // 返回分页结果 return Result::success([ 'count' => $result->total(), 'current_page' => $result->currentPage(), 'last_page' => $result->lastPage(), 'pagesize' => $result->perPage(), 'rows' => $result->items(), ]); } /** * 添加获取职能部门 * @param array $data * @return array */ public function addZhinengbumen(array $data): array { $result = Department::insertGetId($data); if (empty($result)) { return Result::error("创建失败", 0); } else { return Result::success(["id" => $result]); } } public function delZhinengbumen(array $data): array { $result = Department::where('id', $data['id'])->delete(); if (empty($result)) { return Result::error("删除失败", 0); } else { return Result::success(); } } public function getZhinengbumen(array $data): array { $result = Department::where('id', $data['id'])->first(); return Result::success($result); } public function getPidZhinengbumen(array $data): array { if (empty($data['pid'])) { $data['pid'] = 0; } $result = Department::where('pid', $data['pid'])->get(); return Result::success($result); } public function modZhinengbumen(array $data): array { $result = Department::where('id', $data['id'])->update($data); if (empty($result)) { return Result::error("修改失败", 0); } else { return Result::success(); } } /** * 查询职能列表 * @param array $data * @return array */ public function getDepartment(array $data): array { $where = []; if (isset($data['pid'])) { $where = [ 'pid' => $data['pid'] ?? 0 ]; } $result = Department::when(!empty($where), function ($query) use ($where) { $query->where($where); })->orderBy("sort", "desc")->get(); if (empty($result)) { return Result::error("查询失败", 0); } else { return Result::success($result); } } /** * 获取所有的buckets * @param array $data * @return array */ public function getBuckets(array $data): array { $result = new MinioService(); // 调用服务层的方法获取存储桶列表 $bucketsResponse = $result->listBuckets(); // 直接返回服务层生成的响应 return Result::success($bucketsResponse['data']); } /** * 上传文件 * @param array $data * @return array */ public function uploadFile(array $data): array { $result = new MinioService(); $rep = $result->uploadFile($data); if ($rep['code'] == 200) { return Result::success($rep['data']); } else { return Result::error("上传失败!"); } } /** * 黑名单管理 * @param array $data * @return array */ public function getBlackWordList(array $data): array { $result = BlackWord::when($data, function ($query) use ($data) { if (isset($data['name']) && $data['name']) { $query->where('black_word.name', 'like', '%' . $data['name'] . '%'); } })->orderBy('black_word.id', 'desc') ->paginate( intval($data['pageSize']), [ 'black_word.*', ], 'page', intval($data['page']) ); $count = $result->total(); $returnData = [ 'rows' => $result->items(), 'count' => $count ]; return Result::success($returnData); } /** * 添加黑名单 * @param array $data * @return array */ public function addBlackWord(array $data): array { Db::beginTransaction(); try { $info = BlackWord::where(['name' => $data['name']])->first(); if ($info) { Db::rollBack(); return Result::error("该黑名单已存在", 0); } $data['type'] = 10; $result = BlackWord::insertGetId($data); $redisKey = 'black_word'; $this->redis->sAdd($redisKey, $data['name']); Db::commit(); return Result::success(["id" => $result]); } catch (\Exception $e) { Db::rollBack(); return Result::error("创建失败" . $e->getMessage(), 0); } } /** * 删除黑名单 * @param array $data * @return array */ public function delBlackWord(array $data): array { Db::beginTransaction(); try { BlackWord::where(['name' => $data['name']])->delete(); $redisKey = 'black_word'; $this->redis->sRem($redisKey, $data['name']); Db::commit(); return Result::success([]); } catch (\Exception $e) { Db::rollBack(); return Result::error("删除失败" . $e->getMessage(), 0); } } /** * 修改违禁词 * @param array $data * @return array */ public function upBlackWord(array $data): array { Db::beginTransaction(); try { $checkInfo = BlackWord::where(['name' => $data['name']])->first(); if ($checkInfo) { Db::rollBack(); return Result::error("该违禁词已经存在", 0); } $blackWordInfo = BlackWord::where(['id' => $data['id']])->first(); if ($blackWordInfo) { //先删除redis $blackWordInfo = $blackWordInfo->toArray(); $redisKey = 'black_word'; $this->redis->sRem($redisKey, $blackWordInfo['name']); $this->redis->sAdd($redisKey, $data['name']); BlackWord::where(['id' => $data['id']])->update(['name' => $data['name']]); Db::commit(); return Result::success([]); } else { Db::rollBack(); return Result::error("系统错误", 0); } } catch (\Exception $e) { Db::rollBack(); return Result::error("修改失败" . $e->getMessage(), 0); } } /** * 获取风格 * @return void */ public function getTemplateClassList(array $data): array { $where = []; if (isset($data['name']) && $data['name']) { array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']); } if(isset($data['keyword']) && $data['keyword']){ array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']); } $template = TemplateClass::when($where, function ($query) use ($where) { $query->where($where); }); $count = $template->count(); // $countQuery = clone $template; $row = $template ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id') ->select('template_class.*', DB::raw('COUNT(template.id) as template_count')) ->groupBy('template_class.id') ->orderBy('template_class.id', 'desc') ->offset(($data['page'] - 1) * $data['pageSize']) ->limit($data['pageSize']) ->get(); $result = [ 'rows' => $row, 'count' => $count, ]; if ($row->isEmpty()) { return Result::error("暂无风格", 0); } else { return Result::success($result); } } /** * 添加风格 * @param * @return void */ public function addTemplateClass(array $data): array { $data['keyword'] = json_encode($data['keyword']); $template_class = TemplateClass::where('name', $data['name']) ->orWhere('class_id', $data['class_id']) ->first(); if ($template_class) { return Result::error("风格名称或者风格编号已存在,不可添加!", 0); } $result = TemplateClass::insertGetId($data); if (empty($result)) { return Result::error("创建风格失败", 0); } else { return Result::success(["id" => $result]); } } /** * 更新风格 * @param array $data * @return array */ public function upTemplateClass(array $data): array { $where = [ 'id' => $data['id'], ]; $template_class = TemplateClass::where($where)->first(); if (empty($template_class)) { return Result::error("未查询到风格", 0); } if($template_class->type == 1){ return Result::error("默认风格不能修改", 0); } $template = TemplateClass::where('id','!=',$data['id']) // ->where(['name' => $data['name']]) // ->orWhere(['class_id' => $data['class_id']]) ->where(function ($query) use ($data) { $query->where('name', $data['name']) ->orWhere('class_id', $data['class_id']); }) ->first(); if ($template) { return Result::error("风格名称或者风格编号已存在,不可编辑!", 0); } $updateData = [ 'name' => $data['name'], 'keyword' => json_encode($data['keyword']), 'class_id' => $data['class_id'], ]; $result = TemplateClass::where($where)->update($updateData); if (empty($result)) { return Result::error("更新失败", 0); } else { return Result::success($result); } } /** * 删除风格 * @param array $data * @return array */ public function delTemplateClass(array $data): array { $where = [ 'id' => $data['id'], ]; $template = TemplateClass::where($where)->first(); if (empty($template)) { return Result::error("未查询到风格", 0); } if($template->type == 1){ return Result::error("默认风格不能删除", 0); } $result = TemplateClass::where($where)->delete(); if (empty($result)) { return Result::error("删除失败", 0); } else { return Result::success($result); } } /** * 获取getTemplateClass * @param array $data * @return array */ public function getTemplateClass(array $data): array { $result = TemplateClass::get(); return Result::success($result); } /** * 获取皮肤列表 * @param array $data * @return array */ public function getTemplateList(array $data): array { $where = []; if (!empty($data['template_class_id'])) { $where['template_class_id'] = $data['template_class_id']; } if (!empty($data['template_name'])) { array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']); } if (!empty($data['template_keyword'])) { array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']); } $result = Template::where($where) ->leftJoin('template_class', 'template.template_class_id', 'template_class.id') ->select('template.*', 'template_class.name as template_class_name') ->orderBy('template.id', 'desc') ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']); if(empty($result)){ return Result::error("暂无皮肤", 0); } return Result::success($result); } public function getTemplateInfo(array $data): array { $result = Template::where('template.id', $data['id']) ->leftJoin('template_class', 'template.template_class_id', 'template_class.id') ->select('template.*', 'template_class.name as template_class_name') ->first(); if(empty($result)){ return Result::error("暂无皮肤", 0); } return Result::success($result); } /** * 添加皮肤 * @param array $data * @return array */ public function addTemplate(array $data): array { var_dump($data); unset($data['user_id']); $template = Template::where('template_name', $data['template_name']) ->orWhere('template_id', $data['template_id']) ->first(); if ($template) { return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0); } $data['template_keyword'] = json_encode($data['template_keyword']) ?? ''; $page_type = json_decode($data['page_type'], true); $data['page_type'] = json_encode(array_values(array_unique($page_type))); $result = Template::insertGetId($data); if(empty($result)){ return Result::error("创建失败", 0); }else{ return Result::success($result); } } /** * 删除皮肤 * @param array $data * @return array */ public function delTemplate(array $data): array { $result = Template::where('id', $data['id'])->delete(); var_dump($result, '-------------------delete'); if ($result) { return Result::success($result); } else { return Result::error("删除失败", 0); } } /** * 更新皮肤 * @param array $data * @return array */ public function updateTemplate(array $data): array { unset($data['user_id']); $template = Template::where('id', $data['id']) ->first(); if (empty($template)) { return Result::error("此皮肤不存在!", 0); } $template = Template::where('id', '!=', $data['id']) ->where(function ($query) use ($data) { $query->where('template_name', $data['template_name']) ->orWhere('template_id', $data['template_id']); }) ->first(); if ($template) { return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0); } $data['template_keyword'] = json_encode($data['template_keyword']) ?? ''; $page_type = json_decode($data['page_type'], true); $data['page_type'] = json_encode(array_values(array_unique($page_type))); $result = Template::where('id', $data['id'])->update($data); var_dump($result, '-------------------update'); if (!$result) { return Result::error("更新失败", 0); } else { return Result::success('更新成功'); } } public function getSectorList(array $data): array { $where = []; if (!empty($data['template_class_id'])) { $where['template_class.id'] = $data['template_class_id']; } if (!empty($data['template_class_name'])) { $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%']; } if (!empty($data['sector_name'])) { if (!empty($data['sector_name'])) { // $where['sector_name'] = $data['sector_name']; $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']; } } $result = Sector::where($where) ->leftJoin('template', 'template.id', '=', 'sector.template_id') ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行 ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行 ->orderBy('sector.id', 'desc') ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']); return Result::success($result); } public function getSectorInfo(array $data): array { $where = []; $where[] = ['sector.id', '=', $data['id']]; $result = Sector::where($where) ->leftJoin('template', 'template.id', '=', 'sector.template_id') ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行 ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行 ->orderBy('sector.id', 'desc') ->get(); return Result::success($result); } /** * 获取经纬度信息 * @return void */ public function getIpInfo(array $data) :array { $client_ip = isset($data['ip']) && $data['ip']??$_SERVER['REMOTE_ADDR']; // 使用 IPinfo 服务获取 IP 信息 $api_url = "https://ipinfo.io/{$client_ip}/json"; $ch = curl_init($api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // 解析 JSON 响应 $ip_info = json_decode($response, true); // 提取地址和经纬度 if ($ip_info && !isset($ip_info['bogon'])) { $latitude = explode(',', $ip_info['loc'])[0]; $longitude = explode(',', $ip_info['loc'])[1]; $ip_info['latitude'] = $latitude; $ip_info['longitude'] = $longitude; return Result::success($ip_info); } else { $data['ip'] = '101.254.114.212'; $this->getIpinfo(["ip"=>$data['ip']]); } } /** * 获取天气 * @param array $data * @return array */ public function getWeatherInfo(array $data) :array { $month = $data['month'] ?? date('m'); $day = $data['day'] ?? date('d'); // 使用缓存键 $cacheKey = "tsbb_data_weather_{$month}_{$day}"; // 尝试从缓存获取数据 $container = \Hyperf\Context\ApplicationContext::getContainer(); $cache = $container->get(\Psr\SimpleCache\CacheInterface::class); if ($cachedData = $cache->get($cacheKey)) { return Result::success(unserialize($cachedData)); } $location = $data['latitude'].":".$data['longitude']; $api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c"; $ch = curl_init($api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // 解析 JSON 响应 $WeatherInfo = json_decode($response, true); // 缓存结果,设置1小时过期 $cache->set($cacheKey, serialize($WeatherInfo), 3600); if($WeatherInfo){ return Result::success($WeatherInfo); }else{ return Result::error("获取天气失败", 0); } } /** * 获取农历信息 * @return void */ public function getCalendar(array $data) :array { $calendar = new Calendar(); $result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历 return Result::success($result); } public function addSector(array $data): array { unset($data['user_id']); // $data['page_type'] = json_encode($data['page_type']); $result = Sector::insertGetId($data); return Result::success(); } public function delSector(array $data): array { $result = Sector::where('id', $data['id'])->delete(); if ($result == 1) { return Result::success('删除成功'); } else { return Result::error('删除失败'); } } public function updateSector(array $data): array { unset($data['user_id']); $result = Sector::where('id', $data['id'])->update($data); if ($result == 1) { return Result::success('修改成功'); } else { return Result::error('修改失败'); } } public function getComponentList(array $data): array { var_dump($data, '---------'); $where = []; // $where[] = ['sector.id', '=', $data['id']]; if (!empty($data['template_class_id'])) { $where['template_class.id'] = $data['template_class_id']; } if (!empty($data['component_name'])) { $where['component.component_name'] = $data['component_name']; } if (!empty($data['sector_id'])) { $where['sector.id'] = $data['sector_id']; }; $result = Component::where($where) ->leftJoin('template', 'template.id', '=', 'component.template_id') ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行 ->leftJoin('sector', 'sector.id', '=', 'component.sector_id') ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'template_class.id as template_class_id', 'sector.sector_name as sector_name', 'component.*', 'sector.id as sector_id') // 修改这一行) ->orderBy('sector.updated_at', 'desc') ->orderBy('sector.created_at', 'desc') ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']); return Result::success($result); } public function getComponentInfo(array $data): array { $where = []; $result = Component::where($where) ->leftJoin('template', 'template.id', '=', 'component.template_id') ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行 ->leftJoin('sector', 'sector.id', '=', 'component.sector_id') ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*') ->get(); return Result::success($result); } public function addComponent(array $data): array { unset($data['user_id']); $result = Component::insertGetId($data); if ($result) { return Result::success($result); } else { return Result::error('添加失败'); } } public function delComponent(array $data): array { $result = Component::where('id', $data['id'])->delete(); return Result::success($result); } public function updateComponent(array $data): array { $result = Component::where('id', $data['id'])->update($data); return Result::success($result); } public function getWebsiteTemplateInfo(array $data) { $where = []; if (isset($data['id'])) { $where[] = ['id', '=', $data['id']]; } $result = WebsiteTemplateInfo::where($where) ->leftJoin('website', 'website_template_info.website_id', '=', 'website.id') ->leftJoin('website_template', 'website_template_info.template_id', '=', 'website_template.id') ->select('website_template_info.*', 'website.website_name') ->get(); if ($result) { return Result::success($result); } else { return Result::error('暂无数据'); } } /** * 自助建站----1.获取页面类型回显 * @param array $data * @return array */ public function getWebPageType(array $data): array { // 1:图片 2:文字 3:底部 $friend_link = Link::where('website_id', $data['website_id'])->where('type',3)->get(); if(empty($friend_link->toArray())){ return Result::error('暂无友情链接数据!'); } $footer_category = FooterCategory::where('website_id', $data['website_id'])->get(); if(empty($footer_category->toArray())){ return Result::error('暂无底部导航数据!'); } $result = [ 'friend_link' => $friend_link, 'footer_category' => $footer_category, ]; return Result::success($result); } /** * 自助建站----2.添加页面类型 * @param array $data * @return array */ public function addWebPageType(array $data): array { // 1:首页 2:频道页 3:列表页 4:详情页 5:搜索页 6:特殊列表 7:特殊详情页' if($data['is_search'] == 1){ $page_type = json_encode([1,2,3,4,5,6,7]); }else{ $page_type = json_encode([1,2,3,4,6,7]); } // 0:未构建;1:已填写基础信息;2:已选择模板; action_id $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['page_type' => $page_type],['action_id' => 1]); if ($result) { return Result::success($result); } else { return Result::error('添加失败'); } } /** * 自助建站---流程---3.选择皮肤列表 * @param array $data * @return array */ public function getWebsiteTemplateList(array $data): array { $where = []; if(isset($data['template_class_id']) && $data['template_class_id']){ $where[] = ['template_class_id', '=', $data['template_class_id']]; } // 0:未构建 1:未应用 2:已应用 status $templste_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(); if(empty($templste_info)){ return Result::error('请先填写网站基础信息!'); } if($templste_info['status'] == 2){ return Result::error('网站已应用,不可再次修改!'); } if(isset($data['keyword']) && !empty($data['keyword'])){ if (is_array($data['keyword'])) { // 拼接多个模糊查询条件 $query = Template::query(); foreach ($data['keyword'] as $kw) { $escapedKw = addcslashes($kw, '%_'); // 转义通配符 $query->WhereRaw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?", ["%$escapedKw%"]); } } else { $escapedKeyword = addcslashes($data['keyword'], '%_'); // 转义通配符 $where[] = [DB::raw("JSON_EXTRACT(template_keyword, '$[*]') LIKE ?"), "%$escapedKeyword%"]; } } $template_id = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(['template_id', 'page_type']); // return Result::success($template_id); if(!empty($template_id['page_type']) && $templste_info['page_type'] != '[]' && is_string($templste_info['page_type'])){ $template_page = is_string($templste_info['page_type']) ? json_decode($templste_info['page_type'], true) : []; }else{ $template_page = []; } if(!empty($template_id['template_id'])){ $result['template_id'] = $templste_info['template_id']; } // 确保 $template_page 为有效数据,避免 SQL 注入风险,这里使用参数绑定 $template_page_str = json_encode($template_page); if (isset($query)) { $result['template'] = $query->where($where) ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str]) ->paginate($data['page_size'], ['*'], 'page', $data['page']); } else { $result['template'] = Template::where($where) ->whereRaw("JSON_CONTAINS(template.page_type, ?)", [$template_page_str]) ->paginate($data['page_size'], ['*'], 'page', $data['page']); } if (empty($result['template']['data'])) { $result['template'] = Template::orderBy('updated_at','desc') ->paginate($data['page_size'], ['*'], 'page', $data['page']); } return Result::success($result); } /** * 自助建站---流程---4.选择皮肤 * @param array $data * @return array */ public function chooseWebsiteTemplate(array $data): array { $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(); if(empty($website_template_info)){ return Result::error('请先填写网站基础信息!'); } // 0:未构建 1:未应用 2:已应用 status if($website_template_info['status'] == 2){ return Result::error('网站已应用,不可再次修改!'); } $template = Template::where('id', $data['template_id'])->first(); if(empty($template)){ return Result::error('未查询到皮肤!'); } // 0:未构建;1:已填写基础信息;2:已选择模板; action_id $web_template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id'],'action_id' => 2]); if ($web_template) { return Result::success($web_template); } else { return Result::error('选择皮肤失败!'); } } /** * 自助建站---流程---5.选择组件 * @param array $data * @return array */ public function saveWebsiteTemplate(array $data): array { $website_template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(); if(empty($website_template_info)){ return Result::error('请先填写网站基础信息!'); } // 0:未构建 1:未应用 2:已应用 status if($website_template_info['status'] == 2){ return Result::error('网站已应用,不可再次保存!'); } if($website_template_info['action_id'] != 2){ return Result::error('请完成之前的步骤!'); } $template_info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first(); if(empty($template_info)){ $template = WebsiteTemplate::insertGetId(['website_id' => $data['website_id'],'template_data' => $data['template_data']]); }else{ $template = WebsiteTemplate::where('website_id', $data['website_id'])->update(['template_data' => $data['template_data']]); } if(empty($template)){ return Result::error('保存失败!'); }else{ return Result::success($template); } } /** * 企业管理 * @param array $data * @return array */ public function getCompanyList(array $data): array { $where = []; $user = User::where('id', $data['user_id'])->first(); if(empty($user)){ return Result::error('用户不存在!'); } if($user['type_id']!= 10000){ $where['user_id'] = $data['user_id']; } if(isset($data['title']) && $data['title']){ array_push($where, ['title', 'like', '%'. $data['title']. '%']); } if(isset($data['website_id']) && $data['website_id']){ $where['website_id'] = $data['website_id']; } // 状态:0:未审核 1:已审核 2:已拒绝 $pageSize = isset($data['pageSize']) ? (int)$data['pageSize'] : 10; // 默认每页 10 条记录 $page = isset($data['page']) ? (int)$data['page'] : 1; // 默认第 1 页 if(isset($data['ischeck']) && !empty($data['ischeck'])){ if($data['ischeck'] == 1){ $query = Company::whereIn('status', [0,2]); }else{ $query = Company::where('status', 1); } } $result = $query->where($where)->paginate($pageSize, ['*'], 'page', $page); if(empty($result)){ return Result::error("暂无企业", 0); } return Result::success($result); } /** * 添加企业 * @param array $data * @return array */ public function addCompany(array $data): array { $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : ''; $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : ''; $user = User::where('id', $data['user_id'])->first(); if(empty($user)){ return Result::error('用户不存在!'); } if($user['type_id']== 10000){ $data['status'] = 1; } $result = Company::insertGetId($data); if ($result) { return Result::success($result); } else { return Result::error('添加失败'); } } /** * 更新企业 * @param array $data * @return array */ public function upCompany(array $data): array { $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : ''; $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : ''; $user = User::where('id', $data['user_id'])->first(); if(empty($user)){ return Result::error('用户不存在!'); } if($user['type_id']== 10000){ $data['status'] = 1; }else{ $data['status'] = 0; } $result = Company::where('id', $data['id'])->update($data); if ($result) { return Result::success($result); } else { return Result::error('修改失败'); } } /** * 删除企业 * @param array $data * @return array */ public function delCompany(array $data): array { $result = Company::where('id', $data['id'])->delete(); if ($result) { return Result::success($result); } else { return Result::error('删除失败'); } } /** * 审核企业 * @param array $data * @return array */ public function checkCompany(array $data): array { $user = User::where('id', $data['user_id'])->first(); if(empty($user)){ return Result::error('用户不存在!'); } if($user['type_id'] != 10000){ return Result::error('用户权限不足!'); } $company = Company::where('id', $data['id'])->first(); if(empty($company)){ return Result::error('企业不存在!'); } // 状态:0:未审核 1:已审核 2:已拒绝 if($company['status'] == 0){ switch ($data['status']) { case 0: return Result::error('请选择审核状态!'); break; case 1: $result = Company::where('id', $data['id'])->update(['status' => $data['status']]); break; case 2: $result = Company::where('id', $data['id'])->update(['status' => $data['status'],'reject_reason'=> $data['reject_reason']]); break; default: return Result::error('请选择审核状态!'); break; } }else{ return Result::error('企业已审核!'); } if(empty($result)){ return Result::error('审核失败!'); }else{ return Result::success($result); } } }