1 文件已重命名
16个文件已修改
8个文件已添加
| | |
| | | @Builder |
| | | public static class DaoQuery { |
| | | public Long id; |
| | | public ExchangeRate.ExchangeType exchangeType; |
| | | public ExchangeRate.ExchangeRateType exchangeType; |
| | | public Double rate; |
| | | public Date minStartTime; |
| | | public Date maxStartTime; |
| | |
| | | |
| | | List<UserCreditBalance> list(@Param("query") DaoQuery query); |
| | | |
| | | List<UserCreditBalance> listByIds(@Param("ids") List<Long> ids); |
| | | |
| | | long count(@Param("query") DaoQuery query); |
| | | |
| | | public static class DaoQuery { |
| | |
| | | package com.taoke.autopay.entity.credit; |
| | | |
| | | import lombok.experimental.Tolerate; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | import java.math.BigDecimal; |
| | |
| | | private Date updateTime; // 更新时间 |
| | | |
| | | // 新增默认构造函数 |
| | | @Tolerate |
| | | public CreditExchangeRecord() { |
| | | } |
| | | |
| | |
| | | |
| | | import lombok.Data; |
| | | import lombok.Builder; |
| | | import lombok.experimental.Tolerate; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import java.util.Date; |
| | |
| | | |
| | | // 枚举类型:积分设置类型 |
| | | public enum CreditSettingType { |
| | | MINIMUM_EXCHANGE_AMOUNT, // 最低兑换金额 |
| | | DOUYIN_PAYMENT_SUCCESS_CREDITS, // 抖音支付成功积分 |
| | | KUAISHOU_PAYMENT_SUCCESS_CREDITS, // 快手支付成功积分 |
| | | DAILY_EXCHANGE_LIMIT // 每日兑换次数 |
| | | MINIMUM_EXCHANGE_AMOUNT("最低兑换金额"), // 最低兑换金额 |
| | | DOUYIN_PAYMENT_SUCCESS_CREDITS("抖音支付成功积分"), // 抖音支付成功积分 |
| | | KUAISHOU_PAYMENT_SUCCESS_CREDITS("快手支付成功积分"), // 快手支付成功积分 |
| | | DAILY_EXCHANGE_LIMIT("每日兑换次数"); // 每日兑换次数 |
| | | |
| | | public String getDesc() { |
| | | return desc; |
| | | } |
| | | |
| | | private String desc; |
| | | |
| | | |
| | | private CreditSettingType(String desc){ |
| | | this.desc =desc; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Id |
| | |
| | | |
| | | @Column(name = "update_time") |
| | | private Date updateTime; // 更新时间 |
| | | |
| | | @Tolerate |
| | | // 新增默认构造函数 |
| | | public CreditSetting() { |
| | | } |
| | |
| | | package com.taoke.autopay.entity.credit; |
| | | |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.experimental.Tolerate; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | @Builder |
| | | @Data |
| | | @Table(value = "table_exchange_rate") |
| | | public class ExchangeRate { |
| | | |
| | | public enum ExchangeType { |
| | | public enum ExchangeRateType { |
| | | NEW_USER_EXCHANGE, // 新人兑换 |
| | | GENERAL_EXCHANGE // 一般兑换 |
| | | } |
| | | |
| | | @Tolerate |
| | | public ExchangeRate(){ |
| | | |
| | | } |
| | | |
| | | @Id |
| | |
| | | private Long id; // 主键ID |
| | | |
| | | @Column(name = "exchange_type") |
| | | private ExchangeType exchangeType; // 兑换类型 |
| | | private ExchangeRateType exchangeType; // 兑换类型 |
| | | |
| | | @Column(name = "rate") |
| | | private BigDecimal rate; // 汇率 |
| | |
| | | package com.taoke.autopay.entity.credit; |
| | | |
| | | import lombok.Builder; |
| | | import lombok.Data; |
| | | import lombok.experimental.Tolerate; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.yeshi.utils.generater.mybatis.Table; |
| | | |
| | | import java.util.Date; |
| | | |
| | | @Builder |
| | | @Data |
| | | @Table(value = "table_user_alipay_binding") |
| | | public class UserAlipayBinding { |
| | | |
| | | @Tolerate |
| | | public UserAlipayBinding(){ |
| | | |
| | | } |
| | | |
| | | @Id |
| | | @Column(name = "id") |
| | | private Long id; // 主键ID |
| | |
| | | package com.taoke.autopay.entity.credit; |
| | | |
| | | import lombok.experimental.Tolerate; |
| | | import org.yeshi.utils.generater.mybatis.Column; |
| | | import org.springframework.data.annotation.Id; |
| | | import java.math.BigDecimal; |
| | |
| | | @Column(name = "update_time") |
| | | private Date updateTime; // 更新时间 |
| | | |
| | | @Tolerate |
| | | // 新增默认构造函数 |
| | | public UserCreditRecord() { |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.exception; |
| | | |
| | | /** |
| | | * @author hxh |
| | | * @title: 积分异常 |
| | | * @description: 兑换异常 |
| | | * @date 2024/6/14 18:46 |
| | | */ |
| | | public class UserCreditException extends Exception{ |
| | | |
| | | |
| | | private int code; |
| | | |
| | | public int getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public UserCreditException(int code, String msg){ |
| | | super(msg); |
| | | } |
| | | |
| | | public UserCreditException(String msg){ |
| | | super(msg); |
| | | } |
| | | |
| | | } |
| | |
| | | @Resource |
| | | private UserCreditRecordService userCreditRecordService; |
| | | |
| | | @Resource |
| | | private UserCreditManager userCreditManager; |
| | | |
| | | /** |
| | | * 用户积分兑换 |
| | | * |
| | |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_BALANCE_NOT_ENOUGH, "用户积分不足"); |
| | | } |
| | | |
| | | |
| | | |
| | | // 如果是红包兑换,判断用户兑换频率 |
| | | if (exchangeType == CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) { |
| | | checkRedPacketExchangeFrequency(userId); |
| | |
| | | BigDecimal exchangeAmount = calculateExchangeAmount(request.getUid(), request.getConsumedCredits()); |
| | | exchangeRecord.setExchangeValue(exchangeAmount); |
| | | } |
| | | // 扣减用户积分 |
| | | userCreditBalanceService.decreaseCreditBalance(userId, request.getConsumedCredits()); |
| | | |
| | | // 记录兑换记录 |
| | | exchangeRecord.setUid(userId); |
| | | exchangeRecord.setExchangeType(exchangeType); |
| | |
| | | exchangeRecord.setExchangeInfo2(alipayBindings.get(0).getAlipayAccount()); |
| | | exchangeRecord.setCreateTime(new Date()); |
| | | exchangeRecord.setUpdateTime(new Date()); |
| | | return userCreditExchangeRecordService.addExchangeRecord(exchangeRecord); |
| | | userCreditExchangeRecordService.addExchangeRecord(exchangeRecord); |
| | | |
| | | // 扣减用户积分 |
| | | userCreditManager.decreaseCredit(UserCreditRecord.builder() |
| | | .creditAmount(request.getConsumedCredits()) |
| | | .consumptionMethod(UserCreditRecord.ConsumptionMethod.EXCHANGE_RED_PACKET) |
| | | .direction(UserCreditRecord.DIRECTION_CONSUME) |
| | | .identifierId(exchangeRecord.getId()+"") |
| | | .uid(exchangeRecord.getUid()) |
| | | .description("红包兑换") |
| | | .build()); |
| | | return exchangeRecord.getId(); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param credit |
| | | * @return |
| | | */ |
| | | private BigDecimal calculateExchangeAmount(Long uid, int credit) throws UserCreditExchangeException{ |
| | | public BigDecimal calculateExchangeAmount(Long uid, int credit) throws UserCreditExchangeException{ |
| | | long count = userCreditExchangeRecordService.countExchangeRecords(CreditExchangeRecordMapper.DaoQuery.builder() |
| | | .uid(uid).build()); |
| | | Date nowDate = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMddHHmm"),"yyyyMMddHHmm")); |
| | |
| | | if(count<=0){ |
| | | // 新人兑换 |
| | | List<ExchangeRate> rates = exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder() |
| | | .exchangeType(ExchangeRate.ExchangeType.NEW_USER_EXCHANGE) |
| | | .minStartTime(nowDate) |
| | | .maxEndTime(nowDate) |
| | | .exchangeType(ExchangeRate.ExchangeRateType.NEW_USER_EXCHANGE) |
| | | .maxStartTime(nowDate) |
| | | .minEndTime(nowDate) |
| | | .count(Integer.MAX_VALUE) |
| | | .build()); |
| | | if(rates.isEmpty()) { |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,"新人兑换汇率未设置"); |
| | |
| | | }else{ |
| | | // 老用户兑换 |
| | | List<ExchangeRate> rates = exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder() |
| | | .exchangeType(ExchangeRate.ExchangeType.GENERAL_EXCHANGE) |
| | | .minStartTime(nowDate) |
| | | .maxEndTime(nowDate) |
| | | .exchangeType(ExchangeRate.ExchangeRateType.GENERAL_EXCHANGE) |
| | | .maxStartTime(nowDate) |
| | | .minEndTime(nowDate) |
| | | .count(Integer.MAX_VALUE) |
| | | .build()); |
| | | if(rates.isEmpty()) { |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,"老用户兑换汇率未设置"); |
| | | } |
| | | money = new BigDecimal(credit).multiply(rates.get(0).getRate()).setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | CreditSetting setting = creditSettingService.getSettingCacheByType(CreditSetting.CreditSettingType.MINIMUM_EXCHANGE_AMOUNT, nowDate); |
| | | if(setting!=null&& new BigDecimal(setting.getValue()).compareTo(money)>0){ |
| | | throw new UserCreditExchangeException(UserCreditExchangeException.CODE_COMMON,String.format("兑换金额不能低于%s元",setting.getValue())); |
| | | } |
| | | return money; |
| | | } |
| | | } |
| | |
| | | package com.taoke.autopay.manager; |
| | | |
| | | import com.taoke.autopay.entity.credit.CreditSetting; |
| | | import com.taoke.autopay.entity.credit.UserCreditBalance; |
| | | import com.taoke.autopay.entity.credit.UserCreditRecord; |
| | | import com.taoke.autopay.exception.UserCreditException; |
| | | import com.taoke.autopay.service.credit.CreditSettingService; |
| | | import com.taoke.autopay.service.credit.UserCreditBalanceService; |
| | | import com.taoke.autopay.service.credit.UserCreditRecordService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | |
| | | @Component |
| | | public class UserCreditManager { |
| | |
| | | |
| | | @Resource |
| | | private UserCreditRecordService userCreditRecordService; |
| | | |
| | | @Resource |
| | | private CreditSettingService creditSettingService; |
| | | |
| | | |
| | | /** |
| | |
| | | // 增加积分记录 |
| | | userCreditRecordService.addCreditRecord(creditRecord); |
| | | } |
| | | |
| | | /** |
| | | * 抖音订单支付记录 |
| | | * @param uid |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addDYOrderPayRecord(Long uid,String keyId) throws UserCreditException { |
| | | CreditSetting setting = creditSettingService.getSettingCacheByType(CreditSetting.CreditSettingType.DOUYIN_PAYMENT_SUCCESS_CREDITS,new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMddHHmm"),"yyyyMMddHHmm"))); |
| | | if(setting==null){ |
| | | throw new UserCreditException("未配置抖音支付成功积分"); |
| | | } |
| | | UserCreditRecord record = UserCreditRecord.builder() |
| | | .creditAmount(Integer.parseInt(setting.getValue())) |
| | | .acquisitionMethod(UserCreditRecord.AcquisitionMethod.COMMAND_PAYMENT) |
| | | .direction(UserCreditRecord.DIRECTION_GAIN) |
| | | .identifierId(keyId) |
| | | .uid(uid) |
| | | .description("抖音代付") |
| | | .build(); |
| | | increaseCredit(record); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 快手订单支付成功增加积分 |
| | | * @param uid |
| | | * @param keyId |
| | | * @throws UserCreditException |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void addKSOrderPayRecord(Long uid,String keyId) throws UserCreditException { |
| | | CreditSetting setting = creditSettingService.getSettingCacheByType(CreditSetting.CreditSettingType.KUAISHOU_PAYMENT_SUCCESS_CREDITS,new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(System.currentTimeMillis(),"yyyyMMddHHmm"),"yyyyMMddHHmm"))); |
| | | if(setting==null){ |
| | | throw new UserCreditException("未配置快手支付成功积分"); |
| | | } |
| | | UserCreditRecord record = UserCreditRecord.builder() |
| | | .creditAmount(Integer.parseInt(setting.getValue())) |
| | | .acquisitionMethod(UserCreditRecord.AcquisitionMethod.COMMAND_PAYMENT) |
| | | .direction(UserCreditRecord.DIRECTION_GAIN) |
| | | .identifierId(keyId) |
| | | .uid(uid) |
| | | .description("快手代付") |
| | | .build(); |
| | | increaseCredit(record); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.taoke.autopay.service.impl; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.taoke.autopay.entity.SystemConfigKeyEnum; |
| | | import com.taoke.autopay.utils.StringUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | import com.taoke.autopay.service.SystemConfigService; |
| | | import com.taoke.autopay.service.WxUserSettingService; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class WxUserSettingServiceImpl implements WxUserSettingService { |
| | | |
| | |
| | | |
| | | @Override |
| | | public int addSetting(CreditSetting creditSetting) { |
| | | if(creditSetting.getCreateTime()==null){ |
| | | creditSetting.setCreateTime(new Date()); |
| | | } |
| | | return creditSettingMapper.insertSelective(creditSetting); |
| | | } |
| | | |
| | |
| | | import com.taoke.autopay.service.credit.ExchangeRateService; |
| | | import org.springframework.stereotype.Service; |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Override |
| | | public int addExchangeRate(ExchangeRate exchangeRate) { |
| | | if(exchangeRate.getCreateTime()==null){ |
| | | exchangeRate.setCreateTime(new Date()); |
| | | } |
| | | return exchangeRateMapper.insertSelective(exchangeRate); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public void initializeCreditBalance(Long userId) { |
| | | if(getCreditBalanceByUserId(userId)!=null){ |
| | | return; |
| | | } |
| | | UserCreditBalance userCreditBalance = new UserCreditBalance(); |
| | | userCreditBalance.setId(userId); |
| | | userCreditBalance.setCreditBalance(BigDecimal.ZERO); |
| | | userCreditBalance.setCreditBalance(0); |
| | | userCreditBalance.setCreateTime(new Date()); |
| | | userCreditBalance.setUpdateTime(new Date()); |
| | | userCreditBalanceMapper.insert(userCreditBalance); |
| | |
| | | |
| | | @Override |
| | | public Map<Long, UserCreditBalance> getCreditBalancesByUserIds(List<Long> userIds) { |
| | | List<UserCreditBalance> userCreditBalances = userCreditBalanceMapper.selectByIds(userIds); |
| | | List<UserCreditBalance> userCreditBalances = userCreditBalanceMapper.listByIds(userIds); |
| | | Map<Long, UserCreditBalance> balanceMap = new HashMap<>(); |
| | | for (UserCreditBalance balance : userCreditBalances) { |
| | | balanceMap.put(balance.getId(), balance); |
| | |
| | | public void increaseCreditBalance(Long userId, int amount) { |
| | | UserCreditBalance userCreditBalance = userCreditBalanceMapper.selectByPrimaryKeyForUpdate(userId); |
| | | if (userCreditBalance != null) { |
| | | userCreditBalance.setCreditBalance(userCreditBalance.getCreditBalance().add(amount)); |
| | | userCreditBalance.setUpdateTime(new Date()); |
| | | userCreditBalanceMapper.updateByPrimaryKeySelective(userCreditBalance); |
| | | userCreditBalanceMapper.updateByPrimaryKeySelective(UserCreditBalance.builder() |
| | | .id(userCreditBalance.getId()) |
| | | .creditBalance(userCreditBalance.getCreditBalance() + amount) |
| | | .updateTime(new Date()) |
| | | .build()); |
| | | } |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void decreaseCreditBalance(Long userId, int amount) { |
| | | UserCreditBalance userCreditBalance = userCreditBalanceMapper.selectByPrimaryKeyForUpdate(userId); |
| | | if (userCreditBalance != null) { |
| | | userCreditBalance.setCreditBalance(userCreditBalance.getCreditBalance().subtract(amount)); |
| | | userCreditBalance.setUpdateTime(new Date()); |
| | | userCreditBalanceMapper.updateByPrimaryKeySelective(userCreditBalance); |
| | | userCreditBalanceMapper.updateByPrimaryKeySelective(UserCreditBalance.builder() |
| | | .id(userCreditBalance.getId()) |
| | | .creditBalance(userCreditBalance.getCreditBalance() - amount) |
| | | .updateTime(new Date()) |
| | | .build()); |
| | | } |
| | | } |
| | | } |
| | |
| | | spring: |
| | | profiles: |
| | | active: pro |
| | | active: dev |
| | |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | |
| | | <select id="selectByType" resultMap="BaseResultMap" parameterType="com.taoke.autopay.entity.credit.CreditSetting.CreditSettingType"> |
| | | <select id="selectByType" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from table_credit_setting |
| | | where type = #{type,jdbcType=VARCHAR} |
| | | </select> |
| | | |
| | | <select id="list" resultMap="BaseResultMap" parameterType="com.taoke.autopay.dao.credit.CreditSettingMapper.DaoQuery"> |
| | | |
| | | <sql id="listWhereSQL"> |
| | | <if test="query.id != null">and id = #{query.id,jdbcType=BIGINT}</if> |
| | | <if test="query.type != null">and type = #{query.type,jdbcType=VARCHAR}</if> |
| | | <if test="query.name != null">and name = #{query.name,jdbcType=VARCHAR}</if> |
| | | <if test="query.value != null">and value = #{query.value,jdbcType=VARCHAR}</if> |
| | | <if test="query.minStartTime != null">and start_time >= #{query.minStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.maxStartTime != null">and start_time < #{query.maxStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.minEndTime != null">and end_time >= #{query.minEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.maxEndTime != null">and end_time < #{query.maxEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.minCreateTime != null">and create_time >= #{query.minCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.maxCreateTime != null">and create_time < #{query.maxCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.minUpdateTime != null">and update_time >= #{query.minUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="query.maxUpdateTime != null">and update_time < #{query.maxUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | </sql> |
| | | |
| | | <select id="list" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from table_credit_setting |
| | | <where> |
| | | <if test="id != null">and id = #{id,jdbcType=BIGINT}</if> |
| | | <if test="type != null">and type = #{type,jdbcType=VARCHAR}</if> |
| | | <if test="name != null">and name = #{name,jdbcType=VARCHAR}</if> |
| | | <if test="value != null">and value = #{value,jdbcType=VARCHAR}</if> |
| | | <if test="minStartTime != null">and start_time >= #{minStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxStartTime != null">and start_time < #{maxStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minEndTime != null">and end_time >= #{minEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxEndTime != null">and end_time < #{maxEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minCreateTime != null">and create_time >= #{minCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxCreateTime != null">and create_time < #{maxCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minUpdateTime != null">and update_time >= #{minUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxUpdateTime != null">and update_time < #{maxUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | <include refid="listWhereSQL" /> |
| | | </where> |
| | | <if test="sortList != null and sortList.size() > 0"> |
| | | <if test="query.sortList != null and query.sortList.size() > 0"> |
| | | order by |
| | | <foreach collection="sortList" item="sort" separator=","> |
| | | <foreach collection="query.sortList" item="sort" separator=","> |
| | | ${sort} |
| | | </foreach> |
| | | </if> |
| | | <if test="start != null and count != null"> |
| | | limit #{start,jdbcType=BIGINT}, #{count,jdbcType=INTEGER} |
| | | <if test="query.start != null and query.count != null"> |
| | | limit #{query.start,jdbcType=BIGINT}, #{query.count,jdbcType=INTEGER} |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="count" resultType="long" parameterType="com.taoke.autopay.dao.credit.CreditSettingMapper.DaoQuery"> |
| | | <select id="count" resultType="long" > |
| | | select count(*) |
| | | from table_credit_setting |
| | | <where> |
| | | <if test="id != null">and id = #{id,jdbcType=BIGINT}</if> |
| | | <if test="type != null">and type = #{type,jdbcType=VARCHAR}</if> |
| | | <if test="name != null">and name = #{name,jdbcType=VARCHAR}</if> |
| | | <if test="value != null">and value = #{value,jdbcType=VARCHAR}</if> |
| | | <if test="minStartTime != null">and start_time >= #{minStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxStartTime != null">and start_time < #{maxStartTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minEndTime != null">and end_time >= #{minEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxEndTime != null">and end_time < #{maxEndTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minCreateTime != null">and create_time >= #{minCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxCreateTime != null">and create_time < #{maxCreateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="minUpdateTime != null">and update_time >= #{minUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | <if test="maxUpdateTime != null">and update_time < #{maxUpdateTime,jdbcType=TIMESTAMP}</if> |
| | | <include refid="listWhereSQL" /> |
| | | </where> |
| | | </select> |
| | | |
| | |
| | | <if test="query.id!=null">AND id = #{query.id}</if> |
| | | <if test="query.creditBalance!=null">AND credit_balance = #{query.creditBalance}</if> |
| | | <if test="query.minCreateTime!=null">AND create_time >= #{query.minCreateTime}</if> |
| | | <if test="query.maxCreateTime!=null">AND create_time < #{query.maxCreateTime}</if> |
| | | <if test="query.maxCreateTime!=null">AND create_time <![CDATA[ < ]]> #{query.maxCreateTime}</if> |
| | | <if test="query.minUpdateTime!=null">AND update_time >= #{query.minUpdateTime}</if> |
| | | <if test="query.maxUpdateTime!=null">AND update_time < #{query.maxUpdateTime}</if> |
| | | <if test="query.maxUpdateTime!=null">AND update_time <![CDATA[ < ]]> #{query.maxUpdateTime}</if> |
| | | </sql> |
| | | |
| | | <select id="list" resultMap="BaseResultMap" parameterType="com.taoke.autopay.dao.credit.UserCreditBalanceMapper.DaoQuery"> |
| | | <select id="list" resultMap="BaseResultMap" > |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from table_user_credit_balance |
| | |
| | | limit #{query.start},#{query.count} |
| | | </select> |
| | | |
| | | <select id="count" resultType="java.lang.Long" parameterType="com.taoke.autopay.dao.credit.UserCreditBalanceMapper.DaoQuery"> |
| | | <select id="listByIds" resultMap="BaseResultMap"> |
| | | select |
| | | <include refid="Base_Column_List" /> |
| | | from table_user_credit_balance |
| | | <foreach collection="ids" item="id" open=" where ( " close=")" separator=" OR "> |
| | | id = #{id} |
| | | </foreach> |
| | | </select> |
| | | |
| | | |
| | | |
| | | <select id="count" resultType="java.lang.Long"> |
| | | select count(*) |
| | | from table_user_credit_balance |
| | | where 1=1 |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <html> |
| | | |
| | | <head> |
| | | <meta charset="utf-8"> |
| | | <meta name="viewport" content="width=device-width, viewport-fit=cover, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> |
| | | <title>支付宝账号设置</title> |
| | | <script> |
| | | window.onresize = function() { |
| | | document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + 'px'; |
| | | }; |
| | | window.onresize(); |
| | | </script> |
| | | <link rel="stylesheet" type="text/css" href="../layui/css/layui.css" /> |
| | | <link rel="stylesheet" type="text/css" href="css/common.css" /> |
| | | <script src="../js/jquery.min.js"></script> |
| | | <script src="../js/vue.min.js"></script> |
| | | <script src="../layui/layui.js"></script> |
| | | <script src="js/http.js"></script> |
| | | |
| | | <style> |
| | | body { |
| | | background-color: #E0E0E0; |
| | | } |
| | | |
| | | .item { |
| | | margin-bottom: 1px; |
| | | height: 0.89rem; |
| | | display: flex; |
| | | align-items: center; |
| | | background-color: #FFF; |
| | | padding: 0 0.3rem; |
| | | } |
| | | |
| | | .item .title { |
| | | font-size: 0.30rem; |
| | | color: #000000; |
| | | width: 2rem; |
| | | text-align: left; |
| | | } |
| | | |
| | | .item input { |
| | | background-color: transparent; |
| | | border: none; |
| | | font-size: 0.30rem; |
| | | } |
| | | |
| | | .btn { |
| | | width: 6.50rem; |
| | | height: 0.78rem; |
| | | line-height: 0.78rem; |
| | | background: #F6BDD3; |
| | | border-radius: 0.39rem; |
| | | margin: auto 0; |
| | | border: none; |
| | | color: #FFF; |
| | | font-size: 0.36rem; |
| | | margin-top: 1.59rem; |
| | | } |
| | | |
| | | .active { |
| | | background-color: #FF2B4B; |
| | | } |
| | | </style> |
| | | </head> |
| | | |
| | | <body> |
| | | <div id="container" style="text-align: center;"> |
| | | <div class="top-nav"> |
| | | <div @click="goBack"></div> |
| | | <div>支付宝设置</div> |
| | | |
| | | </div> |
| | | <div style="height: 0.82rem;"></div> |
| | | |
| | | <div class="item"> |
| | | <div class="title">姓 名</div> |
| | | <input type="text" id="alipayName" placeholder="输入你支付宝绑定的姓名" /> |
| | | </div> |
| | | <div class="item"> |
| | | <div class="title">支付宝帐号</div> |
| | | <input type="text" id="alipayAccount" placeholder="输入支付宝账号" /> |
| | | </div> |
| | | |
| | | <button class="btn active" @click="save">保存并提交</button> |
| | | |
| | | </div> |
| | | |
| | | <script> |
| | | $(function() { |
| | | var app = new Vue({ |
| | | el: "#container", |
| | | methods: { |
| | | goBack: function() { |
| | | if (window.history.length > 1) { |
| | | window.history.back(); |
| | | } |
| | | }, |
| | | save: function() { |
| | | var account = $("#alipayAccount").val(); |
| | | var name = $("#alipayName").val(); |
| | | if (account.length <= 0) { |
| | | layer.msg("请输入账号"); |
| | | return; |
| | | } |
| | | if (name.length <= 0) { |
| | | layer.msg("请输入名称"); |
| | | return; |
| | | } |
| | | var index = layer.load(); |
| | | http_util.post("/agentapi/admin/setAlipayAccount", { |
| | | alipayAccount: account, |
| | | alipayName: name |
| | | }, function(res) { |
| | | layer.close(index); |
| | | if (res.code == 0) { |
| | | layer.msg("设置成功"); |
| | | app.goBack(); |
| | | } else { |
| | | layer.msg(res.msg); |
| | | } |
| | | }, function(res) { |
| | | layer.close(index); |
| | | layer.msg(res); |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | </script> |
| | | |
| | | </body> |
| | | |
| | | </html> |
File was renamed from src/main/resources/static/credit.html |
| | |
| | | }, |
| | | bindAlipay() { |
| | | // 跳转到支付宝绑定页面 |
| | | window.location.href = '/static/agent/alipay_account_setting.html'; |
| | | window.location.href = '../agent/alipay_account_setting.html'; |
| | | } |
| | | } |
| | | }); |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.dao.credit.ExchangeRateMapper; |
| | | import com.taoke.autopay.entity.credit.ExchangeRate; |
| | | import com.taoke.autopay.entity.credit.UserAlipayBinding; |
| | | import com.taoke.autopay.service.credit.ExchangeRateService; |
| | | import com.taoke.autopay.service.credit.UserAlipayBindingService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @SpringBootTest |
| | | public class AlipayBindTest { |
| | | @Resource |
| | | private UserAlipayBindingService userAlipayBindingService; |
| | | |
| | | @Test |
| | | public void bind(){ |
| | | userAlipayBindingService.addBinding(UserAlipayBinding.builder() |
| | | .uid(2L) |
| | | .alipayAccount("xxxxxxxx@qq.com") |
| | | .alipayName("xxxx") |
| | | .build()); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.entity.credit.UserCreditBalance; |
| | | import com.taoke.autopay.service.credit.UserCreditBalanceService; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.Map; |
| | | |
| | | @SpringBootTest |
| | | public class BalanceTest { |
| | | @Resource |
| | | private UserCreditBalanceService userCreditBalanceService; |
| | | |
| | | @Test |
| | | public void init(){ |
| | | userCreditBalanceService.initializeCreditBalance(2L); |
| | | } |
| | | @Test |
| | | public void test(){ |
| | | long uid = 2L; |
| | | UserCreditBalance balance = userCreditBalanceService.getCreditBalanceByUserId(uid); |
| | | System.out.println(balance); |
| | | userCreditBalanceService.increaseCreditBalance(uid, 10); |
| | | balance = userCreditBalanceService.getCreditBalanceByUserId(uid); |
| | | userCreditBalanceService.decreaseCreditBalance(uid, 10); |
| | | balance = userCreditBalanceService.getCreditBalanceByUserId(uid); |
| | | System.out.println(balance); |
| | | Map<Long, UserCreditBalance> map=userCreditBalanceService.getCreditBalancesByUserIds(Arrays.asList(new Long[]{uid})); |
| | | System.out.println(map); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.entity.credit.CreditExchangeRecord; |
| | | import com.taoke.autopay.exception.UserCreditException; |
| | | import com.taoke.autopay.exception.UserCreditExchangeException; |
| | | import com.taoke.autopay.manager.UserCreditExchangeManager; |
| | | import com.taoke.autopay.manager.UserCreditManager; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | @SpringBootTest |
| | | public class CreditExchangeTest { |
| | | @Resource |
| | | private UserCreditExchangeManager userCreditExchangeManager; |
| | | |
| | | @Test |
| | | public void exchangeCredit() throws UserCreditExchangeException { |
| | | userCreditExchangeManager.exchangeCredit(CreditExchangeRecord.builder() |
| | | .exchangeType(CreditExchangeRecord.ExchangeType.FUND_EXCHANGE) |
| | | .consumedCredits(100) |
| | | .uid(2L) |
| | | .build()); |
| | | } |
| | | |
| | | @Test |
| | | public void pass() throws UserCreditExchangeException { |
| | | userCreditExchangeManager.approveExchange(2L); |
| | | } |
| | | |
| | | @Test |
| | | public void reject() throws UserCreditExchangeException { |
| | | userCreditExchangeManager.rejectExchange(1L); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.entity.credit.CreditSetting; |
| | | import com.taoke.autopay.exception.UserCreditException; |
| | | import com.taoke.autopay.manager.UserCreditManager; |
| | | import com.taoke.autopay.service.credit.CreditSettingService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | |
| | | @SpringBootTest |
| | | public class CreditTest { |
| | | @Resource |
| | | private UserCreditManager userCreditManager; |
| | | |
| | | @Test |
| | | public void addDYOrder() throws UserCreditException { |
| | | userCreditManager.addDYOrderPayRecord(2L,"123123123123"); |
| | | } |
| | | |
| | | @Test |
| | | public void addKSOrder() throws UserCreditException { |
| | | userCreditManager.addKSOrderPayRecord(2L,"12312312234312233"); |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.dao.credit.ExchangeRateMapper; |
| | | import com.taoke.autopay.entity.credit.CreditSetting; |
| | | import com.taoke.autopay.entity.credit.ExchangeRate; |
| | | import com.taoke.autopay.service.credit.CreditSettingService; |
| | | import com.taoke.autopay.service.credit.ExchangeRateService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @SpringBootTest |
| | | public class RateTest { |
| | | @Resource |
| | | private ExchangeRateService exchangeRateService; |
| | | |
| | | @Test |
| | | public void setRate(){ |
| | | exchangeRateService.addExchangeRate(ExchangeRate.builder() |
| | | .rate(new BigDecimal("0.03")) |
| | | .exchangeType(ExchangeRate.ExchangeRateType.NEW_USER_EXCHANGE) |
| | | .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | |
| | | .build()); |
| | | |
| | | exchangeRateService.addExchangeRate(ExchangeRate.builder() |
| | | .rate(new BigDecimal("0.02")) |
| | | .exchangeType(ExchangeRate.ExchangeRateType.GENERAL_EXCHANGE) |
| | | .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | |
| | | .build()); |
| | | |
| | | } |
| | | @Test |
| | | public void getSetting(){ |
| | | long uid = 2L; |
| | | List<ExchangeRate> rateList = exchangeRateService.listExchangeRates(ExchangeRateMapper.DaoQuery.builder() |
| | | .exchangeType(ExchangeRate.ExchangeRateType.NEW_USER_EXCHANGE) |
| | | .build()); |
| | | System.out.println(rateList); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | package com.taoke.autopay.credit; |
| | | |
| | | import com.taoke.autopay.entity.credit.CreditSetting; |
| | | import com.taoke.autopay.entity.credit.UserCreditBalance; |
| | | import com.taoke.autopay.service.credit.CreditSettingService; |
| | | import com.taoke.autopay.service.credit.UserCreditBalanceService; |
| | | import com.taoke.autopay.utils.TimeUtil; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | @SpringBootTest |
| | | public class SettingTest { |
| | | @Resource |
| | | private CreditSettingService creditSettingService; |
| | | |
| | | @Test |
| | | public void addSetting(){ |
| | | // creditSettingService.addSetting(CreditSetting.builder() |
| | | // .type(CreditSetting.CreditSettingType.MINIMUM_EXCHANGE_AMOUNT) |
| | | // .value("100") |
| | | // .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | // .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | // .name(CreditSetting.CreditSettingType.MINIMUM_EXCHANGE_AMOUNT.getDesc()) |
| | | // .build()); |
| | | |
| | | creditSettingService.addSetting(CreditSetting.builder() |
| | | .type(CreditSetting.CreditSettingType.DOUYIN_PAYMENT_SUCCESS_CREDITS) |
| | | .value("2") |
| | | .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | .name(CreditSetting.CreditSettingType.DOUYIN_PAYMENT_SUCCESS_CREDITS.getDesc()) |
| | | .build()); |
| | | |
| | | creditSettingService.addSetting(CreditSetting.builder() |
| | | .type(CreditSetting.CreditSettingType.KUAISHOU_PAYMENT_SUCCESS_CREDITS) |
| | | .value("3") |
| | | .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | .name(CreditSetting.CreditSettingType.KUAISHOU_PAYMENT_SUCCESS_CREDITS.getDesc()) |
| | | .build()); |
| | | |
| | | creditSettingService.addSetting(CreditSetting.builder() |
| | | .type(CreditSetting.CreditSettingType.DAILY_EXCHANGE_LIMIT) |
| | | .value("1") |
| | | .startTime(new Date(TimeUtil.convertToTimeTemp("19700101","yyyyMMdd"))) |
| | | .endTime(new Date(TimeUtil.convertToTimeTemp("29990101","yyyyMMdd"))) |
| | | .name(CreditSetting.CreditSettingType.DAILY_EXCHANGE_LIMIT.getDesc()) |
| | | .build()); |
| | | |
| | | } |
| | | @Test |
| | | public void getSetting(){ |
| | | long uid = 2L; |
| | | CreditSetting setting = creditSettingService.getSettingCacheByType(CreditSetting.CreditSettingType.MINIMUM_EXCHANGE_AMOUNT, new Date()); |
| | | System.out.println(setting); |
| | | } |
| | | |
| | | |
| | | } |