|
@@ -1,5 +1,6 @@
|
|
|
package thyyxxk.wxservice_server.service;
|
|
|
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -33,13 +34,42 @@ public class CouponService {
|
|
|
.openid(openid).couponAttribute(attribute)
|
|
|
.couponSource(source).build().make();
|
|
|
int insertResponse = dao.insert(coupon);
|
|
|
- log.info("发放问卷调查礼品卡券:\n参数:{},结果:{}", JSON.toJSON(coupon), insertResponse);
|
|
|
+ log.info("发放问卷调查礼品卡券:\n参数:{},结果:{}",
|
|
|
+ JSON.toJSONStringWithDateFormat(coupon, "yyyy.MM.dd"), insertResponse);
|
|
|
if (insertResponse == 1) {
|
|
|
return "SUCCESS";
|
|
|
}
|
|
|
return "问卷调查礼品卡券发放失败,请联系管理员。";
|
|
|
}
|
|
|
|
|
|
+ public synchronized String receiveSalesmanCoupon(String key) {
|
|
|
+ String openid = TokenUtil.getInstance().getUserOpenid();
|
|
|
+ String[] decode = Base64.decodeStr(key).split("-");
|
|
|
+ String couponId = decode[0];
|
|
|
+ CouponAttribute attribute = dao.selectSalesmanOperationCouponValue(couponId);
|
|
|
+ if (null == attribute) {
|
|
|
+ return "无效的优惠券。";
|
|
|
+ }
|
|
|
+ int sameCouponCount = dao.selectSameSalesmanOperationCouponCount(openid, couponId);
|
|
|
+ if (sameCouponCount > 0) {
|
|
|
+ return "您已领取过此优惠券,无法继续领取。";
|
|
|
+ }
|
|
|
+ if (attribute.getLeftQuantity() < 1) {
|
|
|
+ return "优惠券已无余量,领取失败。";
|
|
|
+ }
|
|
|
+ attribute.setSalesman(decode[1]);
|
|
|
+ PatientCoupon coupon = new CouponFactory.Builder()
|
|
|
+ .openid(openid).couponAttribute(attribute)
|
|
|
+ .couponSource("SALESMAN_OPERATION").build().make();
|
|
|
+ int insertResponse = dao.insert(coupon);
|
|
|
+ log.info("患者领取优惠券:\n参数:{},结果:{}",
|
|
|
+ JSON.toJSONStringWithDateFormat(coupon, "yyyy.MM.dd"), insertResponse);
|
|
|
+ if (insertResponse == 1 && dao.updateLeftQuantity(couponId) == 1) {
|
|
|
+ return "SUCCESS";
|
|
|
+ }
|
|
|
+ return "领取优惠券失败,请联系管理员。";
|
|
|
+ }
|
|
|
+
|
|
|
public GetCouponResponse getMyCoupons(String hisOrdNum) {
|
|
|
String openid = TokenUtil.getInstance().getUserOpenid();
|
|
|
boolean isMedins = ifMedinsExist(hisOrdNum);
|
|
@@ -56,13 +86,11 @@ public class CouponService {
|
|
|
response.setUsableCoupons(usableCouponList);
|
|
|
response.setUnusableCoupons(new ArrayList<>());
|
|
|
}
|
|
|
-
|
|
|
List<PatientCoupon> unusableCoupons = dao.selectCouponsByState(openid, CouponState.EXPIRED);
|
|
|
List<CouponModel> unusableCouponList = new ArrayList<>();
|
|
|
for (PatientCoupon coupon : unusableCoupons) {
|
|
|
unusableCouponList.add(new CouponModel.Builder().build(coupon, isMedins));
|
|
|
}
|
|
|
-
|
|
|
response.getUnusableCoupons().addAll(unusableCouponList);
|
|
|
return response;
|
|
|
}
|