Commit c4945143 authored by shiyu's avatar shiyu

保证金

parent 607cdefe
...@@ -45,7 +45,7 @@ public class EarnestEnum { ...@@ -45,7 +45,7 @@ public class EarnestEnum {
GIFT(1, "赠送保证金"), GIFT(1, "赠送保证金"),
PAY(2, "缴纳保证金"), PAY(2, "缴纳保证金"),
WITHDRAW(3, "提取保证金"), WITHDRAW(3, "提取保证金"),
OCCUPY(4, "占用额度"), OCCUPY(4, "占用出价额度"),
RELEASE(5, "释放保证金"), RELEASE(5, "释放保证金"),
DEDUCT(-1, "扣除保证金"), DEDUCT(-1, "扣除保证金"),
; ;
...@@ -83,7 +83,7 @@ public class EarnestEnum { ...@@ -83,7 +83,7 @@ public class EarnestEnum {
public enum StateEnum { public enum StateEnum {
VALID(1, "初始有效状态"), VALID(1, "初始有效状态"),
RELEASE(5, "已释放"), RELEASE(5, "已释放"),
DEDUCT(-1, "中拍超时未支付,已扣除"), DEDUCT(-1, "中拍超时未支付,已扣除保证金"),
; ;
private int code; private int code;
......
...@@ -13,6 +13,8 @@ public interface SpecialPerformanceConfigDao { ...@@ -13,6 +13,8 @@ public interface SpecialPerformanceConfigDao {
SpecialPerformanceConfig findById(int specialPerformanceId, long itemId); SpecialPerformanceConfig findById(int specialPerformanceId, long itemId);
SpecialPerformanceConfig findByItemId(long itemId);
boolean insert(SpecialPerformanceConfig specialPerformanceConfig); boolean insert(SpecialPerformanceConfig specialPerformanceConfig);
boolean update(SpecialPerformanceConfig specialPerformanceConfig); boolean update(SpecialPerformanceConfig specialPerformanceConfig);
......
...@@ -64,6 +64,15 @@ public class SpecialPerformanceConfigDaoImpl implements SpecialPerformanceConfig ...@@ -64,6 +64,15 @@ public class SpecialPerformanceConfigDaoImpl implements SpecialPerformanceConfig
return specialPerformanceConfigMapper.selectOneByExample(example); return specialPerformanceConfigMapper.selectOneByExample(example);
} }
@Override
public SpecialPerformanceConfig findByItemId(long itemId) {
SpecialPerformanceConfigExample example = new SpecialPerformanceConfigExample();
SpecialPerformanceConfigExample.Criteria criteria = example.createCriteria();
criteria.andItemIdEqualTo(itemId);
return specialPerformanceConfigMapper.selectOneByExample(example);
}
@Override @Override
public boolean insert(SpecialPerformanceConfig specialPerformanceConfig) { public boolean insert(SpecialPerformanceConfig specialPerformanceConfig) {
specialPerformanceConfig.setCreateTime(new Date()); specialPerformanceConfig.setCreateTime(new Date());
......
...@@ -48,6 +48,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -48,6 +48,7 @@ import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -151,6 +152,9 @@ public class WxPayCallbackController { ...@@ -151,6 +152,9 @@ public class WxPayCallbackController {
@Autowired @Autowired
AuctionEarnestService auctionEarnestService; AuctionEarnestService auctionEarnestService;
@Autowired
EarnestRecordDao earnestRecordDao;
@RequestMapping(value ="/getPayNotify") @RequestMapping(value ="/getPayNotify")
public String payNotify(HttpServletRequest request) throws IOException { public String payNotify(HttpServletRequest request) throws IOException {
logger.info("------------------ 收到微信支付回调通知 ------------------"); logger.info("------------------ 收到微信支付回调通知 ------------------");
...@@ -689,6 +693,18 @@ public class WxPayCallbackController { ...@@ -689,6 +693,18 @@ public class WxPayCallbackController {
earnestOrder.setUpdateTime(new Date()); earnestOrder.setUpdateTime(new Date());
earnestOrderDao.update(earnestOrder); earnestOrderDao.update(earnestOrder);
//保存充值记录
EarnestRecord earnestRecord = new EarnestRecord();
earnestRecord.setUserId(userId);
earnestRecord.setAmount(amount);
earnestRecord.setEntryType(EarnestEnum.EntryEnum.INCREASE.getCode());
earnestRecord.setCreateTime(new Date());
earnestRecord.setUpdateTime(new Date());
earnestRecord.setType(EarnestEnum.TypeEnum.PAY.getCode());
earnestRecord.setState(EarnestEnum.StateEnum.VALID.getCode());
earnestRecordDao.insert(earnestRecord);
//用户账户,更新保证金额度 //用户账户,更新保证金额度
UserAccount userAccount = userAccountDao.findByUserId(userId); UserAccount userAccount = userAccountDao.findByUserId(userId);
long earnestUsableAmount = userAccount.getEarnestUsableAmount(); long earnestUsableAmount = userAccount.getEarnestUsableAmount();
......
...@@ -163,4 +163,6 @@ public class AuctionDetailVo implements Entity { ...@@ -163,4 +163,6 @@ public class AuctionDetailVo implements Entity {
*/ */
private Boolean isSubscribed; private Boolean isSubscribed;
private Integer lot;
} }
...@@ -103,4 +103,9 @@ public class AuctionRecordVo implements Entity { ...@@ -103,4 +103,9 @@ public class AuctionRecordVo implements Entity {
* 是否足够保证金 * 是否足够保证金
*/ */
private Boolean enoughEarnest = true; private Boolean enoughEarnest = true;
/**
* 可出价额度
*/
private String usableOfferAmount;
} }
...@@ -14,7 +14,9 @@ import com.wwdz.ch.core.util.PriceUtil; ...@@ -14,7 +14,9 @@ import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.db.dao.OfficialAccountSubscribeRecordDao; import com.wwdz.ch.db.dao.OfficialAccountSubscribeRecordDao;
import com.wwdz.ch.db.dao.UserDao; import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.distribution.*; import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.dao.openShop.UserAccountDao;
import com.wwdz.ch.db.domain.distribution.*; import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.domain.openShop.UserAccount;
import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto; import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto;
import com.wwdz.ch.core.api.WxAppletApi; import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg; import com.wwdz.ch.core.entity.AuctionOfferNoticeMsg;
...@@ -45,6 +47,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; ...@@ -45,6 +47,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -113,6 +116,9 @@ public class AuctionRecordServiceImpl implements AuctionRecordService { ...@@ -113,6 +116,9 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
@Autowired @Autowired
AuctionEarnestService auctionEarnestService; AuctionEarnestService auctionEarnestService;
@Autowired
UserAccountDao userAccountDao;
@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
private String env; private String env;
...@@ -331,7 +337,15 @@ public class AuctionRecordServiceImpl implements AuctionRecordService { ...@@ -331,7 +337,15 @@ public class AuctionRecordServiceImpl implements AuctionRecordService {
earnestRecordRequestDto.setUserId(dto.getUserId()); earnestRecordRequestDto.setUserId(dto.getUserId());
earnestRecordRequestDto.setAuctionPrice(PriceUtil.convertPriceFromStr(auctionRecordVo.getNextPrice())); earnestRecordRequestDto.setAuctionPrice(PriceUtil.convertPriceFromStr(auctionRecordVo.getNextPrice()));
Result checkEnoughEarnestResult = auctionEarnestService.checkEnoughEarnest(earnestRecordRequestDto); Result checkEnoughEarnestResult = auctionEarnestService.checkEnoughEarnest(earnestRecordRequestDto);
if (!checkEnoughEarnestResult.getSuccess()) { long auctionPrice = PriceUtil.convertPriceFromStr(auctionRecordVo.getNextPrice());
//换算成对应需要占用的保证金
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();
//当前可出价的额度
auctionRecordVo.setUsableOfferAmount(PriceUtil.convertPriceFenToYuan(earnestUsableAmount * CommConsts.EARNEST_TRANSFORM_AUCTION_REBATE));
if (occupyAmount > earnestUsableAmount) {
auctionRecordVo.setEnoughEarnest(false); auctionRecordVo.setEnoughEarnest(false);
} }
auctionRecordVo.setStartPrice(PriceUtil.convertPriceFenToYuan(auctionConfig.getStartPrice())); auctionRecordVo.setStartPrice(PriceUtil.convertPriceFenToYuan(auctionConfig.getStartPrice()));
......
...@@ -647,6 +647,7 @@ public class SupplierItemServiceImpl implements SupplierItemService { ...@@ -647,6 +647,7 @@ public class SupplierItemServiceImpl implements SupplierItemService {
auctionDetailVo.setSpecialPerformanceId(specialPerformanceConfig.getSpecialPerformanceId()); auctionDetailVo.setSpecialPerformanceId(specialPerformanceConfig.getSpecialPerformanceId());
auctionDetailVo.setCurrentPrice(PriceUtil.convertPriceFenToYuan(specialPerformanceConfig.getCurrentPrice())); auctionDetailVo.setCurrentPrice(PriceUtil.convertPriceFenToYuan(specialPerformanceConfig.getCurrentPrice()));
auctionDetailVo.setIsSubscribed(disposableSubscribeRecordDao.isSubscribed(dto.getUserId(), itemId, DisposableSubscribeRecordEnum.TypeEnum.ITEM_PRE_END.getType())); auctionDetailVo.setIsSubscribed(disposableSubscribeRecordDao.isSubscribed(dto.getUserId(), itemId, DisposableSubscribeRecordEnum.TypeEnum.ITEM_PRE_END.getType()));
auctionDetailVo.setLot(specialPerformanceConfig.getLot());
//查询用户是否关注该商品 //查询用户是否关注该商品
SpecialPerformanceItemFollowRequestDto specialPerformanceItemFollowRequestDto = new SpecialPerformanceItemFollowRequestDto(); SpecialPerformanceItemFollowRequestDto specialPerformanceItemFollowRequestDto = new SpecialPerformanceItemFollowRequestDto();
specialPerformanceItemFollowRequestDto.setSpecialPerformanceId(specialPerformanceConfig.getSpecialPerformanceId()); specialPerformanceItemFollowRequestDto.setSpecialPerformanceId(specialPerformanceConfig.getSpecialPerformanceId());
......
...@@ -132,7 +132,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService { ...@@ -132,7 +132,7 @@ public class AuctionEarnestServiceImpl implements AuctionEarnestService {
if (occupyAmount > earnestUsableAmount) { if (occupyAmount > earnestUsableAmount) {
return Result.failed("保证金不足,去缴纳"); return Result.failed("保证金不足,去缴纳");
} }
return Result.success(); return Result.success(earnestUsableAmount);
} catch (Exception e) { } catch (Exception e) {
logger.error("检查是否有足够的保证金失败 error : {}", e); logger.error("检查是否有足够的保证金失败 error : {}", e);
} }
......
package com.wwdz.ch.wx.impl.openShop; package com.wwdz.ch.wx.impl.openShop;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.consts.CommConsts;
import com.wwdz.ch.core.consts.EarnestEnum; import com.wwdz.ch.core.consts.EarnestEnum;
import com.wwdz.ch.core.entity.openShop.EarnestRecordVo; import com.wwdz.ch.core.entity.openShop.EarnestRecordVo;
import com.wwdz.ch.core.type.PageSearchResult; import com.wwdz.ch.core.type.PageSearchResult;
...@@ -20,6 +21,8 @@ import org.slf4j.Logger; ...@@ -20,6 +21,8 @@ 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.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
@Service @Service
...@@ -40,7 +43,8 @@ public class EarnestRecordServiceImpl implements EarnestRecordService { ...@@ -40,7 +43,8 @@ public class EarnestRecordServiceImpl implements EarnestRecordService {
public Result findList(EarnestRecordRequestDto dto) { public Result findList(EarnestRecordRequestDto dto) {
try { try {
List<EarnestRecordVo> earnestRecordVos = new ArrayList<>(); List<EarnestRecordVo> earnestRecordVos = new ArrayList<>();
dto.setTypeList(Arrays.asList(EarnestEnum.TypeEnum.PAY.getCode(), EarnestEnum.TypeEnum.DEDUCT.getCode(), EarnestEnum.TypeEnum.WITHDRAW.getCode())); dto.setTypeList(Arrays.asList(EarnestEnum.TypeEnum.PAY.getCode(), EarnestEnum.TypeEnum.DEDUCT.getCode(),
EarnestEnum.TypeEnum.WITHDRAW.getCode(), EarnestEnum.TypeEnum.GIFT.getCode()));
List<EarnestRecord> earnestRecordList = earnestRecordDao.findList(dto); List<EarnestRecord> earnestRecordList = earnestRecordDao.findList(dto);
PageInfo pageInfo = new PageInfo<>(earnestRecordList); PageInfo pageInfo = new PageInfo<>(earnestRecordList);
for (EarnestRecord earnestRecord : earnestRecordList) { for (EarnestRecord earnestRecord : earnestRecordList) {
...@@ -76,6 +80,13 @@ public class EarnestRecordServiceImpl implements EarnestRecordService { ...@@ -76,6 +80,13 @@ public class EarnestRecordServiceImpl implements EarnestRecordService {
earnestRecordVo.setAmount(PriceUtil.convertPriceFenToYuan(earnestRecord.getAmount())); earnestRecordVo.setAmount(PriceUtil.convertPriceFenToYuan(earnestRecord.getAmount()));
if (earnestRecord.getState() != EarnestEnum.StateEnum.VALID.getCode()) { if (earnestRecord.getState() != EarnestEnum.StateEnum.VALID.getCode()) {
earnestRecordVo.setStateName(EarnestEnum.StateEnum.getNameByCode(earnestRecord.getState())); earnestRecordVo.setStateName(EarnestEnum.StateEnum.getNameByCode(earnestRecord.getState()));
if (earnestRecord.getState() == EarnestEnum.StateEnum.DEDUCT.getCode()) {
//算出被扣除的保证金金额
BigDecimal earnestAmount = new BigDecimal(String.valueOf(earnestRecord.getAmount())).multiply(new BigDecimal(CommConsts.EARNEST_REBATE));
//换算成对应占用的保证金
long occupyAmount = earnestAmount.longValue();
earnestRecordVo.setStateName(EarnestEnum.StateEnum.getNameByCode(earnestRecord.getState()) + "¥" + PriceUtil.convertPriceFenToYuan(occupyAmount));
}
} }
SupplierItem supplierItem = supplierItemDao.findById(earnestRecord.getItemId()); SupplierItem supplierItem = supplierItemDao.findById(earnestRecord.getItemId());
earnestRecordVo.setItemName(supplierItem.getName()); earnestRecordVo.setItemName(supplierItem.getName());
......
package com.wwdz.ch.wx.service; package com.wwdz.ch.wx.service;
import com.wwdz.ch.core.type.Result; import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.db.domain.distribution.DistributionOrder;
public interface UserAccountService { public interface UserAccountService {
......
...@@ -89,12 +89,12 @@ public class WxPayServiceTest { ...@@ -89,12 +89,12 @@ public class WxPayServiceTest {
@Test @Test
public void refund() { public void refund() {
List<String> list = Arrays.asList("DA2411042000269405675"); List<String> list = Arrays.asList("AE2411111432126726864");
list.forEach(orderId ->{ list.forEach(orderId ->{
DistributionOrderRequestDto dto = new DistributionOrderRequestDto(); DistributionOrderRequestDto dto = new DistributionOrderRequestDto();
dto.setDistributionOrderId(orderId); dto.setDistributionOrderId(orderId);
dto.setAmount("30"); dto.setAmount("0.1");
dto.setRefundPrice("30"); dto.setRefundPrice("0.1");
Result result = wxPayServiceApi.refund(dto); Result result = wxPayServiceApi.refund(dto);
logger.info("申请微信支付退款:{}", result); logger.info("申请微信支付退款:{}", result);
}); });
......
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