|
@@ -220,6 +220,8 @@ public class CmPayShopController extends BaseController {
|
|
|
double totalCostFee = 0D;
|
|
|
double totalTaxesFee = 0D;
|
|
|
NewShopOrder shopOrder = newShopOrderService.get(shopOrderID);
|
|
|
+ // 初始运费
|
|
|
+ Double postFee = null == shopOrder.getShopPostFee() ? 0d : shopOrder.getShopPostFee();
|
|
|
String dbcostType = shopOrder.getCostType();
|
|
|
String cmChangePayShopRecondId = "0";
|
|
|
if (StringUtils.isEmpty(dbcostType)) {
|
|
@@ -325,70 +327,74 @@ public class CmPayShopController extends BaseController {
|
|
|
//子订单的成本方式第一次填写以后就不能修改了
|
|
|
// 固定成本
|
|
|
//if ("1".equals(costType)) {
|
|
|
- // List<CmReturnedPurchaseProduct> rL = cmReturnedPurchaseProductService.findReturnedByShopOrderID(Integer.parseInt(shopOrderID));
|
|
|
- for (NewOrderProduct product : newOrderProducts) {
|
|
|
- Integer orderProductID = product.getOrderProductID();
|
|
|
- Double costPrice = product.getCostPrice() == null ? 0d : product.getCostPrice();
|
|
|
- Double organizeCostPrice = product.getOrganizeCostPrice() == null ? 0d : product.getOrganizeCostPrice();
|
|
|
- Double cmCostPrice = product.getCmCostPrice() == null ? 0d : product.getCmCostPrice();
|
|
|
- if (soZeroCostFlag && costPrice > 0) {
|
|
|
- soZeroCostFlag = false;
|
|
|
- }
|
|
|
- // 在订单商品含税的情况下, 成本计算税费
|
|
|
- if ("0".equals(product.getIncludedTax()) && null != product.getSupplierTaxRate() && product.getSupplierTaxRate() > 0d) {
|
|
|
- costPrice = MathUtil.add(costPrice, MathUtil.div(MathUtil.mul(costPrice, product.getSupplierTaxRate()), 100)).doubleValue();
|
|
|
- }
|
|
|
- // product.setSingleShouldPayTotalTax(MathUtil.div(MathUtil.mul(MathUtil.div(product.getCostPrice(), MathUtil.div(MathUtil.add(product.getTaxRate(), 100),100)), product.getSupplierTaxRate()), 100).doubleValue());
|
|
|
- Double singleShouldPayTotalTax = product.getSingleShouldPayTotalTax() == null ? 0d : product.getSingleShouldPayTotalTax();
|
|
|
- Double supplierTaxRate = product.getSupplierTaxRate() == null ? 0d : product.getSupplierTaxRate();
|
|
|
- // 获取已被退款的商品数量
|
|
|
- Integer returnNum = newOrderProductDao.CountReturnedPurchaseProduct(Integer.parseInt(shopOrderID), orderProductID);
|
|
|
- returnNum = returnNum == null ? 0 : returnNum;
|
|
|
- NewOrderProduct orderProduct = newOrderProductService.get(String.valueOf(orderProductID));
|
|
|
- // 修改前
|
|
|
- if (StringUtils.isEmpty(dbcostType)) {
|
|
|
+ // List<CmReturnedPurchaseProduct> rL = cmReturnedPurchaseProductService.findReturnedByShopOrderID(Integer.parseInt(shopOrderID));
|
|
|
+ for (NewOrderProduct product : newOrderProducts) {
|
|
|
+ Integer orderProductID = product.getOrderProductID();
|
|
|
+ Double costPrice = product.getCostPrice() == null ? 0d : product.getCostPrice();
|
|
|
+ Double organizeCostPrice = product.getOrganizeCostPrice() == null ? 0d : product.getOrganizeCostPrice();
|
|
|
+ Double cmCostPrice = product.getCmCostPrice() == null ? 0d : product.getCmCostPrice();
|
|
|
+ if (soZeroCostFlag && costPrice > 0) {
|
|
|
+ soZeroCostFlag = false;
|
|
|
+ }
|
|
|
+ // 在订单商品含税的情况下, 成本计算税费
|
|
|
+ if ("0".equals(product.getIncludedTax()) && null != product.getSupplierTaxRate() && product.getSupplierTaxRate() > 0d) {
|
|
|
+ costPrice = MathUtil.add(costPrice, MathUtil.div(MathUtil.mul(costPrice, product.getSupplierTaxRate()), 100)).doubleValue();
|
|
|
+ }
|
|
|
+ // product.setSingleShouldPayTotalTax(MathUtil.div(MathUtil.mul(MathUtil.div(product.getCostPrice(), MathUtil.div(MathUtil.add(product.getTaxRate(), 100),100)), product.getSupplierTaxRate()), 100).doubleValue());
|
|
|
+ Double singleShouldPayTotalTax = product.getSingleShouldPayTotalTax() == null ? 0d : product.getSingleShouldPayTotalTax();
|
|
|
+ Double supplierTaxRate = product.getSupplierTaxRate() == null ? 0d : product.getSupplierTaxRate();
|
|
|
+ // 获取已被退款的商品数量
|
|
|
+ Integer returnNum = newOrderProductDao.CountReturnedPurchaseProduct(Integer.parseInt(shopOrderID), orderProductID);
|
|
|
+ returnNum = returnNum == null ? 0 : returnNum;
|
|
|
+ NewOrderProduct orderProduct = newOrderProductService.get(String.valueOf(orderProductID));
|
|
|
+ // 修改前
|
|
|
+ if (StringUtils.isEmpty(dbcostType)) {
|
|
|
+ CmChangePayShopProduct cmChangePayShopProduct = new CmChangePayShopProduct();
|
|
|
+ cmChangePayShopProduct.setRecondType("1");
|
|
|
+ cmChangePayShopProduct.setChangeType("1");
|
|
|
+ cmChangePayShopProduct.setChangePayShopId(Integer.parseInt(cmChangePayShopRecondId));
|
|
|
+ cmChangePayShopProduct.setOrderProductId(orderProductID);
|
|
|
+ cmChangePayShopProduct.setOrderProductName(product.getName());
|
|
|
+ // 同步使用机构税率 作为供应商税率
|
|
|
+ cmChangePayShopProduct.setSupplierTaxRate(product.getTaxRate());
|
|
|
+ cmChangePayShopProduct.setCostPrice(orderProduct.getNewCostPrice());
|
|
|
+ cmChangePayShopProduct.setOrganizeCostPrice(orderProduct.getOrganizeCostPrice());
|
|
|
+ cmChangePayShopProduct.setCmCostPrice(orderProduct.getCmCostPrice());
|
|
|
+ cmChangePayShopProduct.setSingleShouldPayTotalTax(orderProduct.getSingleShouldPayTotalTax());
|
|
|
+ cmChangePayShopProductService.save(cmChangePayShopProduct);
|
|
|
+ }
|
|
|
+
|
|
|
+ orderProduct.setCostPrice(costPrice);
|
|
|
+ orderProduct.setOrganizeCostPrice(organizeCostPrice);
|
|
|
+ orderProduct.setCmCostPrice(cmCostPrice);
|
|
|
+ // 同步使用机构税率 作为供应商税率
|
|
|
+ orderProduct.setSupplierTaxRate(supplierTaxRate);
|
|
|
+ orderProduct.setTaxRate(product.getTaxRate());
|
|
|
+ orderProduct.setSingleShouldPayTotalTax(singleShouldPayTotalTax);
|
|
|
+ orderProducts.add(orderProduct);
|
|
|
+ int num = orderProduct.getNum() == null ? 0 : orderProduct.getNum();
|
|
|
+ int presentNum = orderProduct.getPresentNum() == null ? 0 : orderProduct.getPresentNum();
|
|
|
+ totalCostFee += (num + presentNum - returnNum) * costPrice;
|
|
|
+ orderProduct.setShouldPayTotalTax(singleShouldPayTotalTax * (num + presentNum - returnNum));
|
|
|
+ totalTaxesFee += singleShouldPayTotalTax * (num + presentNum - returnNum);
|
|
|
+ // 修改后
|
|
|
CmChangePayShopProduct cmChangePayShopProduct = new CmChangePayShopProduct();
|
|
|
- cmChangePayShopProduct.setRecondType("1");
|
|
|
- cmChangePayShopProduct.setChangeType("1");
|
|
|
- cmChangePayShopProduct.setChangePayShopId(Integer.parseInt(cmChangePayShopRecondId));
|
|
|
+ cmChangePayShopProduct.setRecondType("2");
|
|
|
+ cmChangePayShopProduct.setChangeType(costType);
|
|
|
+ cmChangePayShopProduct.setChangePayShopId(Integer.parseInt(cmChangePayShopRecondId2));
|
|
|
cmChangePayShopProduct.setOrderProductId(orderProductID);
|
|
|
cmChangePayShopProduct.setOrderProductName(product.getName());
|
|
|
- // 同步使用机构税率 作为供应商税率
|
|
|
- cmChangePayShopProduct.setSupplierTaxRate(product.getTaxRate());
|
|
|
- cmChangePayShopProduct.setCostPrice(orderProduct.getNewCostPrice());
|
|
|
- cmChangePayShopProduct.setSingleShouldPayTotalTax(orderProduct.getSingleShouldPayTotalTax());
|
|
|
+ cmChangePayShopProduct.setSupplierTaxRate(supplierTaxRate);
|
|
|
+ cmChangePayShopProduct.setCostPrice(product.getCostPrice());
|
|
|
+ cmChangePayShopProduct.setOrganizeCostPrice(product.getOrganizeCostPrice());
|
|
|
+ cmChangePayShopProduct.setCmCostPrice(product.getCmCostPrice());
|
|
|
+ cmChangePayShopProduct.setSingleShouldPayTotalTax(product.getSingleShouldPayTotalTax());
|
|
|
cmChangePayShopProductService.save(cmChangePayShopProduct);
|
|
|
}
|
|
|
-
|
|
|
- orderProduct.setCostPrice(costPrice);
|
|
|
- orderProduct.setOrganizeCostPrice(organizeCostPrice);
|
|
|
- orderProduct.setCmCostPrice(cmCostPrice);
|
|
|
- // 同步使用机构税率 作为供应商税率
|
|
|
- orderProduct.setSupplierTaxRate(supplierTaxRate);
|
|
|
- orderProduct.setTaxRate(product.getTaxRate());
|
|
|
- orderProduct.setSingleShouldPayTotalTax(singleShouldPayTotalTax);
|
|
|
- orderProducts.add(orderProduct);
|
|
|
- int num = orderProduct.getNum() == null ? 0 : orderProduct.getNum();
|
|
|
- int presentNum = orderProduct.getPresentNum() == null ? 0 : orderProduct.getPresentNum();
|
|
|
- totalCostFee += (num + presentNum - returnNum) * costPrice;
|
|
|
- orderProduct.setShouldPayTotalTax(singleShouldPayTotalTax * (num + presentNum - returnNum));
|
|
|
- totalTaxesFee += singleShouldPayTotalTax * (num + presentNum - returnNum);
|
|
|
- // 修改后
|
|
|
- CmChangePayShopProduct cmChangePayShopProduct = new CmChangePayShopProduct();
|
|
|
- cmChangePayShopProduct.setRecondType("2");
|
|
|
- cmChangePayShopProduct.setChangeType(costType);
|
|
|
- cmChangePayShopProduct.setChangePayShopId(Integer.parseInt(cmChangePayShopRecondId2));
|
|
|
- cmChangePayShopProduct.setOrderProductId(orderProductID);
|
|
|
- cmChangePayShopProduct.setOrderProductName(product.getName());
|
|
|
- cmChangePayShopProduct.setSupplierTaxRate(supplierTaxRate);
|
|
|
- cmChangePayShopProduct.setCostPrice(product.getCostPrice());
|
|
|
- cmChangePayShopProduct.setSingleShouldPayTotalTax(product.getSingleShouldPayTotalTax());
|
|
|
- cmChangePayShopProductService.save(cmChangePayShopProduct);
|
|
|
- }
|
|
|
- //总税费
|
|
|
- shopOrder.setShopTaxFee(totalTaxesFee);
|
|
|
- //商品费
|
|
|
- shopOrder.setShopProductAmount(totalCostFee);
|
|
|
+ //总税费
|
|
|
+ shopOrder.setShopTaxFee(totalTaxesFee);
|
|
|
+ //商品费
|
|
|
+ shopOrder.setShopProductAmount(totalCostFee);
|
|
|
//}
|
|
|
// 比例成本
|
|
|
/*if ("2".equals(costType)) {
|
|
@@ -482,40 +488,40 @@ public class CmPayShopController extends BaseController {
|
|
|
}*/
|
|
|
shopOrder.setPayStatus(soZeroCostFlag ? "3" : "1");
|
|
|
shopOrder.setZeroCostFlag(soZeroCostFlag ? 1 : 0);
|
|
|
-// //当子订单0成本时,若主订单中其他子订单(除了运费子订单)都为0成本,设主订单为已付款,否则设为部分付款
|
|
|
-// NewOrder newOrder = newOrderService.get(shopOrder.getOrderID().toString());
|
|
|
-// if (soZeroCostFlag) {
|
|
|
-// AtomicReference<Boolean> zeroCostFlag = new AtomicReference<>(true);
|
|
|
-// AtomicReference<Boolean> freightFlag = new AtomicReference<>(false);
|
|
|
-// newOrder.getNewShopOrders().forEach(item -> {
|
|
|
-// if (item.getShopID().equals(998)) {
|
|
|
-// freightFlag.set(true);
|
|
|
-// } else if (!item.getShopOrderID().equals(shopOrder.getShopOrderID()) && 0 == item.getZeroCostFlag()) {
|
|
|
-// zeroCostFlag.set(false);
|
|
|
-// }
|
|
|
-// });
|
|
|
-// //如果含有运费子订单且其他子订单都为0成本,将运费子订单置为已付款
|
|
|
-// if (freightFlag.get() && zeroCostFlag.get()) {
|
|
|
-// newOrder.getNewShopOrders().forEach(item -> {
|
|
|
-// if (item.getShopID().equals(998)) {
|
|
|
-// item.setPayStatus("3");
|
|
|
-// //更新运费子订单
|
|
|
-// newShopOrderService.updatePayStatus(item);
|
|
|
-// cmPayShopService.payFreightShopOrder(item);
|
|
|
-//
|
|
|
-// }
|
|
|
-// });
|
|
|
-// }
|
|
|
-// if (zeroCostFlag.get()) {
|
|
|
-// newOrder.setPayStatus("3");
|
|
|
-// newOrder.setZeroCostFlag(1);
|
|
|
-// } else {
|
|
|
-// newOrder.setPayStatus("2");
|
|
|
-// newOrder.setZeroCostFlag(0);
|
|
|
-// }
|
|
|
-// newOrderService.updatePayStatus(newOrder);
|
|
|
-// }
|
|
|
- shopOrder.setSupplierFreight(freight); //运费
|
|
|
+ //当子订单0成本时,若主订单中其他子订单(除了运费子订单)都为0成本,设主订单为已付款,否则设为部分付款
|
|
|
+ NewOrder newOrder = newOrderService.get(shopOrder.getOrderID().toString());
|
|
|
+ if (soZeroCostFlag) {
|
|
|
+ AtomicReference<Boolean> zeroCostFlag = new AtomicReference<>(true);
|
|
|
+ AtomicReference<Boolean> freightFlag = new AtomicReference<>(false);
|
|
|
+ newOrder.getNewShopOrders().forEach(item -> {
|
|
|
+ if (item.getShopID().equals(998)) {
|
|
|
+ freightFlag.set(true);
|
|
|
+ } else if (!item.getShopOrderID().equals(shopOrder.getShopOrderID()) && 0 == item.getZeroCostFlag()) {
|
|
|
+ zeroCostFlag.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //如果含有运费子订单且其他子订单都为0成本,将运费子订单置为已付款
|
|
|
+ if (freightFlag.get() && zeroCostFlag.get()) {
|
|
|
+ newOrder.getNewShopOrders().forEach(item -> {
|
|
|
+ if (item.getShopID().equals(998)) {
|
|
|
+ item.setPayStatus("3");
|
|
|
+ //更新运费子订单
|
|
|
+ newShopOrderService.updatePayStatus(item);
|
|
|
+ cmPayShopService.payFreightShopOrder(item);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (zeroCostFlag.get()) {
|
|
|
+ newOrder.setPayStatus("3");
|
|
|
+ newOrder.setZeroCostFlag(1);
|
|
|
+ } else {
|
|
|
+ newOrder.setPayStatus("2");
|
|
|
+ newOrder.setZeroCostFlag(0);
|
|
|
+ }
|
|
|
+ newOrderService.updatePayStatus(newOrder);
|
|
|
+ }
|
|
|
+ shopOrder.setShopPostFee(freight); //运费
|
|
|
shopOrder.setShopOtherFee(thirdPartyFee); //付第三方
|
|
|
shopOrder.setCostType(costType);
|
|
|
shopOrder.setModifyShouldPayNote(modifyShouldPayNote); //备注
|
|
@@ -526,7 +532,7 @@ public class CmPayShopController extends BaseController {
|
|
|
shopOrder.setPayStatus("3");
|
|
|
}
|
|
|
// 付供应商 - 优惠券 - 促销满减优惠
|
|
|
- shopOrder.setShouldPayShopAmount(MathUtil.sub(shouldPayShopAmount, MathUtil.add(shopOrder.getCouponAmount(), shopOrder.getPromotionFullReduction())).doubleValue());
|
|
|
+ shopOrder.setShouldPayShopAmount(MathUtil.sub(shouldPayShopAmount , MathUtil.add(shopOrder.getCouponAmount(), shopOrder.getPromotionFullReduction())).doubleValue());
|
|
|
newShopOrderService.modifyPayShopAmount(shopOrder, orderProducts);
|
|
|
return "redirect:" + Global.getAdminPath() + "/shopOrder/payOrderList";
|
|
|
}
|