添加pcpay 支付

This commit is contained in:
牛叉闪闪
2024-09-13 11:06:36 +08:00
parent 50041dc1cc
commit 0775b09c77
3 changed files with 184 additions and 144 deletions

View File

@@ -1,8 +1,10 @@
package com.chaozhanggui.system.cashierservice.controller; package com.chaozhanggui.system.cashierservice.controller;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient; import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient; import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipaySystemOauthTokenRequest; import com.alipay.api.request.AlipaySystemOauthTokenRequest;
import com.alipay.api.request.AlipayUserInfoShareRequest; import com.alipay.api.request.AlipayUserInfoShareRequest;
@@ -17,6 +19,7 @@ import com.chaozhanggui.system.cashierservice.service.PayService;
import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.sign.Result;
import com.chaozhanggui.system.cashierservice.util.IpUtil; import com.chaozhanggui.system.cashierservice.util.IpUtil;
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.RedisCst; import com.chaozhanggui.system.cashierservice.util.RedisCst;
import com.chaozhanggui.system.cashierservice.util.WechatUtil; import com.chaozhanggui.system.cashierservice.util.WechatUtil;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
@@ -28,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -304,6 +308,10 @@ public class PayController {
} }
@RequestMapping("createOrder") @RequestMapping("createOrder")
public Result createOrder(HttpServletRequest request,@RequestBody PaymentReq paymentReq){ public Result createOrder(HttpServletRequest request,@RequestBody PaymentReq paymentReq){
try { try {
@@ -315,8 +323,10 @@ public class PayController {
} }
@GetMapping("queryOrderPay")
public Result queryOrderPay(String orderId){
return payService.queryOrderPay(orderId);
}
@@ -365,15 +375,32 @@ public class PayController {
return Result.success(CodeEnum.SUCCESS,openid); return Result.success(CodeEnum.SUCCESS,openid);
}else if("ALIPAY".equals(payType)){ }else if("ALIPAY".equals(payType)){
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",aliAppId,privateKey,"json","GBK",publicKey,"RSA2");
AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); // 初始化SDK
AlipayUserInfoShareResponse response = alipayClient.execute(request,code); AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());
log.info("AlipayUserInfoShareResponse:{}",JSONObject.toJSONString(response));
if(!response.isSuccess()){ // 构造请求参数以调用接口
AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
// 设置刷新令牌
// request.setRefreshToken("201208134b203fe6c11548bcabd8da5bb087a83b");
// 设置授权码
request.setCode(code);
// 设置授权方式
request.setGrantType("authorization_code");
AlipaySystemOauthTokenResponse response = alipayClient.execute(request);
log.info("AlipaySystemOauthTokenResponse:{}", JSONUtil.toJSONString(response));
response.setAccessToken(response.getRefreshToken());
if (!response.isSuccess()) {
return Result.fail("获取支付宝userId失败"); return Result.fail("获取支付宝userId失败");
} }
return Result.success(CodeEnum.SUCCESS,response.getUserId()); return Result.success(CodeEnum.SUCCESS, ObjectUtil.isNull(response.getUserId())?response.getOpenId():response.getUserId());
} }
return Result.fail(CodeEnum.FAIL); return Result.fail(CodeEnum.FAIL);
@@ -381,6 +408,28 @@ public class PayController {
private AlipayConfig getAlipayConfig() {
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
alipayConfig.setAppId(aliAppId);
alipayConfig.setPrivateKey(privateKey);
alipayConfig.setFormat("json");
alipayConfig.setAlipayPublicKey(publicKey);
alipayConfig.setCharset("UTF-8");
alipayConfig.setSignType("RSA2");
return alipayConfig;
}
public static void main(String[] args){
LocalDate date=LocalDate.now();
if(date.isLeapYear()){
System.out.println();
}
}

View File

@@ -31,6 +31,7 @@ public class WebAppConfigurer implements WebMvcConfigurer {
.excludePathPatterns("/pay/pcscanpay") .excludePathPatterns("/pay/pcscanpay")
.excludePathPatterns("/pay/openId") .excludePathPatterns("/pay/openId")
.excludePathPatterns("/pay/createOrder") .excludePathPatterns("/pay/createOrder")
.excludePathPatterns("/pay/queryOrderPay")
; ;

View File

@@ -40,7 +40,6 @@ import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.ACCOUNTEIXST; import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.ACCOUNTEIXST;
import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS; import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
@@ -50,43 +49,27 @@ import static com.chaozhanggui.system.cashierservice.sign.CodeEnum.SUCCESS;
public class PayService { public class PayService {
private final RedisTemplate<String, Object> redisTemplate;
@Autowired @Autowired
TbOrderInfoMapper tbOrderInfoMapper; TbOrderInfoMapper tbOrderInfoMapper;
@Autowired @Autowired
TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper; TbMerchantThirdApplyMapper tbMerchantThirdApplyMapper;
@Autowired @Autowired
TbOrderPaymentMapper tbOrderPaymentMapper; TbOrderPaymentMapper tbOrderPaymentMapper;
@Autowired @Autowired
TbShopPayTypeMapper tbShopPayTypeMapper; TbShopPayTypeMapper tbShopPayTypeMapper;
@Autowired @Autowired
TbCashierCartMapper tbCashierCartMapper; TbCashierCartMapper tbCashierCartMapper;
@Autowired @Autowired
TbShopUserMapper tbShopUserMapper; TbShopUserMapper tbShopUserMapper;
@Autowired @Autowired
TbShopUserFlowMapper tbShopUserFlowMapper; TbShopUserFlowMapper tbShopUserFlowMapper;
@Autowired @Autowired
TbOrderDetailMapper tbOrderDetailMapper; TbOrderDetailMapper tbOrderDetailMapper;
@Autowired @Autowired
RestTemplate restTemplate; RestTemplate restTemplate;
@Autowired @Autowired
RabbitProducer producer; RabbitProducer producer;
@Resource
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
@Resource
private TbGroupOrderCouponMapper couponMapper;
@Autowired @Autowired
TbUserInfoMapper tbUserInfoMapper; TbUserInfoMapper tbUserInfoMapper;
@Autowired @Autowired
@@ -95,22 +78,24 @@ public class PayService {
TbShopInfoMapper tbShopInfoMapper; TbShopInfoMapper tbShopInfoMapper;
@Autowired @Autowired
TbQuickPayMapper tbQuickPayMapper; TbQuickPayMapper tbQuickPayMapper;
@Autowired
TbmerchantAccountMapper tbmerchantAccountMapper;
@Autowired
TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Resource
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
@Resource
private TbGroupOrderCouponMapper couponMapper;
@Autowired @Autowired
private TbProductSkuMapper productSkuMapper; private TbProductSkuMapper productSkuMapper;
@Autowired @Autowired
private TbProductMapper productMapper; private TbProductMapper productMapper;
@Autowired @Autowired
private TbShopUnitMapper shopUnitMapper; private TbShopUnitMapper shopUnitMapper;
@Autowired @Autowired
private TbProductStockDetailMapper productStockDetailMapper; private TbProductStockDetailMapper productStockDetailMapper;
@Autowired @Autowired
private RedisUtils redisUtil; private RedisUtils redisUtil;
@Value("${gateway.url}") @Value("${gateway.url}")
private String gateWayUrl; private String gateWayUrl;
@Value("${client.backUrl}") @Value("${client.backUrl}")
@@ -121,14 +106,6 @@ public class PayService {
private String url; private String url;
@Value("${thirdPay.callBack}") @Value("${thirdPay.callBack}")
private String callBack; private String callBack;
@Autowired
TbmerchantAccountMapper tbmerchantAccountMapper;
@Autowired
TbPlussShopStaffMapper tbPlussShopStaffMapper;
@Autowired @Autowired
private MpShopUserMapper mpShopUserMapper; private MpShopUserMapper mpShopUserMapper;
@Autowired @Autowired
@@ -136,12 +113,13 @@ public class PayService {
@Autowired @Autowired
private MpShopTableMapper mpShopTableMapper; private MpShopTableMapper mpShopTableMapper;
private final RedisTemplate<String, Object> redisTemplate;
public PayService(RedisTemplate<String, Object> redisTemplate) { public PayService(RedisTemplate<String, Object> redisTemplate) {
this.redisTemplate = redisTemplate; this.redisTemplate = redisTemplate;
} }
public static void main(String[] args) {
System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
}
public Result queryPayType(String shopId) { public Result queryPayType(String shopId) {
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId)); return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
@@ -305,7 +283,7 @@ public class PayService {
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
//更新子单状态 //更新子单状态
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token); jsonObject.put("token", token);
@@ -387,10 +365,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
@@ -509,10 +487,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("token", token); jsonObject.put("token", token);
@@ -595,7 +573,7 @@ public class PayService {
if (ObjectUtil.isNotEmpty(memberAccount)) { if (ObjectUtil.isNotEmpty(memberAccount)) {
if (!memberAccount.substring(0, 2).equals("46")) { if (!memberAccount.startsWith("46")) {
return Result.fail(CodeEnum.ERRORQR); return Result.fail(CodeEnum.ERRORQR);
} }
@@ -647,10 +625,10 @@ public class PayService {
//更新购物车状态 //更新购物车状态
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
@@ -671,14 +649,13 @@ public class PayService {
producer.sendStockSaleMsg(mqData); producer.sendStockSaleMsg(mqData);
JSONObject baObj = new JSONObject();
JSONObject baObj=new JSONObject(); baObj.put("userId", user.getUserId());
baObj.put("userId",user.getUserId()); baObj.put("shopId", user.getShopId());
baObj.put("shopId",user.getShopId()); baObj.put("amount", orderInfo.getPayAmount());
baObj.put("amount",orderInfo.getPayAmount()); baObj.put("balance", user.getAmount());
baObj.put("balance",user.getAmount()); baObj.put("type", "消费");
baObj.put("type","消费"); baObj.put("time", flow.getCreateTime());
baObj.put("time",flow.getCreateTime());
producer.balance(baObj.toString()); producer.balance(baObj.toString());
String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(), String tableCartKey = RedisCst.getCurrentOrderKey(orderInfo.getTableId(),
@@ -738,7 +715,7 @@ public class PayService {
} }
TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(),"2").get(0); TbShopUser user = tbShopUserMapper.selectByShopId(orderInfo.getShopId(), tbUserInfo.getId().toString(), "2").get(0);
if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) { if (ObjectUtil.isEmpty(user) || !"1".equals(user.getIsVip().toString())) {
return Result.fail(CodeEnum.MEMBERNOEXIST); return Result.fail(CodeEnum.MEMBERNOEXIST);
} }
@@ -778,11 +755,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); } else {
}else { tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null);
} }
@@ -804,14 +780,13 @@ public class PayService {
producer.sendStockSaleMsg(mqData); producer.sendStockSaleMsg(mqData);
JSONObject baObj = new JSONObject();
JSONObject baObj=new JSONObject(); baObj.put("userId", user.getUserId());
baObj.put("userId",user.getUserId()); baObj.put("shopId", user.getShopId());
baObj.put("shopId",user.getShopId()); baObj.put("amount", orderInfo.getPayAmount());
baObj.put("amount",orderInfo.getPayAmount()); baObj.put("balance", user.getAmount());
baObj.put("balance",user.getAmount()); baObj.put("type", "消费");
baObj.put("type","消费"); baObj.put("time", flow.getCreateTime());
baObj.put("time",flow.getCreateTime());
producer.balance(baObj.toString()); producer.balance(baObj.toString());
clearTableInfoCache(orderInfo); clearTableInfoCache(orderInfo);
@@ -823,7 +798,7 @@ public class PayService {
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
} }
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId)); TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(orderId);
if (ObjectUtil.isEmpty(orderInfo)) { if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST); return Result.fail(CodeEnum.ORDERNOEXIST);
@@ -859,8 +834,6 @@ public class PayService {
} }
TbShopUserFlow userFlow = new TbShopUserFlow(); TbShopUserFlow userFlow = new TbShopUserFlow();
userFlow.setAmount((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount()); userFlow.setAmount((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount());
userFlow.setBalance(shopUser.getAmount().subtract((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount())); userFlow.setBalance(shopUser.getAmount().subtract((payAmount != null && discountAmount != null) ? payAmount : orderInfo.getOrderAmount()));
@@ -890,10 +863,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(String.valueOf(orderId), "final"); int cartCount = tbCashierCartMapper.updateByOrderId(String.valueOf(orderId), "final");
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(orderId, "closed", null);
} }
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
@@ -980,10 +953,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
@@ -1074,10 +1047,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
@@ -1216,7 +1189,7 @@ public class PayService {
detailPo.setStatus("closed"); detailPo.setStatus("closed");
} }
BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));; BigDecimal returnAmount = it.getPriceAmount().divide(new BigDecimal(it.getNum()), 2, RoundingMode.DOWN).multiply(new BigDecimal(map1.get(it.getId())));
detailPo.setReturnNum(map1.get(it.getId())); detailPo.setReturnNum(map1.get(it.getId()));
detailPos.add(detailPo); detailPos.add(detailPo);
@@ -1266,7 +1239,7 @@ public class PayService {
} }
} else { } else {
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId + ""); TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(String.valueOf(orderId));
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken()); PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
@@ -1318,13 +1291,13 @@ public class PayService {
tbShopUserFlowMapper.insert(flow); tbShopUserFlowMapper.insert(flow);
JSONObject baObj=new JSONObject(); JSONObject baObj = new JSONObject();
baObj.put("userId",user.getUserId()); baObj.put("userId", user.getUserId());
baObj.put("shopId",user.getShopId()); baObj.put("shopId", user.getShopId());
baObj.put("amount",newOrderInfo.getPayAmount()); baObj.put("amount", newOrderInfo.getPayAmount());
baObj.put("balance",user.getAmount()); baObj.put("balance", user.getAmount());
baObj.put("type","退款"); baObj.put("type", "退款");
baObj.put("time",flow.getCreateTime()); baObj.put("time", flow.getCreateTime());
producer.balance(baObj.toString()); producer.balance(baObj.toString());
} }
@@ -1365,13 +1338,9 @@ public class PayService {
producer.putOrderCollect(jsonObject.toJSONString()); producer.putOrderCollect(jsonObject.toJSONString());
producer.printMechine(newOrderInfo.getId().toString()); producer.printMechine(newOrderInfo.getId().toString());
//修改耗材数据 //修改耗材数据
JSONObject jsonObject1 = new JSONObject(); JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("orderId", newOrderInfo.getId()); jsonObject1.put("orderId", newOrderInfo.getId());
@@ -1692,7 +1661,6 @@ public class PayService {
return Result.success(CodeEnum.SUCCESS); return Result.success(CodeEnum.SUCCESS);
} }
public Result getOrderDiscount(String staffId, String orderId, String token) { public Result getOrderDiscount(String staffId, String orderId, String token) {
if (ObjectUtil.isNull(staffId) || ObjectUtil.isNull(orderId) || ObjectUtil.isEmpty(staffId) || ObjectUtil.isEmpty(orderId)) { if (ObjectUtil.isNull(staffId) || ObjectUtil.isNull(orderId) || ObjectUtil.isEmpty(staffId) || ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
@@ -1719,7 +1687,7 @@ public class PayService {
} }
if ("master".equals(staff.getType())) { if ("master".equals(staff.getType())) {
return Result.success(SUCCESS, new BigDecimal(0.1)); return Result.success(SUCCESS, new BigDecimal("0.1"));
} }
if (ObjectUtil.isEmpty(staff.getMaxDiscountAmount()) || ObjectUtil.isNull(staff.getMaxDiscountAmount())) { if (ObjectUtil.isEmpty(staff.getMaxDiscountAmount()) || ObjectUtil.isNull(staff.getMaxDiscountAmount())) {
@@ -1729,7 +1697,7 @@ public class PayService {
if ("0".equals(staff.getDiscountType())) { if ("0".equals(staff.getDiscountType())) {
if (staff.getMaxDiscountAmount().compareTo(tbOrderInfo.getOrderAmount()) >= 0) { if (staff.getMaxDiscountAmount().compareTo(tbOrderInfo.getOrderAmount()) >= 0) {
staff.setMaxDiscountAmount(new BigDecimal(0.1)); staff.setMaxDiscountAmount(new BigDecimal("0.1"));
} else { } else {
staff.setMaxDiscountAmount(BigDecimal.ONE.subtract(staff.getMaxDiscountAmount().divide(tbOrderInfo.getOrderAmount(), 2, RoundingMode.HALF_DOWN).setScale(2, RoundingMode.HALF_DOWN))); staff.setMaxDiscountAmount(BigDecimal.ONE.subtract(staff.getMaxDiscountAmount().divide(tbOrderInfo.getOrderAmount(), 2, RoundingMode.HALF_DOWN).setScale(2, RoundingMode.HALF_DOWN)));
} }
@@ -1739,8 +1707,7 @@ public class PayService {
return Result.success(SUCCESS, staff.getMaxDiscountAmount()); return Result.success(SUCCESS, staff.getMaxDiscountAmount());
} }
public Result pcscanpay(String orderId, String ip, String userId, String payType) throws JsonProcessingException {
public Result pcscanpay(String orderId,String ip,String userId,String payType) throws JsonProcessingException {
if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) { if (ObjectUtil.isEmpty(orderId) || ObjectUtil.isEmpty(ip)) {
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
} }
@@ -1757,7 +1724,6 @@ public class PayService {
} }
List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null); List<TbCashierCart> cashierCarts = tbCashierCartMapper.selectByOrderId(orderId, null);
if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) { if (ObjectUtil.isEmpty(cashierCarts) || ObjectUtil.isNull(cashierCarts)) {
return Result.fail(CodeEnum.CARTEXIST); return Result.fail(CodeEnum.CARTEXIST);
@@ -1778,7 +1744,6 @@ public class PayService {
} }
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId); TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
if (ObjectUtil.isEmpty(payment) || payment == null) { if (ObjectUtil.isEmpty(payment) || payment == null) {
payment = new TbOrderPayment(); payment = new TbOrderPayment();
@@ -1814,7 +1779,7 @@ public class PayService {
reqbody = body.toString(); reqbody = body.toString();
} }
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl); PublicResp<JspayResp> publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
@@ -1835,10 +1800,10 @@ public class PayService {
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final"); int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
log.info("更新购物车:{}", cartCount); log.info("更新购物车:{}", cartCount);
if(ObjectUtil.isNotNull(orderInfo.getDiscountRatio())&&ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())){ if (ObjectUtil.isNotNull(orderInfo.getDiscountRatio()) && ObjectUtil.isNotEmpty(orderInfo.getDiscountRatio())) {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",orderInfo.getDiscountRatio()); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", orderInfo.getDiscountRatio());
}else { } else {
tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed",null); tbOrderDetailMapper.updateStatusByOrderId(Integer.valueOf(orderId), "closed", null);
} }
// JSONObject jsonObject = new JSONObject(); // JSONObject jsonObject = new JSONObject();
@@ -1854,7 +1819,7 @@ public class PayService {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo())); return Result.success(CodeEnum.SUCCESS, mapper.readTree(scanpayResp.getPayInfo()));
}else if("TRADE_AWAIT".equals(scanpayResp.getState())){ } else if ("TRADE_AWAIT".equals(scanpayResp.getState())) {
orderInfo.setStatus("paying"); orderInfo.setStatus("paying");
orderInfo.setPayOrderNo(payment.getTradeNumber()); orderInfo.setPayOrderNo(payment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo); tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
@@ -1864,11 +1829,11 @@ public class PayService {
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment); tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
if("WECHAT".equals(scanpayResp.getPayType())){ if ("WECHAT".equals(scanpayResp.getPayType())) {
orderInfo.setPayType("WECHAT"); orderInfo.setPayType("WECHAT");
}else if("ALIPAY".equals(scanpayResp.getPayType())){ } else if ("ALIPAY".equals(scanpayResp.getPayType())) {
orderInfo.setPayType("ALIPAY"); orderInfo.setPayType("ALIPAY");
}else if("UNIONPAY".equals(scanpayResp.getPayType())){ } else if ("UNIONPAY".equals(scanpayResp.getPayType())) {
orderInfo.setPayType("UNIONPAY"); orderInfo.setPayType("UNIONPAY");
} }
@@ -1877,7 +1842,7 @@ public class PayService {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.PAYING,mapper.readTree(scanpayResp.getPayInfo())); return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
} }
} }
} }
@@ -1886,7 +1851,6 @@ public class PayService {
} }
public String generateOrderNumber() { public String generateOrderNumber() {
String date = DateUtils.getSdfTimes(); String date = DateUtils.getSdfTimes();
Random random = new Random(); Random random = new Random();
@@ -1894,28 +1858,23 @@ public class PayService {
return "QR" + date + randomNum; 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,BigDecimal amount) throws JsonProcessingException { if (ObjectUtil.isNull(userId) || ObjectUtil.isEmpty(userId) || ObjectUtil.isEmpty(payType) || ObjectUtil.isNull(payType)
if(ObjectUtil.isNull(userId)||ObjectUtil.isEmpty(userId)||ObjectUtil.isEmpty(payType)||ObjectUtil.isNull(payType) || ObjectUtil.isNull(shopId) || ObjectUtil.isEmpty(shopId) || ObjectUtil.isNull(shopId) || ObjectUtil.isNull(amount) || ObjectUtil.isEmpty(amount)
) {
||ObjectUtil.isNull(shopId)||ObjectUtil.isEmpty(shopId)||ObjectUtil.isNull(shopId)||ObjectUtil.isNull(amount)||ObjectUtil.isEmpty(amount)
){
return Result.fail(CodeEnum.PARAM); return Result.fail(CodeEnum.PARAM);
} }
if(!"WECHAT".equals(payType)||!"ALIPAY".equals(payType)){ TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
return Result.fail(CodeEnum.PARAM);
}
TbShopInfo shopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if(ObjectUtil.isNull(shopInfo)){ if (ObjectUtil.isNull(shopInfo)) {
return Result.fail(CodeEnum.SHOPINFONOEXIST); return Result.fail(CodeEnum.SHOPINFONOEXIST);
} }
TbOrderInfo orderInfo = new TbOrderInfo();
TbOrderInfo orderInfo=new TbOrderInfo();
String orderNo = generateOrderNumber(); String orderNo = generateOrderNumber();
orderInfo.setOrderNo(orderNo); orderInfo.setOrderNo(orderNo);
@@ -1963,8 +1922,6 @@ public class PayService {
} }
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId())); TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) { if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
return Result.fail(CodeEnum.NOCUSTOMER); return Result.fail(CodeEnum.NOCUSTOMER);
@@ -1973,7 +1930,7 @@ public class PayService {
String reqbody = "店铺收款码"; String reqbody = "店铺收款码";
PublicResp<JspayResp> publicResp = thirdPayService.jspay(url,thirdApply.getAppId(),thirdApply.getAppToken(),reqbody,reqbody,orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(),payType,"WECHAT".equals(payType)?thirdApply.getSmallAppid():null,userId,ip,DateUtils.getSsdfTimes(),thirdApply.getStoreId(),backUrl,backUrl); PublicResp<JspayResp> publicResp = thirdPayService.jspay(url, thirdApply.getAppId(), thirdApply.getAppToken(), reqbody, reqbody, orderInfo.getOrderAmount().multiply(new BigDecimal(100)).longValue(), payType, "WECHAT".equals(payType) ? thirdApply.getSmallAppid() : null, userId, ip, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), backUrl, backUrl);
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) { if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
@@ -2014,22 +1971,55 @@ public class PayService {
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
return Result.success(CodeEnum.PAYING, mapper.readTree(scanpayResp.getPayInfo()));
Map<String,Object> map=new HashMap<>();
map.put("orderInfo",orderInfo);
map.put("payInfo",mapper.readTree(scanpayResp.getPayInfo()));
return Result.success(CodeEnum.PAYING, map);
} }
} }
} }
return Result.fail(CodeEnum.FAIL); return Result.fail(CodeEnum.FAIL);
} }
public Result queryOrderPay(String orderId) {
if (ObjectUtil.isEmpty(orderId)) {
return Result.fail(CodeEnum.PARAM);
}
TbOrderInfo orderInfo = tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
if (ObjectUtil.isEmpty(orderInfo)) {
return Result.fail(CodeEnum.ORDERNOEXIST);
}
if ("unpaid".equals(orderInfo.getStatus()) || "paying".equals(orderInfo.getStatus())) {
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getMerchantId()));
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
return Result.fail(CodeEnum.NOCUSTOMER);
}
TbOrderPayment tbOrderPayment = tbOrderPaymentMapper.selectByOrderId(orderId);
if (ObjectUtil.isNotEmpty(tbOrderPayment)) {
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), tbOrderPayment.getTradeNumber(), null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
if ("000000".equals(orderstatus.getCode())) {
if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
orderInfo.setStatus("closed");
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
}
}
}
}
}
return Result.success(CodeEnum.SUCCESS, orderInfo);
public static void main(String[] args) {
System.out.println(MD5Util.encrypt("123456".concat("13718478323").concat("10")));
} }
} }