|
@@ -3,11 +3,13 @@ package com.caimei365.order.service.impl;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.order.components.WeChatService;
|
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
|
+import com.caimei365.order.mapper.OrderClubMapper;
|
|
|
import com.caimei365.order.mapper.OrderCommonMapper;
|
|
|
import com.caimei365.order.mapper.PayOrderMapper;
|
|
|
import com.caimei365.order.model.ResponseJson;
|
|
|
import com.caimei365.order.model.bo.PayParamBo;
|
|
|
import com.caimei365.order.model.bo.VipRecordBo;
|
|
|
+import com.caimei365.order.model.dto.PayCouponDto;
|
|
|
import com.caimei365.order.model.dto.PaySecondDto;
|
|
|
import com.caimei365.order.model.dto.PayVipDto;
|
|
|
import com.caimei365.order.model.po.*;
|
|
@@ -49,6 +51,8 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
|
|
|
@Resource
|
|
|
private OrderCommonMapper orderCommonMapper;
|
|
|
@Resource
|
|
|
+ private OrderClubMapper orderClubMapper;
|
|
|
+ @Resource
|
|
|
private WeChatService weChatService;
|
|
|
@Value("${pay.second-notify-url}")
|
|
|
private String secondHandUrl;
|
|
@@ -56,6 +60,8 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
|
|
|
private String superVipUrl;
|
|
|
@Value("${pay.auth-vip-notify-url}")
|
|
|
private String authVipUrl;
|
|
|
+ @Value("${pay.coupon-notify-url}")
|
|
|
+ private String couponUrl;
|
|
|
@Resource
|
|
|
private RemoteCallService remoteCallService;
|
|
|
|
|
@@ -216,6 +222,7 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
|
|
|
String sign = PayUtil.getPaySign(json, PayUtil.merKey);
|
|
|
json.put("sign", sign);
|
|
|
// 私钥加密
|
|
|
+ log.info("发送参数 json:" + json);
|
|
|
String data = RSAUtil.privateEncrypt(json.toJSONString(), PayUtil.merKey);
|
|
|
// 提交
|
|
|
result = PayUtil.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", PayUtil.merAccount, data);
|
|
@@ -503,6 +510,7 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
|
|
|
String sign = PayUtil.getPaySign(json, PayUtil.merKey);
|
|
|
json.put("sign", sign);
|
|
|
// 私钥加密
|
|
|
+ log.info("发送参数 json:" + json);
|
|
|
String data = RSAUtil.privateEncrypt(json.toJSONString(), PayUtil.merKey);
|
|
|
// 提交
|
|
|
result = PayUtil.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", PayUtil.merAccount, data);
|
|
@@ -730,6 +738,311 @@ public class PayNonOrderServiceImpl implements PayNonOrderService {
|
|
|
return ResponseJson.success(result);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 微信买优惠券
|
|
|
+ *
|
|
|
+ * @param payCouponDto
|
|
|
+ * @param headers
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<JSONObject> payCouponByWeChat(PayCouponDto payCouponDto, HttpHeaders headers) {
|
|
|
+ Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
|
|
|
+ if (null != status && 1 == status) {
|
|
|
+ return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
|
|
|
+ }
|
|
|
+ PayParamBo tempParam = new PayParamBo();
|
|
|
+ // payDto -> payParam
|
|
|
+ BeanUtils.copyProperties(payCouponDto, tempParam);
|
|
|
+ ResponseJson<PayParamBo> jsonParam = getWeChatResponseJson(tempParam, headers);
|
|
|
+ if (-1 == jsonParam.getCode()) {
|
|
|
+ return ResponseJson.error(jsonParam.getMsg(), null);
|
|
|
+ }
|
|
|
+ PayParamBo payParam = jsonParam.getData();
|
|
|
+ // 获取优惠券价格
|
|
|
+ Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
|
|
|
+ payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
|
|
|
+ payParam.setNotifyUrl(couponUrl);
|
|
|
+ payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
|
|
|
+ log.info("【购买价值优惠券微信支付】>>>>>>>>>>>couponId:" + payParam.getCouponId() + ",获取openId:" + payParam.getOpenId());
|
|
|
+ return toPayCoupon(payParam, headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付宝买优惠券
|
|
|
+ *
|
|
|
+ * @param headers
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<JSONObject> payCouponByAlipay(PayCouponDto payCouponDto, HttpHeaders headers) {
|
|
|
+ Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
|
|
|
+ if (null != status && 1 == status) {
|
|
|
+ return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
|
|
|
+ }
|
|
|
+ PayParamBo payParam = new PayParamBo();
|
|
|
+ // payDto -> payParam
|
|
|
+ BeanUtils.copyProperties(payCouponDto, payParam);
|
|
|
+ //支付宝支付
|
|
|
+ payParam.setPayWay("ALIPAY");
|
|
|
+ payParam.setPayType("ALIPAY_H5");
|
|
|
+ // 获取优惠券价格
|
|
|
+ Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
|
|
|
+ payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
|
|
|
+ payParam.setNotifyUrl(couponUrl);
|
|
|
+ payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
|
|
|
+ log.info("【购买价值优惠券支付宝支付】>>>>>>>>>>>couponId:" + payParam.getCouponId());
|
|
|
+ return toPayCoupon(payParam, headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<JSONObject> payCouponUnionPay(PayCouponDto payCouponDto, HttpHeaders headers) {
|
|
|
+ Integer status = payOrderMapper.findPayStatus(payCouponDto.getCouponRecordId());
|
|
|
+ if (null != status && 1 == status) {
|
|
|
+ return ResponseJson.error("该笔记录已支付,请勿重复支付!", null);
|
|
|
+ }
|
|
|
+ PayParamBo payParam = new PayParamBo();
|
|
|
+ // payDto -> payParam
|
|
|
+ BeanUtils.copyProperties(payCouponDto, payParam);
|
|
|
+ // 银联支付
|
|
|
+ payParam.setPayWay("UNIONPAY");
|
|
|
+ payParam.setPayType("GATEWAY_UNIONPAY");
|
|
|
+ // 获取会员套餐价格
|
|
|
+ Double price = payOrderMapper.getCouponPrice(payCouponDto.getCouponId());
|
|
|
+ if ("ENTERPRISE".equals(payCouponDto.getUserType()) && price <= 8) {
|
|
|
+ return ResponseJson.error("企业网银支付金额低于手续费!", null);
|
|
|
+ }
|
|
|
+ payParam.setPayAmount(MathUtil.mul(price, 100).intValue());
|
|
|
+ payParam.setNotifyUrl(couponUrl);
|
|
|
+ payParam.setCouponRecordId(payCouponDto.getCouponRecordId());
|
|
|
+ log.info("【购买价值优惠券银联线上支付】>>>>>>>>>>>RecordId:" + payCouponDto.getCouponRecordId());
|
|
|
+ return toPayCoupon(payParam, headers);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PayCouponDto> getCouponRecord(PayCouponDto payCouponDto, HttpHeaders headers) {
|
|
|
+ //个人机构返回状态码-1 不是医美 -2
|
|
|
+ if (49 == payCouponDto.getCouponId()) {
|
|
|
+ //正式id49优惠券 普通机构和非医美机构无法购买
|
|
|
+ //先判断是否是普通机构,是就打回
|
|
|
+ Integer userIdentity = baseMapper.getIdentityByUserId(payCouponDto.getUserId());
|
|
|
+ if (userIdentity != null && 4 == userIdentity) {
|
|
|
+ return ResponseJson.error(-1, "仅供医美机构购买!", null);
|
|
|
+ }
|
|
|
+ Integer clubType = payOrderMapper.findClubType(payCouponDto.getUserId());
|
|
|
+ //为空或者不等于1 医美=1和生美=2
|
|
|
+ if (null == clubType || 1 != clubType) {
|
|
|
+ return ResponseJson.error(-2, "仅供医美机构购买!", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CouponRecordPo cr = new CouponRecordPo();
|
|
|
+ cr.setCouponId(payCouponDto.getCouponId());
|
|
|
+ cr.setUserId(payCouponDto.getUserId());
|
|
|
+ payOrderMapper.insertCouponRecord(cr);
|
|
|
+ payCouponDto.setCouponRecordId(cr.getId());
|
|
|
+ return ResponseJson.success(payCouponDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson couponCheck(Integer recordId) {
|
|
|
+ Integer status = payOrderMapper.findPayStatus(recordId);
|
|
|
+ if (null != status && 1 == status) {
|
|
|
+ return ResponseJson.success("支付成功", null);
|
|
|
+ }
|
|
|
+ return ResponseJson.error("支付失败", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseJson vipCheck(Integer recordId) {
|
|
|
+ // 获取会员套餐记录
|
|
|
+ VipRecordBo record = payOrderMapper.getVipPackageRecord(recordId);
|
|
|
+ if (null != record.getPayStatus() && 1 == record.getPayStatus()) {
|
|
|
+ return ResponseJson.success("支付成功!", null);
|
|
|
+ }
|
|
|
+ return ResponseJson.error("支付失败", null);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private ResponseJson<JSONObject> toPayCoupon(PayParamBo payParam, HttpHeaders headers) {
|
|
|
+ // 定义支付请求结果
|
|
|
+ JSONObject result = null;
|
|
|
+ try {
|
|
|
+ // 时间戳
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ // 设置支付基础参数
|
|
|
+ JSONObject json = getPayJsonObject(payParam, headers, time);
|
|
|
+ // 支付环境
|
|
|
+ String environment = "";
|
|
|
+ if (payParam.getNotifyUrl().contains("18002")) {
|
|
|
+ environment = "DEV";
|
|
|
+ } else if (payParam.getNotifyUrl().contains("core-b")) {
|
|
|
+ environment = "BETA";
|
|
|
+ }
|
|
|
+ // 商户订单号
|
|
|
+ String orderId = payParam.getUserId() + "C" + payParam.getCouponId() + "R" + payParam.getCouponRecordId() + "T" + time + environment;
|
|
|
+ json.put("orderId", orderId);
|
|
|
+ //商品名称
|
|
|
+ String product = "采美订单" + orderId;
|
|
|
+ json.put("product", product);
|
|
|
+ //支付类型
|
|
|
+ String payType = PayUtil.getPayTypeId(payParam.getPayType(), payParam.getUserType());
|
|
|
+ String attach = payParam.getCouponId() + "," + payParam.getUserId() + "," + payParam.getCouponRecordId() + "," + payType + "," + payParam.getSource();
|
|
|
+ json.put("attach", attach);
|
|
|
+ // 价值优惠券默认公账专票,彩美信息
|
|
|
+ List<Map<String, String>> list = new ArrayList<>();
|
|
|
+ Map<String, String> map = new HashMap<>(3);
|
|
|
+ map.put("subUserNo", PayUtil.publicAccountNo);
|
|
|
+ // 1按比例分账
|
|
|
+ map.put("splitBillType", "1");
|
|
|
+ // 1比例值总额
|
|
|
+ map.put("splitBillValue", "1");
|
|
|
+ list.add(map);
|
|
|
+ String splitBillDetail = JSONObject.toJSONString(list);
|
|
|
+ json.put("splitBillDetail", splitBillDetail);
|
|
|
+ String sign = PayUtil.getPaySign(json, PayUtil.merKey);
|
|
|
+ json.put("sign", sign);
|
|
|
+ log.info("发送参数 json:" + json);
|
|
|
+ // 私钥加密
|
|
|
+ String data = RSAUtil.privateEncrypt(json.toJSONString(), PayUtil.merKey);
|
|
|
+ // 提交
|
|
|
+ result = PayUtil.httpGet("https://platform.mhxxkj.com/paygateway/mbpay/order/v1", PayUtil.merAccount, data);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("错误信息", e);
|
|
|
+ return ResponseJson.error("支付失败!", null);
|
|
|
+ }
|
|
|
+ String code = result.getString("code");
|
|
|
+ if (!"000000".equals(code)) {
|
|
|
+ String msg = result.getString("msg");
|
|
|
+ log.info("第三方支付失败>>>>>>>msg:" + msg);
|
|
|
+ return ResponseJson.error(msg, null);
|
|
|
+ }
|
|
|
+ // 保存购买优惠券分账参数
|
|
|
+ JSONObject data = result.getJSONObject("data");
|
|
|
+ SplitAccountPo splitAccount = new SplitAccountPo();
|
|
|
+ splitAccount.setCouponRecordId(payParam.getCouponRecordId());
|
|
|
+ // 优惠券 公账-专票
|
|
|
+ splitAccount.setType(1);
|
|
|
+ // 待分账总金额
|
|
|
+ double splitAmount = MathUtil.div(payParam.getPayAmount(), 100).doubleValue();
|
|
|
+ // 总手续费
|
|
|
+ double procedureFee;
|
|
|
+ if ("UNIONPAY".equals(payParam.getPayWay())) {
|
|
|
+ procedureFee = 8.00;
|
|
|
+ } else {
|
|
|
+ //手续费
|
|
|
+ procedureFee = MathUtil.mul(splitAmount, 0.0038, 2).doubleValue();
|
|
|
+ if (MathUtil.compare(procedureFee, 0) == 0) {
|
|
|
+ procedureFee = 0.01;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ splitAmount = MathUtil.sub(splitAmount, procedureFee).doubleValue();
|
|
|
+ splitAccount.setSplitAccount(splitAmount);
|
|
|
+ splitAccount.setMbOrderId(data.getString("mbOrderId"));
|
|
|
+ splitAccount.setOrderRequestNo(data.getString("orderId"));
|
|
|
+ splitAccount.setPayStatus(0);
|
|
|
+ // 保存分账详情
|
|
|
+ payOrderMapper.insertSplitAccount(splitAccount);
|
|
|
+ log.info("【购买优惠券支付成功!】>>>>>>>>>>>couponRecordId:" + payParam.getCouponRecordId() + ",data:" + data.toJSONString());
|
|
|
+ return ResponseJson.success(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String couponCallback(String data) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
|
|
+ log.info("******************** 购买优惠券异步回调 start *******************");
|
|
|
+ // 公钥解密
|
|
|
+ JSONObject json = PayUtil.publicKeyDecrypt(data, PayUtil.publicKey);
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>公钥解密:" + json);
|
|
|
+ // 公钥验签
|
|
|
+ String signaa = json.getString("sign");
|
|
|
+ json.remove("sign");
|
|
|
+ String signbb = PayUtil.getPaySign(json, PayUtil.publicKey);
|
|
|
+ if (!signaa.equals(signbb)) {
|
|
|
+ return "验签失败";
|
|
|
+ }
|
|
|
+ // 订单状态
|
|
|
+ String orderStatus = json.getString("orderStatus");
|
|
|
+ // 平台唯一流水号
|
|
|
+ String mbOrderId = json.getString("mbOrderId");
|
|
|
+ // 商户唯一订单号
|
|
|
+ String orderRequestNo = json.getString("orderId");
|
|
|
+ // 金额,以元为单位
|
|
|
+ Double amount = json.getDouble("amount");
|
|
|
+ String payFormData = json.toJSONString();
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>支付订单状态:" + orderStatus);
|
|
|
+ if ("FAILED".equals(orderStatus)) {
|
|
|
+ return "支付失败";
|
|
|
+ }
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>本次支付金额:" + amount);
|
|
|
+ // 附加数据,支付时若有传输则原样返回(vipId,userId,recordId,payType),下单时为空,则不返回该数据
|
|
|
+ String attach = json.getString("attach");
|
|
|
+ String[] split = attach.split(",");
|
|
|
+ int couponId = 0;
|
|
|
+ int userId = 0;
|
|
|
+ int recordId = 0;
|
|
|
+ int payType = 0;
|
|
|
+ int source = 0;
|
|
|
+ try {
|
|
|
+ // 优惠券Id
|
|
|
+ couponId = Integer.parseInt(split[0]);
|
|
|
+ // 用户Id
|
|
|
+ userId = Integer.parseInt(split[1]);
|
|
|
+ // 购买历史记录Id
|
|
|
+ recordId = Integer.parseInt(split[2]);
|
|
|
+ // 支付方式
|
|
|
+ payType = Integer.parseInt(split[3]);
|
|
|
+ //购买渠道
|
|
|
+ source = Integer.parseInt(split[4]);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>获取回调参数解析失败!");
|
|
|
+ }
|
|
|
+ //cm_coupon_club数据库修改
|
|
|
+ CouponClubPo couponClubPo = new CouponClubPo();
|
|
|
+ couponClubPo.setSource(source);
|
|
|
+ couponClubPo.setUserId(userId);
|
|
|
+ couponClubPo.setCouponId(couponId);
|
|
|
+ couponClubPo.setStatus("1");
|
|
|
+ couponClubPo.setDelFlag("0");
|
|
|
+ couponClubPo.setCreateDate(new Date());
|
|
|
+ orderClubMapper.insertCouponClub(couponClubPo);
|
|
|
+ // 改历史记录支付状态
|
|
|
+ payOrderMapper.updateCouponRecord(recordId);
|
|
|
+ Date date = new Date();
|
|
|
+ String curDateStr = (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).format(date);
|
|
|
+ // 保存收款记录
|
|
|
+ DiscernReceiptPo discernReceipt = new DiscernReceiptPo();
|
|
|
+ discernReceipt.setPayWay(1);
|
|
|
+ discernReceipt.setPayType(payType);
|
|
|
+ discernReceipt.setReceiptType(8);
|
|
|
+ discernReceipt.setReceiptStatus(3);
|
|
|
+ discernReceipt.setReceiptAmount(amount);
|
|
|
+ discernReceipt.setConfirmType(4);
|
|
|
+ discernReceipt.setRePayFlag(1);
|
|
|
+ discernReceipt.setFormData(payFormData);
|
|
|
+ discernReceipt.setReceiptDate(curDateStr);
|
|
|
+ discernReceipt.setConfirmDate(curDateStr);
|
|
|
+ discernReceipt.setReviewDate(curDateStr);
|
|
|
+ discernReceipt.setUpdateDate(curDateStr);
|
|
|
+ discernReceipt.setDelFlag(0);
|
|
|
+ // 保存 收款记录
|
|
|
+ baseMapper.insertDiscernReceipt(discernReceipt);
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>>>>保存识别款项(insert[cm_discern_receipt])id:" + discernReceipt.getId() + ",couponRecordId:" + recordId);
|
|
|
+ // 收款项和订单关系表
|
|
|
+ OrderReceiptRelationPo relation = new OrderReceiptRelationPo();
|
|
|
+ relation.setReceiptId(discernReceipt.getId());
|
|
|
+ relation.setCouponRecordId(recordId);
|
|
|
+ relation.setAssociateAmount(amount);
|
|
|
+ relation.setMbOrderId(mbOrderId);
|
|
|
+ relation.setOrderRequestNo(orderRequestNo);
|
|
|
+ relation.setSplitStatus(1);
|
|
|
+ relation.setRelationType(6);
|
|
|
+ relation.setDelFlag(0);
|
|
|
+ // 保存 收款项和订单关系
|
|
|
+ baseMapper.insertOrderReceiptRelation(relation);
|
|
|
+ log.info("【购买优惠券异步回调】>>>>>>>>>>>收款项和购买历史关系(insert[cm_receipt_order_relation])id:" + relation.getId() + ",couponRecordId:" + recordId);
|
|
|
+ //修改分账付款状态
|
|
|
+ payOrderMapper.updateSplitAccountByPay(mbOrderId);
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 开通认证通会员-微信线上支付
|
|
|
*
|