Acquisition.php
3.8 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
<?php
/**
* Created by PhpStorm.
* User: ty01
* Date: 2022/3/10
* Time: 14:31
*/
namespace app\api\controller\v1;
use think\Db;
/**
* 文章管理
* Class Acquisition
* @package app\api\controller\core
*/
class Acquisition extends Base
{
/**
* 文章采集入库
*/
public function article()
{
$response = $this->request->param();
$title = $response['title'];//文章标题
$articlecontent = $response['content'];
$url = $response['url'];
$from = $response['source'];
$cjtime = $response['tacq'];
$fwtime = $response['DispatchTime'];
$Sensitive = $response['Sensitive'];
$group_id = $response['group_id'];
$fakeid = $response['fakeid'];//公众号id
$ss = [];
$ids_string = "";
if (!empty($Sensitive)) {
foreach ($Sensitive as $kk=>$vv){
if (!empty($vv)) {
$ids = Db::name("theme_keywords")->where("name", $vv)->column("id");
if (!empty($ids)) {
$ss = array_unique(array_merge($ss, $ids));
}
}
}
if (!empty($ss)) {
$ids_string = implode(",", $ss);
}
$Sensitive = implode(",", $Sensitive);
}
if (empty($title)) {
$this->error("文章标题不能为空");
}
if (empty($articlecontent)) {
$this->error("文章内容不能为空");
}
if (empty($from) || !in_array($from, ['微信', '网站', '论坛', '全部网页', '网络问政', '头条号', '广播电视', '搜狐号', '微博', '视频'])) {
$this->error("文章来源渠道参数异常");
}
$admin_id = Db::name("auth_group_access")->where("group_id", $group_id)->value("uid");//获取角色组下第一层的某个管理id
$data = [
"title" => $title,
"articlecontent" => $articlecontent,
"url" => $url,
"from" => $from,
"cjtime" => $cjtime,
"fwtime" => $fwtime,
"createtime" => time(),
"sensitive" => $Sensitive,
"theme_keywords_ids"=>$ids_string,
"admin_id" => $admin_id ? $admin_id : 1,
"fakeid"=>$fakeid,
];
$ac_id = Db::name("article_acquisition")->insertGetId($data);
if ($ac_id) {
$this->success("数据入库成功", $ac_id);
} else {
$this->error("数据入库失败");
}
}
/**
* 处理敏感词老数据(多个id用逗号隔开)
*/
public function test()
{
$article = Db::name("article_acquisition")->order("id asc")->select();
if (!empty($article)) {
foreach ($article as $k => $v) {
if (!empty($v['sensitive'])) {
$sensitive_array = explode(",", $v['sensitive']);
$ss = [];
foreach ($sensitive_array as $kk => $vv) {
if (!empty($vv)) {
$ids = Db::name("theme_keywords")->where("name", $vv)->column("id");
if (!empty($ids)) {
$ss = array_unique(array_merge($ss, $ids));
}
}
}
if (!empty($ss)) {
$ids_string = "";
$ids_string = implode(",", $ss);
Db::name("article_acquisition")->where("id", $v['id'])->update(["theme_keywords_ids" => $ids_string]);
}
}
}
}
}
}