|
|
@@ -5,10 +5,7 @@ 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.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.GoodsSellDto;
|
|
|
import com.ym.mec.biz.dal.dto.RepairGoodsDto;
|
|
|
@@ -19,6 +16,7 @@ import com.ym.mec.biz.service.*;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.exception.BizException;
|
|
|
import com.ym.mec.common.page.PageInfo;
|
|
|
+import com.ym.mec.common.page.QueryInfo;
|
|
|
import com.ym.mec.common.service.IdGeneratorService;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
|
|
|
@@ -51,7 +49,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
- private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
@Autowired
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
|
@Autowired
|
|
|
@@ -61,15 +59,15 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentDao studentDao;
|
|
|
@Autowired
|
|
|
- private GoodsService goodsService;
|
|
|
- @Autowired
|
|
|
private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
|
@Autowired
|
|
|
private SellOrderService sellOrderService;
|
|
|
@Autowired
|
|
|
- private SellOrderDao sellOrderDao;
|
|
|
+ private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
@Autowired
|
|
|
private ContractService contractService;
|
|
|
+ @Autowired
|
|
|
+ private GoodsService goodsService;
|
|
|
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
@@ -106,12 +104,30 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
|
|
|
@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(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
|
|
|
+ //关闭老订单
|
|
|
+ if(StringUtils.isNotEmpty(studentGoodsSell.getOrderNo())){
|
|
|
+ StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(studentGoodsSell.getOrderNo());
|
|
|
+ if(orderByOrderNo.getBalancePaymentAmount() != null){
|
|
|
+ studentGoodsSell.setIsUseBalancePayment(true);
|
|
|
+ }else {
|
|
|
+ studentGoodsSell.setIsUseBalancePayment(false);
|
|
|
+ }
|
|
|
+ orderByOrderNo.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ studentPaymentOrderService.update(orderByOrderNo);
|
|
|
+ if (orderByOrderNo.getBalancePaymentAmount() != null && orderByOrderNo.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(orderByOrderNo.getUserId(), orderByOrderNo.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
|
|
|
+ }
|
|
|
+ StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
|
|
|
+ if(byOrderNo != null){
|
|
|
+ studentGoodsSell = byOrderNo;
|
|
|
+ studentGoodsSell.setGoodsSellDtos(JSON.parseArray(byOrderNo.getGoodsJson(),GoodsSellDto.class));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer studentId = studentGoodsSell.getUserId();
|
|
|
+ List<GoodsSellDto> goodsSellDtos = studentGoodsSell.getGoodsSellDtos();
|
|
|
+ if(goodsSellDtos == null || goodsSellDtos.size() == 0){
|
|
|
throw new BizException("请选择需要购买的商品");
|
|
|
}
|
|
|
if (studentId == null) {
|
|
|
@@ -119,15 +135,54 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
studentDao.lockUser(studentId);
|
|
|
SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
- String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ //如果教务老师为空,代表学员自己创建的订单
|
|
|
+ if(studentGoodsSell.getTeacherId() == null){
|
|
|
+ //获取学生关联的所有教务老师列表
|
|
|
+ List<Integer> stuEducation = studentRepairDao.countStuEducation(studentId);
|
|
|
+ if (stuEducation != null && stuEducation.size() == 1){
|
|
|
+ //获取学员乐团关联的教务
|
|
|
+ MusicGroup musicGroup = musicGroupDao.getStuMusic(studentId);
|
|
|
+ studentGoodsSell.setTeacherId(stuEducation.get(0));
|
|
|
+ if(musicGroup != null){
|
|
|
+ studentGoodsSell.setCooperationOrganId(musicGroup.getCooperationOrganId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else if(studentGoodsSell.getCooperationOrganId() == null){
|
|
|
+ //获取教务老师,学员关联的乐团
|
|
|
+ MusicGroup musicGroup = musicGroupDao.getStuEduMusic(studentId,studentGoodsSell.getTeacherId());
|
|
|
+ if(musicGroup != null){
|
|
|
+ studentGoodsSell.setCooperationOrganId(musicGroup.getCooperationOrganId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ 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;
|
|
|
- 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));
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentGoodsSell.setOrderNo(orderNo);
|
|
|
+ studentGoodsSellDao.insert(studentGoodsSell);
|
|
|
+
|
|
|
+ if (studentGoodsSell.getType() == 1) {
|
|
|
+ Map<String, Object> repairInfoMap = new HashMap<>();
|
|
|
+ MapUtil.populateMap(repairInfoMap, studentGoodsSell);
|
|
|
+ return repairInfoMap;
|
|
|
}
|
|
|
- List<Goods> goods = goodsService.findGoodsByIds(goodsId);
|
|
|
|
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
studentPaymentOrder.setUserId(studentId);
|
|
|
@@ -141,32 +196,119 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
|
studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
- Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
- List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
|
- for (String id : goodsIds) {
|
|
|
- Goods e = collect.get(id).get(0);
|
|
|
- StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
- studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
|
|
|
- OrderDetailTypeEnum type = null;
|
|
|
- if (e.getType() == GoodsType.INSTRUMENT) {
|
|
|
- type = OrderDetailTypeEnum.MUSICAL;
|
|
|
- } else if (e.getType() == GoodsType.ACCESSORIES) {
|
|
|
- type = OrderDetailTypeEnum.ACCESSORIES;
|
|
|
- } else if (e.getType() == GoodsType.OTHER) {
|
|
|
- type = OrderDetailTypeEnum.TEACHING;
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
|
|
|
+ if (userCashAccount == null) {
|
|
|
+ throw new BizException("用户账户不存在");
|
|
|
+ }
|
|
|
+ if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
|
|
|
+ amount = amount.subtract(balance);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(balance);
|
|
|
+ sysUserCashAccountService.updateBalance(studentId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
|
|
|
+
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, student.getOrganId(), balance);
|
|
|
+ Map<String, String> notifyMap = new HashMap<>();
|
|
|
+ notifyMap.put("tradeState", "1");
|
|
|
+ notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
|
+ studentPaymentOrderService.updateOrder(notifyMap);
|
|
|
+ notifyMap.put("orderNo", orderNo);
|
|
|
+ return notifyMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
|
|
|
+
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ balance,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + orderNo,
|
|
|
+ "商品销售",
|
|
|
+ "商品销售",
|
|
|
+ student.getOrganId(),
|
|
|
+ "goodsSell"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public Map studentPaymentGoodsOrder(Integer goodsSellId) throws Exception {
|
|
|
+ StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
|
|
|
+ Integer studentId = studentGoodsSell.getUserId();
|
|
|
+ studentDao.lockUser(studentId);
|
|
|
+// SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
+ List<GoodsSellDto> goodsSellDtos = JSONObject.parseArray(studentGoodsSell.getGoodsJson(),GoodsSellDto.class);
|
|
|
+ List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ 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;
|
|
|
+ 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("操作失败:订单金额异常");
|
|
|
+ }
|
|
|
+ String orderNo1 = studentGoodsSell.getOrderNo();
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+
|
|
|
+ studentGoodsSell.setOrderNo(orderNo);
|
|
|
+ StudentPaymentOrder studentPaymentOrder = null;
|
|
|
+ if(StringUtils.isNotEmpty(orderNo1)){
|
|
|
+ studentPaymentOrder = studentPaymentOrderService.findOrderByOrderNo(orderNo1);
|
|
|
+ if(studentPaymentOrder != null){
|
|
|
+ if(studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS){
|
|
|
+ throw new BizException("该订单已支付");
|
|
|
+ }
|
|
|
+ //关闭老订单
|
|
|
+ if(studentPaymentOrder.getBalancePaymentAmount() != null){
|
|
|
+ studentGoodsSell.setIsUseBalancePayment(true);
|
|
|
+ }else {
|
|
|
+ studentGoodsSell.setIsUseBalancePayment(false);
|
|
|
+ }
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
|
|
|
+ }
|
|
|
}
|
|
|
- studentPaymentOrderDetail.setType(type);
|
|
|
- studentPaymentOrderDetail.setPrice(e.getGroupPurchasePrice());
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(id);
|
|
|
- studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
- studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
|
- studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
}
|
|
|
- studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+ studentGoodsSellDao.update(studentGoodsSell);
|
|
|
+ studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setUserId(studentId);
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.GOODS_SELL);
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setOrganId(studentGoodsSell.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(studentGoodsSell.getOrganId());
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
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);
|
|
|
if (userCashAccount == null) {
|
|
|
throw new BizException("用户账户不存在");
|
|
|
@@ -183,7 +325,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
|
|
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- studentPaymentRouteOrderService.addRouteOrder(orderNo, student.getOrganId(), balance);
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, studentGoodsSell.getOrganId(), balance);
|
|
|
Map<String, String> notifyMap = new HashMap<>();
|
|
|
notifyMap.put("tradeState", "1");
|
|
|
notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
|
@@ -202,7 +344,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + orderNo,
|
|
|
"商品销售",
|
|
|
"商品销售",
|
|
|
- student.getOrganId(),
|
|
|
+ studentGoodsSell.getOrganId(),
|
|
|
"goodsSell"
|
|
|
);
|
|
|
|
|
|
@@ -509,7 +651,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
- public void goodsSellorderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ public void goodsSellOrderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
//更新订单信息
|
|
|
studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
@@ -524,6 +666,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
map.put(userId, userId.toString());
|
|
|
|
|
|
if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
+ try {
|
|
|
+ contractService.transferProduceContract(userId, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("产品协议生成失败", e);
|
|
|
+ }
|
|
|
//插入交易明细
|
|
|
BigDecimal amount = studentPaymentOrder.getActualAmount();
|
|
|
SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
|
|
|
@@ -537,8 +684,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
|
|
|
rechargeDetail.setUserId(userId);
|
|
|
rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
- rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
|
|
|
- rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
|
|
|
+ if (studentPaymentOrder.getComAmount() != null) {
|
|
|
+ rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
|
|
|
+ rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
|
+ }
|
|
|
sysUserCashAccountDetailService.insert(rechargeDetail);
|
|
|
//缴费
|
|
|
SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
|
|
|
@@ -549,25 +698,139 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
paymentDetail.setType(PlatformCashAccountDetailTypeEnum.GOODS_SELL);
|
|
|
paymentDetail.setUserId(userId);
|
|
|
- rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
- if (studentPaymentOrder.getComAmount() != null) {
|
|
|
- rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
|
|
|
- rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
|
- }
|
|
|
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) {
|
|
|
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, "乐器购买支付失败");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public PageInfo<BasicUserDto> queryEduStudents(QueryInfo queryInfo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ throw new BizException("请登录");
|
|
|
+ }
|
|
|
+ PageInfo<BasicUserDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ MapUtil.populateMap(params, queryInfo);
|
|
|
+ params.put("teacherId",sysUser.getId());
|
|
|
+
|
|
|
+ List<BasicUserDto> dataList = null;
|
|
|
+ int count = studentRepairDao.countEduStudents(params);
|
|
|
+ if (count > 0) {
|
|
|
+ pageInfo.setTotal(count);
|
|
|
+ params.put("offset", pageInfo.getOffset());
|
|
|
+ dataList = studentRepairDao.queryEduStudents(params);
|
|
|
+ }
|
|
|
+ if (count == 0) {
|
|
|
+ dataList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ pageInfo.setRows(dataList);
|
|
|
+ return pageInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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<>();
|
|
|
+ BigDecimal balancePaymentAmount = orderByOrderNo.getBalancePaymentAmount();
|
|
|
+ //可用余额
|
|
|
+ BigDecimal usableBalance = balancePaymentAmount;
|
|
|
+ BigDecimal marketAmount = studentGoodsSell.getMarketAmount();
|
|
|
+ //可用减免金额
|
|
|
+ BigDecimal usableMarketAmount = marketAmount;
|
|
|
+ //包含减免余额的总金额
|
|
|
+ BigDecimal totalAmount = goodsSellDtos.stream().map(e -> e.getTotalGoodsPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ //应付总额
|
|
|
+ BigDecimal totalActual = totalAmount.subtract(marketAmount);
|
|
|
+ //可用应付
|
|
|
+ BigDecimal usableActual = totalActual;
|
|
|
+ //获取实付总额
|
|
|
+ BigDecimal realityAmount = totalActual.subtract(usableBalance);
|
|
|
+ //可用实付总额
|
|
|
+ BigDecimal usableAmount = realityAmount;
|
|
|
+ for (int i = 0; i < goodsId.size(); i++) {
|
|
|
+ Integer e = goodsId.get(i);
|
|
|
+ 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());
|
|
|
+ //获取比例
|
|
|
+ BigDecimal ratioAmount = goodsSellDto.getTotalGoodsPrice().divide(totalAmount, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ //如果有减免金额
|
|
|
+ if(marketAmount.doubleValue() > 0l){
|
|
|
+ //如果是最后一件商品
|
|
|
+ if(i == goodsId.size() - 1){
|
|
|
+ goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(usableMarketAmount));
|
|
|
+ }else {
|
|
|
+ //获取分配的减免金额
|
|
|
+ BigDecimal multiply = ratioAmount.multiply(usableMarketAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ goodsSellDto.setTotalGoodsPrice(goodsSellDto.getTotalGoodsPrice().subtract(multiply));
|
|
|
+ usableMarketAmount = usableMarketAmount.subtract(multiply);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果没有使用余额,那么实际金额和预计金额一致
|
|
|
+ if(balancePaymentAmount.doubleValue() == 0l){
|
|
|
+ sellOrder.setActualAmount(goodsSellDto.getTotalGoodsPrice());
|
|
|
+ sellOrder.setBalanceAmount(BigDecimal.ZERO);
|
|
|
+ }else {
|
|
|
+ //如果是最后一件商品
|
|
|
+ if(i == goodsId.size() - 1){
|
|
|
+ sellOrder.setActualAmount(usableAmount);
|
|
|
+ sellOrder.setBalanceAmount(usableBalance);
|
|
|
+ }else {
|
|
|
+ //获取分配的余额
|
|
|
+ BigDecimal multiply = ratioAmount.multiply(balancePaymentAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ //分配的实际支付
|
|
|
+ BigDecimal multiply1 = ratioAmount.multiply(realityAmount).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
|
+ sellOrder.setActualAmount(multiply1);
|
|
|
+ sellOrder.setBalanceAmount(multiply);
|
|
|
+ usableAmount = usableAmount.subtract(multiply1);
|
|
|
+ usableBalance = usableBalance.subtract(multiply);
|
|
|
+ usableActual = usableActual.subtract(multiply1).subtract(multiply);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sellOrder.setExpectAmount(sellOrder.getActualAmount().add(sellOrder.getBalanceAmount()));
|
|
|
+ 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());
|
|
|
+ sellOrder.setEduTeacherId(studentGoodsSell.getTeacherId());
|
|
|
+ sellOrder.setCooperationOrganId(studentGoodsSell.getCooperationOrganId());
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
+ }
|
|
|
+ if(sellOrders.size() > 0){
|
|
|
+ sellOrderService.batchInsert(sellOrders);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
@@ -592,12 +855,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
map.put(userId, userId.toString());
|
|
|
|
|
|
if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
- if(repairInfo.getType()==1){
|
|
|
- try {
|
|
|
- contractService.transferProduceContract(userId, null);
|
|
|
- } catch (Exception e) {
|
|
|
- logger.error("产品协议生成失败", e);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ contractService.transferProduceContract(userId, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("产品协议生成失败", e);
|
|
|
}
|
|
|
|
|
|
repairInfo.setPayStatus(2);
|