package cc.mrbird.febs;
|
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.enumerates.FlowTypeEnum;
|
import cc.mrbird.febs.common.enumerates.MemberLevelEnum;
|
import cc.mrbird.febs.common.enumerates.MoneyFlowTypeEnum;
|
import cc.mrbird.febs.common.enumerates.PerkEnum;
|
import cc.mrbird.febs.common.utils.AppContants;
|
import cc.mrbird.febs.common.utils.MallUtils;
|
import cc.mrbird.febs.mall.entity.AdminAgentInfo;
|
import cc.mrbird.febs.mall.entity.DataDictionaryCustom;
|
import cc.mrbird.febs.mall.entity.MallMember;
|
import cc.mrbird.febs.mall.entity.MallOrderItem;
|
import cc.mrbird.febs.mall.mapper.DataDictionaryCustomMapper;
|
import cc.mrbird.febs.mall.mapper.MallMemberMapper;
|
import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper;
|
import cc.mrbird.febs.mall.mapper.MallOrderItemMapper;
|
import cc.mrbird.febs.mall.quartz.OrderSettlementJob;
|
import cc.mrbird.febs.mall.service.IAgentService;
|
import cc.mrbird.febs.mall.service.IApiMallMemberWalletService;
|
import cc.mrbird.febs.mall.service.IMallAchieveService;
|
import cc.mrbird.febs.mall.service.IMemberProfitService;
|
import cc.mrbird.febs.pay.model.*;
|
import cc.mrbird.febs.pay.service.UnipayService;
|
import cc.mrbird.febs.rabbit.consumer.AgentConsumer;
|
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.alibaba.fastjson.JSONObject;
|
import org.junit.jupiter.api.Test;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import java.math.BigDecimal;
|
import java.text.DecimalFormat;
|
import java.util.*;
|
|
/**
|
* @author wzy
|
* @date 2022-06-02
|
**/
|
@SpringBootTest
|
public class ProfitTest {
|
|
// @Autowired
|
// private AgentConsumer agentConsumer;
|
//
|
@Autowired
|
private IAgentService agentService;
|
@Autowired
|
private MallMemberMapper mallMemberMapper;
|
//
|
// @Autowired
|
// private IMemberProfitService memberProfitService;
|
//
|
|
|
@Autowired
|
private IApiMallMemberWalletService walletService;
|
@Autowired
|
private DataDictionaryCustomMapper dataDictionaryCustomMapper;
|
@Test
|
public void dynamicProfit() {
|
BigDecimal amountTC = new BigDecimal("100");
|
MallMember mallMember = mallMemberMapper.selectById(921L);
|
if(StrUtil.isNotEmpty(mallMember.getReferrerIds())){
|
//团队补贴对象
|
String referrerIds = mallMember.getReferrerIds();
|
List<String> referrerIdList = StrUtil.splitTrim(referrerIds, ",");
|
if(CollUtil.isNotEmpty(referrerIdList)){
|
String levelNormal = MemberLevelEnum.V1.getType();
|
BigDecimal cashPercentNormal = BigDecimal.ZERO;
|
BigDecimal scorePercentNormal = BigDecimal.ZERO;
|
|
DataDictionaryCustom poolScorePriceDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
|
PerkEnum.POOL_SCORE_PRICE.getType(),
|
PerkEnum.POOL_SCORE_PRICE.getCode());
|
BigDecimal poolScorePrice = new BigDecimal(poolScorePriceDic.getValue() == null ? "1" : poolScorePriceDic.getValue());
|
for(String teamPerkMemberInviteId : referrerIdList){
|
MallMember teamPerkMember = mallMemberMapper.selectInfoByInviteId(teamPerkMemberInviteId);
|
String level = teamPerkMember.getLevel();
|
//比较两个级别的大小,level大于levelNormal返回1
|
int compareMin = MemberLevelEnum.V1.compareLevel(level, levelNormal);
|
int compareMax = MemberLevelEnum.V1.compareLevel(MemberLevelEnum.V6.getType(), level);
|
if(compareMin >= 1 && compareMax >= 1){
|
Long teamPerkMemberId = teamPerkMember.getId();
|
DataDictionaryCustom teamPerkMemberDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
|
"AGENT_PERK_SET", level);
|
|
AdminAgentInfo adminAgentInfo = JSONObject.parseObject(teamPerkMemberDic.getValue(), AdminAgentInfo.class);
|
BigDecimal cashPercent = adminAgentInfo.getCashPercent().multiply(AppContants.PERCENTAGE);
|
BigDecimal scorePercent = adminAgentInfo.getScorePercent().multiply(AppContants.PERCENTAGE);
|
//极差
|
cashPercent = cashPercent.subtract(cashPercentNormal);
|
scorePercent = scorePercent.subtract(scorePercentNormal);
|
|
BigDecimal cashAmount = amountTC.multiply(cashPercent).setScale(2, BigDecimal.ROUND_DOWN);
|
|
//如果是H金劵,除以当前价格,得到数量。
|
BigDecimal scoreCnt = amountTC.multiply(scorePercent).setScale(2, BigDecimal.ROUND_DOWN);
|
scoreCnt = scoreCnt.divide(poolScorePrice, 2 ,BigDecimal.ROUND_DOWN);
|
MallMember mallMember1 = mallMemberMapper.selectById(teamPerkMemberId);
|
if(cashAmount.compareTo(BigDecimal.ZERO) > 0){
|
System.out.println(mallMember1.getName()+"获得:" + cashAmount);
|
}
|
if(scoreCnt.compareTo(BigDecimal.ZERO) > 0){
|
System.out.println(mallMember1.getName()+"获得:" + scoreCnt);
|
}
|
levelNormal = level;
|
cashPercentNormal = adminAgentInfo.getCashPercent().multiply(AppContants.PERCENTAGE);
|
scorePercentNormal = adminAgentInfo.getScorePercent().multiply(AppContants.PERCENTAGE);
|
}
|
}
|
}
|
|
|
}
|
// List<MallMember> mallMembers = mallMemberMapper.selectList(null);
|
// if(CollUtil.isEmpty(mallMembers)){
|
// return;
|
// }
|
// for(MallMember mallMember : mallMembers){
|
// boolean flag = false;
|
// String parentId = mallMember.getReferrerId();
|
// if (StrUtil.isBlank(parentId)) {
|
// flag = true;
|
// }
|
// String ids = "";
|
// while (!flag) {
|
// if (StrUtil.isBlank(ids)) {
|
// ids += parentId;
|
// } else {
|
// ids += ("," + parentId);
|
// }
|
// MallMember parentMember = mallMemberMapper.selectInfoByInviteId(parentId);
|
// if (parentMember == null) {
|
// break;
|
// }
|
// parentId = parentMember.getReferrerId();
|
// if (StrUtil.isBlank(parentMember.getReferrerId())) {
|
// flag = true;
|
// }
|
// }
|
//
|
// if (StrUtil.isNotBlank(ids)) {
|
// mallMember.setReferrerIds(ids);
|
// }
|
// mallMemberMapper.updateById(mallMember);
|
// }
|
|
|
// walletService.add(new BigDecimal(2000), 1L, "equityLimit");//减少权益积分
|
// agentService.returnMoneyToAgent(3323L);
|
// agentService.autoUpAgentLevel(640L);
|
}
|
// @Test
|
// public void agentProfit() {
|
// memberProfitService.agentProfit(null);
|
// }
|
//
|
//
|
//// @Test
|
//// public void staticProfit() {
|
//// memberProfitService.staticProfit(new Date());
|
//// }
|
//
|
// @Test
|
// public void thankfulProfit() {
|
// memberProfitService.thankfulProfit(new Date());
|
// }
|
//
|
// @Test
|
// public void rankProfit() {
|
// memberProfitService.rankProfit();
|
// }
|
//
|
// @Autowired
|
// private MallOrderInfoMapper mallOrderInfoMapper;
|
//
|
// @Test
|
// public void directorProfitTest() {
|
// memberProfitService.storeAndDirectorProfit(new Date());
|
// }
|
//
|
// @Autowired
|
// private MallOrderItemMapper mallOrderItemMapper;
|
//
|
// @Autowired
|
// private IMallAchieveService mallAchieveService;
|
//
|
// @Test
|
// public void achieveTest() {
|
// List<MallOrderItem> items = mallOrderItemMapper.selectList(null);
|
// for (MallOrderItem item : items) {
|
// mallAchieveService.add(item.getId());
|
// }
|
// }
|
//
|
// @Test
|
// public void paramTest() {
|
// Map<String, Integer> map = new HashMap<>();
|
// BigDecimal amount = new BigDecimal("100");
|
// map.put("amount", 1);
|
// changeAmount(map);
|
// System.out.println(map.get("amount"));
|
// }
|
//
|
// public void changeAmount(Map<String, Integer> amount) {
|
// amount.put("amount", 2);
|
// }
|
//
|
// @Test
|
// public void scorePool(){
|
// memberProfitService.scorePool();
|
// }
|
//
|
// @Test
|
// public void staticProfit(){
|
// memberProfitService.staticProfit(null);
|
// }
|
//
|
// @Autowired
|
// private OrderSettlementJob orderSettlementJob;
|
//
|
// @Test
|
// public void orderSettlementJobTest() {
|
//// orderSettlementJob.normalGoodsSettlementJob();
|
//
|
// mallAchieveService.add(83L);
|
// }
|
//
|
//
|
// @Autowired
|
// private UnipayService unipayService;
|
// @Test
|
// public void unipay(){
|
// UnipayDto unipayDto = new UnipayDto();
|
// unipayDto.setAmount(new BigDecimal("0.01"));
|
// unipayDto.setFrpCode("ALIPAY_H5");
|
// unipayDto.setTradeMerchantNo("777180800385820");
|
//// unipayDto.setFrpCode("WEIXIN_APP3");
|
// unipayDto.setOrderNo("2022082316415386395");
|
// unipayDto.setProductName("洗护套装");
|
// unipayService.unipay(unipayDto);
|
// }
|
// @Test
|
// public void getAgreeMentPaySms(){
|
// AgreeMentPaySmsDto agreeMentPaySmsDto = new AgreeMentPaySmsDto();
|
// agreeMentPaySmsDto.setOrderNo("2022082617305930328");
|
//
|
// BigDecimal value = new BigDecimal("0.1").setScale(2, BigDecimal.ROUND_DOWN);
|
// DecimalFormat decimalFormat = new DecimalFormat("0.00#");
|
// String strVal = decimalFormat.format(value);
|
// agreeMentPaySmsDto.setOrderAmount(new BigDecimal(strVal));
|
// agreeMentPaySmsDto.setName("肖永");
|
// agreeMentPaySmsDto.setCreatedTime(DateUtil.now());
|
// agreeMentPaySmsDto.setIdType("1");
|
// agreeMentPaySmsDto.setIdCardNum("430321199310113713");
|
// agreeMentPaySmsDto.setBankNo("6222031901002389639");
|
// agreeMentPaySmsDto.setPhone("15274802129");
|
// String agreeMentPaySms = unipayService.getAgreeMentPaySms(agreeMentPaySmsDto);
|
// if("JS000000".equals(agreeMentPaySms)){
|
// System.out.println("获取成功");
|
// }else{
|
// System.out.println(agreeMentPaySms);
|
// }
|
// }
|
//
|
// @Test
|
// public void agreementSign(){
|
// AgreementSignDto agreementSignDto = new AgreementSignDto();
|
// agreementSignDto.setOrderNo("2022082614465345250");
|
// agreementSignDto.setSmsCode("841243");
|
// unipayService.agreementSign(agreementSignDto);
|
// }
|
//
|
// @Test
|
// public void agreementPay(){
|
// AgreementPayDto agreementPayDto = new AgreementPayDto();
|
// agreementPayDto.setOrderNo("2022082614465345250");
|
//
|
// BigDecimal value = new BigDecimal("0.1").setScale(2, BigDecimal.ROUND_DOWN);
|
// DecimalFormat decimalFormat = new DecimalFormat("0.00#");
|
// String strVal = decimalFormat.format(value);
|
// agreementPayDto.setOrderAmount(new BigDecimal(strVal));
|
// agreementPayDto.setOrderTime(DateUtil.now());
|
// agreementPayDto.setOrderDesc("测试");
|
// agreementPayDto.setBankNo("6222031901002389639");
|
// unipayService.agreementPay(agreementPayDto);
|
// }
|
//
|
// @Test
|
// public void singlePay(){
|
// /**
|
// * 调用汇聚代付
|
// */
|
// String orderNo = MallUtils.getOrderNum("W");
|
// SinglePayDto singlePayDto = new SinglePayDto();
|
// singlePayDto.setMerchantOrderNo(orderNo);
|
// singlePayDto.setReceiverAccountNoEncBankNo("6222031903210023839639");
|
// singlePayDto.setReceiverAccountNoEncName("肖永");
|
// singlePayDto.setReceiverAccountType("201");
|
// BigDecimal paidAmount = new BigDecimal(1.00);
|
// singlePayDto.setPaidAmount(paidAmount);
|
// singlePayDto.setCurrency("201");
|
// singlePayDto.setIsChecked("202");
|
// singlePayDto.setPaidDesc("用户提现");
|
// singlePayDto.setPaidUse("202");
|
// String singlePayRep = unipayService.singlePay(singlePayDto);
|
//
|
// System.out.println(singlePayRep);
|
// }
|
}
|