|
@@ -1,5 +1,6 @@
|
|
|
package thyyxxk.wxservice_server.service;
|
|
|
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.wechat.pay.java.service.payments.model.Transaction;
|
|
@@ -10,10 +11,14 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import thyyxxk.wxservice_server.config.exception.ExceptionEnum;
|
|
|
import thyyxxk.wxservice_server.constant.CardCostTypes;
|
|
|
+import thyyxxk.wxservice_server.dao.CouponDao;
|
|
|
import thyyxxk.wxservice_server.dao.InpatientDao;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.entity.PureCodeName;
|
|
|
import thyyxxk.wxservice_server.entity.ResultVo;
|
|
|
+import thyyxxk.wxservice_server.entity.coupon.CouponAttribute;
|
|
|
+import thyyxxk.wxservice_server.entity.coupon.CouponFactory;
|
|
|
+import thyyxxk.wxservice_server.entity.coupon.PatientCoupon;
|
|
|
import thyyxxk.wxservice_server.entity.electronichealthcard.HisRegister;
|
|
|
import thyyxxk.wxservice_server.entity.inpatient.GetZyFeeParam;
|
|
|
import thyyxxk.wxservice_server.entity.paymzfee.MedinsPresettle;
|
|
@@ -39,6 +44,7 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class SavePayResultService {
|
|
|
private final WxApiDao dao;
|
|
|
private final InpatientDao yjjDao;
|
|
|
+ private final CouponDao couponDao;
|
|
|
private final ThmzService thmzService;
|
|
|
private final WxRefundService refundService;
|
|
|
private final PushWxMessageService pushWxMessageService;
|
|
@@ -47,10 +53,11 @@ public class SavePayResultService {
|
|
|
private String siMzApiUrl;
|
|
|
|
|
|
@Autowired
|
|
|
- public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, ThmzService thmzService, WxRefundService refundService,
|
|
|
+ public SavePayResultService(WxApiDao dao, InpatientDao yjjDao, CouponDao couponDao, ThmzService thmzService, WxRefundService refundService,
|
|
|
PushWxMessageService pushWxMessageService, ElectronicHealthCardService healthCardService) {
|
|
|
this.dao = dao;
|
|
|
this.yjjDao = yjjDao;
|
|
|
+ this.couponDao = couponDao;
|
|
|
this.thmzService = thmzService;
|
|
|
this.refundService = refundService;
|
|
|
this.pushWxMessageService = pushWxMessageService;
|
|
@@ -240,4 +247,30 @@ public class SavePayResultService {
|
|
|
return payTime;
|
|
|
}
|
|
|
|
|
|
+ public String saveCouponPurchase(WxPayOrder order) {
|
|
|
+ String[] decode = Base64.decodeStr(order.getCouponId()).split("-");
|
|
|
+ String couponId = decode[0];
|
|
|
+ CouponAttribute attribute = couponDao.selectSalesmanOperationCouponValue(couponId);
|
|
|
+ if (null == attribute) {
|
|
|
+ String tradeNo = order.getTradeNo();
|
|
|
+ String refund = refundService.autoRefund(tradeNo, "无效的优惠券,领取失败。");
|
|
|
+ if (!refund.startsWith("ERROR:")) {
|
|
|
+ dao.refundOrder(tradeNo, "无效的优惠券,领取失败。");
|
|
|
+ return "ERROR:【无效的优惠券,领取失败。】已为您自动退款,请留意到账信息。";
|
|
|
+ }
|
|
|
+ return "ERROR:【无效的优惠券,领取失败。】自动退款失败,请联系服务中心进行退款。";
|
|
|
+ }
|
|
|
+ attribute.setSalesman(decode[1]);
|
|
|
+ PatientCoupon coupon = new CouponFactory.Builder()
|
|
|
+ .openid(order.getOpenid()).couponAttribute(attribute)
|
|
|
+ .couponSource("SALESMAN_OPERATION").build().make();
|
|
|
+ int insertResponse = couponDao.insert(coupon);
|
|
|
+ log.info("患者领取优惠券:\n参数:{},结果:{}",
|
|
|
+ JSON.toJSONStringWithDateFormat(coupon, "yyyy.MM.dd"), insertResponse);
|
|
|
+ if (insertResponse == 1) {
|
|
|
+ couponDao.updateLeftQuantity(order.getCouponId());
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+ return "领取优惠券失败,请联系管理员。";
|
|
|
+ }
|
|
|
}
|