作者 lyh

gx

... ... @@ -10,7 +10,10 @@
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Product\Keyword;
use App\Models\Project\AggregateKeyword;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class AggregateKeywordLogic extends BaseLogic
{
... ... @@ -22,7 +25,7 @@ class AggregateKeywordLogic extends BaseLogic
}
/**
* @remark :
* @remark :保存关键词
* @name :saveKeyword
* @author :lyh
* @method :post
... ... @@ -34,7 +37,16 @@ class AggregateKeywordLogic extends BaseLogic
$this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$id = $this->model->addReturnId($this->param);
//保存到客户关键词
$keywords = explode("\n", $this->param['keywords']);
if(!empty($keywords)){
ProjectServer::useProject($this->param['project_id']);
$keywordModel = new Keyword();
$keywordModel->saveBKeyword($this->param['keyword'],$keywords);
DB::disconnect('custom_mysql');
}
}
return $this->success(['id'=>$id]);
}
}
... ...
... ... @@ -79,8 +79,8 @@ class KeywordLogic extends BaseLogic
if($info !== false){
return $this->success(['id'=>$info['id']]);
}
$this->param = $this->addHandleParam($this->param);
$id = $this->model->insertGetId($this->param);
$this->param['project_id'] = $this->user['project_id'];
$id = $this->model->addReturnId($this->param);
//路由映射
$route = RouteMap::setRoute($this->param['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$id]);
... ... @@ -93,20 +93,6 @@ class KeywordLogic extends BaseLogic
}
/**
* @remark :添加组装数据
* @name :addHandleParam
* @author :lyh
* @method :post
* @time :2023/11/30 15:00
*/
public function addHandleParam($param){
$param['project_id'] = $this->user['project_id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
return $this->success($param);
}
/**
* @remark :保存数据时参数处理
* @name :handleSaveParam
* @author :lyh
... ... @@ -135,27 +121,11 @@ class KeywordLogic extends BaseLogic
if(!empty($param['seo_title'])){
$param['seo_title'] = ucfirst($param['seo_title']);
}
$param['first_word'] = $this->first_word($param['title']);
$param['first_word'] = $this->model->first_word($param['title']);
return $param;
}
/**
* @remark :获取字符串首字符
* @name :first_word
* @author :lyh
* @method :post
* @time :2024/10/28 10:47
*/
public function first_word($title){
$first_title = mb_substr(strtolower($title), 0, 1);
if (is_numeric($first_title)){
return 0;
}
$string_key = array_search($first_title, $this->model->firstNumWord);
return $string_key ?: 27;
}
/**
* @remark :批量添加关键词任务, 异步处理
* @name :batchAdd
* @author :lyh
... ... @@ -164,20 +134,7 @@ class KeywordLogic extends BaseLogic
*/
public function batchAdd(){
try {
foreach ($this->param['title'] as $k=>$v){
if(empty($v)){
continue;
}
$info = $this->model->read(['title'=>$v],['id']);
if($info === false){
$param['project_id'] = $this->user['project_id'];
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
$param['title'] = $v;
$param['first_word'] = $this->first_word($param['title']);
$this->model->insertGetId($param);
}
}
$this->model->saveBKeyword($this->user['project_id'],$this->param['title']);
}catch (\Exception $e){
$this->fail('保存失败,请联系管理员');
}
... ... @@ -249,7 +206,7 @@ class KeywordLogic extends BaseLogic
if($v){
$keyword_info = $this->model->read(['title'=>$v]);
if(!$keyword_info){
$k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->first_word($v),'project_id'=>$project_id]);
$k_id = $this->model->addReturnId(['title'=>$v,'first_word' => $this->model->first_word($v),'project_id'=>$project_id]);
$route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $k_id, $project_id);
$this->model->edit(['route'=>$route],['id'=>$k_id]);
}else{
... ...
... ... @@ -3,8 +3,13 @@
namespace App\Models\Product;
use App\Helper\Arr;
use App\Helper\Common;
use App\Models\Base;
use App\Models\Com\NoticeLog;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class Keyword extends Base
{
... ... @@ -149,4 +154,44 @@ class Keyword extends Base
}
return $result;
}
/**
* @remark :保存到产品关键词中
* @name :saveBKeyword
* @author :lyh
* @method :post
* @time :2025/3/25 16:28
*/
public function saveBKeyword($project_id,$keywords){
foreach ($keywords as $v){
if(empty($v)){
continue;
}
$info = $this->read(['title'=>$v],['id']);
if($info === false){
$param['project_id'] = $project_id;
$param['title'] = $v;
$param['first_word'] = $this->first_word($param['title']);
$this->addReturnId($param);
}
}
NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
return true;
}
/**
* @remark :获取字符串首字符
* @name :first_word
* @author :lyh
* @method :post
* @time :2025/3/25 16:42
*/
public function first_word($title){
$first_title = mb_substr(strtolower($title), 0, 1);
if (is_numeric($first_title)){
return 0;
}
$string_key = array_search($first_title, $this->model->firstNumWord);
return $string_key ?: 27;
}
}
... ...