admin
2019-11-01 56bcbcf230f4ce53376c7ccc99b91990d3375f9d
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package com.yeshi.fanli.util.factory;
 
import java.math.BigDecimal;
import java.util.Date;
 
import com.yeshi.fanli.entity.redpack.RedPackDetail;
import com.yeshi.fanli.entity.redpack.RedPackDetail.RedPackDetailTypeEnum;
import com.yeshi.fanli.entity.redpack.RedPackExchange;
import com.yeshi.fanli.entity.redpack.RedPackGiveRecord;
import com.yeshi.fanli.exception.redpack.RedPackDetailException;
import com.yeshi.fanli.util.StringUtil;
 
public class RedPackDetailFactory {
 
    /**
     * 红包提现
     * 
     * @param extract
     * @return
     */
    public static RedPackDetail createExchange(RedPackExchange exchange) throws RedPackDetailException {
        if (exchange == null)
            throw new RedPackDetailException(1, "提现记录不能为空");
 
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(false);
        detail.setDesc("等待人工审核");
        detail.setUid(exchange.getUid());
        detail.setMoney(new BigDecimal("-" + exchange.getMoney()));
        detail.setType(RedPackDetailTypeEnum.redExchange);
        detail.setTitle(RedPackDetailTypeEnum.redExchange.getDesc());
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.redExchange.name() + ":" + exchange.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 红包提现通过
     * 
     * @param extract
     * @return
     */
    public static RedPackDetail updateExchangePass(Long id, RedPackExchange exchange) throws RedPackDetailException {
        if (id == null)
            throw new RedPackDetailException(1, "明细ID不能为空");
 
        if (exchange == null)
            throw new RedPackDetailException(1, "提现记录不能为空");
 
        RedPackDetail detail = new RedPackDetail();
        detail.setId(id);
        detail.setDisplay(true);
        detail.setDesc("请到账户余额中查看");
        detail.setType(RedPackDetailTypeEnum.redExchangePass);
        detail.setTitle(RedPackDetailTypeEnum.redExchangePass.getDesc());
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.redExchangePass.name() + ":" + exchange.getId()));
        return detail;
    }
 
    /**
     * 红包提现拒绝
     * 
     * @param extract
     * @return
     */
    public static RedPackDetail createExchangeReject(RedPackExchange exchange) throws RedPackDetailException {
        if (exchange == null)
            throw new RedPackDetailException(1, "提现记录不能为空");
 
        // 红包明细- 退回红包
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(false);
        detail.setUid(exchange.getUid());
        detail.setMoney(exchange.getMoney());
        detail.setDesc("红包产生过程中涉嫌违规");
        detail.setTitle(RedPackDetailTypeEnum.redExchangeReject.getDesc());
        detail.setType(RedPackDetailTypeEnum.redExchangeReject);
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.redExchangeReject.name() + ":" + exchange.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 赠送好友明细
     * 
     * @param giveRecord
     * @return
     * @throws RedPackDetailException
     */
    public static RedPackDetail createGiveOthers(RedPackGiveRecord giveRecord) throws RedPackDetailException {
        if (giveRecord == null)
            throw new RedPackDetailException(1, "赠送记录不能为空");
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(true);
        detail.setUid(giveRecord.getGiveUid());
        detail.setMoney(new BigDecimal("-" + giveRecord.getAmount()));
        detail.setType(RedPackDetailTypeEnum.giveOthers);
        detail.setTitle(RedPackDetailTypeEnum.giveOthers.getDesc());
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.giveOthers.name() + ":" + giveRecord.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 赠送成功
     * 
     * @param id
     * @param giveRecord
     * @return
     * @throws RedPackDetailException
     */
    public static RedPackDetail createGiveOthersSucceed(Long id, RedPackGiveRecord giveRecord)
            throws RedPackDetailException {
        if (giveRecord == null)
            throw new RedPackDetailException(1, "赠送记录不能为空");
        RedPackDetail detail = new RedPackDetail();
        detail.setId(id);
        detail.setDisplay(true);
        detail.setType(RedPackDetailTypeEnum.giveOthersSucceed);
        detail.setTitle(RedPackDetailTypeEnum.giveOthersSucceed.getDesc());
        detail.setIdentifyCode(
                StringUtil.Md5(RedPackDetailTypeEnum.giveOthersSucceed.name() + ":" + giveRecord.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 赠送失败
     * 
     * @param giveRecord
     * @return
     * @throws RedPackDetailException
     */
    public static RedPackDetail createGiveOthersFail(RedPackGiveRecord giveRecord) throws RedPackDetailException {
        if (giveRecord == null)
            throw new RedPackDetailException(1, "赠送记录不能为空");
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(true);
        detail.setUid(giveRecord.getGiveUid());
        detail.setMoney(giveRecord.getAmount());
        detail.setType(RedPackDetailTypeEnum.giveOthersFail);
        detail.setTitle(RedPackDetailTypeEnum.giveOthersFail.getDesc());
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.giveOthersFail.name() + ":" + giveRecord.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 赠送失败
     * 
     * @param giveRecord
     * @return
     * @throws RedPackDetailException
     */
    public static RedPackDetail createGiveOthersReceive(RedPackGiveRecord giveRecord) throws RedPackDetailException {
        if (giveRecord == null)
            throw new RedPackDetailException(1, "赠送记录不能为空");
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(true);
        detail.setUid(giveRecord.getReceiveUid());
        detail.setMoney(giveRecord.getAmount());
        detail.setType(RedPackDetailTypeEnum.giveOthersReceive);
        detail.setTitle(RedPackDetailTypeEnum.giveOthersReceive.getDesc());
        detail.setIdentifyCode(
                StringUtil.Md5(RedPackDetailTypeEnum.giveOthersReceive.name() + ":" + giveRecord.getId()));
        detail.setCreateTime(new Date());
        return detail;
    }
 
    /**
     * 
     * @param giveRecord
     * @return
     * @throws RedPackDetailException
     */
    public static RedPackDetail createUseByShopOrder(Long orderId, Long uid, String title, String setName,
            BigDecimal money) throws RedPackDetailException {
        if (orderId == null)
            throw new RedPackDetailException(1, "订单ID不能为空");
        if (uid == null)
            throw new RedPackDetailException(1, "用户ID不能为空");
        RedPackDetail detail = new RedPackDetail();
        detail.setDisplay(false);
        detail.setUid(uid);
        detail.setMoney(money);
        detail.setType(RedPackDetailTypeEnum.useByShopOrder);
        detail.setTitle(title);
        detail.setIdentifyCode(StringUtil.Md5(RedPackDetailTypeEnum.useByShopOrder.name() + "-" + orderId));
        detail.setCreateTime(new Date());
        detail.setDesc(setName);
        return detail;
    }
 
}