|
@@ -1,11 +1,17 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+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.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.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.page.RepairStudentQueryInfo;
|
|
@@ -17,6 +23,7 @@ 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.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -44,6 +51,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
+ private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
+ @Autowired
|
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
|
@Autowired
|
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
@@ -52,7 +61,13 @@ 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;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, StudentRepair> getDAO() {
|
|
@@ -88,6 +103,113 @@ 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)) {
|
|
|
+ throw new BizException("请选择需要购买的商品");
|
|
|
+ }
|
|
|
+ if (studentId == null) {
|
|
|
+ throw new BizException("请指定学员");
|
|
|
+ }
|
|
|
+ studentDao.lockUser(studentId);
|
|
|
+ SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+
|
|
|
+ String[] goodsIds = goodsId.split(",");
|
|
|
+ Map<String, BigDecimal> map = getMap("goods", "id_", "group_purchase_price_", goodsId, String.class, BigDecimal.class);
|
|
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
+ for (String id : goodsIds) {
|
|
|
+ amount.add(map.get(id));
|
|
|
+ }
|
|
|
+ List<Goods> goods = goodsService.findGoodsByIds(goodsId);
|
|
|
+
|
|
|
+ StudentPaymentOrder 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(student.getOrganId());
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetail.setType(type);
|
|
|
+ studentPaymentOrderDetail.setPrice(e.getGroupPurchasePrice());
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(id);
|
|
|
+ studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
+ studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
|
+ studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
|
+ }
|
|
|
+ studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
|
|
|
+
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ if (goodsSellDto.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(rollbackFor = Exception.class)
|
|
|
public Map addRepair(StudentRepair repairInfo) throws Exception {
|
|
|
studentDao.lockUser(repairInfo.getEmployeeId());
|
|
|
if (repairInfo.getSendType() != null && repairInfo.getSendType().equals(1) &&
|
|
@@ -108,12 +230,34 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
repairInfo.setPayStatus(0);
|
|
|
repairInfo.setCreateTime(date);
|
|
|
repairInfo.setUpdateTime(date);
|
|
|
+ String goodsJson = repairInfo.getGoodsJson();
|
|
|
+ if (StringUtils.isNotEmpty(goodsJson)) {
|
|
|
+ List<RepairGoodsDto> 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_", "group_purchase_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
+ repairGoodsDtos.forEach(e -> {
|
|
|
+ e.setGroupPurchasePrice(map.get(e.getId()));
|
|
|
+ });
|
|
|
+ repairInfo.setGoodsJson(JSONObject.toJSONString(repairGoodsDtos));
|
|
|
+ }
|
|
|
studentRepairDao.insert(repairInfo);
|
|
|
if (repairInfo.getType() == 1) {
|
|
|
Map<String, Object> repairInfoMap = new HashMap<>();
|
|
|
MapUtil.populateMap(repairInfoMap, repairInfo);
|
|
|
return repairInfoMap;
|
|
|
}
|
|
|
+
|
|
|
+ if (StringUtils.isNoneBlank(repairInfo.getGoodsJson())) {
|
|
|
+ JSONArray goods = JSON.parseArray(repairInfo.getGoodsJson());
|
|
|
+ for (Object good : goods) {
|
|
|
+ JSONObject goodObject = (JSONObject) good;
|
|
|
+ BigDecimal groupPurchasePrice = goodObject.getBigDecimal("groupPurchasePrice");
|
|
|
+ if (Objects.nonNull(groupPurchasePrice)) {
|
|
|
+ amount = amount.add(groupPurchasePrice);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
repairInfo.setPayStatus(1);
|
|
|
String channelType = "";
|
|
|
|
|
@@ -257,6 +401,12 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
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);
|
|
|
+ BigDecimal reduce = repairGoodsDtos.stream().map(e -> e.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ amount = amount.add(reduce);
|
|
|
+ }
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
studentRepair.setIsUseBalancePayment(repairInfo.getIsUseBalancePayment());
|
|
|
studentRepair.setTransNo(orderNo);
|
|
@@ -355,6 +505,66 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
+ public void goodsSellorderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ //更新订单信息
|
|
|
+ studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
+ int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ if (updateCount <= 0) {
|
|
|
+ throw new BizException("订单更新失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = studentPaymentOrder.getUserId();
|
|
|
+
|
|
|
+ Map<Integer, String> map = new HashMap<>();
|
|
|
+ map.put(userId, userId.toString());
|
|
|
+
|
|
|
+ if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
+ //插入交易明细
|
|
|
+ BigDecimal amount = studentPaymentOrder.getActualAmount();
|
|
|
+ SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
|
|
|
+ //充值
|
|
|
+ SysUserCashAccountDetail rechargeDetail = new SysUserCashAccountDetail();
|
|
|
+ rechargeDetail.setAmount(amount);
|
|
|
+ rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
|
|
|
+ rechargeDetail.setComment("缴费前充值");
|
|
|
+ rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
+ rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
|
|
|
+ rechargeDetail.setUserId(userId);
|
|
|
+ rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
|
|
|
+ rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
|
|
|
+ sysUserCashAccountDetailService.insert(rechargeDetail);
|
|
|
+ //缴费
|
|
|
+ SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
|
|
|
+ paymentDetail.setAmount(amount.negate());
|
|
|
+ paymentDetail.setBalance(cashAccount.getBalance());
|
|
|
+ paymentDetail.setComment("商品销售");
|
|
|
+ paymentDetail.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ } 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, "乐器维修支付失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
Date nowDate = new Date();
|
|
|
//更新订单信息
|
|
@@ -368,13 +578,13 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
if (repairInfo == null) {
|
|
|
throw new BizException("维修单不存在");
|
|
|
}
|
|
|
- if(repairInfo.getPayStatus().equals(2)){
|
|
|
+ if (repairInfo.getPayStatus().equals(2)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
Integer userId = studentPaymentOrder.getUserId();
|
|
|
|
|
|
- Map<Integer, String> map = new HashMap();
|
|
|
+ Map<Integer, String> map = new HashMap<>();
|
|
|
map.put(userId, userId.toString());
|
|
|
|
|
|
if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
@@ -420,6 +630,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
|
}
|
|
|
sysUserCashAccountDetailService.insert(paymentDetail);
|
|
|
+ //生成销售订单
|
|
|
+ if (StringUtils.isNotBlank(repairInfo.getGoodsJson())) {
|
|
|
+ List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
|
|
|
+ List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
|
|
|
+ if (goodsIds.size() > 0) {
|
|
|
+ sellOrderService.addSellOrder(studentPaymentOrder.getId(), repairInfo.getMusicGroupId(), goodsIds, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
String imContent = repairInfo.getStudentName() + "学员您好,您的乐器维修已受理,我们会尽快完成保养维修";
|
|
|
|