Commit ecf8c45f authored by hj's avatar hj

更新提交

parent 222b8520
......@@ -60,50 +60,10 @@ class WuxiLabNewJobCommand extends Command
$service = app(WuxiLabNewService::class);
switch($action_type){
case 'initProductToExcel' :
if(!isset($params) || $params == 0){
$params['limit'] = 1000;
case 'batchUpdateProducts': $service->batchUpdateProducts($params);break;
case 'batchUpdateProductPrice': $service->batchUpdateProductPrice($params);break;
case 'batchUpdateProductStock': $service->batchUpdateProductStock($params);break;
}
$service->initCreateProductsToExcel($params['limit']);
break;
case 'batchUpdatePackages' :
if(!isset($params) || $params == 0){
$params['limit'] = 1000;
}
$service->batchUpdatePackagesInfo($params);
break;
case 'batchUploadProducts' :
$service->batchUploadProducts();
break;
case 'batchUpdateToWuxiLab' :
$service->batchUpdateToWuxiLab();
break;
case 'batchUpdateProduct' :
$service->batchUpdateProducts();
break;
case 'test' :
$service->test($params);
break;
case 'test1' :
$service->test1();
break;
case 'batchUploadNewProducts' :
$service->batchUploadNewProducts();
break;
case 'batchUpdateProductPackages' :
$service->batchUploadPackages();
break;
case 'batchUpdateProductsShelves' :
$service->batchUpdateProductsShelves();
break;
case 'initToken' :
$service->initToken();
break;
default:
}
/*$productUpdateJob = (new WuxiLabJob($action_type,$params))->delay(100)->onQueue('slow');
app('Illuminate\Contracts\Bus\Dispatcher')->dispatch($productUpdateJob);*/
}
}
......
......@@ -67,6 +67,26 @@ class RhawnProductService
}
}
public function getProductsListThroughPids($pIds)
{
try{
$dbConnect = DB::connection('rhawn_mysql');
$product = $dbConnect->table('products')
->whereIn('p_id',(array)$pIds)
->get()->toArray();
if(count($product) > 0){
return $product;
}
return null;
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':getRawProductsThroughPid ','error');
throw $exception;
}
}
/**
* 通过产品code查找
* @param $pCode
......
<?php
/*
* This file is part of the Jiannei/lumen-api-starter.
*
* (c) Jiannei <longjian.huang@foxmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace App\Services\ThirdPlatform\Api;
use App\ImportExport\WuxiLab\WuxiLabExport;
use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Services\ThirdPlatform\PlatformAbstractService;
use App\Support\Facades\SimpleLogs;
......@@ -29,27 +19,23 @@ class WuxiApiNewService extends PlatformAbstractService
$this->getPlatformInfo();
}
public function getToken()
{
return $this->postApi('/token/fetch', [
'username' => '790087059@qq.com',
'password' => 'YXH19920517!!'
]);
}
/**
* 批量更新商品信息
* @param $product
* @return bool
*/
public function pushBatchUpdateProduct($product)
public function pushBatchUpdateProduct($product, $token)
{
try{
if($this->checkPlatformStatus()){
$params = $this->mergeApiMetaData($product);
$response = $this->getPostClient($this->platformInfo['platform_url'].'/api/v2/updateChamical',$params, null,
[
'authorization' => $this->getAuthHeader()
]
);
return $this->apiResponse($response);
}
}catch(\Exception $e){
$this->requestError($e);
}
return $this->postApi('/api/v2/updateChamical', $params, $token);
}
/**
......@@ -60,87 +46,17 @@ class WuxiApiNewService extends PlatformAbstractService
*/
public function pushBatchUpdatePackages($packages,$token)
{
try{
if($this->checkPlatformStatus()){
$params = [];
$params['company_id'] = $this->platformInfo['platform_params']['companyId'];
$params['product_type'] = 'CHAMICAL';
$params = array_merge($params,$packages);
$response = $this->getPostClient($this->platformInfo['platform_params']['adminUrl'].'/package/specification/save',$params,null, [
//'cookie' => $this->getCookie($token)
]);
return $this->apiResponse($response);
}
}catch(\Exception $e){
$this->requestError($e);
}
return $this->postApi('/api/v2/syncProductPackageStatus', $packages, $token);
}
public function getPackageList($token)
public function pushBatchUpdatePrice($prices,$token)
{
try{
if($this->checkPlatformStatus()){
$params = [];
$params['companyId'] = $this->platformInfo['platform_params']['companyId'];
$params['productType'] = 'CHAMICAL';
$urlParams = [];
foreach($params as $key => $param){
$urlParams[] = $key.'='.$param;
}
$response = $this->clientRequest('get',
$this->platformInfo['platform_params']['adminUrl'].'/package/specification/count?'.implode('&',$urlParams),
[
'headers' => [
//'cookie' => $this->getCookie($token),
'content-type' => 'application/json;charset=UTF-8'
]
]);
if($response && $response > 0){
$page = 1;
$count = ceil($response / 30);
$packageList = [];
while(true){
$params['page'] = $page;
$params['rows'] = 30;
$urlParams = [];
foreach($params as $key => $param){
$urlParams[] = $key.'='.$param;
}
$packageListResponse = $this->clientRequest('get',
$this->platformInfo['platform_params']['adminUrl'].'/package/specification/list?'.implode('&',$urlParams),
[
'headers' => [
//'cookie' => $this->getCookie($token),
'content-type' => 'application/json;charset=UTF-8'
]
]);
$result = $this->apiResponse($packageListResponse);
if($result){
$packageList = array_merge($packageList,$result);
}
$page ++;
if($page > $count){
break;
}
sleep(2);
}
return $packageList;
return $this->postApi('/api/v2/syncPackagePrice', $prices, $token);
}
return $this->apiResponse($response);
}
}catch(\Exception $e){
$this->requestError($e);
}
public function pushBatchUpdateStock($stock,$token)
{
return $this->postApi('/api/v2/syncRealTimeInventory', $stock, $token);
}
/**
......@@ -163,7 +79,8 @@ class WuxiApiNewService extends PlatformAbstractService
$tempData['chinese_name'] = $datas['r_cn_name'];
$tempData['english_name'] = $datas['r_en_name'];
$tempData['chemicalformula'] = $datas['c_fzs'] ?? '';
$tempData['purity'] = $datas['r_level'];
$tempData['purity'] = '00AR';//$datas['r_level'];
/*$tempData['usually_ships_days_min'] = '';
$tempData['usually_ships_within_days'] = '';
$tempData['backorder_lead_time'] = '';*/
......@@ -182,6 +99,9 @@ class WuxiApiNewService extends PlatformAbstractService
case 2: $tempData['transportation_condition'] = 1;break;
}
$tempData['smiles'] = $datas['c_smiles'];
$tempData['sub_category'] = 'INHIBITOR';
/*产品种类
1: Templates/Scaffolds,
2: Amino Acids &
......@@ -203,30 +123,31 @@ Compounds,
//$tempData['status'] = $datas['r_status'] == '1' ? 'ACTIVE' : 'INACTIVE';
$tempData['inventorys'][] = [
/*$tempData['inventorys'][] = [
'type' => $datas['r_unit'],
'quantity' => floatval($datas['r_stock']),
'country' => 'CN',
'stock_status' => $datas['r_stock'] > 0 ? 'INSTOCK' : 'OUTSTOCK',
];
];*/
$tempData['packages'] = [];
if(isset($metaData['packageList'][$datas['r_code']])){
$package = $metaData['packageList'][$datas['r_code']];
$pack['unit_description'] = $package['p_pack_unit'];
$currentPackageList = $metaData['packageList'];
if(!empty($currentPackageList)){
foreach($currentPackageList as $package){
$pack = [];
if($package['r_code'] == $datas['r_code']){
$pack['unit_description'] = $package['p_pack'].''.$package['p_pack_unit'];
//$pack['package_status'] = $package['p_status'] == '1' && $package['p_show'] == '1' && $package['p_if_big'] == 0 ? 'ACTIVE' : 'INACTIVE';
//$tempData['status'] = $package['p_status'] == '1' && $package['p_show'] == '1' && $package['p_if_big'] == 0 ? 'ACTIVE' : 'INACTIVE';
$pack['inventorys'] = [
'package_quantity' => $package['p_stock'],
$pack['inventorys'][] = [
'package_quantity' => '1',//$package['p_stock'],
//'stock_status' => $package['p_stock'] > 0 ? 'INSTOCK' : 'OUTSTOK',
'country' => 'CN'
'country' => 'CN-SH'
];
$pack['prices'] = [
'price' => $package['p_price'],
$pack['prices'][] = [
'price' => bcmul($package['p_price'], 0.5, 2),
'currency' => 'RMB',
//'status' => 'ACTIVE'
];
......@@ -237,15 +158,15 @@ Compounds,
'status' => $package['p_stock'] > 0 ? 'ACTIVE' : 'INACTVIE',
];*/
$pack['wuxiPackagePricings'] = [
'discount'=> 0.00,
$pack['wuxiPackagePricings'][] = [
'discount'=> 0.5,
'currency' => 'RMB',
//'status' => 'INACTIVE'
];
$tempData['packages'][] = $pack;
}
}
}
$mergeData[] = $tempData;
unset($tempData);
}
......@@ -253,26 +174,18 @@ Compounds,
return $mergeData;
}
public function getAuthHeader()
protected function postApi($apiUri, $postParams, $token = null)
{
$auth = $this->getPlatformDataEntries('wuxi_api_auth', 'data_values');
if(!$auth){
$response = $this->getPostClient($this->platformInfo['platform_url'].'/token/fetch', [
'username' => '790087059@qq.com',
'password' => 'YXH1992xb!!'
]
try {
if ($this->checkPlatformStatus()) {
$response = $this->getPostClient($this->platformInfo['platform_url'] . $apiUri, $postParams, null,
!is_null($token) ? [ 'Authorization' => 'Bearer ' . $token] : null
);
$result = $this->apiResponse($response);
if($result){
if($result['code'] == '200' && $result['success'] == 'true'){
$this->dataEntriesService->storeEntries(6, 'wuxi_api_auth',
['authorization' => $result['data']]
);
}
return $this->apiResponse($response);
}
return $result['data'];
}catch(\Exception $e){
$this->requestError($e);
}
return $auth['authorization'];
}
protected function apiResponse($response)
......
......@@ -31,7 +31,6 @@ abstract class PlatformAbstractService
}
protected function setPlatformName($platformName){
$this->platformName = '';
$this->platformName = $platformName;
}
......
......@@ -2,11 +2,11 @@
namespace App\Services\ThirdPlatform;
use App\ImportExport\WuxiLab\WuxiLabExport;
use App\Repositories\Contracts\ThirdApiPlatformRepository;
use App\Rhawn\Services\RhawnProductService;
use App\Services\ThirdPlatform\Api\WuxiApiNewService;
use App\Support\Facades\SimpleLogs;
use Illuminate\Support\Facades\DB;
class WuxiLabNewService
{
......@@ -19,14 +19,13 @@ class WuxiLabNewService
public function initToken()
{
$this->getToken();
//$this->apiService->removePlatformDataEntries('wuxilab_backlogin_token');
return $this->getToken();
}
/**
* 批量更新商品
*/
public function batchUpdateProducts($params = null)
public function batchUpdateProducts($type = 'all')
{
$status = $this->apiService->checkPlatformStatus();
if($status){
......@@ -54,291 +53,138 @@ class WuxiLabNewService
//$newPackages[$pack['r_code']] = $pack;
}
}
if(!empty($rawList)){
$this->apiService->pushQueue([
$queueParams = [];
switch($type){
case 'all': $queueParams = [
'params' => ['rawList' => $rawList,'packageList' => $newPackages],
'consumer' => __CLASS__,
'method' => 'queueBatchUpdateProductToApi'
];break;
case 'package': $queueParams = [
'params' => ['packageList' => $newPackages],
'consumer' => __CLASS__,
'method' => 'queueBatchUpdatePackagesToApi'
];break;
default:
$queueParams = [
'params' => ['rawList' => $rawList,'packageList' => $newPackages],
'consumer' => __CLASS__,
'method' => 'batchUpdateTo'
'method' => 'queueBatchUpdateProductToApi'
];
}
],'wuxilab_api');
if(!empty($rawList)){
$this->apiService->pushQueue($queueParams,'wuxilab_api');
}
break;
$page ++;
}
}
}
/**
* 商品批量下架
* @param null $params
* 批量更新产品价格
* @return void
* @throws \Exception
*/
public function batchUpdateProductsShelves($params = null)
public function batchUpdateProductPrice()
{
$status = $this->apiService->checkPlatformStatus();
if($status){
$limit = $this->apiService->getPlatformInfo('platform_params')['batchNums'];
$page = 0;
$dbConnect = DB::connection('rhawn_mysql');
ini_set('memory_limit','3072M');
$rawCodeList = [];
while(true) {
$rawList = $this->rhawnChemicalsService->getRawsList($page * $limit, $limit);
if (!$rawList) {
break;
}
foreach ($rawList as $raw) {
if(!in_array($raw['r_code'],$rawCodeList)){
array_push($rawCodeList,$raw['r_code']);
}
}
$page ++;
}
$path = app(WuxiLabExport::class)->saveExcel(
['rawCode' => $rawCodeList], 'product_shelves'
);
if($path){
list($file,$expend) = explode('.',$path);
$newPath = $file.'.'.strtolower($expend);
$cmd = 'mv '.storage_path('app/'.$path).' '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
$filePathList = explode('/',$file);
$fileName = $filePathList[count($filePathList) - 1];
/*$result = $this->apiService->pushBatchUploadFile($params['type'],$fileName, $this->apiService->backgroundLogin());
if($result){
$cmd = 'rm -rf '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
SimpleLogs::writeLog('文件名为:'.$fileName.'路径:'.$newPath.'药明康德后台上传完成', __CLASS__.':processNotExistProductsUpdate');
}*/
}
}
}
$startime = date('Y-m-d', strtotime('-1 day')).' 00:00:00';
$endtime = date('Y-m-d', time()).' 00:00:00';
/**
* 批量更新新的商品
*/
public function batchUploadNewProducts()
{
$storeEntries = $this->apiService->getPlatformDataEntries('wuxiLab_not_exist_products','data_values');
if(isset($storeEntries['products']) && !empty($storeEntries['products'])){
$countNum = 0;
$products = [];
foreach($storeEntries['products'] as $product){
if(!in_array($product,$products) || empty($products)){
array_push($products,$product);
$countNum ++;
}
if($countNum == $this->apiService->getPlatformInfo('platform_params')['excelCreateLimit']){
$this->apiService->pushQueue([
'params' => ['products' => $products,'type' => 'all'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
],'wuxilab_product');
$countNum = 0;
$products = [];
}
$product = $dbConnect->table('prochange')
->whereRaw("updatetime >=".strtotime($startime)." and updatetime <=".strtotime($endtime))
->where('type', '2')
->get()->toArray();
if(count($product) > 0){
$productIds = array_unique(array_column($product, 'p_id'));
$productList = $this->rhawnChemicalsService->getProductsListThroughPids($productIds);
$updateProductPrice = [];
foreach($productList as $product){
$tempData = [];
$tempData['product_division'] = 'CHEMICAL';
list($pCode, $packCode) = explode('-', $product->p_code);
$tempData['productId'] = $pCode;
$tempData['packageUnitDescription'] = $product->p_code;
$tempData['minPackageUnitDescription'] = '';
$tempData['price'] = bcmul($product->p_price, 0.5, 2);
$tempData['discount'] = '0.5';
$tempData['inCostCurrency'] = 'RMB';
$tempData['status'] = $product->p_status == '1' ? 'ACTIVE' : 'INACTIVE';;
$updateProductPrice[] = $tempData;
}
$result = $this->apiService->pushBatchUpdatePrice($updateProductPrice, $this->getToken());
$this->processApiResponse($result);
}
$this->apiService->removePlatformDataEntries('wuxiLab_not_exist_products');
}
}
/**
* @批量后台请求更新商品规格
* @param null $params
*/
public function batchUpdatePackagesInfo($params = null)
public function batchUpdateProductStock()
{
$token = $this->getToken();
$wuxiLabPackage = ['bottle','box','bp','case','ea','g','gal','hole','kg','kit','l','m','m2','mg','ml','mm','mmol','mu',
'ng','nmole','od','package','pair','piece','pmole','RL','sets','test', 'unit','vial','xa','µci','µg','µl','µmol'];
//$path = config('filesystems.disks.local.root').'/upload/'.$params;
//$generator = Helpers::yieldLoadCsv($path);
$status = $this->apiService->checkPlatformStatus();
if($status){
$dbConnect = DB::connection('rhawn_mysql');
// yield 循环逐行读取csv内容
/*while ($generator->valid()) {
$content = $generator->current();
if(in_array($content[1],$wuxiLabPackage)){
$this->apiService->pushBatchUpdatePackages([
'unit_quantity' => $content[0], 'unit_type' => $content[1], 'unit_description' => $content[0].$content[1]
],$token);
}
usleep(30000);
$generator->next();
}*/
$packageList = $this->apiService->getPackageList($token);
$startime = date('Y-m-d', strtotime('-1 day')).' 00:00:00';
$endtime = date('Y-m-d', time()).' 00:00:00';
$packagesUnit = $this->rhawnChemicalsService->getProductPackagesThroughGroupByPackUnit();
$product = $dbConnect->table('prochange')
->whereRaw("updatetime >=".strtotime($startime)." and updatetime <=".strtotime($endtime))
->where('type', '1')
->get()->toArray();
if(count($product) > 0){
$productIds = array_unique(array_column($product, 'p_id'));
$productList = $this->rhawnChemicalsService->getProductsListThroughPids($productIds);
foreach($packagesUnit as $package){
if(!empty($packageList)){
$exist = 0;
foreach($packageList as $p){
$name = $package['p_pack'].$package['p_pack_unit'];
if($name == $p['unitDescription']){
$exist = 1;
}
}
if(!$exist){
//转换
$package['p_pack_unit'] = strtolower($package['p_pack_unit']);
switch($package['p_pack_unit']){
case 'ul' : $package['p_pack_unit'] = 'µl';break;
case 'ug' : $package['p_pack_unit'] = 'µg';break;
}
if(!in_array($package['p_pack_unit'],$wuxiLabPackage)){
SimpleLogs::writeLog('unit_description:'.$package['p_pack'].strtolower($package['p_pack_unit']).'规格不在范围内,跳过', __CLASS__.':batchUpdatePackagesInfo');
continue;
}
try{
//如果包装数量不是数字,跳过
if(is_numeric($package['p_pack'])){
SimpleLogs::writeLog('unit_quantity:'.$package['p_pack'].' unit_type:'.strtolower($package['p_pack_unit']).' unit_description:'.$package['p_pack'].strtolower($package['p_pack_unit']), __CLASS__.':batchUpdatePackagesInfo');
$this->apiService->pushBatchUpdatePackages([
'unit_quantity' => $package['p_pack'], 'unit_type' => strtolower($package['p_pack_unit']), 'unit_description' => $package['p_pack'].strtolower($package['p_pack_unit'])
],$token);
}else{
SimpleLogs::writeLog('unit_description:'.$package['p_pack'].strtolower($package['p_pack_unit']).'数量不是数字,跳过', __CLASS__.':batchUpdatePackagesInfo');
continue;
}
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':batchUpdatePackagesInfo', 'error');
}
$updateProductStock = [];
foreach($productList as $product){
$tempData = [];
$tempData['product_division'] = 'CHEMICAL';
list($pCode, $packCode) = explode('-', $product->p_code);
$tempData['productId'] = 'R003250';//$pCode;
$tempData['packageUnitDescription'] = 'R003250-1ml';//$product->p_code;
$tempData['packageStockQuantity'] = $product->p_stock;
$tempData['packageStockLocation'] = 'CN-SH';
$tempData['stockStatus'] = $product->p_status == '1' ? 'ACTIVE' : 'INACTIVE';;
$updateProductStock[] = $tempData;
break;
}
$result = $this->apiService->pushBatchUpdateStock($updateProductStock, $this->getToken());
$this->processApiResponse($result);
}
}
}
/**
* @处理不存在商品的更新
* @param $params
* @return false|void
*/
public function processProductsUpdateThroughtExcel($params)
public function queueBatchUpdatePackagesToApi($updateData)
{
ini_set('memory_limit','3072M');
if(!isset($params['products']) || empty($params['products'])){
if(empty($updateData['packageList'])){
return false;
}
try{
$rawsList = $newPackages = [];
$slice_array_length= 500;
$current_length = 0;
while(true){
$list = [];
$product = array_slice($params['products'],$current_length,$slice_array_length);
$list = $this->rhawnChemicalsService->getChemicalRawThroughtCode($product);
if($list){
$rawIdList = [];
foreach ($list as $raw){
$rawIdList[] = $raw['r_id'];
}
$rawsList = array_merge($rawsList,$list);
$packages = $this->rhawnChemicalsService->getChemicalPackage($rawIdList);
if($packages){
foreach($packages as $pack){
//符合110状态才上架
if($pack['p_status'] == 1 && $pack['p_show'] == 1 && $pack['p_if_big'] == 0){
$newPackages[$pack['p_code']] = $pack;
}
}
}
}
if($current_length >= $this->apiService->getPlatformInfo('platform_params')['excelCreateLimit']){
break;
}
$current_length += $slice_array_length;
$packageList = [];
foreach($updateData['packageList'] as $packageCode => $data){
$tempData = [];
$tempData['product_division'] = 'CHEMICAL';
$tempData['productId'] = $data['r_code'];
$tempData['status'] = $data['p_status'] == '1' ? 'ACTIVE' : 'INACTIVE';
$tempData['packageUnitDescription'] = $packageCode;
$packageList[] = $tempData;
}
if($params['type'] == 'all'){
$productPath = app(WuxiLabExport::class)->saveExcel(
['rawList' => $rawsList,'packageList' => $newPackages],
'product'
);
if($productPath){
list($file,$expend) = explode('.',$productPath);
$newPath = $file.'.'.strtolower($expend);
$cmd = 'mv '.storage_path('app/'.$productPath).' '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
$filePathList = explode('/',$file);
$fileName = $filePathList[count($filePathList) - 1];
$result = $this->apiService->pushBatchUploadFile('product',$fileName, $this->apiService->backgroundLogin());
if($result){
$cmd = 'rm -rf '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
SimpleLogs::writeLog('文件名为:'.$fileName.'路径:'.$newPath.'药明康德后台上传完成', __CLASS__.':processNotExistProductsUpdate');
}
}
$packagePath = app(WuxiLabExport::class)->saveExcel(
['rawList' => $rawsList,'packageList' => $newPackages],
'package'
);
if($packagePath){
list($file,$expend) = explode('.',$packagePath);
$newPath = $file.'.'.strtolower($expend);
$cmd = 'mv '.storage_path('app/'.$packagePath).' '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
$filePathList = explode('/',$file);
$fileName = $filePathList[count($filePathList) - 1];
$result = $this->apiService->pushBatchUploadFile('product',$fileName, $this->apiService->backgroundLogin());
if($result){
$cmd = 'rm -rf '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
SimpleLogs::writeLog('文件名为:'.$fileName.'路径:'.$newPath.'药明康德后台上传完成', __CLASS__.':processNotExistProductsUpdate');
}
}
}else{
$path = app(WuxiLabExport::class)->saveExcel(
['rawList' => $rawsList,'packageList' => $newPackages],
$params['type']
);
if($path){
list($file,$expend) = explode('.',$path);
$newPath = $file.'.'.strtolower($expend);
$cmd = 'mv '.storage_path('app/'.$path).' '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
$filePathList = explode('/',$file);
$fileName = $filePathList[count($filePathList) - 1];
$result = $this->apiService->pushBatchUploadFile($params['type'],$fileName, $this->apiService->backgroundLogin());
if($result){
$cmd = 'rm -rf '.storage_path('app/'.$newPath);
trim(shell_exec("$cmd 2>&1"));
SimpleLogs::writeLog('文件名为:'.$fileName.'路径:'.$newPath.'药明康德后台上传完成', __CLASS__.':processNotExistProductsUpdate');
}
}
}
usleep(rand(1000000,5000000));
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':processNotExistProductsUpdate', 'error');
}
}
$result = $this->apiService->pushBatchUpdatePackages($packageList, $this->getToken());
$this->processApiResponse($result);
/**
* 批量更新商品包装
*/
public function batchUploadPackages()
{
$storeEntries = [];
$storeEntries = $this->apiService->getPlatformDataEntries('wuxiLab_do_not_update_products','data_values');
if(isset($storeEntries['products']) && !empty($storeEntries['products'])){
$countNum = 0;
$products = [];
foreach($storeEntries['products'] as $product){
if(!in_array($product,$products) || empty($products)){
array_push($products,$product);
$countNum ++;
}
if($countNum >= $this->apiService->getPlatformInfo('platform_params')['excelCreateLimit']){
$this->apiService->pushQueue([
'params' => ['products' => $products,'type' => 'package'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
],'wuxilab_package');
$countNum = 0;
$products = [];
}
}
$this->apiService->removePlatformDataEntries('wuxiLab_do_not_update_products');
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':batchUpdateToWuxiLab', 'error');
var_dump($exception->getMessage());
}
}
......@@ -346,93 +192,71 @@ class WuxiLabNewService
* @批量更新商品
* @param $updateData
*/
public function batchUpdateTo($updateData)
public function queueBatchUpdateProductToApi($updateData)
{
if(empty($updateData['rawList'])){
return false;
}
if(empty($updateData['packageList'])){
if(empty($updateData['rawList']) || empty($updateData['packageList'])){
return false;
}
try{
$result = $this->apiService->pushBatchUpdateProduct($updateData);
if($result){
//处理更新不成功的商品
if(!empty($result['errorProduct'])){
$storeEntries = $this->apiService->getPlatformDataEntries('wuxiLab_not_exist_products','data_values');
if(isset($storeEntries) && !empty($storeEntries)){
if(count($storeEntries['products']) >= $this->apiService->getPlatformInfo('platform_params')['excelCreateLimit']){
$this->apiService->pushQueue([
'params' => ['products' => $storeEntries['products'],'type' => 'product'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
],'wuxilab_product');
/*$this->apiService->pushQueue([
'params' => ['products' => $storeEntries['products'],'type' => 'package'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
],'wuxilab_package');*/
$this->apiService->removePlatformDataEntries('wuxiLab_not_exist_products');
/*SimpleKafka::produerSend(
[
'params' => ['products' => $storeEntries['products'],'type' => 'product'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
]
);*/
$storeEntries = [];
$noSmiles = [];
foreach($updateData['rawList'] as $data){
if(empty($data['c_smiles']) && !empty($data['c_cas'])){
$noSmiles[] = $data['c_cas'];
}
}
foreach($result['errorProduct'] as $errorProduct){
if($errorProduct['reason'] == 'PRODUCT_NOT_EXIST'){
if(!is_null($storeEntries) && !empty($storeEntries['products'])){
if(!in_array($errorProduct['data'],$storeEntries['products'])){
array_push($storeEntries['products'],$errorProduct['data']);
$updateData['rawList'] = array_column($updateData['rawList'], null, 'c_cas');
if(!empty($noSmiles)){
$noSmiles = array_unique($noSmiles);
$baikeMysql = DB::connection('baike_mysql');
$casResult = $baikeMysql->table('tp_mol_data')->whereIn('cas', $noSmiles)->get()->toArray();
if($casResult){
foreach($casResult as $cas){
$updateData['rawList'][$cas->cas]['c_smiles'] = $cas->smiles;
}
}else{
$storeEntries['products'][] = $errorProduct['data'];
}
}
$result = $this->apiService->pushBatchUpdateProduct($updateData, $this->getToken());
$this->processApiResponse($result);
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':batchUpdateToWuxiLab', 'error');
var_dump($exception->getMessage());
}
$this->apiService->storePlatformDataEntries('wuxiLab_not_exist_products',['products' => $storeEntries['products']]);
}
//更新成功,批量更新包装规格
$storeEntries = $this->apiService->getPlatformDataEntries('wuxiLab_do_not_update_products','data_values');
if(isset($storeEntries) && !empty($storeEntries)){
if(!is_null($storeEntries) && count($storeEntries['products']) >= $this->apiService->getPlatformInfo('platform_params')['excelCreateLimit']){
$this->apiService->pushQueue([
'params' => ['products' => $storeEntries['products'],'type' => 'package'],
'consumer' => __CLASS__,
'method' => 'processProductsUpdateThroughtExcel'
],'wuxilab_package');
$this->apiService->removePlatformDataEntries('wuxiLab_do_not_update_products');
$storeEntries = [];
protected function processApiResponse($apiResponse)
{
if($apiResponse){
//处理更新不成功的商品
if(!empty($apiResponse['errorProduct'])){
$errorProductsList = $this->apiService->getPlatformDataEntries('wuxiLab_error_products','data_values');
foreach($apiResponse['errorProduct'] as $errorProduct){
if(!is_null($errorProductsList) && !empty($errorProductsList['products'])){
if(!in_array($errorProduct['data'],$errorProductsList['products'])){
array_push($errorProductsList['products'],$errorProduct['data']);
}
}else{
$errorProductsList['products'][] = $errorProduct['data'];
}
$updateSuccessStoreEntries = $this->apiService->getPlatformDataEntries('wuxiLab_update_success_products','data_values');
//更新成功的商品
foreach($result['successProduct'] as $successProduct){
if(!is_null($storeEntries) && !empty($storeEntries['products'])){
if(!in_array($successProduct,$storeEntries['products'])){
array_push($storeEntries['products'],$successProduct);
}
}else{
$storeEntries['products'][] = $successProduct;
$this->apiService->storePlatformDataEntries('wuxiLab_error_products',['products' => $errorProductsList['products']]);
}
if(!is_null($updateSuccessStoreEntries) && !empty($updateSuccessStoreEntries['products'])){
if(!in_array($successProduct,$updateSuccessStoreEntries['products'])){
array_push($updateSuccessStoreEntries['products'],$successProduct);
if(!empty($apiResponse['errorPackage'])) {
$errorPackagesList = $this->apiService->getPlatformDataEntries('wuxiLab_error_packages', 'data_values');
//更新成功的商品
foreach ($apiResponse['errorPackage'] as $errorPackage) {
if (!is_null($errorPackagesList) && !empty($errorPackagesList['products'])) {
if (!in_array($errorPackage['data'], $errorPackagesList['products'])) {
array_push($errorPackagesList['products'], $errorPackage['data']);
}
}else{
$updateSuccessStoreEntries['products'][] = $successProduct;
} else {
$errorPackagesList['products'][] = $errorPackage['data'];
}
}
$this->apiService->storePlatformDataEntries('wuxiLab_do_not_update_products',['products' => $storeEntries['products']]);
$this->apiService->storePlatformDataEntries('wuxiLab_update_success_products',['products' => $updateSuccessStoreEntries['products']]);
$this->apiService->storePlatformDataEntries('wuxiLab_error_packages', ['products' => $errorPackagesList['products']]);
}
}catch(\Throwable $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':batchUpdateToWuxiLab', 'error');
var_dump($exception->getMessage());
}
}
......@@ -442,68 +266,18 @@ class WuxiLabNewService
*/
public function getToken(){
try{
$token = $this->apiService->getPlatformDataEntries('wuxilab_backlogin_token','data_values');
if(empty($token)){
$apiToken = $this->apiService->backgroundLogin();
if($apiToken){
$backloginToken = [];
$backloginToken['currentTime'] = time();
$backloginToken['token'] = $apiToken;
$this->apiService->storePlatformDataEntries('wuxilab_backlogin_token',$backloginToken);
return $apiToken;
}
}else{
//超过有效期,重新请求获取
if(intval(gmdate('i',time() - intval($token['currentTime']))) > 30){
$apiToken = $this->apiService->backgroundLogin();
if($apiToken){
$apiToken['currentTime'] = time();
$this->apiService->storePlatformDataEntries('wuxilab_backlogin_token',$apiToken);
return $apiToken['token'];
$token = $this->apiService->getPlatformDataEntries('wuxilab_token','data_values');
if(empty($token) || (time() > $token['ttl'])){
$token = $this->apiService->getToken();
if($token && $token['code'] == 200){
$this->apiService->storePlatformDataEntries('wuxilab_token',['token' => $token['data'], 'ttl' => strtotime('+2 hour')]);
return $token['data'];
}
}
return $token['token'];
}
}catch(\Exception $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':token error', 'error');
return false;
}
}
/**
* @初始化生成产品excel文档
* @param $exportLimit
*/
public function initCreateProductsToExcel($exportLimit)
{
$limit = $exportLimit;
$page = 0;
while(true) {
$rawList = $this->rhawnChemicalsService->getRawsList($page * $limit, $limit);
if (!$rawList) {
break;
}
$rawIdList = [];
foreach ($rawList as $raw) {
$rawIdList[] = $raw['r_id'];
}
$packages = $this->rhawnChemicalsService->getChemicalPackage($rawIdList);
$newPackages = [];
if($packages){
foreach($packages as $pack){
$newPackages[$pack['r_code']] = $pack;
}
}
if(!empty($rawList)){
app(WuxiLabExport::class)->saveExcel(
['rawList' => $rawList,'packageList' => $newPackages]
);
}
break;
}
}
}
......@@ -107,6 +107,22 @@ return [
'timezone' => env('CHEMSITE_DB_TIMEZONE', '+00:00'),
],
'baike_mysql' => [
'driver' => 'mysql',
'host' => env('BAIKE_DB_HOST', '127.0.0.1'),
'port' => env('BAIKE_DB_PORT', 3306),
'database' => env('BAIKE_DB_DATABASE', 'forge'),
'username' => env('BAIKE_DB_USERNAME', 'forge'),
'password' => env('BAIKE_DB_PASSWORD', ''),
'unix_socket' => env('BAIKE_DB_SOCKET', ''),
'charset' => env('BAIKE_DB_CHARSET', 'utf8mb4'),
'collation' => env('BAIKE_DB_COLLATION', 'utf8mb4_unicode_ci'),
'prefix' => env('BAIKE_DB_PREFIX', ''),
'strict' => env('BAIKE_DB_STRICT_MODE', true),
'engine' => env('BAIKE_DB_ENGINE', null),
'timezone' => env('BAIKE_DB_TIMEZONE', '+00:00'),
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment