Commit 40c47280 authored by hangjun83's avatar hangjun83

罗恩工具类更新

parent 36251951
......@@ -340,7 +340,7 @@ class RhawnOrdersService
$pstk_ids[] = $pstkArr[0];
}
//分组查询发货数量
$dpdSum = $dbConnect->table('dpdetail')
/*$dpdSum = $dbConnect->table('dpdetail')
->whereIn('pstk_id', $pstk_ids)
->where('dpd_invoiced', '=', 0)
->groupBy('pstk_id')
......@@ -359,11 +359,11 @@ class RhawnOrdersService
throw new \LogicException('退货数量大于购买数量', 500);
}
}
});
});*/
}
// 如果是期货,强行初始一个数组执行一次
if($futuresNum > 0){
if($futuresNum > 0 && empty($refundNums)){
$refundNums[0] = $futuresNum;
}
......@@ -371,12 +371,7 @@ class RhawnOrdersService
foreach ($refundNums as $pstk_id => $num) {
$currentProcessNums = $num;
// 如果有期货数量优先处理
if ($futuresNum > 0) {
$currentProcessNums = $futuresNum;
}
while (true) {
//修改item数据项
$service = app(RhawnSoitemsRepository::class);
......@@ -386,14 +381,48 @@ class RhawnOrdersService
throw new \LogicException('购买项数据id:' . $orderitem['si_id'] . '数据不存在或已取消!', 500);
}
// 判断有期货的时候退货数量是否大于soitem的数量
if($futuresNum > 0 && $futuresNum > $soItem['si_assigned_num']){
throw new \LogicException('期货退货数量大于已分配数量', 500);
//如果有退货期货,检查退货期货数量是否大于当前期货数量
if ($futuresNum > 0) {
if($pstk_id > 0){
$dpdSum = $dbConnect->table('dpdetail')
->where('pstk_id', $pstk_id)
->where('si_id', $refundInfo->item_id)
->where('dpd_invoiced', '=', 0)
->groupBy('pstk_id')
->select(DB::raw("sum(dpd_num) as num"),)
->get()->first();
}else{
$dpdSum = $dbConnect->table('dpdetail')
->where('si_id',$refundInfo->item_id)
->where('dpd_invoiced', '=', 0)
->select(DB::raw("sum(dpd_num) as num"),)
->get()->first();
}
if(($soItem['si_num'] - $dpdSum->num) == 0){
$futuresNum = 0;
if($pstk_id == 0){
throw new \LogicException('当前数据不存在期货,无法对期货进行退货', 500);
}
}
if($futuresNum > 0) {
if ($futuresNum > ($soItem['si_num'] - $dpdSum->num)) {
throw new \LogicException('期货退货数量大于可退货数量', 500);
}
}
}
// 判断现货退货数量是否大于soitem的数量
if($num > ($soItem['si_num'] - $soItem['si_assigned_num'])){
throw new \LogicException('现货退货数量大于已分配数量', 500);
if ($num > $soItem['si_num']) {
throw new \LogicException('现货退货数量大于可退货数量', 500);
}
// 如果有期货数量优先处理
if ($futuresNum > 0) {
$currentProcessNums = $futuresNum;
}else{
$currentProcessNums = $num;
}
//更新原本数据
......@@ -427,10 +456,10 @@ class RhawnOrdersService
if ($futuresNum > 0) {
$updateArr['si_num'] = $orderitem['si_num'] - $futuresNum;
$updateArr['si_assigned_num'] = $orderitem['si_assigned_num'] - $futuresNum;
//$updateArr['si_assigned_num'] = $orderitem['si_assigned_num'] - $futuresNum;
} else {
$updateArr['si_num'] = bcsub($orderitem['si_num'], $currentProcessNums); // 如果数量只有1,且退货数量相等
//$updateArr['si_assigned_num'] = $updateArr['si_num'];
$updateArr['si_assigned_num'] = $updateArr['si_num'];
}
$updateArr['si_amount'] = bcmul(
......@@ -507,13 +536,13 @@ class RhawnOrdersService
->get()->first();
//$dpdDetail = $dpdDetail->toArray();
if($dpdDetail) {
if ($dpdDetail) {
// 更新当前记录
$dpUpdateArr = [];
$dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num - $currentProcessNums;
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $dpUpdateArr['dpd_num'], 2);
$dbConnect->table('dpdetail')
->where('dpd_id',$dpdDetail->dpd_id)
->where('dpd_id', $dpdDetail->dpd_id)
->update($dpUpdateArr);
// 如果是部分退货
if ($currentProcessNums < $dpdDetail->dpd_num) {
......@@ -531,12 +560,10 @@ class RhawnOrdersService
//预存款和退款处理
$this->cancelAndTransPrePay($dbConnect, $updatedItem['cancel_si_id'], $refundInfo);
if ($currentProcessNums > 0) {
if ($futuresNum > 0) {
$futuresNum = 0;
}
$currentProcessNums = 0;
if(empty($numArr)) break;
} else {
break;
}
......@@ -544,6 +571,7 @@ class RhawnOrdersService
}
}
}
}
$dbConnect->commit();
......
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