GeoLogic.php
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
/**
* @remark :
* @name :GeoLogic.php
* @author :lyh
* @method :post
* @time :2025/10/25 11:08
*/
namespace App\Http\Logic\Aside\Geo;
use App\Console\Commands\Geo\GeoQuestionRes;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Geo\GeoArticle;
use App\Models\Geo\GeoConf;
use App\Models\Geo\GeoLink;
use App\Models\Geo\GeoQuestion;
use App\Models\Geo\GeoWritings;
use App\Models\Manage\ManageHr;
use App\Models\Project\DeployBuild;
use App\Models\Project\KeywordPrefix;
use App\Models\Project\Project;
/**
* @remark :geo设置
* @name :GeoLogic
* @author :lyh
* @method :post
* @time :2025/10/25 11:08
*/
class GeoLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new GeoConf();
}
/**
* @remark :获取geo设置数据详情
* @name :getCongInfo
* @author :lyh
* @method :post
* @time :2025/10/25 11:10
*/
public function getCongInfo($project_id)
{
$projectModel = new Project();
$project_geo_conf = $projectModel->read(['id' => $project_id],['title', 'version', 'geo_status', 'geo_qualify_num']);
$geoConfModel = new GeoConf();
$geo_conf = $geoConfModel->read(['project_id' => $project_id]);
$deployModel = new DeployBuild();
$seo_plan = $deployModel->getValue(['project_id'=>$project_id],'seo_plan');
$seo_plan_name = ($projectModel::seoMap()[$seo_plan]) ?? '无选择';
$geo_conf['seo_plan_name'] = $seo_plan_name;
if($geo_conf === false){//数据未初始化
$geo_conf = [
'project_id' => $project_id, 'manager_id'=>0, 'company'=>$project_geo_conf['title'], 'brand'=>'', 'description'=>'','seo_plan_name'=>$seo_plan_name
];
}
//负责人集合
$geo_manage_list = $geoConfModel->geoManage();
// // geo配置管理员,已经移除管理员列表,补充管理员信息
// if ($geo_conf && isset($geo_conf['manager_id']) && empty($geo_manage_list[$geo_conf['manager_id']])) {
// $manage = ManageHr::where(['id' => $geo_conf['manager_id']])->pluck('name', 'id')->toArray();
// $geo_manage_list = array_merge($geo_manage_list, $manage);
// }
$result = [
'project_geo_conf' => $project_geo_conf,
'geo_conf' => $geo_conf,
'geo_manage_list' => $geo_manage_list,
'geo_keyword' => [
'prefix' => KeywordPrefix::getKeyword($project_id, KeywordPrefix::TYPE_GEO_PREFIX),
'suffix' => KeywordPrefix::getKeyword($project_id, KeywordPrefix::TYPE_GEO_SUFFIX),
],
];
return $this->success($result);
}
/**
* @remark :保存数据详情
* @name :saveCongInfo
* @author :lyh
* @method :post
* @time :2025/10/25 11:14
* @param->gl_geo_conf : project_id->项目id;manager_id->管理员id;company->公司名称;brand->品牌名;description->描述(必传)
* @param :prefix->前缀;suffix->后缀(非必传)
* @param->gl_project : geo_status->开启/关闭状态 geo_qualify_num->达标数量
*/
public function saveConfig($param)
{
$projectModel = new Project();
$projectModel->edit(['geo_status'=>$param['geo_status'],'geo_qualify_num'=>$param['geo_qualify_num']],['id'=>$param['project_id']]);
try {
unset($param['geo_status'],$param['geo_qualify_num']);//无需保存
$info = $this->model->read(['project_id' => $param['project_id']]);
if($info === false){
$id = $this->model->addReturnId($param);
}else{
$id = $param['id'];
$this->model->edit($param,['id'=>$info['id']]);
}
} catch (\Exception $e) {
$this->fail('配置保存失败, error:' . $e->getMessage());
}
return $this->success(['id'=>$id]);
}
/**
* @remark :获取统计数据
* @name :getCount
* @author :lyh
* @method :post
* @time :2025/10/30 10:39
*/
public function getCount()
{
//获取问题数量
$geo_question_count = GeoQuestion::selectRaw('SUM(JSON_LENGTH(question)) as total_count')->where('project_id',$this->param['project_id'])->value('total_count');
if(empty($geo_question_count)){
$geo_question_count = 0;
}
$geo_pr_count = GeoLink::where('project_id',$this->param['project_id'])->where('type',GeoLink::TYPE_NEWS)->count();
$geo_link_count = GeoLink::where('project_id',$this->param['project_id'])->where('type',GeoLink::TYPE_LINK)->count();
$geo_writings_count = GeoWritings::where('project_id',$this->param['project_id'])->count();
$geo_writings_count += GeoArticle::where('project_id',$this->param['project_id'])->count();
return $this->success(['geo_writings_count'=>$geo_writings_count,'geo_pr_count'=>$geo_pr_count,'geo_question_count'=>$geo_question_count,'geo_link_count'=>$geo_link_count]);
}
}