use of cn.imhtb.antlive.entity.Room in project Ant-Live by PinTeh.
the class PresentRewardRewardServiceImpl method createReward.
@Override
public boolean createReward(Integer fromId, Integer presentId, Integer rvId, Integer number, Integer type) {
String mark = null;
Integer toId = null;
Room room;
Present present = presentMapper.selectById(presentId);
BigDecimal totalPrice = present.getPrice().multiply(new BigDecimal(number));
Bill fromLast = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", fromId).orderByDesc("id").last("limit 0,1"));
BigDecimal ret = fromLast.getBalance().subtract(totalPrice);
// 余额不足
if (ret.compareTo(BigDecimal.ZERO) < 0) {
log.info("余额不足");
return false;
}
PresentReward presentReward = new PresentReward();
if (type.equals(Constants.PresentRewardType.LIVE.getCode())) {
room = roomMapper.selectById(rvId);
toId = room.getUserId();
presentReward.setRoomId(room.getId());
presentReward.setType(Constants.PresentRewardType.LIVE.getCode());
mark = Constants.BillMark.LIVE_REWARD.getDesc();
// 直播间显示赠送礼物信息
try {
// TODO 逻辑有点问题
String key = String.format(RedisPrefix.LIVE_KEY_PREFIX, room.getId());
if (redisUtils.exists(key)) {
// 舍去小数点
redisUtils.hIncrBy(key, RedisPrefix.LIVE_PRESENT_COUNT, totalPrice.longValue());
}
User fromUser = userMapper.selectById(fromId);
WebMessage webMessage = WebMessage.createPresent(fromUser, new WebMessage.P(present.getId(), present.getName(), present.getIcon(), number));
roomChatServer.sendSystemPresentMessage(webMessage.toJson(), room.getId());
} catch (Exception e) {
log.error("RoomChatServer err:{}", e.getMessage());
}
} else if (type.equals(Constants.PresentRewardType.VIDEO.getCode())) {
Video video = videoMapper.selectById(rvId);
toId = video.getUserId();
presentReward.setVideoId(video.getId());
presentReward.setType(Constants.PresentRewardType.VIDEO.getCode());
mark = Constants.BillMark.VIDEO_REWARD.getDesc();
}
presentReward.setNumber(number);
presentReward.setUnitPrice(present.getPrice());
presentReward.setFromId(fromId);
presentReward.setToId(toId);
presentReward.setPresentId(present.getId());
presentReward.setTotalPrice(totalPrice);
Bill toLast = billMapper.selectOne(new QueryWrapper<Bill>().eq("user_id", toId).orderByDesc("id").last("limit 0,1"));
Bill fromBill = new Bill();
fromBill.setBillChange(totalPrice.negate());
fromBill.setBalance(fromLast.getBalance().subtract(totalPrice));
fromBill.setMark(mark);
fromBill.setType(Constants.BillType.OUTLAY.getCode());
fromBill.setBillChange(totalPrice.negate());
fromBill.setUserId(fromId);
fromBill.setOrderNo(CommonUtils.getOrderNo());
Bill toBill = new Bill();
toBill.setBillChange(totalPrice);
toBill.setBalance(toLast.getBalance().add(totalPrice));
toBill.setMark(mark);
toBill.setType(Constants.BillType.INCOME.getCode());
toBill.setBillChange(totalPrice);
toBill.setUserId(toId);
toBill.setOrderNo(CommonUtils.getOrderNo());
int rf = presentRewardMapper.insert(presentReward);
int rs = billMapper.insert(fromBill);
int rt = billMapper.insert(toBill);
return rf == 1 && rs == 1 && rt == 1;
}
use of cn.imhtb.antlive.entity.Room in project Ant-Live by PinTeh.
the class LiveInfoController method list.
@GetMapping("/list")
public ApiResponse list(Integer rid, @RequestParam(required = false) String dateRange, @RequestParam(required = false, defaultValue = "10") Integer limit, @RequestParam(required = false, defaultValue = "1") Integer page, HttpServletRequest request) {
String token = request.getHeader(JwtUtils.getHeaderKey());
Integer uid = JwtUtils.getId(token);
Room room = roomService.getOne(new QueryWrapper<Room>().eq("user_id", uid));
String maxTime = "", minTime = "";
boolean condition = !StringUtils.isEmpty(dateRange) && !"null".equals(dateRange);
if (condition) {
maxTime = dateRange.split(",")[1];
minTime = dateRange.split(",")[0];
}
QueryWrapper<LiveInfo> liveInfoQueryWrapper = new QueryWrapper<LiveInfo>().eq("room_id", room.getId()).eq("status", 1).le(condition, "start_time", maxTime).ge(condition, "start_time", minTime).orderByDesc("id");
Page<LiveInfo> liveInfoPage = liveInfoService.page(new Page<>(page, limit), liveInfoQueryWrapper);
LiveStatResponse response = packageResponse(liveInfoPage.getRecords());
response.setTotal(liveInfoPage.getTotal());
return ApiResponse.ofSuccess(response);
}
use of cn.imhtb.antlive.entity.Room in project Ant-Live by PinTeh.
the class LiveController method publish.
/**
* nginx授权认证
*/
@RequestMapping("/on_publish")
public ApiResponse publish(String name, String key, HttpServletResponse response) {
Integer roomId = Integer.valueOf(name);
Room room = roomService.getById(roomId);
if (room != null) {
if (key.equals(room.getSecret())) {
return ApiResponse.ofSuccess();
}
}
response.setStatus(400);
return ApiResponse.ofError();
}
use of cn.imhtb.antlive.entity.Room in project Ant-Live by PinTeh.
the class LiveController method config.
/**
* 更新直播间信息
*/
@PostMapping("/config")
public ApiResponse config(@RequestBody RoomRequest request) {
Room room = modelMapper.map(request, Room.class);
roomService.updateById(room);
return ApiResponse.ofSuccess(room);
}
use of cn.imhtb.antlive.entity.Room in project Ant-Live by PinTeh.
the class RoomController method saveInfo.
@PostMapping("/info/save")
public ApiResponse saveInfo(@RequestBody RoomInfoSaveRequest request, HttpServletRequest r) {
Integer uid = JwtUtils.getId(r);
Room one = roomService.getOne(new QueryWrapper<Room>().eq("user_id", uid).last("limit 0,1"));
if (one == null) {
return ApiResponse.ofError();
}
Room room = new Room();
room.setId(one.getId());
room.setTitle(request.getTitle());
room.setCover(request.getCover());
room.setCategoryId(request.getCid());
room.setNotice(request.getNotice());
roomService.updateById(room);
return ApiResponse.ofSuccess();
}
Aggregations