| | |
| | | <dependency> |
| | | <groupId>com.ks</groupId> |
| | | <artifactId>facade-vip</artifactId> |
| | | <version>0.1.4</version> |
| | | <version>0.1.7</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.ks</groupId> |
| | | <artifactId>facade-lijin</artifactId> |
| | | <version>0.0.7</version> |
| | | <version>0.0.8</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | |
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException; |
| | | import com.yeshi.fanli.lijin.manager.GoodsLijinMnager; |
| | | import com.yeshi.fanli.lijin.manager.UserLijinMnager; |
| | | import com.yeshi.fanli.lijin.manager.UserLijinSendManager; |
| | | import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service; |
| | | import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service; |
| | | import com.yeshi.fanli.service.inter.pdd.PDDAuthService; |
| | |
| | | private UserLijinMnager userLijinMnager; |
| | | |
| | | @Resource |
| | | private UserLijinSendManager userLijinSendManager; |
| | | |
| | | @Resource |
| | | private PIDManager pidManager; |
| | | @Resource |
| | | private ScanHistoryV2Service scanHistoryV2Service; |
| | |
| | | switch (goodsType) { |
| | | case Constant |
| | | .SOURCE_TYPE_TAOBAO: |
| | | |
| | | if (uid != null) { |
| | | ThreadUtil.run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //小于10块自动发放奖金 |
| | | userLijinSendManager.autoSendLijin(uid, new BigDecimal(10)); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | TaoBaoGoodsBrief goods = getTaoBaoGoods(Long.parseLong(goodsId)); |
| | | |
| | | |
| | |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | |
| | | try { |
| | | userLijinSendManager.autoSendLijin(uid, new BigDecimal(10)); |
| | | userLijinSendManager.autoRecieveLijin(acceptData.getSystem(), acceptData.getDevice(), uid); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | try { |
| | | LiJinExpendRecord record = goodsLijinMnager.createTBLijin(Long.parseLong(goodsId), uid, new Date(user.getCreatetime())); |
| | | String sendUrl = record.getSendUrl(); |
| | | if (StringUtil.isNullOrEmpty(sendUrl)) { |
| | |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | return; |
| | | } catch (LiJinUserException e) { |
| | | if (e.getCode() == LiJinUserException.CODE_USER_BALANCE_NOT_ENOUGH) { |
| | | //TODO 余额不足 |
| | | } |
| | | out.print(JsonUtil.loadFalseResult(2001, "今日领取红包次数超限")); |
| | | return; |
| | | } |
New file |
| | |
| | | package com.yeshi.fanli.controller.client.lijin; |
| | | |
| | | import com.google.gson.*; |
| | | import com.ks.vip.exception.OrderPayException; |
| | | import com.ks.vip.exception.VipOrderException; |
| | | import com.ks.vip.pojo.DO.*; |
| | | import com.ks.vip.pojo.DTO.PayWayInfoDTO; |
| | | import com.ks.vip.pojo.Enums.OrderTypeEnum; |
| | | import com.ks.vip.pojo.Enums.PayWayEnum; |
| | | import com.ks.vip.pojo.Enums.VIPEnum; |
| | | import com.ks.vip.service.LijinRecordService; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum; |
| | | import com.yeshi.fanli.lijin.dto.LijinSendInfo; |
| | | import com.yeshi.fanli.lijin.dto.TodayLijinCreatedInfo; |
| | | import com.yeshi.fanli.lijin.manager.UserLijinMnager; |
| | | import com.yeshi.fanli.lijin.manager.UserLijinSendManager; |
| | | import com.yeshi.fanli.lijin.vo.LijinRecordVO; |
| | | import com.yeshi.fanli.lijin.vo.VIPGradeVO; |
| | | import com.yeshi.fanli.lijin.vo.VipRecordVO; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.util.Constant; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.dubbo.config.annotation.Reference; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.yeshi.utils.*; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.PrintWriter; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/lijin/hongbao") |
| | | public class LijinHongBaoController { |
| | | |
| | | @Resource |
| | | private UserLijinMnager userLijinMnager; |
| | | |
| | | @Resource |
| | | private UserLijinSendManager userLijinSendManager; |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | |
| | | /** |
| | | * 获取红包 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping("getSendingHongBao") |
| | | public void getSendingHongBao(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | LijinSendInfo lijinSendInfo = userLijinSendManager.getSendingLijinInfo(acceptData.getSystem(), acceptData.getDevice(), uid); |
| | | if (lijinSendInfo == null) { |
| | | userLijinSendManager.sendLijin(acceptData.getSystem(), acceptData.getDevice(), uid, new BigDecimal(10)); |
| | | lijinSendInfo = userLijinSendManager.getSendingLijinInfo(acceptData.getSystem(), acceptData.getDevice(), uid); |
| | | } |
| | | if (lijinSendInfo == null) { |
| | | out.print(JsonUtil.loadFalseResult("无红包")); |
| | | return; |
| | | } |
| | | |
| | | Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | |
| | | @Override |
| | | public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { |
| | | return src == null ? new JsonPrimitive(0) : new JsonPrimitive(src.getTime()); |
| | | } |
| | | }).create(); |
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(lijinSendInfo))); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取红包余额 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping("getHongBaoBalance") |
| | | public void getHongBaoBalance(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | BigDecimal balance = userLijinMnager.getLijinBalance(uid); |
| | | if (balance == null) |
| | | balance = new BigDecimal(0); |
| | | BigDecimal using = userLijinMnager.getUsingLijin(uid); |
| | | if (using == null) |
| | | using = new BigDecimal(0); |
| | | |
| | | String recordLink = configService.getValue(ConfigKeyEnum.lijinRecordLink, acceptData.getSystem()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("balance", balance); |
| | | data.put("using", using); |
| | | data.put("recordLink", recordLink); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取红包记录 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping("getHongBaoRecordList") |
| | | public void getHongBaoRecordList(AcceptData acceptData, Long uid, Integer type, int page, PrintWriter out) { |
| | | List<UserLijinRecord> recordList = userLijinMnager.getLijinRecord(uid, type, page, Constant.PAGE_SIZE); |
| | | List<LijinRecordVO> voList = new ArrayList<>(); |
| | | for (UserLijinRecord record : recordList) { |
| | | LijinRecordVO vo = new LijinRecordVO(); |
| | | vo.setCreateTime(record.getCreateTime()); |
| | | vo.setMoney(record.getMoney()); |
| | | vo.setTitle(record.getTitle()); |
| | | vo.setType(record.getType()); |
| | | voList.add(vo); |
| | | } |
| | | |
| | | Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { |
| | | return src == null ? new JsonPrimitive("") : new JsonPrimitive(TimeUtil.getGernalTime(src.getTime(), "yyyy.MM.dd HH:mm:ss")); |
| | | } |
| | | }).create(); |
| | | |
| | | long count = userLijinMnager.countLijinRecord(uid, type); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | | data.put("list", gson.toJson(voList)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | |
| | | @RequestMapping("recieveHongBao") |
| | | public void recieveHongBao(AcceptData acceptData, Long uid, String id, PrintWriter out) { |
| | | try { |
| | | LijinSendInfo lijinSendInfo = userLijinSendManager.recieveLijin(id, uid); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("url", configService.getValue(ConfigKeyEnum.lijinRecievedSuccessLink, acceptData.getSystem()).replace("{name}", lijinSendInfo.getName()).replace("{money}", lijinSendInfo.getMoney() + "")); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | return; |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getMessage())); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | List<TaoBaoGoodsBrief> goodsBriefList = new ArrayList<>(); |
| | | int count = 0; |
| | | try { |
| | | if (goodsId != null) { |
| | | try { |
| | | TaoBaoGoodsBrief goods = TaoKeApiUtil.searchGoodsDetail(goodsId); |
| | |
| | | if (taoBaoGoodsBriefs != null) |
| | | goodsBriefList.addAll(taoBaoGoodsBriefs); |
| | | } |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | |
| | | GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(), |
| | | acceptData.getVersion(), acceptData.getSystem()); |
| | |
| | | vipLink("vip_link", "超级会员升级链接"), // 转移至VIPConfig 已废弃 |
| | | helpLinkVipInfo("help_link_vip_info", "超级会员详情页帮助链接"), // 已废弃 |
| | | lijinVIPLink("lijin_vip_link", "礼金会员链接"), |
| | | lijinRecordLink("lijin_record_link", "礼金记录链接"), |
| | | lijinRecievedSuccessLink("lijin_recieve_success_link", "礼金领取成功链接"), |
| | | |
| | | |
| | | // 文案转链 |
| | | convertDocWebLink("convert_doc_web_link", "文案转链网页"), |
New file |
| | |
| | | package com.yeshi.fanli.lijin.dto; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.annotations.Expose; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | public class LijinSendInfo implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @Expose |
| | | private String id; |
| | | @Expose |
| | | private String name; |
| | | private String category; |
| | | private SystemEnum system; |
| | | private String deviceId; |
| | | @Expose |
| | | private UserInfo user; |
| | | @Expose |
| | | private BigDecimal money; |
| | | @Expose |
| | | private Date expireTime; |
| | | @Expose |
| | | private String md5; |
| | | |
| | | public String getCategory() { |
| | | return category; |
| | | } |
| | | |
| | | public void setCategory(String category) { |
| | | this.category = category; |
| | | } |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public SystemEnum getSystem() { |
| | | return system; |
| | | } |
| | | |
| | | public void setSystem(SystemEnum system) { |
| | | this.system = system; |
| | | } |
| | | |
| | | public String getDeviceId() { |
| | | return deviceId; |
| | | } |
| | | |
| | | public void setDeviceId(String deviceId) { |
| | | this.deviceId = deviceId; |
| | | } |
| | | |
| | | public UserInfo getUser() { |
| | | return user; |
| | | } |
| | | |
| | | public void setUser(UserInfo user) { |
| | | this.user = user; |
| | | } |
| | | |
| | | public BigDecimal getMoney() { |
| | | return money; |
| | | } |
| | | |
| | | public void setMoney(BigDecimal money) { |
| | | this.money = money; |
| | | } |
| | | |
| | | public Date getExpireTime() { |
| | | return expireTime; |
| | | } |
| | | |
| | | public void setExpireTime(Date expireTime) { |
| | | this.expireTime = expireTime; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public void setName(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | public String toMD5() { |
| | | return StringUtil.Md5(new Gson().toJson(this)); |
| | | } |
| | | |
| | | public String getMd5() { |
| | | return md5; |
| | | } |
| | | |
| | | public void setMd5(String md5) { |
| | | this.md5 = md5; |
| | | } |
| | | } |
| | |
| | | import com.ks.lijin.service.LiJinExpendRecordService; |
| | | import com.ks.lijin.service.LiJinLinkService; |
| | | import com.ks.lijin.service.LijinCreateService; |
| | | import com.ks.vip.exception.LijinBalanceException; |
| | | import com.ks.vip.exception.OrderPayException; |
| | | import com.ks.vip.exception.VipOrderException; |
| | | import com.ks.vip.pojo.DO.*; |
| | |
| | | //@Reference(version = "1.0", check = false,url="dubbo://193.112.35.168:20902/com.ks.vip.service.VipOrederPayService") |
| | | @Reference(version = "1.0", check = false) |
| | | private VipOrederPayService vipOrederPayService; |
| | | //@Reference(version = "1.0", check = false,url="dubbo://193.112.35.168:20902/com.ks.vip.service.VipOrederPayService") |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinBalanceService lijinBalanceService; |
| | | |
| | | @Reference(version = "1.0", check = false) |
| | | private LijinRecordService lijinRecordService; |
| | | |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | |
| | | return vipOrederPayService.getAlipayPaySuccessOutOrderNo(params); |
| | | } |
| | | |
| | | public void addLijin(Long uid, BigDecimal money, String title, String category) throws LijinBalanceException { |
| | | lijinBalanceService.addLijin(getUid(uid), money, title, category, null); |
| | | } |
| | | |
| | | public List<UserLijinRecord> getLijinRecord(Long uid, Integer type, int page, int pageSize) { |
| | | return lijinRecordService.listRecord(getUid(uid), type, page, pageSize); |
| | | } |
| | | |
| | | public long countLijinRecord(Long uid, Integer type) { |
| | | return lijinRecordService.countRecord(getUid(uid), type); |
| | | } |
| | | |
| | | public UserLijinRecord getLijinRecord(Long uid, Integer type, String category) { |
| | | return lijinRecordService.getRecord(getUid(uid), type, category, null); |
| | | } |
| | | |
| | | /** |
| | | * 获取礼金余额 |
| | | * |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public BigDecimal getLijinBalance(Long uid) { |
| | | return lijinBalanceService.getBalance(getUid(uid)); |
| | | } |
| | | |
| | | /** |
| | | * 获取使用中的礼金 |
| | | * |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public BigDecimal getUsingLijin(Long uid) { |
| | | return lijinBalanceService.getUsingLijin(getUid(uid)); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.fanli.lijin.manager; |
| | | |
| | | import com.ks.vip.pojo.DO.UserLijinRecord; |
| | | import com.ks.vip.pojo.Enums.VIPEnum; |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.push.DeviceActive; |
| | | import com.yeshi.fanli.lijin.dto.LijinSendInfo; |
| | | import com.yeshi.fanli.service.inter.push.DeviceActiveService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.util.RedisManager; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 用户礼金发放管理器 |
| | | */ |
| | | @Component |
| | | public class UserLijinSendManager { |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @Resource |
| | | private DeviceActiveService deviceActiveService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserLijinMnager userLijinMnager; |
| | | |
| | | |
| | | private String getRedisKey(SystemEnum system, String deviceId, Long uid) { |
| | | String key = "lijinsend-" + system.name() + "-"; |
| | | if (uid != null) { |
| | | key += "uid-" + uid; |
| | | } else { |
| | | key += "device-" + StringUtil.Md5(deviceId); |
| | | } |
| | | return key; |
| | | } |
| | | |
| | | /** |
| | | * 礼金发放 |
| | | * |
| | | * @param system |
| | | * @param deviceId |
| | | * @param uid |
| | | */ |
| | | public void sendLijin(SystemEnum system, String deviceId, Long uid, BigDecimal minMoney) { |
| | | String key = getRedisKey(system, deviceId, uid); |
| | | if (redisManager.hasKey(key)) { |
| | | //还有未领取的礼金 |
| | | return; |
| | | } |
| | | |
| | | if (uid == null) { |
| | | //未登录 |
| | | //查询是否为新设备 |
| | | DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(deviceId); |
| | | if (deviceActive == null || System.currentTimeMillis() - deviceActive.getCreateTime().getTime() < 1000 * 60 * 60 * 48L) { |
| | | //新设备 |
| | | LijinSendInfo sendInfo = new LijinSendInfo(); |
| | | sendInfo.setExpireTime(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 48L)); |
| | | sendInfo.setDeviceId(deviceId); |
| | | sendInfo.setMoney(new BigDecimal("188")); |
| | | sendInfo.setName("新用户福利"); |
| | | sendInfo.setSystem(system); |
| | | sendInfo.setUser(null); |
| | | sendInfo.setId(key); |
| | | sendInfo.setCategory(UserLijinRecord.Category.newer.name()); |
| | | sendInfo.setMd5(sendInfo.toMD5()); |
| | | redisManager.saveObj(sendInfo, key, 60 * 60 * 48); |
| | | return; |
| | | } else { |
| | | //非新设备不发送 |
| | | return; |
| | | } |
| | | } else { |
| | | //已登录 |
| | | //查询是否为新用户ID |
| | | UserInfo userInfo = userInfoService.getUserByIdWithMybatis(uid); |
| | | if (userInfo == null) { |
| | | return; |
| | | } |
| | | |
| | | UserInfo simpleUser = new UserInfo(); |
| | | simpleUser.setId(userInfo.getId()); |
| | | simpleUser.setNickName(userInfo.getNickName()); |
| | | simpleUser.setPortrait(userInfo.getPortrait()); |
| | | |
| | | if (System.currentTimeMillis() - userInfo.getCreatetime() < 1000 * 60 * 60 * 48L) { |
| | | |
| | | //是否已经领取过新人红包 |
| | | UserLijinRecord record = userLijinMnager.getLijinRecord(uid, null, UserLijinRecord.Category.newer.name()); |
| | | if (record == null) { |
| | | //新用户 |
| | | LijinSendInfo sendInfo = new LijinSendInfo(); |
| | | sendInfo.setExpireTime(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 48L)); |
| | | sendInfo.setDeviceId(deviceId); |
| | | sendInfo.setMoney(new BigDecimal("188")); |
| | | sendInfo.setSystem(system); |
| | | sendInfo.setUser(simpleUser); |
| | | sendInfo.setId(key); |
| | | sendInfo.setName("新用户福利"); |
| | | sendInfo.setCategory(UserLijinRecord.Category.newer.name()); |
| | | sendInfo.setMd5(sendInfo.toMD5()); |
| | | redisManager.saveObj(sendInfo, key, 60 * 60 * 48); |
| | | return; |
| | | } |
| | | } |
| | | //是否余额已经不足 |
| | | BigDecimal balance = userLijinMnager.getLijinBalance(uid); |
| | | if (balance != null && balance.compareTo(minMoney) >= 0) { |
| | | //余额充足 |
| | | return; |
| | | } |
| | | |
| | | LijinSendInfo sendInfo = new LijinSendInfo(); |
| | | sendInfo.setExpireTime(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 48L)); |
| | | sendInfo.setDeviceId(deviceId); |
| | | sendInfo.setSystem(system); |
| | | sendInfo.setUser(simpleUser); |
| | | sendInfo.setId(key); |
| | | //老用户 |
| | | String[] normal = new String[]{"66.66", "88.88", "99.99"}; |
| | | String[] vip = new String[]{"166.66", "188.88", "199.99"}; |
| | | VIPEnum rank = userLijinMnager.getVIPRank(uid); |
| | | if (rank == VIPEnum.silver) { |
| | | //白银 |
| | | sendInfo.setMoney(new BigDecimal(normal[(int) (normal.length * Math.random())])); |
| | | sendInfo.setName("白银会员福利"); |
| | | } else { |
| | | sendInfo.setMoney(new BigDecimal(vip[(int) (vip.length * Math.random())])); |
| | | sendInfo.setName("铂金会员福利"); |
| | | } |
| | | sendInfo.setMd5(sendInfo.toMD5()); |
| | | redisManager.saveObj(sendInfo, key, 60 * 60 * 48); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取发放中的礼金信息 |
| | | * |
| | | * @param system |
| | | * @param deviceId |
| | | * @param uid |
| | | */ |
| | | public LijinSendInfo getSendingLijinInfo(SystemEnum system, String deviceId, Long uid) { |
| | | String key = getRedisKey(system, deviceId, uid); |
| | | return (LijinSendInfo) redisManager.getObj(LijinSendInfo.class, key); |
| | | } |
| | | |
| | | /** |
| | | * 领取礼金 |
| | | * |
| | | * @param id |
| | | */ |
| | | public LijinSendInfo recieveLijin(String id, Long uid) throws Exception { |
| | | LijinSendInfo lijinSendInfo = (LijinSendInfo) redisManager.getObj(LijinSendInfo.class, id); |
| | | if (lijinSendInfo == null) |
| | | throw new Exception("红包为空"); |
| | | if (System.currentTimeMillis() > lijinSendInfo.getExpireTime().getTime()) { |
| | | throw new Exception("红包已过期"); |
| | | } |
| | | |
| | | //判断是否是新人红包 |
| | | if(lijinSendInfo.getCategory().equalsIgnoreCase(UserLijinRecord.Category.newer.name())){ |
| | | UserLijinRecord record = userLijinMnager.getLijinRecord(uid, null, UserLijinRecord.Category.newer.name()); |
| | | if(record!=null){ |
| | | throw new Exception("已领过新人红包"); |
| | | } |
| | | } |
| | | |
| | | |
| | | userLijinMnager.addLijin(uid, lijinSendInfo.getMoney(), lijinSendInfo.getName(), lijinSendInfo.getCategory()); |
| | | redisManager.removeKey(id); |
| | | return lijinSendInfo; |
| | | } |
| | | |
| | | /** |
| | | * 自动发送礼金 |
| | | * |
| | | * @param uid |
| | | * @param minMoney |
| | | */ |
| | | public void autoSendLijin(Long uid, BigDecimal minMoney) { |
| | | UserInfo user = userInfoService.getUserByIdWithMybatis(uid); |
| | | BigDecimal balance = userLijinMnager.getLijinBalance(uid); |
| | | if (balance == null || balance.compareTo(minMoney) < 0) { |
| | | sendLijin(user.getSystem(), null, uid, minMoney); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 自动领取礼金 |
| | | * |
| | | * @param system |
| | | * @param deviceId |
| | | * @param uid |
| | | * @throws Exception |
| | | */ |
| | | public void autoRecieveLijin(SystemEnum system, String deviceId, Long uid) throws Exception { |
| | | LijinSendInfo sendInfo = getSendingLijinInfo(system, deviceId, uid); |
| | | if (sendInfo != null) { |
| | | recieveLijin(sendInfo.getId(), uid); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.fanli.lijin.vo; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | public class LijinRecordVO { |
| | | private String title; |
| | | private Integer type; |
| | | private BigDecimal money; |
| | | private Date createTime; |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public Integer getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(Integer type) { |
| | | this.type = type; |
| | | } |
| | | |
| | | public BigDecimal getMoney() { |
| | | return money; |
| | | } |
| | | |
| | | public void setMoney(BigDecimal money) { |
| | | this.money = money; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | } |
| | |
| | | * @param key |
| | | * @param value |
| | | */ |
| | | private void removeKey(String key) { |
| | | public void removeKey(String key) { |
| | | Jedis jedis = getJedis(); |
| | | try { |
| | | jedis.del(key); |
| | |
| | | Jedis jedis = getJedis(); |
| | | try { |
| | | jedis.expire(key, seconds); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | } |
| | | |
| | | public boolean hasKey(String key) { |
| | | Jedis jedis = getJedis(); |
| | | try { |
| | | return jedis.exists(key); |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public Class<?> getObj(Class<?> clazz, String key) { |
| | | public Object getObj(Class<?> clazz, String key) { |
| | | String value = getCommonString(key); |
| | | return (Class<?>) new Gson().fromJson(value, clazz); |
| | | return new Gson().fromJson(value, clazz); |
| | | } |
| | | |
| | | /** |