作者 李宇航

合并分支 'master-server' 到 'master'

Master server



查看合并请求 !633
... ... @@ -89,9 +89,9 @@ class VideoTask extends Command
}
ProjectServer::useProject($task_project->project_id);
if(!empty($task_project->keywords)){
$task_project->keywords = explode(',',trim(',',$task_project->keywords));
$keywords = explode(',',trim(',',$task_project->keywords));
}
$keyword = $this->getProjectKeyword($task_project->number,$task_project->keywords);
$keyword = $this->getProjectKeyword($task_project->number,$keywords ?? []);
// 已经没有需要生成视频的关键词
if (!$keyword) {
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
... ... @@ -176,24 +176,15 @@ class VideoTask extends Command
*/
public function getProjectKeyword($number,$keywords = [])
{
if(!empty($keywords)){
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray();
if(count($keyword_id) == 0){
->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->limit($number)->pluck('id')->toArray();
$need = $number - count($keyword_id);
if ($need > 0) {
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
}else{
$keyword_arr_id = Keyword::where('video', null)->whereNotIn("title", $keywords)->where('route', 'not like', '%-tag')
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number - count($keyword_id))->pluck('id')->toArray();
$keyword_arr_id = array_merge($keyword_id,$keyword_arr_id);
}
}else{
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
->whereNotNull('keyword_content')->orderBy('id','asc')->limit($number)->pluck('id')->toArray();
}
if(count($keyword_arr_id) == 0){
return [];
->whereNotNull('keyword_content')->whereNotIn('id', $keyword_id)->orderBy('id','asc')->limit($need)->pluck('id')->toArray();
}
$keyword_arr_id = array_merge($keyword_id, $keyword_arr_id);
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
return $keyword;
}
... ... @@ -235,7 +226,7 @@ class VideoTask extends Command
}
}
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$thumb = $this->getRecommendAndHotProducts($keyword_id,$project_id);
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
$data = [
'url'=> 'https://' . $domain.'/'.$keywordInfo['route'],
... ... @@ -251,37 +242,43 @@ class VideoTask extends Command
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($route,$project_id): ?array
public function getRecommendAndHotProducts($keyword_id,$project_id): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
if (!empty($productKeyword)){
$productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
$productKeyword = Keyword::where("id",$keyword_id)->first();
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(7)->get();
if (!empty($productsQuery)){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$array_count = count($product_all_id);
if ($array_count > 0) {
$product_id = array_rand($product_all_id, min($array_count, $number - count($productIds)));
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$product_id_key = array_rand($product_all_id, min($array_count, $number - count($productIds)));
foreach ($product_id_key as $value_key){
$project_id_arr = $product_all_id[$value_key];
}
$randomData = Product::whereIn("id", $project_id_arr)->get();
$products = $productsQuery->merge($randomData);
}
}else{
$products = $productsQuery;
}
}else{
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
shuffle($product_all_id);
$number = 40;
$array_count = count($product_all_id);
if ($array_count > 0)
{
$product_id = array_rand($product_all_id, min($array_count, $number-count($productIds)));
$products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$project_id_arr = [];
$product_id_key = array_rand($product_all_id, min($array_count, $number-count($productIds)));
foreach ($product_id_key as $value_key){
$project_id_arr = $product_all_id[$value_key];
}
$products = Product::where("project_id", $project_id)->whereIn("id", $project_id_arr)->get();
}
}
$data = [];
... ... @@ -293,11 +290,11 @@ class VideoTask extends Command
if(count($data) > 13){
break;
}
$keyword_id = implode(',',$item->keyword_id);
if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) {
$keyword_ids = implode(',',$item->keyword_id);
if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
//不包含
$productModel = new Product();
$keyword_id = ','.$keyword_id.',' . $productKeyword->id.',';
$keyword_id = ','.$keyword_ids.',' . $keyword_id.',';
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
}
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
... ...
... ... @@ -874,3 +874,37 @@ function textareaToArr($content, $separator = ','){
return trim($v);
},explode($separator, $content)))));
}
/**
* @remark :字符串
* @name :base62_encode
* @author :lyh
* @method :post
* @time :2024/6/26 10:46
*/
function ip_to_unique_string($ip) {
// 将IP地址转换为数值表示
$ip_number = ip2long($ip);
// 使用哈希函数生成唯一数值
$hash = hash('sha256', $ip_number, false);
$hash_number = hexdec(substr($hash, 0, 15)); // 取前15位作为大整数
// 将哈希值转换为Base62编码
$unique_string = base62_encode($hash_number);
// 确保唯一字符串为6位,如果不足则补齐,超出则截取前6位
$unique_string = str_pad($unique_string, 6, '0', STR_PAD_LEFT);
$unique_string = substr($unique_string, 0, 6);
return $unique_string;
}
function base62_encode($num) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$base = strlen($characters);
$result = '';
while ($num > 0) {
$result = $characters[$num % $base] . $result;
$num = intval($num / $base);
}
return $result;
}
... ...
... ... @@ -30,6 +30,11 @@ class ServersController extends BaseController
}
$serversModel = new ServersModel();
$lists = $serversModel->list($this->map);
foreach ($lists as $k => $v){
if($v['being_number'] >= $v['total']){
unset($lists[$k]);
}
}
$this->response('success',Code::SUCCESS,$lists);
}
... ... @@ -82,14 +87,18 @@ class ServersController extends BaseController
'total'=>'required',
'account'=>'required',
'password'=>'required',
'port'=>'required'
'port'=>'required',
'ip_total'=>'required',
'domain'=>'required'
],[
'server_name.required' => '服务器名称server_name不能为空',
'service_type.required' => '服务器类型不能为空',
'total.required' => '总数不能为空',
'account.required' => '账号不能为空',
'password.required' => '密码不能为空',
'port.required' => '端口不能为空'
'port.required' => '端口不能为空',
'ip_total.required' => 'ip使用數量不能为空',
'domain.required' => '初始域名不能为空',
]);
$data = $serversLogic->saveServers();
$this->response('success',Code::SUCCESS,$data);
... ...
... ... @@ -12,7 +12,9 @@ namespace App\Http\Controllers\Aside\Devops;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Devops\ServersIpLogic;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp as ServersIpModel;
use App\Models\Project\Project;
class ServersIpController extends BaseController
{
... ... @@ -30,7 +32,13 @@ class ServersIpController extends BaseController
],[
'servers_id.required' => '服务器servers_id不能为空'
]);
$serverModel = new Servers();
$info = $serverModel->read(['id'=>$this->param['servers_id']]);
if($info === false){
$this->response('當前服務器不存在',Code::SERVER_ERROR);
}
$serversIpModel = new ServersIpModel();
$this->map['total'] = ['<',$info['ip_total']];
$data = $serversIpModel->list($this->map);
$this->response('success',Code::SUCCESS,$data);
}
... ... @@ -101,10 +109,10 @@ class ServersIpController extends BaseController
*/
public function batchSave(ServersIpLogic $serversIpLogic){
$this->request->validate([
'data'=>'required',
'ip'=>'required|array',
'servers_id'=>'required',
],[
'data.required' => 'data集合不能为空',
'ip.required' => 'ip集合不能为空',
'servers_id.required' => '服务器servers_id不能为空',
]);
$data = $serversIpLogic->batchSaveServersIp();
... ...
... ... @@ -422,7 +422,6 @@ class OptimizeController extends BaseController
if($info === false){
$this->response('请先创建视频任务,才能开启',Code::SYSTEM_ERROR);
}
$keywordVideoModel->edit(['status'=>$this->param['status']],['project_id'=>$this->param['project_id']]);
$optimizeModel = new DeployOptimize();
$optimizeModel->edit(['ai_video'=>$this->param['status']],['project_id'=>$this->param['project_id']]);
$this->response('success');
... ...
... ... @@ -31,7 +31,6 @@ class ProjectKeywordController extends BaseController
$data['search_keywords'] = $info['search_keywords'];
$data['customer_keywords'] = $info['customer_keywords'];
$data['brand_keyword'] = $info['brand_keyword'];
$data['minor_keywords'] = $info['minor_keywords'];
$this->response('success',Code::SUCCESS,$data);
}
... ...
... ... @@ -10,6 +10,7 @@
namespace App\Http\Logic\Aside\Devops;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
class ServersIpLogic extends BaseLogic
... ... @@ -32,6 +33,11 @@ class ServersIpLogic extends BaseLogic
* @time :2024/6/24 17:28
*/
public function saveServersIp(){
//验证域名是否唯一
$info = $this->model->read(['domain'=>$this->param['domain']]);
if($info !== false){
$this->fail('当前初始域名已存在');
}
if(isset($this->param['id']) && !empty($this->param['id'])){
$id = $this->param['id'];
$this->model->edit($this->param,['id'=>$this->param['id']]);
... ... @@ -49,17 +55,23 @@ class ServersIpLogic extends BaseLogic
* @time :2024/6/24 17:25
*/
public function batchSaveServersIp(){
$data = [];
foreach ($this->param['data'] as $v){
if(empty($v['ip']) || empty($v['domain'])){
//獲取初始域名
$serverModel = new Servers();
$info = $serverModel->read(['id'=>$this->param['servers_id']]);
if($info === false){
$this->fail('當前服務器數據不存在');
}
foreach ($this->param['ip'] as $v){
if(empty($v)){
continue;
}
$data[] = [
'ip'=>$v['ip'],
'domain'=>$v['domain'],
$param = [
'ip'=>$v,
'domain'=>ip_to_unique_string($v).'.'.$info['domain'],
'servers_id'=>$this->param['servers_id']
];
$this->model->addReturnId($param);
}
return $this->addReturnId($data);
return $this->success();
}
}
... ...
... ... @@ -165,10 +165,12 @@ class HrLogic extends BaseLogic
if(($this->manager['gid'] != ManageHr::GID_ZERO) && isset($this->param['id'])){
$groupModel = new Group();
$groupInfo = $groupModel->read(['id'=>$this->manager['gid']]);
if (!in_array(20,$groupInfo['rights']) && ($data['manage_id'] != $this->manager['id'])) {
if ((!in_array(20,$groupInfo['rights'])) && ($data['manage_id'] != $this->manager['id'])) {
if(strpos($this->manager['rules'],'20') == false){
$this->fail('无权限查看其他用户信息');
}
}
}
foreach ($this->model::specieField() as $v){
$data[$v] = json_decode($data[$v],true);
}
... ...
... ... @@ -19,6 +19,8 @@ use App\Models\Channel\Zone;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateLog;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryIP;
use App\Models\Inquiry\InquirySet;
... ... @@ -145,8 +147,6 @@ class ProjectLogic extends BaseLogic
* @time :2023/8/30 11:57
*/
public function projectSave(){
DB::beginTransaction();
try {
if($this->param['type'] == Project::TYPE_SEVEN){
//错误单直接返回,单独处理
$this->setTypeSevenEdit($this->param);
... ... @@ -169,11 +169,52 @@ class ProjectLogic extends BaseLogic
$this->syncImageFile($this->param['project_location'],$this->param['id']);
//同步信息表
(new SyncService())->projectAcceptAddress($this->param['id']);
//双向绑定服务器
// $this->setServers($this->param['server_id'],$this->param['id']);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('保存失败,请联系管理员');
return $this->success();
}
/**
* @remark :选择服务器后双向绑定
* @name :setServers
* @author :lyh
* @method :post
* @time :2024/6/25 15:34
*/
public function setServers($servers_id,$project_id){
//查看當前項目服務器是否有更改
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$project_id],['serve_id']);
if(!empty($projectInfo['serve_id'])){
if($projectInfo['serve_id'] == $servers_id){
return $this->success();
}
}
$serversIpModel = new ServersIp();
$serversIpInfo = $serversIpModel->read(['project_arr'=>['like','%,'.$project_id.',%']]);
if($serversIpInfo !== false){
$string = str_replace(','.$project_id.',',',',$serversIpInfo['project_arr']);
if($string == ','){
$string = '';
}
$serversIpModel->edit(['project_arr'=>$string],['id'=>$serversIpInfo['id']]);
}
$info = $serversIpModel->read(['id'=>$servers_id]);
$serversModel = new Servers();
$serversInfo = $serversModel->read(['id'=>$info['servers_id']]);
if($serversInfo['being_number'] >= $serversInfo['total']){
$this->fail('请选择其他服务器,当前服务器已满');
}
$project_arr = explode(',',trim($info['project_arr'],','));
if(count($project_arr) >= $serversInfo['ip_total']){
$this->fail('请选择其他服务器,当前ip已满');
}
if(!in_array($project_id,$project_arr)){
array_push($project_id);
$project_str = ','.implode(',',$project_arr).',';
$serversIpModel->edit(['project_arr'=>$project_str,'total'=>count($project_arr)],['id'=>$servers_id]);
$serversModel->where(['id'=>$info['servers_id']])->increment('being_number');
}
return $this->success();
}
... ...
... ... @@ -17,7 +17,6 @@ class Project extends Base
protected $table = 'gl_project';
const DATABASE_NAME_FIX = 'gl_data_';
const CUSTOMIZED_ONE = 1;//定制项目
const DEMO_PROJECT_ID = 1;
... ...