admin
2022-05-07 15bedcc619b1edb6eb987f9288db7670e5b38c46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.yeshi.makemoney.app.utils.factory.goldcorn;
 
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord;
import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
 
/**
 * @author hxh
 * @title: GoldCornConsumeRecordFactory
 * @description: 金币消费记录工厂
 * @date 2022/4/21 11:28
 */
public class GoldCornConsumeRecordFactory {
 
    public static GoldCornConsumeRecord createExchange(Long uid, String day, int cornNum, BigDecimal rate) {
        GoldCornConsumeRecord record = new GoldCornConsumeRecord();
        record.setUid(uid);
        record.setCornNum(cornNum);
        record.setMoney(rate.multiply(new BigDecimal(record.getCornNum())).setScale(2, RoundingMode.FLOOR));
        record.setType(GoldCornConsumeType.changeMoney);
        record.setId(uid + "-" + record.getType().name() + "-" + day);
        //积分兑换少于1分的按照1分计算
        if (record.getMoney().compareTo(new BigDecimal(0)) == 0 && cornNum > 0) {
            record.setMoney(new BigDecimal("0.01"));
        }
        return record;
    }
 
 
}