|
@@ -168,20 +168,63 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
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);
|
|
|
- } 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("更新成功");
|
|
|
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage(), 0);
|
|
|
}
|
|
|
}
|
|
|
/**
|