Commit 2317f863 authored by hangjun83's avatar hangjun83

乐妍

parent 3cbc7c48
......@@ -28,52 +28,52 @@ class LeyanService
public function updateProductsByEveryDay()
{
$currentPage = 1;
while(true){
$result = $this->apiService->pushBatchUpdateProductByPage($currentPage,1000,$this->getToken());
if(!$result || !$result['productInfo']){
while (true) {
$result = $this->apiService->pushBatchUpdateProductByPage($currentPage, 1000, $this->getToken());
if (!$result || !$result['productInfo']) {
return null;
}
try{
try {
$this->storeLeyanProducts($result['productInfo']);
if($result['allPage'] == $currentPage){
if ($result['allPage'] == $currentPage) {
break;
}
$currentPage ++;
}catch(\Exception $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':updateProductsByEveryDay', 'error');
$currentPage ++;
$currentPage++;
} catch (\Exception $exception) {
SimpleLogs::writeLog($exception->getMessage(), __CLASS__ . ':updateProductsByEveryDay', 'error');
$currentPage++;
}
}
}
public function batchUpdateProducts($params = null)
{
ini_set('memory_limit','3072M');
ini_set('memory_limit', '3072M');
$casList = app(BhuaProductService::class)->getProductCasByBidToGroupByCas($params);
if($casList){
foreach($casList as $cas){
if(empty($cas['c_cas'])) continue;
if ($casList) {
foreach ($casList as $cas) {
if (empty($cas['c_cas'])) continue;
$this->apiService->pushQueue([
'params' => ['cas' => $cas['c_cas']],
'consumer' => __CLASS__,
'method' => 'updateProductByCas'
],'leyan');
], 'leyan');
}
}
}
public function updateProductByCas($params)
{
if(!$params['cas']) return null;
if (!$params['cas']) return null;
$result = $this->apiService->pushUpdateProductByCas($params['cas'],$this->getToken());
if(!$result){
$result = $this->apiService->pushUpdateProductByCas($params['cas'], $this->getToken());
if (!$result) {
return null;
}
try{
try {
$result = $this->storeLeyanProducts($result);
}catch(\Exception $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':updateProductByCas', 'error');
} catch (\Exception $exception) {
SimpleLogs::writeLog($exception->getMessage(), __CLASS__ . ':updateProductByCas', 'error');
}
}
......@@ -81,34 +81,35 @@ class LeyanService
* @ 获取api token
* @return false|mixed
*/
public function getToken(){
try{
$token = $this->apiService->getPlatformDataEntries('leyan_api_token','data_values');
if(empty($token)){
public function getToken()
{
try {
$token = $this->apiService->getPlatformDataEntries('leyan_api_token', 'data_values');
if (empty($token)) {
$apiToken = $this->apiService->getToken();
if($apiToken){
if ($apiToken) {
$storeToken = [];
$storeToken['token'] = $apiToken;
$storeToken['currentTime'] = time();
$this->apiService->storePlatformDataEntries('leyan_api_token',$storeToken);
$this->apiService->storePlatformDataEntries('leyan_api_token', $storeToken);
return $storeToken['token'];
}
}else{
if((time() - $token['currentTime']) >= 86400){
} else {
if ((time() - $token['currentTime']) >= 86400) {
$apiToken = $this->apiService->getToken();
if($apiToken){
if ($apiToken) {
$storeToken = [];
$storeToken['token'] = $apiToken;
$storeToken['currentTime'] = time();
$this->apiService->storePlatformDataEntries('leyan_api_token',$storeToken);
$this->apiService->storePlatformDataEntries('leyan_api_token', $storeToken);
return $storeToken['token'];
}
}else{
} else {
return $token['token'];
}
}
}catch(\Exception $exception){
SimpleLogs::writeLog($exception->getMessage(), __CLASS__.':token error', 'error');
} catch (\Exception $exception) {
SimpleLogs::writeLog($exception->getMessage(), __CLASS__ . ':token error', 'error');
return false;
}
}
......@@ -124,22 +125,24 @@ class LeyanService
}
$bId = 108;
try {
$dbConnect = DB::connection('bh_mysql');
$dbConnect->beginTransaction();
$errorProduct = [];
foreach ($products as $product) {
try {
$id = 0;
$dbConnect->beginTransaction();
$chemicalsRow = $dbConnect->table('chemicals')
->where('c_cas', $product['casNo'])
->get()->toArray();
if (empty($chemicalsRow)) {
array_push($errorProduct,$product['casNo']);
array_push($errorProduct, $product['casNo']);
continue;
}
$chemicalsRow = current($chemicalsRow);
......@@ -149,12 +152,12 @@ class LeyanService
->where('b_id', $bId)
->update(['p_status' => 0, 'p_show' => 0, 'modifytime' => time()]);
foreach($product['productStockPrices'] as $package){
foreach ($product['productStockPrices'] as $package) {
$p_tod = '无货,请咨询';
$status = 0;
if(!empty($package['productStockInfos'])){
foreach($package['productStockInfos'] as $stock){
if(isset($stock['city'])){
if (!empty($package['productStockInfos'])) {
foreach ($package['productStockInfos'] as $stock) {
if (isset($stock['city'])) {
if ($stock['city'] == '上海' && isset($stock['number']) && $stock['number'] > 0) {
$p_tod = '现货';
$status = 1;
......@@ -175,8 +178,8 @@ class LeyanService
$pro_data = [];
if (empty($productRow)) {
if($status == 0){
SimpleLogs::writeLog('Leyan cas : '.$chemicalsRow->c_cas. '为下架状态不做更新',__CLASS__.':storeLeyanProducts');
if ($status == 0) {
SimpleLogs::writeLog('Leyan cas : ' . $chemicalsRow->c_cas . '为下架状态不做更新', __CLASS__ . ':storeLeyanProducts');
continue;
}
......@@ -193,7 +196,7 @@ class LeyanService
} else {
$pro_data['p_en_name'] = $product['productNameEn'];
}
if(isset($product['purity']) && !empty($product['purity'])){
if (isset($product['purity']) && !empty($product['purity'])) {
$pro_data['p_level'] = $product['purity'];
}
$pro_data['p_pack'] = $package['size'];
......@@ -214,7 +217,7 @@ class LeyanService
$pro_data['p_status'] = $status;
$pro_data['p_show'] = 1;
if($status == 1){
if ($status == 1) {
$pro_data['p_price'] = $package['price'];
}
$pro_data['p_tod'] = $p_tod;
......@@ -227,19 +230,17 @@ class LeyanService
}
}
if($id > 0){
SimpleLogs::writeLog('Leyan p_id : '.$id.' cas : '.$chemicalsRow->c_cas. ' 更新成功,更新时间:'.date('Y-m-d H:i:s',time()),__CLASS__.':storeLeyanProducts');
}
if ($id > 0) {
SimpleLogs::writeLog('Leyan p_id : ' . $id . ' cas : ' . $chemicalsRow->c_cas . ' 更新成功,更新时间:' . date('Y-m-d H:i:s', time()), __CLASS__ . ':storeLeyanProducts');
}
$dbConnect->commit();
return true;
}catch(\Exception $exception){
SimpleLogs::writeLog($exception->getMessage(),__CLASS__.':storeLeyanProducts', 'error');
} catch (\Exception $exception) {
SimpleLogs::writeLog($exception->getMessage(), __CLASS__ . ':storeLeyanProducts', 'error');
$dbConnect->rollback();
throw $exception;
}
}
return true;
}
}
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