Commit 38c73c6c authored by hangjun83's avatar hangjun83

修复bug

parent b6165e6f
......@@ -158,6 +158,7 @@ class BhOrdersService
}
$request->attributes->add(['type' => 'sorder_refund']);
$service = app(BhSorderRefundRepository::class);
$service->pushCriteria(new BhSorderRefundCriteria($request));
$tasks = $service->paginate($params['page_size']);
......@@ -243,6 +244,10 @@ class BhOrdersService
// 减去退货数量,剩余的更新数量
$num = intval($orderitem['si_num']) - intval($refundInfo->refund_nums);
if($num < 0){
throw new \LogicException('退货数量大于购买数量',500);
}
//查询是否已经开票,如果开票不能进行退货
$dpdetail = $dbConnect->table('dpdetail')
->where('si_id',$orderitem['si_id'])
......@@ -258,11 +263,15 @@ class BhOrdersService
//修改item数据项
$service = app(BhSoitemsRepository::class);
$soItem = $service->findWhere(['si_id' => $orderitem['si_id'],'si_if_cancel' => 0]);
$soItem = current($soItem->toArray());
//更新原本数据
$updateArr = [];
$updateArr['si_num'] = $num == 0 ? 1 :$num; // 如果数量只有1,且退货数量相等
if($num == 0){
$updateArr['si_num'] = $refundInfo->refund_nums; // 如果数量只有1,且退货数量相等
}else{
$updateArr['si_num'] = bcsub($orderitem['si_num'], $refundInfo->refund_nums); // 如果数量只有1,且退货数量相等
}
$updateArr['si_assigned_num'] = $updateArr['si_num'];
$updateArr['si_amount'] = bcmul(
$orderitem['si_discount'] ,
......@@ -270,17 +279,20 @@ class BhOrdersService
2
);
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);
}
if($num > 1){
$updateArr['si_discount'] = bcdiv($updateArr['si_amount'] , $num, 2);
}else{
$updateArr['si_discount'] = $updateArr['si_amount'];
}
$service->update($updateArr,$soItem['si_id']);
// 如果数量等于0,更新原有的数据,不重新生成新的
$updatedItem = [];
if($num == 0){
$updatedItem = $soItem;
$updatedItem = array_merge($updatedItem,$updateArr);
}else{
//生成新记录
$createArr = $soItem;
unset($createArr['si_id']);
......@@ -305,6 +317,8 @@ class BhOrdersService
}
$newItem = $service->create($createArr);
$updatedItem = $newItem->toArray();
}
//修改配货单记录
if($dpdetail){
......@@ -344,7 +358,7 @@ class BhOrdersService
// 如果退货数量跟此明细数量相同
if(!is_null($needUpdate)){
$dpUpdateArr = [];
$dpUpdateArr['si_id'] = $newItem->toArray()['si_id'];
$dpUpdateArr['si_id'] = $updatedItem['si_id'];
// 如果有手续费,对价格进行更新
if($refundInfo->handle_fee > 0){
// 如果有手续费,将价格进行修改
......@@ -374,9 +388,10 @@ class BhOrdersService
arsort($minRecord); // 降序排序
$num = $refundInfo->refund_nums;
// minrecord有值,只有退货数量大于此条记录的数量时
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$newItem->toArray()['si_id'],$createArr,$updateArr,$refundInfo,'asort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$newItem->toArray()['si_id'],$createArr,$updateArr,$refundInfo,'arsort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$minRecord,$updatedItem['si_id'],$updatedItem,$refundInfo,'asort'));
$cancelRecord = array_merge($cancelRecord,$this->handleDpdetailInfo($dbConnect,$num,$maxRecord,$updatedItem['si_id'],$updatedItem,$refundInfo,'arsort'));
}
// 更新除了取消的记录以外的记录的价格
......@@ -426,7 +441,7 @@ class BhOrdersService
}
// 如果退货数量小于采购订单数量
if($item->pi_num >= $refundInfo->refund_nums){
if($item->pi_num > $refundInfo->refund_nums){
// 修改当前的数量和金额
$poItemUpdateArr = [];
$poNums = bcsub($item->pi_num, $refundInfo->refund_nums);
......@@ -454,13 +469,23 @@ class BhOrdersService
$poItemsId = $dbConnect->table('poitems')->insertGetId($poItemCreateArr);
//将soitems表中的新增记录中的pi_id修改为新值
$newItem->update([
$dbConnect->table('soitems')
->where('si_id',$updatedItem['si_id'])
->update([
'pi_id' => $poItemsId
]);
if($refundInfo->cancel_porder == 1){
echo 'afadfs';
// 取消采购订单
$this->cancelPorderItems($dbConnect,$poItemCreateArr['po_id'],$poItemsId);
}
}elseif($item->pi_num == $refundInfo->refund_nums){
if($refundInfo->cancel_porder == 1){
// 取消采购订单
$this->cancelPorderItems($dbConnect,$item->po_id,$item->pi_id);
}
}
}
}
......@@ -481,7 +506,7 @@ class BhOrdersService
*/
//预存款和退款处理
$this->cancelAndTransPrePay($dbConnect,$newItem->toArray()['si_id'],$refundInfo);
$this->cancelAndTransPrePay($dbConnect,$updatedItem['si_id'],$refundInfo);
}
}
......@@ -506,7 +531,7 @@ class BhOrdersService
* @param string $sort
* @return array
*/
protected function handleDpdetailInfo($dbConnect, &$num, $recordsArr, $si_id, $createArr, $updateArr, $refundInfo, $sort = 'arsort')
protected function handleDpdetailInfo($dbConnect, &$num, $recordsArr, $si_id, $updatedItem, $refundInfo, $sort = 'arsort')
{
$cancelRecord = [];
if(!empty($recordsArr) && count($recordsArr) > 0){
......@@ -520,9 +545,7 @@ class BhOrdersService
$num = $num - $re['dpd_num'];
$dpUpdateArr = [];
$dpUpdateArr['si_id'] = $si_id;
if($refundInfo->handle_fee > 0){
$dpUpdateArr['dpd_amount'] = bcmul($createArr['si_discount'], $re['dpd_num'], 2);
}
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $re['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr);
......@@ -535,9 +558,7 @@ class BhOrdersService
// 更新当前记录
$dpUpdateArr = [];
$dpUpdateArr['dpd_num'] = $re['dpd_num'] - $num;
if($refundInfo->handle_fee > 0){
$dpUpdateArr['dpd_amount'] = bcmul($updateArr['si_discount'], $dpUpdateArr['dpd_num'], 2);
}
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $dpUpdateArr['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$re['dpd_id'])
->update($dpUpdateArr);
......@@ -548,9 +569,7 @@ class BhOrdersService
$dpCreateArr = $re;
unset($dpCreateArr['dpd_id']);
$dpCreateArr['dpd_num'] = $num;
if($refundInfo->handle_fee > 0){
$dpCreateArr['dpd_amount'] = bcmul($createArr['si_discount'], $num, 2);
}
$dpCreateArr['dpd_amount'] = bcmul($updatedItem['si_discount'], $num, 2);
$dpCreateArr['si_id'] = $si_id;
$dpId = $dbConnect->table('dpdetail')->insertGetId($dpCreateArr);
......@@ -825,7 +844,7 @@ class BhOrdersService
}
app(BhSordersRepository::class)->update(['so_review_status' => '3', 'so_total' => '0'], $sOrderItem['so_id']);
app(BhSoitemsRepository::class)->update(['si_if_cancel' => '1', 'si_cancel_time' => $si_cancel_time], $sOrderItem['so_id']);
app(BhSoitemsRepository::class)->update(['si_if_cancel' => '1', 'si_cancel_time' => $si_cancel_time], $si_id);
}
$db->table('logs')->insertGetId(
......
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