123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632 |
- <?php
- namespace App\JsonRpc;
- use App\Model\Article;
- use App\Model\Ad;
- use App\Model\Category;
- use App\Model\AdPlace;
- use App\Model\Department;
- use App\Model\District;
- use App\Model\FooterCategory;
- use App\Model\FooterContent;
- use App\Model\WebsiteTemplateInfo;
- use App\Model\Link;
- use App\Model\LetterOfComplaint;
- use App\Model\TemplateClass;
- use App\Model\Template;
- use App\Model\User;
- use App\Model\UserInfo;
- use App\Model\WebsiteRole;
- use App\Model\WebsiteRoleUser;
- use App\Model\Website;
- use App\Model\WebsiteColumn;
- use Hyperf\DbConnection\Db;
- use Hyperf\RpcServer\Annotation\RpcService;
- use App\Tools\Result;
- use Carbon\Carbon;
- use App\Model\WebsiteCategory;
- use App\Model\WebsiteGroup;
- use function PHPUnit\Framework\isNull;
- #[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
- class WebsiteService implements WebsiteServiceInterface
- {
- /**
- * 获取网站列表
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsitetList(array $data): array
- {
- $resultWwhere = Website::when($data, function ($query) use ($data) {
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- $query->where('website.website_name', 'like', '%' . $data['keyword'] . '%');
- }
- if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
- $query->whereJsonContains("website.website_column_arr_id", intval($data['website_column_id']));
- }
- if (isset($data['city_id']) && !empty($data['city_id'])) {
- $query->whereJsonContains("website.city_arr_id", intval($data['city_id']));
- }
- });
- $count = $resultWwhere->count();
- $result = $resultWwhere->leftJoin("website_column", "website.website_column_id", "website_column.id")
- ->leftJoin("district", "district.id", "website.city_id")
- ->select("website.*", "website_column.column_name", "district.name as city_name")
- ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->orderBy("website.updated_at", "desc")->get();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsite(array $data): array
- {
- var_dump("网站数据:", $data);
- $insertData = [
- 'website_name' => $data['website_name'],
- 'logo' => $data['logo'] ?? '',
- 'website_url' => $data['website_url'] ?? '',
- // 'city_id'=>$data['city_id']??0,
- 'website_column_id' => $data['website_column_id'],
- 'title' => $data['title'] ?? '',
- 'keywords' => $data['keywords'] ?? '',
- 'description' => $data['description'] ?? '',
- 'status' => $data['status'] ?? 0,
- 'website_column_arr_id' => $data['website_column_arr_id'],
- // 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' => $data['template_id'] ?? 0,
- ];
- $result = Website::insertGetId($insertData);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsite(int $id, array $data): array
- {
- $insertData = [
- 'website_name' => $data['website_name'],
- 'logo' => $data['logo'] ?? '',
- 'website_url' => $data['website_url'] ?? '',
- // 'city_id'=>$data['city_id']??0,
- 'website_column_id' => $data['website_column_id'],
- 'title' => $data['title'] ?? '',
- 'keywords' => $data['keywords'] ?? '',
- 'description' => $data['description'] ?? '',
- 'status' => $data['status'] ?? 0,
- 'website_column_arr_id' => $data['website_column_arr_id'],
- // 'city_arr_id'=>$data['city_arr_id']??[0],
- 'template_id' => $data['template_id'] ?? 0,
- ];
- $result = Website::where('id', $id)->update($insertData);
- var_dump("更新站点", $result);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsite(int $id): array
- {
- $result = Website::where('id', $id)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function getWebsiteInfo(int $id): array
- {
- $where = [
- ['website.id', '=', $id],
- ];
- $result = Website::where($where)
- ->leftJoin("template", "template.id", "website.template_id")
- ->select("website.*", "template.template_name", "template.template_img")
- ->first();
- if (empty($result)) {
- return Result::error("数据不存在", 0);
- } else {
- return Result::success($result->toArray());
- }
- }
- /**
- * 查询所有的站点栏目
- * @return array
- */
- public function getWebsiteColumn(array $data): array
- {
- $result = WebsiteColumn::where($data)->get();
- if (empty($result)) {
- return Result::error("数据不存在", 0);
- } else {
- return Result::success($result->toArray());
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteColumnList(array $data): array
- {
- $where = [];
- if (isset($data['keyword']) && $data['keyword']) {
- array_push($where, ['website_column.column_name', 'like', '%' . $data['keyword'] . '%']);
- }
- $result = WebsiteColumn::where($where)
- ->leftJoin("website_column as wc", "website_column.pid", "wc.id")
- ->select("website_column.*", "wc.column_name as parent_column_name")
- ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])->get();
- $count = WebsiteColumn::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteColumn(array $data): array
- {
- $insertData = [
- 'column_name' => $data['column_name'],
- 'pid' => $data['pid'] ?? '',
- 'column_arr_id' => $data['column_arr_id'] ?? [0],
- 'sort' => $data['sort'] ?? 0,
- 'remark' => $data['remark'] ?? '',
- ];
- $result = WebsiteColumn::insertGetId($insertData);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteColumn(int $id, array $data): array
- {
- $insertData = [
- 'column_name' => $data['column_name'],
- 'pid' => $data['pid'] ?? '',
- 'column_arr_id' => $data['column_arr_id'] ?? [0],
- 'sort' => $data['sort'] ?? 0,
- 'remark' => $data['remark'] ?? '',
- ];
- $result = WebsiteColumn::where('id', $id)->update($insertData);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteColumn(int $id): array
- {
- $list = WebsiteColumn::where(['pid' => $id])->get();
- if ($list) {
- return Result::error("存在子网系,不能删除,请先删除子网系", 0);
- }
- $result = WebsiteColumn::where('id', $id)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleList(string $keyword, int $page, int $pageSize, int $websiteId): array
- {
- $where = [
- ['role.role_name', 'like', '%' . $keyword . '%'],
- ['website_role.website_id', '=', $websiteId],
- ];
- $result = WebsiteRole::where($where)
- ->leftJoin("role", "role.id", "website_role.role_id")
- ->select("role.*", "website_role.type", "website_role.role_id", "website_role.id as website_role_id", "website_role.website_id")
- ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
- $count = WebsiteRole::where($where)->leftJoin("role", "role.id", "website_role.role_id")->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRole(array $data): array
- {
- $insertData = [
- 'website_id' => $data['website_id'],
- 'role_id' => $data['role_id'] ?? '',
- ];
- $info = WebsiteRole::where($insertData)->first();
- if ($info) {
- return Result::error("不能重复添加角色", 0);
- }
- $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
- $insertData['type'] = $data['type'] ?? '';
- $result = WebsiteRole::insertGetId($insertData);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 暂时用不上
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRole(int $id, array $data): array
- {
- $insertData = [
- 'website_id' => $data['website_id'],
- 'type' => $data['type'] ?? '',
- ];
- $result = WebsiteRole::where('id', $id)->update($insertData);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRole(int $id): array
- {
- $result = WebsiteRole::where('id', $id)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param string $keyword
- * @param int $page
- * @param int $pageSize
- * @return array
- */
- public function getWebsiteRoleUserList(string $keyword, int $page, int $pageSize, int $websiteId, int $roleId): array
- {
- $where = [
- ['website_role_user.website_id', '=', $websiteId],
- ['website_role_user.role_id', '=', $roleId],
- ];
- $count = WebsiteRoleUser::where($where)->count();
- $where[] = ['u.user_name', 'like', '%' . $keyword . '%'];
- $result = WebsiteRoleUser::where($where)
- ->leftJoin("user as u", "website_role_user.user_id", "u.id")
- ->leftJoin("website as w", "website_role_user.website_id", "u.id")
- ->leftJoin("role as r", "website_role_user.role_id", "r.id")
- ->select("u.*", "u.user_name", 'w.website_name', 'r.role_name', 'website_role_user.id as website_role_user_id', 'website_role_user.updated_at as user_update_at')
- ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * @param array $data
- * @return array
- */
- public function createWebsiteRoleUser(array $data): array
- {
- $insertData = [
- 'website_id' => $data['website_id'],
- 'user_id' => $data['user_id'] ?? '',
- ];
- $info = WebsiteRoleUser::where($insertData)->first();
- if ($info) {
- return Result::error("不能重复添加角色用户", 0);
- }
- $insertData['role_id'] = $data['role_id'] ?? '';
- $insertData['admin_user_id'] = $data['admin_user_id'] ?? '';
- $insertData['type'] = $data['type'] ?? '';
- $result = WebsiteRoleUser::insertGetId($insertData);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * @param int $id
- * @param array $data
- * @return array
- */
- public function updateWebsiteRoleUser(int $id, array $data): array
- {
- $insertData = [
- 'website_id' => $data['website_id'],
- 'type' => $data['type'] ?? '',
- 'type_id' => $data['type_id'] ?? '',
- 'role_id' => $data['role_id'] ?? '',
- ];
- $result = WebsiteRoleUser::where('id', $id)->update($insertData);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * @param int $id
- * @return array
- */
- public function delWebsiteRoleUser(int $id): array
- {
- $result = WebsiteRoleUser::where('id', $id)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 根据域名获取网站 站点id
- * @param array $data
- * @return array
- */
- public function getWebsiteId(array $data): array
- {
- $result = Website::whereJsonContains('website_url', $data['website_url'])->first();
- if (empty($result)) {
- return Result::error("查询站点失败", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 查询网站下面的导航
- * @param array $data
- * @return array
- */
- public function getWebsiteCategory(array $data): array
- {
- $where = [
- 'website_id'=>$data['website_id']
- ];
- // 使用递归查询构建树状结构
- $category = WebsiteCategory::where($where)
- ->with([
- 'children' => function ($query) {
- $query->orderBy('sort', 'asc');
- }
- ])
- ->orderBy('sort', 'asc')
- ->where('pid', 0) // 仅查询顶级节点
- ->get()->all();
- if(empty($category)){
- return Result::error("查询站点栏目失败",0);
- }else{
- $count = WebsiteCategory::where($where)->count();
- $result = [
- 'rep' => $category,
- 'count' => $count
- ];
- return Result::success($result);
- }
- }
- /**
- * 查询网站的广告
- * @param array $data
- * @return array
- */
- public function getWebsiteAdvertisement(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'ad_place.status' => 1,
- // 'ad.status' => 1,
- ];
- if (isset($data['ad_tag']) && !empty($data['ad_tag'])) {
- $now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
- $where[] = ['ad_place.ad_tag','like','%'.$data['ad_tag'].'%'];
- $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")
- ->get()->all();
- if(empty($result)){
- return Result::error("此广告位不存在!",0);
- }
- }else{
- return Result::error("请选择广告位!",0);
- }
- return Result::success($result);
- }
- /**
- *
- * @param array $data
- * @return array
- */
- /**网站行政职能搜索 */
- public function selectWebsiteDepartment(array $data): array
- {
- $depart = Department::where('pid', 0)->orderBy('id', 'asc')->limit(10)->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,
- ];
- }
- $result['sele'] = $m;
- return Result::success($result['sele']);
- }
- $result = $depart;
- return Result::success($result);
- }
- /**
- * 搜索地区
- * @param array $data
- * @return array
- */
- public function selectWebsiteArea(array $data): array
- {
- $provinces = District::where('pid', 0)->where('status', 1)->get();
- if (isset($data['province'])) {
- $province = District::where('pid', 0)->where('status', 1)->where('id', $data['province'])->orderBy('id')->get();
- $province = $province->toArray();
- if (!empty($province)) {
- $citys = District::where('pid', $data['province'])->where('status', 1)->orderBy('id')->get();
- if (!empty($citys) && isset($data['city']) && !empty($data['city'])) {
- // $province = $province->toArray();
- $province_id = [];
- foreach ($province as $val) {
- array_push($province_id, $val['id']);
- }
- // var_dump($province_id);
- $city = District::whereIn('pid', $province_id)->where('status', 1)->where('id', $data['city'])->orderBy('id')->get();
- if (!empty($city)) {
- $city_id = [];
- foreach ($city as $val) {
- array_push($city_id, $val['id']);
- }
- $regions = District::whereIn('pid', $city_id)->where('status', 1)->orderBy('id')->get();
- $result = [
- 'province' => $province,
- 'city' => $city,
- 'region' => $regions,
- ];
- } else {
- return Result::error("未查询到此城市", 0);
- }
- } else {
- $result = [
- 'province' => $province,
- 'city' => $citys,
- 'region' => null,
- ];
- }
- } else {
- return Result::error("未查询到此省份", 0);
- }
- } else {
- // $keys = array('data');
- $result = $provinces;
- }
- return Result::success($result);
- }
- /**
- * 获取栏目
- * @param array $data
- * @return array
- */
- 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;
- }
- }
- return Result::success($result);
- if (!empty($result)) {
- return Result::success($result);
- } else {
- return Result::error("本网站暂无栏目", 0);
- }
- }
- /**
- * 获取友情链接
- * @param array $data
- * @return array
- */
- public function selectWebsiteLinks(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'status' => 1,
- 'type' => $data['type']
- ];
- $num=$data['num'];
- $result=Link::where($where)->orderBy('sort')->limit($num)->get();
- if(!empty($result)){
- return Result::success($result);
- }else{
- return Result::error("本网站暂无此类型友情链接",0);
- }
- }
- /**
- * 网站首页数据统计, 管理员
- * @return void
- */
- public function getAdminIndex(array $data): array
- {
- var_dump("用户类型:", $data['type_id']);
- switch ($data['type_id']) {
- case 4:
- $result = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM letter_of_complaint WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
- return Result::success($result);
- break;
- case 10000:
- $res = [];
- //网站
- $res['website']['count'] = 0;
- $res['website']['growth_rate'] = 0;
- //资讯
- $res['article']['count'] = 0;
- $res['article']['growth_rate'] = 0;
- //导航池
- $res['category']['count'] = 0;
- $res['category']['growth_rate'] = 0;
- //近一月数据
- $res['monthArticle'] = [];
- //用户类型
- $res['userType'] = [];
- $res['website']['count'] = Website::where([])->count();
- $res['article']['count'] = Article::whereNotIn('status', ['404'])->count();
- $res['category']['count'] = Category::where([])->count();
- $res['monthArticle'] = Db::select('SELECT DATE(created_at) AS date,COUNT(*) AS total_count FROM article WHERE created_at >= CURDATE() - INTERVAL 30 DAY GROUP BY DATE(created_at) ORDER BY date ASC;');
- $res['userType'] = User::where([])->selectRaw("count(*) as counts,type_id")->groupBy('type_id')->get();
- return Result::success($res);
- }
- return [];
- }
- /**
- * 获取模板类型
- * @return void
- */
- public function getTemplateClass(array $data): array
- {
- $where = [];
- if (isset($data['name']) && $data['name']) {
- array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
- }
- $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
- if (empty($result)) {
- return Result::error("没有模板类型", 0);
- } else {
- return Result::success($result);
- }
- }
- /**
- * 添加模板类型
- * @param
- * @return void
- */
- public function addTemplateClass(array $data): array
- {
- $insertData = [
- 'name' => $data['name'],
- ];
- $result = TemplateClass::insertGetId($insertData);
- 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'],
- ];
- $insertData = [
- 'name' => $data['name'],
- ];
- $result = TemplateClass::where($where)->update($insertData);
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplateClass(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $result = TemplateClass::where($where)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 获取分类下的模板
- * @param array $data
- * @return array
- */
- public function getTemplate(array $data): array
- {
- $page = $data['page'];
- $pageSize = $data['pageSize'];
- $where = [];
- if (isset($data['template_class_id']) && $data['template_class_id']) {
- array_push($where, ['template_class_id', '=', $data['template_class_id']]);
- }
- $result = Template::where($where)
- ->limit($pageSize)->offset(($page - 1) * $pageSize)->get();
- $count = Template::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- return Result::success($data);
- }
- /**
- * 创建模板
- * @param
- * @return void
- */
- public function addTemplate(array $data): array
- {
- $insertData = [
- 'template_name' => $data['template_name'],
- 'template_img' => json_encode($data['template_img']),
- 'template_class_id' => $data['template_class_id'],
- ];
- $result = Template::insertGetId($insertData);
- if (empty($result)) {
- return Result::error("创建模板失败", 0);
- } else {
- return Result::success(["id" => $result]);
- }
- }
- /**
- * 更新模板
- * @param array $data
- * @return array
- */
- public function upTemplate(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $insertData = [
- 'template_name' => $data['template_name'],
- 'template_img' => json_encode($data['template_img']),
- 'template_class_id' => $data['template_class_id'],
- ];
- $result = Template::where($where)->update($insertData);
- if (empty($result)) {
- return Result::error("更新模板失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 删除模板
- * @param array $data
- * @return array
- */
- public function delTemplate(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $result = Template::where($where)->delete();
- if (empty($result)) {
- return Result::error("删除模板失败", 0);
- } else {
- return Result::success();
- }
- }
- /**
- * 搜索网站
- * @param array $data
- * @return array
- */
- public function websiteList(array $data): array
- {
- $where = [];
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
- }
- $result = Website::where($where)->get();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("没有网站", 0);
- }
- }
- public function addWebsiteCategory(array $data): array
- {
- $website_id = $data['website_id'];
- $category_arr_id = $data['category_arr_id'];
- $categoryList = Category::whereIn('id', $category_arr_id)->get();
- $categoryListIds = [];
- if ($categoryList) {
- foreach ($categoryList->toArray() as $val) {
- array_push($categoryListIds, $val['id']);
- }
- }
- $arr = [];
- if ($categoryListIds) {
- foreach ($categoryListIds as $v) {
- $ids = $this->getUnderlingUIds(intval($v));
- $ids_arr = explode(",", $ids);
- array_push($arr, $ids_arr);
- }
- }
- $mergedArray = [];
- foreach ($arr as $subarray) {
- $mergedArray = array_merge($mergedArray, $subarray);
- }
- var_dump("所有:", $arr, $mergedArray);
- //查询出所有的分类进行分割插入 组装数据
- $categoryListData = Category::whereIn('id', $mergedArray)->get();
- $categoryListData = $categoryListData->toArray();
- $insertData = [];
- if ($categoryListData) {
- foreach ($categoryListData as $key => $value) {
- $insertData[$key]['website_id'] = $website_id;
- $insertData[$key]['name'] = $value['name'];
- $insertData[$key]['sort'] = $value['sort'];
- $insertData[$key]['pid'] = $value['pid'];
- $insertData[$key]['pid_arr'] = $value['pid_arr'];
- $insertData[$key]['seo_title'] = $value['seo_title'];
- $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
- $insertData[$key]['seo_description'] = $value['seo_description'];
- $insertData[$key]['alias'] = $value['name'];
- $insertData[$key]['category_id'] = $value['id'];
- }
- }
- $result = WebsiteCategory::insert($insertData);
- var_dump("插入数据状态:", $result);
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("创建失败", 0);
- }
- }
- /**
- * 删除网站导航
- * @param array $data
- * @return array
- */
- public function delWebsiteCategory(array $data): array
- {
- $website_id = $data['website_id'] ?? 0;
- $category_id = $data['category_id'] ?? 0;
- $ids = $this->getUnderlingUIds(intval($category_id));
- $ids_arr = explode(",", $ids);
- $result = WebsiteCategory::where(['website_id' => $website_id])->whereIn("category_id", $ids_arr)->delete();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("删除失败", 0);
- }
- }
- /**
- * 获取网站导航
- * @param array $data
- * @return array
- */
- public function getAdminWebsiteCategory(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'pid' => 0,
- ];
- $result = WebsiteCategory::where($where)->get();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 更新网站导航
- * @param array $data
- * @return array
- */
- public function upWebsiteCategory(array $data): array
- {
- Db::beginTransaction();
- try {
- //合并栏目id
- $reqIds = array_merge($data['old_category_arr_id'], $data['new_category_arr_id']);
- //对比old 数组差异化,把差异化的删除
- $result = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])->get();
- $result = $result->toArray();
- $categoryIds = [];
- if ($result) {
- foreach ($result as $val) {
- array_push($categoryIds, $val['category_id']);
- }
- }
- //和原始数据对比取交际
- $reqidsIntersect = array_intersect($reqIds, $categoryIds);
- //再取差集 进行对比
- $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds), array_diff($categoryIds, $reqidsIntersect));
- var_dump("差集:", $differenceIDS);
- $arr_ids = [];
- if (count($differenceIDS) > 0) {
- foreach ($differenceIDS as $vv) {
- $idV = $this->getUnderlingUIds(intval($vv));
- $ids_arrV = explode(",", $idV);
- array_push($arr_ids, $ids_arrV);
- }
- }
- $del_ids = array_reduce($arr_ids, 'array_merge', array());
- //有差异 删除
- if (count($del_ids) > 0) {
- WebsiteCategory::where(['website_id' => $data['website_id']])->whereIn("category_id", $del_ids)->delete();
- }
- //传过来的值 和 交际 对比,选出要添加的值 进行插入
- $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect), array_diff($reqidsIntersect, $reqIds));
- var_dump("要存储的:", $insertIDS);
- //新的数组重新创建
- if (count($insertIDS) > 0) {
- $arr = [];
- $categoryListIds = $insertIDS;
- if ($categoryListIds) {
- foreach ($categoryListIds as $v) {
- $ids = $this->getUnderlingUIds(intval($v));
- $ids_arr = explode(",", $ids);
- array_push($arr, $ids_arr);
- }
- }
- $mergedArray = [];
- foreach ($arr as $subarray) {
- $mergedArray = array_merge($mergedArray, $subarray);
- }
- var_dump("要插入的ID:", $mergedArray);
- //查询出所有的分类进行分割插入 组装数据
- $categoryListData = Category::whereIn('id', $mergedArray)->get();
- $categoryListData = $categoryListData->toArray();
- $insertData = [];
- if ($categoryListData) {
- foreach ($categoryListData as $key => $value) {
- $insertData[$key]['website_id'] = $data['website_id'];
- $insertData[$key]['name'] = $value['name'];
- $insertData[$key]['sort'] = $value['sort'];
- $insertData[$key]['pid'] = $value['pid'];
- $insertData[$key]['pid_arr'] = $value['pid_arr'];
- $insertData[$key]['seo_title'] = $value['seo_title'];
- $insertData[$key]['seo_keywords'] = $value['seo_keywords'];
- $insertData[$key]['seo_description'] = $value['seo_description'];
- $insertData[$key]['alias'] = $value['name'];
- $insertData[$key]['category_id'] = $value['id'];
- }
- }
- WebsiteCategory::insert($insertData);
- }
- Db::commit();
- } catch (\Throwable $ex) {
- Db::rollBack();
- var_dump($ex->getMessage());
- return Result::error("修改失败", 0);
- }
- return Result::success();
- }
- /**
- * 获取网站列表
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryList(array $data): array
- {
- $where = [];
- if (isset($data['keyword']) && !empty($data['keyword'])) {
- array_push($where, ['website.website_name', 'like', '%' . $data['keyword'] . '%']);
- }
- if (isset($data['website_column_id']) && !empty($data['website_column_id'])) {
- array_push($where, ['website.website_column_id', '=', $data['website_column_id']]);
- }
- $result = Website::where($where)
- ->with(["websiteCategory" => function ($query) {
- $query->where(['pid' => 0])->select('website_id', 'name', 'alias', 'category_id');
- }])
- ->limit($data['pageSize'])->orderBy("updated_at", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
- ->get();
- $count = Website::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- if ($result) {
- return Result::success($data);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 删除网站下的所有导航
- * @param array $data
- * @return array
- */
- public function delWebsiteAllCategory(array $data): array
- {
- $website_id = $data['website_id'];
- $result = WebsiteCategory::where(['website_id' => $website_id])->delete();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("删除失败", 0);
- }
- }
- /**
- * 获取网站下的某一个导航
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryOnes(array $data): array
- {
- $website_id = $data['website_id'];
- $category_id = $data['category_id'];
- $result = WebsiteCategory::where(['website_category.website_id' => $website_id, 'website_category.category_id' => $category_id])
- ->first();
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 更新网闸下的某一个导航
- * @param array $data
- * @return array
- */
- public function upWebsiteCategoryones(array $data): array
- {
- $where = [
- 'website_id' => $data['website_id'],
- 'category_id' => $data['category_id'],
- ];
- $result = WebsiteCategory::where($where)->update($data);
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("更新失败", 0);
- }
- }
- /**
- * 获取网站下的所有导航(包含子导航)
- * @param array $data
- * @return array
- */
- public function getWebsiteAllCategory(array $data): array
- {
- $where = [];
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- array_push($where, ['website_category.website_id', '=', $data['website_id']]);
- }
- if (isset($data['name']) && !empty($data['name'])) {
- array_push($where, ['website_category.name', 'like', '%' . $data['name'] . '%']);
- }
- if (isset($data['alias']) && !empty($data['alias'])) {
- array_push($where, ['website_category.alias', 'like', '%' . $data['alias'] . '%']);
- }
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- array_push($where, ['category.department_id', '=', $data['department_id']]);
- }
- if (isset($data['city_id']) && !empty($data['city_id'])) {
- array_push($where, ['category.city_id', '=', $data['city_id']]);
- }
- $result = WebsiteCategory::where($where)
- ->leftJoin("category", 'website_category.category_id', 'category.id')
- ->leftJoin("department", 'category.department_id', 'department.id')
- ->leftJoin("district", 'category.city_id', 'district.id')
- ->select("website_category.*", "department.name as department_name", "district.name as city_name")
- ->limit($data['pageSize'])->offset(($data['page'] - 1) * $data['pageSize'])
- ->get();
- $count = WebsiteCategory::where($where)
- ->leftJoin("category", 'website_category.category_id', 'category.id')
- ->leftJoin("department", 'category.department_id', 'department.id')
- ->leftJoin("district", 'category.city_id', 'district.id')
- ->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- $data = [
- 'rows' => $result->toArray(),
- 'count' => $count,
- ];
- if ($result) {
- return Result::success($data);
- } else {
- return Result::error("查询失败", 0);
- }
- if ($result) {
- return Result::success($result);
- } else {
- return Result::error("查询失败", 0);
- }
- }
- /**
- * 递归查询数据
- * @param $id
- * @param $ids
- * @return string
- */
- public function getUnderlingUIds($id, $ids = '')
- {
- $back = Category::where(['pid' => $id])->get();
- $back = $back->toArray();
- if (!empty($back) && is_array($back)) {
- foreach ($back as $v) {
- //防止当前人的ID重复去查询,形成恶性循环
- if ($v['id'] == $id) {
- continue;
- }
- $back2 = Category::where(['pid' => $id])->count('id');
- if ($back2 > 0) {
- $ids = $this->getUnderlingUIds($v['id'], $ids);
- } else {
- $ids .= ',' . $v['id'];
- }
- }
- }
- $ids = $id . ',' . $ids . ',';
- $ids = str_replace(',,', ",", $ids);
- $ids = trim($ids, ',');
- return $ids;
- }
- /**
- * 检测网站名称是否重复
- * @param array $data
- * @return array
- */
- public function checkWebsiteName(array $data): array
- {
- if (isset($data['id'])) {
- $data[] = ['id', "!=", $data['id']];
- unset($data['id']);
- }
- $websiteInfo = Website::query()->where($data)->first();
- if (empty($websiteInfo)) {
- return Result::error("找不到网站", 0);
- }
- return Result::success($websiteInfo->toArray());
- }
- /**
- * 检测网站url是否重复
- * @param array $data
- * @return array
- */
- public function checkWebsiteUrl(array $data): array
- {
- $whereData = [];
- if (isset($data['id'])) {
- $whereData = [['id', "!=", $data['id']]];
- unset($data['id']);
- }
- $websiteInfo = Website::query()->where($whereData)->whereJsonContains('website_url', $data['website_url'])->first();
- if (empty($websiteInfo)) {
- return Result::error("找不到URL", 0);
- }
- return Result::success($websiteInfo->toArray());
- }
- /**
- * 获取网站底部基础信息
- * @param array $data
- * @return array
- */
- public function getWebsiteFootInfo(array $data): array
- {
- 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);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $website_foot = WebsiteTemplateInfo::where('website_id', $data['website_id'])->where('status', 2)->first();
- $website_head = Website::where('id', $data['website_id'])
- ->select('id', 'website_name', 'logo', 'title', 'keywords', 'description')->first();
- if (empty($website_foot)) {
- return Result::error("暂无底部基础信息", 0);
- }
- if (empty($website_head)) {
- return Result::error("暂无头部基础信息", 0);
- }
- $result = [
- 'website_foot' => $website_foot,
- 'website_head' => $website_head,
- ];
- return Result::success($result);
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategory(array $data): array
- {
- 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);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $result = FooterCategory::where('website_id', $data['website_id'])->get();
- if (empty($result)) {
- return Result::error("暂无底部导航", 0);
- }
- return Result::success($result->toArray());
- }
- /**
- * 获取网站底部导航列表
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryList(array $data): array
- {
- 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);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- $footercategory = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
- // '底部导航类型 0:内容型;1:列表型;',
- if (!isset($footercategory['type']) || $footercategory['type'] == 0) {
- return Result::error("底部导航id错误", 0);
- } else {
- $query = FooterContent::where('fcat_id', $data['fcat_id']);
- if ($query->count() == 0) {
- return Result::error("暂无底部导航列表", 0);
- } elseif ($query->count() == 1) {
- $result = $query->first();
- } else {
- $result = $query->get();
- }
- }
- return Result::success($result);
- }
- /**
- * 获取网站底部导航
- * @param array $data
- * @return array
- */
- public function getWebsiteFooterCategoryInfo(array $data): array
- {
- 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);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- if (isset($data['type']) && $data['type'] == 0) {
- $fcatid = FooterCategory::where('website_id', $data['website_id'])->where('id', $data['fcat_id'])->first();
- if (empty($fcatid)) {
- return Result::error("底部导航id错误", 0);
- }
- $result = FooterContent::where('fcat_id', $data['fcat_id'])->first();
- } else {
- $result = FooterContent::where('id', $data['fcat_id'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无底部导航内容", 0);
- }
- return Result::success($result);
- }
- /*
- * 搜索网站二级导航
- * @param array $data
- * @return array
- * */
- public function selectWebsiteCategory(array $data): array
- {
- 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);
- }
- $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id')->all();
- // return Result::success($category);
- if (empty($category)) {
- return Result::error("暂无此导航", 0);
- }
- $query = Category::whereIn('id', $category);
- if (isset($data['cityid']) && !empty($data['cityid'])) {
- $cityid = District::where('id', $data['cityid'])->first();
- if (empty($cityid)) {
- return Result::error("暂无此城市", 0);
- } else {
- $city_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->pluck('id');
- // $where[] = ['JSON_CONTAINS(city_arr_id, ?)', $data['cityid']];
- if (empty($city_category)) {
- return Result::error("暂无此城市下的导航", 0);
- }
- $result['catid'] = $city_category;
- $city = 1;
- // var_dump("城市====================",$result);
- }
- }
- if (isset($data['department_id']) && !empty($data['department_id'])) {
- $departmentid = Department::where('id', $data['department_id'])->first();
- if (empty($departmentid)) {
- return Result::error("暂无此部门", 0);
- } else {
- $depart_category = $query->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
- if (empty($depart_category)) {
- return Result::error("暂无此部门下的导航", 0);
- }
- $result['catid'] = $depart_category;
- // var_dump("职能部门*******************",$result);
- $department = 1;
- }
- }
- if (!empty($city) && !empty($department)) {
- // var_dump("城市和职能部门----------------------",$result);
- $sel_category = $query->whereRaw('JSON_CONTAINS(city_arr_id,?)', [$data['cityid']])->whereRaw('JSON_CONTAINS(department_arr_id,?)', [$data['department_id']])->pluck('id');
- if (empty($sel_category)) {
- return Result::error("暂无此城市和职能部门下的导航", 0);
- }
- $result['catid'] = $sel_category;
- }
- if (empty($result)) {
- return Result::error("暂无导航", 0);
- }
- // department_id
- } else {
- return Result::error("参数错误", 0);
- }
- return Result::success($result);
- }
- /**
- * 获取网站栏目seo
- * @param array $data
- * @return array
- */
- public function getWebsiteCategoryHead(array $data): array
- {
- 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);
- }
- } else {
- return Result::error("参数错误", 0);
- }
- if (isset($data['catid']) && !empty($data['catid'])) {
- $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
- if (empty($fcatid)) {
- return Result::error("导航id错误", 0);
- }
- $result = Category::where('id', $data['catid'])->first();
- }
- if (empty($result)) {
- return Result::error("暂无导航", 0);
- }
- return Result::success($result);
- }
- /*
- * 获取某个栏目
- * @param array $data
- * @return array
- * */
- public function getOneWebsiteCategory(array $data): array
- {
- 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);
- }
- $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);
- }
- // department_id
- } else {
- return Result::error("参数错误", 0);
- }
- return Result::success($result);
- }
- //20250212 网站标识
- public function addWebsiteGroup(array $data): array
- {
- //判斷name是不是重复
- $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
- if (!empty($websiteGroupInfo)) {
- return Result::error("网站标识重复", 0);
- }
- //添加信息
- $result = WebsiteGroup::insertGetId($data);
- var_dump($result);
- if (empty($result)) {
- return Result::error("创建失败", 0);
- } else {
- return Result::success($result);
- }
- }
- public function getWebsiteGroupList(array $data): array
- {
- $where = [];
- if (isset($data['name']) && !empty($data['name'])) {
- array_push($where, ['website_group.name', 'like', '%' . $data['name'] . '%']);
- }
- $result = WebsiteGroup::where($where)
- ->limit($data['pageSize'])->orderBy("id", "desc")->offset(($data['page'] - 1) * $data['pageSize'])
- ->get();
- foreach ($result as $websiteGroup) {
- $webIds = json_decode($websiteGroup->web_ids, true);
- $websites = Website::whereIn('id', $webIds)->get();
- $websiteNames = $websites->pluck('website_name', 'id')->toArray();
- $websiteGroup->website_names = $websiteNames;
- $websiteGroup->website_names1 = implode(',', array_values($websiteNames));
- }
- $count = WebsiteGroup::where($where)->count();
- if (empty($result)) {
- return Result::error("没有数据", 0);
- }
- return Result::success(['list' => $result->toArray(), 'count' => $count]);
- }
- public function getWebsiteGroupInfo(array $data): array
- {
- $websiteInfo = WebsiteGroup::query()->where('id', $data['id'])->first();
- $webIds = json_decode($websiteInfo->web_ids, true);
- $websites = Website::whereIn('id', $webIds)->get();
- $websiteNames = $websites->pluck('website_name', 'id')->toArray();
- $websiteInfo->website_names = $websiteNames;
- $websiteInfo->website_names1 = implode(',', array_values($websiteNames));
- if (empty($websiteInfo)) {
- return Result::error("找不到URL", 0);
- }
- return Result::success($websiteInfo->toArray());
- }
- public function updateWebsiteGroup(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- $insertData = [
- 'name' => $data['name'],
- 'web_ids' => $data['web_ids'],
- ];
- //判斷name是不是重复
- $websiteGroupInfo = WebsiteGroup::query()->where('name', $data['name'])->first();
- if (!empty($websiteGroupInfo)) {
- return Result::error("网站标识重复", 0);
- }
- $result = WebsiteGroup::where($where)->update($insertData);
- var_dump($result, '------更新');
- if (empty($result)) {
- return Result::error("更新失败", 0);
- } else {
- return Result::success();
- }
- }
- public function deleteWebsiteGroup(array $data): array
- {
- $where = [
- 'id' => $data['id'],
- ];
- //看看user表是不是有这个id
- $userGroup = User::query()->where('sszq', $data['id'])->first();
- if (!empty($userGroup)) {
- return Result::error("有用户在使用该网站标识,不能删除", 0);
- }
- $result = WebsiteGroup::where($where)->delete();
- if (empty($result)) {
- return Result::error("删除失败", 0);
- } else {
- return Result::success();
- }
- }
- public function getWebsiteNavList(array $data): array
- {
- $where = [];
- if (isset($data['website_id']) && !empty($data['website_id'])) {
- array_push($where, ['website_id', '=', $data['website_id']]);
- }
- if (isset($data['pid'])) {
- array_push($where, ['pid', '=', $data['pid']]);
- }
- $list = WebsiteCategory::query()->where($where)->get();
- if (empty($list)) {
- return Result::error("获取失败", 0);
- } else {
- return Result::success($list);
- }
- }
- }
|