作者 赵彬吉

update

<?php
namespace App\Http\Controllers\Aside;
use App\Http\Logic\Aside\CollectLogic;
/**
* 提供给AICC采集
* Class CollectController
* @package App\Http\Controllers\Aside
* @author zbj
* @date 2023/11/10
*/
class CollectController extends BaseController
{
/**
* @author zbj
* @date 2023/11/10
*/
public function index(CollectLogic $collectLogic)
{
$data = $collectLogic->collect_data();
return $this->success($data);
}
}
... ...
... ... @@ -782,7 +782,7 @@ class ProjectController extends BaseController
'project_id.required' => 'project_id不能为空',
]);
$token = $logic->getAiccToken($this->map);
$token = $logic->getSiteToken($this->map);
$this->response('success',Code::SUCCESS,['site_token' => $token]);
... ...
<?php
namespace App\Http\Logic\Aside;
use App\Helper\Arr;
use App\Http\Logic\Logic;
use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\News\News;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
/**
* Class CollectLogic
* @package App\Http\Logic\Aside
* @author zbj
* @date 2023/11/10
*/
class CollectLogic extends Logic
{
protected $project;
protected $domain;
protected $type;
protected $page_size = 100;
public function __construct()
{
$this->checkAuth();
}
/**
* 校验权限
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
* @author zbj
* @date 2023/11/10
*/
public function checkAuth()
{
$request = request();
$site_token = $request->header('site-token');
$domain = $request->input('domain');
if (!$site_token) {
$this->fail('参数异常');
}
$this->project = Project::where('site_token', $site_token)->first();
if (!$this->project) {
$this->fail('授权码无效');
}
$domain_info = DomainInfo::where('project_id', $this->project->id)->where('domain', $domain)->first();
if (!$domain_info) {
$this->fail('域名不匹配');
}
$this->domain = 'https://' . $domain_info['domain'] . '/';
$this->type = $request->input('type', '');
}
public function collect_data()
{
ProjectServer::useProject($this->project->id);
$action = $this->type;
return $this->$action();
}
public function __call($name, $param)
{
return [];
}
public function product()
{
$this->model = new Product();
$where[] = ['status' => Product::STATUS_ON];
$sort = ['sort' => 'desc'];
$columns = ['title', 'content', 'gallery', 'seo_mate', 'intro', 'route', 'keyword_id'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
//关键词标签 没有就取seo 键词
if($item['keyword_id']){
$keyword = Keyword::whereIn('id', $item['keyword_id'])->pluck('title')->toArray();
if($keyword){
$keyword = implode(',', $keyword);
}
}
$keyword = $keyword ?: ($item['seo_mate']['keyword'] ?? '');
$data[] = [
'title' => $item['title'],
'url' => $this->domain . $item['route'],
'keywords' => $keyword,
'description' => strip_tags($item['intro']?:''),
'content' => strip_tags($item['content'] ?: ''),
'img' => array_column($item['gallery'] ?: [], 'url')
];
}
$list['list'] = $data;
return $list;
}
public function news()
{
$this->model = new News();
$where[] = ['status' => News::STATUS_ONE];
$sort = ['sort' => 'desc'];
$columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
$data[] = [
'title' => $item['name'],
'url' => $this->domain . $item['url'],
'keywords' => $item['seo_keywords'],
'description' => strip_tags($item['remark']?:''),
'content' => strip_tags($item['text'] ?: ''),
'img' => $item['image'] ?:''
];
}
$list['list'] = $data;
return $list;
}
public function blog()
{
$this->model = new Blog();
$where[] = ['status' => Blog::STATUS_ONE];
$sort = ['sort' => 'desc'];
$columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
$list = self::getList($where,$sort, $columns, $this->page_size);
$data =[];
foreach ($list['list'] as $item){
$data[] = [
'title' => $item['name'],
'url' => $this->domain . $item['url'],
'keywords' => $item['seo_keywords'],
'description' => strip_tags($item['remark']?:''),
'content' => strip_tags($item['text'] ?: ''),
'img' => $item['image'] ?:''
];
}
$list['list'] = $data;
return $list;
}
}
... ...
... ... @@ -651,6 +651,7 @@ class ProjectLogic extends BaseLogic
$query->select('*')->from("{$name}");
}
);
if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
}
... ... @@ -659,16 +660,16 @@ class ProjectLogic extends BaseLogic
}
/**
* 获取AICC采集数据接口token
* 对外接口token
* @param $data
* @return string
* @author zbj
* @date 2023/11/10
*/
public function getAiccToken($data){
public function getSiteToken($data){
$project = $this->getCacheInfo($data['project_id']);
if(empty($project['site_token']) || !empty($data['refresh'])){
$token = strtolower(Str::random() . base64_encode("globalso_v6"));
$token = strtolower(base64_encode("6.0") . md5('project_' . $data['project_id'] . '_' . time()));
$project->site_token = $token;
$project->save();
}
... ...
... ... @@ -340,6 +340,8 @@ Route::group([], function () {
// 提供模板 提单后台查看
Route::any('get_template_list', [Aside\Template\ATemplateController::class, 'getTemplateList'])->name('admin.get_template_list');
Route::any('get_template_detail', [Aside\Template\ATemplateController::class, 'getTemplateDetail'])->name('admin.get_template_detail');
Route::any('/collect', [Aside\CollectController::class, 'index'])->name('admin.collect');
});
... ...