|
@@ -5,10 +5,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
-import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
|
-import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
|
-import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
|
|
-import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
import com.ym.mec.biz.dal.dto.GoodsSellDto;
|
|
import com.ym.mec.biz.dal.dto.RepairGoodsDto;
|
|
import com.ym.mec.biz.dal.dto.RepairGoodsDto;
|
|
@@ -28,6 +25,7 @@ import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Isolation;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -51,7 +49,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
@Autowired
|
|
@Autowired
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
- private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -61,15 +59,15 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
@Autowired
|
|
@Autowired
|
|
private StudentDao studentDao;
|
|
private StudentDao studentDao;
|
|
@Autowired
|
|
@Autowired
|
|
- private GoodsService goodsService;
|
|
|
|
- @Autowired
|
|
|
|
private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
private SellOrderService sellOrderService;
|
|
private SellOrderService sellOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
- private SellOrderDao sellOrderDao;
|
|
|
|
|
|
+ private StudentGoodsSellDao studentGoodsSellDao;
|
|
@Autowired
|
|
@Autowired
|
|
private ContractService contractService;
|
|
private ContractService contractService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private GoodsService goodsService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
@@ -106,12 +104,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
- public Map addGoodsSellOrder(GoodsSellDto goodsSellDto) throws Exception {
|
|
|
|
- SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
|
- Integer studentId = sysUser.getId();
|
|
|
|
- String goodsId = goodsSellDto.getGoodsId();
|
|
|
|
- if (StringUtils.isEmpty(goodsId)) {
|
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
|
+ public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
|
|
|
|
+ Integer studentId = studentGoodsSell.getUserId();
|
|
|
|
+ List<GoodsSellDto> goodsSellDtos = studentGoodsSell.getGoodsSellDtos();
|
|
|
|
+ if(goodsSellDtos == null || goodsSellDtos.size() == 0){
|
|
throw new BizException("请选择需要购买的商品");
|
|
throw new BizException("请选择需要购买的商品");
|
|
}
|
|
}
|
|
if (studentId == null) {
|
|
if (studentId == null) {
|
|
@@ -120,14 +117,45 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
studentDao.lockUser(studentId);
|
|
studentDao.lockUser(studentId);
|
|
SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
|
+ studentGoodsSell.setOrderNo(orderNo);
|
|
|
|
+ if(studentGoodsSell.getTeacherId() == null){
|
|
|
|
+ //获取学员第一个教务老师
|
|
|
|
+ studentGoodsSell.setTeacherId(musicGroupDao.getFirstEduTeacherId(studentGoodsSell.getUserId()));
|
|
|
|
+ }
|
|
|
|
+ List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
|
|
|
- String[] goodsIds = goodsId.split(",");
|
|
|
|
- Map<String, BigDecimal> map = getMap("goods", "id_", "group_purchase_price_", goodsId, String.class, BigDecimal.class);
|
|
|
|
|
|
+// String[] goodsIds = goodsJson.split(",");
|
|
|
|
+ Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
|
+ for (GoodsSellDto goodsSellDto : goodsSellDtos) {
|
|
|
|
+ goodsSellDto.setGoodsPrice(map.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));
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
- for (String id : goodsIds) {
|
|
|
|
- amount.add(map.get(id));
|
|
|
|
|
|
+ for (Integer id : goodsIds) {
|
|
|
|
+ GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
|
|
|
|
+ amount = amount.add(goodsSellDto.getTotalGoodsPrice());
|
|
|
|
+ }
|
|
|
|
+ amount = amount.subtract(studentGoodsSell.getMarketAmount());
|
|
|
|
+ if(amount.signum() < 0){
|
|
|
|
+ throw new BizException("操作失败:订单金额异常");
|
|
|
|
+ }
|
|
|
|
+ studentGoodsSell.setOrganId(student.getOrganId());
|
|
|
|
+ studentGoodsSell.setTotalAmount(amount);
|
|
|
|
+ studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
|
|
|
|
+ if(studentGoodsSell.getId() == null){
|
|
|
|
+ studentGoodsSellDao.insert(studentGoodsSell);
|
|
|
|
+ }else {
|
|
|
|
+ studentGoodsSellDao.update(studentGoodsSell);
|
|
}
|
|
}
|
|
- List<Goods> goods = goodsService.findGoodsByIds(goodsId);
|
|
|
|
|
|
+
|
|
|
|
+ if (studentGoodsSell.getType() == 1) {
|
|
|
|
+ Map<String, Object> repairInfoMap = new HashMap<>();
|
|
|
|
+ MapUtil.populateMap(repairInfoMap, studentGoodsSell);
|
|
|
|
+ return repairInfoMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
|
|
|
|
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
studentPaymentOrder.setUserId(studentId);
|
|
studentPaymentOrder.setUserId(studentId);
|
|
@@ -141,7 +169,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
- Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
|
|
|
+ /*Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
for (String id : goodsIds) {
|
|
for (String id : goodsIds) {
|
|
Goods e = collect.get(id).get(0);
|
|
Goods e = collect.get(id).get(0);
|
|
@@ -162,11 +190,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
}
|
|
}
|
|
- studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);*/
|
|
|
|
|
|
studentPaymentOrder.setVersion(0);
|
|
studentPaymentOrder.setVersion(0);
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
- if (goodsSellDto.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
|
+ if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
|
|
SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
|
|
if (userCashAccount == null) {
|
|
if (userCashAccount == null) {
|
|
throw new BizException("用户账户不存在");
|
|
throw new BizException("用户账户不存在");
|
|
@@ -509,7 +537,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
- public void goodsSellorderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
|
|
|
+ public void goodsSellOrderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
Date nowDate = new Date();
|
|
Date nowDate = new Date();
|
|
//更新订单信息
|
|
//更新订单信息
|
|
studentPaymentOrder.setUpdateTime(nowDate);
|
|
studentPaymentOrder.setUpdateTime(nowDate);
|
|
@@ -555,11 +583,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
}
|
|
}
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
- //销售订单详情
|
|
|
|
- List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderDetail(studentPaymentOrder.getId());
|
|
|
|
- if (orderDetails.size() > 0) {
|
|
|
|
- sellOrderService.addOrderDetail2SellOrder(orderDetails, studentPaymentOrder, null);
|
|
|
|
- }
|
|
|
|
|
|
+ saveSellOrder(studentPaymentOrder.getOrderNo());
|
|
} else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
} else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
|
|
sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器维修支付失败");
|
|
@@ -567,6 +591,50 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void saveSellOrder(String orderNo){
|
|
|
|
+ StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(orderNo);
|
|
|
|
+ StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(orderNo);
|
|
|
|
+ String goodsJson = studentGoodsSell.getGoodsJson();
|
|
|
|
+ List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(goodsJson, GoodsSellDto.class);
|
|
|
|
+ Map<Integer, List<GoodsSellDto>> collect = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
|
+ List<Integer> goodsId = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
|
+ List<Goods> goodsByIds = goodsService.findGoodsByIds(StringUtils.join(goodsId, ","));
|
|
|
|
+ Map<Integer, List<Goods>> goodsMap = goodsByIds.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
|
+ Map<String, BigDecimal> costMap = new HashMap<>(2);
|
|
|
|
+ List<SellOrder> sellOrders = new ArrayList<>();
|
|
|
|
+ goodsId.forEach(e->{
|
|
|
|
+ GoodsSellDto goodsSellDto = collect.get(e).get(0);
|
|
|
|
+ Goods goods = goodsMap.get(e).get(0);
|
|
|
|
+
|
|
|
|
+ costMap.put("sellCost", goods.getDiscountPrice());
|
|
|
|
+ if (goods.getAgreeCostPrice() != null) {
|
|
|
|
+ costMap.put("SellCost2", goods.getAgreeCostPrice());
|
|
|
|
+ }
|
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
|
+ sellOrder.setOrganId(orderByOrderNo.getOrganId());
|
|
|
|
+ sellOrder.setTransNo(orderByOrderNo.getTransNo());
|
|
|
|
+ sellOrder.setOrderId(orderByOrderNo.getId());
|
|
|
|
+ sellOrder.setOrderNo(orderByOrderNo.getOrderNo());
|
|
|
|
+ sellOrder.setExpectAmount(orderByOrderNo.getExpectAmount());
|
|
|
|
+ sellOrder.setActualAmount(orderByOrderNo.getActualAmount());
|
|
|
|
+ sellOrder.setBalanceAmount(orderByOrderNo.getBalancePaymentAmount());
|
|
|
|
+ sellOrder.setSellCost(goods.getDiscountPrice());
|
|
|
|
+ sellOrder.setSellCost2(JSONObject.toJSONString(costMap));
|
|
|
|
+ sellOrder.setType(SellTypeEnum.valueOf(goods.getType().getCode()));
|
|
|
|
+ sellOrder.setGoodsId(e);
|
|
|
|
+ sellOrder.setGoodsName(goods.getName());
|
|
|
|
+ sellOrder.setNum(goodsSellDto.getGoodsNum());
|
|
|
|
+ sellOrder.setUserId(studentGoodsSell.getUserId());
|
|
|
|
+ sellOrder.setPaymentChannel(orderByOrderNo.getPaymentChannel());
|
|
|
|
+ sellOrder.setMerNo(orderByOrderNo.getMerNos());
|
|
|
|
+ sellOrder.setSellTime(orderByOrderNo.getPayTime());
|
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
|
+ });
|
|
|
|
+ if(sellOrders.size() > 0){
|
|
|
|
+ sellOrderService.batchInsert(sellOrders);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|