This commit is contained in:
luofei 2024-03-22 15:20:54 +08:00
commit 2338f133a1
64 changed files with 91 additions and 76 deletions

View File

@ -897,7 +897,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
return $data;
}
public function v2CreateOrder($key, int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post)
public function v2CreateOrder($key, int $pay_type, $user, array $cartId, array $extend, array $mark, array $receipt_data, array $takes = null, array $useCoupon = null, bool $useIntegral = false, int $addressId = null, array $post,$remarkMoney)
{
$uid = $user->uid;
// $orderInfo = $this->v2CartIdByOrderInfo($user, $cartId, $takes, $useCoupon, $useIntegral, $addressId, true);
@ -1134,6 +1134,14 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$totalCost = bcadd($totalCost, $cost, 2);
$totalNum += $merchantCart['order']['total_num'];
}
//当$remarkMoney不为0得时候就是输入金额匹配去处理得
$pay_price = $orderInfo['order_price'];
$coupon_price = bcadd($orderInfo['total_platform_coupon_price'], $orderInfo['order_coupon_price'], 2);
if($remarkMoney){
$pay_price = $remarkMoney;//输入得金额
$coupon_price = $orderInfo['order_price'] -$pay_price;
}
$groupOrder = [
'uid' => $uid,
'group_order_sn' => count($orderList) === 1 ? $orderList[0]['order_sn'] : ($this->getNewOrderId(StoreOrderRepository::TYPE_SN_ORDER) . '0'),
@ -1143,8 +1151,8 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'real_name' => $address['real_name'] ?? '',
'user_phone' => $address['phone'] ?? '',
'user_address' => $user_address,
'pay_price' => $orderInfo['order_price'],
'coupon_price' => bcadd($orderInfo['total_platform_coupon_price'], $orderInfo['order_coupon_price'], 2),
'pay_price' => $pay_price,
'coupon_price' => $coupon_price,
'pay_postage' => $totalPostage,
'cost' => $totalCost,
'coupon_id' => $orderInfo['usePlatformCouponId'] > 0 ? $orderInfo['usePlatformCouponId'] : '',
@ -1157,7 +1165,7 @@ class StoreOrderCreateRepository extends StoreOrderRepository
'sale_type' => $saleType,
];
event('order.create.before', compact('groupOrder', 'orderList'));
$group = Db::transaction(function () use ($ex, $user, $topUid, $spreadUid, $uid, $receipt_data, $cartIds, $allUseCoupon, $groupOrder, $orderList, $orderInfo, $useCoupon) {
$group = Db::transaction(function () use ($ex, $user, $topUid, $spreadUid, $uid, $receipt_data, $cartIds, $allUseCoupon, $groupOrder, $orderList, $orderInfo, $useCoupon,$pay_type) {
$storeGroupOrderRepository = app()->make(StoreGroupOrderRepository::class);
$storeCartRepository = app()->make(StoreCartRepository::class);
$attrValueRepository = app()->make(ProductAttrValueRepository::class);
@ -1169,46 +1177,49 @@ class StoreOrderCreateRepository extends StoreOrderRepository
$userMerchantRepository = app()->make(UserMerchantRepository::class);
$storeCouponUserDao = new StoreCouponUserDao();
//减库存
foreach ($orderList as $order) {
foreach ($order['cartInfo']['list'] as $cart) {
if (!isset($uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']]))
$uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']] = true;
else
throw new ValidateException('购物车商品信息重复');
//线下扫码支付不扣库存
if ($this->isScanOrder) {
continue;
}
//减库存 ---不为对公转账
try {
if ($cart['product_type'] == '1') {
$attrValueRepository->descSkuStock($cart['product']['old_product_id'], $cart['productAttr']['sku'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
// $productRepository->incSales($cart['product']['old_product_id'], $cart['cart_num']);
$productRepository->incSales($cart['product']['product_id'], $cart['cart_num']);
} else if ($cart['product_type'] == '2') {
$productPresellSkuRepository = app()->make(ProductPresellSkuRepository::class);
$productPresellSkuRepository->descStock($cart['productPresellAttr']['product_presell_id'], $cart['productPresellAttr']['unique'], $cart['cart_num']);
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
} else if ($cart['product_type'] == '3') {
app()->make(ProductAssistSkuRepository::class)->descStock($cart['productAssistAttr']['product_assist_id'], $cart['productAssistAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
$attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
} else if ($cart['product_type'] == '4') {
app()->make(ProductGroupSkuRepository::class)->descStock($cart['activeSku']['product_group_id'], $cart['activeSku']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
$attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
} else {
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
if ($cart['integral'] && $cart['integral']['use'] > 0) {
$productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']);
}
if ($pay_type != Enum::public) {
foreach ($orderList as $order) {
foreach ($order['cartInfo']['list'] as $cart) {
if (!isset($uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']]))
$uniqueList[$cart['productAttr']['product_id'] . $cart['productAttr']['unique']] = true;
else
throw new ValidateException('购物车商品信息重复');
//线下扫码支付不扣库存
if ($this->isScanOrder) {
continue;
}
try {
if ($cart['product_type'] == '1') {
$attrValueRepository->descSkuStock($cart['product']['old_product_id'], $cart['productAttr']['sku'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
// $productRepository->incSales($cart['product']['old_product_id'], $cart['cart_num']);
$productRepository->incSales($cart['product']['product_id'], $cart['cart_num']);
} else if ($cart['product_type'] == '2') {
$productPresellSkuRepository = app()->make(ProductPresellSkuRepository::class);
$productPresellSkuRepository->descStock($cart['productPresellAttr']['product_presell_id'], $cart['productPresellAttr']['unique'], $cart['cart_num']);
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
} else if ($cart['product_type'] == '3') {
app()->make(ProductAssistSkuRepository::class)->descStock($cart['productAssistAttr']['product_assist_id'], $cart['productAssistAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
$attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
} else if ($cart['product_type'] == '4') {
app()->make(ProductGroupSkuRepository::class)->descStock($cart['activeSku']['product_group_id'], $cart['activeSku']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['old_product_id'], $cart['cart_num']);
$attrValueRepository->descStock($cart['product']['old_product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
} else {
$attrValueRepository->descStock($cart['productAttr']['product_id'], $cart['productAttr']['unique'], $cart['cart_num']);
$productRepository->descStock($cart['product']['product_id'], $cart['cart_num']);
if ($cart['integral'] && $cart['integral']['use'] > 0) {
$productRepository->incIntegral($cart['product']['product_id'], $cart['integral']['use'], $cart['integral']['price']);
}
}
} catch (\Exception $e) {
throw new ValidateException('库存不足');
}
} catch (\Exception $e) {
throw new ValidateException('库存不足');
}
}
}

View File

@ -83,7 +83,7 @@ class StoreOrder extends BaseController
$payType = $this->request->param('pay_type');
$key = (string)$this->request->param('key');
$post = (array)$this->request->param('post');
$remarkMoney = $this->request->param('money')??0;//匹配金额
if(!$key){
return app('json')->fail('订单操作超时,请刷新页面');
}
@ -108,9 +108,9 @@ class StoreOrder extends BaseController
// if (!$addressId)
// return app('json')->fail('请选择地址');
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($key, $orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post) {
$groupOrder = app()->make(LockService::class)->exec('order.create', function () use ($key, $orderCreateRepository, $receipt_data, $mark, $extend, $cartId, $payType, $takes, $couponIds, $useIntegral, $addressId, $post,$remarkMoney) {
$orderCreateRepository->isScanOrder = (int)$this->request->param('source') == 999;
return $orderCreateRepository->v2CreateOrder($key, array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post);
return $orderCreateRepository->v2CreateOrder($key, array_search($payType, StoreOrderRepository::PAY_TYPE), $this->request->userInfo(), $cartId, $extend, $mark, $receipt_data, $takes, $couponIds, $useIntegral, $addressId, $post,$remarkMoney);
});
if ($isPc) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long