修改店铺二维码收款
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.chaozhanggui.system.cashierservice.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
@@ -11,11 +12,14 @@ import com.alipay.api.request.AlipayUserInfoShareRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.alipay.api.response.AlipayUserInfoShareResponse;
|
||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ReturnGroupOrderDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
|
||||
import com.chaozhanggui.system.cashierservice.model.PaymentReq;
|
||||
import com.chaozhanggui.system.cashierservice.service.PayService;
|
||||
import com.chaozhanggui.system.cashierservice.service.ShopInfoService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
||||
@@ -32,7 +36,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@CrossOrigin(origins = "*")
|
||||
@@ -40,26 +46,26 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
@RequestMapping("pay")
|
||||
public class PayController {
|
||||
|
||||
|
||||
@Autowired
|
||||
PayService payService;
|
||||
@Autowired
|
||||
private ShopInfoService shopInfoService;
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopInfoMapper tbShopInfoMapper;
|
||||
|
||||
@RequestMapping("queryPayType")
|
||||
public Result queryPayType(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("shopId") String shopId
|
||||
|
||||
){
|
||||
@RequestParam("shopId") String shopId) {
|
||||
return payService.queryPayType(shopId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 扫码支付
|
||||
*
|
||||
* @param request
|
||||
* @param token
|
||||
* @param loginName
|
||||
@@ -72,33 +78,32 @@ public class PayController {
|
||||
@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody PaymentReq paymentReq
|
||||
) {
|
||||
@RequestBody PaymentReq paymentReq) {
|
||||
return payService.scanPay(paymentReq.getOrderId(), paymentReq.getAuthCode(), IpUtil.getIpAddr(request), token, paymentReq.getPayAmount(), paymentReq.getDiscountAmount());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 储值卡支付
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
* @return
|
||||
*/
|
||||
|
||||
@RequestMapping("accountPay")
|
||||
@LimitSubmit(key = "accountPay:%s")
|
||||
public Result accountPay(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody PaymentReq paymentReq
|
||||
){
|
||||
@RequestBody PaymentReq paymentReq) {
|
||||
return payService.accountPay(paymentReq.getOrderId(), paymentReq.getMemberId(), token, paymentReq.getMemberAccount(), paymentReq.getPayAmount(), paymentReq.getDiscountAmount());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 快捷收款
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -114,14 +119,14 @@ public class PayController {
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("amount") String amount,
|
||||
@RequestParam("authCode") String authCode,
|
||||
@RequestParam("payType") String payType
|
||||
){
|
||||
@RequestParam("payType") String payType) {
|
||||
return payService.quickPay(token, amount, authCode, payType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询快捷订单状态
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -131,14 +136,14 @@ public class PayController {
|
||||
public Result queryQuickPayStatus(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("orderId") String orderId
|
||||
){
|
||||
@RequestParam("orderId") String orderId) {
|
||||
return payService.queryQuickPayStatus(orderId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取快捷收款信息
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -151,18 +156,13 @@ public class PayController {
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("page") Integer page,
|
||||
@RequestParam("pageSize") Integer pageSize
|
||||
){
|
||||
@RequestParam("pageSize") Integer pageSize) {
|
||||
return payService.queryQuickPay(token, page, pageSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 会员扫码支付
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -173,15 +173,14 @@ public class PayController {
|
||||
public Result memberScanPay(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody PaymentReq paymentReq
|
||||
){
|
||||
@RequestBody PaymentReq paymentReq) {
|
||||
return payService.memberScanPay(paymentReq.getOrderId(), paymentReq.getMemberCode(), token, paymentReq.getPayAmount(), paymentReq.getDiscountAmount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 现金支付
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -197,9 +196,9 @@ public class PayController {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 会员支付
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -210,27 +209,21 @@ public class PayController {
|
||||
public Result vipPay(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody VipPayDTO vipPayDTO
|
||||
){
|
||||
@RequestBody VipPayDTO vipPayDTO) {
|
||||
if (vipPayDTO.getOrderId() == null || vipPayDTO.getVipUserId() == null) {
|
||||
return Result.fail("参数缺失");
|
||||
}
|
||||
|
||||
if (
|
||||
(vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
|
||||
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)
|
||||
) {
|
||||
if ((vipPayDTO.getPayAmount() != null && vipPayDTO.getPayAmount().compareTo(BigDecimal.ZERO) <= 0) ||
|
||||
(vipPayDTO.getDiscountAmount() != null && vipPayDTO.getDiscountAmount().compareTo(BigDecimal.ZERO) <= 0)) {
|
||||
return Result.fail("折扣金额必须大于0");
|
||||
}
|
||||
return payService.vipPay(vipPayDTO.getOrderId(), token, vipPayDTO.getVipUserId(), vipPayDTO.getPayAmount(), vipPayDTO.getDiscountAmount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 银行卡支付
|
||||
*
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
@@ -245,8 +238,6 @@ public class PayController {
|
||||
return payService.bankPay(paymentReq.getOrderId(), token, paymentReq.getPayAmount(), paymentReq.getDiscountAmount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("returnOrder")
|
||||
@LimitSubmit(key = "returnOrder:%s", limit = 10)
|
||||
public Result returnOrder(@RequestHeader("token") String token,
|
||||
@@ -254,11 +245,7 @@ public class PayController {
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestBody List<TbOrderDetail> list,
|
||||
@RequestParam("pwd") String pwd,
|
||||
@RequestParam(defaultValue = "true") boolean isOnline
|
||||
){
|
||||
|
||||
|
||||
|
||||
@RequestParam(defaultValue = "true") boolean isOnline) {
|
||||
return payService.returnOrder(list, token, pwd, isOnline);
|
||||
}
|
||||
|
||||
@@ -276,26 +263,21 @@ public class PayController {
|
||||
return payService.returnGroupOrder(param);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("test")
|
||||
@LimitSubmit(key = "testOrder:%s")
|
||||
public Result testOrder(@RequestParam("orderId") String orderId) {
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("getOrderDiscount")
|
||||
public Result getOrderDiscount(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("orderId") String orderId,
|
||||
@RequestParam("staffId") String staffId
|
||||
){
|
||||
@RequestParam("staffId") String staffId) {
|
||||
return payService.getOrderDiscount(staffId, orderId, token);
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("pcscanpay")
|
||||
@LimitSubmit(key = "pcscanpay:%s")
|
||||
public Result pcscanpay(HttpServletRequest request, @RequestBody PaymentReq paymentReq) {
|
||||
@@ -307,15 +289,11 @@ public class PayController {
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping("createOrder")
|
||||
public Result createOrder(HttpServletRequest request, @RequestBody PaymentReq paymentReq) {
|
||||
try {
|
||||
return payService.createOrder(IpUtil.getIpAddr(request),paymentReq.getUserId(),paymentReq.getPayType(),paymentReq.getShopId(),paymentReq.getPayAmount());
|
||||
return payService.createOrder(IpUtil.getIpAddr(request), paymentReq.getUserId(), paymentReq.getPayType(),
|
||||
paymentReq.getShopId(), paymentReq.getOrderId(), paymentReq.getPayAmount());
|
||||
} catch (JsonProcessingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -328,20 +306,12 @@ public class PayController {
|
||||
return payService.queryOrderPay(orderId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Value("${wx.ysk.appId}")
|
||||
private String appId;
|
||||
|
||||
@Value("${wx.ysk.secrete}")
|
||||
private String secrete;
|
||||
|
||||
|
||||
|
||||
@Value("${ali.appId}")
|
||||
private String aliAppId;
|
||||
|
||||
@@ -352,17 +322,29 @@ public class PayController {
|
||||
private String publicKey;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取支付宝或微信openId
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/openId")
|
||||
public Result getOpenId(
|
||||
@RequestParam String code,
|
||||
@RequestParam String payType
|
||||
) throws AlipayApiException {
|
||||
public Result getOpenId(@RequestParam String code, @RequestParam String payType,
|
||||
@RequestParam String shopId) throws AlipayApiException {
|
||||
if (StrUtil.isBlank(shopId)) {
|
||||
return Result.fail("店铺ID不能为空");
|
||||
}
|
||||
|
||||
// 查询店铺信息
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
if (Objects.isNull(shopInfo)) {
|
||||
return Result.fail("店铺不存在");
|
||||
}
|
||||
|
||||
Map<String, Object> data = new HashMap<>(4);
|
||||
data.put("shopId", shopInfo.getId());
|
||||
data.put("shopName", shopInfo.getShopName());
|
||||
data.put("shopImage", shopInfo.getCoverImg());
|
||||
|
||||
if ("WECHAT".equals(payType)) {
|
||||
JSONObject SessionKeyOpenId = WechatUtil.getSessionKeyOrOpenId(code, appId, secrete);
|
||||
@@ -372,19 +354,13 @@ public class PayController {
|
||||
return Result.fail("获取微信id失败");
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS,openid);
|
||||
data.put("openId", openid);
|
||||
return Result.success(CodeEnum.SUCCESS, data);
|
||||
} else if ("ALIPAY".equals(payType)) {
|
||||
|
||||
|
||||
// 初始化SDK
|
||||
AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
|
||||
|
||||
// 构造请求参数以调用接口
|
||||
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
|
||||
|
||||
// 设置刷新令牌
|
||||
// request.setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
|
||||
|
||||
// 设置授权码
|
||||
request.setCode(code);
|
||||
|
||||
@@ -400,14 +376,16 @@ public class PayController {
|
||||
return Result.fail("获取支付宝userId失败");
|
||||
}
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, ObjectUtil.isNull(response.getUserId())?response.getOpenId():response.getUserId());
|
||||
String openid = ObjectUtil.isNull(response.getUserId()) ? response.getOpenId() : response.getUserId();
|
||||
data.put("openId", openid);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, data);
|
||||
}
|
||||
|
||||
return Result.fail(CodeEnum.FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private AlipayConfig getAlipayConfig() {
|
||||
AlipayConfig alipayConfig = new AlipayConfig();
|
||||
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
|
||||
@@ -429,8 +407,4 @@ public class PayController {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,4 @@ public class PaymentReq implements Serializable {
|
||||
private String userId;
|
||||
|
||||
private String shopId;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1854,7 +1854,7 @@ public class PayService {
|
||||
return "QR" + date + randomNum;
|
||||
}
|
||||
|
||||
public Result createOrder(String ip, String userId, String payType, String shopId, BigDecimal amount) throws JsonProcessingException {
|
||||
public Result createOrder(String ip, String userId, String payType, String shopId, String orderId, BigDecimal amount) throws JsonProcessingException {
|
||||
|
||||
if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(payType) ||
|
||||
ObjectUtil.isNull(payType) || ObjectUtil.isNull(shopId) || ObjectUtil.isEmpty(shopId) ||
|
||||
@@ -1868,8 +1868,12 @@ public class PayService {
|
||||
return Result.fail(CodeEnum.SHOPINFONOEXIST);
|
||||
}
|
||||
|
||||
TbOrderInfo orderInfo;
|
||||
|
||||
TbOrderInfo orderInfo = new TbOrderInfo();
|
||||
if (StrUtil.isNotBlank(orderId)) {
|
||||
orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
} else {
|
||||
orderInfo = new TbOrderInfo();
|
||||
|
||||
String orderNo = generateOrderNumber();
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
@@ -1893,6 +1897,7 @@ public class PayService {
|
||||
orderInfo.setTradeDay(DateUtils.getDay());
|
||||
|
||||
tbOrderInfoMapper.insert(orderInfo);
|
||||
}
|
||||
|
||||
|
||||
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderInfo.getId().toString());
|
||||
|
||||
Reference in New Issue
Block a user