通用文件上传
团购卷支付
This commit is contained in:
@@ -37,12 +37,26 @@ public class PayController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping("orderPay")
|
@RequestMapping("orderPay")
|
||||||
|
public Result pay(HttpServletRequest request, @RequestHeader("openId") String openId, @RequestBody Map<String,String> map) {
|
||||||
|
if(ObjectUtil.isEmpty(map)||map.size()<=0||!map.containsKey("orderId")||ObjectUtil.isEmpty(map.get("orderId"))){
|
||||||
|
return Result.fail("订单号不允许为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return payService.payOrder(openId,map.get("orderId").toString(), IpUtil.getIpAddr(request));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return Result.fail("支付失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequestMapping("groupOrderPay")
|
||||||
public Result pay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map<String, String> map) {
|
public Result pay(HttpServletRequest request, @RequestHeader String environment,@RequestHeader String token, @RequestBody Map<String, String> map) {
|
||||||
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) {
|
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("orderId") || ObjectUtil.isEmpty(map.get("orderId"))) {
|
||||||
return Result.fail("订单号不允许为空");
|
return Result.fail("订单号不允许为空");
|
||||||
}
|
}
|
||||||
String orderId = map.get("orderId").toString();
|
String orderId = map.get("orderId").toString();
|
||||||
String orderType = map.get("orderType").toString();
|
// String orderType = map.get("orderType").toString();
|
||||||
String payType = map.get("payType").toString();
|
String payType = map.get("payType").toString();
|
||||||
String userId="";
|
String userId="";
|
||||||
if(environment.equals("wx")){
|
if(environment.equals("wx")){
|
||||||
@@ -50,25 +64,18 @@ public class PayController {
|
|||||||
}else {
|
}else {
|
||||||
userId = TokenUtil.parseParamFromToken(token).getString("userId");
|
userId = TokenUtil.parseParamFromToken(token).getString("userId");
|
||||||
}
|
}
|
||||||
log.info("订单支付 orderId:{},orderType:{},payType={},userId:{}",orderId,orderType,payType,userId);
|
log.info("订单支付 orderId:{},payType={},userId:{}",orderId,payType,userId);
|
||||||
try {
|
try {
|
||||||
if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){
|
// if(StringUtils.isNotBlank(orderType) && orderType.equals("group")){
|
||||||
|
// return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request));
|
||||||
|
// }
|
||||||
return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request));
|
return payService.groupOrderPay(orderId, payType, userId, IpUtil.getIpAddr(request));
|
||||||
}else {
|
|
||||||
return payService.payOrder(userId, orderId, payType, IpUtil.getIpAddr(request));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return Result.fail("支付失败");
|
return Result.fail("支付失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("returnGpOrder")
|
|
||||||
public Result returnOrder(@RequestBody ReturnGroupOrderDto param){
|
|
||||||
return payService.returnOrder(param);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// public Result memberAccountPay(@RequestHeader("openId") String openId,
|
// public Result memberAccountPay(@RequestHeader("openId") String openId,
|
||||||
// @RequestParam("orderId") String orderId,
|
// @RequestParam("orderId") String orderId,
|
||||||
|
|||||||
@@ -118,11 +118,15 @@ public class PayService {
|
|||||||
@Value("${thirdPay.callBack}")
|
@Value("${thirdPay.callBack}")
|
||||||
private String callBack;
|
private String callBack;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
ThirdPayService thirdPayService;
|
ThirdPayService thirdPayService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TbGroupOrderInfoMapper tbGroupOrderInfoMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbProductMapper tbProductMapper;
|
||||||
|
@Resource
|
||||||
|
private GroupOrderCouponService orderCouponService;
|
||||||
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -269,7 +273,191 @@ public class PayService {
|
|||||||
return Result.fail("失败");
|
return Result.fail("失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result groupOrderPay(String orderId, String payType, String userId, String ip) {
|
||||||
|
TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.queryById(Integer.valueOf(orderId));
|
||||||
|
|
||||||
|
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
return Result.fail("订单状态异常,不允许支付");
|
||||||
|
}
|
||||||
|
|
||||||
|
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(orderInfo.getShopId().toString());
|
||||||
|
if (tbMerchantAccount == null) {
|
||||||
|
throw new MsgException("生成订单错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ObjectUtil.isNull(tbMerchantAccount.getMerchantId()) || ObjectUtil.isEmpty(tbMerchantAccount.getMerchantId())) {
|
||||||
|
return Result.fail("没有对应的商户");
|
||||||
|
}
|
||||||
|
|
||||||
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbMerchantAccount.getMerchantId()));
|
||||||
|
|
||||||
|
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||||
|
return Result.fail("支付通道不存在");
|
||||||
|
}
|
||||||
|
StringBuffer body=new StringBuffer();
|
||||||
|
body.append(orderInfo.getProName());
|
||||||
|
TbOrderPayment payment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||||
|
if (ObjectUtil.isEmpty(payment) || payment == null) {
|
||||||
|
payment = new TbOrderPayment();
|
||||||
|
payment.setPayTypeId("ysk");
|
||||||
|
payment.setAmount(orderInfo.getOrderAmount());
|
||||||
|
payment.setPaidAmount(orderInfo.getPayAmount());
|
||||||
|
payment.setHasRefundAmount(BigDecimal.ZERO);
|
||||||
|
if (payType.equals("wechatPay")) {
|
||||||
|
payment.setPayName("微信支付");
|
||||||
|
payment.setPayType("wechatPay");
|
||||||
|
} else if (payType.equals("aliPay")) {
|
||||||
|
payment.setPayName("支付宝支付");
|
||||||
|
payment.setPayType("aliPay");
|
||||||
|
}
|
||||||
|
payment.setReceived(payment.getAmount());
|
||||||
|
payment.setChangeFee(BigDecimal.ZERO);
|
||||||
|
// payment.setMemberId(orderInfo.getMemberId());//会员Id
|
||||||
|
payment.setShopId(orderInfo.getShopId().toString());
|
||||||
|
payment.setOrderId(orderInfo.getId().toString());
|
||||||
|
payment.setCreatedAt(System.currentTimeMillis());
|
||||||
|
tbOrderPaymentMapper.insert(payment);
|
||||||
|
} else {
|
||||||
|
if (payType.equals("wechatPay")) {
|
||||||
|
payment.setPayName("微信支付");
|
||||||
|
payment.setPayType("wechatPay");
|
||||||
|
} else if (payType.equals("aliPay")) {
|
||||||
|
payment.setPayName("支付宝支付");
|
||||||
|
payment.setPayType("aliPay");
|
||||||
|
}
|
||||||
|
payment.setUpdatedAt(System.currentTimeMillis());
|
||||||
|
tbOrderPaymentMapper.updateByPrimaryKey(payment);
|
||||||
|
}
|
||||||
|
if("ysk".equals(thirdPayType)){
|
||||||
|
PayReq req = new PayReq();
|
||||||
|
|
||||||
|
req.setAppId(thirdApply.getAppId());
|
||||||
|
req.setTimestamp(System.currentTimeMillis());
|
||||||
|
req.setIp(ip);
|
||||||
|
req.setMercOrderNo(orderInfo.getOrderNo());
|
||||||
|
req.setNotifyUrl(callBackGroupurl);
|
||||||
|
req.setPayAmt(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
||||||
|
if (payType.equals("wechatPay")) {
|
||||||
|
req.setPayType("03");
|
||||||
|
req.setPayWay("WXZF");//WXZF ZFBZF UNIONPAY
|
||||||
|
} else if (payType.equals("aliPay")) {
|
||||||
|
req.setPayWay("ZFBZF");
|
||||||
|
}
|
||||||
|
req.setSubject("零点八零:团购卷");
|
||||||
|
req.setUserId(userId);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> map = BeanUtil.transBeanMap(req);
|
||||||
|
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||||
|
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(url.concat("trans/pay"), req, String.class);
|
||||||
|
|
||||||
|
|
||||||
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||||
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||||
|
log.info("团购卷支付响应:{}",object);
|
||||||
|
if (object.get("code").equals("0")) {
|
||||||
|
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||||
|
payment.setUpdatedAt(System.currentTimeMillis());
|
||||||
|
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||||
|
orderInfo.setPayType(payType);
|
||||||
|
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||||
|
tbGroupOrderInfoMapper.update(orderInfo);
|
||||||
|
JSONObject jsonObject1 = new JSONObject();
|
||||||
|
jsonObject1.put("status", "success");
|
||||||
|
jsonObject1.put("msg", "成功");
|
||||||
|
jsonObject1.put("type", "");
|
||||||
|
jsonObject1.put("data", new JSONArray());
|
||||||
|
jsonObject1.put("amount", 0);
|
||||||
|
tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber());
|
||||||
|
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
|
||||||
|
} else {
|
||||||
|
return Result.fail(object.getString("msg"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
String reqbody="";
|
||||||
|
|
||||||
|
if(body.length()>15){
|
||||||
|
reqbody=body.substring(0,6).concat("....").concat(body.substring(body.length()-6,body.length())).toString();
|
||||||
|
}else {
|
||||||
|
reqbody=body.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
PublicResp<WxScanPayResp> publicResp= thirdPayService.scanpay(thirdUrl,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),"wx212769170d2c6b2a","wx212769170d2c6b2a",userId,ip,orderInfo.getOrderNo(),"S2405103298",callBack,null,thirdApply.getAppToken());
|
||||||
|
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
||||||
|
if("000000".equals(publicResp.getCode())){
|
||||||
|
WxScanPayResp wxScanPayResp= publicResp.getObjData();
|
||||||
|
if("TRADE_SUCCESS".equals(wxScanPayResp.getState())){
|
||||||
|
payment.setTradeNumber(wxScanPayResp.getPayOrderId());
|
||||||
|
payment.setUpdatedAt(System.currentTimeMillis());
|
||||||
|
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||||
|
orderInfo.setPayType(payType);
|
||||||
|
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||||
|
tbGroupOrderInfoMapper.update(orderInfo);
|
||||||
|
JSONObject jsonObject1 = new JSONObject();
|
||||||
|
jsonObject1.put("status", "success");
|
||||||
|
jsonObject1.put("msg", "成功");
|
||||||
|
jsonObject1.put("type", "");
|
||||||
|
jsonObject1.put("data", new JSONArray());
|
||||||
|
jsonObject1.put("amount", 0);
|
||||||
|
tbProductMapper.upGroupRealSalesNumber(orderInfo.getProId().toString(), orderInfo.getNumber());
|
||||||
|
return Result.success(CodeEnum.SUCCESS,wxScanPayResp.getPayInfo());
|
||||||
|
}else{
|
||||||
|
return Result.fail(publicResp.getMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result.fail("失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result returnOrder(ReturnGroupOrderDto param) {
|
||||||
|
TbGroupOrderInfo groupOrderInfo = tbGroupOrderInfoMapper.queryById(param.getOrderId());
|
||||||
|
List<TbGroupOrderCoupon> tbGroupOrderCoupons = orderCouponService.queryNoRefundByOrderId(param.getOrderId());
|
||||||
|
if (param.getNum() > tbGroupOrderCoupons.size()) {
|
||||||
|
return Result.fail("可退数量不足");
|
||||||
|
}
|
||||||
|
for (int i = 0; i < param.getNum(); i++) {
|
||||||
|
TbGroupOrderCoupon coupon = tbGroupOrderCoupons.get(i);
|
||||||
|
coupon.setIsRefund(1);
|
||||||
|
coupon.setRefundAmount(param.getRefundAmount());
|
||||||
|
coupon.setRefundDesc(param.getRefundDesc());
|
||||||
|
coupon.setRefundReason(param.getRefundReason());
|
||||||
|
orderCouponService.update(coupon);
|
||||||
|
}
|
||||||
|
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(groupOrderInfo.getMerchantId());
|
||||||
|
MsgException.checkNull(thirdApply, "支付参数配置错误");
|
||||||
|
ReturnOrderReq req = new ReturnOrderReq();
|
||||||
|
req.setAppId(thirdApply.getAppId());
|
||||||
|
req.setTimestamp(System.currentTimeMillis());
|
||||||
|
req.setOrderNumber(groupOrderInfo.getPayOrderNo());
|
||||||
|
req.setAmount(param.getRefundAmount().toString());
|
||||||
|
req.setMercRefundNo(groupOrderInfo.getOrderNo());
|
||||||
|
req.setRefundReason("团购卷:退货");
|
||||||
|
req.setPayPassword(thirdApply.getPayPassword());
|
||||||
|
Map<String, Object> map = BeanUtil.transBean2Map(req);
|
||||||
|
req.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||||
|
log.info("groupOrderReturn req:{}", JSONUtil.toJsonStr(req));
|
||||||
|
ResponseEntity<String> response = restTemplate.postForEntity(url.concat("merchantOrder/returnOrder"), req, String.class);
|
||||||
|
log.info("groupOrderReturn:{}", response.getBody());
|
||||||
|
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||||
|
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||||
|
if (!object.get("code").equals("0")) {
|
||||||
|
MsgException.check(true, "退款渠道调用失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
groupOrderInfo.setRefundNumber(groupOrderInfo.getRefundNumber() + param.getNum());
|
||||||
|
groupOrderInfo.setRefundAmount(groupOrderInfo.getRefundAmount().add(param.getRefundAmount()));
|
||||||
|
if (groupOrderInfo.getNumber() == groupOrderInfo.getRefundNumber()) {
|
||||||
|
groupOrderInfo.setRefundAble(0);
|
||||||
|
groupOrderInfo.setStatus("refund");
|
||||||
|
}
|
||||||
|
tbGroupOrderInfoMapper.update(groupOrderInfo);
|
||||||
|
return Result.success(CodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Result modifyOrderStatus(Integer orderId) throws IOException {
|
public Result modifyOrderStatus(Integer orderId) throws IOException {
|
||||||
@@ -528,6 +716,61 @@ public class PayService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public String callBackGroupPay(String payOrderNO) {
|
||||||
|
TbGroupOrderInfo orderInfo = tbGroupOrderInfoMapper.selectByPayOrderNo(payOrderNO);
|
||||||
|
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||||
|
return "订单信息不存在";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("unpaid".equals(orderInfo.getStatus())) {
|
||||||
|
for (int i = 0; i < orderInfo.getNumber(); i++) {
|
||||||
|
TbGroupOrderCoupon groupOrderCoupon = new TbGroupOrderCoupon();
|
||||||
|
groupOrderCoupon.setOrderId(orderInfo.getId());
|
||||||
|
groupOrderCoupon.setCouponNo(genCouponNumber());
|
||||||
|
groupOrderCoupon.setIsRefund(0);
|
||||||
|
groupOrderCouponService.insert(groupOrderCoupon);
|
||||||
|
}
|
||||||
|
orderInfo.setExpDate(getNextMonDate());
|
||||||
|
//修改主单状态
|
||||||
|
orderInfo.setStatus("unused");
|
||||||
|
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||||
|
tbGroupOrderInfoMapper.update(orderInfo);
|
||||||
|
return "SUCCESS";
|
||||||
|
}else {
|
||||||
|
log.error("支付回调异常,订单状态为{}",orderInfo);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成长度为12的随机串
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String genCouponNumber() {
|
||||||
|
Random random = new Random();
|
||||||
|
long min = 10000000000L;
|
||||||
|
long max = 19999999999L;
|
||||||
|
// 生成介于min和max之间的随机整数
|
||||||
|
long randomNumber = min + ((long) (random.nextDouble() * (max - min)));
|
||||||
|
// 将随机整数转换为字符串,并在前面补0,直到长度为12位
|
||||||
|
return String.format("%012d", randomNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取一个月后的时间
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Date getNextMonDate() {
|
||||||
|
// 获取当前日期和时间
|
||||||
|
LocalDateTime currentDateTime = LocalDateTime.now();
|
||||||
|
// 计算一个月后的日期和时间
|
||||||
|
LocalDateTime nextMonthDateTime = currentDateTime.plusMonths(1);
|
||||||
|
return java.sql.Timestamp.valueOf(nextMonthDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public String minsuccess(String payOrderNO,String tradeNo){
|
public String minsuccess(String payOrderNO,String tradeNo){
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ logging:
|
|||||||
aliyun:
|
aliyun:
|
||||||
keyid: LTAI5tPdEfYSZcqHbjCrtPRD
|
keyid: LTAI5tPdEfYSZcqHbjCrtPRD
|
||||||
keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy
|
keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy
|
||||||
|
oss:
|
||||||
|
bucketname: cashier-oss
|
||||||
|
endpoint: oss-cn-beijing.aliyuncs.com
|
||||||
|
|
||||||
thirdPay:
|
thirdPay:
|
||||||
payType: fushangtong
|
payType: fushangtong
|
||||||
|
|||||||
Reference in New Issue
Block a user