剔除旧首充逻辑

This commit is contained in:
2025-06-11 19:00:29 +08:00
parent 56efa5c617
commit b284ebb680
34 changed files with 1 additions and 2042 deletions

View File

@@ -1,18 +0,0 @@
package com.accompany.admin.vo;
import lombok.Data;
@Data
public class FirstChargeRecordStatisticsVo {
private String currentDay;
private Integer oneLevelNum;
private Integer twoLevelNum;
private Integer threeLevelNum;
private Long giveShowPrice;
private String firstChargeInfo;
private Integer firstChargeInfoId;
private Integer firstChargeStatus;
}

View File

@@ -1,20 +0,0 @@
package com.accompany.admin.vo;
import lombok.Data;
@Data
public class FirstChargeRewardAdminVo {
private Long id;
private String showText;
private String showPir;
private Long rewardId;
private Byte rewardType;
private Integer rewardDay;
private Integer rewardNum;
private Integer seqNo;
private String rewardName;
private String type;
private Long giftPrice;
}

View File

@@ -1,15 +0,0 @@
package com.accompany.admin.vo;
import lombok.Data;
@Data
public class FirstChargeRewardRecordAdminVo {
private Long erbanNo;
private String nick;
private String inviteCode;
private String signTime;
private Long money;
private String chargeTime;
private Integer firstChargeLevelId;
}

View File

@@ -1,27 +0,0 @@
package com.accompany.admin.mapper;
import com.accompany.admin.vo.FirstChargeRecordStatisticsVo;
import com.accompany.admin.vo.FirstChargeRewardRecordAdminVo;
import com.accompany.business.model.FirstChargeReward;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
public interface FirstChargeRewardAdminMapper {
List<FirstChargeRecordStatisticsVo> getFirstChargeStatistics(@Param("startTime") String startTime, @Param("endTime")String endTime);
List<FirstChargeRewardRecordAdminVo> getFirstChargeRecordList(@Param("beginTimeOfDay") Date beginTimeOfDay, @Param("endTimeOfDay") Date endTimeOfDay);
int getCloseSwitchNumSwitchNum(@Param("firstChargeLevelId")Integer firstChargeLevelId);
void updateFirstChargeLevelSwitch(@Param("firstChargeLevelId") Integer firstChargeLevelId, @Param("switchStatus") Integer switchStatus,
@Param("infoId")Integer infoId,@Param("showPrice")Integer showPrice);
List<FirstChargeReward> getFirstChargeRewardList(@Param("firstChargeLevelId")Integer firstChargeLevelId);
FirstChargeRecordStatisticsVo getFirstChargeLevelInfo(@Param("firstChargeLevelId")Integer firstChargeLevelId);
}

View File

@@ -1,219 +0,0 @@
package com.accompany.admin.service.charge;
import com.accompany.admin.mapper.FirstChargeRewardAdminMapper;
import com.accompany.admin.vo.FirstChargeRecordStatisticsVo;
import com.accompany.admin.vo.FirstChargeRewardAdminVo;
import com.accompany.admin.vo.FirstChargeRewardRecordAdminVo;
import com.accompany.business.model.*;
import com.accompany.business.mybatismapper.FirstChargeRewardMapper;
import com.accompany.business.mybatismapper.NameplateMapper;
import com.accompany.business.service.car.CarGoodsService;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.headwear.HeadwearService;
import com.accompany.business.vo.FirstChargeInfoVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.StringUtils;
import com.accompany.core.exception.AdminServiceException;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@Service
public class FirstChargeRewardAdminService {
@Autowired
private FirstChargeRewardAdminMapper firstChargeRewardAdminMapper;
@Autowired
private HeadwearService headwearService;
@Autowired
private CarGoodsService carGoodsService;
@Autowired
private NameplateMapper nameplateMapper;
@Autowired
private GiftService giftService;
@Autowired
private FirstChargeRewardMapper firstChargeRewardMapper;
public Map<String, Object> getFirstChargeStatistics(String startTime, String endTime, Integer page, Integer pageSize) {
Map<String, Object> statisticsMap = Maps.newHashMap();
page = page != null ? page : Constant.DEFAULT_PAGE;
pageSize = pageSize != null ? pageSize : Constant.DEFAULT_PAGE_SIZE;
PageHelper.startPage(page, pageSize);
List<FirstChargeRecordStatisticsVo> statisticsList = firstChargeRewardAdminMapper.getFirstChargeStatistics(startTime,endTime);
PageInfo<FirstChargeRecordStatisticsVo> pageInfo = new PageInfo<>(statisticsList);
statisticsMap.put("rows", pageInfo.getList());
statisticsMap.put("total", pageInfo.getTotal());
return statisticsMap;
}
public Map<String, Object> getFirstChargeRecordList(String currentDay, Integer page, Integer pageSize) {
Map<String, Object> statisticsMap = Maps.newHashMap();
page = page != null ? page : Constant.DEFAULT_PAGE;
pageSize = pageSize != null ? pageSize : Constant.DEFAULT_PAGE_SIZE;
Date currentDate = new Date();
if(StringUtils.isNotBlank(currentDay)){
currentDate = DateTimeUtil.convertStrToDate(currentDay, DateTimeUtil.DEFAULT_DATE_PATTERN);
}
Date beginTimeOfDay = DateTimeUtil.getBeginTimeOfDay(currentDate);
Date endTimeOfDay = DateTimeUtil.getEndTimeOfDay(currentDate);
PageHelper.startPage(page, pageSize);
List<FirstChargeRewardRecordAdminVo> recordList = firstChargeRewardAdminMapper.getFirstChargeRecordList(beginTimeOfDay,endTimeOfDay);
PageInfo<FirstChargeRewardRecordAdminVo> pageInfo = new PageInfo<>(recordList);
statisticsMap.put("rows", pageInfo.getList());
statisticsMap.put("total", pageInfo.getTotal());
return statisticsMap;
}
public void updateSwitch(Integer firstChargeLevelId,Integer switchStatus,Integer infoId,Integer showPrice) {
if(switchStatus == 0){
int closeSwitchNum = firstChargeRewardAdminMapper.getCloseSwitchNumSwitchNum(firstChargeLevelId);
if(closeSwitchNum >= 2){
throw new AdminServiceException("必须有档位处于开启状态");
}
}
firstChargeRewardAdminMapper.updateFirstChargeLevelSwitch(firstChargeLevelId,switchStatus,infoId,showPrice);
}
public Map<String, Object> getFirstChargeRewardList(Integer firstChargeLevelId) {
Map statisticsMap = Maps.newHashMap();
List<FirstChargeReward> list = firstChargeRewardAdminMapper.getFirstChargeRewardList(firstChargeLevelId);
List<FirstChargeRewardAdminVo> rewardList = new LinkedList<>();
FirstChargeRewardAdminVo vo;
for(FirstChargeReward reward : list){
vo = new FirstChargeRewardAdminVo();
vo.setId(reward.getId());
vo.setShowText(reward.getShowText());
vo.setShowPir(reward.getShowPir());
Long rewardId = reward.getRewardId();
vo.setRewardId(rewardId);
Byte rewardType = reward.getRewardType();
if(rewardType.equals(Constant.firstChargeRewardType.GIFT)){
Gift gift = giftService.getGiftById(rewardId.intValue());
if(gift == null){
throw new AdminServiceException("礼物不存在");
}
vo.setRewardName(gift.getGiftName());
vo.setGiftPrice(gift.getGoldPrice());
vo.setType("礼物");
} else if(rewardType.equals(Constant.firstChargeRewardType.NAME_PLATE)){
Nameplate nameplate = nameplateMapper.selectById(rewardId);
if(nameplate == null){
throw new AdminServiceException("铭牌不存在");
}
vo.setRewardName(nameplate.getName());
vo.setType("铭牌");
} else if(rewardType.equals(Constant.firstChargeRewardType.CAR)){
CarGoods carGoods = carGoodsService.getCarGoods(rewardId.intValue());
vo.setRewardName(carGoods.getName());
vo.setType("座驾");
} else if(rewardType.equals(Constant.firstChargeRewardType.HEADWEAR)){
Headwear headwear = headwearService.getHeadwear(rewardId.intValue());
if(headwear == null){
throw new AdminServiceException("头饰不存在");
}
vo.setRewardName(headwear.getName());
vo.setType("头饰");
} else if(rewardType.equals(Constant.firstChargeRewardType.DIAMOND)){
// 赠送钻石
vo.setType("额外钻石");
}
vo.setRewardDay(reward.getRewardDay());
vo.setRewardNum(reward.getRewardNum());
vo.setSeqNo(reward.getSeqNo());
rewardList.add(vo);
}
PageInfo<FirstChargeRewardAdminVo> pageInfo = new PageInfo<>(rewardList);
statisticsMap.put("rows", pageInfo.getList());
statisticsMap.put("total", pageInfo.getTotal());
FirstChargeRecordStatisticsVo firstChargeLevelInfo = firstChargeRewardAdminMapper.getFirstChargeLevelInfo(firstChargeLevelId);
statisticsMap.put("giveShowPrice",firstChargeLevelInfo.getGiveShowPrice());
String firstChargeInfoStr = firstChargeLevelInfo.getFirstChargeInfo();
FirstChargeInfoVo infoVo = JSONObject.parseObject(firstChargeInfoStr, FirstChargeInfoVo.class);
statisticsMap.put("chargeMoney",infoVo.getChargeMoney());
String switchStatus;
if(firstChargeLevelInfo.getFirstChargeStatus() == 1){
switchStatus = "开启";
}else{
switchStatus = "关闭";
}
statisticsMap.put("firstChargeSwitchStatus",switchStatus);
return statisticsMap;
}
public void deleteReward(Integer id) {
firstChargeRewardMapper.deleteById(id);
}
public void saveOrUpdateReward(FirstChargeReward reward) {
Byte rewardType = reward.getRewardType();
Long rewardId = reward.getRewardId();
if(rewardType.equals(Constant.firstChargeRewardType.GIFT)){
Gift gift = giftService.getGiftById(rewardId.intValue());
if(gift == null){
throw new AdminServiceException("礼物不存在");
}
} else if(rewardType.equals(Constant.firstChargeRewardType.NAME_PLATE)){
Nameplate nameplate = nameplateMapper.selectById(rewardId);
if(nameplate == null){
throw new AdminServiceException("铭牌不存在");
}
} else if(rewardType.equals(Constant.firstChargeRewardType.CAR)){
carGoodsService.getCarGoods(rewardId.intValue());
} else if(rewardType.equals(Constant.firstChargeRewardType.HEADWEAR)){
Headwear headwear = headwearService.getHeadwear(rewardId.intValue());
if(headwear == null){
throw new AdminServiceException("头饰不存在");
}
}
if(reward.getId() == null){
QueryWrapper<FirstChargeReward> wrapper = new QueryWrapper<>();
wrapper.eq("first_charge_level_id",reward.getFirstChargeLevelId());
long rewardNum = firstChargeRewardMapper.selectCount(wrapper);
if(rewardNum >= 6L){
throw new AdminServiceException("每个档位最多增加6个礼包");
}
firstChargeRewardMapper.insert(reward);
}else{
firstChargeRewardMapper.updateById(reward);
}
}
public Map<String, Object> getFirstChargeRewardId(Integer id) {
Map rewardMap = Maps.newHashMap();
QueryWrapper<FirstChargeReward> wrapper = new QueryWrapper<>();
wrapper.eq("id",id);
List<FirstChargeReward> firstChargeRewards = firstChargeRewardMapper.selectList(wrapper);
PageInfo<FirstChargeReward> pageInfo = new PageInfo<>(firstChargeRewards);
rewardMap.put("rows", pageInfo.getList());
rewardMap.put("total", pageInfo.getTotal());
return rewardMap;
}
public Map<String, Object> getLevelInfo(Integer firstChargeLevelId) {
Map rewardMap = Maps.newHashMap();
FirstChargeRecordStatisticsVo firstChargeLevelInfo = firstChargeRewardAdminMapper.getFirstChargeLevelInfo(firstChargeLevelId);
List<FirstChargeRecordStatisticsVo> list = new LinkedList<>();
list.add(firstChargeLevelInfo);
PageInfo<FirstChargeRecordStatisticsVo> pageInfo = new PageInfo<>(list);
rewardMap.put("rows", pageInfo.getList());
rewardMap.put("total", pageInfo.getTotal());
return rewardMap;
}
}

View File

@@ -16,7 +16,6 @@ import com.accompany.business.mybatismapper.UserInRoomRecordMapper;
import com.accompany.business.mybatismapper.flow.FlowTeamMemberBaseMapper; import com.accompany.business.mybatismapper.flow.FlowTeamMemberBaseMapper;
import com.accompany.business.mybatismapper.room.RoomVisitorMapper; import com.accompany.business.mybatismapper.room.RoomVisitorMapper;
import com.accompany.business.mybatismapper.room.RoomVisitorUserDictMapper; import com.accompany.business.mybatismapper.room.RoomVisitorUserDictMapper;
import com.accompany.business.service.charge.FirstChargeRewardRecordService;
import com.accompany.business.service.user.UserLoginService; import com.accompany.business.service.user.UserLoginService;
import com.accompany.common.redis.RedisKey; import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus; import com.accompany.common.status.BusiStatus;
@@ -92,9 +91,6 @@ public class StatsUserDetailAdminService extends BaseService {
@Autowired @Autowired
private SysConfService sysConfService; private SysConfService sysConfService;
@Autowired
private FirstChargeRewardRecordService firstChargeRewardRecordService;
@Autowired @Autowired
private RoomVisitorService roomVisitorService; private RoomVisitorService roomVisitorService;

View File

@@ -1,85 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.accompany.admin.mapper.FirstChargeRewardAdminMapper">
<select id="getFirstChargeStatistics" resultType="com.accompany.admin.vo.FirstChargeRecordStatisticsVo">
select currentDay,sum(a.oneLevelNum)as oneLevelNum ,sum(a.twoLevelNum) as twoLevelNum,sum(a.threeLevelNum)as threeLevelNum from (
SELECT DATE_FORMAT(create_time,"%Y-%m-%d")as currentDay ,count(1) as oneLevelNum,0 as twoLevelNum,0 as threeLevelNum
FROM first_charge_reward_record
where first_charge_level_id = 1
<if test="startTime != null and startTime != ''">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and create_time &lt;= #{endTime}
</if>
GROUP BY DATE_FORMAT(create_time,"%Y-%m-%d")
union all
SELECT DATE_FORMAT(create_time,"%Y-%m-%d")as currentDay ,0 as oneLevelNum,count(1) as twoLevelNum,0 as threeLevelNum
FROM first_charge_reward_record
where first_charge_level_id = 2
<if test="startTime != null and startTime != ''">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and create_time &lt;= #{endTime}
</if>
GROUP BY DATE_FORMAT(create_time,"%Y-%m-%d")
union all
SELECT DATE_FORMAT(create_time,"%Y-%m-%d")as currentDay ,0 as oneLevelNum,0 as twoLevelNum,count(1) as threeLevelNum
FROM first_charge_reward_record
where first_charge_level_id = 3
<if test="startTime != null and startTime != ''">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null and endTime != ''">
and create_time &lt;= #{endTime}
</if>
GROUP BY DATE_FORMAT(create_time,"%Y-%m-%d")
) a GROUP BY currentDay ORDER BY currentDay DESC
</select>
<select id="getFirstChargeRecordList" resultType="com.accompany.admin.vo.FirstChargeRewardRecordAdminVo">
select us.erban_no,us.nick,us.invite_code,ac.sign_time,(fcr.amount / 100) 'money',fcr.create_time as 'chargeTime',fcr.first_charge_level_id
from first_charge_reward_record fcr
left join users us on us.uid = fcr.uid
left join account ac on ac.uid = fcr.uid
where fcr.create_time &gt;= #{beginTimeOfDay} and fcr.create_time &lt;= #{endTimeOfDay}
</select>
<select id="getCloseSwitchNumSwitchNum" resultType="int">
select count(1) from first_charge_level where first_charge_status = 0 and id &lt;&gt; #{firstChargeLevelId}
</select>
<update id="updateFirstChargeLevelSwitch">
update first_charge_level
<set>
<if test="switchStatus != null">
first_charge_status = #{switchStatus},
</if>
<if test="infoId != null">
first_charge_info_id = #{infoId},
</if>
<if test="showPrice != null">
give_show_price = #{showPrice},
</if>
</set>
where id = #{firstChargeLevelId}
</update>
<select id="getFirstChargeRewardList" resultType="com.accompany.business.model.FirstChargeReward">
SELECT fr.id,fr.show_text,fr.show_pir,fr.reward_id,fr.reward_type,fr.reward_day,fr.reward_num,fr.seq_no
FROM first_charge_reward fr
left join first_charge_level fl on fl.id = fr.first_charge_level_id
where fl.id = #{firstChargeLevelId}
ORDER BY seq_no
</select>
<select id="getFirstChargeLevelInfo" resultType="com.accompany.admin.vo.FirstChargeRecordStatisticsVo">
select fc.give_show_price,fi.first_charge_info,fc.first_charge_status,fc.first_charge_info_id
from first_charge_level fc
left join first_charge_level_info fi on fi.id = fc.first_charge_info_id
where fc.id = #{firstChargeLevelId}
</select>
</mapper>

View File

@@ -1,148 +0,0 @@
package com.accompany.admin.controller.charge;
import com.accompany.admin.controller.BaseController;
import com.accompany.admin.service.charge.FirstChargeRewardAdminService;
import com.accompany.admin.vo.FirstChargeRewardRecordAdminVo;
import com.accompany.business.model.FirstChargeReward;
import com.alibaba.fastjson.JSONObject;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/admin/first/charge/reward")
public class FirstChargeRewardAdminController extends BaseController {
@Autowired
private FirstChargeRewardAdminService firstChargeRewardAdminService;
@GetMapping(value = "statistics")
public void getFirstChargeStatistics(String startTime, String endTime, Integer page, Integer pageSize) {
Map<String, Object> map = firstChargeRewardAdminService.getFirstChargeStatistics(startTime,endTime,page,pageSize);
writeJson(JSONObject.toJSONString(map));
}
@GetMapping(value = "record")
public void getFirstChargeStatistics(String currentDay, Integer page, Integer pageSize) {
Map<String, Object> recordMap = firstChargeRewardAdminService.getFirstChargeRecordList(currentDay,page,pageSize);
writeJson(JSONObject.toJSONString(recordMap));
}
@GetMapping(value = "/export")
public void getFirstChargeExport(HttpServletRequest request, HttpServletResponse response, String currentDay) throws Exception {
Map<String, Object> data = firstChargeRewardAdminService.getFirstChargeRecordList(currentDay, 1, Integer.MAX_VALUE);
List<FirstChargeRewardRecordAdminVo> recordList = (List<FirstChargeRewardRecordAdminVo>) data.get("rows");
try {
List<String> headerList = new LinkedList<>();
headerList.add("平台号");
headerList.add("用户昵称");
headerList.add("邀请码");
headerList.add("注册时间");
headerList.add("充值数额");
headerList.add("充值时间");
headerList.add("获得档位");
String fileName = new StringBuilder(currentDay).append("首充明细记录.xls").toString();
List<List> excelRows = buildFirstChargeExcelData(recordList);
Workbook workbook = com.accompany.admin.util.ExcelUtils.createExcelSheet(headerList, excelRows);
com.accompany.admin.util.ExcelUtils.setExcelResponseHeader(request, response, fileName);
java.io.OutputStream out = response.getOutputStream();
workbook.write(out);
out.flush();
} catch (Exception e) {
logger.error("Failed to export invite_code_stats. Cause by {}", e.getMessage());
writeJson(false, "导出失败");
}
}
@GetMapping(value = "/getId")
public void getFirstChargeRewardId(Integer id){
Map<String, Object> map = firstChargeRewardAdminService.getFirstChargeRewardId(id);
writeJson(JSONObject.toJSONString(map));
}
@GetMapping(value = "/list")
public void getFirstChargeRewardList(Integer firstChargeLevelId){
try{
Map<String, Object> rewardList = firstChargeRewardAdminService.getFirstChargeRewardList(firstChargeLevelId);
writeJson(JSONObject.toJSONString(rewardList));
}catch(Exception e){
logger.error(e.getMessage());
writeJson(false, e.getMessage());
}
}
@PostMapping(value = "/delete")
public void deleteReward(Integer id){
try{
firstChargeRewardAdminService.deleteReward(id);
writeJson(true, "删除成功");
}catch(Exception e){
logger.error(e.getMessage());
writeJson(false, e.getMessage());
}
}
@PostMapping(value = "/saveOrUpdate")
public void saveOrUpdateReward(FirstChargeReward reward){
try{
firstChargeRewardAdminService.saveOrUpdateReward(reward);
writeJson(true, "成功");
}catch(Exception e){
logger.error(e.getMessage());
writeJson(false, e.getMessage());
}
}
@GetMapping(value = "getLevelInfo")
public void getLevelInfo(Integer firstChargeLevelId){
try{
Map<String, Object> map = firstChargeRewardAdminService.getLevelInfo(firstChargeLevelId);
writeJson(JSONObject.toJSONString(map));
}catch(Exception e){
logger.error(e.getMessage());
writeJson(false, e.getMessage());
}
}
@PostMapping(value = "/updateLevelInfo")
public void updateSwitch(Integer firstChargeLevelId,Integer switchStatus,Integer infoId,Integer showPrice){
try{
firstChargeRewardAdminService.updateSwitch(firstChargeLevelId,switchStatus,infoId,showPrice);
writeJson(true, "保存成功");
}catch(Exception e){
logger.error(e.getMessage());
writeJson(false, e.getMessage());
}
}
public List<List> buildFirstChargeExcelData(List<FirstChargeRewardRecordAdminVo> recordList){
List<List> excelRows = new ArrayList<>(recordList.size());
for (FirstChargeRewardRecordAdminVo vo : recordList) {
List<Object> excelData = new ArrayList<>();
excelData.add(vo.getErbanNo());
excelData.add(vo.getNick());
excelData.add(vo.getInviteCode());
excelData.add(vo.getSignTime());
excelData.add(vo.getMoney());
excelData.add(vo.getChargeTime());
excelData.add(vo.getFirstChargeLevelId());
excelRows.add(excelData);
}
return excelRows;
}
}

View File

@@ -2911,19 +2911,6 @@ public class Constant {
public static final Integer VIP_MP_SEND = 7; public static final Integer VIP_MP_SEND = 7;
} }
public static class firstChargeRewardType {
// 面板礼物
public static final Byte GIFT = 1;
// 铭牌
public static final Byte NAME_PLATE = 2;
// 座驾
public static final Byte CAR = 3;
// 头饰
public static final Byte HEADWEAR = 4;
// 额外钻石
public static final Byte DIAMOND = 5;
}
public static class ApplyUserNameplate { public static class ApplyUserNameplate {
// 1:申请铭牌 // 1:申请铭牌
public static final Integer APPLY_NAME_PLATE = 1; public static final Integer APPLY_NAME_PLATE = 1;

View File

@@ -808,23 +808,6 @@ public enum RedisKey {
flow_team_admin_login_error_count, //1天内登录错误次数 flow_team_admin_login_error_count, //1天内登录错误次数
/** 引流小组后台 end **/ /** 引流小组后台 end **/
/**
* 首充激励用户缓存
**/
first_charge_reward_user,
/**
* 首充激励发送奖励锁
**/
first_charge_reward_send_reward_lock,
/**
* 已完成所有限时首充奖励用户
*/
limit_first_charge_finished_user,
/**
* 限时首充奖励激励发送奖励锁
**/
limit_first_charge_reward_send_reward_lock,
room_visitor_user_dict_lock, room_visitor_user_dict_lock,
room_visitor_user_exit_flag,//用户是否为引流直播用户标示有效期1天String room_visitor_user_exit_flag,//用户是否为引流直播用户标示有效期1天String

View File

@@ -1,14 +0,0 @@
package com.accompany.business.dto.exchange;
import lombok.Data;
import java.util.Set;
@Data
public class FirstChargeRoomWindowConfigDto {
private Boolean open;
private Set<String> channels;
private Integer createDayLimit;
private Integer showTimes;
private Integer showAfterSecond;
}

View File

@@ -1,58 +0,0 @@
package com.accompany.business.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel
@TableName("first_charge_level")
public class FirstChargeLevel {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty("id")
private Integer id;
@TableField("first_charge_level_name")
@ApiModelProperty("首充等级显示名称")
private String firstChargeLevelName;
@TableField("first_charge_status")
@ApiModelProperty("等级开关(01开)")
private Integer firstChargeStatus;
@TableField("first_charge_info_id")
@ApiModelProperty("first_charge_level_info关联id")
private Integer firstChargeInfoId;
@TableField("give_show_price")
@ApiModelProperty("赠礼展示价格")
private Long giveShowPrice;
@TableField("lower_limit")
@ApiModelProperty("下限充值金额('充值金额(单位:分)'")
private Long lowerLimit;
@TableField("upper_limit")
@ApiModelProperty("上限充值金额('充值金额(单位:分)'")
private Long upperLimit;
@TableField("create_time")
@ApiModelProperty("创建时间")
private Date createTime;
@TableField("update_time")
@ApiModelProperty("修改时间")
private Date updateTime;
@TableField("first_charge_type")
@ApiModelProperty("首充类型(1:默认首充2:限时首充)")
private Integer firstChargeType;
}

View File

@@ -1,65 +0,0 @@
package com.accompany.business.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel
@TableName("first_charge_reward")
public class FirstChargeReward {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty("id")
private Long id;
@TableField("reward_id")
@ApiModelProperty("奖励id")
private Long rewardId;
@TableField("seq_no")
@ApiModelProperty("排序号")
private Integer seqNo;
@TableField("reward_day")
@ApiModelProperty("奖励天数")
private Integer rewardDay;
@TableField("reward_num")
@ApiModelProperty("奖励数量")
private Integer rewardNum;
@TableField("reward_type")
@ApiModelProperty("奖励类型")
private Byte rewardType;
@TableField("show_text")
@ApiModelProperty("显示文本")
private String showText;
@TableField("show_pir")
@ApiModelProperty("显示图片")
private String showPir;
@TableField("first_charge_level_id")
@ApiModelProperty("首充等级关联id")
private Integer firstChargeLevelId;
@TableField("create_time")
@ApiModelProperty("创建时间")
private Date createTime;
@TableField("update_time")
@ApiModelProperty("修改时间")
private Date updateTime;
@TableField(exist = false)
private String showTime;
}

View File

@@ -1,46 +0,0 @@
package com.accompany.business.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
@ApiModel
@TableName("first_charge_reward_record")
public class FirstChargeRewardRecord {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty("id")
private Long id;
@TableField("uid")
@ApiModelProperty("uid")
private Long uid;
@TableField("first_charge_level_id")
@ApiModelProperty("首充激励奖励id")
private Integer firstChargeLevelId;
@TableField("receive_reward")
@ApiModelProperty("获得奖励")
private String receiveReward;
@TableField("amount")
@ApiModelProperty("充值金额")
private Long amount;
@TableField("charge_record_id")
@ApiModelProperty("充值记录ID")
private String chargeRecordId;
@TableField("create_time")
@ApiModelProperty("创建时间")
private Date createTime;
}

View File

@@ -1,15 +0,0 @@
package com.accompany.business.vo;
import lombok.Data;
@Data
public class FirstChargeInfoVo {
// 安卓、iOS企业包
private String commonChargeProdId;
private Long chargeMoney;
// iOS内购充值Id
private String iOSInternalChargeProdId;
}

View File

@@ -1,15 +0,0 @@
package com.accompany.business.vo;
import lombok.Data;
@Data
public class FirstChargeLevelInfoVo {
private Integer id;
private String firstChargeLevelName;
private String firstChargeInfo;
private Integer giveShowPrice;
}

View File

@@ -1,14 +0,0 @@
package com.accompany.business.vo;
import lombok.Data;
@Data
public class FirstChargeRewardConfigVo {
// 开关
private Boolean open;
// 首充礼包说明
private String chargeProdDesc;
}

View File

@@ -1,28 +0,0 @@
package com.accompany.business.vo;
import com.accompany.business.model.FirstChargeReward;
import lombok.Data;
import java.util.List;
@Data
public class FirstChargeVo {
// 充值产品Id
private String chargeProdId;
// 充值金额
private Double chargeMoney;
// 额外礼包金额
private Integer giveMoney;
// 首充礼包说明
private String chargeProdDesc;
// 首充显示标题
private String chargeProdTitle;
private List<FirstChargeReward> firstChargeRewardList;
}

View File

@@ -1,14 +0,0 @@
package com.accompany.business.vo.firstcharge;
import com.accompany.business.vo.FirstChargeVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class LimitFirstChargeTaskVo extends FirstChargeVo {
@ApiModelProperty("是否完成该类充值")
private Boolean finishCharge;
}

View File

@@ -1,20 +0,0 @@
package com.accompany.business.vo.firstcharge;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Data
@NoArgsConstructor
public class LimitFirstChargeVo {
@ApiModelProperty("限时首充结束时间")
private Date limitEndTime;
@ApiModelProperty("限时首充任务列表")
private List<LimitFirstChargeTaskVo> limitFirstChargeTaskList = new ArrayList<>();
}

View File

@@ -1,53 +0,0 @@
package com.accompany.business.event.listener;
import com.accompany.business.service.activity.FirstRechargeActivityService;
import com.accompany.business.service.activity.h5.ActivityOfChargeService;
import com.accompany.common.constant.Constant;
import com.accompany.payment.event.ChargeSuccessEvent;
import com.accompany.payment.model.ChargeRecord;
import com.accompany.payment.service.ChargeRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
* 充值成功活动监听
*/
@Component
public class ActivityRechargeListener implements ApplicationListener<ChargeSuccessEvent> {
private static final Logger logger = LoggerFactory.getLogger(ActivityRechargeListener.class);
@Autowired
private FirstRechargeActivityService firstRechargeActivityService;
@Autowired
private ChargeRecordService chargeRecordService;
@Override
@Async
public void onApplicationEvent(ChargeSuccessEvent chargeSuccessEvent) {
ChargeRecord chargeRecord = (ChargeRecord) chargeSuccessEvent.getSource();
logger.info("chargeSuccessMessage is {}", chargeRecord);
if(chargeRecord.getBussType().equals(Constant.PayBussType.lucky_tarot)){
return ;
}
try {
Long uid = chargeRecord.getUid();
// 充值人民币(元)
Integer money = chargeRecord.getAmount().intValue() / 100;
// 是否是首充
Integer rechargeCount = chargeRecordService.historyRechargeCount(uid);
Boolean isFirstRecharge = rechargeCount <= 1 ? true : false;
logger.info("ActivityRechargeListener isFirstRecharge, uid:{}, {}", uid, isFirstRecharge);
// 首充活动
firstRechargeActivityService.firstRechargeCheck(uid, money, isFirstRecharge);
}catch (Exception e){
logger.error("chargeSuccessMessage error is {}", chargeRecord, e);
}
}
}

View File

@@ -1,61 +0,0 @@
package com.accompany.business.event.listener;
import com.accompany.business.service.charge.FirstChargeRewardService;
import com.accompany.business.vo.FirstChargeRewardConfigVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.core.service.common.JedisService;
import com.accompany.payment.event.ChargeSuccessEvent;
import com.accompany.payment.model.ChargeRecord;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
/**
* 首充激励监听器
*/
@Slf4j
@Component
public class FirstChargeRewardListener implements ApplicationListener<ChargeSuccessEvent> {
@Autowired
private FirstChargeRewardService firstChargeRewardService;
@Autowired
private JedisService jedisService;
@Override
@Async
public void onApplicationEvent(ChargeSuccessEvent chargeSuccessEvent) {
log.info("FirstChargeRewardListener event{}",chargeSuccessEvent);
ChargeRecord chargeRecord = (ChargeRecord) chargeSuccessEvent.getSource();
Long uid = chargeRecord.getUid();
if (chargeRecord.getChargeStatus().equals(Constant.ChargeRecordStatus.finish)) {
// 限时首充状态
Boolean limitCharge = firstChargeRewardService.checkLimitCharge(uid);
// 处于限时首充活动中,仅获得限时首充奖励
if (limitCharge) {
log.info("uid{} firstCharge in limit ",uid);
firstChargeRewardService.getLimitFirstChargeLevelReward(chargeRecord);
} else {
String userFirstChargeStatus = jedisService.hget(RedisKey.first_charge_reward_user.getKey(), uid.toString());
// 当用户满足首充资格则修改状态
log.info("首充激励: chargeRecord {} 获取首充状态 {},", JSON.toJSONString(chargeRecord), userFirstChargeStatus);
if (userFirstChargeStatus == null || Boolean.parseBoolean(userFirstChargeStatus)) {
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
log.info("首充激励成功: uid {} ", uid);
// 判断首充激励开关
FirstChargeRewardConfigVo config = firstChargeRewardService.getFirstChargeRewardConfig();
if (!config.getOpen()) {
return;
}
firstChargeRewardService.userFirstCharge(chargeRecord);
}
}
}
}
}

View File

@@ -1,9 +0,0 @@
package com.accompany.business.mybatismapper;
import com.accompany.business.model.FirstChargeLevel;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface FirstChargeLevelMapper extends BaseMapper<FirstChargeLevel> {
}

View File

@@ -1,20 +0,0 @@
package com.accompany.business.mybatismapper;
import com.accompany.business.model.FirstChargeReward;
import com.accompany.business.vo.FirstChargeLevelInfoVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface FirstChargeRewardMapper extends BaseMapper<FirstChargeReward> {
List<FirstChargeReward> getFirstChargeRewardList(@Param("firstChargeLevel") Integer firstChargeLevel);
List<FirstChargeLevelInfoVo> getFirstChargeInfoList(@Param("isLimit") Boolean isLimit);
List<FirstChargeReward> getUserFirstChargeRewardList(@Param("amount") Long amount);
FirstChargeLevelInfoVo getFirstChargeInfoByRewardLevel(@Param("rewardLevelId") Long rewardLevelId);
}

View File

@@ -1,9 +0,0 @@
package com.accompany.business.mybatismapper;
import com.accompany.business.model.FirstChargeRewardRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
public interface FirstChargeRewardRecordMapper extends BaseMapper<FirstChargeRewardRecord> {
}

View File

@@ -1,116 +0,0 @@
package com.accompany.business.service.activity;
import cn.hutool.core.collection.CollectionUtil;
import com.accompany.business.model.CarGoods;
import com.accompany.business.model.Headwear;
import com.accompany.business.model.Nameplate;
import com.accompany.business.model.activity.FirstRechargeActivityConfig;
import com.accompany.business.mybatismapper.CarGoodsMapper;
import com.accompany.business.mybatismapper.NameplateMapper;
import com.accompany.business.service.car.CarPayService;
import com.accompany.business.service.headwear.HeadwearService;
import com.accompany.business.service.nameplate.UserNameplateService;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.common.utils.StringUtils;
import com.accompany.core.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 首次充值赠送特权活动
*/
@Service
public class FirstRechargeActivityService extends BaseService {
@Autowired
ActivityConfigService activityConfigService;
@Autowired
private NameplateMapper nameplateMapper;
@Autowired
private UserNameplateService userNameplateService;
@Autowired
private HeadwearService headwearService;
@Autowired
private CarPayService carPayService;
@Autowired
private CarGoodsMapper carGoodsMapper;
private FirstRechargeActivityConfig getConfig() {
// 获取配置
String activityConfig = activityConfigService.getSingleConf("first_recharge_activity");
if (StringUtils.isBlank(activityConfig)) {
return null;
}
return gson.fromJson(activityConfig, FirstRechargeActivityConfig.class);
}
public void firstRechargeCheck(Long uid, Integer money, Boolean isFirstRecharge) {
if (!isFirstRecharge) {
return;
}
FirstRechargeActivityConfig config = getConfig();
if (null == config) {
return;
}
if (money < config.getMoney1()) {
return;
}
if (!DateTimeUtil.isBetweenDate(new Date(), config.getStartTime(), config.getEndTime())) {
return;
}
sendBonus(uid, money, config);
}
private void sendBonus(Long uid, Integer money, FirstRechargeActivityConfig config) {
if (money >= config.getMoney2()) {
sendBonusToOne(uid, config.getBonus2());
return;
}
if (money >= config.getMoney1()) {
sendBonusToOne(uid, config.getBonus1());
return;
}
}
private void sendBonusToOne(Long uid, List<List<Integer>> bonus) {
// bonus: [[铭牌id天数], [头饰id天数], [座驾id天数]]
// 发放铭牌
List<Integer> nameplateBonus = bonus.get(0);
if (CollectionUtil.isNotEmpty(nameplateBonus)) {
Nameplate nameplate = nameplateMapper.selectById(nameplateBonus.get(0));
if (nameplate != null) {
userNameplateService.sendUserNameplate(uid, nameplateBonus.get(0).longValue(), "首充活動贈送",
nameplateBonus.get(1));
userNameplateService.sendNameplateSecretaryMessage(uid,
String.format("小秘書贈送給你的%s有效期%s天已經幫你放進裝扮里啦快點移步查看吧",
nameplate.getName(), nameplateBonus.get(1)));
}
}
// 发放头饰
List<Integer> headwearBonus = bonus.get(1);
if (CollectionUtil.isNotEmpty(headwearBonus)) {
Headwear headwear = headwearService.getHeadwear(headwearBonus.get(0));
if (headwear != null) {
headwearService.officialSendHeadWearSingle(headwearBonus.get(0), uid, headwearBonus.get(1));
headwearService.sendHeadwearSecretaryMessage(uid,
String.format("小秘書贈送給你的%s有效期%s天已經幫你放進裝扮里啦快點移步查看吧",
headwear.getName(), headwearBonus.get(1)));
}
}
// 发放座驾
List<Integer> carBonus = bonus.get(2);
if (CollectionUtil.isNotEmpty(carBonus)) {
CarGoods carGoods = carGoodsMapper.selectByPrimaryKey(carBonus.get(0));
if (carGoods != null) {
carPayService.experCarByOfficial(uid, carBonus.get(0), carBonus.get(1), "首充活動贈送",
true);
}
}
}
}

View File

@@ -1,21 +0,0 @@
package com.accompany.business.service.charge;
import com.accompany.business.model.FirstChargeLevel;
import com.accompany.business.mybatismapper.FirstChargeLevelMapper;
import com.accompany.common.constant.Constant;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class FirstChargeLevelService extends ServiceImpl<FirstChargeLevelMapper, FirstChargeLevel> {
public FirstChargeLevel getOneLimitByAmount(Long amount) {
return this.getOne(new LambdaQueryWrapper<FirstChargeLevel>()
.le(FirstChargeLevel::getLowerLimit, amount)
.ge(FirstChargeLevel::getUpperLimit, amount)
.eq(FirstChargeLevel::getFirstChargeType, 2)
.eq(FirstChargeLevel::getFirstChargeStatus, Constant.status.valid));
}
}

View File

@@ -1,59 +0,0 @@
package com.accompany.business.service.charge;
import com.accompany.business.model.FirstChargeRewardRecord;
import com.accompany.business.mybatismapper.FirstChargeRewardRecordMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.Collections;
import java.util.List;
@Slf4j
@Service
public class FirstChargeRewardRecordService extends ServiceImpl<FirstChargeRewardRecordMapper, FirstChargeRewardRecord> {
/**
* 根据 levelIds 获取 指定用户 限时首充奖励记录,
*
* @param levelIds
* @param uid
* @return 当奖励等级id为空时返回空list
*/
public List<FirstChargeRewardRecord> getRecordByLevelIds(List<Integer> levelIds, Long uid) {
if (CollectionUtils.isEmpty(levelIds)) {
return Collections.emptyList();
} else {
return this.list(new LambdaQueryWrapper<FirstChargeRewardRecord>()
.in(FirstChargeRewardRecord::getFirstChargeLevelId, levelIds)
.eq(FirstChargeRewardRecord::getUid, uid)
);
}
}
/**
* 存在 uid & levelId 唯一索引限制,未成功时返回 null
*
* @param uid
* @param levelId
* @return
*/
public FirstChargeRewardRecord addRecord(Long uid, Integer levelId) {
FirstChargeRewardRecord one = this.getByUidAndLevelId(uid, levelId);
if (one == null) {
FirstChargeRewardRecord entity = new FirstChargeRewardRecord();
entity.setUid(uid);
entity.setFirstChargeLevelId(levelId);
this.save(entity);
return entity;
}
return null;
}
public FirstChargeRewardRecord getByUidAndLevelId(Long uid, Integer levelId) {
return this.getOne(new LambdaQueryWrapper<FirstChargeRewardRecord>()
.eq(FirstChargeRewardRecord::getUid, uid)
.eq(FirstChargeRewardRecord::getFirstChargeLevelId, levelId));
}
}

View File

@@ -1,553 +0,0 @@
package com.accompany.business.service.charge;
import com.accompany.business.enums.resource.ResourceCodeEnum;
import com.accompany.business.model.FirstChargeLevel;
import com.accompany.business.model.FirstChargeReward;
import com.accompany.business.model.FirstChargeRewardRecord;
import com.accompany.business.model.Gift;
import com.accompany.business.mybatismapper.FirstChargeRewardMapper;
import com.accompany.business.param.UserBackpackParam;
import com.accompany.business.param.neteasepush.NeteasePushParam;
import com.accompany.business.param.neteasepush.NeteaseSendMsgParam;
import com.accompany.business.service.SendSysMsgService;
import com.accompany.business.service.car.CarPayService;
import com.accompany.business.service.gift.GiftService;
import com.accompany.business.service.headwear.HeadwearService;
import com.accompany.business.service.nameplate.UserNameplateService;
import com.accompany.business.service.purse.UserPurseService;
import com.accompany.business.service.record.BillRecordService;
import com.accompany.business.service.resource.ResourceService;
import com.accompany.business.service.user.UserBackpackService;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.FirstChargeInfoVo;
import com.accompany.business.vo.FirstChargeLevelInfoVo;
import com.accompany.business.vo.FirstChargeRewardConfigVo;
import com.accompany.business.vo.FirstChargeVo;
import com.accompany.business.vo.config.LimitFirstChargeConfig;
import com.accompany.business.vo.firstcharge.LimitFirstChargeTaskVo;
import com.accompany.business.vo.firstcharge.LimitFirstChargeVo;
import com.accompany.common.config.SystemConfig;
import com.accompany.common.constant.Attach;
import com.accompany.common.constant.Constant;
import com.accompany.common.device.DeviceInfo;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.status.BusiStatus;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.enumeration.BillObjTypeEnum;
import com.accompany.core.exception.ServiceException;
import com.accompany.core.model.Account;
import com.accompany.core.model.Users;
import com.accompany.core.mybatismapper.AccountMapper;
import com.accompany.core.service.SysConfService;
import com.accompany.core.service.base.BaseService;
import com.accompany.core.util.StringUtils;
import com.accompany.payment.constant.PayConstant;
import com.accompany.payment.mapper.ChargeRecordMapper;
import com.accompany.payment.model.ChargeRecord;
import com.accompany.payment.model.ChargeRecordExample;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Slf4j
public class FirstChargeRewardService extends BaseService {
@Autowired
private FirstChargeRewardMapper firstChargeRewardMapper;
@Autowired
private SysConfService sysConfService;
@Autowired
private HeadwearService headwearService;
@Autowired
private CarPayService carPayService;
@Autowired
private UserNameplateService userNameplateService;
@Autowired
private GiftService giftService;
@Autowired
private UserBackpackService userBackpackService;
@Autowired
private BillRecordService billRecordService;
@Autowired
private UserPurseService userPurseService;
@Autowired
private SendSysMsgService sendSysMsgService;
@Autowired
private FirstChargeRewardRecordService firstChargeRewardRecordService;
@Autowired
private ChargeRecordMapper chargeRecordMapper;
@Autowired
private AccountMapper accountMapper;
@Autowired
private UsersService usersService;
@Autowired
private FirstChargeLevelService firstChargeLevelService;
@Autowired
private ResourceService resourceService;
public List<FirstChargeVo> getFirstChargeRewardList(DeviceInfo deviceInfo) {
FirstChargeRewardConfigVo config = this.getFirstChargeRewardConfig();
List<FirstChargeVo> chargeReward = new LinkedList<>();
if (!config.getOpen()) {
return chargeReward;
}
String chargeProdDesc = config.getChargeProdDesc();
List<FirstChargeLevelInfoVo> firstChargeInfoList = firstChargeRewardMapper.getFirstChargeInfoList(false);
List<FirstChargeReward> chargeRewardList;
FirstChargeVo firstCharge;
for (FirstChargeLevelInfoVo vo : firstChargeInfoList) {
firstCharge = new FirstChargeVo();
chargeRewardList = firstChargeRewardMapper.getFirstChargeRewardList(vo.getId());
String firstChargeInfoStr = vo.getFirstChargeInfo();
FirstChargeInfoVo infoVo = JSONObject.parseObject(firstChargeInfoStr, FirstChargeInfoVo.class);
// 获取充值产品id
String chargeProdId = this.getChargeProdId(infoVo, deviceInfo);
firstCharge.setChargeProdId(chargeProdId);
BigDecimal chargeMoney = new BigDecimal(infoVo.getChargeMoney().toString()).divide(PayConstant.HUNDRED, 2, RoundingMode.HALF_UP);
firstCharge.setChargeMoney(chargeMoney.doubleValue());
firstCharge.setFirstChargeRewardList(chargeRewardList);
firstCharge.setGiveMoney(vo.getGiveShowPrice());
firstCharge.setChargeProdDesc(chargeProdDesc);
String chargeProdTitle = String.format("充 $%.2f 額外送 $%s 禮包", chargeMoney.doubleValue(), vo.getGiveShowPrice());
firstCharge.setChargeProdTitle(chargeProdTitle);
chargeReward.add(firstCharge);
}
return chargeReward;
}
public LimitFirstChargeVo getLimitFirstChargeRewardList(Long uid, DeviceInfo deviceInfo) {
LimitFirstChargeConfig config = this.getLimitFirstChargeRewardConfig();
Boolean showLimitCharge = this.checkLimitCharge(uid, config);
if (!showLimitCharge) {
throw new ServiceException(BusiStatus.NOTEXISTS);
}
LimitFirstChargeVo limitFirstChargeVo = new LimitFirstChargeVo();
String chargeProdDesc = config.getChargeProdDesc();
// 限时首充奖励等级信息
List<FirstChargeLevelInfoVo> firstChargeInfoList = firstChargeRewardMapper.getFirstChargeInfoList(true);
List<Integer> levelIds = firstChargeInfoList.stream().map(FirstChargeLevelInfoVo::getId).collect(Collectors.toList());
// 用户 获得过的level奖励列表
List<FirstChargeRewardRecord> recordList = firstChargeRewardRecordService.getRecordByLevelIds(levelIds, uid);
Map<Integer, Long> recordMap = recordList.stream().collect(Collectors.toMap(FirstChargeRewardRecord::getFirstChargeLevelId, FirstChargeRewardRecord::getId));
// 检查用户是否完成所有限时首充
this.checkFinishedAllLimitCharge(levelIds, recordMap.keySet(), uid);
Users usersByUid = usersService.getUsersByUid(uid);
List<FirstChargeReward> chargeRewardList;
LimitFirstChargeTaskVo firstCharge;
for (FirstChargeLevelInfoVo levelInfoVo : firstChargeInfoList) {
firstCharge = new LimitFirstChargeTaskVo();
chargeRewardList = firstChargeRewardMapper.getFirstChargeRewardList(levelInfoVo.getId());
String firstChargeInfoStr = levelInfoVo.getFirstChargeInfo();
FirstChargeInfoVo infoVo = JSONObject.parseObject(firstChargeInfoStr, FirstChargeInfoVo.class);
// 获取充值产品id
String chargeProdId = this.getChargeProdId(infoVo, deviceInfo);
firstCharge.setChargeProdId(chargeProdId);
BigDecimal chargeMoney = new BigDecimal(infoVo.getChargeMoney().toString()).divide(PayConstant.HUNDRED, 2, RoundingMode.HALF_UP);
String chargeProdTitle = String.format(config.getChargeProdTitelStr(), chargeMoney, chargeMoney.multiply(new BigDecimal("10")));
firstCharge.setChargeMoney(chargeMoney.doubleValue());
firstCharge.setFirstChargeRewardList(chargeRewardList);
firstCharge.setGiveMoney(levelInfoVo.getGiveShowPrice());
firstCharge.setChargeProdDesc(chargeProdDesc);
firstCharge.setChargeProdTitle(chargeProdTitle);
firstCharge.setFinishCharge(recordMap.get(levelInfoVo.getId()) == null ? false : true);
// 填充vo
limitFirstChargeVo.getLimitFirstChargeTaskList().add(firstCharge);
}
limitFirstChargeVo.setLimitEndTime(getLimitChargeEndTime(usersByUid.getCreateTime()));
return limitFirstChargeVo;
}
private void checkFinishedAllLimitCharge(List<Integer> levelIds, Set<Integer> finishLevelIds, Long uid) {
if (finishLevelIds == null || finishLevelIds.size() == 0)
return;
// 已完成的限时首充等级中包含当前所有生效的限时首充等级
if (!finishLevelIds.containsAll(levelIds))
return;
// 完成所有奖励时,将用户加入完成列表
jedisService.sadd(RedisKey.limit_first_charge_finished_user.getKey(), uid.toString());
}
private LimitFirstChargeConfig getLimitFirstChargeRewardConfig() {
String result = sysConfService.getSysConfValueById(Constant.SysConfId.LIMIT_FIRST_CHARGE_REWARD);
if (StringUtils.isBlank(result)) {
throw new ServiceException(BusiStatus.ALREADY_NOTEXISTS_CONFIG);
}
LimitFirstChargeConfig config = JSONObject.parseObject(result, LimitFirstChargeConfig.class);
return config;
}
public FirstChargeRewardConfigVo getFirstChargeRewardConfig() {
String result = sysConfService.getSysConfValueById(Constant.SysConfId.FIRST_CHARGE_REWARD);
if (StringUtils.isBlank(result)) {
throw new ServiceException(BusiStatus.ALREADY_NOTEXISTS_CONFIG);
}
return JSONObject.parseObject(result, FirstChargeRewardConfigVo.class);
}
public void userFirstCharge(ChargeRecord chargeRecord) {
Long uid = chargeRecord.getUid();
List<FirstChargeReward> chargeRewardList = firstChargeRewardMapper.getUserFirstChargeRewardList(chargeRecord.getAmount());
if (CollectionUtils.isEmpty(chargeRewardList)) {
log.info("首充激励:奖励列表获取失败: 用户 {} ,充值记录ID {},充值金额为 {},", uid, chargeRecord.getChargeRecordId(), chargeRecord.getAmount() / 100);
return;
}
// 判断是否有首充记录
QueryWrapper<FirstChargeRewardRecord> rewardRecordWrapper = new QueryWrapper<>();
rewardRecordWrapper.eq("uid", uid);
long countRewardRecord = firstChargeRewardRecordService.count(rewardRecordWrapper);
long timeMillis = System.currentTimeMillis();
if (countRewardRecord > 0L) {
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
log.info("首充激励:用户已存在首充记录中:{},记录次数为:{},当前时间为:{}", uid, countRewardRecord, countRewardRecord, timeMillis);
return;
}
String lockVal = null;
try {
lockVal = this.jedisLockService.lock(RedisKey.first_charge_reward_send_reward_lock.getKey(uid.toString()), 1000);
if (StringUtils.isEmpty(lockVal)) {
throw new ServiceException(BusiStatus.SERVERBUSY);
}
countRewardRecord = firstChargeRewardRecordService.count(rewardRecordWrapper);
if (countRewardRecord < 1) {
String message = "恭喜通過首充禮包獲得";
Long rewardLevelId = chargeRewardList.get(0).getId();
FirstChargeLevelInfoVo rewardInfo = firstChargeRewardMapper.getFirstChargeInfoByRewardLevel(rewardLevelId);
String firstChargeInfoStr = rewardInfo.getFirstChargeInfo();
FirstChargeInfoVo infoVo = JSONObject.parseObject(firstChargeInfoStr, FirstChargeInfoVo.class);
String chargeProdTitle = String.format("充 $%s 額外送 $%s 禮包", infoVo.getChargeMoney(), rewardInfo.getGiveShowPrice());
// 发放奖励
Map<String, String> sendMsgResultMap = sendReword(chargeRewardList, uid, message);
Boolean notJump = Boolean.getBoolean(sendMsgResultMap.get("notJump"));
String jumpText = sendMsgResultMap.get("jumpText");
message = sendMsgResultMap.get("message");
String rewardJsonStr = sendMsgResultMap.get("rewardJsonStr");
if (!notJump) {
message = message.substring(0, message.length() - 1);
}
// 奖励弹窗
sendRewardMessage(uid, chargeRewardList, chargeProdTitle, Constant.DefMsgType.FIRST_CHARGE_REWARD_MSG);
message = message + jumpText;
// 小秘书消息
sendFirstChargeRewardMsg(uid, message, notJump);
FirstChargeRewardRecord rewardRecord = new FirstChargeRewardRecord();
rewardRecord.setReceiveReward(rewardJsonStr);
rewardRecord.setUid(uid);
rewardRecord.setChargeRecordId(chargeRecord.getChargeRecordId());
rewardRecord.setAmount(chargeRecord.getAmount());
rewardRecord.setFirstChargeLevelId(rewardLevelId.intValue());
firstChargeRewardRecordService.save(rewardRecord);
logger.info("首充激励:用户:{} ,成功获得奖励等级:{},充值记录id:{},获得档位奖励:{}", uid, rewardLevelId, chargeRecord.getChargeRecordId(), JSON.toJSONString(chargeRewardList));
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
}
} finally {
jedisLockService.unlock(RedisKey.first_charge_reward_send_reward_lock.getKey(uid.toString()), lockVal);
}
}
private Map<String, String> sendReword(List<FirstChargeReward> chargeRewardList, Long uid, String message) {
String jumpText = StringUtils.EMPTY;
Boolean notJump = false;
Map<Long, String> rewardMap = new HashMap<>();
for (FirstChargeReward chargeReward : chargeRewardList) {
String awardName = "";
Long rewardId = chargeReward.getRewardId();
if (chargeReward.getRewardType().equals(Constant.firstChargeRewardType.GIFT)) {
sendGiftbyUser(chargeReward.getRewardId().intValue(), uid, chargeReward.getRewardNum());
awardName = chargeReward.getShowText() + "";
} else if (chargeReward.getRewardType().equals(Constant.firstChargeRewardType.NAME_PLATE)) {
userNameplateService.officialSendNameplateSingle(rewardId, uid, chargeReward.getRewardDay(), "首充激勵", SystemConfig.secretaryUid, null, null);
jumpText = "快前往裝扮中心使用吧>>";
notJump = true;
awardName = chargeReward.getShowText() + "";
} else if (chargeReward.getRewardType().equals(Constant.firstChargeRewardType.CAR)) {
carPayService.experCarByOfficial(uid, rewardId.intValue(), chargeReward.getRewardDay(), "首充激勵", false);
jumpText = "快前往裝扮中心使用吧>>";
notJump = true;
awardName = chargeReward.getShowText() + "";
} else if (chargeReward.getRewardType().equals(Constant.firstChargeRewardType.HEADWEAR)) {
headwearService.officialSendHeadWearSingle(rewardId.intValue(), uid, chargeReward.getRewardDay(), false);
jumpText = "快前往裝扮中心使用吧>>";
notJump = true;
awardName = chargeReward.getShowText() + "";
} else if (chargeReward.getRewardType().equals(Constant.firstChargeRewardType.DIAMOND)) {
// 贈送鉆石,插入賬單
awardName = chargeReward.getShowText() + "";
userPurseService.addDiamond(uid, chargeReward.getRewardNum().doubleValue(), BillObjTypeEnum.FRIST_CHARGE_REWARD);
}
message = message + awardName;
rewardMap.put(rewardId, awardName);
}
String rewardJsonStr = JSON.toJSONString(rewardMap);
Map<String, String> resultMap = new HashMap<String, String>();
resultMap.put("message", message);
resultMap.put("rewardJsonStr", rewardJsonStr);
resultMap.put("jumpText", jumpText);
resultMap.put("notJump", notJump.toString());
return resultMap;
}
/**
* 获取限时首充奖励
*
* @param chargeRecord
*/
public void getLimitFirstChargeLevelReward(ChargeRecord chargeRecord) {
Long uid = chargeRecord.getUid();
FirstChargeLevel chargeLevel = firstChargeLevelService.getOneLimitByAmount(chargeRecord.getAmount());
// 查询当前用户当前首充等级奖励记录
FirstChargeRewardRecord rewardRecord = firstChargeRewardRecordService.getByUidAndLevelId(uid, chargeLevel.getId());
if (rewardRecord != null) {
return;
}
String lockVal = null;
try {
lockVal = this.jedisLockService.lock(RedisKey.limit_first_charge_reward_send_reward_lock.getKey(uid.toString()), 1000);
if (StringUtils.isEmpty(lockVal)) {
throw new ServiceException(BusiStatus.SERVERBUSY);
}
LimitFirstChargeConfig config = getLimitFirstChargeRewardConfig();
// 添加记录
rewardRecord = firstChargeRewardRecordService.addRecord(chargeRecord.getUid(), chargeLevel.getId());
// 添加失败表示已被发放
if (rewardRecord == null) {
return;
}
List<FirstChargeReward> rewardList = firstChargeRewardMapper.getFirstChargeRewardList(chargeLevel.getId());
String message = "恭喜通過限時首充禮包獲得";
// 发放奖励
Map<String, String> sendMsgResultMap = this.sendReword(rewardList, uid, message);
Boolean notJump = Boolean.getBoolean(sendMsgResultMap.get("notJump"));
String jumpText = sendMsgResultMap.get("jumpText");
message = sendMsgResultMap.get("message");
String rewardJsonStr = sendMsgResultMap.get("rewardJsonStr");
if (!notJump) {
message = message.substring(0, message.length() - 1);
}
// 弹窗信息
sendRewardMessage(uid, rewardList, config.getSuccessTitelMsg(), Constant.DefMsgType.LIMIT_FIRST_CHARGE_REWARD_MSG);
// 小秘书信息
message = message + jumpText;
sendFirstChargeRewardMsg(uid, message, notJump);
// 更新记录
rewardRecord.setReceiveReward(rewardJsonStr);
rewardRecord.setChargeRecordId(chargeRecord.getChargeRecordId());
rewardRecord.setAmount(chargeRecord.getAmount());
firstChargeRewardRecordService.updateById(rewardRecord);
// 标记已完成 首充
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
} finally {
jedisLockService.unlock(RedisKey.limit_first_charge_reward_send_reward_lock.getKey(uid.toString()), lockVal);
}
}
private void sendGiftbyUser(Integer giftId, Long userId, Integer giftNum) {
Gift gift = giftService.getGiftById(giftId);
UserBackpackParam backpackParam = new UserBackpackParam();
backpackParam.setGiftSeq(gift.getSeqNo());
backpackParam.setGiftId(gift.getGiftId());
backpackParam.setCount(giftNum);
backpackParam.setUid(userId);
backpackParam.setGiftType(Constant.GiftType.ACTIVITY);
userBackpackService.saveOrUpdateUserBackpack(backpackParam);
}
// 首充激励充值成功通知客户端
private void sendRewardMessage(Long uid, List<FirstChargeReward> chargeRewardList, String chargeProdTitle, Integer second) {
NeteasePushParam neteasePushParam = new NeteasePushParam();
neteasePushParam.setFrom(SystemConfig.secretaryUid);
neteasePushParam.setTo(uid.toString());
neteasePushParam.setMsgtype(0);
neteasePushParam.setSave(2);
Attach attach = new Attach();
attach.setFirst(Constant.DefMsgType.FIRST_CHARGE_REWARD);
attach.setSecond(second);
JSONObject jsonObject = new JSONObject();
jsonObject.put("firstChargeRewardList", chargeRewardList);
jsonObject.put("chargeProdTitle", chargeProdTitle);
attach.setData(jsonObject);
neteasePushParam.setAttach(attach);
sendSysMsgService.sendSysAttachMsg(neteasePushParam);
}
// 首充激励奖励小秘书通知
private void sendFirstChargeRewardMsg(Long uid, String message, Boolean notJump) {
NeteaseSendMsgParam msg = new NeteaseSendMsgParam();
if (notJump) {
Attach attach = new Attach();
attach.setFirst(Constant.DefineProtocol.CUSTOM_MESS_HEAD_SECRETARY);
attach.setSecond(Constant.DefineProtocol.CUSTOM_MESS_SUB_SECRETARY_INTRACTION);
JSONObject jsonObject = new JSONObject();
jsonObject.put("msg", message);
jsonObject.put("routerType", Constant.SecretarySkipType.HEADWEAR);
jsonObject.put("routerValue", 1);
attach.setData(jsonObject);
msg.setAttach(attach);
msg.setType(Constant.DefineProtocol.CUSTOM_MESS_DEFINE);
} else {
msg.setBody(message);
}
msg.setFrom(SystemConfig.secretaryUid);
msg.setOpe(0);
msg.setTo(uid.toString());
sendSysMsgService.sendMsg(msg);
}
public Boolean isFirstCharge(Long uid) {
if (!resourceService.isOpen(ResourceCodeEnum.FIRST_CHARGE.name())) {
return false;
}
Boolean chargeRewardUser = jedisService.hexists(RedisKey.first_charge_reward_user.getKey(), uid.toString());
if (chargeRewardUser) {
return Boolean.valueOf(jedisService.hget(RedisKey.first_charge_reward_user.getKey(), uid.toString()));
}
long countRewardRecord = firstChargeRewardRecordService.count(Wrappers.<FirstChargeRewardRecord>lambdaQuery()
.eq(FirstChargeRewardRecord::getUid, uid));
long timeMillis = System.currentTimeMillis();
if (countRewardRecord > 0) {
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), Boolean.FALSE.toString());
log.info("首充激励:{} 用户已存在首充记录中,记录次数为:{},当前时间为:{}", uid, countRewardRecord, timeMillis);
return false;
}
if (!checkUserChargeRecord(uid)) {
return false;
}
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), Boolean.TRUE.toString());
return true;
}
// 校验用户是否有充值过
public Boolean checkUserChargeRecord(Long uid) {
Boolean isFirstCharge = false;
String today = DateTimeUtil.convertDate(new Date());
ChargeRecordExample example = new ChargeRecordExample();
List<Byte> bussType = new LinkedList<>();
bussType.add(Constant.PayBussType.charge);
bussType.add(Constant.PayBussType.lucky_tarot);
example.createCriteria().andChargeStatusEqualTo(Constant.ChargeRecordStatus.finish).andBussTypeIn(bussType).andChannelNotEqualTo("exchange").
andUidEqualTo(uid);
int chargeRecordNum = chargeRecordMapper.countByExample(example);
if (chargeRecordNum > 1) {
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
log.info("首充激励:用户已充值过:{},充值次数为:{},当前时间为:{}", uid, chargeRecordNum, today);
return isFirstCharge;
}
Account userAccount = accountMapper.selectById(uid);
String deviceId = userAccount.getDeviceId();
QueryWrapper<Account> wrapper = new QueryWrapper<>();
wrapper.eq("device_id", deviceId).notIn("uid", uid);
List<Account> accountList = accountMapper.selectList(wrapper);
if (CollectionUtils.isNotEmpty(accountList)) {
List<Long> uids = accountList.stream().map(Account::getUid).collect(Collectors.toList());
example = new ChargeRecordExample();
example.createCriteria().andUidIn(uids).andChargeStatusEqualTo(Constant.ChargeRecordStatus.finish).andBussTypeIn(bussType).andChannelNotEqualTo("exchange");
int countChargeRecord = chargeRecordMapper.countByExample(example);
if (countChargeRecord > 0) {
jedisService.hset(RedisKey.first_charge_reward_user.getKey(), uid.toString(), "false");
log.info("首充激励:用户注册设备关联其他账号已充值过:{},充值次数为:{},当前时间为:{}", uid, countChargeRecord, today);
return isFirstCharge;
}
}
return true;
}
private String getChargeProdId(FirstChargeInfoVo infoVo, DeviceInfo deviceInfo) {
String chargeProdId = StringUtils.EMPTY;
if (deviceInfo != null) {
/** iOS内购支付Id —— 安卓、iOS企业包 **/
if (Constant.OsType.IOS.equalsIgnoreCase(deviceInfo.getOs())) {
chargeProdId = infoVo.getIOSInternalChargeProdId();
} else {
chargeProdId = infoVo.getCommonChargeProdId();
}
}
return chargeProdId;
}
/**
* 限时首充校验
*
* @param uid
* @return 符合所有检验时返回true此时需要展示限时首充
*/
public Boolean checkLimitCharge(Long uid) {
LimitFirstChargeConfig chargeConfig = getLimitFirstChargeRewardConfig();
return checkLimitCharge(uid, chargeConfig);
}
public Boolean checkLimitCharge(Long uid, LimitFirstChargeConfig chargeConfig) {
// 白名单内用户始终开启活动
if (CollectionUtils.isNotEmpty(chargeConfig.getWriteUidList()) && chargeConfig.getWriteUidList().contains(uid)) {
return true;
}
// 活动开关
if (!chargeConfig.getOpen()) {
return false;
}
// 当前用户是否在时限内
Users usersByUid = usersService.getUsersByUid(uid);
if (usersByUid == null)
return false;
Boolean inLimitTime = checkUserLimitTime(usersByUid, chargeConfig.getLimitTimeDays());
if (!inLimitTime) {
return false;
}
// 当前用户是否完成奖励
if (checkFinishedLimitFirstChargeByCache(uid)) {
return false;
}
return true;
}
public Date getLimitChargeEndTime(Date createTime) {
LimitFirstChargeConfig chargeConfig = getLimitFirstChargeRewardConfig();
Date offsetTime = new Date(createTime.getTime() + chargeConfig.getLimitTimeDays() * 24 * 60 * 60 * 1000);
return offsetTime;
}
private Boolean checkUserLimitTime(Users users, Integer limitDays) {
Date createTime = users.getCreateTime();
if (createTime == null)
return false;
Date now = new Date();
Date offsetTime = new Date(now.getTime() - limitDays * 24 * 60 * 60 * 1000);
return createTime.after(offsetTime);
}
/**
* 仅通过缓存检查指定用户是否完成所有限时首充
*
* @param uid
* @return
*/
private Boolean checkFinishedLimitFirstChargeByCache(Long uid) {
return jedisService.sismember(RedisKey.limit_first_charge_finished_user.getKey(), uid.toString());
}
}

View File

@@ -1,104 +0,0 @@
package com.accompany.business.service.charge;
import com.accompany.business.dto.exchange.FirstChargeRoomWindowConfigDto;
import com.accompany.business.service.user.UsersService;
import com.accompany.business.vo.room.RoomFirstChargeWindowVo;
import com.accompany.common.constant.Constant;
import com.accompany.common.redis.RedisKey;
import com.accompany.common.utils.DateTimeUtil;
import com.accompany.core.model.Account;
import com.accompany.core.model.Users;
import com.accompany.core.mybatismapper.AccountMapper;
import com.accompany.core.service.SysConfService;
import com.alibaba.fastjson.JSON;
import org.redisson.api.RMap;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@Service
public class FirstChargeRoomWindowService {
@Autowired
private RedissonClient redissonClient;
@Autowired
private SysConfService sysConfService;
@Autowired
private FirstChargeRewardService firstChargeRewardService;
@Autowired
private AccountMapper accountMapper;
@Autowired
private UsersService usersService;
private FirstChargeRoomWindowConfigDto getRoomWindowConfigDto(){
String configStr = sysConfService.getSysConfValueById(Constant.SysConfId.FIRST_CHARGE_ROOM_WINDOW);
if (StringUtils.hasText(configStr)){
return JSON.parseObject(configStr, FirstChargeRoomWindowConfigDto.class);
}
return null;
}
public RoomFirstChargeWindowVo getVo(Long uid, Long roomUid) {
RoomFirstChargeWindowVo vo = new RoomFirstChargeWindowVo();
vo.setRoomUid(roomUid);
vo.setNeedToShow(false);
vo.setShowAfterSecond(0);
Date now = new Date();
String date = DateTimeUtil.convertDate(now, DateTimeUtil.DEFAULT_DATE_PATTERN);
RMap<Long, Set<Long>> roomUidMap = redissonClient.getMap(RedisKey.room_first_charge_window.getKey(date));
Set<Long> todayRoomUid = roomUidMap.get(uid);
if (!CollectionUtils.isEmpty(todayRoomUid) && todayRoomUid.contains(roomUid)){
return vo;
}
if (!firstChargeRewardService.isFirstCharge(uid)
|| !firstChargeRewardService.checkLimitCharge(uid)){
return vo;
}
FirstChargeRoomWindowConfigDto configDto = getRoomWindowConfigDto();
if (null == configDto || !configDto.getOpen()){
return vo;
}
Account account = accountMapper.selectById(uid);
if (null == account || !configDto.getChannels().contains(account.getChannel())){
return vo;
}
Users user = usersService.getUsersByUid(uid);
if (null == user || DateTimeUtil.compareDay(now, user.getCreateTime()) > configDto.getCreateDayLimit()){
return vo;
}
if (!CollectionUtils.isEmpty(todayRoomUid) && todayRoomUid.size() >= configDto.getShowTimes()){
return vo;
}
roomUidMap.expireAsync(1, TimeUnit.DAYS);
vo.setNeedToShow(true);
vo.setShowAfterSecond(configDto.getShowAfterSecond());
return vo;
}
public void update(Long uid, Long roomUid) {
Date now = new Date();
String date = DateTimeUtil.convertDate(now, DateTimeUtil.DEFAULT_DATE_PATTERN);
RMap<Long, Set<Long>> roomUidMap = redissonClient.getMap(RedisKey.room_first_charge_window.getKey(date));
Set<Long> todayRoomUid = roomUidMap.get(uid);
if (CollectionUtils.isEmpty(todayRoomUid)){
todayRoomUid = new HashSet<>();
}
todayRoomUid.add(roomUid);
roomUidMap.fastPut(uid, todayRoomUid);
}
}

View File

@@ -1,63 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.accompany.business.mybatismapper.FirstChargeRewardMapper">
<select id="getFirstChargeRewardList" resultType="com.accompany.business.model.FirstChargeReward">
SELECT fcr.*,
case when reward_type = 1 then Concat(fcr.reward_num,"个")
when fcr.reward_type = 2 then Concat(fcr.reward_day,"天")
when fcr.reward_type = 3 then Concat(fcr.reward_day,"天")
when fcr.reward_type = 4 then Concat(fcr.reward_day,"天")
ELSE Concat(fcr.reward_num,"个") END as showTime
FROM first_charge_reward fcr
where fcr.first_charge_level_id = #{firstChargeLevel}
order by fcr.seq_no
</select>
<select id="getFirstChargeInfoList" resultType="com.accompany.business.vo.FirstChargeLevelInfoVo">
SELECT fc.id,fc.first_charge_level_name,fi.first_charge_info,give_show_price
FROM first_charge_level fc
left join first_charge_level_info fi on fi.id = fc.first_charge_info_id
where first_charge_status = 1
<choose>
<when test="isLimit">
AND fc.first_charge_type = 2
</when>
<otherwise>
AND fc.first_charge_type = 1
</otherwise>
</choose>
</select>
<select id="getUserFirstChargeRewardList" resultType="com.accompany.business.model.FirstChargeReward">
SELECT fr.first_charge_level_id as 'id',fr.show_text,fr.reward_id,fr.reward_day,fr.reward_num,fr.reward_type,fr.show_pir,
case when reward_type = 1 then Concat(reward_num,"个")
when reward_type = 2 then Concat(reward_day,"天")
when reward_type = 3 then Concat(reward_day,"天")
when reward_type = 4 then Concat(reward_day,"天")
ELSE Concat(reward_num,"个") END as showTime
FROM first_charge_reward fr
inner join first_charge_level fl on fl.id = fr.first_charge_level_id
where fl.lower_limit &lt;= #{amount} and fl.upper_limit &gt;= #{amount}
and fl.first_charge_type = 1 and fl.first_charge_status = 1
</select>
<select id="getLimitFirstChargeRewardList" resultType="com.accompany.business.model.FirstChargeReward">
SELECT fr.first_charge_level_id as 'id',fr.show_text,fr.reward_id,fr.reward_day,fr.reward_num,fr.reward_type,fr.show_pir,
case when reward_type = 1 then Concat(reward_num,"个")
when reward_type = 2 then Concat(reward_day,"天")
when reward_type = 3 then Concat(reward_day,"天")
when reward_type = 4 then Concat(reward_day,"天")
ELSE Concat(reward_num,"个") END as showTime
FROM first_charge_reward fr
left join first_charge_level fl on fl.id = fr.first_charge_level_id
where fl.lower_limit = #{amount} and fl.first_charge_status = 1 and fl.first_charge_type = 2
</select>
<select id="getFirstChargeInfoByRewardLevel" resultType="com.accompany.business.vo.FirstChargeLevelInfoVo">
SELECT fc.id,fc.first_charge_level_name,fi.first_charge_info,give_show_price
FROM first_charge_level fc
left join first_charge_level_info fi on fi.id = fc.first_charge_info_id
where fc.first_charge_status = 1 and fc.first_charge_info_id = #{rewardLevelId}
</select>
</mapper>

View File

@@ -1,58 +0,0 @@
package com.accompany.business.controller.charge;
import com.accompany.business.common.BaseController;
import com.accompany.business.service.charge.FirstChargeRewardService;
import com.accompany.business.vo.FirstChargeVo;
import com.accompany.business.vo.firstcharge.LimitFirstChargeVo;
import com.accompany.common.annotation.Authorization;
import com.accompany.common.device.DeviceInfo;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.vo.BaseResponseVO;
import com.accompany.payment.model.ChargeRecord;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
@Api(tags = "首充激励",value = "首充激励")
@RestController
@RequestMapping(value = "/first/charge")
public class FirstChargeRewardController extends BaseController {
@Autowired
private FirstChargeRewardService firstChargeRewardService;
@Authorization
@ApiModelProperty(value = "首充激励列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
public BaseResponseVO<List<FirstChargeVo>> getFirstChargeRewardList(HttpServletRequest request){
DeviceInfo deviceInfo = getDeviceInfo(request);
List<FirstChargeVo> list = firstChargeRewardService.getFirstChargeRewardList(deviceInfo);
return new BaseResponseVO(BusiStatus.SUCCESS, list);
}
@Authorization
@ApiOperation(value = "限时首充激励列表")
@RequestMapping(value = "limit/list", method = RequestMethod.GET)
public BaseResponseVO<LimitFirstChargeVo> getLimitFirstChargeRewardList(HttpServletRequest request){
DeviceInfo deviceInfo = getDeviceInfo(request);
LimitFirstChargeVo limitFirstChargeVo = firstChargeRewardService.getLimitFirstChargeRewardList(getUid(),deviceInfo);
return new BaseResponseVO(BusiStatus.SUCCESS, limitFirstChargeVo);
}
@ApiOperation(value = "限时首充激励-消息测试")
@RequestMapping(value = "test", method = RequestMethod.GET)
public void test(Long uid,Long amount,String chargeRecordId){
ChargeRecord chargeRecord = new ChargeRecord();
chargeRecord.setUid(uid);
chargeRecord.setAmount(amount);
chargeRecord.setChargeRecordId(chargeRecordId);
firstChargeRewardService.getLimitFirstChargeLevelReward(chargeRecord);
}
}

View File

@@ -9,7 +9,6 @@ import com.accompany.business.enums.resource.ResourceCodeEnum;
import com.accompany.business.enums.resource.ResourceTypeEnum; import com.accompany.business.enums.resource.ResourceTypeEnum;
import com.accompany.business.enums.resource.RuleCodeEnum; import com.accompany.business.enums.resource.RuleCodeEnum;
import com.accompany.business.model.resource.Resource; import com.accompany.business.model.resource.Resource;
import com.accompany.business.service.charge.FirstChargeRewardService;
import com.accompany.business.service.game.GameService; import com.accompany.business.service.game.GameService;
import com.accompany.business.service.game.JoyGameService; import com.accompany.business.service.game.JoyGameService;
import com.accompany.business.service.game.MiniGameForBaiShunService; import com.accompany.business.service.game.MiniGameForBaiShunService;
@@ -21,7 +20,6 @@ import com.accompany.common.annotation.Authorization;
import com.accompany.common.constant.Constant; import com.accompany.common.constant.Constant;
import com.accompany.common.device.DeviceInfo; import com.accompany.common.device.DeviceInfo;
import com.accompany.common.result.BusiResult; import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.base.UidContextHolder; import com.accompany.core.base.UidContextHolder;
import com.accompany.core.exception.ServiceException; import com.accompany.core.exception.ServiceException;
import com.accompany.core.model.Users; import com.accompany.core.model.Users;
@@ -32,7 +30,6 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
@@ -53,8 +50,7 @@ public class ResourceController {
@Autowired @Autowired
private ResourceService resourceService; private ResourceService resourceService;
@Autowired
private FirstChargeRewardService firstChargeRewardService;
@Autowired @Autowired
private MiniGameForBaiShunService miniGameForBaiShunService; private MiniGameForBaiShunService miniGameForBaiShunService;
@Autowired @Autowired
@@ -83,9 +79,6 @@ public class ResourceController {
@Authorization @Authorization
public BusiResult<List<Resource>> banner(@RequestParam(value = "roomUid", required = false) Long roomUid) { public BusiResult<List<Resource>> banner(@RequestParam(value = "roomUid", required = false) Long roomUid) {
List<Resource> resources = resourceService.resources(ResourceTypeEnum.ROOM.ordinal()); List<Resource> resources = resourceService.resources(ResourceTypeEnum.ROOM.ordinal());
if (CollectionUtil.isNotEmpty(resources)) {
resources.removeIf(v -> ResourceCodeEnum.FIRST_CHARGE.name().equals(v.getCode()) && !firstChargeRewardService.isFirstCharge(UidContextHolder.get()));
}
return BusiResult.success(resources); return BusiResult.success(resources);
} }

View File

@@ -1,53 +0,0 @@
package com.accompany.business.controller.room;
import com.accompany.business.common.BaseController;
import com.accompany.business.service.charge.FirstChargeRoomWindowService;
import com.accompany.business.vo.room.RoomFirstChargeWindowVo;
import com.accompany.common.annotation.Authorization;
import com.accompany.common.result.BusiResult;
import com.accompany.common.status.BusiStatus;
import com.accompany.core.exception.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@Api(tags = "房间首充弹窗")
@Slf4j
@RestController
@RequestMapping("/roomFirstChargeWindow")
public class RoomFirstChargeWindowController extends BaseController {
@Autowired
private FirstChargeRoomWindowService firstChargeRoomWindowService;
@ApiOperation("拿次数")
@GetMapping("/get")
@Authorization
public BusiResult<RoomFirstChargeWindowVo> get(HttpServletRequest request, Long roomUid){
if (null == roomUid){
throw new ServiceException(BusiStatus.PARAMERROR);
}
Long uid = getUid(request);
RoomFirstChargeWindowVo vo = firstChargeRoomWindowService.getVo(uid, roomUid);
return new BusiResult<>(vo);
}
@ApiOperation("更新次数")
@PostMapping("/update")
@Authorization
public BusiResult<Void> update(HttpServletRequest request, Long roomUid){
if (null == roomUid){
throw new ServiceException(BusiStatus.PARAMERROR);
}
Long uid = getUid(request);
firstChargeRoomWindowService.update(uid, roomUid);
return new BusiResult<>(BusiStatus.SUCCESS);
}
}