作者 赵彬吉
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :RecommendedSuppliers.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/3/5 11:27
  8 + */
  9 +
  10 +namespace App\Console\Commands\Suppliers;
  11 +
  12 +use App\Models\Com\Purchaser;
  13 +use App\Models\Product\Keyword;
  14 +use App\Models\Project\DeployBuild;
  15 +use App\Models\Project\Project;
  16 +use App\Services\ProjectServer;
  17 +use Illuminate\Console\Command;
  18 +use Illuminate\Support\Facades\DB;
  19 +use Illuminate\Support\Facades\Log;
  20 +
  21 +class RecommendedSuppliers extends Command
  22 +{
  23 + /**
  24 + * The name and signature of the console command.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $signature = 'recommended_suppliers';
  29 +
  30 + /**
  31 + * The console command description.
  32 + *
  33 + * @var string
  34 + */
  35 + protected $description = '推荐供应商';
  36 +
  37 + /**
  38 + * Create a new command instance.
  39 + *
  40 + * @return void
  41 + */
  42 + public function __construct()
  43 + {
  44 + parent::__construct();
  45 + }
  46 +
  47 +
  48 + /**
  49 + * @return bool
  50 + */
  51 + public function handle()
  52 + {
  53 + $projectModel = new DeployBuild();
  54 + $project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商
  55 + foreach ($project_list as $k => $v){
  56 + echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL;
  57 + ProjectServer::useProject($v['id']);
  58 + $info = Keyword::inRandomOrder()->first();
  59 + if(empty($info)){
  60 + continue;
  61 + }
  62 + $keywordInfo = $this->getPurchaser($info['title']);
  63 + if($keywordInfo !== false){
  64 + continue;
  65 + }
  66 + echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;
  67 + $this->savePurchaser($v['id'],$info['title']);
  68 + DB::disconnect('custom_mysql');
  69 + }
  70 + return true;
  71 + }
  72 +
  73 + public function getPurchaser($keyword){
  74 + $purchaserModel = new Purchaser();
  75 + return $purchaserModel->read(['keyword'=>$keyword]);
  76 + }
  77 +
  78 + /**
  79 + * @remark :保存供应商
  80 + * @name :getPurchaser
  81 + * @author :lyh
  82 + * @method :post
  83 + * @time :2024/3/5 11:38
  84 + */
  85 + public function savePurchaser($project_id,$keyword,$row = 10){
  86 + $url = 'https://admin.hagro.cn/api/company_list';
  87 + $data = [
  88 + 'prod_desc'=>$keyword = 'led',
  89 + 'total'=>$row ?? 10,
  90 + ];
  91 + ksort($data);
  92 + $token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);
  93 + echo date('Y-m-d H:i:s') . '加密token:'.md5($token) . PHP_EOL;
  94 + $param = [
  95 + 'prod_desc'=>$keyword,
  96 + 'token'=>md5($token),
  97 + 'total'=>$this->param['row'] ?? 10,
  98 + ];
  99 + $res = http_post($url,json_encode($param));
  100 + if(!empty($res) && $res['code'] == 200){
  101 + $saveData = [
  102 + 'project_id'=>$project_id,
  103 + 'keyword'=>$keyword,
  104 + 'data'=>json_encode($res['data'])
  105 + ];
  106 + $purchaserModel = new Purchaser();
  107 + $purchaserModel->add($saveData);
  108 + }
  109 + return true;
  110 + }
  111 +}
@@ -265,25 +265,26 @@ class Demo extends Command @@ -265,25 +265,26 @@ class Demo extends Command
265 // print_r($include); 265 // print_r($include);
266 // } 266 // }
267 public function handle(){ 267 public function handle(){
268 - $projectModel = new Project();  
269 - $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);  
270 - foreach ($list as $v1){  
271 - ProjectServer::useProject($v1['id']);  
272 - echo date('Y-m-d H:i:s') . '项目id:'.$v1['id'] . PHP_EOL;  
273 - $navGroupModel = new BNavGroup();  
274 - $groupList = $navGroupModel->list(['sort_list'=>['!=','']]);  
275 - if(empty($groupList)){  
276 - continue;  
277 - }  
278 - foreach ($groupList as $k=>$v){  
279 - if(!empty($v['sort_list'])){  
280 - $sort_list = json_decode($v['sort_list']);  
281 - $sort = 0;  
282 - $this->subSort($sort_list,$sort);  
283 - }  
284 - }  
285 - DB::disconnect('custom_mysql');  
286 - } 268 + echo '加密字符串:'.md5('company_list+2024-03-05+prod_desc=led&total=10');
  269 +// $projectModel = new Project();
  270 +// $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
  271 +// foreach ($list as $v1){
  272 +// ProjectServer::useProject($v1['id']);
  273 +// echo date('Y-m-d H:i:s') . '项目id:'.$v1['id'] . PHP_EOL;
  274 +// $navGroupModel = new BNavGroup();
  275 +// $groupList = $navGroupModel->list(['sort_list'=>['!=','']]);
  276 +// if(empty($groupList)){
  277 +// continue;
  278 +// }
  279 +// foreach ($groupList as $k=>$v){
  280 +// if(!empty($v['sort_list'])){
  281 +// $sort_list = json_decode($v['sort_list']);
  282 +// $sort = 0;
  283 +// $this->subSort($sort_list,$sort);
  284 +// }
  285 +// }
  286 +// DB::disconnect('custom_mysql');
  287 +// }
287 return true; 288 return true;
288 } 289 }
289 290
@@ -42,6 +42,8 @@ class Kernel extends ConsoleKernel @@ -42,6 +42,8 @@ class Kernel extends ConsoleKernel
42 // $schedule->command('website_data')->dailyAt('01:00')->withoutOverlapping(1); // 向AICC推送数据 42 // $schedule->command('website_data')->dailyAt('01:00')->withoutOverlapping(1); // 向AICC推送数据
43 // $schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件 43 // $schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件
44 $schedule->command('sync_manager')->dailyAt('01:00')->withoutOverlapping(1); //TODO::手机号码同步 每天执行一次 44 $schedule->command('sync_manager')->dailyAt('01:00')->withoutOverlapping(1); //TODO::手机号码同步 每天执行一次
  45 +
  46 + $schedule->command('recommended_suppliers')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
45 } 47 }
46 48
47 /** 49 /**
@@ -336,14 +336,17 @@ class ComController extends BaseController @@ -336,14 +336,17 @@ class ComController extends BaseController
336 * @time :2024/3/4 10:10 336 * @time :2024/3/4 10:10
337 */ 337 */
338 public function recommendedPurchaser(){ 338 public function recommendedPurchaser(){
339 - $data = [];  
340 $purchaserModel = new Purchaser(); 339 $purchaserModel = new Purchaser();
341 - $info = $purchaserModel->read(['project_id'=>$this->user['project_id']]);  
342 - if($info === false){  
343 - PurchaserJob::dispatch(['keyword'=>$this->param['keyword'] ?? 'led','row'=>$this->param['row'] ?? 10,'project_id'=>$this->user['project_id']]);  
344 - }else{  
345 - $data = json_decode($info['data']); 340 + $data = [];
  341 + $lists = $purchaserModel->list(['project_id'=>$this->user['project_id']]);
  342 + if(!empty($lists)){
  343 + foreach ($lists as $v){
  344 + $resultData = json_decode($v['data']);
  345 + foreach ($resultData as $value){
  346 + $data[] = $value;
  347 + }
  348 + }
346 } 349 }
347 - $this->response('数据生成中',Code::SUCCESS,$data); 350 + $this->response('success',Code::SUCCESS,$data);
348 } 351 }
349 } 352 }
@@ -39,12 +39,11 @@ class LoginController extends BaseController @@ -39,12 +39,11 @@ class LoginController extends BaseController
39 */ 39 */
40 public function login(){ 40 public function login(){
41 $this->request->validate([ 41 $this->request->validate([
42 - 'mobile'=>['required', 'regex:/^1[3-9]\d{9}$/'], 42 + 'mobile'=>['required'],
43 'password'=>['required'], 43 'password'=>['required'],
44 ],[ 44 ],[
45 'mobile.required'=>'电话号码必须填写', 45 'mobile.required'=>'电话号码必须填写',
46 'password.required'=>'内容必须填写', 46 'password.required'=>'内容必须填写',
47 - 'mobile.regex' => '请输入正确的手机号码',  
48 ]); 47 ]);
49 $userLogic = new UserLoginLogic(); 48 $userLogic = new UserLoginLogic();
50 $project = $userLogic->login(); 49 $project = $userLogic->login();
@@ -67,7 +67,7 @@ class MailController extends BaseController @@ -67,7 +67,7 @@ class MailController extends BaseController
67 public function unreadNum(&$mailUserModel,$total){ 67 public function unreadNum(&$mailUserModel,$total){
68 //已读数量 68 //已读数量
69 $count = $mailUserModel->where(['user_id'=>$this->uid])->count(); 69 $count = $mailUserModel->where(['user_id'=>$this->uid])->count();
70 - $num = $total - $count; 70 + $num = ($total - $count > 0) ? $total - $count : 0;
71 return $num; 71 return $num;
72 } 72 }
73 73
1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :PurchaserJob.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2024/3/4 11:06  
8 - */  
9 -  
10 -namespace App\Jobs;  
11 -  
12 -use App\Models\Com\Purchaser;  
13 -use Illuminate\Bus\Queueable;  
14 -use Illuminate\Contracts\Queue\ShouldQueue;  
15 -use Illuminate\Foundation\Bus\Dispatchable;  
16 -use Illuminate\Queue\InteractsWithQueue;  
17 -use Illuminate\Queue\SerializesModels;  
18 -  
19 -class PurchaserJob implements ShouldQueue  
20 -{  
21 - use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;  
22 - public $tries = 3; // 可配置任务重试次数  
23 -  
24 - protected $param;  
25 -  
26 - /**  
27 - * Create a new job instance.  
28 - *  
29 - * @param CopyImageFile $event  
30 - * @return void  
31 - */  
32 - public function __construct($data)  
33 - {  
34 - $this->param = $data;  
35 - }  
36 -  
37 - /**  
38 - * Handle the event.  
39 - *  
40 - * @param UpdateHtml $event  
41 - * @return void  
42 - */  
43 - public function handle()  
44 - {  
45 - $this->param['keyword'] = 'led';  
46 - $url = 'https://admin.hagro.cn/api/company_list';  
47 - $data = [  
48 - 'prod_desc'=>$this->param['keyword'],  
49 - 'total'=>$this->param['row'] ?? 10,  
50 - ];  
51 - arsort($data);  
52 - $token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data);  
53 - $param = [  
54 - 'prod_desc'=>$this->param['keyword'],  
55 - 'token'=>md5($token),  
56 - 'total'=>$this->param['row'] ?? 10,  
57 - ];  
58 - $res = http_post($url,json_encode($param));  
59 - if(!empty($res) && $res['code'] == 200){  
60 - $saveData = [  
61 - 'project_id'=>$this->param['project_id'],  
62 - 'keyword'=>$this->param['keyword'],  
63 - 'data'=>json_encode($res['data'])  
64 - ];  
65 - $purchaserModel = new Purchaser();  
66 - $purchaserModel->add($saveData);  
67 - }  
68 - return true;  
69 - }  
70 -}