|
@@ -147,6 +147,10 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
*/
|
|
|
public function updateWebsite(int $id, array $data): array
|
|
|
{
|
|
|
+ $website = Website::where('id', $id)->first();
|
|
|
+ if (empty($website)) {
|
|
|
+ return Result::error("网站不存在", 0);
|
|
|
+ }
|
|
|
$insertData = [
|
|
|
'website_name' => $data['website_name'],
|
|
|
'logo' => $data['logo'] ?? '',
|
|
@@ -163,25 +167,64 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
'suffix' => $data['suffix'] ?? "",
|
|
|
'ad_key' => $data['ad_key'] ?? "",
|
|
|
];
|
|
|
- $web_templsate = WebsiteTemplateInfo::where('website_id', $data['id'])->first();
|
|
|
+ // $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);
|
|
|
- } else {
|
|
|
- return Result::success("更新成功");
|
|
|
+ // if (!empty($web_templsate) && $web_templsate['status'] == 2) {
|
|
|
+ // return Result::error("此网站已应用,不可修改基本信息", 0);
|
|
|
+ // }
|
|
|
+
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -560,46 +603,47 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$where[] = ['ad_place.ad_tag', 'like', '%' . $data['ad_tag'] . '%'];
|
|
|
// return Result::success($where);
|
|
|
$result = AdPlace::where($where)
|
|
|
- ->leftJoin("ad", function ($join) use ($now) {
|
|
|
- $join->on("ad.pid", "=", "ad_place.id")
|
|
|
- ->where('ad.status', 1)
|
|
|
- ->where('ad.fromtime', '<=', $now)
|
|
|
- ->where('ad.totime', '>=', $now);
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'ad_place.name as place_name',
|
|
|
- 'ad_place.thumb',
|
|
|
- 'ad_place.ad_tag',
|
|
|
- 'ad_place.introduce',
|
|
|
- 'ad.name as ad_name',
|
|
|
- 'ad.image_src',
|
|
|
- 'ad.image_url',
|
|
|
- 'ad.image_alt',
|
|
|
- 'ad_place.ad_url')
|
|
|
- ->get()->all();
|
|
|
-
|
|
|
- }else{
|
|
|
+ ->leftJoin("ad", function ($join) use ($now) {
|
|
|
+ $join->on("ad.pid", "=", "ad_place.id")
|
|
|
+ ->where('ad.status', 1)
|
|
|
+ ->where('ad.fromtime', '<=', $now)
|
|
|
+ ->where('ad.totime', '>=', $now);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'ad_place.name as place_name',
|
|
|
+ 'ad_place.thumb',
|
|
|
+ 'ad_place.ad_tag',
|
|
|
+ 'ad_place.introduce',
|
|
|
+ 'ad.name as ad_name',
|
|
|
+ 'ad.image_src',
|
|
|
+ 'ad.image_url',
|
|
|
+ 'ad.image_alt',
|
|
|
+ 'ad_place.ad_url'
|
|
|
+ )
|
|
|
+ ->get()->all();
|
|
|
+ } else {
|
|
|
$now = Carbon::now()->format('Y-m-d H:i:s'); // 获取当前时间
|
|
|
// return Result::success($where);
|
|
|
$result = AdPlace::where($where)
|
|
|
- ->where('ad_place.website_id',$data['website_id'])
|
|
|
- ->leftJoin("ad", function ($join) use ($now) {
|
|
|
- $join->on("ad.pid", "=", "ad_place.id")
|
|
|
- ->where('ad.status', 1)
|
|
|
- ->where('ad.fromtime', '<=', $now)
|
|
|
- ->where('ad.totime', '>=', $now);
|
|
|
- })
|
|
|
- ->select(
|
|
|
- 'ad_place.name as place_name',
|
|
|
- 'ad_place.thumb',
|
|
|
- 'ad_place.ad_tag',
|
|
|
- 'ad_place.introduce',
|
|
|
- 'ad.name as ad_name',
|
|
|
- 'ad.image_src',
|
|
|
- 'ad.image_url',
|
|
|
- 'ad.image_alt',
|
|
|
- 'ad_place.ad_url',)
|
|
|
- ->get()->all();
|
|
|
+ ->where('ad_place.website_id', $data['website_id'])
|
|
|
+ ->leftJoin("ad", function ($join) use ($now) {
|
|
|
+ $join->on("ad.pid", "=", "ad_place.id")
|
|
|
+ ->where('ad.status', 1)
|
|
|
+ ->where('ad.fromtime', '<=', $now)
|
|
|
+ ->where('ad.totime', '>=', $now);
|
|
|
+ })
|
|
|
+ ->select(
|
|
|
+ 'ad_place.name as place_name',
|
|
|
+ 'ad_place.thumb',
|
|
|
+ 'ad_place.ad_tag',
|
|
|
+ 'ad_place.introduce',
|
|
|
+ 'ad.name as ad_name',
|
|
|
+ 'ad.image_src',
|
|
|
+ 'ad.image_url',
|
|
|
+ 'ad.image_alt',
|
|
|
+ 'ad_place.ad_url',
|
|
|
+ )
|
|
|
+ ->get()->all();
|
|
|
// return Result::error("请选择广告位!",0);
|
|
|
}
|
|
|
if (empty($result)) {
|
|
@@ -1422,6 +1466,43 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
+ //处理所有path
|
|
|
+ var_dump($data, '--------111----');
|
|
|
+ $website_id = $data['website_id'];
|
|
|
+ //获取所有数据
|
|
|
+ $result = WebsiteCategory::where(['website_id' => $website_id, 'path' => NULL])->get()->toArray();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有数据", 0);
|
|
|
+ }
|
|
|
+ //处理path
|
|
|
+ foreach ($result as $key => $value) {
|
|
|
+ $array_category_arr_id = json_decode($value['category_arr_id'], true);
|
|
|
+ $result[$key]['path'] = WebsiteCategory::where('website_id', $website_id)
|
|
|
+ ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
|
|
|
+ ->whereIn('category_id', $array_category_arr_id)
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ }
|
|
|
+ //批量更新数据path
|
|
|
+ $updateData = [];
|
|
|
+ foreach ($result as $item) {
|
|
|
+ $updateData[] = [
|
|
|
+ 'id' => $item['id'],
|
|
|
+ 'path' => $item['path']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //批量更新
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($result as $item) {
|
|
|
+ WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ throw $e; // 或者返回错误信息
|
|
|
+ }
|
|
|
+
|
|
|
Db::commit();
|
|
|
return Result::success();
|
|
|
} catch (\Throwable $ex) {
|
|
@@ -1528,7 +1609,91 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::error("更新失败", 0);
|
|
|
}
|
|
|
}
|
|
|
- //处理所有数据
|
|
|
+ //处理所有path
|
|
|
+ if (isset($data['pathone']) && $data['pathone'] == 'pathone') {
|
|
|
+ var_dump($data, '--------111----');
|
|
|
+ $website_id = $data['website_id'];
|
|
|
+ //获取所有数据
|
|
|
+ $result = WebsiteCategory::where(['website_id' => $website_id, 'path' => NULL])->get()->toArray();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有数据", 0);
|
|
|
+ }
|
|
|
+ //处理path
|
|
|
+ foreach ($result as $key => $value) {
|
|
|
+ $array_category_arr_id = json_decode($value['category_arr_id'], true);
|
|
|
+ $result[$key]['path'] = WebsiteCategory::where('website_id', $website_id)
|
|
|
+ ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
|
|
|
+ ->whereIn('category_id', $array_category_arr_id)
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ }
|
|
|
+ //批量更新数据path
|
|
|
+ $updateData = [];
|
|
|
+ foreach ($result as $item) {
|
|
|
+ $updateData[] = [
|
|
|
+ 'id' => $item['id'],
|
|
|
+ 'path' => $item['path']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ //批量更新
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($result as $item) {
|
|
|
+ WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ throw $e; // 或者返回错误信息
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['pathall']) && $data['pathall'] == 'pathall') {
|
|
|
+ //获取所有数据
|
|
|
+ $result = WebsiteCategory::where(['path' => NULL])->get()->toArray();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有数据", 0);
|
|
|
+ }
|
|
|
+ //处理path
|
|
|
+ foreach ($result as $key => $value) {
|
|
|
+ if (empty($value['category_arr_id'])) continue;
|
|
|
+ if ($key >= 4) { // 改为 >= 4 如果你想处理最多4个元素
|
|
|
+ // break;
|
|
|
+ }
|
|
|
+ $array_category_arr_id = json_decode($value['category_arr_id'], true);
|
|
|
+ $result[$key]['path'] = WebsiteCategory::where('website_id', $value['website_id'])
|
|
|
+ ->orderByRaw('FIELD(category_id, ' . implode(',', $array_category_arr_id) . ')')
|
|
|
+ ->whereIn('category_id', $array_category_arr_id)
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ }
|
|
|
+ //批量更新数据path
|
|
|
+ $updateData = [];
|
|
|
+ foreach ($result as $item) {
|
|
|
+ $updateData[] = [
|
|
|
+ 'id' => $item['id'],
|
|
|
+ 'category_arr_id' => $item['category_arr_id'],
|
|
|
+ 'path' => $item['path']
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ // var_dump($updateData);
|
|
|
+ // return Result::success($updateData);
|
|
|
+ //批量更新
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ foreach ($result as $item) {
|
|
|
+ WebsiteCategory::where('id', $item['id'])->update(['path' => $item['path']]);
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ DB::rollBack();
|
|
|
+ throw $e; // 或者返回错误信息
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$where = [
|
|
|
'website_id' => $data['website_id'],
|
|
|
'category_id' => $data['category_id'],
|
|
@@ -1538,14 +1703,58 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$aLIas_pinyin = $pinyin->permalink($alias, '');
|
|
|
//从WebsiteCategory取出alis ,并转成拼音存放到aLIas_pinyin
|
|
|
$result = WebsiteCategory::where($where)->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有数据", 0);
|
|
|
+ }
|
|
|
$result = $result->toArray();
|
|
|
//+四位随机字母
|
|
|
$letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
// 打乱字符串顺序并截取前四位
|
|
|
// $randss = substr(str_shuffle($letters), 0, 4);
|
|
|
- if ($data['alias_pinyin'] == '') {
|
|
|
- }
|
|
|
+
|
|
|
$data['aLIas_pinyin'] = $aLIas_pinyin;
|
|
|
+ //数据库先更新一下,再改path
|
|
|
+ WebsiteCategory::where($where)->update(['aLIas_pinyin' => $data['aLIas_pinyin']]);
|
|
|
+ //处理path
|
|
|
+ $category_arr_id = json_decode($result['category_arr_id'], true);
|
|
|
+ //取出来设置path
|
|
|
+ $path = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->orderByRaw('FIELD(category_id, ' . implode(',', $category_arr_id) . ')')
|
|
|
+ ->whereIn('category_id', $category_arr_id)
|
|
|
+ ->pluck('aLIas_pinyin')
|
|
|
+ ->implode('/');
|
|
|
+ $data['path'] = $path;
|
|
|
+ //处理包含此id的所有path
|
|
|
+ // 取出category_arr_id包含此id的所有数据
|
|
|
+ $all_other = WebsiteCategory::where('website_id', $data['website_id'])
|
|
|
+ ->whereJsonContains('category_arr_id', $data['category_id'])
|
|
|
+ ->get();
|
|
|
+ var_dump($all_other, '------------');
|
|
|
+
|
|
|
+ // 遍历所有数据,更新path
|
|
|
+ $newAliasPinyin = $aLIas_pinyin ?? ''; // 添加空值判断
|
|
|
+ $oldAliasPinyin = $result['alias_pinyin'] ?? ''; // 修正键名大小写
|
|
|
+
|
|
|
+ // 收集需要更新的ID和路径
|
|
|
+ $updateData = [];
|
|
|
+ foreach ($all_other as $item) {
|
|
|
+ $newPath = str_replace($oldAliasPinyin, $newAliasPinyin, $item->path);
|
|
|
+ if ($newPath !== $item->path) { // 仅在路径变化时更新
|
|
|
+ $updateData[] = [
|
|
|
+ 'id' => $item->id,
|
|
|
+ 'path' => $newPath
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量更新提高性能
|
|
|
+ if (!empty($updateData)) {
|
|
|
+ // 假设模型对应的数据表为 'table_name',请替换为实际表名
|
|
|
+ Db::table('website_category')->updateOrInsert(
|
|
|
+ ['id' => DB::raw('VALUES(id)')],
|
|
|
+ $updateData
|
|
|
+ );
|
|
|
+ }
|
|
|
|
|
|
$result = WebsiteCategory::where($where)->update($data);
|
|
|
if ($result) {
|
|
@@ -1917,8 +2126,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
public function getWebsiteintel(array $data): array
|
|
|
{
|
|
|
//查询所有网站模板信息
|
|
|
- $query = Website::where('website.status', 1)
|
|
|
- ->leftJoin("website_template_info", "website_template_info.website_id", "website.id")
|
|
|
+ $query = Website::leftJoin("website_template_info", "website_template_info.website_id", "website.id")
|
|
|
->leftJoin("template", "template.template_id", "website_template_info.template_id")
|
|
|
->leftJoin("template_class", "template_class.class_id", "template.template_class_id")
|
|
|
->leftJoin('website_column', 'website_column.id', 'website.website_column_id')
|
|
@@ -1997,9 +2205,9 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
// if (!in_array(1, $foot_type) ) {
|
|
|
// $missingTypes[] = "列表型底部导航";
|
|
|
// }
|
|
|
- if (!in_array(0, $foot_type) ) {
|
|
|
+ if (!in_array(0, $foot_type)) {
|
|
|
$missingTypes[] = "单页(详情)";
|
|
|
- }
|
|
|
+ }
|
|
|
if (!empty($missingTypes)) {
|
|
|
$errorMessage = "请先添加" . $missingTypes . "!";
|
|
|
return Result::error($errorMessage, 0);
|
|
@@ -2035,13 +2243,18 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
if (empty($result)) {
|
|
|
return Result::error("请输入正确的网站id!", 0);
|
|
|
}
|
|
|
+ // 0:未构建 1:未应用 2:已应用
|
|
|
+ if($result['status'] == 2){
|
|
|
+ return Result::error("此网站的模板正在应用中,暂不可编辑!", 0);
|
|
|
+ }
|
|
|
+
|
|
|
// 订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束
|
|
|
$order = Order::where('website_id', $data['website_id'])->where('status', 1)->first();
|
|
|
if (!empty($order)) {
|
|
|
return Result::error("此网站的广告位正在使用中,暂不可编辑!", 0);
|
|
|
}
|
|
|
$check = $this->checkWebsiteBuild($data);
|
|
|
- if($check['code'] != 200){
|
|
|
+ if ($check['code'] != 200) {
|
|
|
return Result::error($check['message'], 0);
|
|
|
}
|
|
|
// return Result::success($check);
|
|
@@ -3383,7 +3596,8 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function delWebsiteUrl(array $data): array{
|
|
|
+ public function delWebsiteUrl(array $data): array
|
|
|
+ {
|
|
|
try {
|
|
|
$wensiteInfo = Website::where(["id" => $data['website_id']])->first();
|
|
|
if (empty($wensiteInfo)) {
|