Commit 8b86c936 authored by hangjun83's avatar hangjun83

修复bug

parent a0117c9e
...@@ -269,11 +269,34 @@ class BhOrdersService ...@@ -269,11 +269,34 @@ class BhOrdersService
//更新原本数据 //更新原本数据
$updateArr = []; $updateArr = [];
$createArr = [];
$updatedItem = [];
//如果取消的是全部
if($num == 0){ if($num == 0){
$updateArr['si_num'] = $refundInfo->refund_nums; // 如果数量只有1,且退货数量相等 // 如果需要手续费
if(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){
$createArr = $soItem;
unset($createArr['si_id']);
$createArr['si_num'] = $orderitem['si_num'];
$createArr['si_assigned_num'] = $createArr['si_num'];
$createArr['si_amount'] = bcsub($orderitem['si_amount'] , $refundInfo->handle_fee,2);
$createArr['si_discount'] = bcdiv($createArr['si_amount'], $orderitem['si_num'], 2);
$updateArr['si_num'] = $refundInfo->refund_nums;
$updateArr['si_assigned_num'] = $updateArr['si_num'];
$updateArr['si_amount'] = $refundInfo->handle_fee;
$updateArr['si_discount'] = bcdiv($updateArr['si_amount'],$refundInfo->refund_nums, 2);
}else{ }else{
$updateArr['si_num'] = bcsub($orderitem['si_num'], $refundInfo->refund_nums); // 如果数量只有1,且退货数量相等 $updatedItem['cancel_si_id'] = $orderitem['si_id'];
} }
} // 部分退货
else{
$updateArr['si_num'] = bcsub($orderitem['si_num'], $refundInfo->refund_nums); // 如果数量只有1,且退货数量相等
$updateArr['si_assigned_num'] = $updateArr['si_num']; $updateArr['si_assigned_num'] = $updateArr['si_num'];
$updateArr['si_amount'] = bcmul( $updateArr['si_amount'] = bcmul(
$orderitem['si_discount'] , $orderitem['si_discount'] ,
...@@ -283,33 +306,57 @@ class BhOrdersService ...@@ -283,33 +306,57 @@ class BhOrdersService
if(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){ if(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){
$updateArr['si_amount'] = bcadd($updateArr['si_amount'] , $refundInfo->handle_fee,2); $updateArr['si_amount'] = bcadd($updateArr['si_amount'] , $refundInfo->handle_fee,2);
} }
$updateArr['si_discount'] = bcdiv($updateArr['si_amount'] , $num, 2);
// 新增
$createArr = $soItem;
unset($createArr['si_id']);
$createArr['si_num'] = $refundInfo->refund_nums;
if(isset($refundInfo->handle_fee) && floatval($refundInfo->handle_fee) > 0){
$createArr['si_amount'] = abs(bcsub($currentAmount, $updateArr['si_amount'], 2));
$createArr['si_discount'] = bcdiv($createArr['si_amount'], $createArr['si_num'], 2);
} // 没有手续费的情况下
else{
$createArr['si_discount'] = $soItem['si_discount'];
$createArr['si_amount'] = bcmul($soItem['si_discount'], $refundInfo->refund_nums, 2);
}
$createArr['si_num'] = $refundInfo->refund_nums;
$createArr['si_assigned_num'] = $createArr['si_num'];
if($createArr['si_amount'] < 0){
throw new \LogicException('手续费异常,处理失败!',500);
}
}
/*If(isset($refundInfo->handle_fee) && $refundInfo->handle_fee > 0){
$updateArr['si_amount'] = bcadd($updateArr['si_amount'] , $refundInfo->handle_fee,2);
}
if($num > 1){ if($num > 1){
$updateArr['si_discount'] = bcdiv($updateArr['si_amount'] , $num, 2); $updateArr['si_discount'] = bcdiv($updateArr['si_amount'] , $num, 2);
}*/
if(!empty($updateArr)){
$update = $service->update($updateArr,$soItem['si_id']);
$updatedItem['update'] = $update->toArray();
}else{
$updatedItem['update'] = $orderitem;
} }
$service->update($updateArr,$soItem['si_id']);
/*$update = $service->update($updateArr,$soItem['si_id']);
$updatedItem['update'] = $update->toArray();*/
//判断是否能除尽 //判断是否能除尽
if(!empty($updateArr)){
if($updateArr['si_amount'] != $currentAmount && abs(bcsub($currentAmount , $updateArr['si_amount'])) < 1){ if($updateArr['si_amount'] != $currentAmount && abs(bcsub($currentAmount , $updateArr['si_amount'])) < 1){
$note[] = $soItem['si_id'] . '金额有小数'; $note[] = $soItem['si_id'] . '金额有小数';
} }
}
// 如果数量等于0,更新原有的数据,不重新生成新的
$updatedItem = [];
if($num == 0){
$updatedItem = $soItem;
$updatedItem = array_merge($updatedItem,$updateArr);
}else{
//生成新记录 //生成新记录
$createArr = $soItem; /*unset($createArr['si_id']);
unset($createArr['si_id']); $createArr['si_num'] = $refundInfo->refund_nums;
if(isset($refundInfo->handle_fee) && floatval($refundInfo->handle_fee) > 0){ if(isset($refundInfo->handle_fee) && floatval($refundInfo->handle_fee) > 0){
if($num == 0){ $createArr['si_amount'] = abs(bcsub($currentAmount, $updateArr['si_amount'], 2));
$createArr['si_amount'] = $refundInfo->handle_fee;
}else{
$createArr['si_amount'] = bcmul($refundInfo->refund_nums, $soItem['si_discount'], 2);
}
$createArr['si_discount'] = bcdiv($createArr['si_amount'], $createArr['si_num'], 2); $createArr['si_discount'] = bcdiv($createArr['si_amount'], $createArr['si_num'], 2);
} // 没有手续费的情况下 } // 没有手续费的情况下
else{ else{
...@@ -321,11 +368,18 @@ class BhOrdersService ...@@ -321,11 +368,18 @@ class BhOrdersService
if($createArr['si_amount'] < 0){ if($createArr['si_amount'] < 0){
throw new \LogicException('手续费异常,处理失败!',500); throw new \LogicException('手续费异常,处理失败!',500);
} }*/
if(!empty($createArr)){
$newItem = $service->create($createArr); $newItem = $service->create($createArr);
$updatedItem = $newItem->toArray(); $updatedItem['create'] = $newItem->toArray();
// 如果是部分退货
if($num > 0 || ($num == 0 && $refundInfo->handle_fee > 0)){
$updatedItem['cancel_si_id'] = $updatedItem['create']['si_id'];
} }
}
$updatedItem['total'] = $currentAmount;
//修改配货单记录 //修改配货单记录
if($dpdetail){ if($dpdetail){
...@@ -365,21 +419,22 @@ class BhOrdersService ...@@ -365,21 +419,22 @@ class BhOrdersService
// 如果退货数量跟此明细数量相同 // 如果退货数量跟此明细数量相同
if(!is_null($needUpdate)){ if(!is_null($needUpdate)){
$dpUpdateArr = []; $dpUpdateArr = [];
$dpUpdateArr['si_id'] = $updatedItem['si_id']; $dpUpdateArr['si_id'] = $updatedItem['update']['si_id'];
// 如果有手续费,对价格进行更新 // 如果有手续费,对价格进行更新
if($refundInfo->handle_fee > 0){ if($refundInfo->handle_fee > 0){
// 如果有手续费,将价格进行修改 // 如果有手续费,将价格进行修改
foreach($dpdetail as $detail){ /*foreach($dpdetail as $detail){
if($detail->dpd_id != $needUpdate['dpd_id']){ if($detail->dpd_id != $needUpdate['dpd_id']){
$otherUpdate = []; $otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updateArr['si_discount'], $needUpdate['dpd_num'], 2); $otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
->where('dpd_id',$dpdetail->dpd_id) ->where('dpd_id',$dpdetail->dpd_id)
->update($otherUpdate); ->update($otherUpdate);
} }
} }*/
//将取消的记录价格进行更新 //将取消的记录价格进行更新
$dpUpdateArr['dpd_amount'] = bcmul($createArr['si_discount'], $needUpdate['dpd_num'], 2); $dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $needUpdate['dpd_num'], 2);
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
->where('dpd_id',$needUpdate['dpd_id']) ->where('dpd_id',$needUpdate['dpd_id'])
->update($dpUpdateArr); ->update($dpUpdateArr);
...@@ -397,8 +452,8 @@ class BhOrdersService ...@@ -397,8 +452,8 @@ class BhOrdersService
$num = $refundInfo->refund_nums; $num = $refundInfo->refund_nums;
// minrecord有值,只有退货数量大于此条记录的数量时 // minrecord有值,只有退货数量大于此条记录的数量时
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$updatedItem['si_id'],$updatedItem,$refundInfo,'asort')); $cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$updatedItem,$refundInfo,'asort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$updatedItem['si_id'],$updatedItem,$refundInfo,'arsort')); $cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$updatedItem,$refundInfo,'arsort'));
} }
// 更新除了取消的记录以外的记录的价格 // 更新除了取消的记录以外的记录的价格
...@@ -478,7 +533,7 @@ class BhOrdersService ...@@ -478,7 +533,7 @@ class BhOrdersService
//将soitems表中的新增记录中的pi_id修改为新值 //将soitems表中的新增记录中的pi_id修改为新值
$dbConnect->table('soitems') $dbConnect->table('soitems')
->where('si_id',$updatedItem['si_id']) ->where('si_id',$updatedItem['create']['si_id'])
->update([ ->update([
'pi_id' => $poItemsId 'pi_id' => $poItemsId
]); ]);
...@@ -512,7 +567,7 @@ class BhOrdersService ...@@ -512,7 +567,7 @@ class BhOrdersService
*/ */
//预存款和退款处理 //预存款和退款处理
$this->cancelAndTransPrePay($dbConnect,$updatedItem['si_id'],$refundInfo); $this->cancelAndTransPrePay($dbConnect,$updatedItem['cancel_si_id'],$refundInfo);
} }
} }
...@@ -537,7 +592,7 @@ class BhOrdersService ...@@ -537,7 +592,7 @@ class BhOrdersService
* @param string $sort * @param string $sort
* @return array * @return array
*/ */
protected function handleDpdetailInfo($dbConnect, &$num, $recordsArr, $si_id, $updatedItem, $refundInfo, $sort = 'arsort') protected function handleDpdetailInfo($dbConnect, &$num, $recordsArr, $updatedItem, $refundInfo, $sort = 'arsort')
{ {
$cancelRecord = []; $cancelRecord = [];
if(!empty($recordsArr) && count($recordsArr) > 0){ if(!empty($recordsArr) && count($recordsArr) > 0){
...@@ -550,8 +605,8 @@ class BhOrdersService ...@@ -550,8 +605,8 @@ class BhOrdersService
if(($num > $re['dpd_num']) || ($num == $re['dpd_num'])){ if(($num > $re['dpd_num']) || ($num == $re['dpd_num'])){
$num = $num - $re['dpd_num']; $num = $num - $re['dpd_num'];
$dpUpdateArr = []; $dpUpdateArr = [];
$dpUpdateArr['si_id'] = $si_id; //$dpUpdateArr['si_id'] = $updatedItem['update']['si_id'];
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $re['dpd_num'], 2); $dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $re['dpd_num'], 2);
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id']) ->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr); ->update($dpUpdateArr);
...@@ -564,7 +619,7 @@ class BhOrdersService ...@@ -564,7 +619,7 @@ class BhOrdersService
// 更新当前记录 // 更新当前记录
$dpUpdateArr = []; $dpUpdateArr = [];
$dpUpdateArr['dpd_num'] = $re['dpd_num'] - $num; $dpUpdateArr['dpd_num'] = $re['dpd_num'] - $num;
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $dpUpdateArr['dpd_num'], 2); $dpUpdateArr['dpd_amount'] = bcsub($updatedItem['total'], $updatedItem['create']['si_amount'], 2);
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id']) ->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr); ->update($dpUpdateArr);
...@@ -574,15 +629,15 @@ class BhOrdersService ...@@ -574,15 +629,15 @@ class BhOrdersService
//添加新的取消记录 //添加新的取消记录
$dpCreateArr = $re; $dpCreateArr = $re;
unset($dpCreateArr['dpd_id']); unset($dpCreateArr['dpd_id']);
$dpCreateArr['dpd_num'] = $num; $dpCreateArr['dpd_num'] = $num;
$dpCreateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $num, 2); $dpCreateArr['dpd_amount'] = bcmul($updatedItem['create']['si_discount'], $num, 2);
$dpCreateArr['si_id'] = $si_id; $dpCreateArr['si_id'] = $updatedItem['create']['si_id'];
$dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr); $dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr);
$num = 0; $num = 0;
$cancelRecord[] = $dpId; $cancelRecord[] = $dpId;
} }
} }
} }
} }
...@@ -911,4 +966,23 @@ class BhOrdersService ...@@ -911,4 +966,23 @@ class BhOrdersService
} }
public function getBhSorderTaskLog($request)
{
$params = $this->formatKeysfromArray($request->all(),'toUnderScore');
$this->bhPordersRepository->pushCriteria(new BhPordersCriteria($request));
$pOrdersList = $this->bhPordersRepository->paginate($params['page_size']);
$returnRecord = [];
if($pOrdersList){
$record = $this->procOrderResponseData($pOrdersList->items());
}
// 获取当前角色的所有权限
$returnRecord['data'] = $this->formatKeysfromArray($record);
$returnRecord['current_page'] = $pOrdersList->currentPage();
$returnRecord['total'] = $pOrdersList->total();
return $returnRecord; }
} }
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