更新
This commit is contained in:
parent
9b30aafceb
commit
e4233b502d
@ -131,10 +131,10 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$noDeliver = false;
|
||||
$presellType = 0;
|
||||
$fn = [];
|
||||
if(in_array($source,[0,2,103])){
|
||||
$enabledPlatformCoupon=true;
|
||||
}else{
|
||||
$enabledPlatformCoupon=false;
|
||||
if (in_array($source, [0, 2, 103])) {
|
||||
$enabledPlatformCoupon = true;
|
||||
} else {
|
||||
$enabledPlatformCoupon = false;
|
||||
}
|
||||
$order_total_postage = 0;
|
||||
$platformCoupon = [];
|
||||
@ -483,6 +483,161 @@ class StoreOrderCreateRepository extends StoreOrderRepository
|
||||
$usePlatformCouponId = 0;
|
||||
$total_platform_coupon_price = 0;
|
||||
|
||||
//计算平台券优惠金额
|
||||
// if ($total_true_price > 0) {
|
||||
$StoreCouponUser = app()->make(StoreCouponUserRepository::class);
|
||||
$platformCoupon = $StoreCouponUser->validUserPlatformCoupon($uid);
|
||||
if ($enabledPlatformCoupon && count($platformCoupon)) {
|
||||
|
||||
$catePriceLst = [];
|
||||
$storePriceLst = [];
|
||||
$_cartNum = 0;
|
||||
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
if ($merchantCart['order']['true_price'] <= 0) continue;
|
||||
foreach ($merchantCart['list'] as &$cart) {
|
||||
$_cartNum++;
|
||||
if ($cart['product']['cate_id']) {
|
||||
if (!isset($catePriceLst[$cart['product']['cate_id']])) {
|
||||
$catePriceLst[$cart['product']['cate_id']] = ['price' => 0, 'cart' => []];
|
||||
}
|
||||
$catePriceLst[$cart['product']['cate_id']]['price'] = bcadd($catePriceLst[$cart['product']['cate_id']]['price'], $cart['true_price']);
|
||||
$catePriceLst[$cart['product']['cate_id']]['cart'][] = &$cart;
|
||||
}
|
||||
}
|
||||
unset($cart);
|
||||
$storePriceLst[$merchantCart['mer_id']] = [
|
||||
'price' => $merchantCart['order']['true_price'],
|
||||
'num' => count($merchantCart['list'])
|
||||
];
|
||||
}
|
||||
unset($merchantCart);
|
||||
$flag = false;
|
||||
$platformCouponRate = null;
|
||||
|
||||
foreach ($platformCoupon as &$coupon) {
|
||||
$coupon['checked'] = false;
|
||||
//通用券
|
||||
if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_ALL) {
|
||||
$coupon['disabled'] = $total_true_price <= 0 || $coupon['use_min_price'] > $total_true_price;
|
||||
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
|
||||
$platformCouponRate = [
|
||||
'id' => $coupon['coupon_user_id'],
|
||||
'type' => $coupon['coupon']['type'],
|
||||
'price' => $total_true_price,
|
||||
'coupon_price' => $coupon['coupon_price'],
|
||||
'use_count' => $_cartNum,
|
||||
'check' => function ($cart) {
|
||||
return true;
|
||||
}
|
||||
];
|
||||
$coupon['checked'] = true;
|
||||
$flag = true;
|
||||
}
|
||||
//品类券
|
||||
} else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_CATE) {
|
||||
$_price = 0;
|
||||
$_use_count = 0;
|
||||
$cateIds = $coupon['product']->column('product_id');
|
||||
$allCateIds = array_unique(array_merge(app()->make(StoreCategoryRepository::class)->allChildren($cateIds), $cateIds));
|
||||
$flag2 = true;
|
||||
foreach ($allCateIds as $cateId) {
|
||||
if (isset($catePriceLst[$cateId])) {
|
||||
$_price = bcadd($catePriceLst[$cateId]['price'], $_price, 2);
|
||||
$_use_count += count($catePriceLst[$cateId]['cart']);
|
||||
$flag2 = false;
|
||||
}
|
||||
}
|
||||
$coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price;
|
||||
//品类券可用
|
||||
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
|
||||
$platformCouponRate = [
|
||||
'id' => $coupon['coupon_user_id'],
|
||||
'type' => $coupon['coupon']['type'],
|
||||
'price' => $_price,
|
||||
'use_cate' => $allCateIds,
|
||||
'coupon_price' => $coupon['coupon_price'],
|
||||
'use_count' => $_use_count,
|
||||
'check' => function ($cart) use ($allCateIds) {
|
||||
return in_array($cart['product']['cate_id'], $allCateIds);
|
||||
}
|
||||
];
|
||||
$coupon['checked'] = true;
|
||||
$flag = true;
|
||||
}
|
||||
//跨店券
|
||||
} else if ($coupon['coupon']['type'] === StoreCouponRepository::TYPE_PLATFORM_STORE) {
|
||||
$_price = 0;
|
||||
$_use_count = 0;
|
||||
$flag2 = true;
|
||||
foreach ($coupon['product'] as $item) {
|
||||
$merId = $item['product_id'];
|
||||
if (isset($storePriceLst[$merId])) {
|
||||
$_price = bcadd($storePriceLst[$merId]['price'], $_price, 2);
|
||||
$_use_count += $storePriceLst[$merId]['num'];
|
||||
$flag2 = false;
|
||||
}
|
||||
}
|
||||
$coupon['disabled'] = $flag2 || $coupon['use_min_price'] > $_price;
|
||||
//店铺券可用
|
||||
if (!$platformCouponRate && !$coupon['disabled'] && !$flag && !$flag2 && ((!$usePlatformCouponId && !$usePlatformCouponFlag) || $usePlatformCouponId == $coupon['coupon_user_id'])) {
|
||||
$_merIds = $coupon['product']->column('product_id');
|
||||
$platformCouponRate = [
|
||||
'id' => $coupon['coupon_user_id'],
|
||||
'type' => $coupon['coupon']['type'],
|
||||
'price' => $_price,
|
||||
'use_store' => $_merIds,
|
||||
'coupon_price' => $coupon['coupon_price'],
|
||||
'use_count' => $_use_count,
|
||||
'check' => function ($cart) use ($_merIds) {
|
||||
return in_array($cart['mer_id'], $_merIds);
|
||||
}
|
||||
];
|
||||
$coupon['checked'] = true;
|
||||
$flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($coupon);
|
||||
}
|
||||
// }
|
||||
|
||||
$usePlatformCouponId = 0;
|
||||
$total_platform_coupon_price = 0;
|
||||
//计算平台优惠券
|
||||
if (isset($platformCouponRate)) {
|
||||
$_coupon_price = $platformCouponRate['coupon_price'];
|
||||
foreach ($merchantCartList as &$merchantCart) {
|
||||
$_ids = array_column($merchantCart['list'], 'cart_id');
|
||||
usort($merchantCart['list'], function ($a, $b) {
|
||||
return $a['true_price'] > $b['true_price'] ? 1 : -1;
|
||||
});
|
||||
$_price = 0;
|
||||
foreach ($merchantCart['list'] as &$cart) {
|
||||
if ($cart['true_price'] <= 0 || !$platformCouponRate['check']($cart)) continue;
|
||||
|
||||
if ($platformCouponRate['use_count'] === 1) {
|
||||
$couponPrice = min($platformCouponRate['coupon_price'], $cart['true_price']);
|
||||
} else {
|
||||
$couponPrice = min(max(0.01, bcmul($_coupon_price, bcdiv($cart['true_price'], $platformCouponRate['price'], 6), 2)), $cart['true_price']);
|
||||
}
|
||||
$platformCouponRate['coupon_price'] = bcsub($platformCouponRate['coupon_price'], $couponPrice, 2);
|
||||
$cart['true_price'] = bcsub($cart['true_price'], $couponPrice, 2);
|
||||
$cart['platform_coupon_price'] = $couponPrice;
|
||||
$platformCouponRate['use_count']--;
|
||||
$_price = bcadd($couponPrice, $_price, 2);
|
||||
}
|
||||
unset($cart);
|
||||
$merchantCart['order']['platform_coupon_price'] = $_price;
|
||||
$merchantCart['order']['true_price'] = bcsub($merchantCart['order']['true_price'], $_price, 2);
|
||||
$total_platform_coupon_price = bcadd($total_platform_coupon_price, $_price, 2);
|
||||
usort($merchantCart['list'], function ($a, $b) use ($_ids) {
|
||||
return array_search($a['cart_id'], $_ids) > array_search($b['cart_id'], $_ids) ? 1 : -1;
|
||||
});
|
||||
}
|
||||
$usePlatformCouponId = $platformCouponRate['id'];
|
||||
unset($merchantCart);
|
||||
}
|
||||
//积分配置
|
||||
$sysIntegralConfig = systemConfig(['integral_money', 'integral_status', 'integral_order_rate']);
|
||||
$merIntegralFlag = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user