|
|
@@ -390,59 +390,141 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
}*/
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 立即咨询创建订单
|
|
|
+ * <p>
|
|
|
+ * 创建咨询订单前会进行以下处理:
|
|
|
+ * 1. 参数校验:客户端用户ID、律师用户ID、订单金额不能为空
|
|
|
+ * 2. 生成订单编号:LAW + 年月日(8位) + 随机5位数字
|
|
|
+ * 3. 计算本单收益:根据律所平台佣金比例计算咨询费用
|
|
|
+ * 4. 设置订单初始状态:待支付、未支付
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param lawyerConsultationOrder 咨询订单信息
|
|
|
+ * @return 创建结果
|
|
|
+ */
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public R<LawyerConsultationOrderDto> consultNow(LawyerConsultationOrder lawyerConsultationOrder) {
|
|
|
- log.info("LawyerConsultationOrderController.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (lawyerConsultationOrder == null) {
|
|
|
+ log.warn("创建咨询订单失败:订单信息为空");
|
|
|
+ return R.fail("订单信息不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer clientUserId = lawyerConsultationOrder.getClientUserId();
|
|
|
+ Integer lawyerUserId = lawyerConsultationOrder.getLawyerUserId();
|
|
|
+ Integer orderAmount = lawyerConsultationOrder.getOrderAmount();
|
|
|
+
|
|
|
+ if (clientUserId == null || clientUserId <= 0) {
|
|
|
+ log.warn("创建咨询订单失败:客户端用户ID无效,clientUserId={}", clientUserId);
|
|
|
+ return R.fail("客户端用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lawyerUserId == null || lawyerUserId <= 0) {
|
|
|
+ log.warn("创建咨询订单失败:律师用户ID无效,lawyerUserId={}", lawyerUserId);
|
|
|
+ return R.fail("律师用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderAmount == null || orderAmount <= 0) {
|
|
|
+ log.warn("创建咨询订单失败:订单金额无效,orderAmount={}", orderAmount);
|
|
|
+ return R.fail("订单金额不能为空且必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建订单DTO对象
|
|
|
LawyerConsultationOrderDto order = new LawyerConsultationOrderDto();
|
|
|
- order.setClientUserId(lawyerConsultationOrder.getClientUserId());
|
|
|
- order.setLawyerUserId(lawyerConsultationOrder.getLawyerUserId());
|
|
|
+ Date now = new Date();
|
|
|
+
|
|
|
+ // 设置订单基本信息
|
|
|
+ order.setClientUserId(clientUserId);
|
|
|
+ order.setLawyerUserId(lawyerUserId);
|
|
|
order.setProblemScenarioId(lawyerConsultationOrder.getProblemScenarioId());
|
|
|
order.setProblemDescription(lawyerConsultationOrder.getProblemDescription());
|
|
|
- order.setOrderAmount(lawyerConsultationOrder.getOrderAmount());
|
|
|
- order.setOrderStatus(0);
|
|
|
- order.setPaymentStatus(0);
|
|
|
- order.setOrderTime(new Date());
|
|
|
-// order.setValidityPeriod(DateUtils.addDays(new Date(), 7));
|
|
|
- order.setCreatedTime(new Date());
|
|
|
- order.setUpdatedTime(new Date());
|
|
|
- order.setDeleteFlag(0);
|
|
|
+ order.setOrderAmount(orderAmount);
|
|
|
order.setAlipayNo(lawyerConsultationOrder.getAlipayNo());
|
|
|
order.setOrderStr(lawyerConsultationOrder.getOrderStr());
|
|
|
order.setPlaceId(lawyerConsultationOrder.getPlaceId());
|
|
|
- //订单编号想要LAW+年月日(8位数字)+随机5位数字这种格式的
|
|
|
- String orderNumber = "LAW" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + String.format("%05d", RandomUtils.nextInt(100000));
|
|
|
+
|
|
|
+ // 设置订单状态
|
|
|
+ order.setOrderStatus(0); // 待支付
|
|
|
+ order.setPaymentStatus(0); // 未支付
|
|
|
+ order.setOrderTime(now);
|
|
|
+ order.setCreatedTime(now);
|
|
|
+ order.setUpdatedTime(now);
|
|
|
+ order.setDeleteFlag(0);
|
|
|
+
|
|
|
+ // 生成订单编号:LAW + 年月日(8位数字)+ 随机5位数字
|
|
|
+ String orderNumber = generateOrderNumber();
|
|
|
order.setOrderNumber(orderNumber);
|
|
|
- //计算本单收益
|
|
|
- LawyerUser lawyerUser = lawyerUserMapper.selectById(lawyerConsultationOrder.getLawyerUserId());
|
|
|
- Float commissionRate = 3F;
|
|
|
- if(lawyerUser != null){
|
|
|
- //获取律所信息
|
|
|
+ log.info("生成订单编号:orderNumber={}", orderNumber);
|
|
|
+
|
|
|
+ // 计算本单收益(咨询费用)
|
|
|
+ Integer consultationFee = calculateConsultationFee(lawyerUserId, orderAmount);
|
|
|
+ order.setConsultationFee(consultationFee);
|
|
|
+ log.info("计算咨询费用:lawyerUserId={}, orderAmount={}, consultationFee={}",
|
|
|
+ lawyerUserId, orderAmount, consultationFee);
|
|
|
+
|
|
|
+ // 插入订单
|
|
|
+ int insertCount = consultationOrderMapper.insertOrder(order);
|
|
|
+ if (insertCount > 0) {
|
|
|
+ log.info("创建咨询订单成功:orderNumber={}, orderId={}", orderNumber, order.getId());
|
|
|
+ return R.data(order);
|
|
|
+ } else {
|
|
|
+ log.error("创建咨询订单失败:数据库插入失败,orderNumber={}", orderNumber);
|
|
|
+ return R.fail("创建订单失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成订单编号
|
|
|
+ * <p>
|
|
|
+ * 格式:LAW + 年月日(8位数字)+ 随机5位数字
|
|
|
+ * 示例:LAW2025011512345
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @return 订单编号
|
|
|
+ */
|
|
|
+ private String generateOrderNumber() {
|
|
|
+ String dateStr = new SimpleDateFormat("yyyyMMdd").format(new Date());
|
|
|
+ String randomStr = String.format("%05d", RandomUtils.nextInt(100000));
|
|
|
+ return "LAW" + dateStr + randomStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算咨询费用(本单收益)
|
|
|
+ * <p>
|
|
|
+ * 根据律所的平台佣金比例计算咨询费用
|
|
|
+ * 如果律师没有关联律所或律所没有设置佣金比例,则使用默认佣金比例3%
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param lawyerUserId 律师用户ID
|
|
|
+ * @param orderAmount 订单金额(单位:分)
|
|
|
+ * @return 咨询费用(单位:分)
|
|
|
+ */
|
|
|
+ private Integer calculateConsultationFee(Integer lawyerUserId, Integer orderAmount) {
|
|
|
+ // 默认佣金比例:3%
|
|
|
+ float defaultCommissionRate = 3.0F;
|
|
|
+ float commissionRate = defaultCommissionRate;
|
|
|
+
|
|
|
+ // 查询律师信息
|
|
|
+ LawyerUser lawyerUser = lawyerUserMapper.selectById(lawyerUserId);
|
|
|
+ if (lawyerUser != null) {
|
|
|
+ // 获取律所信息
|
|
|
Integer firmId = lawyerUser.getFirmId();
|
|
|
- if(firmId != null && firmId > 0){
|
|
|
- LawFirm lawyerFirm = lawFirmMapper.selectById(firmId);
|
|
|
- if(lawyerFirm != null && lawyerFirm.getPlatformCommissionRatio() != null && lawyerFirm.getPlatformCommissionRatio() > 0){
|
|
|
+ if (firmId != null && firmId > 0) {
|
|
|
+ LawFirm lawyerFirm = lawFirmMapper.selectById(firmId);
|
|
|
+ if (lawyerFirm != null && lawyerFirm.getPlatformCommissionRatio() != null
|
|
|
+ && lawyerFirm.getPlatformCommissionRatio() > 0) {
|
|
|
commissionRate = lawyerFirm.getPlatformCommissionRatio();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- Integer orderAmount = lawyerConsultationOrder.getOrderAmount();
|
|
|
-// BigDecimal result2 = orderAmount.multiply(new BigDecimal(rate/100))
|
|
|
-// .setScale(0, RoundingMode.HALF_UP);
|
|
|
- int result2 = Math.round(orderAmount*commissionRate/100);
|
|
|
- order.setConsultationFee(result2);
|
|
|
}
|
|
|
- int num = consultationOrderMapper.insertOrder(order);
|
|
|
-
|
|
|
|
|
|
-// boolean result = this.save(order);
|
|
|
-// if (result) {
|
|
|
-// return R.data(order);
|
|
|
-// }
|
|
|
-// return R.fail("新增失败");
|
|
|
- if (num >0){
|
|
|
- return R.data(order);
|
|
|
- }
|
|
|
- return null;
|
|
|
+ // 计算咨询费用:订单金额 * 佣金比例 / 100,四舍五入
|
|
|
+ int consultationFee = Math.round(orderAmount * commissionRate / 100);
|
|
|
+ return consultationFee;
|
|
|
}
|
|
|
|
|
|
|