admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
package com.yeshi.fanli.job;
 
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Component;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.yeshi.fanli.dto.user.PullNewRuleTerm;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
import com.yeshi.fanli.service.inter.redpack.RedPackWinInviteService;
import com.yeshi.fanli.util.StringUtil;
 
@Component
public class RedPackJob {
 
    @Resource
    private RedPackWinInviteService redPackWinInviteService;
    
    @Resource
    private RedPackConfigService redPackConfigService;
    
    
    
    @XxlJob("RedPackJob-arriveMoney")
    public ReturnT<String> arriveMoney(String param) throws Exception {
        arriveMoney();
        return ReturnT.SUCCESS;
    }
    
    /**
     * 红包每月26到账
     */
    public void arriveMoney() {
        try {
            String value = redPackConfigService.getValueByKey("win_redpack_term");
            if (StringUtil.isNullOrEmpty(value)) {
                return;
            }
            
            Type type = new TypeToken<ArrayList<PullNewRuleTerm>>() {
            }.getType();
            List<PullNewRuleTerm> listRule = new Gson().fromJson(value, type);
            if (listRule == null || listRule.size() == 0) {
                return;
            }
            
            int start = 0;
            Date date = new Date();
            while(true) {
                // 上月存在邀请的用用户id
                List<Long> list = redPackWinInviteService.listWinUid(start, 1000);
                if (list == null || list.size() == 0) {
                    break;
                }
                
                for (Long uid: list) {
                    // 统计上月邀请成功数量
                    long count = redPackWinInviteService.countLastMonthByUid(uid);
                    if (count == 0)
                        continue;
                    
                    BigDecimal money = null;
                    for (PullNewRuleTerm term: listRule) {
                        if (count >= term.getMin() && (term.getMax() != null && count <= term.getMax())) {
                            money = term.getMoney();
                        }
                    }
                    
                    if (money == null) {
                        LogHelper.test("红包奖励未匹配到规则count =" + count + " uid =" + uid);
                        continue;
                    }
                    
                    try {
                        redPackWinInviteService.arriveMoney(uid, money, date);
                    } catch (Exception e) {
                        LogHelper.errorDetailInfo(e);
                    }
                }
            }
        } catch (Exception e) {
            LogHelper.errorDetailInfo(e);
        }
    }
     
}