Commit 0fe01137 authored by hangjun83's avatar hangjun83

乐妍

parent 8b9ceb08
...@@ -86,9 +86,9 @@ class LeyanService ...@@ -86,9 +86,9 @@ class LeyanService
/** /**
* 保存bjs平台的产品数据 * 保存bjs平台的产品数据
*/ */
public function storeLeyanProducts($bideProducts) public function storeLeyanProducts($products)
{ {
if (!is_array($bideProducts) || empty($bideProducts)) { if (!is_array($products) || empty($products)) {
return false; return false;
} }
...@@ -100,83 +100,95 @@ class LeyanService ...@@ -100,83 +100,95 @@ class LeyanService
$dbConnect = DB::connection('bh_mysql'); $dbConnect = DB::connection('bh_mysql');
$dbConnect->beginTransaction(); $dbConnect->beginTransaction();
$chemicalsRow = $dbConnect->table('chemicals') $errorProduct = [];
->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()]);
foreach ($products as $product) {
foreach ($bideProducts as $product) { $chemicalsRow = $dbConnect->table('chemicals')
if ($product['Weight'] > 0) { ->where('c_cas', $product['casNo'])
$p_tod = '现货'; ->get()->toArray();
} else { if (empty($chemicalsRow)) {
$p_tod = '无货,请咨询'; array_push($errorProduct,$product['casNo']);
continue;
} }
$p_code = $product['ProductNum'] . '-' . $product['PackSize']; $chemicalsRow = current($chemicalsRow);
$productRow = $dbConnect->table('products') $dbConnect->table('products')
->where('b_id', $bId)
->where('c_id', $chemicalsRow->c_id) ->where('c_id', $chemicalsRow->c_id)
->where('p_code', 'like', $p_code) ->where('b_id', $bId)
->get()->toArray(); ->update(['p_status' => 0, 'p_show' => 0, 'modifytime' => time()]);
$pro_data = [];
if (empty($productRow)) {
$pro_data['b_id'] = $bId; foreach($product as $item){
$pro_data['c_id'] = $chemicalsRow->c_id; $p_tod = '无货,请咨询';
$pro_data['p_code'] = $p_code; if(!empty($item['productStockInfos'])){
if (!$product['ProductCName']) { foreach($item['productStockInfos'] as $stock){
$pro_data['p_cn_name'] = ''; if ($stock['city'] == '上海' && $stock['number'] > 0) {
} else { $p_tod = '现货';
$pro_data['p_cn_name'] = $product['ProductCName']; break;
}
}
} }
if (!$product['ProductEName']) { foreach($item['productStockPrices'] as $package){
$pro_data['p_en_name'] = '';
} else { $p_code = $item['catalogNo'] . '-' . $package['size'];
$pro_data['p_en_name'] = $product['ProductEName'];
$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(); $dbConnect->commit();
SimpleLogs::writeLog('Leyan p_id : '.$id.' cas : '.$chemicalsRow->c_cas. ' 更新成功,更新时间:'.date('Y-m-d H:i:s',time()),__CLASS__.':storeLeyanProducts');
return true; return true;
}catch(\Exception $exception){ }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