您的位置:首页 > 移动开发 > 微信开发

微信小程序转发链接交互逻辑

2017-12-28 00:00 393 查看
摘要: 业务逻辑:用户A转发给用户B,用户A和B都收到一个服务通知,用户B再次点击转发链接双方不会收到服务通知,针对同一封贺卡 同一个用户只能收到一条模版消息.

/**
* 保存卡券
*/
public void sendAndSave(CouponDTO couponDTO) {
Long cardId = couponDTO.getCardId();
Long userId = SecurityUtils.getCurrentUserId();

//formId不能为空
if (StringUtils.isEmpty(couponDTO.getFormId())) {
throw new BaseAppException("formId不能为空");
}
//当前用户是否是卡的创建人
Card card = cardRepository.findOne(cardId);
if(userId.equals(card.getCreateId())){
return;
}

//如果当前用户已经点开过
List<Coupon> couponForCurrentIds = couponRepository.findByCardIdAndReceiveId(cardId,userId);

//当前用户添加十张卡券(不考虑使用情况)[当前用户]
List<Coupon> sumCouponForCurrentIds = couponRepository.findByReceiveId(userId);

String templateId = applicationProperties.getTemplateId();//模板消息id
String accessToken = getAccessToken().get("accessToken");
Card cardCoupon = new Card();
cardCoupon.setId(couponDTO.getCardId());
if(couponForCurrentIds.size() == 0 && sumCouponForCurrentIds.size() < 10){
//给当前用户发送微信信息
String openIdForCurrentUser = SecurityUtils.getCurrentUser().getOpenId();
String formIdForCurrentUser =  couponDTO.getFormId();
templateItem(openIdForCurrentUser, templateId, accessToken, formIdForCurrentUser);

//保存当前用户的券记录
Coupon coupon = new Coupon();
coupon.setReceiveId(SecurityUtils.getCurrentUserId());
coupon.setCard(cardCoupon);
save(coupon);
}

//制卡人是否已收到券信息
List<Coupon> couponForCreateIds = couponRepository.findByCardIdAndReceiveId(cardId,card.getCreateId());

//当前用户添加十张卡券(不考虑使用情况)[当前用户]
List<Coupon> sumCouponForCreateIds = couponRepository.findByReceiveId(userId);

if(couponForCreateIds.size()==0 && sumCouponForCreateIds.size() < 10){
//给制卡人发送微信信息
String openIdForCreateId = userInfoRepository.findOne(card.getCreateId()).getOpenId();
//创建贺卡用户模板 创建者的formId从表单表里面取
Form form = formRepository.findByCreateIdAndCardId(card.getCreateId(),cardId);
//form为空或超过7天,无法发送模板消息
if (form == null || form.getFailureTime().toInstant().toEpochMilli() < ZonedDateTime.now().toInstant().toEpochMilli()) {
return;
}
String formIdForCreateId = form.getFormId();
templateItem(openIdForCreateId, templateId, accessToken, formIdForCreateId);

//保存制卡人的券记录
Coupon couponForCreateId = new Coupon();
couponForCreateId.setReceiveId(card.getId());
couponForCreateId.setCard(cardCoupon);
save(couponForCreateId);
}
//修改分享状态
card.setState(1);
cardRepository.save(card);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  微信小程序