|
@@ -1,1399 +1,1442 @@
|
|
|
-<?php
|
|
|
-namespace App\JsonRpc;
|
|
|
-
|
|
|
-use App\Model\Article;
|
|
|
-use App\Model\Category;
|
|
|
-use App\Model\FooterCategory;
|
|
|
-use App\Model\FooterContent;
|
|
|
-use App\Model\LetterOfComplaint;
|
|
|
-use App\Model\Link;
|
|
|
-use App\Model\TemplateClass;
|
|
|
-use App\Model\Template;
|
|
|
-use App\Model\User;
|
|
|
-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 App\Model\WebsiteCategory;
|
|
|
-use App\Model\WebsiteTemplate;
|
|
|
-use App\Model\WebsiteTemplateInfo;
|
|
|
-use function PHPUnit\Framework\isNull;
|
|
|
-// use Illuminate\Support\Facades\DB;
|
|
|
-#[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
|
|
|
- {
|
|
|
- $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']]);
|
|
|
- }
|
|
|
- if (isset($data['city_id']) && !empty($data['city_id'])) {
|
|
|
- array_push($where, ['website.city_id', '=', $data['city_id']]);
|
|
|
- }
|
|
|
-
|
|
|
- $result = Website::where($where)
|
|
|
- ->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.id", "desc")->get();
|
|
|
-
|
|
|
- $count = Website::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 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'],
|
|
|
- 'pid' => 0,
|
|
|
- ];
|
|
|
- $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("查询站点栏目失败", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 网站首页数据统计, 管理员
|
|
|
- * @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'])->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 getWebsiteintel(array $data): array
|
|
|
- {
|
|
|
- //查询所有网站模板信息
|
|
|
- $query = Website::where('website.status', 1)
|
|
|
- ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
|
|
|
- ->leftJoin("template", "template.id", "website_template_info.template_id")
|
|
|
- ->select(
|
|
|
- "website.website_name",
|
|
|
- "website.website_url",
|
|
|
- "website_template_info.id as tid",
|
|
|
- "website_template_info.created_at",
|
|
|
- "website_template_info.updated_at",
|
|
|
- "website_template_info.page_type",
|
|
|
- DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
|
|
|
- "template.template_name"
|
|
|
- )
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->orderBy("website_template_info.updated_at", "asc");
|
|
|
- //若存在条件;则在$query的基础上进行筛选
|
|
|
- if (isset($data['website_name'])) {
|
|
|
- $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
|
|
|
- }
|
|
|
- if (isset($data['status'])) {
|
|
|
- $query->where('website_template_info.status', $data['status']);
|
|
|
- }
|
|
|
- $rep = $query->get();
|
|
|
- if ($rep->count() == 0) {
|
|
|
- return Result::error("没有查找到相关数据", 0);
|
|
|
- } else {
|
|
|
- $result = [
|
|
|
- "rows" => $rep->toArray(),
|
|
|
- "count" => $rep->count(),
|
|
|
- ];
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- // return Result::success($result);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加网站基础信息
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function addWebsiteTemplateintel(array $data): array
|
|
|
- {
|
|
|
- $website = Website::where('website.id', $data['website_id'])->first();
|
|
|
- if (empty($website)) {
|
|
|
- return Result::error("请输入正确的网站id!", 0);
|
|
|
- }
|
|
|
- if (empty($website['website_column_id'])) {
|
|
|
- return Result::error("请先关联导航池!", 0);
|
|
|
- }
|
|
|
- if (isset($data['page_type'])) {
|
|
|
- // 删除重复元素并重新索引数组
|
|
|
- $data['page_type'] = array_unique($data['page_type']);
|
|
|
- $data['page_type'] = array_values($data['page_type']);
|
|
|
- if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
|
|
|
- // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
|
|
|
- $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if (empty($info)) {
|
|
|
- // 将数组转换为 JSON 字符串
|
|
|
- $data['page_type'] = json_encode($data['page_type']) ?? '';
|
|
|
- $result = WebsiteTemplateInfo::insertGetId($data);
|
|
|
- } else {
|
|
|
- return Result::error("该网站已经存在首页和底部导航详情页!", 0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- return Result::error("请先选择首页和底部导航详情页!", 0);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
|
|
|
- $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
|
- if (empty($foot_type)) {
|
|
|
- return Result::error("请先关联导航池!", 0);
|
|
|
- } elseif (in_array(1, $foot_type)) {
|
|
|
- $foot_type = 1;
|
|
|
- } else {
|
|
|
- $foot_type = 0;
|
|
|
- }
|
|
|
- $result['foot_type'] = $foot_type;
|
|
|
- // 友情链接类型'1:图片 2:文字 3:底部';
|
|
|
- $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
|
- $missingTypes = [];
|
|
|
- if (!in_array(1, $types)) {
|
|
|
- $missingTypes[] = "文字链接";
|
|
|
- }
|
|
|
- if (!in_array(2, $types)) {
|
|
|
- $missingTypes[] = "图片链接";
|
|
|
- }
|
|
|
- if (!in_array(3, $types)) {
|
|
|
- $missingTypes[] = "底部链接";
|
|
|
- }
|
|
|
- if (!empty($missingTypes)) {
|
|
|
- $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
|
|
|
- return Result::error($errorMessage, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("添加失败!", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 获取网站基础信息
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getWebsiteTemplateintel(array $data): array
|
|
|
- {
|
|
|
- $result = WebsiteTemplateInfo::where('website_template_info.id', $data['id'])
|
|
|
- ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
|
|
|
- ->select(
|
|
|
- "website_template_info.*",
|
|
|
- "footer_category.type",
|
|
|
- )
|
|
|
- ->first();
|
|
|
-
|
|
|
- if ($result) {
|
|
|
- $result['page_type'] = json_decode($result['page_type'], true);
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error("请先添加网站基础信息!", 0);
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 修改网站基础信息
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function upWebsiteTemplateintel(array $data): array
|
|
|
- {
|
|
|
- $where = ['website_id' => $data['website_id']];
|
|
|
- $result = WebsiteTemplateInfo::where($where)->first();
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("请先添加网站基础信息!", 0);
|
|
|
- } else {
|
|
|
- unset($data['website_id']);
|
|
|
- // 删除重复元素
|
|
|
- $data['page_type'] = array_unique($data['page_type']);
|
|
|
- // 重新索引数组
|
|
|
- $data['page_type'] = array_values($data['page_type']);
|
|
|
- // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
|
|
|
- if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
|
|
|
- // 将数组转换为 JSON 字符串
|
|
|
- $data['page_type'] = json_encode($data['page_type']) ?? '';
|
|
|
- $result = WebsiteTemplateInfo::where($where)->update($data);
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error("请先选择首页和底部导航详情页!", 0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- /**
|
|
|
- * 获取所有网站风格信息
|
|
|
- *
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getAllTemplateClass(array $data): array
|
|
|
- {
|
|
|
- $result = TemplateClass::all();
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("没有查找到相关数据!", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 搜索并获取网站模板信息
|
|
|
- * @param array $data
|
|
|
- * @return array
|
|
|
- */
|
|
|
- public function getWebsiteTemplateList(array $data): array
|
|
|
- {
|
|
|
- $website = Website::where('website.id', $data['website_id'])->first();
|
|
|
- if (empty($website)) {
|
|
|
- $message = "请输入正确的网站id!";
|
|
|
- } else {
|
|
|
- $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
|
|
|
- if (empty($page_type)) {
|
|
|
- $message = "此网站还未添加基础信息!";
|
|
|
- } else {
|
|
|
- $where = json_decode($page_type['page_type'], true);
|
|
|
- // $where = $data["page_type"];
|
|
|
- if (isset($data['template_class_id'])) {
|
|
|
- $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
|
|
|
- if (empty($template_class)) {
|
|
|
- $message = "请输入正确的模板风格id!";
|
|
|
- } else {
|
|
|
- // 获取指定风格下的模板
|
|
|
- $rep = Template::where('template_class_id', $data['template_class_id'])
|
|
|
- ->where(function ($query) use ($where) {
|
|
|
- foreach ($where as $value) {
|
|
|
- $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
- }
|
|
|
- })
|
|
|
- ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
|
|
|
- ->select('template.*', 'template_class.name', 'template_class.id as class_id')
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->orderBy("template.updated_at", "desc")
|
|
|
- ->get();
|
|
|
- }
|
|
|
- } else {
|
|
|
- //获取所有模板
|
|
|
- $rep = Template::where(function ($query) use ($where) {
|
|
|
- foreach ($where as $value) {
|
|
|
- $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
- }
|
|
|
- })
|
|
|
- ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
- ->limit($data['pageSize'])
|
|
|
- ->orderBy("template.updated_at", "desc")
|
|
|
- ->get();
|
|
|
- }
|
|
|
- if (empty($rep) || $rep->count() == 0) {
|
|
|
- $message = "没有查找到相关数据!";
|
|
|
- } else {
|
|
|
- // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
|
|
|
- $rep->each(function ($item) use ($where) {
|
|
|
- $template_img = json_decode($item->template_img, true);
|
|
|
- $filtered_img = array_filter($template_img, function ($img) use ($where) {
|
|
|
- return in_array($img['value'], $where);
|
|
|
- });
|
|
|
- $item->template_img = $filtered_img;
|
|
|
- });
|
|
|
- $result = [
|
|
|
- "rows" => $rep->toArray(),
|
|
|
- "count" => $rep->count(),
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- if (!empty($message)) {
|
|
|
- return Result::error($message, 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 添加网站模板
|
|
|
- * @param array $data
|
|
|
- */
|
|
|
- public function addWebsiteTemplateclassintel(array $data): array
|
|
|
- {
|
|
|
- $template = Template::where('id', $data['template_id'])->first();
|
|
|
- $web = Website::where('id', $data['website_id'])->first();
|
|
|
- if (empty($template)) {
|
|
|
- return Result::error("请输入正确的模板id", 0);
|
|
|
- }
|
|
|
- if (empty($web)) {
|
|
|
- return Result::error("请输入正确的网站id", 0);
|
|
|
- }
|
|
|
-
|
|
|
- $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id']]);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("添加失败", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- /**
|
|
|
- * 获取网站模板信息
|
|
|
- * @param array $data
|
|
|
- */
|
|
|
- public function getWebsiteTemplateclassintel(array $data): array
|
|
|
- {
|
|
|
- $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
- if (empty($template)) {
|
|
|
- return Result::error("请输入正确的搭建网站id", 0);
|
|
|
- }
|
|
|
- $page_type = json_decode($template['page_type'], true);
|
|
|
- // 获取指定网站下的基础信息和模板及风格信息
|
|
|
- $result = WebsiteTemplateInfo::where([
|
|
|
- ['website_template_info.website_id', $data['website_id']],
|
|
|
- ['template_id', '!=', null],
|
|
|
- ])
|
|
|
- ->leftJoin('template', 'template.id', 'website_template_info.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
|
|
|
- ->where(function ($query) use ($page_type) {
|
|
|
- // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
|
|
|
- foreach ($page_type as $pageType) {
|
|
|
- $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
|
|
|
- }
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'template.template_name',
|
|
|
- 'template.template_img',
|
|
|
- 'template.id as tid', 'template_class.name',
|
|
|
- 'template_class.id as class_id',
|
|
|
- 'website_template_info.*')
|
|
|
- ->first();
|
|
|
- // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
|
|
|
- $template_img = json_decode($result['template_img'], true);
|
|
|
- $page_type = json_decode($result['page_type'], true);
|
|
|
- foreach ($template_img as $key => $value) {
|
|
|
- if (!in_array($value['value'], $page_type)) {
|
|
|
- unset($template_img[$key]);
|
|
|
- }
|
|
|
- }
|
|
|
- $result['template_img'] = $template_img;
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("没有查找到相关数据", 0);
|
|
|
- } else {
|
|
|
- return Result::success($result);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
+<?php
|
|
|
+namespace App\JsonRpc;
|
|
|
+
|
|
|
+use App\Model\Article;
|
|
|
+use App\Model\Category;
|
|
|
+use App\Model\FooterCategory;
|
|
|
+use App\Model\FooterContent;
|
|
|
+use App\Model\LetterOfComplaint;
|
|
|
+use App\Model\Link;
|
|
|
+use App\Model\TemplateClass;
|
|
|
+use App\Model\Template;
|
|
|
+use App\Model\User;
|
|
|
+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 App\Model\WebsiteCategory;
|
|
|
+use App\Model\WebsiteTemplate;
|
|
|
+use App\Model\WebsiteTemplateInfo;
|
|
|
+use Hamcrest\Arrays\IsArray;
|
|
|
+
|
|
|
+use function PHPUnit\Framework\isNull;
|
|
|
+// use Illuminate\Support\Facades\DB;
|
|
|
+#[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
|
|
|
+ {
|
|
|
+ $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']]);
|
|
|
+ }
|
|
|
+ if (isset($data['city_id']) && !empty($data['city_id'])) {
|
|
|
+ array_push($where, ['website.city_id', '=', $data['city_id']]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = Website::where($where)
|
|
|
+ ->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.id", "desc")->get();
|
|
|
+
|
|
|
+ $count = Website::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 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'],
|
|
|
+ 'pid' => 0,
|
|
|
+ ];
|
|
|
+ $result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("查询站点栏目失败", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 网站首页数据统计, 管理员
|
|
|
+ * @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'])->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 getWebsiteintel(array $data): array
|
|
|
+ {
|
|
|
+ //查询所有网站模板信息
|
|
|
+ $query = Website::where('website.status', 1)
|
|
|
+ ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
|
|
|
+ ->leftJoin("template", "template.id", "website_template_info.template_id")
|
|
|
+ ->select(
|
|
|
+ "website.website_name",
|
|
|
+ "website.website_url",
|
|
|
+ "website_template_info.id as tid",
|
|
|
+ "website_template_info.created_at",
|
|
|
+ "website_template_info.updated_at",
|
|
|
+ "website_template_info.page_type",
|
|
|
+ DB::raw("COALESCE(website_template_info.status, 0) as template_status"),
|
|
|
+ "template.template_name"
|
|
|
+ );
|
|
|
+
|
|
|
+ //若存在条件;则在$query的基础上进行筛选
|
|
|
+ if (isset($data['website_name'])) {
|
|
|
+ $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
|
|
|
+ }
|
|
|
+ if (isset($data['status'])) {
|
|
|
+ $query->where('website_template_info.status', $data['status']);
|
|
|
+ }
|
|
|
+ $count = $query->count();
|
|
|
+ $query->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->orderBy("website_template_info.updated_at", "desc");
|
|
|
+ $rep = $query->get();
|
|
|
+ if ($rep->count() == 0) {
|
|
|
+ return Result::error("没有查找到相关数据", 0);
|
|
|
+ } else {
|
|
|
+ $rep->each(function ($item) {
|
|
|
+ if (!empty($item->page_type)) {
|
|
|
+ $pageTypeArray = json_decode($item->page_type, true);
|
|
|
+ if (is_array($pageTypeArray)) {
|
|
|
+ $item->page_type = $pageTypeArray;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ "rows" => $rep->toArray(),
|
|
|
+ "count" => $count,
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ // return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加网站基础信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function addWebsiteTemplateintel(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('website.id', $data['website_id'])->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("请输入正确的网站id!", 0);
|
|
|
+ }
|
|
|
+ if (empty($website['website_column_id'])) {
|
|
|
+ return Result::error("请先关联导航池!", 0);
|
|
|
+ }
|
|
|
+ if (isset($data['page_type'])) {
|
|
|
+ // 删除重复元素并重新索引数组
|
|
|
+ $data['page_type'] = array_unique($data['page_type']);
|
|
|
+ $data['page_type'] = array_values($data['page_type']);
|
|
|
+ if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
|
|
|
+ // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
|
|
|
+ $info = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
+ if (empty($info)) {
|
|
|
+ // 将数组转换为 JSON 字符串
|
|
|
+ $data['page_type'] = json_encode($data['page_type']) ?? '';
|
|
|
+ $result = WebsiteTemplateInfo::insertGetId($data);
|
|
|
+ } else {
|
|
|
+ return Result::error("该网站已经存在首页和底部导航详情页!", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result::error("请先选择首页和底部导航详情页!", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
|
|
|
+ $foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
|
+ if (empty($foot_type)) {
|
|
|
+ return Result::error("请先关联导航池!", 0);
|
|
|
+ } elseif (in_array(1, $foot_type)) {
|
|
|
+ $foot_type = 1;
|
|
|
+ } else {
|
|
|
+ $foot_type = 0;
|
|
|
+ }
|
|
|
+ $result['foot_type'] = $foot_type;
|
|
|
+ // 友情链接类型'1:图片 2:文字 3:底部';
|
|
|
+ $types = Link::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
|
+ $missingTypes = [];
|
|
|
+ if (!in_array(1, $types)) {
|
|
|
+ $missingTypes[] = "文字链接";
|
|
|
+ }
|
|
|
+ if (!in_array(2, $types)) {
|
|
|
+ $missingTypes[] = "图片链接";
|
|
|
+ }
|
|
|
+ if (!in_array(3, $types)) {
|
|
|
+ $missingTypes[] = "底部链接";
|
|
|
+ }
|
|
|
+ if (!empty($missingTypes)) {
|
|
|
+ $errorMessage = "请先添加 " . implode(" 和 ", $missingTypes) . "!";
|
|
|
+ return Result::error($errorMessage, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败!", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站基础信息
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteTemplateintel(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+ $result = WebsiteTemplateInfo::where('website_template_info.id', $data['id'])
|
|
|
+ ->leftJoin('footer_category', 'footer_category.website_id', 'website_template_info.website_id')
|
|
|
+ ->leftJoin('website', 'website.id', 'website_template_info.website_id')
|
|
|
+ ->select(
|
|
|
+ "website_template_info.*",
|
|
|
+ "footer_category.type",
|
|
|
+ "website.website_name"
|
|
|
+ )
|
|
|
+ ->first();
|
|
|
+ if (empty($result['website_name'])) {
|
|
|
+ return Result::error("请输入正确的网站id!", 0);
|
|
|
+ }
|
|
|
+ if ($result) {
|
|
|
+ $result['page_type'] = json_decode($result['page_type'], true);
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("请先添加网站基础信息!", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改网站基础信息
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function upWebsiteTemplateintel(array $data): array
|
|
|
+ {
|
|
|
+ $web = Website::where('website.id', $data['website_id'])->first();
|
|
|
+ if (empty($web)) {
|
|
|
+ return Result::error("请输入正确的网站id!", 0);
|
|
|
+ }
|
|
|
+ $where = ['website_id' => $data['website_id']];
|
|
|
+ $result = WebsiteTemplateInfo::where($where)->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("请先添加网站基础信息!", 0);
|
|
|
+ } else {
|
|
|
+ unset($data['website_id']);
|
|
|
+ // 删除重复元素
|
|
|
+ $data['page_type'] = array_unique($data['page_type']);
|
|
|
+ // 重新索引数组
|
|
|
+ $data['page_type'] = array_values($data['page_type']);
|
|
|
+ // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
|
|
|
+ if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
|
|
|
+ // 将数组转换为 JSON 字符串
|
|
|
+ $data['page_type'] = json_encode($data['page_type']) ?? '';
|
|
|
+ $result = WebsiteTemplateInfo::where($where)->update($data);
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error("请先选择首页和底部导航详情页!", 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("修改失败!", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取所有网站风格信息
|
|
|
+ *
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getAllTemplateClass(array $data): array
|
|
|
+ {
|
|
|
+ $result = TemplateClass::all();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有查找到相关数据!", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 搜索并获取网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteTemplateList(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('website.id', $data['website_id'])->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ $message = "请输入正确的网站id!";
|
|
|
+ } else {
|
|
|
+ $page_type = WebsiteTemplateInfo::where('website_id', $data['website_id'])->select('page_type')->first();
|
|
|
+ if (empty($page_type)) {
|
|
|
+ $message = "此网站还未添加基础信息!";
|
|
|
+ } else {
|
|
|
+ $where = json_decode($page_type['page_type'], true);
|
|
|
+ // $where = $data["page_type"];
|
|
|
+ if (isset($data['template_class_id'])) {
|
|
|
+ $template_class = TemplateClass::where('id', $data['template_class_id'])->first();
|
|
|
+ if (empty($template_class)) {
|
|
|
+ $message = "请输入正确的模板风格id!";
|
|
|
+ } else {
|
|
|
+ // 获取指定风格下的模板
|
|
|
+ $rep = Template::where('template_class_id', $data['template_class_id'])
|
|
|
+ ->where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $value) {
|
|
|
+ $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
|
|
|
+ ->select('template.*', 'template_class.name', 'template_class.id as class_id')
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->orderBy("template.updated_at", "desc")
|
|
|
+ ->get();
|
|
|
+ $count = Template::where('template_class_id', $data['template_class_id'])
|
|
|
+ ->where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $value) {
|
|
|
+ $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
+ }
|
|
|
+ })->count();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //获取所有模板
|
|
|
+ $rep = Template::where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $value) {
|
|
|
+ $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
|
|
|
+ ->select('template.*', 'template_class.name', 'template_class.id as class_id')
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->orderBy("template.updated_at", "desc")
|
|
|
+ ->get();
|
|
|
+ $count = Template::where('template_class_id', $data['template_class_id'])
|
|
|
+ ->where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $value) {
|
|
|
+ $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
+ }
|
|
|
+ })->count();
|
|
|
+
|
|
|
+ }
|
|
|
+ if (empty($rep) || $rep->count() == 0) {
|
|
|
+ $message = "没有查找到相关数据!";
|
|
|
+ } else {
|
|
|
+ // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
|
|
|
+ $rep->each(function ($item) use ($where) {
|
|
|
+ $template_img = json_decode($item->template_img, true);
|
|
|
+ if (is_array($template_img)) {
|
|
|
+ $filtered_img = array_filter($template_img, function ($img) use ($where) {
|
|
|
+ return isset($img['value']) && in_array($img['value'], $where);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $item->template_img = $filtered_img;
|
|
|
+ });
|
|
|
+ $result = [
|
|
|
+ "rows" => $rep->toArray(),
|
|
|
+ "count" => $count,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!empty($message)) {
|
|
|
+ return Result::error($message, 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加网站模板
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function addWebsiteTemplateclassintel(array $data): array
|
|
|
+ {
|
|
|
+ $template = Template::where('id', $data['template_id'])->first();
|
|
|
+ $web = Website::where('id', $data['website_id'])->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("请输入正确的模板id", 0);
|
|
|
+ }
|
|
|
+ if (empty($web)) {
|
|
|
+ return Result::error("请输入正确的网站id", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = WebsiteTemplateInfo::where('website_id', $data['website_id'])->update(['template_id' => $data['template_id']]);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getWebsiteTemplateclassintel(array $data): array
|
|
|
+ {
|
|
|
+ $template = WebsiteTemplateInfo::where('website_id', $data['website_id'])->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("请输入正确的搭建网站id", 0);
|
|
|
+ }
|
|
|
+ $page_type = json_decode($template['page_type'], true);
|
|
|
+ // 获取指定网站下的基础信息和模板及风格信息
|
|
|
+ $result = WebsiteTemplateInfo::where([
|
|
|
+ ['website_template_info.website_id', $data['website_id']],
|
|
|
+ ['template_id', '!=', null],
|
|
|
+ ])
|
|
|
+ ->leftJoin('template', 'template.id', 'website_template_info.template_id')
|
|
|
+ ->leftJoin('template_class', 'template_class.id', 'template.template_class_id')
|
|
|
+ ->where(function ($query) use ($page_type) {
|
|
|
+ // 假设 $data['page_type'] 是一个数组,包含需要匹配的 page_type 值
|
|
|
+ foreach ($page_type as $pageType) {
|
|
|
+ $query->orWhereJsonContains('template.template_img', ['value' => $pageType]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'template.template_name',
|
|
|
+ 'template.template_img',
|
|
|
+ 'template.id as tid', 'template_class.name',
|
|
|
+ 'template_class.id as class_id',
|
|
|
+ 'website_template_info.*')
|
|
|
+ ->first();
|
|
|
+ // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
|
|
|
+ $template_img = json_decode($result['template_img'], true);
|
|
|
+ $page_type = json_decode($result['page_type'], true);
|
|
|
+ foreach ($template_img as $key => $value) {
|
|
|
+ if (!in_array($value['value'], $page_type)) {
|
|
|
+ unset($template_img[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result['template_img'] = $template_img;
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有查找到相关数据", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|