Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate
正在显示
4 个修改的文件
包含
120 行增加
和
83 行删除
| 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\Project; | ||
| 15 | +use App\Services\ProjectServer; | ||
| 16 | +use Illuminate\Console\Command; | ||
| 17 | +use Illuminate\Support\Facades\DB; | ||
| 18 | +use Illuminate\Support\Facades\Log; | ||
| 19 | + | ||
| 20 | +class RecommendedSuppliers extends Command | ||
| 21 | +{ | ||
| 22 | + /** | ||
| 23 | + * The name and signature of the console command. | ||
| 24 | + * | ||
| 25 | + * @var string | ||
| 26 | + */ | ||
| 27 | + protected $signature = 'recommended_suppliers'; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * The console command description. | ||
| 31 | + * | ||
| 32 | + * @var string | ||
| 33 | + */ | ||
| 34 | + protected $description = '推荐供应商'; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * Create a new command instance. | ||
| 38 | + * | ||
| 39 | + * @return void | ||
| 40 | + */ | ||
| 41 | + public function __construct() | ||
| 42 | + { | ||
| 43 | + parent::__construct(); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * @return bool | ||
| 49 | + */ | ||
| 50 | + public function handle() | ||
| 51 | + { | ||
| 52 | + $projectModel = new Project(); | ||
| 53 | + $project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商 | ||
| 54 | + foreach ($project_list as $k => $v){ | ||
| 55 | + echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; | ||
| 56 | + ProjectServer::useProject($v['id']); | ||
| 57 | + $keywordInfo = Keyword::inRandomOrder()->first(); | ||
| 58 | + if(empty($keywordInfo)){ | ||
| 59 | + continue; | ||
| 60 | + } | ||
| 61 | + $keywordInfo = $this->getPurchaser($keywordInfo['title']); | ||
| 62 | + if($keywordInfo !== false){ | ||
| 63 | + continue; | ||
| 64 | + } | ||
| 65 | + $this->savePurchaser($v['id'],$keywordInfo['title']); | ||
| 66 | + DB::disconnect('custom_mysql'); | ||
| 67 | + } | ||
| 68 | + return true; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + public function getPurchaser($keyword){ | ||
| 72 | + $purchaserModel = new Purchaser(); | ||
| 73 | + return $purchaserModel->read(['keyword'=>$keyword]); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * @remark :保存供应商 | ||
| 78 | + * @name :getPurchaser | ||
| 79 | + * @author :lyh | ||
| 80 | + * @method :post | ||
| 81 | + * @time :2024/3/5 11:38 | ||
| 82 | + */ | ||
| 83 | + public function savePurchaser($project_id,$keyword,$row = 10){ | ||
| 84 | + $url = 'https://admin.hagro.cn/api/company_list'; | ||
| 85 | + $data = [ | ||
| 86 | + 'prod_desc'=>$keyword, | ||
| 87 | + 'total'=>$row ?? 10, | ||
| 88 | + ]; | ||
| 89 | + arsort($data); | ||
| 90 | + $token = 'company_list+'.date('Y-m-d').'+'.http_build_query($data); | ||
| 91 | + $param = [ | ||
| 92 | + 'prod_desc'=>$keyword, | ||
| 93 | + 'token'=>md5($token), | ||
| 94 | + 'total'=>$this->param['row'] ?? 10, | ||
| 95 | + ]; | ||
| 96 | + $res = http_post($url,json_encode($param)); | ||
| 97 | + if(!empty($res) && $res['code'] == 200){ | ||
| 98 | + $saveData = [ | ||
| 99 | + 'project_id'=>$project_id, | ||
| 100 | + 'keyword'=>$keyword, | ||
| 101 | + 'data'=>json_encode($res['data']) | ||
| 102 | + ]; | ||
| 103 | + $purchaserModel = new Purchaser(); | ||
| 104 | + $purchaserModel->add($saveData); | ||
| 105 | + } | ||
| 106 | + return true; | ||
| 107 | + } | ||
| 108 | +} |
| @@ -336,14 +336,14 @@ class ComController extends BaseController | @@ -336,14 +336,14 @@ 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 | + $lists = $purchaserModel->lists(['project_id'=>$this->user['project_id']],$this->page,$this->row); |
| 341 | + if(!empty($lists) && !empty($lists['list'])){ | ||
| 342 | + foreach ($lists['list'] as $k => $v){ | ||
| 343 | + $v['data'] = json_decode($v['data']); | ||
| 344 | + $lists['list'][$k] = $v; | ||
| 345 | + } | ||
| 346 | } | 346 | } |
| 347 | - $this->response('数据生成中',Code::SUCCESS,$data); | 347 | + $this->response('success',Code::SUCCESS,$lists); |
| 348 | } | 348 | } |
| 349 | } | 349 | } |
| @@ -173,12 +173,11 @@ class BaseLogic extends Logic | @@ -173,12 +173,11 @@ class BaseLogic extends Logic | ||
| 173 | $data['project_id'] = $this->user['project_id']; | 173 | $data['project_id'] = $this->user['project_id']; |
| 174 | $str = http_build_query($data); | 174 | $str = http_build_query($data); |
| 175 | $url = $this->user['domain'].'api/delHtml/?'.$str; | 175 | $url = $this->user['domain'].'api/delHtml/?'.$str; |
| 176 | - $rs = shell_exec('curl -k "'.$url.'"'); | ||
| 177 | -// if($this->user['project_id'] == 177){ | ||
| 178 | -// @file_put_contents(storage_path('logs/lyh_error.log'), var_export($url, true) . PHP_EOL, FILE_APPEND); | ||
| 179 | -// @file_put_contents(storage_path('logs/lyh_error.log'), var_export($rs, true) . PHP_EOL, FILE_APPEND); | ||
| 180 | -// } | ||
| 181 | -// curlGet($url); | 176 | + if($this->user['project_id'] == 672){//TODO::当前项目通知不过 ,跳过自动更新 |
| 177 | + exec('curl -k "'.$url.'" > /dev/null 2>&1 &'); | ||
| 178 | + }else{ | ||
| 179 | + shell_exec('curl -k "'.$url.'"'); | ||
| 180 | + } | ||
| 182 | return $this->success(); | 181 | return $this->success(); |
| 183 | } | 182 | } |
| 184 | } | 183 | } |
app/Jobs/PurchaserJob.php
已删除
100644 → 0
| 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 | -} |
-
请 注册 或 登录 后发表评论