From f4a0f2acc63d7785eab108419a4e16f5f688cb95 Mon Sep 17 00:00:00 2001 From: yujian <yujian@163.com> Date: 星期六, 18 一月 2020 12:06:27 +0800 Subject: [PATCH] 用户注册信息 --- fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java | 278 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 236 insertions(+), 42 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java index fa99491..3f56d12 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/user/UserLotteryRecordServiceImpl.java @@ -2,6 +2,7 @@ import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import javax.annotation.Resource; @@ -10,15 +11,24 @@ import org.yeshi.utils.DateUtil; import com.yeshi.fanli.dao.mybatis.user.UserLotteryRecordMapper; +import com.yeshi.fanli.entity.bus.user.UserInfoExtra; import com.yeshi.fanli.entity.bus.user.UserLotteryRecord; import com.yeshi.fanli.entity.bus.user.UserSystemCoupon; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.fanli.entity.system.SystemCoupon; import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum; +import com.yeshi.fanli.exception.user.UserInfoExtraException; import com.yeshi.fanli.exception.user.UserLotteryRecordException; import com.yeshi.fanli.exception.user.UserSystemCouponException; +import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.order.CommonOrderCountService; +import com.yeshi.fanli.service.inter.config.SystemCouponService; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; import com.yeshi.fanli.service.inter.user.UserLotteryRecordService; import com.yeshi.fanli.service.inter.user.UserSystemCouponService; +import com.yeshi.fanli.util.StringUtil; + +import net.sf.json.JSONObject; @Service public class UserLotteryRecordServiceImpl implements UserLotteryRecordService { @@ -30,10 +40,13 @@ private ConfigService configService; @Resource - private CommonOrderCountService commonOrderCountService; + private UserSystemCouponService userSystemCouponService; @Resource - private UserSystemCouponService userSystemCouponService; + private SystemCouponService systemCouponService; + + @Resource + private UserInfoExtraService userInfoExtraService; public UserLotteryRecord getLotteryByTypeAndUid(Long uid, String type) { @@ -58,10 +71,9 @@ // 1銆佸ぉ澶╅�佹娊濂栨鏁� num = UserLotteryRecord.COUNT_DAILY_REBATE; } else if(UserLotteryRecord.TYPE_NEWBIES.equals(type)) { - // 2銆佹柊浜烘娊濂� - boolean hasOrder = commonOrderCountService.hasRebateAndShareOrder(uid); - // 鏂扮敤鎴峰瓨鍦�5娆℃娊濂栨満浼� (鏃犺鍗曪細杩斿埄銆佸垎浜鍗�) - if (!hasOrder) { + // 2銆佹柊浜烘娊濂� : 15澶╀箣鍐呴娆$櫥褰曠郴缁� + boolean isNewUser = userInfoExtraService.isNewUser(uid); + if (isNewUser) { num = UserLotteryRecord.COUNT_NEWBIES; } } @@ -83,14 +95,187 @@ record.setUid(uid); record.setType(type); record.setCount(num); + } else { + record.setCount(num); } - return record; } @Override - public Map<String, Object> getLotteryCountDaily(Long uid) throws UserLotteryRecordException,Exception { + public JSONObject getLotteryCountNewbies(Long uid) throws UserLotteryRecordException,Exception { + + if (uid == null || uid == 0) { + throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); + } + + + // 鍏煎1.5.3涔嬪墠鐗堟湰 + UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); + if (userInfoExtra == null) { + throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); + } + + //鎶藉娆℃暟 + int count = 0; + Integer lotteryNewbies = userInfoExtra.getLotteryNewbies(); + if (lotteryNewbies != null) { + count = lotteryNewbies; + } else { + UserLotteryRecord record = getLotteryByTypeAndUid(uid, UserLotteryRecord.TYPE_NEWBIES); + if (record != null) { + count = record.getCount(); + } + } + + // 鎶藉瑙勫垯 + String lotteryRule = configService.get(ConfigKeyEnum.lotteryRuleNewbies.getKey()); + + JSONObject data = new JSONObject(); + data.put("count", count); + data.put("rule", lotteryRule); + return data; + } + + + @Override + public Map<String, Object> executeLotteryNewbies(Long uid) throws UserLotteryRecordException, Exception{ + if (uid == null || uid == 0) { + throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); + } + + UserInfoExtra userInfoExtra = userInfoExtraService.getUserInfoExtra(uid); + if (userInfoExtra == null) { + throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); + } + + int count = 0; + boolean isold = true; + UserLotteryRecord record = null; + + Integer lotteryNewbies = userInfoExtra.getLotteryNewbies(); + if (lotteryNewbies != null) { + // 鑰佺増鐨勬鏁� 鍏煎1.5.3涔嬪墠鐗堟湰 + count = lotteryNewbies; + } else { + isold = false; // 鏂扮増 + record = getLotteryByTypeAndUid(uid, UserLotteryRecord.TYPE_NEWBIES); + if (record != null) { + count = record.getCount(); + } + } + + if (count <= 0) { + throw new UserLotteryRecordException(2, "鎶藉娆℃暟涓嶈冻"); + } + + String prize = null; + String couponType = null; + // 鏂颁汉鎶藉 -宸叉娊涓鍝� + List<UserSystemCoupon> list = userSystemCouponService.getUserCouponBySource(uid, UserSystemCoupon.SOURCE_NEWBIES); + + if (list == null || list.size() == 0) { + prize = getLotteryPrizeNewbies(count, 0, null); + } else if (list.size() == 1) { + + UserSystemCoupon userSystemCoupon = list.get(0); + SystemCoupon systemCoupon = userSystemCoupon.getSystemCoupon(); + if (systemCoupon != null) { + SystemCoupon coupon = systemCouponService.selectByPrimaryKey(systemCoupon.getId()); + couponType = coupon.getType().name(); + } + + if (couponType != null && couponType.trim().length() > 0) { + prize = getLotteryPrizeNewbies(count, 1, couponType); + } + } + + if (prize == null || prize.trim().length() == 0) { + prize = "NoPrize"; + } else if (prize.equals(couponType)) { + // 宸插瓨鍦ㄦ鍒� + prize = "NoPrize"; + } else { + try { + userSystemCouponService.insertUserCoupon(uid, prize, UserSystemCoupon.SOURCE_NEWBIES, null,true); + } catch (UserSystemCouponException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + // 鍑忓皯娆℃暟 + count--; + + // 鏇存柊璁板綍 + if (isold) { + UserInfoExtra extra = new UserInfoExtra(); + extra.setId(userInfoExtra.getId()); + extra.setLotteryNewbies(count); + try { + userInfoExtraService.saveUserInfoExtra(extra); + } catch (UserInfoExtraException e) { + e.printStackTrace(); + } + } else { + UserLotteryRecord updateRecord = new UserLotteryRecord(); + updateRecord.setId(record.getId()); + updateRecord.setCount(count); + updateRecord.setUpdateTime(new Date()); + userLotteryRecordMapper.updateByPrimaryKeySelective(updateRecord); + } + + Map<String,Object> map = new HashMap<String, Object>(); + map.put("count", count); + map.put("result", prize); + return map; + } + + /** + * 鏂颁汉鐢ㄦ埛鎶藉 + * @param count + * @param countPrize + * @param couponType + * @return + */ + @Override + public String getLotteryPrizeNewbies(int count, int countPrize, String couponType) { + String prize = null; + String freeCoupon = CouponTypeEnum.welfareFreeCoupon.name(); // 绂忓埄鍏嶈垂鍒� + String rebateCoupon = CouponTypeEnum.rebatePercentCoupon.name(); // 濂栧姳鍒� + + if (countPrize == 1 && count == 1) { + // 鏈�鍚庝竴娆★細 鍙敹鍒颁竴涓鍝� + if (rebateCoupon.equals(couponType)) { + prize = freeCoupon; // 绂忓埄鍏嶈垂鍒� + } else { + prize = rebateCoupon; // 濂栧姳鍒� + } + } else if (countPrize == 0 && count == 2) { + // 鍚庨潰涓ゆ蹇呬腑 + long result = (1 + Math.round(Math.random() * (9))); + if (result <= 5) { + prize = freeCoupon; // 绂忓埄鍏嶈垂鍒� + } else { + prize = rebateCoupon; // 濂栧姳鍒� + } + } else { + long result = (1 + Math.round(Math.random() * (9))); + if (result <= 3) { + prize = freeCoupon; // 绂忓埄鍏嶈垂鍒� + } else if (result <= 6) { + prize = rebateCoupon; // 濂栧姳鍒� + } + } + return prize; + } + + + + @Override + public JSONObject getLotteryCountDaily(Long uid) throws UserLotteryRecordException,Exception { if (uid == null || uid == 0) { throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); @@ -105,18 +290,17 @@ } // 鎶藉瑙勫垯 - String lotteryRule = configService.get("lottery_rule_newbies"); + String lotteryRule = configService.get(ConfigKeyEnum.lotteryRuleDailyRebate.getKey()); - Map<String,Object> map = new HashMap<String, Object>(); - map.put("count", count); - map.put("rule", lotteryRule); - - return map; + JSONObject data = new JSONObject(); + data.put("count", count); + data.put("rule", lotteryRule); + return data; } @Override - public Map<String, Object> executeLotteryDaily(Long uid) throws UserLotteryRecordException,Exception{ + public Map<String, Object> executeLotteryDaily(Long uid) throws UserLotteryRecordException, Exception{ if (uid == null || uid == 0) { throw new UserLotteryRecordException(1, "鏈櫥褰曠郴缁�"); } @@ -132,28 +316,33 @@ throw new UserLotteryRecordException(2, "鎶藉娆℃暟涓嶈冻"); } - int countPrize = 0; + String prize = null; + // 浠婃棩澶╁ぉ鎶藉-宸叉娊涓嫢鏈夊埜鏁伴噺 + int todayHas = userSystemCouponService.countTodatyUserCouponBySource(uid, UserSystemCoupon.SOURCE_DAILY_REBATE); - - String prize = getLotteryPrizeDaily(countPrize, count); - if (prize == null || prize.trim().length() == 0) { - prize = "NoPrize"; + if (todayHas == 0) { + // 鎶藉 + prize = getLotteryPrizeDaily(count); + LogHelper.test(uid + "涓缁撴灉锛�" + prize); + try { + int num = 0; + if ("rebateCoupon".equals(prize)) { + num = 1; + } else if ("doubleCoupon".equals(prize)) { + num = 2; + } + + // 鎻掑叆濂栧姳鍒� + if (num > 0) { + userSystemCouponService.randomRewardCoupon(num, uid, UserSystemCoupon.SOURCE_DAILY_REBATE); + } + + } catch (UserSystemCouponException e) { + throw new UserLotteryRecordException(1, "鎶藉澶辫触"); + } } - try { - // 鎻掑叆鍒镐俊鎭� - if ("rebateCoupon".equals(prize)) { - String rebateCoupon = CouponTypeEnum.rebatePercentCoupon.name(); // 濂栧姳鍒� - userSystemCouponService.insertUserCoupon(uid, rebateCoupon, UserSystemCoupon.SOURCE_NEWBIES); - } else if ("doubleCoupon".equals(prize)) { - String rebateCoupon = CouponTypeEnum.rebatePercentCoupon.name(); // 濂栧姳鍒� - userSystemCouponService.insertUserCoupon(uid, rebateCoupon, UserSystemCoupon.SOURCE_NEWBIES); - userSystemCouponService.insertUserCoupon(uid, rebateCoupon, UserSystemCoupon.SOURCE_NEWBIES); - } - } catch (UserSystemCouponException e) { - throw new UserLotteryRecordException(1, "鎶藉澶辫触"); - } - + // 鍑忓皯娆℃暟 count--; // 鏇存柊璁板綍 @@ -162,6 +351,12 @@ updateRecord.setCount(count); updateRecord.setUpdateTime(new Date()); userLotteryRecordMapper.updateByPrimaryKeySelective(updateRecord); + + LogHelper.test(uid + "杩斿洖H5涓缁撴灉锛�" + prize); + if (StringUtil.isNullOrEmpty(prize)) { + prize = "NoPrize"; + } + LogHelper.test(uid + "杩斿洖H5涓缁撴灉澶勭悊绌哄�硷細" + prize); Map<String,Object> map = new HashMap<String, Object>(); map.put("count", count); @@ -173,19 +368,18 @@ /** * 濂栧搧鎶藉彇 * - * @param countPrize 宸叉娊娆℃暟 - * @param countUsed 鍒竔d + * @param count 鍓╀綑娆℃暟 * @return */ - public String getLotteryPrizeDaily(int countPrize, int count) { + public String getLotteryPrizeDaily(int count) { String prize = null; String rebateCoupon = "rebateCoupon"; // 涓�寮犲鍔卞埜 - String doubleCoupon = "doubleCoupon"; // 濂栧姳鍒� + String doubleCoupon = "doubleCoupon"; // 涓ゅ紶濂栧姳鍒� - if (countPrize == 0 && count== 1) { - // 鍓╀綑鏈�鍚庝竴娆� 涓旀湭涓鍒欐湰娆″繀涓� + if (count == 1) { + // 鍓╀綑鏈�鍚庝竴娆″繀涓� long result = (1 + Math.round(Math.random() * (9))); if (result <= 7) { prize = rebateCoupon; @@ -194,7 +388,7 @@ } } else { long result = (1 + Math.round(Math.random() * (9))); - if (result <= 2) { + if (result <= 3) { prize = rebateCoupon; } else if (result <= 5) { prize = doubleCoupon; -- Gitblit v1.8.0