|
@@ -1,18 +1,88 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import static com.ym.mec.biz.dal.enums.CouponDetailTypeEnum.ACCESSORIES;
|
|
|
+import static com.ym.mec.biz.dal.enums.CouponDetailTypeEnum.MUSICAL;
|
|
|
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.CLOSE;
|
|
|
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.ING;
|
|
|
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsProcurementDao;
|
|
|
+import com.ym.mec.biz.dal.dao.MusicGroupDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
|
import com.ym.mec.biz.dal.dto.RepairGoodsDto;
|
|
|
-import com.ym.mec.biz.dal.entity.*;
|
|
|
-import com.ym.mec.biz.dal.enums.*;
|
|
|
+import com.ym.mec.biz.dal.entity.Goods;
|
|
|
+import com.ym.mec.biz.dal.entity.GoodsProcurement;
|
|
|
+import com.ym.mec.biz.dal.entity.MusicGroup;
|
|
|
+import com.ym.mec.biz.dal.entity.SellOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentGoodsSell;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentInstrument;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentRepair;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
|
|
|
+import com.ym.mec.biz.dal.enums.AccountType;
|
|
|
+import com.ym.mec.biz.dal.enums.CouponDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
+import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
+import com.ym.mec.biz.dal.enums.MessageTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.PayStatus;
|
|
|
+import com.ym.mec.biz.dal.enums.PaymentChannelEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.SellTypeEnum;
|
|
|
import com.ym.mec.biz.dal.page.RepairStudentQueryInfo;
|
|
|
-import com.ym.mec.biz.service.*;
|
|
|
+import com.ym.mec.biz.service.ContractService;
|
|
|
+import com.ym.mec.biz.service.GoodsService;
|
|
|
+import com.ym.mec.biz.service.PayService;
|
|
|
+import com.ym.mec.biz.service.SellOrderService;
|
|
|
+import com.ym.mec.biz.service.StudentGoodsSellService;
|
|
|
+import com.ym.mec.biz.service.StudentInstrumentService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentOrderService;
|
|
|
+import com.ym.mec.biz.service.StudentPaymentRouteOrderService;
|
|
|
+import com.ym.mec.biz.service.StudentRepairService;
|
|
|
+import com.ym.mec.biz.service.SysConfigService;
|
|
|
+import com.ym.mec.biz.service.SysCouponCodeService;
|
|
|
+import com.ym.mec.biz.service.SysMessageService;
|
|
|
+import com.ym.mec.biz.service.SysPaymentConfigService;
|
|
|
+import com.ym.mec.biz.service.SysUserCashAccountDetailService;
|
|
|
+import com.ym.mec.biz.service.SysUserCashAccountService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
@@ -21,22 +91,6 @@ import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
|
-import org.apache.commons.collections.CollectionUtils;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Isolation;
|
|
|
-import org.springframework.transaction.annotation.Propagation;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import static com.ym.mec.biz.dal.enums.CouponDetailTypeEnum.*;
|
|
|
-import static com.ym.mec.biz.dal.enums.DealStatusEnum.*;
|
|
|
|
|
|
@Service
|
|
|
public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRepair> implements StudentRepairService {
|
|
@@ -54,6 +108,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
+ private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
+ @Autowired
|
|
|
private SysPaymentConfigService sysPaymentConfigService;
|
|
|
@Autowired
|
|
|
private MusicGroupDao musicGroupDao;
|
|
@@ -72,6 +128,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
@Autowired
|
|
|
+ private GoodsProcurementDao goodsProcurementDao;
|
|
|
+ @Autowired
|
|
|
private ContractService contractService;
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
@@ -149,6 +207,54 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
//退优惠券
|
|
|
sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
|
|
|
+
|
|
|
+ Date nowDate = new Date();
|
|
|
+ //增加商品库存
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(orderByOrderNo.getId());
|
|
|
+ String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
+ if(StringUtils.isNotBlank(goodsIds)){
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
+
|
|
|
+ // 进货清单
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
+ goodsProcurement.setUpdateTime(nowDate);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
|
|
|
if (byOrderNo != null) {
|
|
@@ -199,11 +305,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
goodsSellDto.setGoodsGroupPrice(groupPriceMap.get(goodsSellDto.getGoodsId()));
|
|
|
goodsSellDto.setTotalGoodsPrice(map.get(goodsSellDto.getGoodsId()).multiply(new BigDecimal(goodsSellDto.getGoodsNum())));
|
|
|
}
|
|
|
- Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+ Map<Integer, List<GoodsSellDto>> goodsSellDtoMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
BigDecimal groupAmount = BigDecimal.ZERO;
|
|
|
for (Integer id : goodsIds) {
|
|
|
- GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
|
|
|
+ GoodsSellDto goodsSellDto = goodsSellDtoMap.get(id).get(0);
|
|
|
amount = amount.add(goodsSellDto.getTotalGoodsPrice());
|
|
|
groupAmount = groupAmount.add(goodsSellDto.getGoodsGroupPrice());
|
|
|
}
|
|
@@ -252,6 +358,75 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
|
studentPaymentOrder.setTenantId(student.getTenantId());
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ //添加订单详情
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
+ // 添加studentPaymentOrderDetail
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = null;
|
|
|
+
|
|
|
+ BigDecimal totalPrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ if(goodsSellDtos != null){
|
|
|
+ //String goodsIdsStr = goodsSellDtos.stream().map(t -> t.getGoodsId().toString()).collect(Collectors.joining(","));
|
|
|
+
|
|
|
+ StringBuffer sb = new StringBuffer();
|
|
|
+ for(GoodsSellDto goodsSellDto : goodsSellDtos){
|
|
|
+ for(int i = 0; i < goodsSellDto.getGoodsNum() ; i++){
|
|
|
+ sb.append(goodsSellDto.getGoodsId()).append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String goodsIdsStr = StringUtils.removeEnd(sb.toString(), ",");
|
|
|
+
|
|
|
+ List<Goods> goodsList = goodsService.findGoodsByIds(goodsIdsStr);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIdsStr.split(",")){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goodsMap.get(Integer.parseInt(goodsIdStr)).getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ Goods goods = null;
|
|
|
+ for(String goodsIdStr : goodsIdsStr.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIdsStr.split(",").length == studentPaymentOrderDetailList.size() + 1){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ }
|
|
|
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
@@ -455,9 +630,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
repairInfo.setPayStatus(0);
|
|
|
repairInfo.setCreateTime(date);
|
|
|
repairInfo.setUpdateTime(date);
|
|
|
+
|
|
|
+ List<RepairGoodsDto> repairGoodsDtos = null;
|
|
|
+
|
|
|
String goodsJson = repairInfo.getGoodsJson();
|
|
|
if (StringUtils.isNotEmpty(goodsJson)) {
|
|
|
- List<RepairGoodsDto> repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
+ repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
List<Integer> goodsIds = repairGoodsDtos.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
Map<Integer, BigDecimal> map = getMap("goods", "id_", "discount_price_", goodsIds,student.getTenantId(), Integer.class, BigDecimal.class);
|
|
|
repairGoodsDtos.forEach(e -> {
|
|
@@ -466,6 +644,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
repairInfo.setGoodsJson(JSONObject.toJSONString(repairGoodsDtos));
|
|
|
}
|
|
|
|
|
|
+ BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
|
if (StringUtils.isNoneBlank(repairInfo.getGoodsJson())) {
|
|
|
JSONArray goods = JSON.parseArray(repairInfo.getGoodsJson());
|
|
|
for (Object good : goods) {
|
|
@@ -473,6 +652,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
BigDecimal groupPurchasePrice = goodObject.getBigDecimal("groupPurchasePrice");
|
|
|
if (Objects.nonNull(groupPurchasePrice)) {
|
|
|
amount = amount.add(groupPurchasePrice);
|
|
|
+ goodsPrice = goodsPrice.add(groupPurchasePrice);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -509,6 +689,78 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
+ // 添加studentPaymentOrderDetail
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.REPAIR);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(null);
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().multiply(repairInfo.getAmount()).divide(goodsPrice.add(repairInfo.getAmount()), RoundingMode.UP));
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+
|
|
|
+ BigDecimal totalPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+ BigDecimal repairPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(repairInfo.getGoodsJson()) && repairGoodsDtos != null){
|
|
|
+ String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
+ List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIds.split(",").length == studentPaymentOrderDetailList.size()){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ }
|
|
|
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
if (repairInfo.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -629,18 +881,32 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
) {
|
|
|
throw new BizException("邮寄信息必填");
|
|
|
}
|
|
|
+
|
|
|
+ List<RepairGoodsDto> repairGoodsDtos = null;
|
|
|
Date date = new Date();
|
|
|
StudentRepair studentRepair = studentRepairDao.get(repairInfo.getId());
|
|
|
studentDao.lockUser(studentRepair.getStudentId());
|
|
|
BigDecimal amount = studentRepair.getAmount();
|
|
|
String goodsJson = studentRepair.getGoodsJson();
|
|
|
if (StringUtils.isNotEmpty(goodsJson)) {
|
|
|
- List<RepairGoodsDto> repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
+ repairGoodsDtos = JSONObject.parseArray(goodsJson, RepairGoodsDto.class);
|
|
|
BigDecimal reduce = repairGoodsDtos.stream().map(e -> e.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
amount = amount.add(reduce);
|
|
|
}
|
|
|
amount = amount.subtract(studentRepair.getExemptionAmount());
|
|
|
|
|
|
+ BigDecimal goodsPrice = BigDecimal.ZERO;
|
|
|
+ if (StringUtils.isNoneBlank(goodsJson)) {
|
|
|
+ JSONArray goods = JSON.parseArray(goodsJson);
|
|
|
+ for (Object good : goods) {
|
|
|
+ JSONObject goodObject = (JSONObject) good;
|
|
|
+ BigDecimal groupPurchasePrice = goodObject.getBigDecimal("groupPurchasePrice");
|
|
|
+ if (Objects.nonNull(groupPurchasePrice)) {
|
|
|
+ goodsPrice = goodsPrice.add(groupPurchasePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
studentRepair.setUseBalancePayment(repairInfo.getUseBalancePayment());
|
|
|
studentRepair.setTransNo(orderNo);
|
|
@@ -673,6 +939,77 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
|
|
|
+ // 添加studentPaymentOrderDetail
|
|
|
+ StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.REPAIR);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(null);
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().multiply(studentRepair.getAmount()).divide(goodsPrice.add(studentRepair.getAmount()), RoundingMode.UP));
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+
|
|
|
+ BigDecimal totalPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+ BigDecimal repairPrice = studentPaymentOrderDetail.getPrice();
|
|
|
+
|
|
|
+ if(StringUtils.isNotBlank(studentRepair.getGoodsJson()) && repairGoodsDtos != null){
|
|
|
+ String goodsIds = repairGoodsDtos.stream().map(t -> t.getId().toString()).collect(Collectors.joining(","));
|
|
|
+ List<Goods> goodsList = goodsService.findGoodsByIds(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ BigDecimal totalGroupPurchasePrice = BigDecimal.ZERO;
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ totalGroupPurchasePrice = totalGroupPurchasePrice.add(goods.getGroupPurchasePrice());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+
|
|
|
+ if(goods != null){
|
|
|
+ studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
+ studentPaymentOrderDetail.setCreateTime(date);
|
|
|
+ if(goods.getType() == GoodsType.INSTRUMENT){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.MUSICAL);
|
|
|
+ }else if(goods.getType() == GoodsType.ACCESSORIES){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.ACCESSORIES);
|
|
|
+ }else if(goods.getType() == GoodsType.TEACHING || goods.getType() == GoodsType.STAFF){
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.TEACHING);
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setType(OrderDetailTypeEnum.OTHER);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(goodsIdStr);
|
|
|
+
|
|
|
+ BigDecimal tempPrice = studentPaymentOrder.getExpectAmount().subtract(repairPrice).multiply(goods.getGroupPurchasePrice()).divide(totalGroupPurchasePrice, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+
|
|
|
+ if(totalPrice.add(tempPrice).compareTo(studentPaymentOrder.getExpectAmount()) > 0 || goodsIds.split(",").length == studentPaymentOrderDetailList.size()){
|
|
|
+ studentPaymentOrderDetail.setPrice(studentPaymentOrder.getExpectAmount().subtract(totalPrice));
|
|
|
+ }else{
|
|
|
+ studentPaymentOrderDetail.setPrice(tempPrice);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setUpdateTime(date);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+
|
|
|
+ totalPrice = totalPrice.add(studentPaymentOrderDetail.getPrice());
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(studentPaymentOrderDetailList.size() > 0){
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ }
|
|
|
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
if (studentRepair.getUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
@@ -794,7 +1131,55 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
//购买的商品加入销售列表
|
|
|
saveSellOrder(studentPaymentOrder.getOrderNo());
|
|
|
} else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
- if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+
|
|
|
+ //增加商品库存
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
|
|
|
+ String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
+ if(StringUtils.isNotBlank(goodsIds)){
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
+
|
|
|
+ // 进货清单
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
+ goodsProcurement.setUpdateTime(nowDate);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器购买支付失败");
|
|
|
}
|
|
|
sysCouponCodeService.quit(studentPaymentOrder.getCouponCodeId());
|
|
@@ -1173,6 +1558,54 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
if (this.update(repairInfo) <= 0) {
|
|
|
throw new BizException("维修单更新失败");
|
|
|
}
|
|
|
+
|
|
|
+ //增加商品库存
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailService.queryOrderDetail(studentPaymentOrder.getId());
|
|
|
+ String goodsIds = studentPaymentOrderDetailList.stream().filter(t -> StringUtils.isNotBlank(t.getMinuendStockGoodsIdList())).map(t -> t.getMinuendStockGoodsIdList()).collect(Collectors.joining(","));
|
|
|
+ if(StringUtils.isNotBlank(goodsIds)){
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ List<Goods> goodsList = goodsService.getGoodsWithLocked(goodsIds);
|
|
|
+ Map<Integer,Goods> goodsMap = goodsList.stream().collect(Collectors.toMap(Goods :: getId, t -> t));
|
|
|
+ Goods goods = null;
|
|
|
+ Map<Integer, Goods> batchUpdateGoodsMap = new HashMap<Integer, Goods>();
|
|
|
+ Map<Long, GoodsProcurement> goodsProcurementMap = new HashMap<Long, GoodsProcurement>();
|
|
|
+
|
|
|
+ for(String goodsIdStr : goodsIds.split(",")){
|
|
|
+ if(StringUtils.isBlank(goodsIdStr)){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ goods = goodsMap.get(Integer.parseInt(goodsIdStr));
|
|
|
+ if(batchUpdateGoodsMap.get(goods.getId()) != null){
|
|
|
+ goods = batchUpdateGoodsMap.get(goods.getId());
|
|
|
+ }
|
|
|
+ goods.setStockCount(new AtomicInteger(goods.getStockCount()).incrementAndGet());
|
|
|
+ goods.setSellCount(new AtomicInteger(goods.getSellCount()).decrementAndGet());
|
|
|
+ goods.setUpdateTime(nowDate);
|
|
|
+
|
|
|
+ batchUpdateGoodsMap.put(goods.getId(), goods);
|
|
|
+
|
|
|
+ // 进货清单
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ if(goodsProcurement != null){
|
|
|
+ if(goodsProcurementMap.get(goodsProcurement.getId()) != null){
|
|
|
+ goodsProcurement = goodsProcurementMap.get(goodsProcurement.getId());
|
|
|
+ }
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).decrementAndGet());
|
|
|
+ goodsProcurement.setUpdateTime(nowDate);
|
|
|
+ goodsProcurementMap.put(goodsProcurement.getId(), goodsProcurement);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(goodsProcurementMap.size() > 0){
|
|
|
+ goodsProcurementDao.batchUpdate(new ArrayList<GoodsProcurement>(goodsProcurementMap.values()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if(batchUpdateGoodsMap.size() > 0){
|
|
|
+ goodsService.batchUpdate(new ArrayList<Goods>(batchUpdateGoodsMap.values()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
|
|
|
}
|