微信小程序转发链接交互逻辑
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); }
相关文章推荐
- 微信小程序入门二之逻辑层与表现层的数据交互
- 微信小程序 转发功能的实现
- 【微信小程序】事件交互案例演示
- 微信小程序-订单评价交互样式(WXML&WXSS&JS)
- 微信小程序开发《6 .框架之逻辑层》
- 小程序web-view跳转外部链接,微信小程序打开url外部链接
- 转发程序无法决定链接类型 推荐
- 微信小程序 各种页面特效链接
- 微信小程序转发功能
- 微信小程序如何转发给朋友?
- 微信转发链接不显示图片和描述文字
- 微信小程序开发教程(七)逻辑层——.js详解
- 提示:微信小程序开发教程链接
- 微信小程序 视图层(xx.xml)和逻辑层(xx.js)详细介绍
- 微信小程序教学第三章(含视频):小程序中级实战教程:列表-页面逻辑处理
- 微信小程序 简单DEMO布局,逻辑,样式的练习
- 微信小程序——智能小秘“遥知之”(语义理解基于olami,源码见原文链接,PC端打开)
- 微信小程序-页面链接
- 微信小程序返回上级页面时单个数据交互
- 从零开始学微信小程序开发:7 交互反馈