From 62a447d89331aee1feae7724c7616aa1bb2cfe79 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 16 十月 2024 14:28:37 +0800 Subject: [PATCH] 将CMQ替换为rabbitmq --- fanli/src/main/java/com/yeshi/fanli/controller/client/v2/RedPackControllerV2.java | 1115 +++++++++++++++++++++++++++++----------------------------- 1 files changed, 558 insertions(+), 557 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/RedPackControllerV2.java b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/RedPackControllerV2.java index f5bfbef..3119166 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/RedPackControllerV2.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/client/v2/RedPackControllerV2.java @@ -1,557 +1,558 @@ -package com.yeshi.fanli.controller.client.v2; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Type; -import java.math.BigDecimal; -import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; - -import javax.annotation.Resource; - -import com.yeshi.fanli.util.*; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.yeshi.utils.JsonUtil; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.yeshi.fanli.entity.accept.AcceptData; -import com.yeshi.fanli.entity.bus.user.ThreeSale; -import com.yeshi.fanli.entity.bus.user.UserInfo; -import com.yeshi.fanli.entity.common.AdminUser; -import com.yeshi.fanli.entity.common.Config; -import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum; -import com.yeshi.fanli.entity.redpack.RedPackExchange; -import com.yeshi.fanli.entity.redpack.RedPackWinInvite; -import com.yeshi.fanli.entity.redpack.RedPackWinInvite.RedPackWinInviteTypeEnum; -import com.yeshi.fanli.entity.system.ConfigKeyEnum; -import com.yeshi.fanli.exception.redpack.RedPackExchangeException; -import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException; -import com.yeshi.fanli.service.AdminUserService; -import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; -import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; -import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; -import com.yeshi.fanli.service.inter.redpack.RedPackConfigService; -import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; -import com.yeshi.fanli.service.inter.redpack.RedPackExchangeService; -import com.yeshi.fanli.service.inter.redpack.RedPackForbidService; -import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService; -import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService; -import com.yeshi.fanli.service.inter.user.UserInfoExtraService; -import com.yeshi.fanli.service.inter.user.UserInfoService; -import com.yeshi.fanli.service.inter.user.UserSystemCouponService; -import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; -import com.yeshi.fanli.util.email.MailSenderUtil; -import com.yeshi.fanli.vo.redpack.RedPackDetailVO; -import com.yeshi.fanli.vo.redpack.RedPackGiveVO; -import com.yeshi.fanli.vo.redpack.RedPackWinInviteVO; -import com.yeshi.fanli.vo.redpack.RedPackWinProgressVO; - -import net.sf.json.JSONObject; - -@Controller -@RequestMapping("api/v2/redpack") -public class RedPackControllerV2 { - - @Resource - private RedPackConfigService redPackConfigService; - - @Resource - private RedPackBalanceService redPackBalanceService; - - @Resource - private RedPackDetailService redPackDetailService; - - @Resource - private RedPackGiveRecordService redPackGiveRecordService; - - @Resource - private RedPackExchangeService redPackExchangeService; - - @Resource - private RedPackWinInviteService redPackWinInviteService; - - @Resource - private UserInfoService userInfoService; - - @Resource - private UserInfoExtraService userInfoExtraService; - - @Resource - private JumpDetailV2Service jumpDetailV2Service; - - @Resource - private SwiperPictureService swiperPictureService; - - @Resource - private UserSystemCouponService userSystemCouponService; - - @Resource - private RedPackForbidService redPackForbidService; - - @Resource - private ThreeSaleSerivce threeSaleSerivce; - - @Resource - private ConfigService configService; - - @Resource - private AdminUserService adminUserService; - - /** - * 缁熻 - * - * @param acceptData - * @param uid - * @param out - */ - @RequestMapping(value = "countInfo", method = RequestMethod.POST) - public void countInfo(AcceptData acceptData, Long uid, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - BigDecimal zero = new BigDecimal(0); - BigDecimal todayWin = zero; - BigDecimal yesterdayWin = zero; - BigDecimal thisMonthWin = zero; - BigDecimal lastMonthWin = zero; - - BigDecimal todayUse = zero; - BigDecimal yesterdayUse = zero; - BigDecimal thisMonthUse = zero; - BigDecimal lastMonthUse = zero; - BigDecimal balance = redPackBalanceService.getBalance(uid); - ; - if (balance == null) { - balance = zero; - } else { - // 鑾峰緱 - todayWin = redPackDetailService.countAddMoneyByDate(uid, 1); - yesterdayWin = redPackDetailService.countAddMoneyByDate(uid, 2); - thisMonthWin = redPackDetailService.countAddMoneyByDate(uid, 3); - lastMonthWin = redPackDetailService.countAddMoneyByDate(uid, 4); - - // 娑堣�� - todayUse = redPackDetailService.countUseMoneyByDate(uid, 1); - if (todayUse == null || todayUse.compareTo(zero) > 0) { - todayUse = zero; - } - - yesterdayUse = redPackDetailService.countUseMoneyByDate(uid, 2); - if (yesterdayUse == null || yesterdayUse.compareTo(zero) > 0) { - yesterdayUse = zero; - } - thisMonthUse = redPackDetailService.countUseMoneyByDate(uid, 3); - if (thisMonthUse == null || thisMonthUse.compareTo(zero) > 0) { - thisMonthUse = zero; - } - lastMonthUse = redPackDetailService.countUseMoneyByDate(uid, 4); - if (lastMonthUse == null || lastMonthUse.compareTo(zero) > 0) { - lastMonthUse = zero; - } - } - - List<String> tips = new ArrayList<String>(); - tips.add("绾㈠寘浣欓鈮�20鍏冨悗鍙彁鐜帮紝褰撳墠浣欓涓嶈冻锛岃缁х画鍔犳补鍝︼紒"); - tips.add("浣犱篃鍙互閫夋嫨浣跨敤绾㈠寘锛屼韩鍙楃粰鍔涙姌鎵c��"); - String giveMin = redPackConfigService.getValueByKey("give_money_min"); - String giveMax = redPackConfigService.getValueByKey("give_money_max"); - - // 姝e湪鎻愮幇閲戦 - BigDecimal extractingMoney = redPackExchangeService.countMoneyByUidAndState(uid, RedPackExchange.STATE_INIT); - - JSONObject data = new JSONObject(); - data.put("balance", balance.setScale(2).toString()); - data.put("helpLink", redPackConfigService.getValueByKey("desc_help_link")); - data.put("giveMin", giveMin); - data.put("giveMax", giveMax); - data.put("giveDesc", "娉�:绾㈠寘璧犻�侀噾棰濊嚦灏�" + giveMin + "鍏冭嚦澶�" + giveMax + "鍏�"); - - if (extractingMoney != null && extractingMoney.compareTo(zero) > 0) - data.put("extractingInfo", "鎻愮幇涓細楼" + extractingMoney.setScale(2)); - - data.put("extractShortage", tips); - data.put("extractMin", redPackConfigService.getValueByKey("extract_money_min")); - data.put("extractMax", redPackConfigService.getValueByKey("extract_money_max")); - data.put("extractBanlenMin", redPackConfigService.getValueByKey("extract_banlen_min")); - data.put("extractDesc", "娉細3涓伐浣滄棩鍐呭畬鎴愬鏍革紝绾㈠寘鎻愮幇鎴愬姛鍚庡皢浼氳繘鍏ュ埌浣欓銆�"); - data.put("giveTotal", redPackGiveRecordService.countGiveList(uid)); - data.put("useLink", redPackConfigService.getValueByKey("use_link")); - data.put("winLink", redPackConfigService.getValueByKey("invite_win_redpack_link")); - - data.put("todayWin", todayWin.setScale(2).toString()); - data.put("yesterdayWin", yesterdayWin.setScale(2).toString()); - data.put("thisMonthWin", thisMonthWin.setScale(2).toString()); - data.put("lastMonthWin", lastMonthWin.setScale(2).toString()); - data.put("todayUse", todayUse.setScale(2).toString().replaceAll("-", "")); - data.put("yesterdayUse", yesterdayUse.setScale(2).toString().replaceAll("-", "")); - data.put("thisMonthUse", thisMonthUse.setScale(2).toString().replaceAll("-", "")); - data.put("lastMonthUse", lastMonthUse.setScale(2).toString().replaceAll("-", "")); - out.print(JsonUtil.loadTrueResult(data)); - } - - /** - * 鏄庣粏璇︽儏鍒楄〃 - * - * @param acceptData - * @param uid - * @param index List鏈�鏈殑涓婚敭ID - * @param year 骞翠唤 - * @param month 鏈堜唤 - * @param out - */ - @RequestMapping(value = "getMoneyDetails") - public void getMoneyDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, - PrintWriter out) { - if (uid == null || uid == 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - if ((year == null && month != null) || (year != null && month == null)) { - out.print(JsonUtil.loadFalseResult(1, "鏃ユ湡涓嶅畬鏁�")); - return; - } - - Date date = null; - - if (year != null && month != null) { - date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M")); - Calendar ca = Calendar.getInstance(); - ca.setTime(date); - ca.add(Calendar.MONTH, 1); - date = new Date(ca.getTimeInMillis() - 1); - } - - // 鏌ヨ鍒楄〃 - List<RedPackDetailVO> list = redPackDetailService.listUserMoneyDetailForClient(uid, index, date); - // 缁熻鎬绘潯鏁� - long count = redPackDetailService.countUserMoneyDetailForClient(uid, index, date); - - GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); - gsonBuilder.registerTypeAdapter(RedPackDetailTypeEnum.class, new TypeAdapter<RedPackDetailTypeEnum>() { - @Override - public RedPackDetailTypeEnum read(JsonReader arg0) throws IOException { - return null; - } - - @Override - public void write(JsonWriter out, RedPackDetailTypeEnum arg1) throws IOException { - out.beginObject(); - out.name("portrait").value(arg1.getPicture()); - out.endObject(); - } - }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { - @Override - public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { - if (value == null) { - return new JsonPrimitive(""); - } else { - return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm")); - } - } - }).registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() { - @Override - public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) { - if (value == null) { - return new JsonPrimitive(""); - } else { - // 淇濈暀2浣嶅皬鏁� - value = value.setScale(2); - return new JsonPrimitive(value.toString()); - } - } - }); - - Gson gson = gsonBuilder.create(); - - JSONObject data = new JSONObject(); - data.put("count", count); - data.put("data", gson.toJson(list)); - out.print(JsonUtil.loadTrueResult(data)); - } - - /** - * 璧犻�佺孩鍖� - * - * @param acceptData - * @param uid - * @param amount - * @param out - */ - @RequestMapping(value = "giving", method = RequestMethod.POST) - public void giving(AcceptData acceptData, Long uid, BigDecimal amount, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - try { - String tips = redPackGiveRecordService.giving(uid, amount); - out.print(JsonUtil.loadTrueResult(tips)); - } catch (RedPackGiveRecordException e) { - out.print(JsonUtil.loadFalseResult(1, e.getMsg())); - } - } - - @RequestMapping(value = "getGiveList", method = RequestMethod.POST) - public void getGiveList(AcceptData acceptData, Integer page, Long uid, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - if (page == null || page <= 0) - page = 1; - - try { - List<RedPackGiveVO> list = redPackGiveRecordService.getGiveList(page, Constant.PAGE_SIZE, uid); - - GsonBuilder gsonBuilder = new GsonBuilder(); - Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy.MM.dd HH:mm").create(); - - JSONObject data = new JSONObject(); - data.put("list", gson.toJson(list)); - data.put("count", redPackGiveRecordService.countGiveList(uid)); - out.print(JsonUtil.loadTrueResult(data)); - } catch (Exception e) { - e.printStackTrace(); - out.print(JsonUtil.loadFalseResult(1, "鏌ヨ澶辫触")); - } - } - - /** - * 杞崲绾㈠寘涓虹湡瀹為噾閽� - * - * @param acceptData - * @param uid - * @param amount - * @param out - */ - @RequestMapping(value = "exchangeCash", method = RequestMethod.POST) - public void exchangeCash(AcceptData acceptData, Long uid, BigDecimal amount, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - try { - redPackExchangeService.exchangeCash(uid, amount); - out.print(JsonUtil.loadTrueResult("鎻愮幇鐢宠鎴愬姛")); - - ThreadUtil.run(new Runnable() { - @Override - public void run() { - JSONObject json = new JSONObject(); - json.put("timeStamp", java.lang.System.currentTimeMillis()); - json.put("adminId", 4L); - String sign = AESUtil.encrypt(json.toString(), Constant.ADMINH5_AESKEY); - String url = ""; - try { - url = String.format("%s?from=emailh5&sign=%s", - Constant.systemCommonConfig.getExtractNotifyUrl(), URLEncoder.encode(sign, "UTF-8")); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - - long[] targetUids = new long[] { 3L, 4L }; - Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(), SystemInfoUtil.getSystem(acceptData)); - String[] sts = config.getValue().split(","); - String account = sts[0]; - String pwd = sts[1]; - for (long adminId : targetUids) { - AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId); - String msg = "鏈夌敤鎴烽噰鐢ㄧ孩鍖呭厬鎹㈢幇閲�"; - boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "绾㈠寘鍏戞崲鐜伴噾鎻愰啋", msg); - } - } - }); - - } catch (RedPackExchangeException e) { - out.print(JsonUtil.loadFalseResult(1, e.getMsg())); - } - } - - /** - * 绾㈠寘閭�璇疯繘搴� - * - * @param acceptData - * @param page - * @param uid - * @param out - */ - @RequestMapping(value = "getRewardList") - public void getRewardList(AcceptData acceptData, Integer page, Long uid, String callback, PrintWriter out) { - if (uid == null || uid <= 0) { - out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - if (page == null || page < 1) { - out.print(JsonUtil.loadFalseResult(1, "椤电爜涓嶆纭�")); - return; - } - - List<RedPackWinInviteVO> list = new ArrayList<RedPackWinInviteVO>(); - - List<RedPackWinInvite> listRecord = redPackWinInviteService.getRewardList((page - 1) * Constant.PAGE_SIZE, - Constant.PAGE_SIZE, uid); - if (listRecord != null && !listRecord.isEmpty()) { - for (RedPackWinInvite record : listRecord) { - UserInfo user = null; - RedPackWinInviteVO winVO = new RedPackWinInviteVO(); - RedPackWinInviteTypeEnum type = record.getType(); - if (RedPackWinInviteTypeEnum.newUserReward == type) { - user = userInfoService.selectByPKey(uid); - } else { - user = userInfoService.selectByPKey(record.getTeamUid()); - } - winVO.setPortrait(user.getPortrait()); - winVO.setNickName(user.getNickName()); - winVO.setDesc(type.getDesc()); - winVO.setMoney(record.getMoney().toString()); - list.add(winVO); - } - } - - JSONObject data = new JSONObject(); - data.put("winMoney", redPackWinInviteService.getRewardMoney(uid).setScale(2)); - data.put("count", redPackWinInviteService.countRewardRecord(uid)); - data.put("list", JsonUtil.getApiCommonGson().toJson(list)); - if (!StringUtil.isNullOrEmpty(callback)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - } else { - out.print(JsonUtil.loadTrueResult(data)); - } - } - - /** - * 鐢ㄦ埛鍩虹淇℃伅 - * - * @param acceptData - * @param uid - * @param out - */ - @RequestMapping(value = "getBasicInfo") - public void getBasicInfo(AcceptData acceptData, Long uid, String callback, PrintWriter out) { - if (uid == null || uid <= 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - JSONObject data = new JSONObject(); - data.put("balance", redPackBalanceService.getBalance(uid)); - data.put("ruleLink", redPackConfigService.getValueByKey("invite_reward_rule_link")); - data.put("shareLink", UserInviteUtil.getShareUrl(uid)); - data.put("redPackLock", redPackForbidService.verifyForbid(uid)); - - String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); - if (!StringUtil.isNullOrEmpty(inviteCode)) { - data.put("inviteCode", inviteCode); - } else { - data.put("inviteCode", ""); - } - - // 璧犻�佸厤鍗曞埜 - long freeCouponCount = userSystemCouponService.countGiveFreeCoupon(uid); - // 濂栧姳鍒� - long rewardCouponCount = userSystemCouponService.countUsableRewardCoupon(uid); - - data.put("freeCouponCount", freeCouponCount); - data.put("rewardCouponCount", rewardCouponCount); - - if (!StringUtil.isNullOrEmpty(callback)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - } else { - out.print(JsonUtil.loadTrueResult(data)); - } - } - - /** - * 璇ョ敤鎴烽個璇峰閲戞 - * - * @param acceptData - * @param uid 涓嬬嚎UID - * @param out - */ - @RequestMapping(value = "getInviteReward") - public void getInviteReward(AcceptData acceptData, Integer page, Long uid, String callback, PrintWriter out) { - if (uid == null || uid <= 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); - return; - } - - if (page == null || page < 1) - page = 1; - - List<RedPackWinProgressVO> listVO = new ArrayList<RedPackWinProgressVO>(); - List<RedPackWinInvite> list = redPackWinInviteService.getWinTopListByBossId(page, Constant.PAGE_SIZE, uid); - if (list != null) { - for (RedPackWinInvite win : list) { - ThreeSale threeSale = threeSaleSerivce.getNearRelationByBossIdAndWorkerId(uid, win.getTeamUid()); - if (threeSale == null) - continue; - - UserInfo userInfo = userInfoService.selectByPKey(win.getTeamUid()); - if (userInfo == null) - continue; - - RedPackWinProgressVO progressVO = new RedPackWinProgressVO(); - progressVO.setUid(userInfo.getId()); - progressVO.setName(userInfo.getNickName()); - progressVO.setPortrait(userInfo.getPortrait()); - progressVO.setMoney(win.getMoney().setScale(2).toString()); - progressVO.setTime("閭�璇凤細" + TimeUtil.formatDate(threeSale.getSucceedTime())); - listVO.add(progressVO); - } - } - - JSONObject data = new JSONObject(); - data.put("list", listVO); - data.put("count", redPackWinInviteService.countWinTopListByBossId(uid)); - if (!StringUtil.isNullOrEmpty(callback)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - } else { - out.print(JsonUtil.loadTrueResult(data)); - } - } - - /** - * 璇ョ敤鎴烽個璇疯繘搴� - * - * @param acceptData - * @param tid 涓嬬嚎UID - * @param out - */ - @RequestMapping(value = "getInviteProgress") - public void getInviteProgress(AcceptData acceptData, Long uid, Long tid, String callback, PrintWriter out) { - if (uid == null || uid <= 0 || tid == null || tid <= 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "浼犻�掑弬鏁扮己澶�")); - return; - } - - JSONObject data = new JSONObject(); - data.put("list", redPackWinInviteService.getInviteProgressByWorkerId(uid, tid)); - data.put("num", redPackWinInviteService.countTeamNumByTid(uid, tid)); - if (!StringUtil.isNullOrEmpty(callback)) { - out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); - } else { - out.print(JsonUtil.loadTrueResult(data)); - } - } -} +package com.yeshi.fanli.controller.client.v2; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Type; +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import com.yeshi.fanli.util.*; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.yeshi.utils.JsonUtil; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.google.gson.JsonPrimitive; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.yeshi.fanli.entity.accept.AcceptData; +import com.yeshi.fanli.entity.bus.user.ThreeSale; +import com.yeshi.fanli.entity.bus.user.UserInfo; +import com.yeshi.fanli.entity.common.AdminUser; +import com.yeshi.fanli.entity.common.Config; +import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum; +import com.yeshi.fanli.entity.redpack.RedPackExchange; +import com.yeshi.fanli.entity.redpack.RedPackWinInvite; +import com.yeshi.fanli.entity.redpack.RedPackWinInvite.RedPackWinInviteTypeEnum; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.fanli.exception.redpack.RedPackExchangeException; +import com.yeshi.fanli.exception.redpack.RedPackGiveRecordException; +import com.yeshi.fanli.service.AdminUserService; +import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; +import com.yeshi.fanli.service.inter.config.ConfigService; +import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService; +import com.yeshi.fanli.service.inter.redpack.RedPackBalanceService; +import com.yeshi.fanli.service.inter.redpack.RedPackConfigService; +import com.yeshi.fanli.service.inter.redpack.RedPackDetailService; +import com.yeshi.fanli.service.inter.redpack.RedPackExchangeService; +import com.yeshi.fanli.service.inter.redpack.RedPackForbidService; +import com.yeshi.fanli.service.inter.redpack.RedPackGiveRecordService; +import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService; +import com.yeshi.fanli.service.inter.user.UserInfoExtraService; +import com.yeshi.fanli.service.inter.user.UserInfoService; +import com.yeshi.fanli.service.inter.user.UserSystemCouponService; +import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; +import com.yeshi.fanli.util.email.MailSenderUtil; +import com.yeshi.fanli.vo.redpack.RedPackDetailVO; +import com.yeshi.fanli.vo.redpack.RedPackGiveVO; +import com.yeshi.fanli.vo.redpack.RedPackWinInviteVO; +import com.yeshi.fanli.vo.redpack.RedPackWinProgressVO; + +import net.sf.json.JSONObject; +import org.yeshi.utils.TimeUtil; + +@Controller +@RequestMapping("api/v2/redpack") +public class RedPackControllerV2 { + + @Resource + private RedPackConfigService redPackConfigService; + + @Resource + private RedPackBalanceService redPackBalanceService; + + @Resource + private RedPackDetailService redPackDetailService; + + @Resource + private RedPackGiveRecordService redPackGiveRecordService; + + @Resource + private RedPackExchangeService redPackExchangeService; + + @Resource + private RedPackWinInviteService redPackWinInviteService; + + @Resource + private UserInfoService userInfoService; + + @Resource + private UserInfoExtraService userInfoExtraService; + + @Resource + private JumpDetailV2Service jumpDetailV2Service; + + @Resource + private SwiperPictureService swiperPictureService; + + @Resource + private UserSystemCouponService userSystemCouponService; + + @Resource + private RedPackForbidService redPackForbidService; + + @Resource + private ThreeSaleSerivce threeSaleSerivce; + + @Resource + private ConfigService configService; + + @Resource + private AdminUserService adminUserService; + + /** + * 缁熻 + * + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "countInfo", method = RequestMethod.POST) + public void countInfo(AcceptData acceptData, Long uid, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + BigDecimal zero = new BigDecimal(0); + BigDecimal todayWin = zero; + BigDecimal yesterdayWin = zero; + BigDecimal thisMonthWin = zero; + BigDecimal lastMonthWin = zero; + + BigDecimal todayUse = zero; + BigDecimal yesterdayUse = zero; + BigDecimal thisMonthUse = zero; + BigDecimal lastMonthUse = zero; + BigDecimal balance = redPackBalanceService.getBalance(uid); + ; + if (balance == null) { + balance = zero; + } else { + // 鑾峰緱 + todayWin = redPackDetailService.countAddMoneyByDate(uid, 1); + yesterdayWin = redPackDetailService.countAddMoneyByDate(uid, 2); + thisMonthWin = redPackDetailService.countAddMoneyByDate(uid, 3); + lastMonthWin = redPackDetailService.countAddMoneyByDate(uid, 4); + + // 娑堣�� + todayUse = redPackDetailService.countUseMoneyByDate(uid, 1); + if (todayUse == null || todayUse.compareTo(zero) > 0) { + todayUse = zero; + } + + yesterdayUse = redPackDetailService.countUseMoneyByDate(uid, 2); + if (yesterdayUse == null || yesterdayUse.compareTo(zero) > 0) { + yesterdayUse = zero; + } + thisMonthUse = redPackDetailService.countUseMoneyByDate(uid, 3); + if (thisMonthUse == null || thisMonthUse.compareTo(zero) > 0) { + thisMonthUse = zero; + } + lastMonthUse = redPackDetailService.countUseMoneyByDate(uid, 4); + if (lastMonthUse == null || lastMonthUse.compareTo(zero) > 0) { + lastMonthUse = zero; + } + } + + List<String> tips = new ArrayList<String>(); + tips.add("绾㈠寘浣欓鈮�20鍏冨悗鍙彁鐜帮紝褰撳墠浣欓涓嶈冻锛岃缁х画鍔犳补鍝︼紒"); + tips.add("浣犱篃鍙互閫夋嫨浣跨敤绾㈠寘锛屼韩鍙楃粰鍔涙姌鎵c��"); + String giveMin = redPackConfigService.getValueByKey("give_money_min"); + String giveMax = redPackConfigService.getValueByKey("give_money_max"); + + // 姝e湪鎻愮幇閲戦 + BigDecimal extractingMoney = redPackExchangeService.countMoneyByUidAndState(uid, RedPackExchange.STATE_INIT); + + JSONObject data = new JSONObject(); + data.put("balance", balance.setScale(2).toString()); + data.put("helpLink", redPackConfigService.getValueByKey("desc_help_link")); + data.put("giveMin", giveMin); + data.put("giveMax", giveMax); + data.put("giveDesc", "娉�:绾㈠寘璧犻�侀噾棰濊嚦灏�" + giveMin + "鍏冭嚦澶�" + giveMax + "鍏�"); + + if (extractingMoney != null && extractingMoney.compareTo(zero) > 0) + data.put("extractingInfo", "鎻愮幇涓細楼" + extractingMoney.setScale(2)); + + data.put("extractShortage", tips); + data.put("extractMin", redPackConfigService.getValueByKey("extract_money_min")); + data.put("extractMax", redPackConfigService.getValueByKey("extract_money_max")); + data.put("extractBanlenMin", redPackConfigService.getValueByKey("extract_banlen_min")); + data.put("extractDesc", "娉細3涓伐浣滄棩鍐呭畬鎴愬鏍革紝绾㈠寘鎻愮幇鎴愬姛鍚庡皢浼氳繘鍏ュ埌浣欓銆�"); + data.put("giveTotal", redPackGiveRecordService.countGiveList(uid)); + data.put("useLink", redPackConfigService.getValueByKey("use_link")); + data.put("winLink", redPackConfigService.getValueByKey("invite_win_redpack_link")); + + data.put("todayWin", todayWin.setScale(2).toString()); + data.put("yesterdayWin", yesterdayWin.setScale(2).toString()); + data.put("thisMonthWin", thisMonthWin.setScale(2).toString()); + data.put("lastMonthWin", lastMonthWin.setScale(2).toString()); + data.put("todayUse", todayUse.setScale(2).toString().replaceAll("-", "")); + data.put("yesterdayUse", yesterdayUse.setScale(2).toString().replaceAll("-", "")); + data.put("thisMonthUse", thisMonthUse.setScale(2).toString().replaceAll("-", "")); + data.put("lastMonthUse", lastMonthUse.setScale(2).toString().replaceAll("-", "")); + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 鏄庣粏璇︽儏鍒楄〃 + * + * @param acceptData + * @param uid + * @param index List鏈�鏈殑涓婚敭ID + * @param year 骞翠唤 + * @param month 鏈堜唤 + * @param out + */ + @RequestMapping(value = "getMoneyDetails") + public void getMoneyDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, + PrintWriter out) { + if (uid == null || uid == 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + if ((year == null && month != null) || (year != null && month == null)) { + out.print(JsonUtil.loadFalseResult(1, "鏃ユ湡涓嶅畬鏁�")); + return; + } + + Date date = null; + + if (year != null && month != null) { + date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M")); + Calendar ca = Calendar.getInstance(); + ca.setTime(date); + ca.add(Calendar.MONTH, 1); + date = new Date(ca.getTimeInMillis() - 1); + } + + // 鏌ヨ鍒楄〃 + List<RedPackDetailVO> list = redPackDetailService.listUserMoneyDetailForClient(uid, index, date); + // 缁熻鎬绘潯鏁� + long count = redPackDetailService.countUserMoneyDetailForClient(uid, index, date); + + GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); + gsonBuilder.registerTypeAdapter(RedPackDetailTypeEnum.class, new TypeAdapter<RedPackDetailTypeEnum>() { + @Override + public RedPackDetailTypeEnum read(JsonReader arg0) throws IOException { + return null; + } + + @Override + public void write(JsonWriter out, RedPackDetailTypeEnum arg1) throws IOException { + out.beginObject(); + out.name("portrait").value(arg1.getPicture()); + out.endObject(); + } + }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { + @Override + public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { + if (value == null) { + return new JsonPrimitive(""); + } else { + return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm")); + } + } + }).registerTypeAdapter(BigDecimal.class, new JsonSerializer<BigDecimal>() { + @Override + public JsonElement serialize(BigDecimal value, Type theType, JsonSerializationContext context) { + if (value == null) { + return new JsonPrimitive(""); + } else { + // 淇濈暀2浣嶅皬鏁� + value = value.setScale(2); + return new JsonPrimitive(value.toString()); + } + } + }); + + Gson gson = gsonBuilder.create(); + + JSONObject data = new JSONObject(); + data.put("count", count); + data.put("data", gson.toJson(list)); + out.print(JsonUtil.loadTrueResult(data)); + } + + /** + * 璧犻�佺孩鍖� + * + * @param acceptData + * @param uid + * @param amount + * @param out + */ + @RequestMapping(value = "giving", method = RequestMethod.POST) + public void giving(AcceptData acceptData, Long uid, BigDecimal amount, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + try { + String tips = redPackGiveRecordService.giving(uid, amount); + out.print(JsonUtil.loadTrueResult(tips)); + } catch (RedPackGiveRecordException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + @RequestMapping(value = "getGiveList", method = RequestMethod.POST) + public void getGiveList(AcceptData acceptData, Integer page, Long uid, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + if (page == null || page <= 0) + page = 1; + + try { + List<RedPackGiveVO> list = redPackGiveRecordService.getGiveList(page, Constant.PAGE_SIZE, uid); + + GsonBuilder gsonBuilder = new GsonBuilder(); + Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy.MM.dd HH:mm").create(); + + JSONObject data = new JSONObject(); + data.put("list", gson.toJson(list)); + data.put("count", redPackGiveRecordService.countGiveList(uid)); + out.print(JsonUtil.loadTrueResult(data)); + } catch (Exception e) { + e.printStackTrace(); + out.print(JsonUtil.loadFalseResult(1, "鏌ヨ澶辫触")); + } + } + + /** + * 杞崲绾㈠寘涓虹湡瀹為噾閽� + * + * @param acceptData + * @param uid + * @param amount + * @param out + */ + @RequestMapping(value = "exchangeCash", method = RequestMethod.POST) + public void exchangeCash(AcceptData acceptData, Long uid, BigDecimal amount, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + try { + redPackExchangeService.exchangeCash(uid, amount); + out.print(JsonUtil.loadTrueResult("鎻愮幇鐢宠鎴愬姛")); + + ThreadUtil.run(new Runnable() { + @Override + public void run() { + JSONObject json = new JSONObject(); + json.put("timeStamp", java.lang.System.currentTimeMillis()); + json.put("adminId", 4L); + String sign = AESUtil.encrypt(json.toString(), Constant.ADMINH5_AESKEY); + String url = ""; + try { + url = String.format("%s?from=emailh5&sign=%s", + Constant.systemCommonConfig.getExtractNotifyUrl(), URLEncoder.encode(sign, "UTF-8")); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + long[] targetUids = new long[] { 3L, 4L }; + Config config = configService.getConfig(ConfigKeyEnum.extractCodeEmailFrom.getKey(), SystemInfoUtil.getSystem(acceptData)); + String[] sts = config.getValue().split(","); + String account = sts[0]; + String pwd = sts[1]; + for (long adminId : targetUids) { + AdminUser adminUser = adminUserService.selectByPrimaryKey(adminId); + String msg = "鏈夌敤鎴烽噰鐢ㄧ孩鍖呭厬鎹㈢幇閲�"; + boolean isS = MailSenderUtil.sendEmail(adminUser.getEmail(), account, pwd, "绾㈠寘鍏戞崲鐜伴噾鎻愰啋", msg); + } + } + }); + + } catch (RedPackExchangeException e) { + out.print(JsonUtil.loadFalseResult(1, e.getMsg())); + } + } + + /** + * 绾㈠寘閭�璇疯繘搴� + * + * @param acceptData + * @param page + * @param uid + * @param out + */ + @RequestMapping(value = "getRewardList") + public void getRewardList(AcceptData acceptData, Integer page, Long uid, String callback, PrintWriter out) { + if (uid == null || uid <= 0) { + out.print(JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + if (page == null || page < 1) { + out.print(JsonUtil.loadFalseResult(1, "椤电爜涓嶆纭�")); + return; + } + + List<RedPackWinInviteVO> list = new ArrayList<RedPackWinInviteVO>(); + + List<RedPackWinInvite> listRecord = redPackWinInviteService.getRewardList((page - 1) * Constant.PAGE_SIZE, + Constant.PAGE_SIZE, uid); + if (listRecord != null && !listRecord.isEmpty()) { + for (RedPackWinInvite record : listRecord) { + UserInfo user = null; + RedPackWinInviteVO winVO = new RedPackWinInviteVO(); + RedPackWinInviteTypeEnum type = record.getType(); + if (RedPackWinInviteTypeEnum.newUserReward == type) { + user = userInfoService.selectByPKey(uid); + } else { + user = userInfoService.selectByPKey(record.getTeamUid()); + } + winVO.setPortrait(user.getPortrait()); + winVO.setNickName(user.getNickName()); + winVO.setDesc(type.getDesc()); + winVO.setMoney(record.getMoney().toString()); + list.add(winVO); + } + } + + JSONObject data = new JSONObject(); + data.put("winMoney", redPackWinInviteService.getRewardMoney(uid).setScale(2)); + data.put("count", redPackWinInviteService.countRewardRecord(uid)); + data.put("list", JsonUtil.getApiCommonGson().toJson(list)); + if (!StringUtil.isNullOrEmpty(callback)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + } else { + out.print(JsonUtil.loadTrueResult(data)); + } + } + + /** + * 鐢ㄦ埛鍩虹淇℃伅 + * + * @param acceptData + * @param uid + * @param out + */ + @RequestMapping(value = "getBasicInfo") + public void getBasicInfo(AcceptData acceptData, Long uid, String callback, PrintWriter out) { + if (uid == null || uid <= 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + JSONObject data = new JSONObject(); + data.put("balance", redPackBalanceService.getBalance(uid)); + data.put("ruleLink", redPackConfigService.getValueByKey("invite_reward_rule_link")); + data.put("shareLink", UserInviteUtil.getShareUrl(uid)); + data.put("redPackLock", redPackForbidService.verifyForbid(uid)); + + String inviteCode = userInfoExtraService.getInviteCodeByUid(uid); + if (!StringUtil.isNullOrEmpty(inviteCode)) { + data.put("inviteCode", inviteCode); + } else { + data.put("inviteCode", ""); + } + + // 璧犻�佸厤鍗曞埜 + long freeCouponCount = userSystemCouponService.countGiveFreeCoupon(uid); + // 濂栧姳鍒� + long rewardCouponCount = userSystemCouponService.countUsableRewardCoupon(uid); + + data.put("freeCouponCount", freeCouponCount); + data.put("rewardCouponCount", rewardCouponCount); + + if (!StringUtil.isNullOrEmpty(callback)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + } else { + out.print(JsonUtil.loadTrueResult(data)); + } + } + + /** + * 璇ョ敤鎴烽個璇峰閲戞 + * + * @param acceptData + * @param uid 涓嬬嚎UID + * @param out + */ + @RequestMapping(value = "getInviteReward") + public void getInviteReward(AcceptData acceptData, Integer page, Long uid, String callback, PrintWriter out) { + if (uid == null || uid <= 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "鐢ㄦ埛鏈櫥褰�")); + return; + } + + if (page == null || page < 1) + page = 1; + + List<RedPackWinProgressVO> listVO = new ArrayList<RedPackWinProgressVO>(); + List<RedPackWinInvite> list = redPackWinInviteService.getWinTopListByBossId(page, Constant.PAGE_SIZE, uid); + if (list != null) { + for (RedPackWinInvite win : list) { + ThreeSale threeSale = threeSaleSerivce.getNearRelationByBossIdAndWorkerId(uid, win.getTeamUid()); + if (threeSale == null) + continue; + + UserInfo userInfo = userInfoService.selectByPKey(win.getTeamUid()); + if (userInfo == null) + continue; + + RedPackWinProgressVO progressVO = new RedPackWinProgressVO(); + progressVO.setUid(userInfo.getId()); + progressVO.setName(userInfo.getNickName()); + progressVO.setPortrait(userInfo.getPortrait()); + progressVO.setMoney(win.getMoney().setScale(2).toString()); + progressVO.setTime("閭�璇凤細" + TimeUtil.formatDate(threeSale.getSucceedTime())); + listVO.add(progressVO); + } + } + + JSONObject data = new JSONObject(); + data.put("list", listVO); + data.put("count", redPackWinInviteService.countWinTopListByBossId(uid)); + if (!StringUtil.isNullOrEmpty(callback)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + } else { + out.print(JsonUtil.loadTrueResult(data)); + } + } + + /** + * 璇ョ敤鎴烽個璇疯繘搴� + * + * @param acceptData + * @param tid 涓嬬嚎UID + * @param out + */ + @RequestMapping(value = "getInviteProgress") + public void getInviteProgress(AcceptData acceptData, Long uid, Long tid, String callback, PrintWriter out) { + if (uid == null || uid <= 0 || tid == null || tid <= 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(1, "浼犻�掑弬鏁扮己澶�")); + return; + } + + JSONObject data = new JSONObject(); + data.put("list", redPackWinInviteService.getInviteProgressByWorkerId(uid, tid)); + data.put("num", redPackWinInviteService.countTeamNumByTid(uid, tid)); + if (!StringUtil.isNullOrEmpty(callback)) { + out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); + } else { + out.print(JsonUtil.loadTrueResult(data)); + } + } +} -- Gitblit v1.8.0