作者 赵彬吉

update

  1 +<?php
  2 +
  3 +namespace App\Http\Controllers\Aside;
  4 +
  5 +use App\Http\Logic\Aside\CollectLogic;
  6 +
  7 +
  8 +/**
  9 + * 提供给AICC采集
  10 + * Class CollectController
  11 + * @package App\Http\Controllers\Aside
  12 + * @author zbj
  13 + * @date 2023/11/10
  14 + */
  15 +class CollectController extends BaseController
  16 +{
  17 + /**
  18 + * @author zbj
  19 + * @date 2023/11/10
  20 + */
  21 + public function index(CollectLogic $collectLogic)
  22 + {
  23 + $data = $collectLogic->collect_data();
  24 + return $this->success($data);
  25 + }
  26 +}
@@ -782,7 +782,7 @@ class ProjectController extends BaseController @@ -782,7 +782,7 @@ class ProjectController extends BaseController
782 'project_id.required' => 'project_id不能为空', 782 'project_id.required' => 'project_id不能为空',
783 ]); 783 ]);
784 784
785 - $token = $logic->getAiccToken($this->map); 785 + $token = $logic->getSiteToken($this->map);
786 786
787 $this->response('success',Code::SUCCESS,['site_token' => $token]); 787 $this->response('success',Code::SUCCESS,['site_token' => $token]);
788 788
  1 +<?php
  2 +
  3 +namespace App\Http\Logic\Aside;
  4 +
  5 +use App\Helper\Arr;
  6 +use App\Http\Logic\Logic;
  7 +use App\Models\Blog\Blog;
  8 +use App\Models\Domain\DomainInfo;
  9 +use App\Models\News\News;
  10 +use App\Models\Product\Keyword;
  11 +use App\Models\Product\Product;
  12 +use App\Models\Project\Project;
  13 +use App\Services\ProjectServer;
  14 +
  15 +
  16 +/**
  17 + * Class CollectLogic
  18 + * @package App\Http\Logic\Aside
  19 + * @author zbj
  20 + * @date 2023/11/10
  21 + */
  22 +class CollectLogic extends Logic
  23 +{
  24 + protected $project;
  25 + protected $domain;
  26 + protected $type;
  27 + protected $page_size = 100;
  28 +
  29 + public function __construct()
  30 + {
  31 + $this->checkAuth();
  32 + }
  33 +
  34 + /**
  35 + * 校验权限
  36 + * @throws \App\Exceptions\AsideGlobalException
  37 + * @throws \App\Exceptions\BsideGlobalException
  38 + * @author zbj
  39 + * @date 2023/11/10
  40 + */
  41 + public function checkAuth()
  42 + {
  43 + $request = request();
  44 + $site_token = $request->header('site-token');
  45 + $domain = $request->input('domain');
  46 + if (!$site_token) {
  47 + $this->fail('参数异常');
  48 + }
  49 + $this->project = Project::where('site_token', $site_token)->first();
  50 + if (!$this->project) {
  51 + $this->fail('授权码无效');
  52 + }
  53 + $domain_info = DomainInfo::where('project_id', $this->project->id)->where('domain', $domain)->first();
  54 + if (!$domain_info) {
  55 + $this->fail('域名不匹配');
  56 + }
  57 + $this->domain = 'https://' . $domain_info['domain'] . '/';
  58 + $this->type = $request->input('type', '');
  59 + }
  60 +
  61 + public function collect_data()
  62 + {
  63 + ProjectServer::useProject($this->project->id);
  64 + $action = $this->type;
  65 + return $this->$action();
  66 + }
  67 +
  68 + public function __call($name, $param)
  69 + {
  70 + return [];
  71 + }
  72 +
  73 +
  74 + public function product()
  75 + {
  76 + $this->model = new Product();
  77 + $where[] = ['status' => Product::STATUS_ON];
  78 + $sort = ['sort' => 'desc'];
  79 + $columns = ['title', 'content', 'gallery', 'seo_mate', 'intro', 'route', 'keyword_id'];
  80 + $list = self::getList($where,$sort, $columns, $this->page_size);
  81 + $data =[];
  82 + foreach ($list['list'] as $item){
  83 + //关键词标签 没有就取seo 键词
  84 + if($item['keyword_id']){
  85 + $keyword = Keyword::whereIn('id', $item['keyword_id'])->pluck('title')->toArray();
  86 + if($keyword){
  87 + $keyword = implode(',', $keyword);
  88 + }
  89 + }
  90 + $keyword = $keyword ?: ($item['seo_mate']['keyword'] ?? '');
  91 + $data[] = [
  92 + 'title' => $item['title'],
  93 + 'url' => $this->domain . $item['route'],
  94 + 'keywords' => $keyword,
  95 + 'description' => strip_tags($item['intro']?:''),
  96 + 'content' => strip_tags($item['content'] ?: ''),
  97 + 'img' => array_column($item['gallery'] ?: [], 'url')
  98 + ];
  99 + }
  100 + $list['list'] = $data;
  101 + return $list;
  102 + }
  103 +
  104 + public function news()
  105 + {
  106 + $this->model = new News();
  107 + $where[] = ['status' => News::STATUS_ONE];
  108 + $sort = ['sort' => 'desc'];
  109 + $columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
  110 + $list = self::getList($where,$sort, $columns, $this->page_size);
  111 + $data =[];
  112 + foreach ($list['list'] as $item){
  113 + $data[] = [
  114 + 'title' => $item['name'],
  115 + 'url' => $this->domain . $item['url'],
  116 + 'keywords' => $item['seo_keywords'],
  117 + 'description' => strip_tags($item['remark']?:''),
  118 + 'content' => strip_tags($item['text'] ?: ''),
  119 + 'img' => $item['image'] ?:''
  120 + ];
  121 + }
  122 + $list['list'] = $data;
  123 + return $list;
  124 + }
  125 +
  126 + public function blog()
  127 + {
  128 + $this->model = new Blog();
  129 + $where[] = ['status' => Blog::STATUS_ONE];
  130 + $sort = ['sort' => 'desc'];
  131 + $columns = ['name', 'text', 'image', 'seo_keywords', 'remark', 'url'];
  132 + $list = self::getList($where,$sort, $columns, $this->page_size);
  133 + $data =[];
  134 + foreach ($list['list'] as $item){
  135 + $data[] = [
  136 + 'title' => $item['name'],
  137 + 'url' => $this->domain . $item['url'],
  138 + 'keywords' => $item['seo_keywords'],
  139 + 'description' => strip_tags($item['remark']?:''),
  140 + 'content' => strip_tags($item['text'] ?: ''),
  141 + 'img' => $item['image'] ?:''
  142 + ];
  143 + }
  144 + $list['list'] = $data;
  145 + return $list;
  146 + }
  147 +}
@@ -651,6 +651,7 @@ class ProjectLogic extends BaseLogic @@ -651,6 +651,7 @@ class ProjectLogic extends BaseLogic
651 $query->select('*')->from("{$name}"); 651 $query->select('*')->from("{$name}");
652 } 652 }
653 ); 653 );
  654 +
654 if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) { 655 if (Schema::connection('custom_mysql')->hasColumn($table, 'project_id')) {
655 DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]); 656 DB::connection('custom_mysql')->table($table)->update(['project_id' => $news_project_id]);
656 } 657 }
@@ -659,16 +660,16 @@ class ProjectLogic extends BaseLogic @@ -659,16 +660,16 @@ class ProjectLogic extends BaseLogic
659 } 660 }
660 661
661 /** 662 /**
662 - * 获取AICC采集数据接口token 663 + * 对外接口token
663 * @param $data 664 * @param $data
664 * @return string 665 * @return string
665 * @author zbj 666 * @author zbj
666 * @date 2023/11/10 667 * @date 2023/11/10
667 */ 668 */
668 - public function getAiccToken($data){ 669 + public function getSiteToken($data){
669 $project = $this->getCacheInfo($data['project_id']); 670 $project = $this->getCacheInfo($data['project_id']);
670 if(empty($project['site_token']) || !empty($data['refresh'])){ 671 if(empty($project['site_token']) || !empty($data['refresh'])){
671 - $token = strtolower(Str::random() . base64_encode("globalso_v6")); 672 + $token = strtolower(base64_encode("6.0") . md5('project_' . $data['project_id'] . '_' . time()));
672 $project->site_token = $token; 673 $project->site_token = $token;
673 $project->save(); 674 $project->save();
674 } 675 }
@@ -340,6 +340,8 @@ Route::group([], function () { @@ -340,6 +340,8 @@ Route::group([], function () {
340 // 提供模板 提单后台查看 340 // 提供模板 提单后台查看
341 Route::any('get_template_list', [Aside\Template\ATemplateController::class, 'getTemplateList'])->name('admin.get_template_list'); 341 Route::any('get_template_list', [Aside\Template\ATemplateController::class, 'getTemplateList'])->name('admin.get_template_list');
342 Route::any('get_template_detail', [Aside\Template\ATemplateController::class, 'getTemplateDetail'])->name('admin.get_template_detail'); 342 Route::any('get_template_detail', [Aside\Template\ATemplateController::class, 'getTemplateDetail'])->name('admin.get_template_detail');
  343 +
  344 + Route::any('/collect', [Aside\CollectController::class, 'index'])->name('admin.collect');
343 }); 345 });
344 346
345 347