|
@@ -22,12 +22,16 @@ use App\Model\WebsiteRole;
|
|
|
use App\Model\WebsiteRoleUser;
|
|
|
use App\Model\Website;
|
|
|
use App\Model\WebsiteColumn;
|
|
|
+
|
|
|
use Hyperf\DbConnection\Db;
|
|
|
use Hyperf\RpcServer\Annotation\RpcService;
|
|
|
use App\Tools\Result;
|
|
|
use Carbon\Carbon;
|
|
|
use App\Model\WebsiteCategory;
|
|
|
use App\Model\WebsiteGroup;
|
|
|
+use App\Model\WebsiteTemplate;
|
|
|
+use App\Model\Sector;
|
|
|
+use PhpParser\Node\Stmt\Return_;
|
|
|
use function PHPUnit\Framework\isNull;
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
|
|
@@ -1563,6 +1567,468 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ // 自助建站--fr-------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取并搜索 网站模板信息
|
|
|
+ * @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")
|
|
|
+ ->leftJoin("template_class", "template_class.id", "template.template_class_id")
|
|
|
+ ->select(
|
|
|
+ "website_template_info.id",
|
|
|
+ "template_class.name",
|
|
|
+ "website.id as website_id",
|
|
|
+ "website.website_name",
|
|
|
+ "website.website_url",
|
|
|
+ "website_template_info.action_id",
|
|
|
+ "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']) && !empty($data['website_name'])){
|
|
|
+ $query->where('website.website_name', 'like', '%' . $data['website_name'] . '%');
|
|
|
+ }
|
|
|
+ if(isset($data['status']) && !empty($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);
|
|
|
+ }
|
|
|
+ // 获取此网站的底部导航 类型 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(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'])??'';
|
|
|
+ // 操作状态:1:填写完成基础信息;2:选择完成模板;0:未构建
|
|
|
+ $data['action_id'] = 1;
|
|
|
+
|
|
|
+ try {
|
|
|
+ $result = WebsiteTemplateInfo::insertGetId($data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ if ($e->getCode() == 22001) {
|
|
|
+ $errorMessage = $e->getMessage();
|
|
|
+ return Result::error("请检查表单,某个字段超出了长度限制!");
|
|
|
+ } else {
|
|
|
+ // 处理其他类型的数据库错误
|
|
|
+ return Result::error("插入操作失败: " . $e->getMessage());
|
|
|
+ }
|
|
|
+ return Result::error("添加失败!", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result::error("该网站已经构建过了!", 0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return Result::error("请先选择首页和底部导航详情页!", 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.website_id',$data['website_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",
|
|
|
+ "website.id as website_id"
|
|
|
+ )
|
|
|
+ ->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'])??'';
|
|
|
+ try {
|
|
|
+ $result = WebsiteTemplateInfo::where($where)->update($data);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ if ($e->getCode() == 22001) {
|
|
|
+ $errorMessage = $e->getMessage();
|
|
|
+ return Result::error("请检查表单,某个字段超出了长度限制!");
|
|
|
+ } else {
|
|
|
+ // 处理其他类型的数据库错误
|
|
|
+ return Result::error("修改操作失败: " . $e->getMessage());
|
|
|
+ }
|
|
|
+ return Result::error("修改失败!", 0);
|
|
|
+ }
|
|
|
+ }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)){
|
|
|
+ return Result::error("请输入正确的网站id!",0);
|
|
|
+ }else{
|
|
|
+ $page_type = WebsiteTemplateInfo::where('website_id',$data['website_id'])->select('page_type')->first();
|
|
|
+ if(empty($page_type)){
|
|
|
+ return Result::error("此网站还未添加基础信息!",0);
|
|
|
+ } else{
|
|
|
+ $where = json_decode($page_type['page_type'], true);
|
|
|
+ // $where = $data["page_type"];
|
|
|
+ if(isset($data['template_class_id']) && !empty($data['template_class_id'])){
|
|
|
+ $template_class = TemplateClass::where('id',$data['template_class_id'])->first();
|
|
|
+ if(empty($template_class)){
|
|
|
+ return Result::error("请输入正确的模板风格id!",0);
|
|
|
+ }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]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->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]);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->orderBy("template.updated_at", "desc")
|
|
|
+ ->get();
|
|
|
+ $count = Template::where(function ($query) use ($where) {
|
|
|
+ foreach ($where as $value) {
|
|
|
+ $query->whereJsonContains('template_img', ['value' => $value]);
|
|
|
+ }
|
|
|
+ })->count();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ if(empty($rep) || $rep->count()==0){
|
|
|
+ return Result::error("没有查找到相关数据!",0);
|
|
|
+ }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
|
|
|
+ // ];
|
|
|
+ $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);
|
|
|
+ });
|
|
|
+ // 对过滤后的数组进行重新排序
|
|
|
+ $sorted_img = array_values($filtered_img);
|
|
|
+ $item->template_img = $sorted_img;
|
|
|
+ } else {
|
|
|
+ $item->template_img = []; // 如果无法解码为数组,则设置为空数组
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ "rows" => $rep->toArray(),
|
|
|
+ "count" => $count
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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'],'action_id'=>2]);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("添加失败",0);
|
|
|
+ }else{
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getWebsiteTemplateclassintel(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $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.page_type',
|
|
|
+ 'website_template_info.website_id')
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("没有查找到相关数据",0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // return Result::success($result);
|
|
|
+ // 过滤 template_img 字段 只获取 基础信息中 包含的模板图片
|
|
|
+ $template_img = $result['template_img'] !== null ? json_decode($result['template_img'], true) : [];
|
|
|
+ $page_type = $result['page_type'] !== null ? json_decode($result['page_type'], true) : [];
|
|
|
+ foreach ($template_img as $key => $value) {
|
|
|
+ if (!in_array($value['value'], $page_type)) {
|
|
|
+ unset($template_img[$key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // return Result::success($result);
|
|
|
+ $result['template_img'] = array_values($template_img);
|
|
|
+ $result['page_type'] = $page_type;
|
|
|
+
|
|
|
+ // $templateList = $this->getWebsiteTemplateList($data);
|
|
|
+ // $count = $templateList['data']['count']??'';
|
|
|
+ // $pages = $count / $data['pageSize'];
|
|
|
+ // $found = false;
|
|
|
+ // while ($pages && !$found) {
|
|
|
+ // $templates = $this->getWebsiteTemplateList($pages,$data['pageSize']);
|
|
|
+ // $index = array_search($template['template_id'], array_column($templates['rows'], 'id'));
|
|
|
+ // if ($index !== false) {
|
|
|
+ // $found = true;
|
|
|
+ // $result['page'] = $pages;
|
|
|
+ // $pages = 0;
|
|
|
+ // // echo "查询到的 template 在第 $page 页";
|
|
|
+ // }
|
|
|
+ // $pages--;
|
|
|
+ // }
|
|
|
+
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站模板下的板块信息
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getWebsiteSectorList(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ return Result::error("请输入正确的网站id",0);
|
|
|
+ }
|
|
|
+ $template = WebsiteTemplateInfo::where('website_id',$data['website_id'])->first();
|
|
|
+ if(empty($template['template_id'])){
|
|
|
+ return Result::error("请先添加网站模板",0);
|
|
|
+ }
|
|
|
+ $query = Sector::where('template_id',$template['template_id']);
|
|
|
+ if($query->count() == 0){
|
|
|
+ return Result::error("没有查找到相关板块数据",0);
|
|
|
+ }elseif($query->count() == 1){
|
|
|
+ $sector = $query->first();
|
|
|
+ }else{
|
|
|
+ $sector = $query->get();
|
|
|
+ }
|
|
|
+ $result['page_type'] = $template['page_type'];
|
|
|
+ $result['tid'] = $template['template_id'];
|
|
|
+ $result = [
|
|
|
+ "tid" => $template['template_id'],
|
|
|
+ "page_type" => $template['page_type'],
|
|
|
+ "sector" => $sector
|
|
|
+ ];
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 自助建站---------------fr---------------
|
|
|
+
|
|
|
//20250212 网站标识
|
|
|
public function addWebsiteGroup(array $data): array
|
|
|
{
|