|  | @@ -1,16 +1,5 @@
 | 
	
		
			
				|  |  | -/*
 | 
	
		
			
				|  |  | - * Copyright (c) 2018-2999 广州亚米信息科技有限公司 All rights reserved.
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * https://www.gz-yami.com/
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * 未经允许,不可做商业用途!
 | 
	
		
			
				|  |  | - *
 | 
	
		
			
				|  |  | - * 版权所有,侵权必究!
 | 
	
		
			
				|  |  | - */
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  package com.yami.shop.api.controller;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |  import cn.hutool.core.util.StrUtil;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import com.yami.shop.bean.app.param.PayParam;
 | 
	
	
		
			
				|  | @@ -18,21 +7,27 @@ import com.yami.shop.bean.model.Order;
 | 
	
		
			
				|  |  |  import com.yami.shop.bean.model.RefundDelivery;
 | 
	
		
			
				|  |  |  import com.yami.shop.bean.pay.PayInfoDto;
 | 
	
		
			
				|  |  |  import com.yami.shop.common.exception.GlobalException;
 | 
	
		
			
				|  |  | +import com.yami.shop.common.util.Arith;
 | 
	
		
			
				|  |  |  import com.yami.shop.security.api.model.YamiUser;
 | 
	
		
			
				|  |  |  import com.yami.shop.security.api.util.SecurityUtils;
 | 
	
		
			
				|  |  |  import com.yami.shop.service.*;
 | 
	
		
			
				|  |  | +import com.yami.shop.wx.po.JsapiPayInfoPo;
 | 
	
		
			
				|  |  | +import com.yami.shop.wx.service.WxProviderService;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import lombok.AllArgsConstructor;
 | 
	
		
			
				|  |  |  import lombok.SneakyThrows;
 | 
	
		
			
				|  |  | +import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.http.ResponseEntity;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.servlet.http.HttpServletResponse;
 | 
	
		
			
				|  |  |  import javax.validation.Valid;
 | 
	
		
			
				|  |  | +import java.util.Map;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @RestController
 | 
	
		
			
				|  |  | -@RequestMapping("/p/order")
 | 
	
		
			
				|  |  | +@RequestMapping("/order")
 | 
	
		
			
				|  |  | +//@RequestMapping("/p/order")
 | 
	
		
			
				|  |  |  @Api(tags = "订单接口")
 | 
	
		
			
				|  |  |  @AllArgsConstructor
 | 
	
		
			
				|  |  |  public class PayController {
 | 
	
	
		
			
				|  | @@ -42,31 +37,39 @@ public class PayController {
 | 
	
		
			
				|  |  |      private final OrderService orderService;
 | 
	
		
			
				|  |  |      private final OrderRefundService orderRefundService;
 | 
	
		
			
				|  |  |      private final RefundDeliveryService refundDeliveryService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private final WxProviderService wxProviderService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 支付接口
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | +    @SneakyThrows
 | 
	
		
			
				|  |  |      @PostMapping("/pay")
 | 
	
		
			
				|  |  |      @ApiOperation(value = "根据订单号进行支付", notes = "根据订单号进行支付")
 | 
	
		
			
				|  |  | -    @SneakyThrows
 | 
	
		
			
				|  |  | -    public ResponseEntity<?> pay(HttpServletResponse httpResponse, @Valid @RequestBody PayParam payParam) {
 | 
	
		
			
				|  |  | +    public ResponseEntity<?> pay(@Valid @RequestBody PayParam payParam) {
 | 
	
		
			
				|  |  |          YamiUser user = SecurityUtils.getUser();
 | 
	
		
			
				|  |  |          String userId = user.getUserId();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          if (!user.isEnabled()) {
 | 
	
		
			
				|  |  |              throw new GlobalException("您已被禁用,不能购买,请联系平台客服");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |          PayInfoDto payInfo = payService.pay(userId, payParam);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        payInfo.setBizUserId(user.getBizUserId());
 | 
	
		
			
				|  |  | -        payInfo.setPayType(payParam.getPayType());
 | 
	
		
			
				|  |  | -        payInfo.setApiNoticeUrl("/notice/pay/order/" + payParam.getPayType());
 | 
	
		
			
				|  |  | -        payInfo.setReturnUrl(payParam.getReturnUrl());
 | 
	
		
			
				|  |  | +        if (payInfo.getPayAmount() < 0.01 && payInfo.getIsScore() == 1) {
 | 
	
		
			
				|  |  | +            return ResponseEntity.ok().build();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if (payInfo.getPayAmount() < 0.01) {
 | 
	
		
			
				|  |  | +            throw new GlobalException("订单金额有误,无法进行支付");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        return payManagerService.doPay(httpResponse, payInfo);
 | 
	
		
			
				|  |  | +        JsapiPayInfoPo po = new JsapiPayInfoPo();
 | 
	
		
			
				|  |  | +        po.setDescription(payInfo.getBody());
 | 
	
		
			
				|  |  | +        po.setTotal((int) Arith.mul(payInfo.getPayAmount(), 100));
 | 
	
		
			
				|  |  | +        po.setOpenId(user.getBizUserId());
 | 
	
		
			
				|  |  | +        po.setOutTradeNo(payInfo.getPayNo());
 | 
	
		
			
				|  |  | +        po.setNotifyUrl("http://localhost:8112/notice/pay/order/" + payParam.getPayType());
 | 
	
		
			
				|  |  | +        return ResponseEntity.ok(wxProviderService.subJsapi(po));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 |