Browse Source

律师端代码

ldz 3 weeks ago
parent
commit
fff6bd2971

+ 1 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/OrderRevenueVO.java

@@ -44,3 +44,4 @@ public class OrderRevenueVO implements Serializable {
     private Long completedRevenueStr;
 }
 
+

+ 76 - 7
alien-entity/src/main/java/shop/alien/mapper/LawyerConsultationOrderMapper.java

@@ -95,10 +95,10 @@ public interface LawyerConsultationOrderMapper extends BaseMapper<LawyerConsulta
             "`alipay_no`," +
             "`order_str`," +
             "place_id," +
-            "lawyer_earnings" +
-            "accept_orders_time" +
-            "reason_order_refusal" +
-            "accept_orders_status" +
+            "lawyer_earnings ," +
+            "accept_orders_time ," +
+            "reason_order_refusal ," +
+            "accept_orders_status " +
             ")"+
             "VALUES" +
             " (" +
@@ -127,14 +127,83 @@ public interface LawyerConsultationOrderMapper extends BaseMapper<LawyerConsulta
             " #{alipayNo}," +
             " #{orderStr}," +
             "#{placeId}," +
-            "#{lawyerEarnings}" +
-            "#{acceptOrdersTime}" +
-            "#{reasonOrderRefusal}" +
+            "#{lawyerEarnings} ," +
+            "#{acceptOrdersTime} ," +
+            "#{reasonOrderRefusal} ," +
             "#{acceptOrdersStatus}" +
             ")")
             int insertOrder(LawyerConsultationOrderDto order);
 
 
+//    @Insert("<script>" +
+//            "INSERT INTO `alien`.`lawyer_consultation_order`" +
+//            "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">" +
+//            "<if test='id != null'>`id`,</if>" +
+//            "<if test='orderNumber != null'>`order_number`,</if>" +
+//            "<if test='clientUserId != null'>`client_user_id`,</if>" +
+//            "<if test='lawyerUserId != null'>`lawyer_user_id`,</if>" +
+//            "<if test='problemScenarioId != null'>`problem_scenario_id`,</if>" +
+//            "<if test='problemDescription != null'>`problem_description`,</if>" +
+//            "<if test='orderAmount != null'>`order_amount`,</if>" +
+//            "<if test='consultationFee != null'>`consultation_fee`,</if>" +
+//            "<if test='startTime != null'>`start_time`,</if>" +
+//            "<if test='endTime != null'>`end_time`,</if>" +
+//            "<if test='orderStatus != null'>`order_status`,</if>" +
+//            "<if test='paymentStatus != null'>`payment_status`,</if>" +
+//            "<if test='orderTime != null'>`order_time`,</if>" +
+//            "<if test='paymentTime != null'>`payment_time`,</if>" +
+//            "<if test='validityPeriod != null'>`validity_period`,</if>" +
+//            "<if test='rating != null'>`rating`,</if>" +
+//            "<if test='comment != null'>`comment`,</if>" +
+//            "<if test='deleteFlag != null'>`delete_flag`,</if>" +
+//            "<if test='createdTime != null'>`created_time`,</if>" +
+//            "<if test='createdUserId != null'>`created_user_id`,</if>" +
+//            "<if test='updatedTime != null'>`updated_time`,</if>" +
+//            "<if test='updatedUserId != null'>`updated_user_id`,</if>" +
+//            "<if test='alipayNo != null'>`alipay_no`,</if>" +
+//            "<if test='orderStr != null'>`order_str`,</if>" +
+//            "<if test='placeId != null'>`place_id`,</if>" +
+//            "<if test='lawyerEarnings != null'>`lawyer_earnings`,</if>" +
+//            "<if test='acceptOrdersTime != null'>`accept_orders_time`,</if>" +
+//            "<if test='reasonOrderRefusal != null'>`reason_order_refusal`,</if>" +
+//            "<if test='acceptOrdersStatus != null'>`accept_orders_status`,</if>" +
+//            "</trim>" +
+//            " VALUES " +
+//            "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">" +
+//            "<if test='id != null'>#{id},</if>" +
+//            "<if test='orderNumber != null'>#{orderNumber},</if>" +
+//            "<if test='clientUserId != null'>#{clientUserId},</if>" +
+//            "<if test='lawyerUserId != null'>#{lawyerUserId},</if>" +
+//            "<if test='problemScenarioId != null'>#{problemScenarioId},</if>" +
+//            "<if test='problemDescription != null'>#{problemDescription},</if>" +
+//            "<if test='orderAmount != null'>#{orderAmount},</if>" +
+//            "<if test='consultationFee != null'>#{consultationFee},</if>" +
+//            "<if test='startTime != null'>#{startTime},</if>" +
+//            "<if test='endTime != null'>#{endTime},</if>" +
+//            "<if test='orderStatus != null'>#{orderStatus},</if>" +
+//            "<if test='paymentStatus != null'>#{paymentStatus},</if>" +
+//            "<if test='orderTime != null'>#{orderTime},</if>" +
+//            "<if test='paymentTime != null'>#{paymentTime},</if>" +
+//            "<if test='validityPeriod != null'>#{validityPeriod},</if>" +
+//            "<if test='rating != null'>#{rating},</if>" +
+//            "<if test='comment != null'>#{comment},</if>" +
+//            "<if test='deleteFlag != null'>#{deleteFlag},</if>" +
+//            "<if test='createdTime != null'>#{createdTime},</if>" +
+//            "<if test='createdUserId != null'>#{createdUserId},</if>" +
+//            "<if test='updatedTime != null'>#{updatedTime},</if>" +
+//            "<if test='updatedUserId != null'>#{updatedUserId},</if>" +
+//            "<if test='alipayNo != null'>#{alipayNo},</if>" +
+//            "<if test='orderStr != null'>#{orderStr},</if>" +
+//            "<if test='placeId != null'>#{placeId},</if>" +
+//            "<if test='lawyerEarnings != null'>#{lawyerEarnings},</if>" +
+//            "<if test='acceptOrdersTime != null'>#{acceptOrdersTime},</if>" +
+//            "<if test='reasonOrderRefusal != null'>#{reasonOrderRefusal},</if>" +
+//            "<if test='acceptOrdersStatus != null'>#{acceptOrdersStatus},</if>" +
+//            "</trim>" +
+//            "</script>")
+//    int insertOrder(LawyerConsultationOrderDto order);
+
+
 
 
 

+ 8 - 0
alien-entity/src/main/java/shop/alien/mapper/LawyerServiceAreaMapper.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Constants;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Select;
+import shop.alien.entity.store.LawyerLegalProblemScenario;
 import shop.alien.entity.store.LawyerServiceArea;
 import shop.alien.entity.store.vo.LifeAppealManageVo;
 import shop.alien.entity.store.vo.LifeCouponVo;
@@ -28,5 +29,12 @@ public interface LawyerServiceAreaMapper extends BaseMapper<LawyerServiceArea> {
             "left join lawyer_legal_problem_scenario llps on llps.id = lsa.problem_scenario_id \n" +
             " ${ew.customSqlSegment}")
     List<Map<String, Object>> getLawyerLegalProblemScenarioList(@Param(Constants.WRAPPER) QueryWrapper<LawyerServiceArea> queryWrapper);
+
+
+
+    @Select("select lsa.lawyer_user_id, llps.id ,llps.name from lawyer_service_area lsa \n" +
+            "left join lawyer_legal_problem_scenario llps on llps.id = lsa.problem_scenario_id \n" +
+            " ${ew.customSqlSegment}")
+    List<LawyerLegalProblemScenario> getProblemScenario(@Param(Constants.WRAPPER) QueryWrapper<LawyerServiceArea> queryWrapper);
 }
 

+ 17 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/controller/AliController.java

@@ -72,4 +72,21 @@ public class AliController {
                                 @RequestParam(value = "partialRefundCode") String partialRefundCode) {
         return aliApi.processRefund(outTradeNo, refundAmount, refundReason, partialRefundCode);
     }
+
+
+    @ApiOperation("律师端or用户退款")
+    @ApiOperationSupport(order = 14)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "outTradeNo", value = "订单号", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "refundAmount", value = "退款金额", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "refundReason", value = "退款原因", dataType = "String", paramType = "query", required = true),
+            @ApiImplicitParam(name = "partialRefundCode", value = "部分退款编码", dataType = "String", paramType = "query", required = false)
+    })
+    @GetMapping("/processLawRefund")
+    public R<String> processLawRefund(@RequestParam(value = "outTradeNo") String outTradeNo,
+                                @RequestParam(value = "refundAmount") String refundAmount,
+                                @RequestParam(value = "refundReason") String refundReason,
+                                @RequestParam(value = "partialRefundCode") String partialRefundCode) {
+        return R.data(aliApi.processRefund(outTradeNo, refundAmount, refundReason, partialRefundCode));
+    }
 }

+ 26 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/controller/LawyerClientConsultationOrderController.java

@@ -3,11 +3,14 @@ package shop.alien.lawyer.controller;
 import io.swagger.annotations.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import shop.alien.entity.result.R;
 import shop.alien.entity.store.LawyerConsultationOrder;
 import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
 import shop.alien.lawyer.service.LawyerClientConsultationOrderService;
+import shop.alien.lawyer.service.LawyerConsultationOrderService;
+import shop.alien.lawyer.service.OrderExpirationService;
 
 import java.util.Map;
 
@@ -124,5 +127,28 @@ public class LawyerClientConsultationOrderController {
         return lawyerClientConsultationOrderService.confirmOrder(id, actionType);
     }
 
+    @ApiOperation("申请退款(律师端)")
+    @ApiOperationSupport(order = 6)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "id", value = "订单ID", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "refundReason", value = "退款原因", dataType = "String", paramType = "query", required = true)
+    })
+    @PostMapping("/requestRefund")
+    public R<Boolean> requestRefund(@RequestParam(value = "id", required = true) Integer id,
+                                     @RequestParam(value = "refundReason", required = true) String refundReason) {
+        log.info("申请退款,订单ID={}, 退款原因={}", id, refundReason);
+        if (id == null) {
+            log.warn("申请退款失败:订单ID为空");
+            return R.fail("订单ID不能为空");
+        }
+        if (refundReason == null || refundReason.trim().isEmpty()) {
+            log.warn("申请退款失败:退款原因为空");
+            return R.fail("退款原因不能为空");
+        }
+        return lawyerClientConsultationOrderService.requestRefund(id, refundReason);
+    }
+
+
+
 }
 

+ 9 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/LawyerClientConsultationOrderService.java

@@ -52,5 +52,14 @@ public interface LawyerClientConsultationOrderService extends IService<LawyerCon
      * @return R<Boolean> 是否成功
      */
     R<Boolean> confirmOrder(Integer id, Integer actionType);
+
+    /**
+     * 申请退款
+     *
+     * @param id 订单ID
+     * @param refundReason 退款原因
+     * @return R<Boolean> 是否成功
+     */
+    R<Boolean> requestRefund(Integer id, String refundReason);
 }
 

+ 89 - 0
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerClientConsultationOrderServiceImpl.java

@@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.math.RandomUtils;
 import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
@@ -57,6 +58,12 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
     private final OrderExpirationService orderExpirationService;
     private final AlienStoreFeign alienStoreFeign;
 
+    @Value("${order.coefficient}")
+    private String coefficient;
+    @Value("${order.coefficients}")
+    private String coefficients;
+
+
 
     /**
      * 删除咨询订单
@@ -608,6 +615,10 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
             return R.fail("订单不存在");
         }
 
+        //清除redis缓存,避免调用订单超时处理
+        orderExpirationService.cancelOrderAcceptTimeout(order.getOrderNumber());
+
+
         // 验证订单状态是否为待接单(1)
         Integer orderStatus = order.getOrderStatus();
         Integer waitAcceptStatus = 1; // 待接单
@@ -695,5 +706,83 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
             }
         }
     }
+
+    /**
+     * 申请退款
+     * <p>
+     * 申请退款前会进行以下校验:
+     * 1. 参数校验:订单ID不能为空,退款原因不能为空
+     * 2. 订单存在性校验:订单必须存在
+     * 3. 订单支付状态校验:只有已支付的订单才能申请退款
+     * 4. 订单状态校验:待支付、已取消的订单不允许申请退款
+     * </p>
+     *
+     * @param id 订单ID
+     * @param refundReason 退款原因
+     * @return 申请退款结果
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public R<Boolean> requestRefund(Integer id, String refundReason) {
+        log.info("开始申请退款,订单ID={}, 退款原因={}", id, refundReason);
+
+        // 参数校验
+        if (id == null) {
+            log.warn("申请退款失败:订单ID为空");
+            return R.fail("订单ID不能为空");
+        }
+
+        if (!StringUtils.hasText(refundReason)) {
+            log.warn("申请退款失败:退款原因为空,订单ID={}", id);
+            return R.fail("退款原因不能为空");
+        }
+
+        // 查询订单信息
+        LawyerConsultationOrder order = consultationOrderMapper.selectById(id);
+        if (order == null) {
+            log.warn("申请退款失败:订单不存在,订单ID={}", id);
+            return R.fail("订单不存在");
+        }
+
+        // 检查订单支付状态:只有已支付的订单才能申请退款
+        Integer paymentStatus = order.getPaymentStatus();
+        Integer paidStatus = 1; // 1:已支付
+        if (paymentStatus == 0 || !paidStatus.equals(paymentStatus)) {
+            log.warn("申请退款失败:订单未支付,无法申请退款,订单ID={}, 订单编号={}, 支付状态={}",
+                    id, order.getOrderNumber(), paymentStatus);
+            return R.fail("订单未支付,无法申请退款");
+        }
+
+        // 检查订单状态:待支付、已取消的订单不允许申请退款
+        Integer orderStatus = order.getOrderStatus();
+        Integer waitPayStatus = LawyerStatusEnum.WAIT_PAY.getStatus(); // 0:待支付
+        Integer cancelStatus = LawyerStatusEnum.CANCEL.getStatus(); // 4:已取消
+
+        if (waitPayStatus.equals(orderStatus)) {
+            log.warn("申请退款失败:订单待支付,无法申请退款,订单ID={}, 订单编号={}", id, order.getOrderNumber());
+            return R.fail("订单待支付,无法申请退款");
+        }
+
+        if (cancelStatus.equals(orderStatus)) {
+            log.warn("申请退款失败:订单已取消,无法申请退款,订单ID={}, 订单编号={}", id, order.getOrderNumber());
+            return R.fail("订单已取消,无法申请退款");
+        }
+
+        // 检查订单是否已经申请过退款(这里可以根据业务需求添加退款状态字段来判断)
+        // 目前暂时允许重复申请,实际业务中可能需要添加退款状态字段来防止重复申请
+
+        // 更新订单状态为退款中或已退款(根据业务需求,这里暂时不更新订单状态,只记录退款申请)
+        // 如果需要更新订单状态,可以添加退款状态字段,例如:refundStatus (0:未退款, 1:退款中, 2:已退款, 3:退款失败)
+        
+        // 记录退款申请信息(这里可以根据业务需求创建退款记录表,或者更新订单表的退款相关字段)
+        log.info("申请退款成功,订单ID={}, 订单编号={}, 订单金额={}分, 退款原因={}",
+                id, order.getOrderNumber(), order.getOrderAmount(), refundReason);
+
+        // 这里可以调用实际的退款接口处理退款
+        // 例如:调用支付宝退款接口、更新退款状态等
+        // 目前先返回成功,实际业务中需要根据退款接口的返回结果来判断
+
+        return R.data(true, "退款申请已提交,请等待处理");
+    }
 }
 

+ 11 - 4
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerConsultationOrderServiceImpl.java

@@ -397,7 +397,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
 
     @Override
     public R<LawyerConsultationOrderDto> consultNow(LawyerConsultationOrder lawyerConsultationOrder) {
-        log.info("LawyerConsultationOrderServiceImpl.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
+            log.info("LawyerConsultationOrderServiceImpl.consultNow?lawyerConsultationOrder={}", lawyerConsultationOrder);
 
         // 参数校验
         if (lawyerConsultationOrder == null) {
@@ -954,9 +954,16 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
 
         // 更新订单状态为已取消
         LambdaUpdateWrapper<LawyerConsultationOrder> updateWrapper = new LambdaUpdateWrapper<>();
-        updateWrapper.eq(LawyerConsultationOrder::getId, id)
-                .set(LawyerConsultationOrder::getOrderStatus, cancelStatus)
-                .set(LawyerConsultationOrder::getUpdatedTime, new Date());
+
+        if (order.getPaymentStatus() == 1) {
+            updateWrapper.eq(LawyerConsultationOrder::getId, id)
+                    .set(LawyerConsultationOrder::getOrderStatus, LawyerStatusEnum.REFUNDED.getStatus())
+                    .set(LawyerConsultationOrder::getUpdatedTime, new Date());
+        }else if(order.getPaymentStatus() == 0){
+            updateWrapper.eq(LawyerConsultationOrder::getId, id)
+                    .set(LawyerConsultationOrder::getOrderStatus, cancelStatus)
+                    .set(LawyerConsultationOrder::getUpdatedTime, new Date());
+        }
 
         int updateCount = consultationOrderMapper.update(null, updateWrapper);
         boolean success = updateCount > 0;

+ 14 - 1
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerUserServiceImpl.java

@@ -524,6 +524,16 @@ public class LawyerUserServiceImpl extends ServiceImpl<LawyerUserMapper, LawyerU
         }
 
         LawyerUserVo result=lawyerUserMapper.selectInfo(lawyerId);
+
+        //把result中的数据problemScenarioId,scenarioNames 这两个数据放入到lawyerLegalProblemScenarioList中
+        QueryWrapper<LawyerServiceArea> wrapper = new QueryWrapper<>();
+        wrapper.in("lsa.lawyer_user_id", lawyerId)
+                .eq("lsa.delete_flag", 0)
+                .eq("lsa.status", 1);
+        result.setLawyerLegalProblemScenarioList(lawyerServiceAreaMapper.getProblemScenario(wrapper));
+
+
+
         return R.data(result);
     }
 
@@ -542,13 +552,16 @@ public class LawyerUserServiceImpl extends ServiceImpl<LawyerUserMapper, LawyerU
         BeanUtils.copyProperties(lawyerUserVo, lawyerUser);
 
         Integer result = lawyerUserMapper.updateLawyerUser(lawyerUser);
+
+
+
         if (result <= 0) {
             log.warn("更新律师用户信息失败:更新数据库失败,律师ID={}", lawyerUserVo.getId());
             return R.fail("修改律师信息失败");
         }
 
         //更新法律场景部分
-        if(!lawyerUserVo.getFirstLevelScenarioId().isEmpty()){
+        if(lawyerUserVo.getFirstLevelScenarioId() != null && !lawyerUserVo.getFirstLevelScenarioId().isEmpty()){
             lawyerServiceAreaMapper.delete(new QueryWrapper<LawyerServiceArea>().eq("lawyer_user_id", lawyerUserVo.getId()));
             for (String id : lawyerUserVo.getFirstLevelScenarioId().split(",")) {
                 LawyerServiceArea lawyerServiceArea = new LawyerServiceArea();