Commit b1f0a083 authored by shiyu's avatar shiyu

用户账户查询

parent fa14262a
...@@ -22,7 +22,12 @@ public class UserAccountVo implements Entity{ ...@@ -22,7 +22,12 @@ public class UserAccountVo implements Entity{
private String guaranteeAmount; private String guaranteeAmount;
/** /**
* 货款 * 总货款
*/
private String totalGoodsAmount;
/**
* 已入账货款
*/ */
private String goodsAmount; private String goodsAmount;
...@@ -41,6 +46,11 @@ public class UserAccountVo implements Entity{ ...@@ -41,6 +46,11 @@ public class UserAccountVo implements Entity{
*/ */
private String introduceWaitEntryAmount; private String introduceWaitEntryAmount;
/**
* 总介绍佣金
*/
private String totalIntroduceAmount;
/** /**
* 拍卖保证金 * 拍卖保证金
*/ */
...@@ -66,14 +76,16 @@ public class UserAccountVo implements Entity{ ...@@ -66,14 +76,16 @@ public class UserAccountVo implements Entity{
*/ */
private Date updateTime; private Date updateTime;
public UserAccountVo convert(UserAccount userAccount) { public static UserAccountVo convert(UserAccount userAccount) {
UserAccountVo userAccountVo = new UserAccountVo(); UserAccountVo userAccountVo = new UserAccountVo();
EntityMapper.copyAttribute(userAccount, userAccountVo); EntityMapper.copyAttribute(userAccount, userAccountVo);
userAccountVo.setGuaranteeAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGuaranteeAmount())); userAccountVo.setGuaranteeAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGuaranteeAmount()));
userAccountVo.setGoodsAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGoodsAmount())); userAccountVo.setGoodsAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGoodsAmount()));
userAccountVo.setGoodsWaitEntryAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGoodsWaitEntryAmount())); userAccountVo.setGoodsWaitEntryAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGoodsWaitEntryAmount()));
userAccountVo.setTotalGoodsAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGoodsAmount() + userAccount.getGoodsWaitEntryAmount()));
userAccountVo.setIntroduceAmount(PriceUtil.convertPriceFenToYuan(userAccount.getIntroduceAmount())); userAccountVo.setIntroduceAmount(PriceUtil.convertPriceFenToYuan(userAccount.getIntroduceAmount()));
userAccountVo.setIntroduceWaitEntryAmount(PriceUtil.convertPriceFenToYuan(userAccount.getIntroduceWaitEntryAmount())); userAccountVo.setIntroduceWaitEntryAmount(PriceUtil.convertPriceFenToYuan(userAccount.getIntroduceWaitEntryAmount()));
userAccountVo.setTotalIntroduceAmount(PriceUtil.convertPriceFenToYuan(userAccount.getIntroduceAmount() + userAccount.getIntroduceWaitEntryAmount()));
userAccountVo.setEarnestAmount(PriceUtil.convertPriceFenToYuan(userAccount.getEarnestAmount())); userAccountVo.setEarnestAmount(PriceUtil.convertPriceFenToYuan(userAccount.getEarnestAmount()));
userAccountVo.setEarnestUsableAmount(PriceUtil.convertPriceFenToYuan(userAccount.getEarnestUsableAmount())); userAccountVo.setEarnestUsableAmount(PriceUtil.convertPriceFenToYuan(userAccount.getEarnestUsableAmount()));
userAccountVo.setGiftEarnestAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGiftEarnestAmount())); userAccountVo.setGiftEarnestAmount(PriceUtil.convertPriceFenToYuan(userAccount.getGiftEarnestAmount()));
......
package com.wwdz.ch.wx.impl; package com.wwdz.ch.wx.impl;
import com.wwdz.ch.core.consts.CommConsts; import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.entity.UserAccountVo;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dao.openShop.UserAccountDao; import com.wwdz.ch.db.dao.openShop.UserAccountDao;
import com.wwdz.ch.db.domain.openShop.UserAccount; import com.wwdz.ch.db.domain.openShop.UserAccount;
...@@ -45,4 +46,18 @@ public class UserAccountServiceImpl implements UserAccountService { ...@@ -45,4 +46,18 @@ public class UserAccountServiceImpl implements UserAccountService {
} }
return Result.failed(); return Result.failed();
} }
@Override
public Result find(long userId) {
try {
initAccount(userId);
UserAccount userAccount = userAccountDao.findByUserId(userId);
UserAccountVo userAccountVo = UserAccountVo.convert(userAccount);
return Result.success(userAccountVo);
} catch (Exception e) {
logger.info("查询用户账户失败 error: {}", e);
}
return Result.failed();
}
} }
...@@ -24,11 +24,13 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -24,11 +24,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
...@@ -98,6 +100,25 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService { ...@@ -98,6 +100,25 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
} }
@Override
public Result countOfferAmount(EarnestOrderRequestDto dto) {
try {
UserAccount userAccount = userAccountDao.findByUserId(dto.getUserId());
long earnestUsableAmount = userAccount.getEarnestUsableAmount();
String payAmount = StringUtils.isEmpty(dto.getAmount()) ? "0" : dto.getAmount();
long addOfferAmount = PriceUtil.convertPriceFromStr(payAmount);
String totalOfferAmount = PriceUtil.convertPriceFenToYuan((earnestUsableAmount + addOfferAmount) * CommConsts.EARNEST_TRANSFORM_AUCTION_REBATE);
Map<String, Object> map = new HashMap<>();
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));
return Result.success(map);
} catch (Exception e) {
logger.error("计算用户可出价的额度失败 error : {}", e);
}
return Result.failed();
}
@Override @Override
public Result checkEnoughEarnest(EarnestRecordRequestDto dto) { public Result checkEnoughEarnest(EarnestRecordRequestDto dto) {
try { try {
...@@ -193,6 +214,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService { ...@@ -193,6 +214,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
newEarnestRecord.setUserId(dto.getUserId()); newEarnestRecord.setUserId(dto.getUserId());
newEarnestRecord.setItemId(dto.getItemId()); newEarnestRecord.setItemId(dto.getItemId());
newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode()); newEarnestRecord.setType(EarnestEnum.TypeEnum.OCCUPY.getCode());
newEarnestRecord.setState(EarnestEnum.StateEnum.RELEASE.getCode());
earnestRecordDao.update(newEarnestRecord); earnestRecordDao.update(newEarnestRecord);
//更新用户账户,更新保证金额度 //更新用户账户,更新保证金额度
...@@ -214,4 +236,65 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService { ...@@ -214,4 +236,65 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
} }
return Result.failed(); return Result.failed();
} }
@Override
public Result deductEarnest(EarnestRecordRequestDto dto) {
String itemIdKey = CommConsts.EARNEST_ACCOUNT_LOCK + dto.getUserId();
RLock lock = redissonClient.getLock(itemIdKey);
try {
if (!lock.tryLock(5, 5, TimeUnit.SECONDS)) {
return Result.failed("操作过快,稍后再试");
}
long auctionPrice = dto.getAuctionPrice();
BigDecimal earnestAmount = new BigDecimal(String.valueOf(auctionPrice)).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
long occupyAmount = earnestAmount.longValue();
//保证金扣除记录
EarnestRecord earnestRecord = new EarnestRecord();
earnestRecord.setUserId(dto.getUserId());
earnestRecord.setAmount(earnestAmount.longValue());
earnestRecord.setItemId(dto.getItemId());
earnestRecord.setSpecialPerformanceId(dto.getSpecialPerformanceId());
earnestRecord.setEntryType(EarnestEnum.EntryEnum.DEDUCT.getCode());
earnestRecord.setCreateTime(new Date());
earnestRecord.setUpdateTime(new Date());
earnestRecord.setType(EarnestEnum.TypeEnum.DEDUCT.getCode());
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();
newUserAccount.setUserId(dto.getUserId());
UserAccount userAccount = userAccountDao.findByUserId(dto.getUserId());
long oldEarnestAmount = userAccount.getEarnestAmount();
long earnestUsableAmount = userAccount.getEarnestUsableAmount();
long giftEarnestAmount = userAccount.getGiftEarnestAmount();
if (occupyAmount <= giftEarnestAmount) {
newUserAccount.setEarnestUsableAmount(earnestUsableAmount - occupyAmount);
newUserAccount.setGiftEarnestAmount(giftEarnestAmount - occupyAmount);
} else if (occupyAmount > giftEarnestAmount) {
}
userAccountDao.update(newUserAccount);
}catch (Exception e) {
logger.error("释放保证金失败 error : {}", e);
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
} finally {
if (lock != null && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return Result.failed();
}
} }
...@@ -10,4 +10,12 @@ public interface UserAccountService { ...@@ -10,4 +10,12 @@ public interface UserAccountService {
* @return * @return
*/ */
Result initAccount(long userId); Result initAccount(long userId);
/**
* 查询用户账户信息
* @param userId
* @return
*/
Result find(long userId);
} }
...@@ -21,6 +21,13 @@ public interface AuctionEarnestService { ...@@ -21,6 +21,13 @@ public interface AuctionEarnestService {
*/ */
Result getPayParam(EarnestOrderRequestDto dto); Result getPayParam(EarnestOrderRequestDto dto);
/**
* 计算用户可出价的额度,由保证金换算过
* @param dto
* @return
*/
Result countOfferAmount(EarnestOrderRequestDto dto);
/** /**
* 检查是否有足够的保证金出价 * 检查是否有足够的保证金出价
* @param dto * @param dto
...@@ -40,4 +47,10 @@ public interface AuctionEarnestService { ...@@ -40,4 +47,10 @@ public interface AuctionEarnestService {
* @return * @return
*/ */
Result releaseEarnest(EarnestRecordRequestDto dto); Result releaseEarnest(EarnestRecordRequestDto dto);
/**
* 扣除保证金
* @return
*/
Result deductEarnest(EarnestRecordRequestDto dto);
} }
package com.wwdz.ch.wx.web; package com.wwdz.ch.wx.web;
import com.alibaba.fastjson.JSON;
import com.wwdz.ch.core.consts.ResultCode;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.wx.service.UserAccountService; import com.wwdz.ch.wx.service.UserAccountService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
@RequestMapping("/wx/userAccount") @RequestMapping("/wx/userAccount")
public class UserAccountController { public class WxUserAccountController {
private static final Logger logger = LoggerFactory.getLogger(UserAccountController.class); private static final Logger logger = LoggerFactory.getLogger(WxUserAccountController.class);
@Autowired @Autowired
UserAccountService userAccountService; UserAccountService userAccountService;
}
@ApiOperation(value = "查询用户账户信息")
@PostMapping("/find")
public Result find(@RequestBody UserRequestDto dto) {
logger.info("【请求开始】查询用户账户信息,请求参数:{}", JSON.toJSONString(dto));
if (dto.getUserId() == null) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return userAccountService.find(dto.getUserId());
}
}
\ No newline at end of file
...@@ -56,4 +56,18 @@ public class AuctionEarnestController { ...@@ -56,4 +56,18 @@ public class AuctionEarnestController {
} }
return auctionEarnestService.getPayParam(dto); return auctionEarnestService.getPayParam(dto);
} }
@ApiOperation(value = "计算用户可出价的额度")
@PostMapping("/countOfferAmount")
public Result countOfferAmount(@RequestBody EarnestOrderRequestDto dto) {
logger.info("【请求开始】计算用户可出价的额度,请求参数:{}", JSON.toJSONString(dto));
Validator validator = new Validator(FormHandler.ofEntity(dto));
validator.set("userId", "用户id").must().number()
.end();
if (!validator.isValid()) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return auctionEarnestService.countOfferAmount(dto);
}
} }
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