admin
2019-07-15 be44007f1ffdd4d391fd360dce24a3423e37bcc6
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
package com.yeshi.fanli.util.factory;
 
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
 
import com.yeshi.fanli.dto.HongBao;
import com.yeshi.fanli.entity.bus.user.AlipayAccountValidNormalHistory;
import com.yeshi.fanli.entity.bus.user.Extract;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.money.UserMoneyDetail;
import com.yeshi.fanli.entity.money.UserMoneyDetail.UserMoneyDetailTypeEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanDrawBack;
import com.yeshi.fanli.exception.money.UserMoneyDetailException;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.TimeUtil;
 
public class UserMoneyDetailFactory {
 
    /**
     * 返利资金记录
     * 
     * @param hongBaoList
     * @return
     */
    public static UserMoneyDetail createFanLi(Long uid, String orderId, int orderType, String hbIds, BigDecimal money)
            throws UserMoneyDetailException {
 
        if (StringUtil.isNullOrEmpty(orderId))
            throw new UserMoneyDetailException(1, "订单号为空");
 
        if (money == null)
            throw new UserMoneyDetailException(1, "返利金额为空");
 
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil
                .Md5(UserMoneyDetailTypeEnum.fanli.name() + "-" + uid + "-" + orderType + "-" + orderId + "-" + hbIds));
        detail.setMoney(money);
        detail.setTitle(UserMoneyDetailTypeEnum.fanli.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.fanli);
        detail.setDescInfo("订单号:" + orderId);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 分享奖金到账
     * 
     * @param uid
     * @param validCount
     * @param weiQuanCount
     * @param invalidCount
     * @param money
     * @param time
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createShare(Long uid, int validCount, int weiQuanCount, int invalidCount,
            BigDecimal money, Date time) throws UserMoneyDetailException {
        if (money == null)
            throw new UserMoneyDetailException(1, "返利金额为空");
 
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        if (time == null)
            throw new UserMoneyDetailException(1, "发生时间为空");
 
        Calendar ca = Calendar.getInstance();
        ca.setTime(time);
        ca.add(Calendar.MONTH, -1);
 
        String timeF = TimeUtil.getGernalTime(ca.getTimeInMillis(), "yyyy年MM月");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.share.name() + "-" + uid + "-" + timeF));
        detail.setMoney(money);
        detail.setTitle(timeF + UserMoneyDetailTypeEnum.share.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.share);
        detail.setDescInfo(String.format("有效订单:%s笔  维权订单:%s笔  失效订单:%s笔", validCount, weiQuanCount, invalidCount));
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 邀请奖金到账
     * 
     * @param uid
     * @param validCount
     * @param weiQuanCount
     * @param invalidCount
     * @param money
     * @param time
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createInvite(Long uid, int validCount, int weiQuanCount, int invalidCount,
            BigDecimal money, Date time) throws UserMoneyDetailException {
        if (money == null)
            throw new UserMoneyDetailException(1, "返利金额为空");
 
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        if (time == null)
            throw new UserMoneyDetailException(1, "发生时间为空");
 
        Calendar ca = Calendar.getInstance();
        ca.setTime(time);
        ca.add(Calendar.MONTH, -1);
 
        String timeF = TimeUtil.getGernalTime(ca.getTimeInMillis(), "yyyy年MM月");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.invite.name() + "-" + uid + "-" + timeF));
        detail.setMoney(money);
        detail.setTitle(timeF + UserMoneyDetailTypeEnum.invite.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.invite);
        if (validCount != 0 || weiQuanCount != 0 || invalidCount != 0)
            detail.setDescInfo(String.format("有效订单:%s笔   维权订单:%s笔   失效订单:%s笔", validCount, weiQuanCount, invalidCount));
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 返利维权
     * 
     * @param uid
     * @param drawBack
     * @param money
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createFanLiWeiQuan(Long uid, TaoBaoWeiQuanDrawBack drawBack, BigDecimal money)
            throws UserMoneyDetailException {
        if (drawBack == null)
            throw new UserMoneyDetailException(1, "退款为空");
        if (drawBack.getId() == null)
            throw new UserMoneyDetailException(1, "退款ID为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderId()))
            throw new UserMoneyDetailException(1, "订单号为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderItemId()))
            throw new UserMoneyDetailException(1, "子订单号为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "退款金额为空");
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil
                .Md5(UserMoneyDetailTypeEnum.fanliWeiQuan.name() + "-" + uid + "-" + drawBack.getOrderItemId()));
        detail.setMoney(new BigDecimal("0").subtract(money));
        detail.setTitle(UserMoneyDetailTypeEnum.fanliWeiQuan.getDesc());
        detail.setSubTitle("订单维权");
        detail.setType(UserMoneyDetailTypeEnum.fanliWeiQuan);
        detail.setSourceIdentifyId(drawBack.getId());
        detail.setDescInfo("订单号:" + drawBack.getOrderId());
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 分享赚维权
     * 
     * @param uid
     * @param drawBack
     * @param money
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createShareWeiQuan(Long uid, TaoBaoWeiQuanDrawBack drawBack, BigDecimal money)
            throws UserMoneyDetailException {
        if (drawBack == null)
            throw new UserMoneyDetailException(1, "退款为空");
        if (drawBack.getId() == null)
            throw new UserMoneyDetailException(1, "退款ID为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderId()))
            throw new UserMoneyDetailException(1, "订单号为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderItemId()))
            throw new UserMoneyDetailException(1, "子订单号为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "退款金额为空");
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil
                .Md5(UserMoneyDetailTypeEnum.shareWeiQuan.name() + "-" + uid + "-" + drawBack.getOrderItemId()));
        detail.setMoney(new BigDecimal("0").subtract(money));
        detail.setTitle(UserMoneyDetailTypeEnum.shareWeiQuan.getDesc());
        detail.setSubTitle("订单维权");
        detail.setType(UserMoneyDetailTypeEnum.shareWeiQuan);
        detail.setSourceIdentifyId(drawBack.getId());
        detail.setDescInfo("订单号:" + drawBack.getOrderId());
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 邀请赚维权
     * 
     * @param uid
     * @param drawBack
     * @param money
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createInviteWeiQuan(Long uid, TaoBaoWeiQuanDrawBack drawBack, BigDecimal money)
            throws UserMoneyDetailException {
        if (drawBack == null)
            throw new UserMoneyDetailException(1, "退款为空");
        if (drawBack.getId() == null)
            throw new UserMoneyDetailException(1, "退款ID为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderId()))
            throw new UserMoneyDetailException(1, "订单号为空");
        if (StringUtil.isNullOrEmpty(drawBack.getOrderItemId()))
            throw new UserMoneyDetailException(1, "子订单号为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "退款金额为空");
        if (uid == null)
            throw new UserMoneyDetailException(1, "UID为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil
                .Md5(UserMoneyDetailTypeEnum.inviteWeiQuan.name() + "-" + uid + "-" + drawBack.getOrderItemId()));
        detail.setMoney(new BigDecimal("0").subtract(money));
        detail.setTitle(UserMoneyDetailTypeEnum.inviteWeiQuan.getDesc());
        detail.setSubTitle("订单维权");
        detail.setType(UserMoneyDetailTypeEnum.inviteWeiQuan);
        detail.setSourceIdentifyId(drawBack.getId());
        detail.setDescInfo("订单号:" + drawBack.getOrderId());
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(uid));
        return detail;
    }
 
    /**
     * 提现资金记录
     * 
     * @param extract
     * @return
     */
    public static UserMoneyDetail createExtract(Extract extract) throws UserMoneyDetailException {
        if (extract == null)
            throw new UserMoneyDetailException(1, "提现记录不能为空");
        if (extract.getId() == null)
            throw new UserMoneyDetailException(1, "提现记录主键不能为空");
        if (extract.getMoney() == null)
            throw new UserMoneyDetailException(1, "提现金额不能为空");
        if (extract.getUserInfo() == null || extract.getUserInfo().getId() == null)
            throw new UserMoneyDetailException(1, "提现用户不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.extract.name() + ":" + extract.getId()));
        detail.setMoney(new BigDecimal("0").subtract(extract.getMoney()));
        detail.setSourceIdentifyId(extract.getId());
        detail.setTitle(UserMoneyDetailTypeEnum.extract.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.extract);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(extract.getUserInfo());
        return detail;
    }
 
    /**
     * 提现账号验证记录
     * 
     * @param aa
     * @param money
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createExtractAccountValid(AlipayAccountValidNormalHistory aa, BigDecimal money)
            throws UserMoneyDetailException {
        if (aa == null)
            throw new UserMoneyDetailException(1, "验证记录不能为空");
        if (aa.getUid() == null)
            throw new UserMoneyDetailException(1, "UID不能为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "金额不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.extractVerify.name() + ":" + aa.getId()));
        detail.setMoney(new BigDecimal("0").subtract(money));
        detail.setSourceIdentifyId(aa.getId());
        detail.setTitle(UserMoneyDetailTypeEnum.extractVerify.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.extractVerify);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(new UserInfo(aa.getUid()));
        return detail;
    }
 
    /**
     * 提现拒绝
     * 
     * @param extract
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createExtractReject(Extract extract) throws UserMoneyDetailException {
        if (extract == null)
            throw new UserMoneyDetailException(1, "提现记录不能为空");
        if (extract.getId() == null)
            throw new UserMoneyDetailException(1, "提现记录主键不能为空");
        if (extract.getMoney() == null)
            throw new UserMoneyDetailException(1, "提现金额不能为空");
        if (extract.getUserInfo() == null || extract.getUserInfo().getId() == null)
            throw new UserMoneyDetailException(1, "提现用户不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.extractReject.name() + ":" + extract.getId()));
        detail.setMoney(extract.getMoney());
        detail.setSourceIdentifyId(extract.getId());
        detail.setSubTitle("原路退回");
        detail.setTitle(UserMoneyDetailTypeEnum.extractReject.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.extractReject);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(extract.getUserInfo());
        return detail;
    }
 
    /**
     * 系统红包
     * 
     * @param hb
     * @return
     * @throws UserMoneyDetailException
     */
 
    private static UserMoneyDetail createHongBao(HongBao hb, String subTitle) throws UserMoneyDetailException {
        if (hb == null)
            throw new UserMoneyDetailException(1, "红包不能为空");
        if (hb.getUserInfo() == null)
            throw new UserMoneyDetailException(1, "用户不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(
                StringUtil.Md5(UserMoneyDetailTypeEnum.hongbao.name() + "-" + subTitle + "-" + hb.getId()));
        detail.setMoney(hb.getMoney());
        detail.setSourceIdentifyId(hb.getId());
        detail.setTitle(UserMoneyDetailTypeEnum.hongbao.getDesc());
        detail.setSubTitle(subTitle);
        detail.setType(UserMoneyDetailTypeEnum.hongbao);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(hb.getUserInfo());
        return detail;
    }
 
    private static UserMoneyDetail createHongBaoDeduct(HongBao hb, String subTitle) throws UserMoneyDetailException {
        if (hb == null)
            throw new UserMoneyDetailException(1, "红包不能为空");
        if (hb.getUserInfo() == null)
            throw new UserMoneyDetailException(1, "用户不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.hongbaoDeduct.name() + "-" + subTitle + "-"
                + hb.getBeizhu() + "-" + hb.getId()));
        detail.setMoney(hb.getMoney());
        detail.setSourceIdentifyId(hb.getId());
        detail.setTitle(UserMoneyDetailTypeEnum.hongbaoDeduct.getDesc());
        detail.setSubTitle(subTitle);
        detail.setType(UserMoneyDetailTypeEnum.hongbaoDeduct);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(hb.getUserInfo());
        return detail;
    }
 
    /**
     * 新人红包
     * 
     * @param hb
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createNewerHongBao(HongBao hb) throws UserMoneyDetailException {
        return createHongBao(hb, "新人红包");
    }
 
    /**
     * 新人红包扣除
     * 
     * @param hb
     * @return
     * @throws UserMoneyDetailException
     */
 
    public static UserMoneyDetail createNewerHongBaoDeduct(HongBao hb) throws UserMoneyDetailException {
        return createHongBaoDeduct(hb, "新人红包扣除");
    }
 
    /**
     * 返利奖励
     * 
     * @param orderId
     * @param money
     * @param user
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createOrderReward(String orderId, BigDecimal money, UserInfo user)
            throws UserMoneyDetailException {
        if (StringUtil.isNullOrEmpty(orderId))
            throw new UserMoneyDetailException(1, "订单号不能为空");
        if (user == null)
            throw new UserMoneyDetailException(1, "UID不能为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "金额不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(UserMoneyDetailTypeEnum.hongbao.name() + "-" + "老版本" + "-" + orderId));
        detail.setMoney(money);
        detail.setTitle(UserMoneyDetailTypeEnum.orderReward.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.orderReward);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(user);
        // detail.setDescInfo("订单号:" + orderId);
        return detail;
    }
 
    /**
     * 订单重复统计退款
     * 
     * @param orderId
     * @param money
     * @param user
     * @return
     * @throws UserMoneyDetailException
     */
    public static UserMoneyDetail createRepeatStatistic(String orderId, BigDecimal money, UserInfo user)
            throws UserMoneyDetailException {
        if (StringUtil.isNullOrEmpty(orderId))
            throw new UserMoneyDetailException(1, "订单号不能为空");
        if (user == null)
            throw new UserMoneyDetailException(1, "UID不能为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "金额不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(
                StringUtil.Md5(UserMoneyDetailTypeEnum.repeatStatistic.name() + "-" + orderId + "-" + user.getId()));
        detail.setMoney(money);
        detail.setTitle(UserMoneyDetailTypeEnum.repeatStatistic.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.repeatStatistic);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(user);
        detail.setDescInfo("订单号:" + orderId);
        return detail;
    }
 
    public static UserMoneyDetail createSystemEqualize(String desc, BigDecimal money, UserInfo user)
            throws UserMoneyDetailException {
        if (user == null)
            throw new UserMoneyDetailException(1, "UID不能为空");
        if (money == null)
            throw new UserMoneyDetailException(1, "金额不能为空");
 
        UserMoneyDetail detail = new UserMoneyDetail();
        detail.setCreateTime(new Date());
        detail.setIdentifyCode(StringUtil.Md5(
                UserMoneyDetailTypeEnum.systemEqualize.name() + "-" + System.currentTimeMillis() + "-" + user.getId()));
        detail.setMoney(money);
        detail.setTitle(UserMoneyDetailTypeEnum.systemEqualize.getDesc());
        detail.setType(UserMoneyDetailTypeEnum.systemEqualize);
        detail.setUpdateTime(new Date());
        detail.setUserInfo(user);
        if (!StringUtil.isNullOrEmpty(desc)) {
            detail.setDescInfo(desc);
        }
        return detail;
    }
 
}