|
@@ -147,6 +147,10 @@ class WebsiteService implements WebsiteServiceInterface
|
|
*/
|
|
*/
|
|
public function updateWebsite(int $id, array $data): array
|
|
public function updateWebsite(int $id, array $data): array
|
|
{
|
|
{
|
|
|
|
+ $website = Website::where('id', $id)->first();
|
|
|
|
+ if (empty($website)) {
|
|
|
|
+ return Result::error("网站不存在", 0);
|
|
|
|
+ }
|
|
$insertData = [
|
|
$insertData = [
|
|
'website_name' => $data['website_name'],
|
|
'website_name' => $data['website_name'],
|
|
'logo' => $data['logo'] ?? '',
|
|
'logo' => $data['logo'] ?? '',
|
|
@@ -168,19 +172,63 @@ class WebsiteService implements WebsiteServiceInterface
|
|
if (!empty($web_templsate) && $web_templsate['status'] == 2) {
|
|
if (!empty($web_templsate) && $web_templsate['status'] == 2) {
|
|
return Result::error("此网站已应用,不可修改基本信息", 0);
|
|
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);
|
|
|
|
- } else {
|
|
|
|
|
|
+
|
|
|
|
+ Db::beginTransaction();
|
|
|
|
+ try{
|
|
|
|
+ if($data['ad_key'] != $website['ad_key']){
|
|
|
|
+ $web = Website::where(function ($query) use ($data) {
|
|
|
|
+ $query->where('id','!=', $data['id'])
|
|
|
|
+ ->where('ad_key', $data['ad_key']);
|
|
|
|
+ })->first();
|
|
|
|
+ if (!empty($web)) {
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return Result::error("网站名称简写重复,请填写", 0);
|
|
|
|
+ }
|
|
|
|
+ $ad_place = AdPlace::where('website_id', $data['id'])->select('ad_tag','id')->get()->toArray();
|
|
|
|
+ if (!empty($ad_place)) {
|
|
|
|
+ foreach($ad_place as $key => $val){
|
|
|
|
+ $ad_keys = explode('_', $val['ad_tag']);
|
|
|
|
+ $ad_keys[0] = $data['ad_key'];
|
|
|
|
+ $ad_place[$key]['ad_tag'] = implode('_', $ad_keys);
|
|
|
|
+
|
|
|
|
+ // $up_adtags = AdPlace::where('id', $val['id'])->update(['ad_tag' => $ad_tags[$key]]);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ $up_adtags = AdPlace::upsert($ad_place, ['id'], ['ad_tag']);
|
|
|
|
+
|
|
|
|
+ if(empty($up_adtags)){
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return Result::error('广告位标识同步失败', 0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ $template = WebsiteTemplate::where('website_id', $data['id'])->first();
|
|
|
|
+ if (!empty($template)) {
|
|
|
|
+ // Eloquent 没有 replace 方法,推测你可能是想替换模板中的字符串,假设是更新 content 字段
|
|
|
|
+ $uptemplate = WebsiteTemplate::where('website_id', $data['id'])->update([
|
|
|
|
+ 'template_data' => DB::raw("REPLACE(template_data, '{$website['ad_key']}', '{$data['ad_key']}')")
|
|
|
|
+ ]);
|
|
|
|
+ if(empty($uptemplate)){
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return Result::error("更新模板失败!", 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ // return Result::success($UP_template);
|
|
|
|
+
|
|
|
|
+ $result = Website::where('id', $data['id'])->update($insertData);
|
|
|
|
+ if(empty($result)){
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return Result::error("更新网站失败!", 0);
|
|
|
|
+ }
|
|
|
|
+ Db::commit();
|
|
return Result::success("更新成功");
|
|
return Result::success("更新成功");
|
|
|
|
+
|
|
|
|
+ }catch(\Exception $e){
|
|
|
|
+ Db::rollBack();
|
|
|
|
+ return Result::error($e->getMessage(), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
@@ -2089,6 +2137,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
$join->on('website_column.pid', '=', 'parent_column.id')
|
|
$join->on('website_column.pid', '=', 'parent_column.id')
|
|
->where('website_column.pid', 2);
|
|
->where('website_column.pid', 2);
|
|
})
|
|
})
|
|
|
|
+ ->whereRaw('JSON_CONTAINS(website_column_arr_id,?)', [2])
|
|
->select(
|
|
->select(
|
|
"website_template_info.id",
|
|
"website_template_info.id",
|
|
"template_class.name",
|
|
"template_class.name",
|
|
@@ -2154,14 +2203,14 @@ class WebsiteService implements WebsiteServiceInterface
|
|
// 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
|
|
// 获取此网站的底部导航 类型 type: 0:内容型底部导航(只有一条详情内容);1:列表型底部导航(可以有多条详情内容)
|
|
$foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
$foot_type = FooterCategory::where('website_id', $data['website_id'])->pluck('type')->toArray();
|
|
if (empty($foot_type)) {
|
|
if (empty($foot_type)) {
|
|
- return Result::error("请先关联底部导航池!", 0);
|
|
|
|
|
|
+ return Result::error("请先关联单页!", 0);
|
|
}
|
|
}
|
|
// if (!in_array(1, $foot_type) ) {
|
|
// if (!in_array(1, $foot_type) ) {
|
|
// $missingTypes[] = "列表型底部导航";
|
|
// $missingTypes[] = "列表型底部导航";
|
|
// }
|
|
// }
|
|
- if (!in_array(0, $foot_type)) {
|
|
|
|
- $missingTypes[] = "内容型底部导航";
|
|
|
|
- }
|
|
|
|
|
|
+ if (!in_array(0, $foot_type) ) {
|
|
|
|
+ $missingTypes[] = "单页(详情)";
|
|
|
|
+ }
|
|
if (!empty($missingTypes)) {
|
|
if (!empty($missingTypes)) {
|
|
$errorMessage = "请先添加" . $missingTypes . "!";
|
|
$errorMessage = "请先添加" . $missingTypes . "!";
|
|
return Result::error($errorMessage, 0);
|
|
return Result::error($errorMessage, 0);
|
|
@@ -2202,6 +2251,11 @@ class WebsiteService implements WebsiteServiceInterface
|
|
if (!empty($order)) {
|
|
if (!empty($order)) {
|
|
return Result::error("此网站的广告位正在使用中,暂不可编辑!", 0);
|
|
return Result::error("此网站的广告位正在使用中,暂不可编辑!", 0);
|
|
}
|
|
}
|
|
|
|
+ $check = $this->checkWebsiteBuild($data);
|
|
|
|
+ if($check['code'] != 200){
|
|
|
|
+ return Result::error($check['message'], 0);
|
|
|
|
+ }
|
|
|
|
+ // return Result::success($check);
|
|
if ($result['page_type']) {
|
|
if ($result['page_type']) {
|
|
$result['page_type'] = json_decode($result['page_type'], true);
|
|
$result['page_type'] = json_decode($result['page_type'], true);
|
|
return Result::success('网站编辑验证通过!');
|
|
return Result::success('网站编辑验证通过!');
|
|
@@ -2247,7 +2301,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
return Result::error("修改失败!", 0);
|
|
return Result::error("修改失败!", 0);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- return Result::error("请先选择首页和底部导航详情页!", 0);
|
|
|
|
|
|
+ return Result::error("请先选择首页和单页(详情)!", 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (empty($result)) {
|
|
if (empty($result)) {
|
|
@@ -3534,4 +3588,37 @@ class WebsiteService implements WebsiteServiceInterface
|
|
return Result::error($e->getMessage(), 0);
|
|
return Result::error($e->getMessage(), 0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * 删除网站url
|
|
|
|
+ * @param array $data
|
|
|
|
+ * @return array
|
|
|
|
+ */
|
|
|
|
+ public function delWebsiteUrl(array $data): array{
|
|
|
|
+ try {
|
|
|
|
+ $wensiteInfo = Website::where(["id" => $data['website_id']])->first();
|
|
|
|
+ if (empty($wensiteInfo)) {
|
|
|
|
+ return Result::error("找不到该网站", 0);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $websiteUrlArray = [];
|
|
|
|
+ if (!empty($wensiteInfo->website_url)) {
|
|
|
|
+ $decoded = json_decode((string) $wensiteInfo->website_url, true);
|
|
|
|
+ $websiteUrlArray = is_array($decoded) ? $decoded : [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 从数组中按值删除对应的 URL
|
|
|
|
+ $index = array_search($data['website_url'] ?? null, $websiteUrlArray, true);
|
|
|
|
+ if ($index !== false) {
|
|
|
|
+ unset($websiteUrlArray[$index]);
|
|
|
|
+ // 重新索引,保持为连续的 JSON 数组
|
|
|
|
+ $websiteUrlArray = array_values($websiteUrlArray);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $newWebsiteUrlJson = json_encode($websiteUrlArray, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
|
|
+ Website::where(["id" => $data['website_id']])->update(["website_url" => $newWebsiteUrlJson]);
|
|
|
|
+ return Result::success([]);
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
+ return Result::error($e->getMessage(), 0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|