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,83 +100,95 @@ class LeyanService
$dbConnect = DB::connection('bh_mysql');
$dbConnect->beginTransaction();
$chemicalsRow = $dbConnect->table('chemicals')
->where('c_cas', $bideProducts[0]['CASNumber'])
->get()->toArray();
if (empty($chemicalsRow)) {
return false;
}
$chemicalsRow = current($chemicalsRow);
$dbConnect->table('products')
->where('c_id', $chemicalsRow->c_id)
->where('b_id', $bId)
->update(['p_status' => 0, 'p_show' => 0, 'modifytime' => time()]);
$errorProduct = [];
foreach ($products as $product) {
foreach ($bideProducts as $product) {
if ($product['Weight'] > 0) {
$p_tod = '现货';
} else {
$p_tod = '无货,请咨询';
$chemicalsRow = $dbConnect->table('chemicals')
->where('c_cas', $product['casNo'])
->get()->toArray();
if (empty($chemicalsRow)) {
array_push($errorProduct,$product['casNo']);
continue;
}
$p_code = $product['ProductNum'] . '-' . $product['PackSize'];
$chemicalsRow = current($chemicalsRow);
$productRow = $dbConnect->table('products')
->where('b_id', $bId)
$dbConnect->table('products')
->where('c_id', $chemicalsRow->c_id)
->where('p_code', 'like', $p_code)
->get()->toArray();
$pro_data = [];
if (empty($productRow)) {
->where('b_id', $bId)
->update(['p_status' => 0, 'p_show' => 0, 'modifytime' => time()]);
$pro_data['b_id'] = $bId;
$pro_data['c_id'] = $chemicalsRow->c_id;
$pro_data['p_code'] = $p_code;
if (!$product['ProductCName']) {
$pro_data['p_cn_name'] = '';
} else {
$pro_data['p_cn_name'] = $product['ProductCName'];
foreach($product as $item){
$p_tod = '无货,请咨询';
if(!empty($item['productStockInfos'])){
foreach($item['productStockInfos'] as $stock){
if ($stock['city'] == '上海' && $stock['number'] > 0) {
$p_tod = '现货';
break;
}
}
}
if (!$product['ProductEName']) {
$pro_data['p_en_name'] = '';
} else {
$pro_data['p_en_name'] = $product['ProductEName'];
foreach($item['productStockPrices'] as $package){
$p_code = $item['catalogNo'] . '-' . $package['size'];
$productRow = $dbConnect->table('products')
->where('b_id', $bId)
->where('c_id', $chemicalsRow->c_id)
->where('p_code', 'like', $p_code)
->get()->toArray();
$pro_data = [];
if (empty($productRow)) {
$pro_data['b_id'] = $bId;
$pro_data['c_id'] = $chemicalsRow->c_id;
$pro_data['p_code'] = $p_code;
if (!$product['productNameCn']) {
$pro_data['p_cn_name'] = '';
} else {
$pro_data['p_cn_name'] = $product['productNameCn'];
}
if (!$product['productNameEn']) {
$pro_data['p_en_name'] = '';
} else {
$pro_data['p_en_name'] = $product['productNameEn'];
}
$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;
$pro_data['p_show'] = 0;
$pro_data['prom_from'] = 0;
$pro_data['prom_to'] = 0;
$id = $dbConnect->table('products')->insertGetId($pro_data);
} else {
$productRow = current($productRow);
$pro_data['p_status'] = 1;
$pro_data['p_show'] = 0;
$pro_data['p_price'] = $package['price'];
$pro_data['p_tod'] = $p_tod;
$pro_data['modifytime'] = time();
$dbConnect->table('products')
->where('p_id', $productRow->p_id)
->update($pro_data);
$id = $productRow->p_id;
}
}
$pro_data['p_level'] = $product['Purity'];
$pro_data['p_pack'] = $product['PackSize'];
$pro_data['p_price'] = $product['Price'];
$pro_data['p_tod'] = $p_tod;
$pro_data['p_weight'] = '0.01';
$pro_data['p_status'] = 1;
$pro_data['p_show'] = 0;
$pro_data['prom_from'] = 0;
$pro_data['prom_to'] = 0;
$id = $dbConnect->table('products')->insertGetId($pro_data);
} else {
$productRow = current($productRow);
$pro_data['p_status'] = 1;
$pro_data['p_show'] = 0;
$pro_data['p_price'] = $product['Price'];
$pro_data['p_tod'] = $p_tod;
$pro_data['modifytime'] = time();
$dbConnect->table('products')
->where('p_id', $productRow->p_id)
->update($pro_data);
$id = $productRow->p_id;
}
SimpleLogs::writeLog('Leyan p_id : '.$id.' cas : '.$chemicalsRow->c_cas. ' 更新成功,更新时间:'.date('Y-m-d H:i:s',time()),__CLASS__.':storeLeyanProducts');
}
$dbConnect->commit();
SimpleLogs::writeLog('Leyan p_id : '.$id.' cas : '.$chemicalsRow->c_cas. ' 更新成功,更新时间:'.date('Y-m-d H:i:s',time()),__CLASS__.':storeLeyanProducts');
return true;
}catch(\Exception $exception){
......
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