admin
2019-10-10 e19ce4be094d93f68bdb6ee1c28e9caa502bf2c4
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
package com.yeshi.fanli.service.impl.order.tb;
 
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoPunishOrderMapper;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserExtraTaoBaoInfo;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.taobao.TaoBaoPunishOrder;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.tb.TaoBaoPunishOrderService;
import com.yeshi.fanli.service.inter.user.UserAccountService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.tb.UserExtraTaoBaoInfoService;
import com.yeshi.fanli.util.Constant;
 
@Service
public class TaoBaoPunishOrderServiceImpl implements TaoBaoPunishOrderService {
 
    @Resource
    private TaoBaoPunishOrderMapper taoBaoPunishOrderMapper;
 
    @Resource
    private HongBaoV2Service hongBaoV2Service;
 
    @Resource
    private HongBaoOrderService hongBaoOrderService;
 
    @Resource
    private CommonOrderService commonOrderService;
 
    @Resource
    private UserExtraTaoBaoInfoService userExtraTaoBaoInfoService;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserAccountService userAccountService;
 
    @Transactional
    @Override
    public void doPunishOrder(TaoBaoPunishOrder order, Set<Long> uidSets) {
        if (order == null)
            return;
        // 首先保存
        if (taoBaoPunishOrderMapper.selectByTradeId(order.getTbTradeId()) == null)
            savePunishOrder(order);
        // 然后
        CommonOrder co = commonOrderService.selectBySourceTypeAndTradeId(Constant.SOURCE_TYPE_TAOBAO,
                order.getTbTradeId());
        if (co != null) {
            uidSets.add(co.getUserInfo().getId());
            HongBaoOrder hongBaoOder = hongBaoOrderService.selectDetailByCommonOrderId(co.getId());
            if (hongBaoOder.getHongBaoV2() != null
                    && (hongBaoOder.getHongBaoV2().getState() == HongBaoV2.STATE_BUKELINGQU
                            || hongBaoOder.getHongBaoV2().getState() == HongBaoV2.STATE_KELINGQU)) {
                HongBaoV2 updateHongBao = new HongBaoV2(hongBaoOder.getHongBaoV2().getId());
                updateHongBao.setUpdateTime(new Date());
                updateHongBao.setState(HongBaoV2.STATE_SHIXIAO);
                updateHongBao.setBeizhu("联盟违规");
                hongBaoV2Service.updateByPrimaryKeySelective(updateHongBao);
                // 查询是否有子红包
                List<HongBaoV2> childList = hongBaoV2Service.listChildrenById(hongBaoOder.getHongBaoV2().getId());
                for (HongBaoV2 child : childList) {
                    if ((child.getState() == HongBaoV2.STATE_BUKELINGQU
                            || child.getState() == HongBaoV2.STATE_KELINGQU)) {
                        HongBaoV2 update = new HongBaoV2(child.getId());
                        update.setUpdateTime(new Date());
                        update.setState(HongBaoV2.STATE_SHIXIAO);
                        update.setBeizhu("联盟违规");
                        hongBaoV2Service.updateByPrimaryKeySelective(update);
                    }
                }
            } else if (hongBaoOder.getHongBaoV2() != null
                    && hongBaoOder.getHongBaoV2().getState() == HongBaoV2.STATE_YILINGQU) {
                List<HongBaoV2> childList = hongBaoV2Service.listChildrenById(hongBaoOder.getHongBaoV2().getId());
                for (HongBaoV2 child : childList) {
                    if ((child.getState() == HongBaoV2.STATE_BUKELINGQU
                            || child.getState() == HongBaoV2.STATE_KELINGQU)) {
                        //未到账的子红包也需要失效
                        HongBaoV2 update = new HongBaoV2(child.getId());
                        update.setUpdateTime(new Date());
                        update.setState(HongBaoV2.STATE_SHIXIAO);
                        update.setBeizhu("联盟违规");
                        hongBaoV2Service.updateByPrimaryKeySelective(update);
                    }
                }
            }
        }
    }
 
    @Transactional
    @Override
    public void savePunishOrder(TaoBaoPunishOrder order) {
        if (order == null)
            return;
        TaoBaoPunishOrder old = taoBaoPunishOrderMapper.selectByTradeId(order.getTbTradeId());
        if (old == null) {
            if (order.getCreateTime() == null)
                order.setCreateTime(new Date());
        }
        taoBaoPunishOrderMapper.insertSelective(order);
    }
 
    @Override
    public void doPunishOrder(List<TaoBaoPunishOrder> orderList) {
        Set<String> relationIdSets = new HashSet<>();
        Set<String> specialIdSets = new HashSet<>();
        Set<Long> uidSets = new HashSet<>();
 
        // for (TaoBaoPunishOrder order : orderList) {
        // if (!StringUtil.isNullOrEmpty(order.getRelationId()))
        // relationIdSets.add(order.getRelationId());
        //
        // if (!StringUtil.isNullOrEmpty(order.getSpecialId()))
        // specialIdSets.add(order.getSpecialId());
        //
        // doPunishOrder(order, uidSets);
        // }
 
        for (Iterator<String> its = relationIdSets.iterator(); its.hasNext();) {
            String relationId = its.next();
            UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getByRelationId(relationId);
            if (info != null && info.getUser() != null)
                uidSets.add(info.getUser().getId());
        }
 
        for (Iterator<String> its = specialIdSets.iterator(); its.hasNext();) {
            String specialId = its.next();
            UserExtraTaoBaoInfo info = userExtraTaoBaoInfoService.getBySpecialId(specialId);
            if (info != null && info.getUser() != null)
                uidSets.add(info.getUser().getId());
        }
        // 封禁用户
 
        for (Iterator<Long> its = uidSets.iterator(); its.hasNext();) {
            Long uid = its.next();
            userAccountService.forbiddenUserAll(uid, "产生违规订单自动封禁");
        }
 
    }
 
    @Override
    public int countByTradeParentId(String orderId) {
        return (int) (taoBaoPunishOrderMapper.countByParentTradeId(orderId));
    }
 
}