Commit 4701e3ff authored by shiyu's avatar shiyu

保证金使用明细

parent 679fc940
......@@ -160,6 +160,11 @@ public interface CommConsts {
*/
public final static String EARNEST_REBATE = "0.05";
/**
* 保证金换成出价额度比例为1:20
*/
public final static Integer EARNEST_TRANSFORM_AUCTION_REBATE = 20;
/**
* 每个用户赠送50元初始保证金额度
......
......@@ -17,7 +17,7 @@ public class UserAccountDaoImpl implements UserAccountDao {
@Override
public boolean insert(UserAccount userAccount) {
return false;
return userAccountMapper.insert(userAccount) > 0;
}
@Override
......
package com.wwdz.ch.wx.impl;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.openShop.UserAccountDao;
import com.wwdz.ch.db.domain.openShop.UserAccount;
import com.wwdz.ch.wx.service.UserAccountService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
@Service
public class UserAccountServiceImpl implements UserAccountService {
......@@ -19,10 +23,26 @@ public class UserAccountServiceImpl implements UserAccountService {
@Override
public Result initAccount(long userId) {
try {
UserAccount userAccount = userAccountDao.findByUserId(userId);
if (userAccount == null) {
UserAccount newAccount = new UserAccount();
newAccount.setUserId(userId);
newAccount.setGuaranteeAmount(0L);
newAccount.setGoodsAmount(0L);
newAccount.setGoodsWaitEntryAmount(0L);
newAccount.setIntroduceAmount(0L);
newAccount.setIntroduceWaitEntryAmount(0L);
newAccount.setEarnestAmount(0L);
newAccount.setGiftEarnestAmount(CommConsts.GIFT_EARNEST_AMOUNT);
newAccount.setEarnestUsableAmount(CommConsts.GIFT_EARNEST_AMOUNT * CommConsts.EARNEST_TRANSFORM_AUCTION_REBATE);
newAccount.setCreateTime(new Date());
newAccount.setUpdateTime(new Date());
userAccountDao.insert(newAccount);
}
return Result.success();
} catch (Exception e) {
logger.info("初始化用户账户失败 error: {}", e);
}
return null;
return Result.failed();
}
}
......@@ -155,6 +155,8 @@ public class UserServiceImpl implements UserService {
@Autowired
TagOperateWhiteListDao tagOperateWhiteListDao;
@Autowired
UserAccountService userAccountService;
@Override
public Result finishLogin(UserRequestDto dto) {
......@@ -272,6 +274,11 @@ public class UserServiceImpl implements UserService {
//更新或插入登录的用户信息
userDao.insertByMapper(user);
//初始化用户账户
Result initAccountResult = userAccountService.initAccount(dto.getUserId());
if (!initAccountResult.getSuccess()) {
return Result.failed("初始化用户账户失败");
}
// 缓存用户信息
String userKey = MessageFormat.format(CacheCodeConstants.USER_INFO_KEY, user.getId());
redisUtil.set(userKey, user, 2 * 60 * 60);
......
......@@ -19,10 +19,13 @@ import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceConfigRequestDto;
import com.wwdz.ch.db.dto.request.openShop.EarnestRecordRequestDto;
import com.wwdz.ch.wx.entity.vo.distribution.AuctionRecordRowVo;
import com.wwdz.ch.wx.entity.vo.distribution.AuctionRecordVo;
import com.wwdz.ch.wx.service.UserAccountService;
import com.wwdz.ch.wx.service.distribution.AuctionRecordService;
import com.wwdz.ch.core.service.SendMsgService;
import com.wwdz.ch.wx.service.openShop.AuctionEarnestService;
import com.wwdz.mall.common.vo.response.CloudServerResponse;
import com.wwdz.shop.api.DTO.ShopDTO;
import com.wwdz.shop.api.query.ShopQueryOption;
......@@ -104,6 +107,12 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
@Reference
ShopReadService shopReadService;
@Autowired
UserAccountService userAccountService;
@Autowired
AuctionEarnestService auctionEarnestService;
@Value("${spring.profiles.active}")
private String env;
......@@ -114,6 +123,11 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
String itemIdKey = CommConsts.AUCTION_LOCK_KEY_PRE + itemId;
RLock lock = redissonClient.getLock(itemIdKey);
try {
//初始化用户账户
Result initAccountResult = userAccountService.initAccount(dto.getUserId());
if (!initAccountResult.getSuccess()) {
return Result.failed("初始化用户账户失败");
}
if (lock.tryLock(0, 10, TimeUnit.SECONDS)) {
//正式环境需要判断是否是商家
if (!"dev".equals(env)) {
......@@ -153,6 +167,16 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
//查询当前最新的价格
AuctionRecord auctionRecord = auctionRecordDao.findLastedRecord(itemId);
long price = PriceUtil.convertPriceFromStr(dto.getPrice());
//检查用户的保证金额度是否满足出价
EarnestRecordRequestDto earnestRecordRequestDto = new EarnestRecordRequestDto();
earnestRecordRequestDto.setUserId(dto.getUserId());
earnestRecordRequestDto.setAuctionPrice(price);
Result checkEnoughEarnestResult = auctionEarnestService.checkEnoughEarnest(earnestRecordRequestDto);
if (!checkEnoughEarnestResult.getSuccess()) {
return checkEnoughEarnestResult;
}
if (auctionRecord != null) {
long lastedPrice = auctionRecord.getPrice();
if (price <= lastedPrice) {
......@@ -161,7 +185,15 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
//把上次的最高价记录改为落后
auctionRecordDao.updateNotLeadById(auctionRecord.getId());
//把上次出价的用户保证金释放
EarnestRecordRequestDto releaseEarnestDto = new EarnestRecordRequestDto();
releaseEarnestDto.setUserId(auctionRecord.getUserId());
releaseEarnestDto.setAuctionPrice(lastedPrice);
releaseEarnestDto.setItemId(itemId);
Result releaseEarnestResult = auctionEarnestService.releaseEarnest(releaseEarnestDto);
if (!releaseEarnestResult.getSuccess()) {
logger.error("====== 商品id:{}, 用户id:{}, 释放保证金失败 ======", itemId, auctionRecord.getUserId());
throw new Exception("释放保证金失败");
}
//发送模板消息,提示用户出价被超越
String openId = sendMsgService.getOpenIdByUserId(auctionRecord.getUserId());
......@@ -205,6 +237,15 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
specialPerformanceConfigDao.updatePrice(itemId, price);
//把当前领先的用户的保证金额度占用
EarnestRecordRequestDto occupyEarnestDto = new EarnestRecordRequestDto();
occupyEarnestDto.setUserId(dto.getUserId());
occupyEarnestDto.setAuctionPrice(price);
occupyEarnestDto.setItemId(itemId);
Result releaseEarnestResult = auctionEarnestService.occupyEarnest(occupyEarnestDto);
if (!releaseEarnestResult.getSuccess()) {
logger.error("====== 商品id:{}, 用户id:{}, 占用保证金失败 ======", itemId, dto.getUserId());
throw new Exception("占用保证金失败");
}
//如果当前时间是拍卖截止时间的最后五分钟内,则再延长五分钟
Instant instant = endTime.toInstant().minus(Duration.ofMinutes(5));
......@@ -215,30 +256,6 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
auctionConfigDao.updateRealEndTime(itemId, newRealEndTime);
logger.info("商品id:{}, 用户id:{}, 本次出价时间: {}, 原先截拍时间为:{}, 延长截拍时间为{}", itemId, dto.getUserId(), now, endTime, newRealEndTime);
}
//发送消息通知对应的分销商有用户出价, 排除分销商id为系统默认账号的情况
/* if (distributorShareRecord.getDistributorId().longValue() != CommConsts.SYSTEM_ACCOUNT) {
String openId = sendMsgService.getOpenIdByUserId(distributorShareRecord.getDistributorId());
if (com.xxdxxs.utils.StringUtils.hasLength(openId)) {
AuctionOfferNoticeMsg auctionOfferNoticeMsg = new AuctionOfferNoticeMsg();
auctionOfferNoticeMsg.setItemId(supplierItem.getId());
auctionOfferNoticeMsg.setOpenId(openId);
auctionOfferNoticeMsg.setItemName(supplierItem.getName());
auctionOfferNoticeMsg.setCurrentPrice(PriceUtil.convertPriceFenToYuan(price));
Result result = sendMsgService.offerNoticeToDistributorMsg(auctionOfferNoticeMsg);
if (!result.getSuccess()) {
String url = wxAppletApi.getUrlLink(AUCTION_MSG_URL,"itemId=" + itemId + "&shareRecordId=");
String msg = "您分销的拍品" + supplierItem.getName() + "有人成出价" + PriceUtil.convertPriceFenToYuan(price) +
"元,请前往"+ url + "查看";
aliSmsSender.sendSms(distributorShareRecord.getDistributorId(), msg);
}
} else {
String url = wxAppletApi.getUrlLink(AUCTION_MSG_URL,"itemId=" + itemId + "&shareRecordId=");
String msg = "您分销的拍品" + supplierItem.getName() + "有人成出价" + PriceUtil.convertPriceFenToYuan(price) +
"元,请前往"+ url + "查看";
aliSmsSender.sendSms(distributorShareRecord.getDistributorId(), msg);
}
}*/
return Result.success();
} else {
return Result.failed("出价者较多,请刷新出价记录");
......
......@@ -101,6 +101,15 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
@Override
public Result checkEnoughEarnest(EarnestRecordRequestDto dto) {
try {
long auctionPrice = dto.getAuctionPrice();
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应需要占用的保证金
long occupyAmount = earnestAmount.longValue();
UserAccount userAccount = userAccountDao.findByUserId(dto.getUserId());
long earnestUsableAmount = userAccount.getEarnestUsableAmount();
if (occupyAmount > earnestUsableAmount) {
return Result.failed("保证金额度不够,请先缴纳");
}
return Result.success();
} catch (Exception e) {
logger.error("检查是否有足够的保证金失败 error : {}", e);
......
......@@ -86,10 +86,10 @@ public class EarnestRecordServiceImpl implements EarnestRecordService {
earnestRecordRequestDto.setUserId(dto.getUserId());
earnestRecordRequestDto.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
earnestRecordRequestDto.setState(EarnestEnum.StateEnum.VALID.getCode());
long occupyAmount = earnestRecordDao.sumForOccupy(earnestRecordRequestDto);
long occupyAmount = Math.abs(earnestRecordDao.sumForOccupy(earnestRecordRequestDto));
//已用保证金
map.put("usedEarnestAmount", PriceUtil.convertPriceFenToYuan(occupyAmount));
//已用出价,需要在保证金:出价额度 = 120
//已用出价,需要在保证金:出价额度 = 1:20
map.put("usedAuctionAmount", PriceUtil.convertPriceFenToYuan(occupyAmount * 20));
//查询用户的保证金账户
......@@ -97,7 +97,9 @@ public class EarnestRecordServiceImpl implements EarnestRecordService {
long earnestAmount = userAccount.getEarnestAmount();
long giftAmount = userAccount.getGiftEarnestAmount();
if (giftAmount >= occupyAmount) {
//已使用的保证金中,赠送的保证金金额
map.put("usedGiftAmount", PriceUtil.convertPriceFenToYuan(occupyAmount));
//已使用的保证金中,用户自己缴纳的保证金金额
map.put("usedPayAmount", null);
} else {
map.put("usedGiftAmount", PriceUtil.convertPriceFenToYuan(giftAmount));
......
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