zouxuan 4 سال پیش
والد
کامیت
0f01c83494

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentRepairService.java

@@ -79,6 +79,17 @@ public interface StudentRepairService extends BaseService<Integer, StudentRepair
     Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception;
     Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception;
 
 
     /**
     /**
+     * @describe 学员扫码支付
+     * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
+     * @author zouxuan
+     * @date 2020/9/16
+     * @time 13:47
+     * @param goodsSellId:
+     * @return java.util.Map
+     */
+    Map studentPaymentGoodsOrder(Integer goodsSellId) throws Exception;
+
+    /**
      * @describe 商品销售订单回调
      * @describe 商品销售订单回调
      * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
      * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
      * @author zouxuan
      * @author zouxuan

+ 86 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRepairServiceImpl.java

@@ -251,6 +251,92 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
     }
     }
 
 
     @Override
     @Override
+    @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
+    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 = studentGoodsSell.getGoodsSellDtos();
+        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("操作失败:订单金额异常");
+        }
+
+        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
+        studentPaymentOrder.setUserId(studentId);
+        studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
+        studentPaymentOrder.setOrderNo(studentGoodsSell.getOrderNo());
+        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);
+
+        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(studentGoodsSell.getOrderNo(), student.getOrganId(), balance);
+            Map<String, String> notifyMap = new HashMap<>();
+            notifyMap.put("tradeState", "1");
+            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
+            studentPaymentOrderService.updateOrder(notifyMap);
+            notifyMap.put("orderNo", studentGoodsSell.getOrderNo());
+            return notifyMap;
+        }
+
+        String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
+
+        Map payMap = payService.getPayMap(
+                amount,
+                balance,
+                studentGoodsSell.getOrderNo(),
+                baseApiUrl + "/api-student/studentOrder/notify",
+                baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + studentGoodsSell.getOrderNo(),
+                "商品销售",
+                "商品销售",
+                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)
     @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());

+ 12 - 0
mec-student/src/main/java/com/ym/mec/student/controller/RepairController.java

@@ -69,6 +69,18 @@ public class RepairController extends BaseController {
         return succeed(map);
         return succeed(map);
     }
     }
 
 
+    @ApiOperation("学员扫码支付")
+    @PostMapping(value = "/studentPaymentGoodsOrder")
+    public HttpResponseResult studentPaymentGoodsOrder(Integer goodsSellId) throws Exception {
+        Map map = studentRepairService.studentPaymentGoodsOrder(goodsSellId);
+        if(map.containsKey("tradeState")){
+            return failed(HttpStatus.CREATED, "恭喜您,购买成功!");
+        }
+        return succeed(map);
+    }
+
+
+
     @ApiOperation("获取维修记录")
     @ApiOperation("获取维修记录")
     @GetMapping(value = "/getStudentRepairList")
     @GetMapping(value = "/getStudentRepairList")
     public HttpResponseResult getStudentRepairList(RepairStudentQueryInfo queryInfo) {
     public HttpResponseResult getStudentRepairList(RepairStudentQueryInfo queryInfo) {