作者 李宇航

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

更新推荐供应商



查看合并请求 !1386
@@ -9,7 +9,9 @@ @@ -9,7 +9,9 @@
9 9
10 namespace App\Console\Commands\RequestUrlLog; 10 namespace App\Console\Commands\RequestUrlLog;
11 11
  12 +use App\Helper\FormGlobalsoApi;
12 use App\Models\Com\RequestUrl; 13 use App\Models\Com\RequestUrl;
  14 +use App\Models\Domain\DomainInfo;
13 use App\Models\Project\Project; 15 use App\Models\Project\Project;
14 use Illuminate\Console\Command; 16 use Illuminate\Console\Command;
15 17
@@ -40,22 +42,87 @@ class RequestUrlLog extends Command @@ -40,22 +42,87 @@ class RequestUrlLog extends Command
40 //获取需要请求的接口 42 //获取需要请求的接口
41 $requestUrlModel = new RequestUrl(); 43 $requestUrlModel = new RequestUrl();
42 $urlList = $requestUrlModel->list(['status'=>0]); 44 $urlList = $requestUrlModel->list(['status'=>0]);
  45 + //随机获取一个项目,需要验证的其他方法
  46 + $projectModel = new Project();
  47 + $projectInfo = $projectModel->formatQuery(['type'=>2,'delete_status'=>0])->inRandomOrder()->first();
  48 + //获取对应项目的域名
  49 + $domainModel = new DomainInfo();
  50 + $domainInfo = $domainModel->read(['project_id'=>$projectInfo['id']]);
43 foreach ($urlList as $v){ 51 foreach ($urlList as $v){
  52 + //需要单独验证的方法
  53 + if($v['url'] == 'getMonthInquiry'){
  54 + $result = $this->getMonthInquiry($domainInfo['domain'],date('Y-m'), 0);
  55 + $requestUrlModel->edit(['text'=>json_encode($result,true),'time'=>$result['$requestTime'],'http_code'=>$result['http_code']],['id'=>$v['id']]);
  56 + continue;
  57 + }
44 //循环请求设置 58 //循环请求设置
45 - if($v['method'] == 'get'){  
46 -  
47 - }else{  
48 - $url = $v['url'];  
49 - $result = $this->postRequest($url,$v['param']);  
50 - echo '执行的url:' . $url . PHP_EOL . '返回的结果:'.json_encode($result,true) . date('Y-m-d H:i:s').PHP_EOL; 59 + if($v['method'] == 'post'){
  60 + $result = $this->postRequest($v['url'],$v['param']);
  61 + echo '执行的url:' . $v['url'] . PHP_EOL . '返回的结果:'.json_encode($result,true) . date('Y-m-d H:i:s').PHP_EOL;
51 //更新请求结果 62 //更新请求结果
52 - $requestUrlModel->edit(['text'=>json_encode($result,true)],['id'=>$v['id']]); 63 + $requestUrlModel->edit(['text'=>json_encode($result,true),'time'=>$result['$requestTime'],'http_code'=>$result['http_code']],['id'=>$v['id']]);
  64 + continue;
53 } 65 }
54 } 66 }
55 return true; 67 return true;
56 } 68 }
57 69
58 /** 70 /**
  71 + * @remark :按月统计xunpan
  72 + * @name :getMonthInquiry
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2025/3/10 14:15
  76 + */
  77 + public function getMonthInquiry($url,$month,$is_upgrade = 0){
  78 + $url = 'https://'.$url.'/';
  79 + $token = md5($url.date("Y-m-d"));
  80 + $data = [
  81 + 'domain' => $url,
  82 + 'token' => $token,
  83 + 'source'=> $is_upgrade ? '1,2,3,4,5' : '1,3,5',
  84 + 'model' => 'month',
  85 + 'sta_date'=>$month,
  86 + ];
  87 + $queryString = http_build_query($data);
  88 + $url = 'https://www.globalso.site/api/external-interface/country_con/15243d63ed5a5738?'.$queryString;
  89 + $res = $this->getRequest($url);
  90 + return $res;
  91 + }
  92 +
  93 + /**
  94 + * @remark :http_get请求
  95 + * @name :getRequest
  96 + * @author :lyh
  97 + * @method :post
  98 + * @time :2025/3/10 14:35
  99 + */
  100 + public function getRequest($url){
  101 + $header[] = "content-type: application/json";
  102 + $ch1 = curl_init();
  103 + $timeout = 0;
  104 + curl_setopt($ch1, CURLOPT_URL, $url);
  105 + curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
  106 + curl_setopt($ch1, CURLOPT_ENCODING, '');
  107 + curl_setopt($ch1, CURLOPT_MAXREDIRS, 10);
  108 + curl_setopt($ch1, CURLOPT_TIMEOUT, 120);
  109 + curl_setopt($ch1, CURLOPT_HTTPHEADER, $header);
  110 + curl_setopt($ch1, CURLOPT_CONNECTTIMEOUT, $timeout);
  111 + curl_setopt($ch1, CURLOPT_FOLLOWLOCATION, true);
  112 + curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, 'GET');
  113 + curl_setopt($ch1, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  114 + $access_txt = curl_exec($ch1);
  115 + $total_time = curl_getinfo($ch1, CURLINFO_TOTAL_TIME); // 获取请求总时间
  116 + $httpCode = curl_getinfo($ch1, CURLINFO_HTTP_CODE);
  117 + if (curl_errno($ch1)) {
  118 + curl_error($ch1);
  119 + }
  120 + curl_close($ch1);
  121 + $response = json_decode($access_txt, true);
  122 + return ['response' => $response, 'http_code' => $httpCode, 'request_time_ms' => $total_time];
  123 + }
  124 +
  125 + /**
59 * @remark :请求设置 126 * @remark :请求设置
60 * @name :postRequest 127 * @name :postRequest
61 * @author :lyh 128 * @author :lyh
@@ -64,12 +131,10 @@ class RequestUrlLog extends Command @@ -64,12 +131,10 @@ class RequestUrlLog extends Command
64 */ 131 */
65 public function postRequest($url, $postData) 132 public function postRequest($url, $postData)
66 { 133 {
67 - if (empty($header)) {  
68 - $header = array(  
69 - "Accept: application/json",  
70 - "Content-Type:application/json;charset=utf-8",  
71 - );  
72 - } 134 + $header = array(
  135 + "Accept: application/json",
  136 + "Content-Type:application/json;charset=utf-8",
  137 + );
73 $ch = curl_init(); 138 $ch = curl_init();
74 curl_setopt($ch, CURLOPT_URL, $url); 139 curl_setopt($ch, CURLOPT_URL, $url);
75 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 140 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
@@ -81,18 +146,15 @@ class RequestUrlLog extends Command @@ -81,18 +146,15 @@ class RequestUrlLog extends Command
81 curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 146 curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
82 curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 147 curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
83 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 148 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
84 - // 记录请求开始时间  
85 - $startTime = microtime(true);  
86 $res = curl_exec($ch); 149 $res = curl_exec($ch);
87 - // 记录请求结束时间  
88 - $endTime = microtime(true); 150 + $total_time = curl_getinfo($ch, CURLINFO_TOTAL_TIME); // 获取请求总时间
89 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 151 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
90 if (curl_errno($ch)) { 152 if (curl_errno($ch)) {
91 curl_error($ch); 153 curl_error($ch);
92 } 154 }
93 - $requestTime = round(($endTime - $startTime) * 1000, 2); // 转换为毫秒  
94 curl_close($ch); 155 curl_close($ch);
95 - return ['response' => $res, 'http_code' => $httpCode, 'request_time_ms' => $requestTime]; 156 + $response = json_decode($res, true);
  157 + return ['response' => $response, 'http_code' => $httpCode, 'request_time_ms' => $total_time];
96 } 158 }
97 159
98 } 160 }
@@ -11,6 +11,7 @@ namespace App\Console\Commands\Suppliers; @@ -11,6 +11,7 @@ namespace App\Console\Commands\Suppliers;
11 11
12 use App\Models\Product\Keyword; 12 use App\Models\Product\Keyword;
13 use App\Models\Project\DeployBuild; 13 use App\Models\Project\DeployBuild;
  14 +use App\Models\Project\Project;
14 use App\Models\Purchaser\Purchaser; 15 use App\Models\Purchaser\Purchaser;
15 use App\Models\Purchaser\PurchaserInfo; 16 use App\Models\Purchaser\PurchaserInfo;
16 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
@@ -33,6 +34,10 @@ class RecommendedSuppliers extends Command @@ -33,6 +34,10 @@ class RecommendedSuppliers extends Command
33 */ 34 */
34 protected $description = '推荐供应商'; 35 protected $description = '推荐供应商';
35 36
  37 + public $deployBuildModel;
  38 +
  39 + public $projectModel;
  40 +
36 /** 41 /**
37 * Create a new command instance. 42 * Create a new command instance.
38 * 43 *
@@ -40,7 +45,7 @@ class RecommendedSuppliers extends Command @@ -40,7 +45,7 @@ class RecommendedSuppliers extends Command
40 */ 45 */
41 public function __construct() 46 public function __construct()
42 { 47 {
43 - parent::__construct(); 48 + $this->deployBuildModel = new DeployBuild();
44 } 49 }
45 50
46 51
@@ -49,15 +54,42 @@ class RecommendedSuppliers extends Command @@ -49,15 +54,42 @@ class RecommendedSuppliers extends Command
49 */ 54 */
50 public function handle() 55 public function handle()
51 { 56 {
52 - $projectModel = new DeployBuild();  
53 - $project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商 57 + $project_list = $this->deployBuildModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商
54 foreach ($project_list as $v){ 58 foreach ($project_list as $v){
55 echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL; 59 echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL;
56 - ProjectServer::useProject($v['project_id']);  
57 - $title = $this->getKeywords($v['project_id']);  
58 - echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;  
59 - $this->savePurchaser($v['project_id'],$title);  
60 - DB::disconnect('custom_mysql'); 60 + $result = $this->countPurchaser($v);
  61 + if($result !== false){
  62 + ProjectServer::useProject($v['project_id']);
  63 + $title = $this->getKeywords($v['project_id']);
  64 + echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;
  65 + $this->savePurchaser($v['project_id'],$title);
  66 + DB::disconnect('custom_mysql');
  67 + }
  68 + }
  69 + return true;
  70 + }
  71 +
  72 + /**
  73 + * @remark :当前项目拥有的
  74 + * @name :countPurchaser
  75 + * @author :lyh
  76 + * @method :post
  77 + * @time :2025/3/10 16:29
  78 + * @param :is_purchaser_count;1->开启后已达到上线关闭过 0->未关闭过
  79 + * @param :plan(1->专业版 2->标准版 3->商务版 10->旗舰版)
  80 + */
  81 + public function countPurchaser($v){
  82 + if($v['is_purchaser_count'] == 0){
  83 + $purchaserInfoModel = new PurchaserInfo();
  84 + $count = $purchaserInfoModel->counts(['project_id'=>$v['project_id']]);
  85 + //获取项目版本
  86 + $plan = ['专业版'=>300, '标准版'=>500, '商务版'=>800, '旗舰版'=>1200];
  87 + $total_number = $plan[Project::planMap()[$v['plan']]] ?? 300;
  88 + if($count > $total_number){
  89 + //更新数量上限字段,并关闭推荐供应商
  90 + $this->deployBuildModel->edit(['is_purchaser_count'=>1,'is_supplier'=>0],['project_id'=>$v['project_id']]);
  91 + return false;
  92 + }
61 } 93 }
62 return true; 94 return true;
63 } 95 }
@@ -154,12 +154,12 @@ class ProjectLogic extends BaseLogic @@ -154,12 +154,12 @@ class ProjectLogic extends BaseLogic
154 * @author :lyh 154 * @author :lyh
155 * @method :post 155 * @method :post
156 * @time :2023/8/30 11:57 156 * @time :2023/8/30 11:57
  157 + * @param :1->建站中 2->优化中 3->建站完成 6-》错误单
157 */ 158 */
158 public function projectSave(){ 159 public function projectSave(){
159 DB::beginTransaction(); 160 DB::beginTransaction();
160 try { 161 try {
161 if($this->param['type'] == Project::TYPE_SEVEN){ 162 if($this->param['type'] == Project::TYPE_SEVEN){
162 - //错误单直接返回,单独处理  
163 $this->setTypeSevenEdit($this->param); 163 $this->setTypeSevenEdit($this->param);
164 }else{ 164 }else{
165 //初始化项目 165 //初始化项目
@@ -196,6 +196,32 @@ class ProjectLogic extends BaseLogic @@ -196,6 +196,32 @@ class ProjectLogic extends BaseLogic
196 } 196 }
197 197
198 /** 198 /**
  199 + * @remark :开启推荐供应商设置
  200 + * @name :isPurchaser
  201 + * @author :lyh
  202 + * @method :post
  203 + * @time :2025/3/10 15:33
  204 + */
  205 + public function isPurchaser($project_id){
  206 + if($this->param['type'] == Project::TYPE_TWO){
  207 + if(empty($this->param['uptime'])){
  208 + $this->param['deploy_build']['is_supplier'] = 1;
  209 + }else{
  210 + //获取项目的上线时间
  211 + $projectInfo = $this->model->read(['id'=>$project_id],['uptime']);
  212 + //查看上线时间是否大于3天
  213 + $threeDaysAgo = date('Y-m-d H:i:s', strtotime('-3 days'));
  214 + if($projectInfo['uptime'] > $threeDaysAgo){
  215 + //上线时间大于当前时间的3天钱,默认不允许关闭推荐供应商
  216 + $this->param['deploy_build']['is_supplier'] = 1;
  217 + }
  218 + }
  219 + return true;
  220 + }
  221 +
  222 + }
  223 +
  224 + /**
199 * @remark :开启AI博客后 225 * @remark :开启AI博客后
200 * @name :setAiBlog 226 * @name :setAiBlog
201 * @author :lyh 227 * @author :lyh
@@ -206,8 +232,7 @@ class ProjectLogic extends BaseLogic @@ -206,8 +232,7 @@ class ProjectLogic extends BaseLogic
206 if(empty($main_lang_id) || empty($is_ai_blog)){ 232 if(empty($main_lang_id) || empty($is_ai_blog)){
207 return true; 233 return true;
208 } 234 }
209 - $projectModel = new Project();  
210 - $projectInfo = $projectModel->read(['id'=>$project_id],['title','is_ai_blog','main_lang_id','company']); 235 + $projectInfo = $this->model->read(['id'=>$project_id],['title','is_ai_blog','main_lang_id','company']);
211 //获取项目主语种 236 //获取项目主语种
212 $languageModel = new WebLanguage(); 237 $languageModel = new WebLanguage();
213 $languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']); 238 $languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']);
@@ -277,8 +302,7 @@ class ProjectLogic extends BaseLogic @@ -277,8 +302,7 @@ class ProjectLogic extends BaseLogic
277 return $this->success(); 302 return $this->success();
278 } 303 }
279 //查看當前項目服務器是否有更改 304 //查看當前項目服務器是否有更改
280 - $projectModel = new Project();  
281 - $projectInfo = $projectModel->read(['id'=>$project_id],['serve_id']); 305 + $projectInfo = $this->model->read(['id'=>$project_id],['serve_id']);
282 $serversIpModel = new ServersIp(); 306 $serversIpModel = new ServersIp();
283 $serversModel = new Servers(); 307 $serversModel = new Servers();
284 if(!empty($projectInfo['serve_id'])){ 308 if(!empty($projectInfo['serve_id'])){
@@ -57,12 +57,14 @@ class WebSettingTextLogic extends BaseLogic @@ -57,12 +57,14 @@ class WebSettingTextLogic extends BaseLogic
57 if(count($this->param['data']) > $this->param['anchor_num']){ 57 if(count($this->param['data']) > $this->param['anchor_num']){
58 $this->fail('超过最大设置限制'); 58 $this->fail('超过最大设置限制');
59 } 59 }
  60 + //更新描文本设置
  61 + if($this->param['anchor_is_enable'] == 0){
  62 + $this->param['anchor_keyword_is_enable'] = 0;
  63 + $web_setting->edit($this->param,['project_id'=>$this->user['project_id']]);
  64 + return $this->success();
  65 + }
60 DB::beginTransaction(); 66 DB::beginTransaction();
61 try { 67 try {
62 - //更新描文本设置  
63 - if($this->param['anchor_is_enable'] == 0){  
64 - $this->param['anchor_keyword_is_enable'] = 0;  
65 - }  
66 $data = [ 68 $data = [
67 'anchor_setting'=>$this->param['anchor_setting'] ?? [], 69 'anchor_setting'=>$this->param['anchor_setting'] ?? [],
68 'anchor_is_enable'=>$this->param['anchor_is_enable'], 70 'anchor_is_enable'=>$this->param['anchor_is_enable'],
@@ -72,7 +74,7 @@ class WebSettingTextLogic extends BaseLogic @@ -72,7 +74,7 @@ class WebSettingTextLogic extends BaseLogic
72 ]; 74 ];
73 $web_setting->edit($data,['project_id'=>$this->user['project_id']]); 75 $web_setting->edit($data,['project_id'=>$this->user['project_id']]);
74 $this->model->del(['project_id'=>$this->user['project_id']]); 76 $this->model->del(['project_id'=>$this->user['project_id']]);
75 - if(!empty($this->param['data'])){ 77 + if(isset($this->param['data']) && !empty($this->param['data'])){
76 foreach ($this->param['data'] as $k => $v){ 78 foreach ($this->param['data'] as $k => $v){
77 $v['created_at'] = date('Y-m-d H:i:s'); 79 $v['created_at'] = date('Y-m-d H:i:s');
78 $v['updated_at'] = date('Y-m-d H:i:s'); 80 $v['updated_at'] = date('Y-m-d H:i:s');
@@ -86,6 +88,6 @@ class WebSettingTextLogic extends BaseLogic @@ -86,6 +88,6 @@ class WebSettingTextLogic extends BaseLogic
86 DB::rollBack(); 88 DB::rollBack();
87 $this->fail('更新失败'); 89 $this->fail('更新失败');
88 } 90 }
89 - $this->success(); 91 + return $this->success();
90 } 92 }
91 } 93 }
@@ -4,6 +4,7 @@ namespace App\Models\Workchat; @@ -4,6 +4,7 @@ namespace App\Models\Workchat;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
6 use App\Models\Inquiry\InquiryFormData; 6 use App\Models\Inquiry\InquiryFormData;
  7 +use App\Models\Project\Project;
7 use App\Models\ProjectAssociation\ProjectAssociation; 8 use App\Models\ProjectAssociation\ProjectAssociation;
8 use App\Services\ProjectServer; 9 use App\Services\ProjectServer;
9 use App\Utils\LogUtils; 10 use App\Utils\LogUtils;
@@ -40,12 +41,15 @@ class MessagePush extends Base @@ -40,12 +41,15 @@ class MessagePush extends Base
40 * @param $name 41 * @param $name
41 * @param $submit_at 42 * @param $submit_at
42 * @return bool 43 * @return bool
  44 + * @param : is_forward_inquiry:0未开启转发询盘 1:开启转发询盘
43 */ 45 */
44 public static function addInquiryMessage($id, $project_id, $country, $name, $submit_at){ 46 public static function addInquiryMessage($id, $project_id, $country, $name, $submit_at){
45 -// if(!ProjectServer::useProject($project_id)){  
46 -// return false;  
47 -// }  
48 - 47 + //查看项目是否开启转发询盘
  48 + $projectModel = new Project();
  49 + $projectInfo = $projectModel->read(['id'=>$project_id],['is_forward_inquiry']);
  50 + if($projectInfo['is_forward_inquiry'] == 0){
  51 + return false;
  52 + }
49 //项目是否有绑定群 53 //项目是否有绑定群
50 $friend_id = ProjectAssociation::where('project_id', $project_id) 54 $friend_id = ProjectAssociation::where('project_id', $project_id)
51 ->where('status', ProjectAssociation::STATUS_NORMAL) 55 ->where('status', ProjectAssociation::STATUS_NORMAL)