liujie
2026-07-22 fdd6c6769ee253cd20392383aa52a3d73f933619
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/TShoppingOrderController.java
@@ -17,6 +17,11 @@
import com.ruoyi.common.core.utils.OrderCodeUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.log.enums.OperatorType;
import com.ruoyi.common.security.annotation.Logical;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.model.TChargingOrderRefund;
import com.ruoyi.order.api.model.TExchangeOrder;
@@ -31,11 +36,14 @@
import com.ruoyi.other.api.feignClient.CouponClient;
import com.ruoyi.other.api.feignClient.GoodsClient;
import com.ruoyi.payment.api.feignClient.AliPaymentClient;
import com.ruoyi.payment.api.feignClient.IcbcPaymentClient;
import com.ruoyi.payment.api.feignClient.WxPaymentClient;
import com.ruoyi.payment.api.model.RefundReq;
import com.ruoyi.payment.api.model.RefundResp;
import com.ruoyi.payment.api.model.WxPaymentRefundModel;
import com.ruoyi.payment.api.vo.WxRefundNotifyResp;
import com.ruoyi.payment.api.vo.IcbcRefundReq;
import com.ruoyi.payment.api.vo.IcbcRefundResp;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import io.swagger.annotations.Api;
@@ -77,25 +85,34 @@
   @Resource
   private WxPaymentClient wxPaymentClient;
   @Resource
   private IcbcPaymentClient icbcPaymentClient;
   @Resource
   private AppCouponClient appCouponClient;
   @Resource
   private SysUserClient sysUserClient;
   @Resource
   private TShoppingOrderRefundService shoppingOrderRefundService;
   @Resource
   private AppUserAddressClient appUserAddressClient;
   /**
    * 远程管理后台取消订单后退款回调
    */
   @ResponseBody
   @PostMapping(value = "/shoppingOrderWxRefund")
   public void shoppingOrderWxRefund(@RequestParam("out_trade_no") String out_refund_no,
                                       @RequestParam("out_trade_no") String refund_id,
                                       @RequestParam("out_trade_no") String tradeState,
                                       @RequestParam("out_trade_no") String success_time){
   public void shoppingOrderWxRefund(@RequestParam("out_refund_no") String out_refund_no,
                                       @RequestParam("refund_id") String refund_id,
                                       @RequestParam("tradeState") String tradeState,
                                       @RequestParam("success_time") String success_time){
      if("SUCCESS".equals(tradeState)){
         TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no));
         one.setRefundSerialNumber(refund_id);
         one.setRefundStatus(2);
         one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE")));
         one.setRefundTime(LocalDateTime.now());
         shoppingOrderRefundService.updateById(one);
         TShoppingOrder byId = shoppingOrderService.getById(one.getShoppingOrderId());
         byId.setStatus(4);
@@ -106,6 +123,7 @@
      }
   }
   
   @RequiresPermissions(value = {"/shoppingOrder"}, logical = Logical.OR)
   @PostMapping("/getShoppingOrderList")
   @ApiOperation(value = "列表查询", tags = {"管理后台-购物订单"})
   public AjaxResult<PageInfo<TShoppingOrder>> getShoppingOrderList(@RequestBody ShoppingOrderQuery query) {
@@ -129,6 +147,7 @@
      return AjaxResult.success(res);
   }
   
   @RequiresPermissions(value = {"/shoppingOrder/deliver_goods"}, logical = Logical.OR)
   @GetMapping("/getShoppingOrderInfoById")
   @ApiOperation(value = "根据订单id查看订单详情", tags = {"管理后台-购物订单"})
   public AjaxResult<TShoppingOrder> getShoppingOrderList(String id) {
@@ -169,13 +188,17 @@
      return AjaxResult.success(byId);
   }
   
   @RequiresPermissions(value = {"/shoppingOrder/del"}, logical = Logical.OR)
   @GetMapping("/deleteShoppingOrder")
   @ApiOperation(value = "批量删除订单", tags = {"管理后台-购物订单"})
   public AjaxResult<TShoppingOrder> deleteShoppingOrder(String ids) {
      shoppingOrderService.removeBatchByIds(Arrays.asList(ids.split(",")));
      return AjaxResult.success();
   }
   @RequiresPermissions(value = {"/shoppingOrder/cancel"}, logical = Logical.OR)
   @GetMapping("/cancelShoppingOrder")
   @ApiOperation(value = "取消订单", tags = {"管理后台-购物订单"})
   public AjaxResult cancelShoppingOrder(String id) {
@@ -184,13 +207,13 @@
      // todo 根据支付方式 取消订单
      byId.setCancellationId(userid);
      byId.setCancellationTime(LocalDateTime.now());
      byId.setStatus(4);
      byId.setStatus(5);
      SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
      TShoppingOrderRefund tShoppingOrderRefund = new TShoppingOrderRefund();
      tShoppingOrderRefund.setPayTime(byId.getPayTime());
      tShoppingOrderRefund.setPayCode(byId.getSerialNumber());
      tShoppingOrderRefund.setPayAmount(byId.getPaymentAmount());
      tShoppingOrderRefund.setPayType(1);
      tShoppingOrderRefund.setPayType(byId.getPaymentType());
      tShoppingOrderRefund.setShoppingOrderId(byId.getId());
      tShoppingOrderRefund.setRefundAmount(byId.getPaymentAmount());
      tShoppingOrderRefund.setRefundStatus(1);
@@ -219,9 +242,15 @@
            refundAmount.setCurrency("CNY");
            refundAmount.setRefund(i);
            wxPaymentRefundModel.setAmount(refundAmount);
            R<String> stringR = wxPaymentClient.refundOrderR(wxPaymentRefundModel);
            R<Map<String, Object>> stringR = wxPaymentClient.refundOrderR(wxPaymentRefundModel);
            if(200 == stringR.getCode()){
               shoppingOrderRefundService.save(tShoppingOrderRefund);
               //手续费
               Map<String, Object> amount1 = (Map<String, Object>) stringR.getData().get("amount");
               Object refund_fee1 = amount1.get("refund_fee");
               BigDecimal refund_fee = new BigDecimal(null == refund_fee1 ? "0" : refund_fee1.toString()).divide(new BigDecimal(100));
               tShoppingOrderRefund.setRefundFee(refund_fee);
               shoppingOrderRefundService.updateById(tShoppingOrderRefund);
            }
            break;
         case 2:
@@ -252,11 +281,37 @@
               shoppingOrderService.updateById(byId);
            }
            break;
         case 3:
            IcbcRefundReq icbcRefundReq = new IcbcRefundReq();
            icbcRefundReq.setOutTradeNo(byId.getCode());
            icbcRefundReq.setOrderId(byId.getSerialNumber());
            icbcRefundReq.setOutRefundNo(tShoppingOrderRefund.getCode());
            icbcRefundReq.setRefundAmount(byId.getPaymentAmount());
            icbcRefundReq.setTotalAmount(byId.getPaymentAmount());
            icbcRefundReq.setReason("后台购物订单退款");
            R<IcbcRefundResp> icbcRefundResult = icbcPaymentClient.refund(icbcRefundReq);
            IcbcRefundResp icbcRefundResp = icbcRefundResult == null ? null : icbcRefundResult.getData();
            if (icbcRefundResult == null || icbcRefundResult.getCode() != 200 || icbcRefundResp == null || !"SUCCESS".equals(icbcRefundResp.getStatus())) {
               return AjaxResult.error(icbcRefundResult == null ? "工行退款服务无响应" : icbcRefundResult.getMsg());
            }
            tShoppingOrderRefund.setRefundStatus(2);
            tShoppingOrderRefund.setRefundSerialNumber(icbcRefundResp.getRefundId());
            tShoppingOrderRefund.setRefundTime(LocalDateTime.now());
            shoppingOrderRefundService.save(tShoppingOrderRefund);
            byId.setStatus(4);
            byId.setRefundCode(tShoppingOrderRefund.getCode());
            byId.setRefundAmount(byId.getPaymentAmount());
            byId.setRefundStatus(2);
            byId.setRefundSerialNumber(icbcRefundResp.getRefundId());
            byId.setRefundTime(LocalDateTime.now());
            break;
      }
      shoppingOrderService.updateById(byId);
      return AjaxResult.success();
   }
   
   @RequiresPermissions(value = {"/shoppingOrder/deliver_goods"}, logical = Logical.OR)
   @GetMapping("/consignerShoppingOrder")
   @ApiOperation(value = "发货", tags = {"管理后台-购物订单"})
   public AjaxResult consignerShoppingOrder(String id, String companyName, String code) {
@@ -271,12 +326,16 @@
      return AjaxResult.success();
   }
   
   @GetMapping("/getMyShoppingOrderList")
   @ApiOperation(value = "获取购买订单列表", tags = {"小程序-商城购买订单"})
   public AjaxResult<Map<String, Object>> getMyShoppingOrderList(GetMyShoppingOrderList query) {
      Map<String, Object> list = shoppingOrderService.getMyShoppingOrderList(query);
      return AjaxResult.success(list);
   }
   
   @GetMapping("/getMyShoppingOrderListNum")
   @ApiOperation(value = "获取购买订单列表数量", tags = {"小程序-商城购买订单"})
@@ -297,17 +356,39 @@
   
   
   @GetMapping("/getMyShoppingOrderInfo/{id}")
   @ApiOperation(value = "获取购买订单详情", tags = {"小程序-商城购买订单", "管理后台-支付订单-订单信息"})
   @ApiOperation(value = "获取购买订单详情", tags = {"管理后台-支付订单-订单信息"})
   public AjaxResult<MyShoppingOrderInfo> getMyShoppingOrderInfo(@PathVariable String id) {
      TShoppingOrder shoppingOrder = shoppingOrderService.getById(id);
      Long userId = tokenService.getLoginUserApplet().getUserId();
      if(!shoppingOrder.getAppUserId().equals(userId)){
         return AjaxResult.error("权限不足");
      }
      MyShoppingOrderInfo info = shoppingOrderService.getMyShoppingOrderInfo(id);
      return AjaxResult.success(info);
   }
   
   
   @GetMapping("/getMyShoppingOrderInfo1/{id}")
   @ApiOperation(value = "获取购买订单详情", tags = {"小程序-商城购买订单"})
   public AjaxResult<MyShoppingOrderInfo> getMyShoppingOrderInfo1(@PathVariable String id) {
      TShoppingOrder shoppingOrder = shoppingOrderService.getById(id);
      Long userId = tokenService.getLoginUserApplet().getUserId();
      if(!shoppingOrder.getAppUserId().equals(userId)){
         return AjaxResult.error("权限不足");
      }
      MyShoppingOrderInfo info = shoppingOrderService.getMyShoppingOrderInfo(id);
      return AjaxResult.success(info);
   }
   @Log(title = "【我的】确认收货操作", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE)
   @PutMapping("/confirmReceipt/{id}")
   @ApiOperation(value = "确认收货操作", tags = {"小程序-商城购买订单"})
   public AjaxResult confirmReceipt(@PathVariable String id) {
      TShoppingOrder shoppingOrder = shoppingOrderService.getById(id);
      Long userId = tokenService.getLoginUserApplet().getUserId();
      if(!shoppingOrder.getAppUserId().equals(userId)){
         return AjaxResult.error("权限不足");
      }
      if (shoppingOrder.getStatus() == 3) {
         return AjaxResult.error("不能重复确认收货");
      }
@@ -324,9 +405,15 @@
   }
   
   
   @Log(title = "【我的】取消订单操作", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE)
   @PutMapping("/cancelOrder/{id}")
   @ApiOperation(value = "取消订单操作", tags = {"小程序-商城购买订单"})
   public AjaxResult cancelOrder(@PathVariable String id) {
      TShoppingOrder shoppingOrder = shoppingOrderService.getById(id);
      Long userId = tokenService.getLoginUserApplet().getUserId();
      if(!shoppingOrder.getAppUserId().equals(userId)){
         return AjaxResult.error("权限不足");
      }
      return shoppingOrderService.cancelOrder(id);
   }
   
@@ -350,8 +437,7 @@
      return AjaxResult.success(list);
   }
   @Resource
   private AppUserAddressClient appUserAddressClient;
   @PostMapping("/create")
   public R<TShoppingOrder> shopCreate(@RequestBody ExchangeDto exchangeDto) {
      TShoppingOrder shoppingOrder = new TShoppingOrder();