|
@@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.dao.StudentDao;
|
|
import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
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.RepairGoodsDto;
|
|
import com.ym.mec.biz.dal.dto.RepairGoodsDto;
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
import com.ym.mec.biz.dal.entity.*;
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
import com.ym.mec.biz.dal.enums.*;
|
|
@@ -49,6 +50,8 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
@Autowired
|
|
@Autowired
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
|
|
|
|
+ @Autowired
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
private SysUserCashAccountService sysUserCashAccountService;
|
|
@Autowired
|
|
@Autowired
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
private SysUserCashAccountDetailService sysUserCashAccountDetailService;
|
|
@@ -57,6 +60,8 @@ 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;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -93,6 +98,110 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
+ public Map addGoodsSellOrder(GoodsSellDto goodsSellDto) throws Exception {
|
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
|
+ if (sysUser == null) {
|
|
|
|
+ throw new BizException("请登录");
|
|
|
|
+ }
|
|
|
|
+ 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") + "";
|
|
|
|
+ List<Goods> goods = goodsService.findGoodsByIds(goodsId);
|
|
|
|
+ BigDecimal amount = goods.stream().map(e -> e.getGroupPurchasePrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+
|
|
|
|
+ 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<GoodsType, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getType));
|
|
|
|
+ List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
|
|
+ goods.forEach(e->{
|
|
|
|
+ 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());
|
|
|
|
+ String join = StringUtils.join(collect.get(e.getType()).stream().map(g -> g.getId()).collect(Collectors.toList()), ",");
|
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(join);
|
|
|
|
+ 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 {
|
|
public Map addRepair(StudentRepair repairInfo) throws Exception {
|
|
studentDao.lockUser(repairInfo.getEmployeeId());
|
|
studentDao.lockUser(repairInfo.getEmployeeId());
|
|
if (repairInfo.getSendType() != null && repairInfo.getSendType().equals(1) &&
|
|
if (repairInfo.getSendType() != null && repairInfo.getSendType().equals(1) &&
|
|
@@ -388,6 +497,61 @@ 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) {
|
|
|
|
+ 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);
|
|
|
|
+ }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) {
|
|
public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
Date nowDate = new Date();
|
|
Date nowDate = new Date();
|
|
//更新订单信息
|
|
//更新订单信息
|