|
@@ -47,7 +47,8 @@ use Overtrue\Pinyin\Pinyin;
|
|
|
use App\Tools\buildTree;
|
|
|
use App\Model\WhiteRouter;
|
|
|
use App\Model\Size;
|
|
|
-
|
|
|
+use App\Tools\PinyinHelper;
|
|
|
+use Hyperf\HttpServer\Annotation\AutoController;
|
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
@@ -92,41 +93,47 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
];
|
|
|
return Result::success($data);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* @param array $data
|
|
|
- * @return array
|
|
|
*/
|
|
|
public function createWebsite(array $data): array
|
|
|
{
|
|
|
var_dump("网站数据:", $data);
|
|
|
+ // $wzbs = $this->getWebsitetAdkey($data);
|
|
|
+ // return Result::success($wzbs);
|
|
|
+ $web = Website::where('ad_key', $data['ad_key'])->first();
|
|
|
+ if (!empty($web)) {
|
|
|
+ return Result::error("网站名称简写重复,请填写", 0);
|
|
|
+ }
|
|
|
$insertData = [
|
|
|
'website_name' => $data['website_name'],
|
|
|
'logo' => $data['logo'] ?? '',
|
|
|
'website_url' => $data['website_url'] ?? '',
|
|
|
- // 'city_id'=>$data['city_id']??0,
|
|
|
+ //'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'] ?? 1,
|
|
|
'website_column_arr_id' => $data['website_column_arr_id'],
|
|
|
- // 'city_arr_id'=>$data['city_arr_id']??[0],
|
|
|
+ //'city_arr_id'=>$data['city_arr_id']??[0],
|
|
|
'template_id' => $data['template_id'] ?? 0,
|
|
|
'suffix' => $data['suffix'] ?? "",
|
|
|
- ];
|
|
|
+ 'ad_key' => $data['ad_key']?? "",
|
|
|
+ ];
|
|
|
$result = Website::insertGetId($insertData);
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("创建失败", 0);
|
|
|
+ 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
|
|
|
{
|
|
@@ -144,17 +151,28 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
// 'city_arr_id'=>$data['city_arr_id']??[0],
|
|
|
'template_id' => $data['template_id'] ?? 0,
|
|
|
'suffix' => $data['suffix'] ?? "",
|
|
|
+ 'ad_key' => $data['ad_key']?? "",
|
|
|
];
|
|
|
- var_dump("=========:", $insertData);
|
|
|
- $result = Website::where('id', $id)->update($insertData);
|
|
|
- var_dump("更新站点", $result);
|
|
|
+ $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
|
|
|
+ // `status` tinyint(1) DEFAULT '0' COMMENT '0:未构建 1:未应用 2:已应用',
|
|
|
+ if (!empty($web_templsate) && $web_templsate['status'] == 2) {
|
|
|
+ return Result::error("此网站已应用,不可修改基本信息", 0);
|
|
|
+ }
|
|
|
+ $web = Website::where(function ($query) use ($data) {
|
|
|
+ $query->where('id','!=', $data['id'])
|
|
|
+ ->where('ad_key', $data['ad_key']);
|
|
|
+ })->first();
|
|
|
+ if (!empty($web)) {
|
|
|
+ return Result::error("网站名称简写重复,请填写", 0);
|
|
|
+ }
|
|
|
+ $result = Website::where('id', $data['id'])->update($insertData);
|
|
|
+ // var_dump("更新站点", $result);
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("更新失败", 0);
|
|
|
+ return Result::error("更新网站失败", 0);
|
|
|
} else {
|
|
|
- return Result::success();
|
|
|
+ return Result::success("更新成功");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
* @param int $id
|
|
|
* @return array
|
|
@@ -615,44 +633,43 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
* @return array
|
|
|
*/
|
|
|
|
|
|
- public function getWebsiteModelCategory(array $data): array
|
|
|
- {
|
|
|
- // return Result::success($data);
|
|
|
- $website_id = [
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- ];
|
|
|
- // 初始化 $pid 数组
|
|
|
- // $pid = [];
|
|
|
- // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
|
|
|
- $pidQuery = WebsiteCategory::where($website_id)
|
|
|
- ->where('pid', '!=', 0)
|
|
|
- ->orderBy('sort')
|
|
|
- ->select('pid', 'category_id', 'alias');
|
|
|
- $pid = $pidQuery->pluck('pid');
|
|
|
- $pid = array_values(array_unique($pid->toArray()));
|
|
|
-
|
|
|
- // 构建查询语句
|
|
|
- $query = WebsiteCategory::where($website_id)
|
|
|
- ->where('pid', $data['pid'])
|
|
|
- ->offset($data['placeid'])
|
|
|
- ->limit($data['num'])
|
|
|
- ->orderBy('sort');
|
|
|
- // 如果 $pid 数组不为空,添加 CASE WHEN 条件
|
|
|
- if (!empty($pid)) {
|
|
|
- $placeholders = implode(',', array_fill(0, count($pid), '?'));
|
|
|
- $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
|
|
|
- } else {
|
|
|
- // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
|
|
|
- $query->select('website_category.*', DB::raw('0 as children_count'));
|
|
|
- }
|
|
|
-
|
|
|
- // 执行查询
|
|
|
- $placeid = $data['placeid'] - 1;
|
|
|
- $result = $query->offset($placeid)->limit($data['num'])->get();
|
|
|
-
|
|
|
- if (!empty($result)) {
|
|
|
- $pidResults = $pidQuery->get();
|
|
|
- if (isset($data['type']) && $data['type'] == 1) {
|
|
|
+ public function getWebsiteModelCategory(array $data): array
|
|
|
+ {
|
|
|
+ // return Result::success($data);
|
|
|
+ $website_id = [
|
|
|
+ 'website_id' => $data['website_id'],
|
|
|
+ ];
|
|
|
+ // 初始化 $pid 数组
|
|
|
+ // $pid = [];
|
|
|
+ // 以下注释掉的代码是之前的逻辑,用于获取非顶级分类的 pid
|
|
|
+ $pidQuery = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', '!=', 0)
|
|
|
+ ->orderBy('sort')
|
|
|
+ ->select('pid', 'category_id', 'alias','aLIas_pinyin');
|
|
|
+ $pid = $pidQuery->pluck('pid');
|
|
|
+ $pid = array_values(array_unique($pid->toArray()));
|
|
|
+ // 构建查询语句
|
|
|
+ $query = WebsiteCategory::where($website_id)
|
|
|
+ ->where('pid', $data['pid'])
|
|
|
+ ->offset($data['placeid'])
|
|
|
+ ->limit($data['num'])
|
|
|
+ ->orderBy('sort');
|
|
|
+ // 如果 $pid 数组不为空,添加 CASE WHEN 条件
|
|
|
+ if (!empty($pid)) {
|
|
|
+ $placeholders = implode(',', array_fill(0, count($pid), '?'));
|
|
|
+ $query->selectRaw("website_category.*, CASE WHEN website_category.category_id IN ($placeholders) THEN 1 ELSE 0 END AS children_count", $pid);
|
|
|
+ } else {
|
|
|
+ // 如果 $pid 数组为空,不添加 CASE WHEN 条件,添加字段 children_count 并赋值为 0
|
|
|
+ $query->select('website_category.*', DB::raw('0 as children_count'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 执行查询
|
|
|
+ $placeid = $data['placeid'] - 1;
|
|
|
+ $result = $query->offset($placeid)->limit($data['num'])->get();
|
|
|
+
|
|
|
+ if (!empty($result)) {
|
|
|
+ $pidResults = $pidQuery->get();
|
|
|
+ if(isset($data['type']) && $data['type'] == 1){
|
|
|
$result = $result->map(function ($item) use ($pidResults) {
|
|
|
$children = $pidResults->where('pid', $item->category_id)->map(function ($child) {
|
|
|
if (!empty($child)) {
|
|
@@ -670,6 +687,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$pidResult = $pidMap->get($record->category_id);
|
|
|
$record->chilid_id = $pidResult->category_id;
|
|
|
$record->chilid_alias = $pidResult->alias;
|
|
|
+ // $record->aLIas_pinyin = $pidResult->aLIas_pinyin;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -2729,6 +2747,33 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取网站名称缩写
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function getWebsiteAdkey(array $data): array
|
|
|
+ {
|
|
|
+
|
|
|
+ $result = PinyinHelper::getFirstLetter($data['website_name']);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有数据", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 静态资源管理-修改图片别名
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function upStaticResource(array $data): array
|
|
|
+ {
|
|
|
+ $result = WebsiteImg::where('id', $data['id'])->update(['img_alias' => $data['img_alias']]);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("修改失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+
|
|
|
+ }
|
|
|
// --自助建站-----------20250522fr----------------------end
|
|
|
|
|
|
/**
|