Commit 0fe01137 authored by hangjun83's avatar hangjun83

乐妍

parent 8b9ceb08
......@@ -86,9 +86,9 @@ class LeyanService
/**
* 保存bjs平台的产品数据
*/
public function storeLeyanProducts($bideProducts)
public function storeLeyanProducts($products)
{
if (!is_array($bideProducts) || empty($bideProducts)) {
if (!is_array($products) || empty($products)) {
return false;
}
......@@ -100,11 +100,16 @@ class LeyanService
$dbConnect = DB::connection('bh_mysql');
$dbConnect->beginTransaction();
$errorProduct = [];
foreach ($products as $product) {
$chemicalsRow = $dbConnect->table('chemicals')
->where('c_cas', $bideProducts[0]['CASNumber'])
->where('c_cas', $product['casNo'])
->get()->toArray();
if (empty($chemicalsRow)) {
return false;
array_push($errorProduct,$product['casNo']);
continue;
}
$chemicalsRow = current($chemicalsRow);
......@@ -113,14 +118,19 @@ class LeyanService
->where('b_id', $bId)
->update(['p_status' => 0, 'p_show' => 0, 'modifytime' => time()]);
foreach ($bideProducts as $product) {
if ($product['Weight'] > 0) {
$p_tod = '现货';
} else {
foreach($product as $item){
$p_tod = '无货,请咨询';
if(!empty($item['productStockInfos'])){
foreach($item['productStockInfos'] as $stock){
if ($stock['city'] == '上海' && $stock['number'] > 0) {
$p_tod = '现货';
break;
}
}
$p_code = $product['ProductNum'] . '-' . $product['PackSize'];
}
foreach($item['productStockPrices'] as $package){
$p_code = $item['catalogNo'] . '-' . $package['size'];
$productRow = $dbConnect->table('products')
->where('b_id', $bId)
......@@ -134,19 +144,19 @@ class LeyanService
$pro_data['b_id'] = $bId;
$pro_data['c_id'] = $chemicalsRow->c_id;
$pro_data['p_code'] = $p_code;
if (!$product['ProductCName']) {
if (!$product['productNameCn']) {
$pro_data['p_cn_name'] = '';
} else {
$pro_data['p_cn_name'] = $product['ProductCName'];
$pro_data['p_cn_name'] = $product['productNameCn'];
}
if (!$product['ProductEName']) {
if (!$product['productNameEn']) {
$pro_data['p_en_name'] = '';
} else {
$pro_data['p_en_name'] = $product['ProductEName'];
$pro_data['p_en_name'] = $product['productNameEn'];
}
$pro_data['p_level'] = $product['Purity'];
$pro_data['p_pack'] = $product['PackSize'];
$pro_data['p_price'] = $product['Price'];
$pro_data['p_level'] = $product['purity'];
$pro_data['p_pack'] = $package['size'];
$pro_data['p_price'] = $package['price'];
$pro_data['p_tod'] = $p_tod;
$pro_data['p_weight'] = '0.01';
$pro_data['p_status'] = 1;
......@@ -162,7 +172,7 @@ class LeyanService
$pro_data['p_status'] = 1;
$pro_data['p_show'] = 0;
$pro_data['p_price'] = $product['Price'];
$pro_data['p_price'] = $package['price'];
$pro_data['p_tod'] = $p_tod;
$pro_data['modifytime'] = time();
$dbConnect->table('products')
......@@ -172,10 +182,12 @@ class LeyanService
$id = $productRow->p_id;
}
}
$dbConnect->commit();
}
SimpleLogs::writeLog('Leyan p_id : '.$id.' cas : '.$chemicalsRow->c_cas. ' 更新成功,更新时间:'.date('Y-m-d H:i:s',time()),__CLASS__.':storeLeyanProducts');
}
$dbConnect->commit();
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