Commit 18ed0b51 authored by 罗林杰's avatar 罗林杰

Merge remote-tracking branch 'origin/master'

parents 2d988356 8e99f622
...@@ -93,5 +93,12 @@ public class MemLeaveMessage extends CyIdIncreNotDataEntity<MemLeaveMessage> { ...@@ -93,5 +93,12 @@ public class MemLeaveMessage extends CyIdIncreNotDataEntity<MemLeaveMessage> {
*/ */
@TableField(exist = false) @TableField(exist = false)
private String isPay; private String isPay;
/**
* 会员wxOpenid
*/
@TableField(exist = false)
private String wxOpenid;
} }
...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.memInfo.bean.MemberInfoRedisBean; import org.rcisoft.business.memInfo.bean.MemberInfoRedisBean;
import org.rcisoft.business.memInfo.dao.MemInfoRepository;
import org.rcisoft.business.memInfo.entity.MemInfo;
import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean; import org.rcisoft.business.memLeaveMessage.bean.MemLeaveMessageRedisBean;
import org.rcisoft.business.memLeaveMessage.dao.MemLeaveMessageRepository; import org.rcisoft.business.memLeaveMessage.dao.MemLeaveMessageRepository;
import org.rcisoft.business.memLeaveMessage.entity.*; import org.rcisoft.business.memLeaveMessage.entity.*;
...@@ -51,6 +53,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -51,6 +53,8 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
@Autowired @Autowired
private CyRedisServiceImpl cyRedisServiceImpl; private CyRedisServiceImpl cyRedisServiceImpl;
@Autowired
private MemInfoRepository memInfoRepository;
/** /**
* 留言 * 留言
* @param memLeaveMessage * @param memLeaveMessage
...@@ -61,16 +65,30 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -61,16 +65,30 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
public CyPersistModel leaveMessage(MemLeaveMessage memLeaveMessage) { public CyPersistModel leaveMessage(MemLeaveMessage memLeaveMessage) {
String userId = CyUserUtil.getAuthenBusinessId(); String userId = CyUserUtil.getAuthenBusinessId();
//获取留言每天限制条数 //获取留言每天限制条数
List<DictData> articleConfig = dictionaryService.selectByTypes("leave_message_config"); List<DictData> leaveMessageConfig = dictionaryService.selectByTypes("leave_message_config");
DictData dictData = articleConfig.stream().filter(item -> item.getDictLabel().equals("leave_message_limit_count")).findFirst().orElse(null); DictData dictData1 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("leave_message_limit_count")).findFirst().orElse(null);
Integer leaveMessageLimitCount = Integer.valueOf(dictData.getDictValue()); DictData dictData2 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("pay_leave_message_limit_count")).findFirst().orElse(null);
//判断留言次数是否大于等于leaveMessageLimitCount Integer leaveMessageLimitCount = Integer.valueOf(dictData1.getDictValue());
Integer payLeaveMessageLimitCount = Integer.valueOf(dictData2.getDictValue());
//判断redis中的留言次数是否大于等于leaveMessageLimitCount
Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId())); Object redisLeaveMessageCount = cyRedisServiceImpl.hget(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()));
if (redisLeaveMessageCount != null && Integer.parseInt(redisLeaveMessageCount.toString()) >= leaveMessageLimitCount){ //超出留言次数的条件:
//1:redis中的存储数量>=字典限制数量
//2:用户不用金币进行留言
//3:超出金币进行留言的限制数量
if (redisLeaveMessageCount != null && Integer.parseInt(redisLeaveMessageCount.toString()) >= leaveMessageLimitCount && memLeaveMessage.getIsPay().equals("0")){
//超出留言次数 //超出留言次数
throw new CyServiceException("留言次数超出限制"); if (Integer.parseInt(redisLeaveMessageCount.toString()) >= payLeaveMessageLimitCount){
//超出金币进行留言的数量限制
throw new CyServiceException(1002,"今日留言次数超出限制");
} else {
throw new CyServiceException(1001,"留言次数超出限制");
}
} else { } else {
//未超出留言次数 if (Integer.parseInt(redisLeaveMessageCount.toString()) >= payLeaveMessageLimitCount){
//超出金币进行留言的数量限制
throw new CyServiceException(1002,"今日留言次数超出限制");
}
//先插入到留言表 //先插入到留言表
memLeaveMessage.setCreateBy(Integer.valueOf(userId)); memLeaveMessage.setCreateBy(Integer.valueOf(userId));
memLeaveMessage.setUpdateBy(Integer.valueOf(userId)); memLeaveMessage.setUpdateBy(Integer.valueOf(userId));
...@@ -113,6 +131,15 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos ...@@ -113,6 +131,15 @@ public class MemLeaveMessageServiceImpl extends ServiceImpl<MemLeaveMessageRepos
cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L); cyRedisServiceImpl.hset(MemLeaveMessageRedisBean.USER_LEAVE_MESSAGE + userId, String.valueOf(memLeaveMessage.getTargetId()), 1L);
} }
} }
//金币支付进行留言
if (memLeaveMessage.getIsPay().equals("1")){
//扣除该用户的金币数量
DictData dictData3 = leaveMessageConfig.stream().filter(item -> item.getDictLabel().equals("pay_count")).findFirst().orElse(null);
Integer payCount = Integer.valueOf(dictData3.getDictValue());
MemInfo memInfo = memInfoRepository.selectByOpenId(memLeaveMessage.getWxOpenid());
memInfo.setGoldCoinsCount(memInfo.getGoldCoinsCount() - payCount);
memInfoRepository.updateById(memInfo);
}
return new CyPersistModel(line); return new CyPersistModel(line);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment