|
|
@@ -536,37 +536,27 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
StringBuilder goodsName = new StringBuilder();
|
|
|
StringBuilder shortcutJoin = new StringBuilder();
|
|
|
BigDecimal amount = new BigDecimal("0.00");
|
|
|
-
|
|
|
+ BladeUser nowOrderUser = AuthUtil.getUser();
|
|
|
+ Date nowDate = new Date();
|
|
|
//从集合中取出商品生成销售单
|
|
|
if (ObjectUtil.isNotEmpty(list)) {
|
|
|
-
|
|
|
- PjCorpsDesc corpsDesc = null;
|
|
|
//根据当前登录人获得客户
|
|
|
- PjCorpsAttn corpsAttn = corpsAttnService.getAttn(AuthUtil.getUserId());
|
|
|
- if (ObjectUtil.isNotEmpty(corpsAttn)) {
|
|
|
- corpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
- if (ObjectUtil.isEmpty(corpsDesc)) {
|
|
|
- throw new RuntimeException("未查到用户信息");
|
|
|
- }
|
|
|
- } else {
|
|
|
- throw new RuntimeException("未查到用户信息");
|
|
|
+ PjCorpsAttn corpsAttn = UserUtils.getUserCorpsAttn();
|
|
|
+ PjCorpsDesc corpsDesc = corpsDescService.getCorpsDesc(corpsAttn.getPid());
|
|
|
+ if (ObjectUtil.isEmpty(corpsDesc)) {
|
|
|
+ return R.fail("未查到用户信息");
|
|
|
}
|
|
|
-
|
|
|
- PjCorpsDesc finalCorpsDesc = corpsDesc;
|
|
|
-
|
|
|
// 获取系统编号
|
|
|
String billNo = serialService.getBillNo("WB", "WB", "WB");
|
|
|
if (ObjectUtils.isNull(billNo)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- throw new RuntimeException("生成系统编号失败");
|
|
|
+ return R.fail("生成系统编号失败");
|
|
|
}
|
|
|
- billNo = billNo + "-" + AuthUtil.getTenantId();
|
|
|
- Integer i = 1;
|
|
|
+ billNo = billNo + "-" + nowOrderUser.getTenantId();
|
|
|
+ int i = 1;
|
|
|
// 获取系统编号
|
|
|
- String SrcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
- if (ObjectUtils.isNull(SrcOrdNo)) {
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- throw new RuntimeException("生成系统编号失败");
|
|
|
+ String srcOrdNo = serialService.getBillNo("XS", "XS", "XS");
|
|
|
+ if (ObjectUtils.isNull(srcOrdNo)) {
|
|
|
+ return R.fail("生成系统编号失败");
|
|
|
}
|
|
|
List<PjOrder> pjOrderList = new ArrayList<>();
|
|
|
for (Map<String, Object> map : list) {
|
|
|
@@ -576,46 +566,35 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
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.setOrdNo(list.size() == 1 ? srcOrdNo : srcOrdNo + "-" + i);
|
|
|
+ order.setBusinesDate(nowDate);
|
|
|
order.setSrcOrdNo(billNo);
|
|
|
- order.setCreateUser(AuthUtil.getUserId());
|
|
|
+ order.setCreateUser(nowOrderUser.getUserId());
|
|
|
order.setBsType("XS");
|
|
|
order.setRemarks(corpsDesc.getRemarks());
|
|
|
+ order.setStorageId(corpsDesc.getDeliveryWarehouseId());
|
|
|
+ order.setStorageName(corpsDesc.getDeliveryWarehouseName());
|
|
|
//处理部门
|
|
|
- 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(nowOrderUser.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);
|
|
|
+ Date afterSevenDays = new Date(nowDate.getTime() + sevenDays);
|
|
|
order.setDueDate(afterSevenDays);
|
|
|
} else {
|
|
|
- order.setDueDate(new Date());
|
|
|
+ order.setDueDate(nowDate);
|
|
|
}
|
|
|
-
|
|
|
- order.setCreateTime(new Date());
|
|
|
+ order.setCreateTime(nowDate);
|
|
|
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());
|
|
|
+ order.setTenantId(nowOrderUser.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()) {
|
|
|
@@ -641,12 +620,12 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
throw new RuntimeException("库存不足");
|
|
|
}
|
|
|
orderItems.setId(null);
|
|
|
- orderItems.setSendNum(new BigDecimal("0.00"));
|
|
|
- orderItems.setCreateUser(AuthUtil.getUserId());
|
|
|
+ orderItems.setSendNum(FinalMap.ZERO_POINT_ZERO);
|
|
|
+ orderItems.setCreateUser(nowOrderUser.getUserId());
|
|
|
orderItems.setCreateDept(order.getCreateDept());
|
|
|
orderItems.setCreateTime(new Date());
|
|
|
orderItems.setPid(order.getId());
|
|
|
- orderItems.setTenantId(AuthUtil.getTenantId());
|
|
|
+ orderItems.setTenantId(nowOrderUser.getTenantId());
|
|
|
orderItems.setBillNo(order.getOrdNo());
|
|
|
orderItems.setBizType(order.getBsType());
|
|
|
orderItems.setInventory(e.getInventory());
|
|
|
@@ -673,7 +652,7 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
for (SharePutOnShelves item : sharePutOnShelvesList) {
|
|
|
item.setInventory(productLaunch.getInventory());
|
|
|
item.setUpdateTime(new Date());
|
|
|
- item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ item.setUpdateUser(nowOrderUser.getUserId());
|
|
|
sharePutOnShelvesMapper.updateSharePutOnShelves(item);
|
|
|
}
|
|
|
pjProductLaunchList.add(productLaunch);
|
|
|
@@ -685,21 +664,18 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
} else {
|
|
|
order.setBillType(billType.get(0));
|
|
|
}
|
|
|
- BigDecimal totalMoney = BigDecimal.ZERO;
|
|
|
- order.setNumberRows(shoppingCartList.size());//行数
|
|
|
+ order.setNumberRows(shoppingCartList.size());
|
|
|
//明细总数量
|
|
|
order.setGoodsTotalNum(shoppingCartList.stream().map(PjShoppingCart::getGoodsNum).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
|
|
|
//明细总金额
|
|
|
- totalMoney = shoppingCartList.stream().reduce(BigDecimal.ZERO, (x, y) -> {
|
|
|
- return x.add(y.getGoodsNum().multiply(y.getPrice()));
|
|
|
- }, BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ BigDecimal totalMoney = shoppingCartList.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getGoodsNum().multiply(y.getPrice())), BigDecimal::add).setScale(2, RoundingMode.HALF_UP);
|
|
|
|
|
|
order.setSalesAmount(totalMoney);
|
|
|
order.setTotalMoney(totalMoney);
|
|
|
|
|
|
if (order.getGoodsTotalNum().compareTo(new BigDecimal(1)) == 0) {
|
|
|
- String freight = sysClient.getParamServiceDWT("freight", finalCorpsDesc.getTenantId());
|
|
|
+ String freight = sysClient.getParamServiceDWT("freight", corpsDesc.getTenantId());
|
|
|
if (ObjectUtils.isNotNull(freight)) {
|
|
|
try {
|
|
|
BigDecimal freightAmount = new BigDecimal(freight);
|
|
|
@@ -716,7 +692,8 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
amount = amount.add(order.getTotalMoney());
|
|
|
order.setPaymentDate(new Date());
|
|
|
- order.setActualPaymentStatus(1);
|
|
|
+ // 额度支付默认已付款
|
|
|
+ order.setActualPaymentStatus(NumberEnum.TWO.number);
|
|
|
order.setPaymentAmountTl(order.getTotalMoney());
|
|
|
order.setStatus(OrderTypeEnum.XSDQR.getType());
|
|
|
order.setXcxStatus(OrderTypeEnum.XSDFH.getType());
|
|
|
@@ -737,10 +714,10 @@ public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, PjS
|
|
|
}
|
|
|
orderService.updateBatchById(pjOrderList);
|
|
|
corpsDescService.updateById(corpsDesc);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String formatted = now.format(formatter);
|
|
|
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(), "客服");
|
|
|
if (clientDeptIds.isSuccess() && StringUtils.isNotBlank(clientDeptIds.getData())) {
|