erp订单抓取参数
This commit is contained in:
@@ -42,50 +42,102 @@ class ErpController extends Controller
|
||||
$endDate = strtotime($post['endDate']) + 86400;
|
||||
|
||||
$productOrders = ProductOrder::find()->alias('po')->where([
|
||||
'po.prescription_type' => 2,
|
||||
'po.is_sync_erp' => 0,
|
||||
])->andWhere([
|
||||
'in','po.status',[1,2,3,6,7]
|
||||
])->andWhere(['BETWEEN', 'po.created_at', $startDate, $endDate])
|
||||
->joinWith('approvedPrescription')
|
||||
->with(['orderItems','store', 'prescription'])->asArray()->all();
|
||||
'po.prescription_type' => 2,
|
||||
'po.is_sync_erp' => 0,
|
||||
])
|
||||
->andWhere([
|
||||
'in','po.status',[1,2,3,6,7]
|
||||
])
|
||||
->andWhere(['BETWEEN', 'po.created_at', $startDate, $endDate])
|
||||
// ->joinWith('approvedPrescription')
|
||||
->with(['orderItems','store', 'prescription'])
|
||||
->asArray()
|
||||
->all();
|
||||
//解析成erp所需参数(订单详情是否需要改动 - 线上订单的展示)
|
||||
$erpData = [];
|
||||
$ids = [];
|
||||
foreach($productOrders as $k=>$v){
|
||||
$erpData[$k]['orderId'] = $v['order_no'];
|
||||
$erpData[$k]['createTime'] = date('Y-m-d H:i:s', $v['created_at']);
|
||||
$erpData[$k]['userId'] = $v['store']['erp_id'];
|
||||
$erpData[$k]['orderStatus'] = $v['status'];
|
||||
$erpData[$k]['totalAmount'] = $v['total_pay_price'];
|
||||
// $erpData[$k]['deliveryAmount'] = $v['trans_expenses'];
|
||||
if($v['delivery_method'] == 1){ //到店自取
|
||||
$prescriptionContent = Json::decode($v['prescription']['content']);
|
||||
$erpData[$k]['deliveryName'] = $prescriptionContent['patient']['name'];
|
||||
$erpData[$k]['deliveryMobile'] = $prescriptionContent['patient']['mobile'];
|
||||
$erpData[$k]['deliveryAddress'] = $v['store']['position'];
|
||||
} else {//快递到家
|
||||
$erpData[$k]['deliveryName'] = $v['express_name'];
|
||||
$erpData[$k]['deliveryMobile'] = $v['express_mobile'];
|
||||
$erpData[$k]['deliveryAddress'] = $v['express_region'].$v['express_address'];
|
||||
}
|
||||
|
||||
$orderItems = [];
|
||||
foreach($v['orderItems'] as $vk=>$vv){
|
||||
// $drug = Drug::findOne($vv['drug_id']);
|
||||
$orderItems[$vk] = [
|
||||
'detailId' => $vv['id'],
|
||||
'productSku' => $vv['drug_no'],
|
||||
'quantity' => $vv['number'],
|
||||
'paymentPrice' => $vv['buy_price'],
|
||||
'price' => round($vv['number'] * $vv['buy_price'], 2)
|
||||
];
|
||||
}
|
||||
if ($v['order_type'] == 2) {
|
||||
|
||||
$erpData[$k]['orderItems'] = $orderItems;
|
||||
$ids[]=$v['id'];
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单数据:'. $v['id']. ':'. json_encode($orderItems));
|
||||
$erpData[$k]['orderId'] = $v['order_no'];
|
||||
$erpData[$k]['createTime'] = date('Y-m-d H:i:s', $v['created_at']);
|
||||
$erpData[$k]['userId'] = $v['store']['erp_id'];
|
||||
$erpData[$k]['orderStatus'] = $v['status'];
|
||||
$erpData[$k]['totalAmount'] = $v['total_pay_price'];
|
||||
// $erpData[$k]['deliveryAmount'] = $v['trans_expenses'];
|
||||
if($v['delivery_method'] == 1){ //到店自取
|
||||
if (!in_array($v['order_type'], [2])) {
|
||||
$prescriptionContent = Json::decode($v['prescription']['content']);
|
||||
$erpData[$k]['deliveryName'] = $prescriptionContent['patient']['name']?? '';
|
||||
$erpData[$k]['deliveryMobile'] = $prescriptionContent['patient']['mobile']?? '';
|
||||
$erpData[$k]['deliveryAddress'] = $v['store']['position']?? '';
|
||||
}
|
||||
} else {//快递到家
|
||||
$erpData[$k]['deliveryName'] = $v['express_name'];
|
||||
$erpData[$k]['deliveryMobile'] = $v['express_mobile'];
|
||||
$erpData[$k]['deliveryAddress'] = $v['express_region'].$v['express_address'];
|
||||
}
|
||||
|
||||
$orderItems = [];
|
||||
foreach($v['orderItems'] as $vk=>$vv){
|
||||
// $drug = Drug::findOne($vv['drug_id']);
|
||||
$orderItems[$vk] = [
|
||||
'detailId' => $vv['id'],
|
||||
'productSku' => $vv['drug_no'],
|
||||
'quantity' => $vv['number'],
|
||||
'paymentPrice' => $vv['buy_price'],
|
||||
'price' => round($vv['number'] * $vv['buy_price'], 2)
|
||||
];
|
||||
}
|
||||
|
||||
$erpData[$k]['orderItems'] = $orderItems;
|
||||
$ids[]=$v['id'];
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单数据:'. $v['id']. ':'. json_encode($orderItems));
|
||||
} else {
|
||||
|
||||
if (!empty($v['prescription'])) {
|
||||
|
||||
// 如果是处方药或者挂号药
|
||||
if ($v['prescription']['status'] == 1) {
|
||||
$erpData[$k]['orderId'] = $v['order_no'];
|
||||
$erpData[$k]['createTime'] = date('Y-m-d H:i:s', $v['created_at']);
|
||||
$erpData[$k]['userId'] = $v['store']['erp_id'];
|
||||
$erpData[$k]['orderStatus'] = $v['status'];
|
||||
$erpData[$k]['totalAmount'] = $v['total_pay_price'];
|
||||
// $erpData[$k]['deliveryAmount'] = $v['trans_expenses'];
|
||||
if($v['delivery_method'] == 1){
|
||||
//到店自取
|
||||
$prescriptionContent = Json::decode($v['prescription']['content']);
|
||||
$erpData[$k]['deliveryName'] = $prescriptionContent['patient']['name']?? '';
|
||||
$erpData[$k]['deliveryMobile'] = $prescriptionContent['patient']['mobile']?? '';
|
||||
$erpData[$k]['deliveryAddress'] = $v['store']['position']?? '';
|
||||
} else {//快递到家
|
||||
$erpData[$k]['deliveryName'] = $v['express_name'];
|
||||
$erpData[$k]['deliveryMobile'] = $v['express_mobile'];
|
||||
$erpData[$k]['deliveryAddress'] = $v['express_region'].$v['express_address'];
|
||||
}
|
||||
|
||||
$orderItems = [];
|
||||
foreach($v['orderItems'] as $vk=>$vv){
|
||||
// $drug = Drug::findOne($vv['drug_id']);
|
||||
$orderItems[$vk] = [
|
||||
'detailId' => $vv['id'],
|
||||
'productSku' => $vv['drug_no'],
|
||||
'quantity' => $vv['number'],
|
||||
'paymentPrice' => $vv['buy_price'],
|
||||
'price' => round($vv['number'] * $vv['buy_price'], 2)
|
||||
];
|
||||
}
|
||||
|
||||
$erpData[$k]['orderItems'] = $orderItems;
|
||||
$ids[]=$v['id'];
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单数据:'. $v['id']. ':'. json_encode($orderItems));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// ds($erpData);
|
||||
if(!empty($ids)){
|
||||
//更新为已同步erp
|
||||
\Yii::$app->db->createCommand()->update('yii_product_order', [
|
||||
@@ -96,7 +148,15 @@ class ErpController extends Controller
|
||||
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单结束,拉取订单数量:'.count($productOrders).', 拉取的订单ids:'.implode(',',$ids));
|
||||
} catch (\Exception $e) {
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单异常:'.$e->getMessage());
|
||||
// ds([
|
||||
// 'e' => $e->getMessage(),
|
||||
// 'trace' => $e->getTraceAsString(),
|
||||
// 'file' => $e->getFile(),
|
||||
// 'line' => $e->getLine(),
|
||||
// 'code' => $e->getCode(),
|
||||
// 'traceAsString' => $e->getTraceAsString(),
|
||||
// ]);
|
||||
ProductOrderLog::saveLog(0,'江奥川ERP拉取西(中成)药订单异常:'.$e->getMessage(). '在:'. $e->getFile(). '行:'. $e->getLine());
|
||||
throw new Exception('获取处方异常'.$e->getMessage());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user