作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

... ... @@ -43,38 +43,50 @@ class RankData extends BaseCommands
*/
public function do()
{
try {
Log::channel('rank_data')->info('开始-排名数据');
//同步api_no
try {
$this->SyncApiNo();
} catch (\Exception $e) {
Log::channel('rank_data')->error('同步api_no失败:' . $e->getMessage());
}
//所有项目 今日是否达标 重置
//有失败会重跑任务,导致达标又被重置 加缓存一天只重置一次
if(!Cache::get('clear_remain_today_'.date('Y-m-d'))){
if (!Cache::get('clear_remain_today_' . date('Y-m-d'))) {
Project::where('is_remain_today', 1)->update(['is_remain_today' => 0]);
Cache::set('clear_remain_today_'.date('Y-m-d'), 1, 24 * 3600);
Cache::set('clear_remain_today_' . date('Y-m-d'), 1, 24 * 3600);
}
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>' , 0)->select('api_no','minor_languages','project_id')->get();
Log::channel('rank_data')->info('开始-排名数据-'.count($list));
$list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'minor_languages', 'project_id')->get();
Log::channel('rank_data')->info('开始-排名数据-' . count($list));
//当日所有站点谷歌收录数据
$site_res = $api->getSiteRes();
if(!$site_res){
if (!$site_res) {
return false;
}
foreach ($list as $item){
foreach ($list as $item) {
echo $item['api_no'] . PHP_EOL;
try {
(new RankDataLogic())->syncRankData($item['api_no'], $site_res);
}catch (\Exception $e){
} catch (\Exception $e) {
Log::channel('rank_data')->error('RankData:失败 ' . $item['api_no'] . $e->getMessage());
$error++;
continue;
}
}
return !$error;
} catch (\Exception $e) {
Log::channel('rank_data')->error('排名数据任务失败 ' . $e->getMessage());
throw new \Exception($e->getMessage());
}
}
/**
... ... @@ -93,7 +105,7 @@ class RankData extends BaseCommands
$api = new QuanqiusouApi();
$ai_nos = $api->getWebApiNo();
if($ai_nos){
foreach ($deploy_optimizes as $deploy_optimize){
$domain = DomainInfo::where('id', $deploy_optimize['domain'])->value('domain');
if(!$domain){
... ... @@ -106,5 +118,6 @@ class RankData extends BaseCommands
}
}
}
}
}
... ...
<?php
/**
* @remark :
* @name :RecommendedSuppliers.php
* @author :lyh
* @method :post
* @time :2024/3/5 11:27
*/
namespace App\Console\Commands\Suppliers;
use App\Models\Com\Purchaser;
use App\Models\Product\Keyword;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class RecommendedSuppliers extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'recommended_suppliers';
/**
* The console command description.
*
* @var string
*/
protected $description = '推荐供应商';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
$projectModel = new DeployBuild();
$project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商
foreach ($project_list as $k => $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$info = Keyword::inRandomOrder()->first();
if(empty($info)){
continue;
}
$keywordInfo = $this->getPurchaser($info['title']);
if($keywordInfo !== false){
continue;
}
echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;
$this->savePurchaser($v['id'],$info['title']);
DB::disconnect('custom_mysql');
}
return true;
}
public function getPurchaser($keyword){
$purchaserModel = new Purchaser();
return $purchaserModel->read(['keyword'=>$keyword]);
}
/**
* @remark :保存供应商
* @name :getPurchaser
* @author :lyh
* @method :post
* @time :2024/3/5 11:38
*/
public function savePurchaser($project_id,$keyword,$row = 10){
$url = 'https://admin.hagro.cn/api/company_list';
$data = [
'prod_desc'=>$keyword = 'led',
'total'=>$row ?? 10,
];
ksort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
echo date('Y-m-d H:i:s') . '加密token:'.md5($token) . PHP_EOL;
$param = [
'prod_desc'=>$keyword,
'token'=>md5($token),
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
if(!empty($res) && $res['code'] == 200){
$saveData = [
'project_id'=>$project_id,
'keyword'=>$keyword,
'data'=>json_encode($res['data'])
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
}
return true;
}
}
... ...
... ... @@ -265,25 +265,26 @@ class Demo extends Command
// print_r($include);
// }
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
foreach ($list as $v1){
ProjectServer::useProject($v1['id']);
echo date('Y-m-d H:i:s') . '项目id:'.$v1['id'] . PHP_EOL;
$navGroupModel = new BNavGroup();
$groupList = $navGroupModel->list(['sort_list'=>['!=','']]);
if(empty($groupList)){
continue;
}
foreach ($groupList as $k=>$v){
if(!empty($v['sort_list'])){
$sort_list = json_decode($v['sort_list']);
$sort = 0;
$this->subSort($sort_list,$sort);
}
}
DB::disconnect('custom_mysql');
}
echo '加密字符串:'.md5('company_list+2024-03-05+prod_desc=led&total=10');
// $projectModel = new Project();
// $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
// foreach ($list as $v1){
// ProjectServer::useProject($v1['id']);
// echo date('Y-m-d H:i:s') . '项目id:'.$v1['id'] . PHP_EOL;
// $navGroupModel = new BNavGroup();
// $groupList = $navGroupModel->list(['sort_list'=>['!=','']]);
// if(empty($groupList)){
// continue;
// }
// foreach ($groupList as $k=>$v){
// if(!empty($v['sort_list'])){
// $sort_list = json_decode($v['sort_list']);
// $sort = 0;
// $this->subSort($sort_list,$sort);
// }
// }
// DB::disconnect('custom_mysql');
// }
return true;
}
... ...
... ... @@ -167,7 +167,7 @@ class UpdateSeoTdk extends Command
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
foreach ($this->maps as $table => $map) {
$update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
$update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)->select('id')->get();
if (!empty($list)) {
... ...
... ... @@ -312,7 +312,7 @@ class WebTraffic extends Command
$other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
$data = [];
foreach ($list as $project) {
$lang = WebLanguage::getLangById($this->project['main_lang_id']??1)['short'];
$lang = WebLanguage::getLangById($project['main_lang_id']??1)['short'];
if(empty($project->domainInfo['domain'])){
continue;
}
... ...
... ... @@ -42,6 +42,8 @@ class Kernel extends ConsoleKernel
// $schedule->command('website_data')->dailyAt('01:00')->withoutOverlapping(1); // 向AICC推送数据
// $schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件
$schedule->command('sync_manager')->dailyAt('01:00')->withoutOverlapping(1); //TODO::手机号码同步 每天执行一次
$schedule->command('recommended_suppliers')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
}
/**
... ...
... ... @@ -802,14 +802,15 @@ class ProjectController extends BaseController
];
foreach ($data as $k => $v){
if(isset($item[$k])){
$item[$k] = Arr::s2a($item[$k]);
$item[$k] = $v.'总条数:'.$item[$k]['total_page'].
', title更新数:'.$item[$k]['title'].
',keyword更新数据:'.$item[$k]['keyword'].
',des更新数据:'.$item[$k]['des'];
$data = Arr::s2a($item[$k]);
//{"des": 3500, "title": 0, "keyword": 3501, "total_page": 8458, "keyword_title": 3500, "keyword_content": 3500}
$item[$k] = $v.'总条数:'.$data['total_page'].
', title更新数:'.$data['title'].
',keyword更新数:'.$data['keyword'].
',des更新数:'.$data['des'];
if($k == 'gl_product_keyword'){
$item[$k] .= ',keyword_title更新数据:'.$item[$k]['keyword_title'];
$item[$k] .= ',keyword_content更新数据:'.$item[$k]['keyword_content'];
$item[$k] .= ',keyword_title更新数:'.($data['keyword_title']??0);
$item[$k] .= ',keyword_content更新数:'.($data['keyword_content']??0);
}
}
... ...
... ... @@ -336,14 +336,17 @@ class ComController extends BaseController
* @time :2024/3/4 10:10
*/
public function recommendedPurchaser(){
$data = [];
$purchaserModel = new Purchaser();
$info = $purchaserModel->read(['project_id'=>$this->user['project_id']]);
if($info === false){
PurchaserJob::dispatch(['keyword'=>$this->param['keyword'] ?? 'led','row'=>$this->param['row'] ?? 10,'project_id'=>$this->user['project_id']]);
}else{
$data = json_decode($info['data']);
$data = [];
$lists = $purchaserModel->list(['project_id'=>$this->user['project_id']]);
if(!empty($lists)){
foreach ($lists as $v){
$resultData = json_decode($v['data']);
foreach ($resultData as $value){
$data[] = $value;
}
$this->response('数据生成中',Code::SUCCESS,$data);
}
}
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -39,12 +39,11 @@ class LoginController extends BaseController
*/
public function login(){
$this->request->validate([
'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'],
'mobile'=>['required'],
'password'=>['required'],
],[
'mobile.required'=>'电话号码必须填写',
'password.required'=>'内容必须填写',
'mobile.regex' => '请输入正确的手机号码',
]);
$userLogic = new UserLoginLogic();
$project = $userLogic->login();
... ...
... ... @@ -67,7 +67,7 @@ class MailController extends BaseController
public function unreadNum(&$mailUserModel,$total){
//已读数量
$count = $mailUserModel->where(['user_id'=>$this->uid])->count();
$num = $total - $count;
$num = ($total - $count > 0) ? $total - $count : 0;
return $num;
}
... ...
... ... @@ -604,6 +604,9 @@ class ProjectLogic extends BaseLogic
if($rs === false){
$this->fail('error');
}
//更新当前项目所有账号状态
$userModel = new UserModel();
$userModel->edit(['status'=>1],['project_id'=>$this->param['id']]);
return $this->success();
}
... ...
... ... @@ -55,7 +55,7 @@ class UserLoginLogic
$projectArr[] = $v['project_id'];
}
$projectModel = new Project();
$project_list = $projectModel->list(['id'=>['in',$projectArr]],'id',['id','title']);
$project_list = $projectModel->list(['id'=>['in',$projectArr],'delete_status'=>0],'id',['id','title']);
//登录选择项目的有效时间
Cache::add('login-project-'.$this->param['mobile'],1,300);
return $this->success($project_list);
... ...
<?php
/**
* @remark :
* @name :PurchaserJob.php
* @author :lyh
* @method :post
* @time :2024/3/4 11:06
*/
namespace App\Jobs;
use App\Models\Com\Purchaser;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class PurchaserJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 3; // 可配置任务重试次数
protected $param;
/**
* Create a new job instance.
*
* @param CopyImageFile $event
* @return void
*/
public function __construct($data)
{
$this->param = $data;
}
/**
* Handle the event.
*
* @param UpdateHtml $event
* @return void
*/
public function handle()
{
$this->param['keyword'] = 'led';
$url = 'https://admin.hagro.cn/api/company_list';
$data = [
'prod_desc'=>$this->param['keyword'],
'total'=>$this->param['row'] ?? 10,
];
arsort($data);
$token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
$param = [
'prod_desc'=>$this->param['keyword'],
'token'=>md5($token),
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
if(!empty($res) && $res['code'] == 200){
$saveData = [
'project_id'=>$this->param['project_id'],
'keyword'=>$this->param['keyword'],
'data'=>json_encode($res['data'])
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
}
return true;
}
}