|
|
@@ -12,7 +12,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.client.entity.Message;
|
|
|
import org.springblade.client.feign.IMessageClient;
|
|
|
+import org.springblade.common.enums.CommonEnum;
|
|
|
import org.springblade.common.enums.NumberEnum;
|
|
|
+import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
@@ -29,6 +31,7 @@ import org.springblade.salesPart.order.service.IOrderService;
|
|
|
import org.springblade.salesPart.order.service.IPjIntegralDetailService;
|
|
|
import org.springblade.salesPart.payMethod.PayService;
|
|
|
import org.springblade.salesPart.productLaunch.mapper.ProductLaunchMapper;
|
|
|
+import org.springblade.salesPart.recycling.mapper.GreenRecyclingRecordMapper;
|
|
|
import org.springblade.salesPart.serial.service.IPjpfSerialService;
|
|
|
import org.springblade.salesPart.share.entity.SharePutOnShelves;
|
|
|
import org.springblade.salesPart.share.mapper.SharePutOnShelvesMapper;
|
|
|
@@ -36,6 +39,8 @@ import org.springblade.salesPart.shopping.entity.ShoppingMallDetail;
|
|
|
import org.springblade.salesPart.shopping.mapper.ShoppingMallDetailMapper;
|
|
|
import org.springblade.salesPart.shoppingCart.mapper.ShoppingCartMapper;
|
|
|
import org.springblade.salesPart.shoppingCart.service.IShoppingCartService;
|
|
|
+import org.springblade.salesPart.util.UserUtils;
|
|
|
+import org.springblade.salesPart.util.WxParamUtil;
|
|
|
import org.springblade.salesPart.vo.ShoppingCartVO;
|
|
|
import org.springblade.system.feign.ISysClient;
|
|
|
import org.springblade.system.user.entity.User;
|
|
|
@@ -64,9 +69,9 @@ import java.util.stream.Collectors;
|
|
|
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjShoppingCart> implements IShoppingCartService {
|
|
|
|
|
|
private final IPjpfSerialService serialService;
|
|
|
- private final GoodsDescMapper goodsDescMapper;//商品
|
|
|
- private final ICorpsAttnService corpsAttnService;//客户联系人
|
|
|
- private final ICorpsDescService corpsDescService;//客户
|
|
|
+ private final GoodsDescMapper goodsDescMapper;
|
|
|
+ private final ICorpsAttnService corpsAttnService;
|
|
|
+ private final ICorpsDescService corpsDescService;
|
|
|
private final IOrderService orderService;
|
|
|
private final OrderItemsMapper orderItemsMapper;
|
|
|
private final ProductLaunchMapper productLaunchMapper;
|
|
|
@@ -84,6 +89,8 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
|
|
|
private final ShoppingMallDetailMapper shoppingMallDetailMapper;
|
|
|
|
|
|
+ private final GreenRecyclingRecordMapper greenRecyclingRecordMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 保存修改购物车信息
|
|
|
@@ -128,7 +135,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public R generateOrder(String address, List<Map<String, Object>> list, String payType) {
|
|
|
+ public R generateOrder(String address, List<Map<String, Object>> list, String payType, Boolean useRecoveredBalance) {
|
|
|
StringBuilder ids = new StringBuilder();
|
|
|
StringBuilder goodsName = new StringBuilder();
|
|
|
StringBuilder shortcutJoin = new StringBuilder();
|
|
|
@@ -137,97 +144,47 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
//从集合中取出商品生成销售单
|
|
|
if (ObjectUtil.isNotEmpty(list)) {
|
|
|
|
|
|
- PjCorpsDesc corpsDesc = null;
|
|
|
+ PjCorpsAttn corpsAttn = UserUtils.getUserCorpsAttn();
|
|
|
+ PjCorpsDesc finalCorpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
//根据当前登录人获得客户
|
|
|
- PjCorpsAttn corpsAttn = corpsAttnService.getAttn(AuthUtil.getUserId());
|
|
|
- if (ObjectUtil.isNotEmpty(corpsAttn)) {
|
|
|
- corpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
- if (ObjectUtil.isEmpty(corpsDesc)) {
|
|
|
- throw new RuntimeException("未查到用户信息");
|
|
|
- }
|
|
|
- } else {
|
|
|
+ if (ObjectUtil.isEmpty(finalCorpsDesc)) {
|
|
|
throw new RuntimeException("未查到用户信息");
|
|
|
}
|
|
|
|
|
|
- PjCorpsDesc finalCorpsDesc = corpsDesc;
|
|
|
-
|
|
|
+ BladeUser bladeUser = AuthUtil.getUser();
|
|
|
// 获取系统编号
|
|
|
String billNo = serialService.getBillNo("WB", "WB", "WB");
|
|
|
if (ObjectUtils.isNull(billNo)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
- billNo = billNo + "-" + AuthUtil.getTenantId();
|
|
|
- Integer i = 1;
|
|
|
+ billNo = billNo + "-" + bladeUser.getTenantId();
|
|
|
+ int i = 1;
|
|
|
// 获取系统编号
|
|
|
- String SrcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
- if (ObjectUtils.isNull(SrcOrdNo)) {
|
|
|
+ String srcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
+ if (ObjectUtils.isNull(srcOrdNo)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
List<PjOrder> pjOrderList = new ArrayList<>();
|
|
|
+ // 处理部门,取第一个
|
|
|
+ Long deptId = UserUtils.getUserFirstDeptId(bladeUser.getDeptId());
|
|
|
+ // 获取业务员,不存在就远程查找
|
|
|
+ if (ObjectUtils.isNull(finalCorpsDesc.getSalesmanId())) {
|
|
|
+ R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", bladeUser.getDeptId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
+ finalCorpsDesc.setSalesmanId(res.getData().get(0).getId());
|
|
|
+ finalCorpsDesc.setSalesmanName(res.getData().get(0).getAccount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String freight = sysClient.getParamServiceDWT("freight", finalCorpsDesc.getTenantId());
|
|
|
for (Map<String, Object> map : list) {
|
|
|
String k = (String) map.get("name");
|
|
|
if (StringUtil.isNotBlank(k)) {
|
|
|
-
|
|
|
- String jsonStr = JSON.toJSONString(map.get("list"));
|
|
|
- JSONArray objects = JSONArray.parseArray(jsonStr);
|
|
|
- List<PjShoppingCart> shoppingCartList = objects.toJavaList(PjShoppingCart.class);
|
|
|
-
|
|
|
- //保存销售主表信息
|
|
|
- PjOrder order = new PjOrder();
|
|
|
- if (list.size() == 1) {//如果只有一个公司,订单编号和主编号一致
|
|
|
- order.setOrdNo(SrcOrdNo);
|
|
|
- } else {
|
|
|
- order.setOrdNo(SrcOrdNo + "-" + i);
|
|
|
- }
|
|
|
- order.setBusinesDate(new Date());
|
|
|
- order.setSrcOrdNo(billNo);
|
|
|
- order.setCreateUser(AuthUtil.getUserId());
|
|
|
-
|
|
|
- //处理部门
|
|
|
- int index = AuthUtil.getDeptId().indexOf(",");
|
|
|
- Long deptId = null;
|
|
|
- if (index > -1) {
|
|
|
- deptId = Long.valueOf(AuthUtil.getDeptId().substring(0, index));
|
|
|
- } else {
|
|
|
- deptId = (Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- }
|
|
|
-
|
|
|
- //根据客户账期计算应结日期
|
|
|
- if (ObjectUtil.isNotEmpty(corpsDesc.getAccountPeriod())) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long sevenDays = corpsDesc.getAccountPeriod() * 24 * 60 * 60 * 1000L;
|
|
|
- Date afterSevenDays = new Date(now.getTime() + sevenDays);
|
|
|
- order.setDueDate(afterSevenDays);
|
|
|
- } else {
|
|
|
- order.setDueDate(new Date());
|
|
|
- }
|
|
|
-
|
|
|
- order.setCreateTime(new Date());
|
|
|
- order.setCreateDept(deptId);
|
|
|
- order.setTenantId(AuthUtil.getTenantId());
|
|
|
- order.setCustomerId(finalCorpsDesc.getId());
|
|
|
- order.setCustomerName(finalCorpsDesc.getCname());
|
|
|
- if (ObjectUtils.isNotNull(finalCorpsDesc.getSalesmanId())) {
|
|
|
- order.setSalerId(finalCorpsDesc.getSalesmanId());
|
|
|
- order.setSalerName(finalCorpsDesc.getSalesmanName());
|
|
|
- } else {
|
|
|
- R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", AuthUtil.getDeptId());
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
- order.setSalerId(res.getData().get(0).getId());
|
|
|
- order.setSalerName(res.getData().get(0).getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(finalCorpsDesc.getDeliveryWarehouseId())) {
|
|
|
- order.setStorageId(finalCorpsDesc.getDeliveryWarehouseId());
|
|
|
- order.setStorageName(finalCorpsDesc.getDeliveryWarehouseName());
|
|
|
- }
|
|
|
- order.setSalesCompanyId(deptId);
|
|
|
- order.setSalesCompanyName(sysClient.getDeptName(deptId).getData());
|
|
|
- order.setRecAddress(address);
|
|
|
- order.setContacts(corpsAttn.getCname());
|
|
|
- order.setPhone(corpsAttn.getTel());
|
|
|
+ // 如果只有一个公司,订单编号和主编号一致
|
|
|
+ String nowOrderNo = list.size() == 1 ? srcOrdNo: srcOrdNo + "-" + i;
|
|
|
+ List<PjShoppingCart> shoppingCartList = JSONArray.parseArray(String.valueOf(map.get("list")), PjShoppingCart.class);
|
|
|
+ PjOrder order = WxParamUtil.getBaseOrderByCorps(finalCorpsDesc, corpsAttn, bladeUser, nowOrderNo, billNo, deptId, finalCorpsDesc.getCname(), address);
|
|
|
order.setBsType(OrderTypeEnum.SALES.getType());
|
|
|
order.setBusinessSource(OrderTypeEnum.XCX.getType());
|
|
|
order.setReceivableType("网络支付");
|
|
|
@@ -244,11 +201,11 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateDept(order.getCreateDept());
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
orderItems.setPid(order.getId());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(bladeUser.getTenantId());
|
|
|
orderItems.setBillNo(order.getOrdNo());
|
|
|
orderItems.setBizType(order.getBsType());
|
|
|
orderItems.setInventory(e.getInventory());
|
|
|
@@ -292,23 +249,10 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
-
|
|
|
- if (order.getGoodsTotalNum().compareTo(new BigDecimal(1)) == 0) {
|
|
|
- String freight = sysClient.getParamServiceDWT("freight", finalCorpsDesc.getTenantId());
|
|
|
- if (ObjectUtils.isNotNull(freight)) {
|
|
|
- try {
|
|
|
- BigDecimal freightAmount = new BigDecimal(freight);
|
|
|
- order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
- order.setFreight(freightAmount);
|
|
|
- } catch (Exception ignored) {
|
|
|
- order.setFreight(new BigDecimal(0));
|
|
|
- }
|
|
|
- }
|
|
|
- /*//只有一条明细加5元运费
|
|
|
- totalMoney = totalMoney.add(new BigDecimal(5));
|
|
|
- order.setTotalMoney(totalMoney);
|
|
|
- order.setFreight(new BigDecimal(5));*/
|
|
|
- }
|
|
|
+ // 运费不会为空,返回的只有零或设置的参数
|
|
|
+ BigDecimal freightAmount = WxParamUtil.getFreightByOrder(order.getGoodsTotalNum(), freight);
|
|
|
+ order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
+ order.setFreight(freightAmount);
|
|
|
amount = amount.add(order.getTotalMoney());
|
|
|
// order.setPaymentAmountTl(totalMoney);
|
|
|
order.setSharedCompanyId(shoppingCartList.get(0).getSharedCompanyId() + "");
|
|
|
@@ -325,11 +269,49 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
i++;
|
|
|
}
|
|
|
+ useEnd:if (Objects.nonNull(useRecoveredBalance) && useRecoveredBalance && FinalMap.ZERO_POINT_ZERO.compareTo(finalCorpsDesc.getRecoveredBalance()) < 0) {
|
|
|
+ // TODO: 多用户同时使用一个客户进行余额支付时应该进行占额,在订单操作途中占有这部分金额防止超出
|
|
|
+ // 使用余额抵扣
|
|
|
+ BigDecimal orderAmount = pjOrderList.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).filter(e -> e.compareTo(BigDecimal.ZERO) > 0).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (orderAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break useEnd;
|
|
|
+ }
|
|
|
+ BigDecimal halfAmount = orderAmount.divide(FinalMap.TWO, 2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal useAmount = halfAmount.compareTo(finalCorpsDesc.getRecoveredBalance()) > 0 ? finalCorpsDesc.getRecoveredBalance() : halfAmount;
|
|
|
+ if (useAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break useEnd;
|
|
|
+ }
|
|
|
+ BigDecimal orderUserAmount = BigDecimal.ZERO;
|
|
|
+ for (PjOrder item : pjOrderList) {
|
|
|
+ if (Objects.isNull(item.getTotalMoney()) || item.getTotalMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal ratio = item.getTotalMoney().divide(orderAmount, 10, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal allocated = ratio.multiply(useAmount).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setPaymentRecoveredBalance(allocated);
|
|
|
+ orderUserAmount = orderUserAmount.add(allocated);
|
|
|
+ }
|
|
|
+ log.error("使用计算金额金额:" + halfAmount);
|
|
|
+ log.error("使用计算金额金额orderUserAmount--:" + orderUserAmount);
|
|
|
+ log.error("使用余额抵扣金额:" + useAmount);
|
|
|
+ BigDecimal diff = useAmount.subtract(orderUserAmount);
|
|
|
+ if (diff.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ BigDecimal lastAllocated = pjOrderList.get(pjOrderList.size() - 1).getPaymentRecoveredBalance();
|
|
|
+ // 修正时也使用相同精度
|
|
|
+ pjOrderList.get(pjOrderList.size() - 1).setPaymentRecoveredBalance(lastAllocated.add(diff));
|
|
|
+ pjOrderList.get(pjOrderList.size() - 1).setTotalMoney(pjOrderList.get(pjOrderList.size() - 1).getTotalMoney().subtract(diff));
|
|
|
+ }
|
|
|
+ amount = amount.subtract(useAmount);
|
|
|
+ PjCorpsDesc corpsDesc = new PjCorpsDesc();
|
|
|
+ corpsDesc.setId(finalCorpsDesc.getId());
|
|
|
+ corpsDesc.setTenantId(finalCorpsDesc.getTenantId());
|
|
|
+ corpsDesc.setRecoveredBalance(finalCorpsDesc.getRecoveredBalance().subtract(useAmount));
|
|
|
+ corpsDescService.updateById(corpsDesc);
|
|
|
+ greenRecyclingRecordMapper.insert(WxParamUtil.parseGreenRecyclingRecord(corpsDesc, bladeUser.getUserId(), finalCorpsDesc.getRecoveredBalance(), useAmount, NumberEnum.ONE.number));
|
|
|
+ }
|
|
|
+
|
|
|
R<Map<Object, Object>> r = payService.payPrepay(ids.substring(0, ids.length() - 1), amount, billNo, 0, goodsName.substring(0, goodsName.length() - 1), payType);
|
|
|
- if ("W01".equals(payType) ||
|
|
|
- "A01".equals(payType) ||
|
|
|
- "U01".equals(payType) ||
|
|
|
- "S01".equals(payType)) {
|
|
|
+ if (FinalMap.PAY_TYPE_LIST.contains(payType)) {
|
|
|
for (PjOrder item : pjOrderList) {
|
|
|
item.setPayUrl(r.getData().get("url").toString());
|
|
|
}
|
|
|
@@ -1003,65 +985,45 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public R generateOrderShare(String address, List<PjShoppingCart> list, String payType) {
|
|
|
+ public R generateOrderShare(String address, List<PjShoppingCart> list, String payType, Boolean useRecoveredBalance) {
|
|
|
StringBuilder ids = new StringBuilder();
|
|
|
StringBuilder goodsName = new StringBuilder();
|
|
|
BigDecimal amount = new BigDecimal("0.00");
|
|
|
//从集合中取出商品生成销售单
|
|
|
if (ObjectUtil.isNotEmpty(list)) {
|
|
|
BigDecimal num = list.stream().map(PjShoppingCart::getGoodsNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- PjCorpsDesc corpsDesc = null;
|
|
|
+ PjCorpsAttn corpsAttn = UserUtils.getUserCorpsAttn();
|
|
|
//根据当前登录人获得客户
|
|
|
- PjCorpsAttn corpsAttn = corpsAttnService.getAttn(AuthUtil.getUserId());
|
|
|
- if (ObjectUtil.isNotEmpty(corpsAttn)) {
|
|
|
- corpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
- if (ObjectUtil.isEmpty(corpsDesc)) {
|
|
|
- throw new RuntimeException("未查到用户信息");
|
|
|
- }
|
|
|
- } else {
|
|
|
+ PjCorpsDesc corpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
+ if (ObjectUtil.isEmpty(corpsDesc)) {
|
|
|
throw new RuntimeException("未查到用户信息");
|
|
|
}
|
|
|
+ BigDecimal paymentTotalMoney = list.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsNum().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
String count = sysClient.getParamServiceNew("cashier.payment");
|
|
|
- String paymentType;
|
|
|
- if ("1".equals(corpsDesc.getIfLimitAmount())) {
|
|
|
- BigDecimal totalMoney = list.stream().reduce(BigDecimal.ZERO, (x, y) -> {
|
|
|
- return x.add(y.getGoodsNum().multiply(y.getPrice()));
|
|
|
- }, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
- if (corpsDesc.getLimitAmount().compareTo(totalMoney) >= 0) {
|
|
|
- paymentType = "2";
|
|
|
- } else {
|
|
|
- if ("1".equals(count)) {
|
|
|
- paymentType = "1";
|
|
|
- } else {
|
|
|
- paymentType = "0";
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- if ("1".equals(count)) {
|
|
|
- paymentType = "1";
|
|
|
- } else {
|
|
|
- paymentType = "0";
|
|
|
- }
|
|
|
- }
|
|
|
- if ("2".equals(paymentType)) {
|
|
|
- return generateOrderLimitShare(address, list, payType, corpsDesc, corpsAttn);
|
|
|
+ // 额度够返回 2, 否则根据 个体工商户收银台支付 参数返回 1还是0
|
|
|
+ String paymentType = WxParamUtil.wxPayGetPaymentType(corpsDesc.getIfLimitAmount(), corpsDesc.getLimitAmount(), paymentTotalMoney, count);
|
|
|
+ if (CommonEnum.TWO.info.equals(paymentType)) {
|
|
|
+ return generateOrderLimitShare(address, list, useRecoveredBalance, corpsDesc, corpsAttn);
|
|
|
} else {
|
|
|
- //处理部门
|
|
|
- int index = AuthUtil.getDeptId().indexOf(",");
|
|
|
- Long deptId = null;
|
|
|
- if (index > -1) {
|
|
|
- deptId = Long.valueOf(AuthUtil.getDeptId().substring(0, index));
|
|
|
- } else {
|
|
|
- deptId = (Long.valueOf(AuthUtil.getDeptId()));
|
|
|
- }
|
|
|
- String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
// 获取系统编号
|
|
|
String billNo = serialService.getBillNo("WB", "WB", "WB");
|
|
|
if (ObjectUtils.isNull(billNo)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
- billNo = billNo + "-" + AuthUtil.getTenantId();
|
|
|
+ BladeUser bladeUser = AuthUtil.getUser();
|
|
|
+ //处理部门
|
|
|
+ Long deptId = UserUtils.getUserFirstDeptId(bladeUser.getDeptId());
|
|
|
+ String deptName = sysClient.getDeptName(deptId).getData();
|
|
|
+ if (ObjectUtils.isNull(corpsDesc.getSalesmanId())) {
|
|
|
+ R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", bladeUser.getDeptId());
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
+ corpsDesc.setSalesmanId(res.getData().get(0).getId());
|
|
|
+ corpsDesc.setSalesmanName(res.getData().get(0).getAccount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
+ billNo = billNo + "-" + bladeUser.getTenantId();
|
|
|
List<PjOrder> pjOrderList = new ArrayList<>();
|
|
|
List<PjOrderItems> orderItemsList = new ArrayList<>();
|
|
|
List<PjOrderItems> orderItemsListShare = new ArrayList<>();
|
|
|
@@ -1082,9 +1044,9 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(bladeUser.getTenantId());
|
|
|
orderItems.setInventory(item.getInventory());
|
|
|
orderItems.setTotalAmount(orderItems.getGoodsNum().multiply(orderItems.getPrice()));
|
|
|
orderItems.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
@@ -1099,9 +1061,9 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(bladeUser.getTenantId());
|
|
|
orderItems.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
orderItems.setGoodsName(item.getGoodsName());
|
|
|
|
|
|
@@ -1113,9 +1075,9 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderItemsShare.setId(null);
|
|
|
orderItemsShare.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItemsShare.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItemsShare.setCreateUser(bladeUser.getUserId());
|
|
|
orderItemsShare.setCreateTime(new Date());
|
|
|
- orderItemsShare.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItemsShare.setTenantId(bladeUser.getTenantId());
|
|
|
orderItemsShare.setBizType("GX");
|
|
|
orderItemsShare.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
orderItemsShare.setGoodsName(item.getGoodsName());
|
|
|
@@ -1149,9 +1111,9 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderItemsShare.setId(null);
|
|
|
orderItemsShare.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItemsShare.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItemsShare.setCreateUser(bladeUser.getUserId());
|
|
|
orderItemsShare.setCreateTime(new Date());
|
|
|
- orderItemsShare.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItemsShare.setTenantId(bladeUser.getTenantId());
|
|
|
orderItemsShare.setBizType("GX");
|
|
|
orderItemsShare.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
orderItemsShare.setGoodsName(item.getGoodsName());
|
|
|
@@ -1167,55 +1129,19 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
if (!orderItemsListShare.isEmpty()) {
|
|
|
//保存销售主表信息-共享销售单
|
|
|
- PjOrder orderShare = new PjOrder();
|
|
|
String srcOrdNoShare = serialService.getBillNo("GX", "GX", "GX");
|
|
|
if (ObjectUtils.isNull(srcOrdNoShare)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
- orderShare.setOrdNo(srcOrdNoShare);
|
|
|
- orderShare.setBusinesDate(new Date());
|
|
|
- orderShare.setSrcOrdNo(billNo);
|
|
|
- orderShare.setCreateUser(AuthUtil.getUserId());
|
|
|
- //根据客户账期计算应结日期
|
|
|
- if (ObjectUtil.isNotEmpty(corpsDesc.getAccountPeriod())) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long sevenDays = corpsDesc.getAccountPeriod() * 24 * 60 * 60 * 1000L;
|
|
|
- Date afterSevenDays = new Date(now.getTime() + sevenDays);
|
|
|
- orderShare.setDueDate(afterSevenDays);
|
|
|
- } else {
|
|
|
- orderShare.setDueDate(new Date());
|
|
|
- }
|
|
|
- orderShare.setCreateTime(new Date());
|
|
|
- orderShare.setCreateDept(deptId);
|
|
|
- orderShare.setTenantId(AuthUtil.getTenantId());
|
|
|
- orderShare.setCustomerId(corpsDesc.getId());
|
|
|
- orderShare.setCustomerName(corpsDesc.getCname());
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getSalesmanId())) {
|
|
|
- orderShare.setSalerId(corpsDesc.getSalesmanId());
|
|
|
- orderShare.setSalerName(corpsDesc.getSalesmanName());
|
|
|
- } else {
|
|
|
- R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", AuthUtil.getDeptId());
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
- orderShare.setSalerId(res.getData().get(0).getId());
|
|
|
- orderShare.setSalerName(res.getData().get(0).getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getDeliveryWarehouseId())) {
|
|
|
- orderShare.setStorageId(corpsDesc.getDeliveryWarehouseId());
|
|
|
- orderShare.setStorageName(corpsDesc.getDeliveryWarehouseName());
|
|
|
- }
|
|
|
- orderShare.setSalesCompanyId(deptId);
|
|
|
- orderShare.setSalesCompanyName(sysClient.getDeptName(deptId).getData());
|
|
|
- orderShare.setRecAddress(address);
|
|
|
- orderShare.setContacts(corpsAttn.getCname());
|
|
|
- orderShare.setPhone(corpsAttn.getTel());
|
|
|
+ PjOrder orderShare = WxParamUtil.getBaseOrderByCorps(corpsDesc, corpsAttn, bladeUser, srcOrdNoShare, billNo, deptId, deptName, address);
|
|
|
orderShare.setBsType("GX");
|
|
|
orderShare.setBusinessSource("外部销售");
|
|
|
orderShare.setReceivableType("网络支付");
|
|
|
orderShare.setBillType(1);
|
|
|
BigDecimal totalMoney = BigDecimal.ZERO;
|
|
|
- orderShare.setNumberRows(orderItemsListShare.size());//行数
|
|
|
+ //行数
|
|
|
+ orderShare.setNumberRows(orderItemsListShare.size());
|
|
|
//明细总数量
|
|
|
orderShare.setGoodsTotalNum(orderItemsListShare.stream().map(PjOrderItems::getGoodsNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
//明细总金额
|
|
|
@@ -1224,18 +1150,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
orderShare.setSalesAmount(totalMoney);
|
|
|
orderShare.setTotalMoney(totalMoney);
|
|
|
-/* if (num.compareTo(new BigDecimal(1)) == 0) {
|
|
|
- if (ObjectUtils.isNotNull(freight)) {
|
|
|
- try {
|
|
|
- BigDecimal freightAmount = new BigDecimal(freight);
|
|
|
- orderShare.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
- orderShare.setFreight(freightAmount);
|
|
|
- } catch (Exception ignored) {
|
|
|
- orderShare.setFreight(new BigDecimal(0));
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
- orderShare.setFreight(new BigDecimal(0));
|
|
|
+ orderShare.setFreight(BigDecimal.ZERO);
|
|
|
orderShare.setGoodsNameJoin(orderItemsListShare.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(",")));
|
|
|
orderShare.setShortcutJoin(orderItemsListShare.stream().map(PjOrderItems::getCnameInt).collect(Collectors.joining(",")));
|
|
|
orderShare.setPayType(payType);
|
|
|
@@ -1252,60 +1167,19 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
if (!orderItemsList.isEmpty()) {
|
|
|
//保存销售主表信息-本地销售单
|
|
|
- PjOrder order = new PjOrder();
|
|
|
// 获取系统编号
|
|
|
- String SrcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
- if (ObjectUtils.isNull(SrcOrdNo)) {
|
|
|
+ String srcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
+ if (ObjectUtils.isNull(srcOrdNo)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
- order.setOrdNo(SrcOrdNo);
|
|
|
- order.setBusinesDate(new Date());
|
|
|
- order.setSrcOrdNo(billNo);
|
|
|
- order.setCreateUser(AuthUtil.getUserId());
|
|
|
- //根据客户账期计算应结日期
|
|
|
- if (ObjectUtil.isNotEmpty(corpsDesc.getAccountPeriod())) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long sevenDays = corpsDesc.getAccountPeriod() * 24 * 60 * 60 * 1000L;
|
|
|
- Date afterSevenDays = new Date(now.getTime() + sevenDays);
|
|
|
- order.setDueDate(afterSevenDays);
|
|
|
- } else {
|
|
|
- order.setDueDate(new Date());
|
|
|
- }
|
|
|
- order.setCreateTime(new Date());
|
|
|
- order.setCreateDept(deptId);
|
|
|
- order.setTenantId(AuthUtil.getTenantId());
|
|
|
- order.setCustomerId(corpsDesc.getId());
|
|
|
- order.setCustomerName(corpsDesc.getCname());
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getSalesmanId())) {
|
|
|
- order.setSalerId(corpsDesc.getSalesmanId());
|
|
|
- order.setSalerName(corpsDesc.getSalesmanName());
|
|
|
- } else {
|
|
|
- R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", AuthUtil.getDeptId());
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
- order.setSalerId(res.getData().get(0).getId());
|
|
|
- order.setSalerName(res.getData().get(0).getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getDeliveryWarehouseId())) {
|
|
|
- order.setStorageId(corpsDesc.getDeliveryWarehouseId());
|
|
|
- order.setStorageName(corpsDesc.getDeliveryWarehouseName());
|
|
|
- }
|
|
|
- order.setSalesCompanyId(deptId);
|
|
|
- order.setSalesCompanyName(sysClient.getDeptName(deptId).getData());
|
|
|
- order.setRecAddress(address);
|
|
|
- order.setContacts(corpsAttn.getCname());
|
|
|
- order.setPhone(corpsAttn.getTel());
|
|
|
+ PjOrder order = WxParamUtil.getBaseOrderByCorps(corpsDesc, corpsAttn, bladeUser, srcOrdNo, billNo, deptId, deptName, address);
|
|
|
order.setBsType(OrderTypeEnum.SALES.getType());
|
|
|
order.setBusinessSource(OrderTypeEnum.XCX.getType());
|
|
|
order.setReceivableType("网络支付");
|
|
|
- if (!orderItemsListShare.isEmpty()) {
|
|
|
- order.setBillType(1);
|
|
|
- } else {
|
|
|
- order.setBillType(0);
|
|
|
- }
|
|
|
+ order.setBillType(!orderItemsListShare.isEmpty()?1:0);
|
|
|
orderService.save(order);
|
|
|
- pjOrderList.add(order);
|
|
|
+ // pjOrderList.add(order);
|
|
|
ids.append(order.getId()).append(",");
|
|
|
for (PjOrderItems item : orderItemsList) {
|
|
|
item.setCreateDept(order.getCreateDept());
|
|
|
@@ -1324,23 +1198,58 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
- if (num.compareTo(new BigDecimal(1)) == 0) {
|
|
|
- if (ObjectUtils.isNotNull(freight)) {
|
|
|
- try {
|
|
|
- BigDecimal freightAmount = new BigDecimal(freight);
|
|
|
- order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
- order.setFreight(freightAmount);
|
|
|
- } catch (Exception ignored) {
|
|
|
- order.setFreight(new BigDecimal(0));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ // 运费不会为空,返回的只有零或设置的参数
|
|
|
+ BigDecimal freightAmount = WxParamUtil.getFreightByOrder(num, freight);
|
|
|
+ order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
+ order.setFreight(freightAmount);
|
|
|
order.setGoodsNameJoin(orderItemsList.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(",")));
|
|
|
order.setShortcutJoin(orderItemsList.stream().map(PjOrderItems::getCnameInt).collect(Collectors.joining(",")));
|
|
|
order.setPayType(payType);
|
|
|
pjOrderList.add(order);
|
|
|
amount = amount.add(order.getTotalMoney());
|
|
|
}
|
|
|
+ useEnd:if (Objects.nonNull(useRecoveredBalance) && useRecoveredBalance && FinalMap.ZERO_POINT_ZERO.compareTo(corpsDesc.getRecoveredBalance()) < 0) {
|
|
|
+ // TODO: 多用户同时使用一个客户进行余额支付时应该进行占额,在订单操作途中占有这部分金额防止超出
|
|
|
+ // 使用余额抵扣
|
|
|
+ BigDecimal orderAmount = pjOrderList.stream().map(PjOrder::getTotalMoney).filter(Objects::nonNull).filter(e -> e.compareTo(BigDecimal.ZERO) > 0).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (orderAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break useEnd;
|
|
|
+ }
|
|
|
+ BigDecimal halfAmount = orderAmount.divide(FinalMap.TWO, 2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal useAmount = halfAmount.compareTo(corpsDesc.getRecoveredBalance()) > 0 ? corpsDesc.getRecoveredBalance() : halfAmount;
|
|
|
+ if (useAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ break useEnd;
|
|
|
+ }
|
|
|
+ BigDecimal orderUserAmount = BigDecimal.ZERO;
|
|
|
+ for (PjOrder item : pjOrderList) {
|
|
|
+ if (Objects.isNull(item.getTotalMoney()) || item.getTotalMoney().compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ BigDecimal ratio = item.getTotalMoney().divide(orderAmount, 10, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal allocated = ratio.multiply(useAmount).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ item.setPaymentRecoveredBalance(allocated);
|
|
|
+ // item.setTotalMoney(item.getTotalMoney().subtract(allocated));
|
|
|
+ orderUserAmount = orderUserAmount.add(allocated);
|
|
|
+ }
|
|
|
+ log.error("使用计算金额金额:" + halfAmount);
|
|
|
+ log.error("使用计算金额金额11111--:" + orderUserAmount);
|
|
|
+ log.error("使用余额抵扣金额:" + useAmount);
|
|
|
+ BigDecimal diff = useAmount.subtract(orderUserAmount);
|
|
|
+ if (diff.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ // 补偿,如果计算有差那就分配到最后一个订单上
|
|
|
+ BigDecimal lastAllocated = pjOrderList.get(pjOrderList.size() - 1).getPaymentRecoveredBalance();
|
|
|
+ pjOrderList.get(pjOrderList.size() - 1).setPaymentRecoveredBalance(lastAllocated.add(diff));
|
|
|
+ pjOrderList.get(pjOrderList.size() - 1).setTotalMoney(pjOrderList.get(pjOrderList.size() - 1).getTotalMoney().subtract(diff));
|
|
|
+ }
|
|
|
+ amount = amount.subtract(useAmount);
|
|
|
+
|
|
|
+ PjCorpsDesc updateCorpsDesc = new PjCorpsDesc();
|
|
|
+ updateCorpsDesc.setId(corpsDesc.getId());
|
|
|
+ updateCorpsDesc.setTenantId(corpsDesc.getTenantId());
|
|
|
+ updateCorpsDesc.setRecoveredBalance(corpsDesc.getRecoveredBalance().subtract(useAmount));
|
|
|
+ corpsDescService.updateById(updateCorpsDesc);
|
|
|
+ greenRecyclingRecordMapper.insert(WxParamUtil.parseGreenRecyclingRecord(updateCorpsDesc, bladeUser.getUserId(), corpsDesc.getRecoveredBalance(), useAmount, NumberEnum.ONE.number));
|
|
|
+ }
|
|
|
R<Map<Object, Object>> r = payService.payPrepay(ids.substring(0, ids.length() - 1), amount, billNo, 0, goodsName.substring(0, goodsName.length() - 1), payType);
|
|
|
if ("1".equals(paymentType)) {
|
|
|
if (ObjectUtils.isNotNull(r.getData().get("url"))) {
|
|
|
@@ -1420,7 +1329,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
return payResult;
|
|
|
}
|
|
|
|
|
|
- public R generateOrderLimitShare(String address, List<PjShoppingCart> list, String payType, PjCorpsDesc corpsDesc, PjCorpsAttn corpsAttn) {
|
|
|
+ public R generateOrderLimitShare(String address, List<PjShoppingCart> list, Boolean useRecoveredBalance, PjCorpsDesc corpsDesc, PjCorpsAttn corpsAttn) {
|
|
|
// 获取系统编号
|
|
|
String billNo = serialService.getBillNo("WB", "WB", "WB");
|
|
|
if (ObjectUtils.isNull(billNo)) {
|
|
|
@@ -1429,20 +1338,23 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
BigDecimal num = list.stream().map(PjShoppingCart::getGoodsNum).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
// 获取系统编号
|
|
|
- String SrcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
- if (ObjectUtils.isNull(SrcOrdNo)) {
|
|
|
+ String srcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
+ if (ObjectUtils.isNull(srcOrdNo)) {
|
|
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
throw new RuntimeException("生成系统编号失败");
|
|
|
}
|
|
|
+ BladeUser bladeUser = AuthUtil.getUser();
|
|
|
//处理部门
|
|
|
- int index = AuthUtil.getDeptId().indexOf(",");
|
|
|
- Long deptId = null;
|
|
|
- if (index > -1) {
|
|
|
- deptId = Long.valueOf(AuthUtil.getDeptId().substring(0, index));
|
|
|
- } else {
|
|
|
- deptId = (Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ Long deptId = UserUtils.getUserFirstDeptId(bladeUser.getDeptId());
|
|
|
+ String deptName = sysClient.getDeptName(deptId).getData();
|
|
|
+ R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", bladeUser.getDeptId());
|
|
|
+ if (ObjectUtils.isNull(corpsDesc.getSalesmanId())) {
|
|
|
+ if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
+ corpsDesc.setSalesmanId(res.getData().get(0).getId());
|
|
|
+ corpsDesc.setSalesmanName(res.getData().get(0).getAccount());
|
|
|
+ }
|
|
|
}
|
|
|
- R<List<User>> res = userSearchClient.getWarehouseKeeper("业务员", AuthUtil.getDeptId());
|
|
|
+ String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
List<PjOrder> pjOrderList = new ArrayList<>();
|
|
|
List<PjOrderItems> orderItemsList = new ArrayList<>();
|
|
|
List<PjOrderItems> orderItemsListShare = new ArrayList<>();
|
|
|
@@ -1461,11 +1373,11 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItems.setCnameInt(goodsDesc.getCnameInt());
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
- orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setSendNum(FinalMap.ZERO_POINT_ZERO);
|
|
|
+ orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateDept(deptId);
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(bladeUser.getTenantId());
|
|
|
orderItems.setBillNo(billNo);
|
|
|
orderItems.setBizType("XS");
|
|
|
orderItems.setInventory(item.getInventory());
|
|
|
@@ -1479,7 +1391,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
for (SharePutOnShelves items : sharePutOnShelvesList) {
|
|
|
items.setInventory(productLaunch.getInventory());
|
|
|
items.setUpdateTime(new Date());
|
|
|
- items.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ items.setUpdateUser(bladeUser.getUserId());
|
|
|
sharePutOnShelvesMapper.updateSharePutOnShelves(items);
|
|
|
}
|
|
|
} else {//共享销售
|
|
|
@@ -1490,11 +1402,11 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItems.setCnameInt(goodsDesc.getCnameInt());
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
- orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setSendNum(FinalMap.ZERO_POINT_ZERO);
|
|
|
+ orderItems.setCreateUser(bladeUser.getUserId());
|
|
|
orderItems.setCreateDept(deptId);
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(bladeUser.getTenantId());
|
|
|
orderItems.setBillNo(billNo);
|
|
|
orderItems.setBizType("GX");
|
|
|
orderItems.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
@@ -1507,11 +1419,11 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItemsShare.setCnameInt(goodsDesc.getCnameInt());
|
|
|
}
|
|
|
orderItemsShare.setId(null);
|
|
|
- orderItemsShare.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItemsShare.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItemsShare.setSendNum(FinalMap.ZERO_POINT_ZERO);
|
|
|
+ orderItemsShare.setCreateUser(bladeUser.getUserId());
|
|
|
orderItemsShare.setCreateDept(deptId);
|
|
|
orderItemsShare.setCreateTime(new Date());
|
|
|
- orderItemsShare.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItemsShare.setTenantId(bladeUser.getTenantId());
|
|
|
orderItemsShare.setBillNo(billNo);
|
|
|
orderItemsShare.setBizType("GX");
|
|
|
orderItemsShare.setUrl(ObjectUtils.isNotNull(item.getFilesList()) && !item.getFilesList().isEmpty() ? item.getFilesList().get(0).getUrl() : "");
|
|
|
@@ -1533,7 +1445,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
for (SharePutOnShelves items : sharePutOnShelvesList) {
|
|
|
items.setInventory(productLaunch.getInventory());
|
|
|
items.setUpdateTime(new Date());
|
|
|
- items.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ items.setUpdateUser(bladeUser.getUserId());
|
|
|
sharePutOnShelvesMapper.updateSharePutOnShelves(items);
|
|
|
}
|
|
|
orderItemsShare.setInventory(item.getInventory());
|
|
|
@@ -1546,45 +1458,26 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
item.setIsDeleted(1);
|
|
|
baseMapper.updateById(item);
|
|
|
}
|
|
|
+ // 订单最多使用余额
|
|
|
+ BigDecimal useAmount = BigDecimal.ZERO;
|
|
|
+ // 订单已分配余额
|
|
|
+ BigDecimal orderUseAmount = BigDecimal.ZERO;
|
|
|
+ // 订单总金额
|
|
|
+ BigDecimal orderAmount = BigDecimal.ZERO;
|
|
|
+ // 余额支付,提前计算使用余额
|
|
|
+ boolean haveRecoveredBalance = Objects.nonNull(useRecoveredBalance) && useRecoveredBalance && FinalMap.ZERO_POINT_ZERO.compareTo(corpsDesc.getRecoveredBalance()) < 0;
|
|
|
+ if (haveRecoveredBalance) {
|
|
|
+ BigDecimal orderShareItemAmount = orderItemsListShare.stream().reduce(BigDecimal.ZERO, (x, y)
|
|
|
+ -> x.add(y.getGoodsNum().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal orderItemAmount = orderItemsList.stream().reduce(BigDecimal.ZERO, (x, y)
|
|
|
+ -> x.add(y.getGoodsNum().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ orderAmount = orderItemAmount.add(orderShareItemAmount);
|
|
|
+ BigDecimal halfAmount = orderAmount.divide(FinalMap.TWO, 2, RoundingMode.HALF_UP);
|
|
|
+ useAmount = halfAmount.compareTo(corpsDesc.getRecoveredBalance()) > 0 ? corpsDesc.getRecoveredBalance() : halfAmount;
|
|
|
+ }
|
|
|
if (!orderItemsListShare.isEmpty()) {
|
|
|
//保存销售主表信息-共享销售单
|
|
|
- PjOrder orderShare = new PjOrder();
|
|
|
- orderShare.setOrdNo(SrcOrdNo + "-" + 2);
|
|
|
- orderShare.setBusinesDate(new Date());
|
|
|
- orderShare.setSrcOrdNo(billNo);
|
|
|
- orderShare.setCreateUser(AuthUtil.getUserId());
|
|
|
- //根据客户账期计算应结日期
|
|
|
- if (ObjectUtil.isNotEmpty(corpsDesc.getAccountPeriod())) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long sevenDays = corpsDesc.getAccountPeriod() * 24 * 60 * 60 * 1000L;
|
|
|
- Date afterSevenDays = new Date(now.getTime() + sevenDays);
|
|
|
- orderShare.setDueDate(afterSevenDays);
|
|
|
- } else {
|
|
|
- orderShare.setDueDate(new Date());
|
|
|
- }
|
|
|
- orderShare.setCreateTime(new Date());
|
|
|
- orderShare.setCreateDept(deptId);
|
|
|
- orderShare.setTenantId(AuthUtil.getTenantId());
|
|
|
- orderShare.setCustomerId(corpsDesc.getId());
|
|
|
- orderShare.setCustomerName(corpsDesc.getCname());
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getSalesmanId())) {
|
|
|
- orderShare.setSalerId(corpsDesc.getSalesmanId());
|
|
|
- orderShare.setSalerName(corpsDesc.getSalesmanName());
|
|
|
- } else {
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
- orderShare.setSalerId(res.getData().get(0).getId());
|
|
|
- orderShare.setSalerName(res.getData().get(0).getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getDeliveryWarehouseId())) {
|
|
|
- orderShare.setStorageId(corpsDesc.getDeliveryWarehouseId());
|
|
|
- orderShare.setStorageName(corpsDesc.getDeliveryWarehouseName());
|
|
|
- }
|
|
|
- orderShare.setSalesCompanyId(deptId);
|
|
|
- orderShare.setSalesCompanyName(sysClient.getDeptName(deptId).getData());
|
|
|
- orderShare.setRecAddress(address);
|
|
|
- orderShare.setContacts(corpsAttn.getCname());
|
|
|
- orderShare.setPhone(corpsAttn.getTel());
|
|
|
+ PjOrder orderShare = WxParamUtil.getBaseOrderByCorps(corpsDesc, corpsAttn, bladeUser, srcOrdNo + "-" + 2, billNo, deptId, deptName, address);
|
|
|
orderShare.setBsType("GX");
|
|
|
orderShare.setBusinessSource("额度支付");
|
|
|
orderShare.setReceivableType("网络支付");
|
|
|
@@ -1607,57 +1500,27 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderShare.setGoodsNameJoin(orderItemsListShare.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(",")));
|
|
|
orderShare.setShortcutJoin(orderItemsListShare.stream().map(PjOrderItems::getCnameInt).collect(Collectors.joining(",")));
|
|
|
pjOrderList.add(orderShare);
|
|
|
+ orderShare.setPaymentRecoveredBalance(BigDecimal.ZERO);
|
|
|
+ if (haveRecoveredBalance && totalMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ BigDecimal ratio = totalMoney.divide(orderAmount, 10, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal allocated = ratio.multiply(useAmount).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ orderShare.setPaymentRecoveredBalance(allocated);
|
|
|
+ // orderShare.setPaymentAmountTl(orderShare.getPaymentAmountTl().subtract(allocated));
|
|
|
+ orderUseAmount = allocated;
|
|
|
+ }
|
|
|
orderService.save(orderShare);
|
|
|
for (PjOrderItems item : orderItemsListShare) {
|
|
|
item.setPid(orderShare.getId());
|
|
|
orderItemsMapper.insert(item);
|
|
|
}
|
|
|
- corpsDesc.setLimitAmount(corpsDesc.getLimitAmount().subtract(totalMoney));
|
|
|
+ corpsDesc.setLimitAmount(corpsDesc.getLimitAmount().subtract(totalMoney.subtract(orderShare.getPaymentRecoveredBalance())));
|
|
|
corpsDescService.updateById(corpsDesc);
|
|
|
}
|
|
|
if (!orderItemsList.isEmpty()) {
|
|
|
//保存销售主表信息-本地销售单
|
|
|
- PjOrder order = new PjOrder();
|
|
|
- if (list.size() == 1) {//如果只有一个公司,订单编号和主编号一致
|
|
|
- order.setOrdNo(SrcOrdNo);
|
|
|
- } else {
|
|
|
- order.setOrdNo(SrcOrdNo + "-" + 1);
|
|
|
- }
|
|
|
- order.setBusinesDate(new Date());
|
|
|
- order.setSrcOrdNo(billNo);
|
|
|
- order.setCreateUser(AuthUtil.getUserId());
|
|
|
- //根据客户账期计算应结日期
|
|
|
- if (ObjectUtil.isNotEmpty(corpsDesc.getAccountPeriod())) {
|
|
|
- Date now = new Date(); // 获取当前时间
|
|
|
- long sevenDays = corpsDesc.getAccountPeriod() * 24 * 60 * 60 * 1000L;
|
|
|
- Date afterSevenDays = new Date(now.getTime() + sevenDays);
|
|
|
- order.setDueDate(afterSevenDays);
|
|
|
- } else {
|
|
|
- order.setDueDate(new Date());
|
|
|
- }
|
|
|
- order.setCreateTime(new Date());
|
|
|
- order.setCreateDept(deptId);
|
|
|
- order.setTenantId(AuthUtil.getTenantId());
|
|
|
- order.setCustomerId(corpsDesc.getId());
|
|
|
- order.setCustomerName(corpsDesc.getCname());
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getSalesmanId())) {
|
|
|
- order.setSalerId(corpsDesc.getSalesmanId());
|
|
|
- order.setSalerName(corpsDesc.getSalesmanName());
|
|
|
- } else {
|
|
|
- if (res.isSuccess() && ObjectUtils.isNotNull(res.getData()) && !res.getData().isEmpty()) {
|
|
|
- order.setSalerId(res.getData().get(0).getId());
|
|
|
- order.setSalerName(res.getData().get(0).getAccount());
|
|
|
- }
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotNull(corpsDesc.getDeliveryWarehouseId())) {
|
|
|
- order.setStorageId(corpsDesc.getDeliveryWarehouseId());
|
|
|
- order.setStorageName(corpsDesc.getDeliveryWarehouseName());
|
|
|
- }
|
|
|
- order.setSalesCompanyId(deptId);
|
|
|
- order.setSalesCompanyName(sysClient.getDeptName(deptId).getData());
|
|
|
- order.setRecAddress(address);
|
|
|
- order.setContacts(corpsAttn.getCname());
|
|
|
- order.setPhone(corpsAttn.getTel());
|
|
|
+ //如果只有一个公司,订单编号和主编号一致
|
|
|
+ String nowOrderNo = list.size() == 1 ? srcOrdNo : srcOrdNo + "-" + 1;
|
|
|
+ PjOrder order = WxParamUtil.getBaseOrderByCorps(corpsDesc, corpsAttn, bladeUser, nowOrderNo, billNo, deptId, deptName, address);
|
|
|
order.setBsType(OrderTypeEnum.SALES.getType());
|
|
|
order.setBusinessSource("额度支付");
|
|
|
order.setReceivableType("网络支付");
|
|
|
@@ -1673,18 +1536,9 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
// order.getGoodsTotalNum()
|
|
|
- if (num.compareTo(new BigDecimal(1)) == 0) {
|
|
|
- String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
- if (ObjectUtils.isNotNull(freight)) {
|
|
|
- try {
|
|
|
- BigDecimal freightAmount = new BigDecimal(freight);
|
|
|
- order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
- order.setFreight(freightAmount);
|
|
|
- } catch (Exception ignored) {
|
|
|
- order.setFreight(new BigDecimal(0));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ BigDecimal freightAmount = WxParamUtil.getFreightByOrder(num, freight);
|
|
|
+ order.setTotalMoney(totalMoney.add(freightAmount));
|
|
|
+ order.setFreight(freightAmount);
|
|
|
order.setGoodsNameJoin(orderItemsList.stream().map(PjOrderItems::getGoodsName).collect(Collectors.joining(",")));
|
|
|
order.setShortcutJoin(orderItemsList.stream().map(PjOrderItems::getCnameInt).collect(Collectors.joining(",")));
|
|
|
order.setPaymentDate(new Date());
|
|
|
@@ -1693,7 +1547,12 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
order.setPaymentDate(new Date());
|
|
|
order.setStatus(OrderTypeEnum.XSDQR.getType());
|
|
|
order.setXcxStatus(OrderTypeEnum.XSDFH.getType());
|
|
|
- corpsDesc.setLimitAmount(corpsDesc.getLimitAmount().subtract(order.getTotalMoney()));
|
|
|
+ if (haveRecoveredBalance && totalMoney.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ // 不管共享是否使用余额,直接使用可用余额减去已使用的余额
|
|
|
+ order.setPaymentRecoveredBalance(useAmount.subtract(orderUseAmount));
|
|
|
+ // order.setPaymentAmountTl(order.getPaymentRecoveredBalance());
|
|
|
+ }
|
|
|
+ corpsDesc.setLimitAmount(corpsDesc.getLimitAmount().subtract(order.getTotalMoney().subtract(order.getPaymentRecoveredBalance())));
|
|
|
orderService.save(order);
|
|
|
pjOrderList.add(order);
|
|
|
corpsDescService.updateById(corpsDesc);
|
|
|
@@ -1705,14 +1564,23 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
orderItemsMapper.insert(item);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (haveRecoveredBalance) {
|
|
|
+ PjCorpsDesc updateCorpsDesc = new PjCorpsDesc();
|
|
|
+ updateCorpsDesc.setId(corpsDesc.getId());
|
|
|
+ updateCorpsDesc.setTenantId(corpsDesc.getTenantId());
|
|
|
+ updateCorpsDesc.setRecoveredBalance(corpsDesc.getRecoveredBalance().subtract(useAmount));
|
|
|
+ corpsDescService.updateById(updateCorpsDesc);
|
|
|
+ greenRecyclingRecordMapper.insert(WxParamUtil.parseGreenRecyclingRecord(updateCorpsDesc, bladeUser.getUserId(), corpsDesc.getRecoveredBalance(), useAmount, NumberEnum.ONE.number));
|
|
|
+ }
|
|
|
for (PjOrder item : pjOrderList) {
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
String formatted = now.format(formatter);
|
|
|
//给角色为财务的人发送消息
|
|
|
- R<String> clientDeptIds = sysClient.getRoleIds(AuthUtil.getTenantId(), "客服");
|
|
|
+ R<String> clientDeptIds = sysClient.getRoleIds(bladeUser.getTenantId(), "客服");
|
|
|
if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|
|
|
- R<List<User>> userList = userClient.listUserByRoleId(clientDeptIds.getData(), AuthUtil.getTenantId(), item.getSalesCompanyId() + "");
|
|
|
+ R<List<User>> userList = userClient.listUserByRoleId(clientDeptIds.getData(), bladeUser.getTenantId(), item.getSalesCompanyId() + "");
|
|
|
if (userList.isSuccess() && CollectionUtils.isNotEmpty(userList.getData())) {
|
|
|
for (User datum : userList.getData()) {
|
|
|
//循环发送消息
|
|
|
@@ -1723,7 +1591,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
sendMessage.setToUserId(datum.getId());
|
|
|
sendMessage.setToUserName(datum.getName());
|
|
|
sendMessage.setMessageType(1);
|
|
|
- sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setTenantId(bladeUser.getTenantId());
|
|
|
sendMessage.setCreateUser(null);
|
|
|
sendMessage.setCreateTime(new Date());
|
|
|
sendMessage.setUrl("/tirePartsMall/salesManagement/saleOrder/index");
|
|
|
@@ -1746,7 +1614,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
sendMessage.setToUserId(item.getSalerId());
|
|
|
sendMessage.setToUserName(item.getSalerName());
|
|
|
sendMessage.setMessageType(1);
|
|
|
- sendMessage.setTenantId(AuthUtil.getTenantId());
|
|
|
+ sendMessage.setTenantId(bladeUser.getTenantId());
|
|
|
sendMessage.setCreateUser(null);
|
|
|
sendMessage.setCreateTime(new Date());
|
|
|
sendMessage.setUrl("/tirePartsMall/salesManagement/saleOrder/index");
|
|
|
@@ -1760,7 +1628,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>(1);
|
|
|
map.put("type", "2");
|
|
|
return R.data(map);
|
|
|
}
|