Commit 9a5e4142 authored by shiyu's avatar shiyu

拍卖保证金

parent 9f276395
......@@ -45,7 +45,7 @@ public class EarnestEnum {
GIFT(1, "赠送保证金"),
PAY(2, "缴纳保证金"),
WITHDRAW(3, "提取保证金"),
OCCUPY(4, "占用保证金"),
OCCUPY(4, "占用额度"),
RELEASE(5, "释放保证金"),
DEDUCT(-1, "扣除保证金"),
;
......
......@@ -9,6 +9,7 @@ import com.wwdz.ch.db.dao.distribution.UserAccountDetailDao;
import com.wwdz.ch.db.dao.openShop.EarnestRecordDao;
import com.wwdz.ch.db.dao.openShop.UserAccountDao;
import com.wwdz.ch.db.domain.distribution.UserAccountDetail;
import com.wwdz.ch.db.domain.openShop.EarnestRecord;
import com.wwdz.ch.db.domain.openShop.UserAccount;
import com.wwdz.ch.db.dto.request.openShop.EarnestRecordRequestDto;
import com.wwdz.ch.wx.service.UserAccountService;
......@@ -18,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
......@@ -40,6 +42,7 @@ public class UserAccountServiceImpl implements UserAccountService {
try {
UserAccount userAccount = userAccountDao.findByUserId(userId);
if (userAccount == null) {
Date now = new Date();
UserAccount newAccount = new UserAccount();
newAccount.setUserId(userId);
newAccount.setGuaranteeAmount(0L);
......@@ -49,10 +52,21 @@ public class UserAccountServiceImpl implements UserAccountService {
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());
newAccount.setEarnestUsableAmount(CommConsts.GIFT_EARNEST_AMOUNT);
newAccount.setCreateTime(now);
newAccount.setUpdateTime(now);
userAccountDao.insert(newAccount);
//新用户新增默认赠送的保证金额度
EarnestRecord earnestRecord = new EarnestRecord();
earnestRecord.setUserId(userId);
earnestRecord.setAmount(CommConsts.GIFT_EARNEST_AMOUNT);
earnestRecord.setEntryType(EarnestEnum.EntryEnum.INCREASE.getCode());
earnestRecord.setCreateTime(now);
earnestRecord.setUpdateTime(now);
earnestRecord.setType(EarnestEnum.TypeEnum.GIFT.getCode());
earnestRecord.setState(EarnestEnum.StateEnum.VALID.getCode());
earnestRecordDao.insert(earnestRecord);
}
return Result.success();
} catch (Exception e) {
......
......@@ -109,7 +109,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
map.put("totalOfferAmount", totalOfferAmount);
map.put("addOfferAmount", PriceUtil.convertPriceFenToYuan(addOfferAmount * CommConsts.EARNEST_TRANSFORM_AUCTION_REBATE));
map.put("residueOfferAmount", PriceUtil.convertPriceFenToYuan(earnestUsableAmount * CommConsts.EARNEST_TRANSFORM_AUCTION_REBATE));
map.put("option", Arrays.asList("100", "200", "300", "400", "500", "600"));
map.put("option", Arrays.asList("0.1", "200", "300", "400", "500", "600"));
return Result.success(map);
} catch (Exception e) {
logger.error("计算用户可出价的额度失败 error : {}", e);
......@@ -204,6 +204,15 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
long occupyAmount = earnestAmount.longValue();
//把上一次的占用记录状态更改为已释放
EarnestRecord newEarnestRecord = new EarnestRecord();
newEarnestRecord.setUserId(dto.getUserId());
newEarnestRecord.setItemId(dto.getItemId());
newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
newEarnestRecord.setState(EarnestEnum.StateEnum.RELEASE.getCode());
earnestRecordDao.update(newEarnestRecord);
EarnestRecord earnestRecord = new EarnestRecord();
earnestRecord.setUserId(dto.getUserId());
earnestRecord.setAmount(earnestAmount.longValue());
......@@ -216,14 +225,6 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
earnestRecord.setState(EarnestEnum.StateEnum.VALID.getCode());
earnestRecordDao.insert(earnestRecord);
//把上一次的占用记录状态更改为已释放
EarnestRecord newEarnestRecord = new EarnestRecord();
newEarnestRecord.setUserId(dto.getUserId());
newEarnestRecord.setItemId(dto.getItemId());
newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
newEarnestRecord.setState(EarnestEnum.StateEnum.RELEASE.getCode());
earnestRecordDao.update(newEarnestRecord);
//更新用户账户,更新保证金额度
UserAccount userAccount = userAccountDao.findByUserId(dto.getUserId());
long earnestUsableAmount = userAccount.getEarnestUsableAmount();
......@@ -260,6 +261,15 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
long occupyAmount = earnestAmount.longValue();
//把上一次的占用记录状态更改为已扣除
EarnestRecord newEarnestRecord = new EarnestRecord();
newEarnestRecord.setUserId(dto.getUserId());
newEarnestRecord.setItemId(dto.getItemId());
newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
newEarnestRecord.setState(EarnestEnum.StateEnum.DEDUCT.getCode());
earnestRecordDao.update(newEarnestRecord);
//保证金扣除记录
EarnestRecord earnestRecord = new EarnestRecord();
earnestRecord.setUserId(dto.getUserId());
......@@ -273,13 +283,6 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
earnestRecord.setState(EarnestEnum.StateEnum.VALID.getCode());
earnestRecordDao.insert(earnestRecord);
//把上一次的占用记录状态更改为已扣除
EarnestRecord newEarnestRecord = new EarnestRecord();
newEarnestRecord.setUserId(dto.getUserId());
newEarnestRecord.setItemId(dto.getItemId());
newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
newEarnestRecord.setState(EarnestEnum.StateEnum.DEDUCT.getCode());
earnestRecordDao.update(newEarnestRecord);
//更新用户账户,更新保证金额度,先扣除赠送的保证金,额度不够再扣用户自己缴纳的
UserAccount newUserAccount = new UserAccount();
......@@ -288,8 +291,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
long oldEarnestAmount = userAccount.getEarnestAmount();
long earnestUsableAmount = userAccount.getEarnestUsableAmount();
long giftEarnestAmount = userAccount.getGiftEarnestAmount();
//可用的保证金金额
newUserAccount.setEarnestUsableAmount(earnestUsableAmount - occupyAmount);
if (occupyAmount <= giftEarnestAmount) {
//赠送的保证金足够扣除,就只扣除赠送的部分额度
newUserAccount.setGiftEarnestAmount(giftEarnestAmount - occupyAmount);
......
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