|
@@ -2,6 +2,8 @@
|
|
|
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\TemplateClass;
|
|
|
use App\Model\Template;
|
|
@@ -14,8 +16,10 @@ 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
|
|
|
{
|
|
@@ -1077,5 +1081,205 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
return Result::success($websiteInfo->toArray());
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取并搜索 网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWebsiteTemplateinfo(array $data): array
|
|
|
+ {
|
|
|
+ $where = []; // 初始化 $where 数组
|
|
|
+ //若存在条件;则在$rep的基础上进行筛选
|
|
|
+ if(isset($data['website_name'])){
|
|
|
+ array_push($where, ['website.website_name','like','%'.$data['website_name'].'%']);
|
|
|
+ }
|
|
|
+ if(isset($data['status'])){
|
|
|
+ if($data['status'] == 0){
|
|
|
+ array_push($where, ['website_template_info.status','=',null]);
|
|
|
+ }else{
|
|
|
+ array_push($where, ['website_template_info.status','=',$data['status']]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //查询所有网站模板信息
|
|
|
+ if(empty($where)){
|
|
|
+ $rep = 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")
|
|
|
+ ->get();
|
|
|
+ }else{
|
|
|
+ $rep = Website::where($where)
|
|
|
+ ->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")
|
|
|
+ ->get();
|
|
|
|
|
|
+ }
|
|
|
+ $result = [
|
|
|
+ "rows" => $rep->toArray(),
|
|
|
+ "count" => $rep->count()
|
|
|
+ ];
|
|
|
+ if($rep->count()==0){
|
|
|
+ return Result::error("没有查找到相关数据",0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result); // 返回结果应该是 $result,而不是 $where
|
|
|
+ }
|
|
|
+ // return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function addWebsiteTemplateinfo(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('website.id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ $message = "请输入正确的网站id!";
|
|
|
+ }else{
|
|
|
+ if(empty($website['website_column_id'])){
|
|
|
+ $message = "请先关联导航池!";
|
|
|
+ }
|
|
|
+ if(isset($data['page_type'])){
|
|
|
+ if (in_array(1, $data['page_type']) && in_array(7, $data['page_type'])) {
|
|
|
+ // 数组中同时包含值为 1(首页) 和值为 7 (底部导航详情页)的元素
|
|
|
+ $result = 'yes';
|
|
|
+ $data['page_type'] = json_encode($data['page_type'])??''; // 将数组转换为 JSON 字符串
|
|
|
+ $result = WebsiteTemplateInfo::insertGetId($data);
|
|
|
+ } else {
|
|
|
+ $message = "请先选择首页和底部导航详情页!";
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $footer = FooterCategory::where('website_id',$data['website_id'])->select('type')->get();
|
|
|
+ if(empty($footer)){
|
|
|
+ $types = '2';
|
|
|
+ }else{
|
|
|
+ $types = 2;
|
|
|
+ foreach ($footer as $v) {
|
|
|
+ if ($v['type'] == 1) {
|
|
|
+ $types = 1;
|
|
|
+ } else {
|
|
|
+ $types = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result['type'] = $types;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error($message,0);
|
|
|
+ }else{
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加网站模板信息
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function addWebsiteTemplate(array $data): array
|
|
|
+ {
|
|
|
+ $website = Website::where('website.id',$data['website_id'])->first();
|
|
|
+ if(empty($website)){
|
|
|
+ $message = "请输入正确的网站id!";
|
|
|
+ }else{
|
|
|
+ //若存在模板id 则直接添加
|
|
|
+ if(isset($data['template_id'])){
|
|
|
+ $template = Template::where('id',$data['template_id'])->first();
|
|
|
+ if(empty($template)){
|
|
|
+ $message = "请输入正确的模板id!";
|
|
|
+ }else{
|
|
|
+ $result = WebsiteTemplateInfo::where('website_id',$data['website_id'])
|
|
|
+ ->update(['template_id'=>$data['template_id']]);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $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')
|
|
|
+ ->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->toArray())){
|
|
|
+ $message = "没有查找到相关数据!";
|
|
|
+ }else{
|
|
|
+ $result = [
|
|
|
+ "rows" => $rep->toArray(),
|
|
|
+ "count" => $rep->count()
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(empty($rep->toArray())){
|
|
|
+ return Result::error($message,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);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|