|
|
@@ -116,21 +116,21 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
$other_cart_ids[] = $other;
|
|
|
}
|
|
|
$data = [$cart_ids, $other_cart_ids];
|
|
|
- $split_cart_ids = $cart_ids;
|
|
|
- if ($other_cart_ids && $orderInfo['status'] == 0 && $is_refund) {
|
|
|
- //拆分剩余 都是赠品
|
|
|
- $is_gift = true;
|
|
|
- foreach ($other_cart_ids as $cart) {
|
|
|
- if (!isset($cartInfo[$cart['cart_id']]) || !$cartInfo[$cart['cart_id']]['is_gift']) {
|
|
|
- $is_gift = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if ($is_gift) {//未发货 申请退款 整单退
|
|
|
- return [];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ $split_cart_ids = $cart_ids;
|
|
|
+ if ($other_cart_ids && $orderInfo['status'] == 0 && $is_refund) {
|
|
|
+ //拆分剩余 都是赠品
|
|
|
+ $is_gift = true;
|
|
|
+ foreach ($other_cart_ids as $cart) {
|
|
|
+ if (!isset($cartInfo[$cart['cart_id']]) || !$cartInfo[$cart['cart_id']]['is_gift']) {
|
|
|
+ $is_gift = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($is_gift) {//未发货 申请退款 整单退
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** @var StoreOrderServices $storeOrderServices */
|
|
|
$storeOrderServices = app()->make(StoreOrderServices::class);
|
|
|
$orderInfo = $storeOrderServices->tidyOrder($orderInfo, true, true);
|
|
|
@@ -245,9 +245,9 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
$order_data['give_coupon'] = is_array($order_data['give_coupon']) ? implode(',', $order_data['give_coupon']) : $order_data['give_coupon'];
|
|
|
//$pid 平行拆分 0:子订单拆分
|
|
|
$order_data['pid'] = $pid ?: $id;
|
|
|
- $parentOrder = $this->dao->get($order_data['pid']);
|
|
|
- $oldOrderId = $parentOrder['order_id'];
|
|
|
- $childCont = $this->dao->count(['pid' => $parentOrder['id']]);
|
|
|
+ $parentOrder = $this->dao->get($order_data['pid']);
|
|
|
+ $oldOrderId = $parentOrder['order_id'];
|
|
|
+ $childCont = $this->dao->count(['pid' => $parentOrder['id']]);
|
|
|
if ($store_id) {//门店分配拆分
|
|
|
/** @var SystemStoreServices $storeServices */
|
|
|
$storeServices = app()->make(SystemStoreServices::class);
|
|
|
@@ -269,7 +269,7 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
];
|
|
|
} else {//发货拆分
|
|
|
// $order_data['order_id'] = $storeOrderCreateServices->getNewOrderId();
|
|
|
- $order_data['order_id'] = $oldOrderId . '_' . ($childCont + 1);
|
|
|
+ $order_data['order_id'] = $oldOrderId . '_' . ($childCont + 1);
|
|
|
$status_data = [
|
|
|
'change_type' => 'split_create_order',
|
|
|
'change_message' => $is_refund ? '售后退款拆分生成订单' : '发货拆分生成订单',
|
|
|
@@ -299,8 +299,8 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
$cart_data['oid'] = $new_id;
|
|
|
unset($cart_data['id']);
|
|
|
$cart_data['split_surplus_num'] = $cart['cart_num'];
|
|
|
- $unit_write_times = max($_info['productInfo']['attrInfo']['write_times'] ?? 1, 1);
|
|
|
- $cart_data['write_times'] = bcmul((string)$cart['cart_num'], (string)$unit_write_times,0);
|
|
|
+ $unit_write_times = max($_info['productInfo']['attrInfo']['write_times'] ?? 1, 1);
|
|
|
+ $cart_data['write_times'] = bcmul((string)$cart['cart_num'], (string)$unit_write_times, 0);
|
|
|
$split_refund_num = $append[$cart['cart_id']]['cart_num'] ?? 0;
|
|
|
if (!$is_not_split) {//新增cart_info
|
|
|
$cart_data['cart_id'] = $storeOrderCreateServices->getNewOrderId('');
|
|
|
@@ -315,22 +315,22 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
|
|
|
//拆出订单
|
|
|
if (!$i) {
|
|
|
- //无核销 || 核销数量大于拆分数量
|
|
|
- if (!$cart_data['writeoff_time']) {
|
|
|
- $surplus_num = min($cart_data['write_surplus_times'], $cart_data['write_times']);
|
|
|
- } else {
|
|
|
- $writoff_numm = bcsub((string)$cart_data['write_times'], (string)$cart_data['write_surplus_times'], 0);
|
|
|
- $surplus_num = $writoff_numm >= $cart_data['write_times'] ? 0 : bcsub((string)$cart_data['write_times'], (string)$writoff_numm, 0);
|
|
|
+ //无核销 || 核销数量大于拆分数量
|
|
|
+ if (!$cart_data['writeoff_time']) {
|
|
|
+ $surplus_num = min($cart_data['write_surplus_times'], $cart_data['write_times']);
|
|
|
+ } else {
|
|
|
+ $writoff_numm = bcsub((string)$cart_data['write_times'], (string)$cart_data['write_surplus_times'], 0);
|
|
|
+ $surplus_num = $writoff_numm >= $cart_data['write_times'] ? 0 : bcsub((string)$cart_data['write_times'], (string)$writoff_numm, 0);
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
if ($is_refund) $refund_num = $cart['cart_num'];
|
|
|
} else {//修改原订单
|
|
|
//无核销 || 核销数量大于拆分数量
|
|
|
if (!$cart_data['writeoff_time']) {
|
|
|
$surplus_num = $cart_data['write_times'];
|
|
|
} else {
|
|
|
- $cart_num_times = bcmul((string)$cart['cart_num'], (string)$unit_write_times, 0);
|
|
|
- $surplus_num = $cart_data['write_surplus_times'] <= $cart_num_times ? 0 : bcsub((string)$cart_data['write_surplus_times'], (string)$cart_num_times, 0);
|
|
|
+ $cart_num_times = bcmul((string)$cart['cart_num'], (string)$unit_write_times, 0);
|
|
|
+ $surplus_num = $cart_data['write_surplus_times'] <= $cart_num_times ? 0 : bcsub((string)$cart_data['write_surplus_times'], (string)$cart_num_times, 0);
|
|
|
}
|
|
|
if ($is_refund) $refund_num = $split_refund_num >= $cart_data['refund_num'] ? 0 : bcsub((string)$cart_data['refund_num'], (string)$split_refund_num, 0);
|
|
|
}
|
|
|
@@ -435,7 +435,7 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
{
|
|
|
$order_update['cart_id'] = array_column($cart_info_data, 'cart_id');
|
|
|
$order_update['total_num'] = array_sum(array_column($cart_info_data, 'cart_num'));
|
|
|
- $total_price = $true_total_price = $coupon_price = $deduction_price = $use_integral = $pay_postage = $gainIntegral = $one_brokerage = $two_brokerage = $promotions_price = $first_order_price = 0;
|
|
|
+ $cost = $total_price = $true_total_price = $coupon_price = $deduction_price = $use_integral = $pay_postage = $gainIntegral = $one_brokerage = $two_brokerage = $promotions_price = $first_order_price = 0;
|
|
|
$wrrteoffed = 0;
|
|
|
foreach ($cart_info_data as $cart) {
|
|
|
$_info = json_decode($cart['cart_info'], true);
|
|
|
@@ -452,14 +452,15 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
$coupon_price = bcadd((string)$coupon_price, (string)($_info['coupon_price'] ?? '0'), 2);
|
|
|
$use_integral = bcadd((string)$use_integral, (string)($_info['use_integral'] ?? '0'), 0);
|
|
|
if (!in_array($orderInfo['shipping_type'], [2, 4])) {
|
|
|
- $pay_postage = bcadd((string)$pay_postage, (string)($_info['postage_price'] ?? '0'), 2);
|
|
|
+ $pay_postage = bcadd((string)$pay_postage, (string)($_info['postage_price'] ?? '0'), 2);
|
|
|
}
|
|
|
$cartInfoGainIntegral = bcmul((string)$cart['cart_num'], (string)($_info['productInfo']['give_integral'] ?? '0'), 0);
|
|
|
$gainIntegral = bcadd((string)$gainIntegral, (string)$cartInfoGainIntegral, 0);
|
|
|
$one_brokerage = bcadd((string)$one_brokerage, (string)($_info['one_brokerage'] ?? '0'), 2);
|
|
|
$two_brokerage = bcadd((string)$two_brokerage, (string)($_info['two_brokerage'] ?? '0'), 2);
|
|
|
+ $cost = bcadd((string)$cost, (string)bcmul((string)$cart['cart_num'], (string)($_info['costPrice'] ?? '0'), 2), 2);
|
|
|
$promotions_price = bcadd((string)$promotions_price, (string)bcmul((string)$cart['cart_num'], (string)($_info['promotions_true_price'] ?? '0'), 2), 2);
|
|
|
- $first_order_price = bcadd((string)$first_order_price, (string)($_info['first_order_price'] ?? '0'), 2);
|
|
|
+ $first_order_price = bcadd((string)$first_order_price, (string)($_info['first_order_price'] ?? '0'), 2);
|
|
|
}
|
|
|
|
|
|
$order_update['coupon_id'] = array_unique(array_column($cart_info_data, 'coupon_id'));
|
|
|
@@ -485,15 +486,16 @@ class StoreOrderSplitServices extends BaseServices
|
|
|
$order_update['pay_postage'] = $pay_postage;
|
|
|
$order_update['one_brokerage'] = $one_brokerage;
|
|
|
$order_update['two_brokerage'] = $two_brokerage;
|
|
|
+ $order_update['cost'] = $cost;
|
|
|
$order_update['promotions_price'] = $promotions_price;
|
|
|
- $order_update['first_order_price'] = $first_order_price;
|
|
|
+ $order_update['first_order_price'] = $first_order_price;
|
|
|
|
|
|
if ($orderInfo['status'] == 5) {//部分核销拆单
|
|
|
- if(count($cart_info_data) == $wrrteoffed) {//全部核销
|
|
|
- $order_update['status'] = 2;
|
|
|
- } else {
|
|
|
- $order_update['status'] = 0;
|
|
|
- }
|
|
|
+ if (count($cart_info_data) == $wrrteoffed) {//全部核销
|
|
|
+ $order_update['status'] = 2;
|
|
|
+ } else {
|
|
|
+ $order_update['status'] = 0;
|
|
|
+ }
|
|
|
}
|
|
|
if (false === $this->dao->update($id, $order_update, 'id')) {
|
|
|
throw new ValidateException('保存新订单商品信息失败');
|