Commit 0c25be75 authored by hangjun83's avatar hangjun83

罗恩工具类更新

parent 8dc2f273
...@@ -329,26 +329,35 @@ class RhawnOrdersService ...@@ -329,26 +329,35 @@ class RhawnOrdersService
$dbConnect->beginTransaction(); $dbConnect->beginTransaction();
// 处理订单退货项 // 处理订单退货项
foreach($sOrder->toArray() as $orderitem){ foreach($sOrder->toArray() as $key => $orderitem){
if($refundInfo->item_id == $orderitem['si_id']) { if(in_array($orderitem['si_id'],explode(',',$refundInfo->item_id))) {
// 先处理源数据 // 先处理源数据
$currentPrice = floatval($orderitem['si_discount']); $currentPrice = floatval($orderitem['si_discount']);
$currentAmount = floatval($orderitem['si_amount']); $currentAmount = floatval($orderitem['si_amount']);
// 退货剩余数量 // 退货剩余数量
$numArr = !empty($refundInfo->refund_nums) ? explode(',', $refundInfo->refund_nums) : ''; $numArr = !empty($refundInfo->refund_nums) ? explode(',', $refundInfo->refund_nums) : '';
$futuresNum = $refundInfo->futures_num && $refundInfo->futures_num > 0 ? $refundInfo->futures_num : 0 ; $futuresNum = $refundInfo->futures_num && $refundInfo->futures_num > 0 ? $refundInfo->futures_num : 0;
$refundNums = [];
// 预判断退货数量 // 预判断退货数量
if (!empty($numArr)) { if (!empty($numArr)) {
$pstk_ids = []; $pstk_ids = [];
$refundNums = [];
foreach ($numArr as $num) { foreach ($numArr as $num) {
$pstkArr = explode('|', $num); $pstkArr = explode('|', $num);
$refundNums[$pstkArr[0]] = $pstkArr[1]; $refundNumsArr[$pstkArr[0]] = $pstkArr[1];
$pstk_ids[] = $pstkArr[0]; $pstk_ids[] = $pstkArr[0];
} }
$dpd = $dbConnect->table('dpdetail')
->whereIn('pstk_id', $pstk_ids)
->where('si_id',$orderitem['si_id'])
->where('dpd_invoiced', '=', 0)
->get();
foreach($dpd->toArray() as $d){
$refundNums[$d->pstk_id] = $refundNumsArr[$d->pstk_id];
}
//分组查询发货数量 //分组查询发货数量
/*$dpdSum = $dbConnect->table('dpdetail') /*$dpdSum = $dbConnect->table('dpdetail')
->whereIn('pstk_id', $pstk_ids) ->whereIn('pstk_id', $pstk_ids)
...@@ -373,7 +382,7 @@ class RhawnOrdersService ...@@ -373,7 +382,7 @@ class RhawnOrdersService
} }
// 如果是期货,强行初始一个数组执行一次 // 如果是期货,强行初始一个数组执行一次
if($futuresNum > 0 && empty($refundNums)){ if ($futuresNum > 0 && empty($refundNums)) {
$refundNums[0] = $futuresNum; $refundNums[0] = $futuresNum;
} }
...@@ -381,8 +390,6 @@ class RhawnOrdersService ...@@ -381,8 +390,6 @@ class RhawnOrdersService
foreach ($refundNums as $pstk_id => $num) { foreach ($refundNums as $pstk_id => $num) {
while (true) {
//修改item数据项 //修改item数据项
$service = app(RhawnSoitemsRepository::class); $service = app(RhawnSoitemsRepository::class);
$soItem = $service->findWhere(['si_id' => $orderitem['si_id'], 'si_if_cancel' => 0]); $soItem = $service->findWhere(['si_id' => $orderitem['si_id'], 'si_if_cancel' => 0]);
...@@ -393,7 +400,7 @@ class RhawnOrdersService ...@@ -393,7 +400,7 @@ class RhawnOrdersService
//如果有退货期货,检查退货期货数量是否大于当前期货数量 //如果有退货期货,检查退货期货数量是否大于当前期货数量
if ($futuresNum > 0) { if ($futuresNum > 0) {
if($pstk_id > 0){ if ($pstk_id > 0) {
$dpdSum = $dbConnect->table('dpdetail') $dpdSum = $dbConnect->table('dpdetail')
->where('pstk_id', $pstk_id) ->where('pstk_id', $pstk_id)
->where('si_id', $refundInfo->item_id) ->where('si_id', $refundInfo->item_id)
...@@ -401,22 +408,22 @@ class RhawnOrdersService ...@@ -401,22 +408,22 @@ class RhawnOrdersService
->groupBy('pstk_id') ->groupBy('pstk_id')
->select(DB::raw("sum(dpd_num) as num"),) ->select(DB::raw("sum(dpd_num) as num"),)
->get()->first(); ->get()->first();
}else{ } else {
$dpdSum = $dbConnect->table('dpdetail') $dpdSum = $dbConnect->table('dpdetail')
->where('si_id',$refundInfo->item_id) ->where('si_id', $refundInfo->item_id)
->where('dpd_invoiced', '=', 0) ->where('dpd_invoiced', '=', 0)
->select(DB::raw("sum(dpd_num) as num"),) ->select(DB::raw("sum(dpd_num) as num"),)
->get()->first(); ->get()->first();
} }
if(($soItem['si_num'] - $dpdSum->num) == 0){ if (($soItem['si_num'] - $dpdSum->num) == 0) {
$futuresNum = 0; $futuresNum = 0;
if($pstk_id == 0){ if ($pstk_id == 0) {
throw new \LogicException('当前数据不存在期货,无法对期货进行退货', 500); throw new \LogicException('当前数据不存在期货,无法对期货进行退货', 500);
} }
} }
if($futuresNum > 0) { if ($futuresNum > 0) {
if ($futuresNum > ($soItem['si_num'] - $dpdSum->num)) { if ($futuresNum > ($soItem['si_num'] - $dpdSum->num)) {
throw new \LogicException('期货退货数量大于可退货数量', 500); throw new \LogicException('期货退货数量大于可退货数量', 500);
} }
...@@ -431,7 +438,7 @@ class RhawnOrdersService ...@@ -431,7 +438,7 @@ class RhawnOrdersService
// 如果有期货数量优先处理 // 如果有期货数量优先处理
if ($futuresNum > 0) { if ($futuresNum > 0) {
$currentProcessNums = $futuresNum; $currentProcessNums = $futuresNum;
}else{ } else {
$currentProcessNums = $num; $currentProcessNums = $num;
} }
...@@ -518,7 +525,7 @@ class RhawnOrdersService ...@@ -518,7 +525,7 @@ class RhawnOrdersService
if (!empty($updateArr)) { if (!empty($updateArr)) {
$amount = bcmul($updateArr['si_discount'], $updateArr['si_num'], 2); $amount = bcmul($updateArr['si_discount'], $updateArr['si_num'], 2);
//if ($updateArr['si_amount'] != $amount) { //if ($updateArr['si_amount'] != $amount) {
if (bccomp($updateArr['si_amount'],$amount) != 0) { if (bccomp($updateArr['si_amount'], $amount) != 0) {
$note[] = 'si_id = ' . $soItem['si_id'] . '的数据有除不尽的情况,请手工处理'; $note[] = 'si_id = ' . $soItem['si_id'] . '的数据有除不尽的情况,请手工处理';
} }
} }
...@@ -536,6 +543,7 @@ class RhawnOrdersService ...@@ -536,6 +543,7 @@ class RhawnOrdersService
} }
$updatedItem['total'] = $currentAmount; $updatedItem['total'] = $currentAmount;
echo $futuresNum;
// 如果没有期货数量,dpdetail只处理现货数量 // 如果没有期货数量,dpdetail只处理现货数量
if ($futuresNum == 0) { if ($futuresNum == 0) {
...@@ -552,24 +560,24 @@ class RhawnOrdersService ...@@ -552,24 +560,24 @@ class RhawnOrdersService
$dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num - $currentProcessNums; $dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num - $currentProcessNums;
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $dpUpdateArr['dpd_num'], 2); $dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $dpUpdateArr['dpd_num'], 2);
// 出现全部退货 // 出现全部退货
if($dpUpdateArr['dpd_num'] == 0){ if ($dpUpdateArr['dpd_num'] == 0) {
if($refundInfo->handle_fee > 0){ if ($refundInfo->handle_fee > 0) {
$dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num; $dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num;
$dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $currentProcessNums, 2); $dpUpdateArr['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $currentProcessNums, 2);
} // 如果没有手续费,只修改对应的si_id } // 如果没有手续费,只修改对应的si_id
else{ else {
$dpUpdateArr['si_id'] = $updatedItem['create']['si_id']; $dpUpdateArr['si_id'] = $updatedItem['create']['si_id'];
$dpUpdateArr['dpd_amount'] = $dpdDetail->dpd_amount; $dpUpdateArr['dpd_amount'] = $dpdDetail->dpd_amount;
$dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num; $dpUpdateArr['dpd_num'] = $dpdDetail->dpd_num;
} }
} // 如果不是全部退货 } // 如果不是全部退货
else{ else {
if($refundInfo->handle_fee > 0){ if ($refundInfo->handle_fee > 0) {
$otherDpdDetail = $dbConnect->table('dpdetail') $otherDpdDetail = $dbConnect->table('dpdetail')
->where('si_id', $orderitem['si_id']) ->where('si_id', $orderitem['si_id'])
->whereNotIn('pstk_id', [$pstk_id]) ->whereNotIn('pstk_id', [$pstk_id])
->get()->first(); ->get()->first();
if($otherDpdDetail){ if ($otherDpdDetail) {
$otherUpdate = []; $otherUpdate = [];
$otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $otherDpdDetail->dpd_num, 2); $otherUpdate['dpd_amount'] = bcmul($updatedItem['update']['si_discount'], $otherDpdDetail->dpd_num, 2);
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
...@@ -578,11 +586,12 @@ class RhawnOrdersService ...@@ -578,11 +586,12 @@ class RhawnOrdersService
} }
} }
} }
$dbConnect->table('dpdetail') $dbConnect->table('dpdetail')
->where('dpd_id', $dpdDetail->dpd_id) ->where('dpd_id', $dpdDetail->dpd_id)
->update($dpUpdateArr); ->update($dpUpdateArr);
// 如果是部分退货 // 如果是部分退货
if (($currentProcessNums < $dpdDetail->dpd_num ) || ($currentProcessNums == $dpdDetail->dpd_num && $refundInfo->handle_fee > 0)) { if (($currentProcessNums < $dpdDetail->dpd_num) || ($currentProcessNums == $dpdDetail->dpd_num && $refundInfo->handle_fee > 0)) {
//添加新的取消记录 //添加新的取消记录
$dpCreateArr = $dpdDetail; $dpCreateArr = $dpdDetail;
unset($dpCreateArr->dpd_id); unset($dpCreateArr->dpd_id);
...@@ -600,7 +609,7 @@ class RhawnOrdersService ...@@ -600,7 +609,7 @@ class RhawnOrdersService
if ($futuresNum > 0) { if ($futuresNum > 0) {
$futuresNum = 0; $futuresNum = 0;
$currentProcessNums = 0; $currentProcessNums = 0;
if(empty($numArr)) break; if (empty($numArr)) break;
} else { } else {
break; break;
} }
...@@ -608,8 +617,6 @@ class RhawnOrdersService ...@@ -608,8 +617,6 @@ class RhawnOrdersService
} }
} }
} }
}
$dbConnect->commit(); $dbConnect->commit();
}catch(\Exception $e){ }catch(\Exception $e){
......
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