问题说明:代客下单订单提交数据返回处理有误
修改文件:app/services/order/cashier/CashierOrderServices.php
修改方法:computeOrder()
修改最后返回数据
public function computeOrder(int $uid = 0, int $storeId = 0, array $cartIds = [], bool $integral = false, bool $coupon = false, array $userInfo = [], int $coupon_id = 0, bool $new = false, array $cartGroup = [], int $addressId = 0, string $payType = 'yue', int $shippingType = 4, int $is_store_delivery_type = 0, array $addressInfo = [])
{
if (!$userInfo && $uid) {
/** @var UserServices $userService */
$userService = app()->make(UserServices::class);
$userInfo = $userService->getUserInfo($uid);
if (!$userInfo) {
throw new ValidateException('用户不存在');
}
$userInfo = $userInfo->toArray();
}
$payPostage = 0;
$storePostageDiscount = 0;
$firstOrderPrice = 0;
/** @var StoreOrderComputedServices $computeOrderService */
$computeOrderService = app()->make(StoreOrderComputedServices::class);
if ($cartGroup && $shippingType != 4) {
$cartInfo = $cartGroup['cartInfo'];
$priceGroup = $cartGroup['priceGroup'];
$deduction = $cartGroup['deduction'];
$other = $cartGroup['other'];
$promotions = $other['promotions'] ?? [];
$payPrice = (float)$priceGroup['totalPrice'];
$payIntegral = (int)$priceGroup['totalIntegral'] ?? 0;
$couponPrice = (float)$priceGroup['couponPrice'];
$firstOrderPrice = (float)$priceGroup['firstOrderPrice'];
$sumPrice = $priceGroup['sumPrice'];//获取订单原总金额
$totalPrice = $priceGroup['totalPrice'];//获取订单svip、用户等级优惠之后总金额
$settlePrice = $priceGroup['settlePrice'] ?? 0;//供应商商品结算金额
$costPrice = $priceGroup['costPrice'];//获取订单成本价
$vipPrice = $priceGroup['vipPrice'];//获取订单会员优惠金额
$changePrice = (float)$priceGroup['changePrice'] ?? 0.00;
$promotionsPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'sum_promotions_price', false);//优惠活动优惠
$addr = $cartGroup['addr'] ?? $addressInfo;
$postage = $priceGroup;
if($addressId && $addr && isset($addr['id']) && $addr['id'] != $addressId) {
/** @var UserAddressServices $addressServices */
$addressServices = app()->make(UserAddressServices::class);
$addr = $addressServices->getAdderssCache($addressId);
//改变地址重新计算邮费
$postage = [];
}
$type = (int)$deduction['type'] ?? 0;
$results = batch([
'promotions' => function () use ($cartInfo, $type) {
$promotionsPrice = 0;
if ($type == 8) return $promotionsPrice;
foreach ($cartInfo as $key => $cart) {
if (isset($cart['sum_promotions_price']) && isset($cart['price_type']) && $cart['price_type'] == 'promotions') {
$promotionsPrice = bcadd((string)$promotionsPrice, (string)$cart['sum_promotions_price'], 2);
}
}
return $promotionsPrice;
},
'postage' => function () use ($uid, $shippingType, $payType, $cartInfo, $addr, $payPrice, $postage, $other, $type, $computeOrderService,$storeId,$is_store_delivery_type) {
return $computeOrderService->computedPayPostage($uid, $shippingType, $payType, $cartInfo, $addr, $payPrice, $postage, $other,$storeId,$is_store_delivery_type);
},
]);
[$p, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage, $poorFreeShipping, $poorDeliveryPrice, $sameCityStoreFreePostage] = $results['postage'];
} else {
/** @var StoreCartServices $cartServices */
$cartServices = app()->make(StoreCartServices::class);
//获取购物车信息
$cartGroup = $cartServices->getUserProductCartListV1($uid, $cartIds, $new, [], 4, $storeId, $coupon_id);
$cartInfo = $cartGroup['valid'];
if (!$cartInfo) {
throw new ValidateException('购物车暂无货物!');
}
$deduction = $cartGroup['deduction'];
$promotions = $cartGroup['promotions'] ?? [];
$other = [
'offlinePostage' => sys_config('offline_postage'),
'integralRatio' => sys_config('integral_ratio'),
'give_integral' => $cartGroup['giveIntegral'] ?? 0,
'give_coupon' => $cartGroup['giveCoupon'] ?? [],
'give_product' => $cartGroup['giveProduct'],
'promotions' => $cartGroup['promotions']
];
$reservationInfo = ['cart_num' => $cartInfo[0]['cart_num'] ?? 1, 'reservation_type' => 2, 'service_staff_id' => 0, 'real_name' => '', 'user_phone' => '', 'reservation_time' => '', 'reservation_time_id' => 0, 'reservation_show_time' => ''];
if (($deduction['product_type'] ?? 0) == 6) {
$reservationTime = $cartInfo[0]['reservation_time'] ?? '';
$reservationTimeId = $cartInfo[0]['reservation_time_id'] ?? 0;
$reservationTimeInfo = [];
if ($reservationTimeId) {
/** @var StoreProductReservationTimeServices $reservationTimeServices */
$reservationTimeServices = app()->make(StoreProductReservationTimeServices::class);
$reservationTimeInfo = $reservationTimeServices->get(['id' => $reservationTimeId]);
if (!$reservationTimeInfo) {
throw new ValidateException('选择的时段无效');
}
}
$reservationInfo = [
'cart_num' => $cartInfo[0]['cart_num'] ?? 1,
'reservation_type' => $cartInfo[0]['reservation_type'] ?? 2,
'service_staff_id' => $cartInfo[0]['service_staff_id'] ?? 0,
'real_name' => $cartInfo[0]['real_name'] ?? '',
'user_phone' => $cartInfo[0]['user_phone'] ?? '',
'reservation_time' => $reservationTime,
'reservation_time_id' => $reservationTimeId,
'reservation_show_time' => $reservationTimeInfo['show_time'] ?? '',
];
}
$other['reservationInfo'] = $reservationInfo;
$cartGroup['other'] = $other;
$sumPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'sum_price');//获取订单原总金额
$totalPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'pay_price', false);//获取订单svip、用户等级优惠之后总金额
$settlePrice = (float)$computeOrderService->getOrderSumPrice($cartInfo, 'settle_price', false);//结算总价
$costPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'costPrice');//获取订单成本价
$vipPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'vip_truePrice');//获取订单会员优惠金额
$promotionsPrice = $computeOrderService->getOrderSumPrice($cartInfo, 'sum_promotions_price', false);//优惠活动优惠
$changePrice = (float)$computeOrderService->getOrderSumPrice($cartInfo, 'change_price', false);//获取改价优惠金额
$payPrice = (float)$totalPrice;
$couponPrice = floatval($cartGroup['couponPrice'] ?? 0);
//合并赠品
$cartInfo = array_merge($cartGroup['valid'], $cartGroup['giveCartList']);
}
$promotionsDetail = [];
if ($promotions) {
foreach ($promotions as $key => $value) {
if (isset($value['details']['sum_promotions_price']) && $value['details']['sum_promotions_price']) {
$promotionsDetail[] = ['id' => $value['id'], 'name' => $value['name'], 'title' => $value['title'], 'desc' => $value['desc'], 'promotions_price' => $value['details']['sum_promotions_price'], 'promotions_type' => $value['promotions_type']];
}
}
if ($promotionsDetail) {
$typeArr = array_column($promotionsDetail, 'promotions_type');
array_multisort($typeArr, SORT_ASC, $promotionsDetail);
}
}
$is_cashier_yue_pay_verify = (int)sys_config('is_cashier_yue_pay_verify'); // 收银台余额支付是否需要验证【是/否】
if ($firstOrderPrice < $payPrice) {//首单优惠金额
$payPrice = bcsub((string)$payPrice, (string)$firstOrderPrice, 2);
} else {
$payPrice = 0;
}
$SurplusIntegral = $usedIntegral = 0;
$deductionPrice = '0';
//使用积分
if ($userInfo && $integral && sys_config('integral_ratio_status', 0)) {
[
$payPrice,
$deductionPrice,
$usedIntegral,
$SurplusIntegral
] = $computeOrderService->useIntegral(true, $userInfo, $payPrice, [
'offlinePostage' => sys_config('offline_postage'),
'integralRatio' => sys_config('integral_ratio')
]);
}
$payPrice = (float)bcadd((string)$payPrice, (string)$payPostage, 2);
$yue_pay_status = (int)sys_config('balance_func_status') && (int)sys_config('yue_pay_status') == 1 ? (int)1 : (int)2;//余额支付 1 开启 2 关闭
//验证门店是否开启使用余额支付
if ($yue_pay_status == 1 && $storeId) {
/** @var SystemStoreServices $systemStoreServices */
$systemStoreServices = app()->make(SystemStoreServices::class);
$storeInfo = $systemStoreServices->get((int)$storeId, ['id', 'use_system_money']);
$yue_pay_status = $storeInfo['use_system_money'] ? $yue_pay_status : 2;
}
return [
'payPrice' => floatval($payPrice),//支付金额
'settlePrice' => floatval($settlePrice),//结算金额
'vipPrice' => floatval($vipPrice),//会员优惠金额
'totalPrice' => floatval($totalPrice),//会员优惠后订单金额
'costPrice' => floatval($costPrice),//成本金额
'sumPrice' => floatval($sumPrice),//订单总金额
'firstOrderPrice' => floatval($firstOrderPrice),//首单优惠
'couponPrice' => (float)$couponPrice,//优惠券金额
'pay_postage' => (float)($payPostage ?? 0),
'storePostageDiscount' => (float)($storePostageDiscount ?? 0),
'promotionsPrice' => floatval($promotionsPrice),//优惠活动金额
'promotionsDetail' => $promotionsDetail,//优惠
'deductionPrice' => floatval($deductionPrice),//积分抵扣多少钱
'surplusIntegral' => $SurplusIntegral,//抵扣了多少积分
'usedIntegral' => $usedIntegral,//使用了多少积分
'deduction' => $deduction,
'changePrice' => $changePrice,
'isStoreFreePostage' => $isStoreFreePostage ?? false,
'storeFreePostage' => (float)($storeFreePostage ?? 0),
'sameCityStoreFreePostage' => (float)($sameCityStoreFreePostage ?? 0),
'poorFreeShipping' => (float)($poorFreeShipping ?? 0),//差多少包邮
'poorDeliveryPrice' => (float)($poorDeliveryPrice ?? 0),//差多少起送
'servicePrice' => 0.00,
'cartInfo' => $cartInfo,//购物列表
'is_cashier_yue_pay_verify' => $is_cashier_yue_pay_verify,//收银台余额支付验证 1 验证 0不验证
'cartGroup' => $cartGroup,//计算结果
'offline_pay_status' => (int)sys_config('offline_pay_status'),//线下支付1开启2关闭
'yue_pay_status' => (int)$yue_pay_status,//余额支付 1 开启 2 关闭
'ali_pay_status' => (int)sys_config('ali_pay_status'),//支付宝支付 1 开启 0 关闭
'pay_weixin_open' => (int)sys_config('pay_weixin_open') ?? 0,//微信支付 1 开启 0 关闭
];
}
