新版仿ok交易所-后端
1
zj
20 hours ago f31fc9f42f78de0808e7f4bdc797c5e622df09e3
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
package com.yami.trading.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.model.RealNameAuthRecord;
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.model.UserSafewordApply;
import com.yami.trading.bean.user.dto.UserSafewordApplyDto;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.constants.TipConstants;
import com.yami.trading.common.domain.BaseEntity;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.util.Strings;
import com.yami.trading.dao.user.UserSafewordApplyMapper;
import com.yami.trading.service.AwsS3OSSFileService;
import com.yami.trading.service.RealNameAuthRecordService;
import com.yami.trading.service.system.TipService;
import com.yami.trading.service.user.UserSafewordApplyService;
import com.yami.trading.service.user.UserService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.*;
 
@Service
public class UserSafewordApplyServiceImpl extends ServiceImpl<UserSafewordApplyMapper, UserSafewordApply> implements UserSafewordApplyService {
 
    @Autowired
    RealNameAuthRecordService realNameAuthRecordService;
 
    @Autowired
    UserService userService;
 
    @Autowired
    PasswordEncoder passwordEncoder;
 
    @Autowired
    TipService tipService;
 
    @Autowired
    AwsS3OSSFileService awsS3OSSFileService;
 
    public UserSafewordApply findByUserIdNoPass(String userId, int operate) {
 
        List<UserSafewordApply> list = list(Wrappers.<UserSafewordApply>query().lambda()
                .eq(UserSafewordApply::getUserId, userId)
                .eq(UserSafewordApply::getOperate, operate)
                .notIn(UserSafewordApply::getStatus, 2));
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
 
    @Override
    public Page<UserSafewordApplyDto> listRecord(Page page, String rolename, String status, String userCode, String userName, String operate) {
 
        return baseMapper.listRecord(page, rolename, status, userCode, userName, operate);
    }
 
 
 
    /**
     * 尚未通过的申请
     */
    public UserSafewordApply findByPartyIdNoPass(String partyId, Integer operate) {
        List<UserSafewordApply> list= list(Wrappers.<UserSafewordApply>query().lambda().
                eq(UserSafewordApply::getUserId,partyId).notIn(UserSafewordApply::getStatus,2).eq(UserSafewordApply::getOperate,operate));
        return CollectionUtils.isEmpty(list) ? null : list.get(0);
    }
 
    public UserSafewordApply  get(String partyId) {
        List<UserSafewordApply> list= list(Wrappers.<UserSafewordApply>query().lambda().eq(UserSafewordApply::getUserId,partyId));
        return list.size()>0?list.get(0):null;
    }
 
    @Override
    public List<UserSafewordApply> findByUserId(String userId) {
        LambdaQueryWrapper<UserSafewordApply> lambdaQueryWrapper= Wrappers.<UserSafewordApply>query().lambda().eq(UserSafewordApply::getUserId,userId);
        lambdaQueryWrapper.orderByDesc(BaseEntity::getCreateTime);
        return list(lambdaQueryWrapper);
    }
 
    public Map<String, Object> bindOne(UserSafewordApply apply) {
 
        Map<String, Object> result = new HashMap<String, Object>();
 
        String idcard_path_front_path = "";
        String idcard_path_back_path = "";
        String idcard_path_hold_path = "";
 
        if (!StringUtils.isNullOrEmpty(apply.getIdcardPathFront())) {
            idcard_path_front_path = Constants.IMAGES_HTTP+apply.getIdcardPathFront();
        }
        result.put("idcard_path_front_path", idcard_path_front_path);
 
        if (!StringUtils.isNullOrEmpty(apply.getIdcardPathBack())) {
            idcard_path_back_path =Constants.IMAGES_HTTP+apply.getIdcardPathBack();
        }
 
        result.put("idcard_path_back_path", idcard_path_back_path);
 
        if (!StringUtils.isNullOrEmpty(apply.getIdcardPathHold())) {
            idcard_path_hold_path = Constants.IMAGES_HTTP+apply.getIdcardPathHold();
        }
        result.put("idcard_path_hold_path", idcard_path_hold_path);
 
        result.put("id", apply.getUuid());
        result.put("create_time", DateUtils.format(apply.getCreateTime(), DateUtils.DF_yyyyMMddHHmmss));
        result.put("msg", apply.getMsg());
        result.put("apply_time", DateUtils.format(apply.getApplyTime(), DateUtils.DF_yyyyMMddHHmmss));
        result.put("status", apply.getStatus());
        result.put("operate", apply.getOperate());
        result.put("remark", apply.getRemark());
 
        return result;
    }
 
    /**
     * 人工重置  操作类型 operate:     0/修改资金密码;1/取消谷歌绑定;2/取消手机绑定;3/取消邮箱绑定;
     */
    public void saveApply(String partyId, String idcard_path_front, String idcard_path_back, String idcard_path_hold, String safeword,
                          String safeword_confirm, Integer operate, String remark) {
 
        if (null == operate || !Arrays.asList(0, 1, 2, 3).contains(operate)) {
            throw new YamiShopBindException("Invalid operation type");
        }
 
        // 操作类型 operate:     0/修改资金密码;
        if (0 == operate.intValue()) {
 
            if (StringUtils.isEmptyString(safeword)) {
                throw new YamiShopBindException("Fund password cannot be empty");
            }
 
            if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
                throw new YamiShopBindException("Fund password does not meet requirements");
            }
 
            if (StringUtils.isEmptyString(safeword_confirm)) {
                throw new YamiShopBindException("Fund password confirmation cannot be empty");
            }
 
            if (!safeword.equals(safeword_confirm)) {
                throw new YamiShopBindException("Fund passwords do not match");
            }
        }
//        // 操作类型 operate:     0/修改资金密码;
//        if (0 == operate.intValue()) {
        RealNameAuthRecord  kyc = realNameAuthRecordService.getByUserId(partyId);
        if (null == kyc || kyc.getStatus() != 2) {
            throw new YamiShopBindException("Identity verification not passed, cannot reset");
        }
//        }
 
        UserSafewordApply apply =findByPartyIdNoPass(partyId, operate);
        if (null == apply) {
            apply = new UserSafewordApply();
            apply.setCreateTime(new Date());
        } else if (apply.getStatus() != 3) {
            throw new YamiShopBindException("Your application has already been submitted");
        }
 
        // 操作类型 operate:     0/修改资金密码;
        if (0 == operate.intValue()) {
            String safewordMd5 = passwordEncoder.encode(safeword);
            apply.setSafeword(safewordMd5);
        } else {
            apply.setSafeword("");
        }
 
        apply.setIdcardPathFront(idcard_path_front);
        apply.setIdcardPathBack(idcard_path_back);
        apply.setIdcardPathHold(idcard_path_hold);
        apply.setOperate(operate);
        apply.setRemark(remark);
        apply.setStatus(1);
 
        if (null == apply.getUserId()) {
            apply.setUserId(partyId);
            save(apply);
        } else {
            updateById(apply);
        }
        tipService.saveTip(apply.getUuid(), TipConstants.USER_SAFEWORD_APPLY+"-"+ operate);
    }
 
 
    @Override
    @Transactional
    public void examine(String id ,String content,int type) {
        UserSafewordApply apply = getById(id);
        if (null == apply) {
            throw new YamiShopBindException("Application does not exist, please refresh and try again");
        }
        RealNameAuthRecord kyc = realNameAuthRecordService.getByUserId(apply.getUserId());
        if (null == kyc || kyc.getStatus() != 2) {
            throw new YamiShopBindException("Verification not passed, cannot reset");
        }
//        if (apply.getStatus()!=2){
//            throw new YamiShopBindException("Record already processed");
//        }
        apply.setApplyTime(new Date());
        if (type==1){
            apply.setStatus(2);
            User user = userService.getById(apply.getUserId());
            // 操作类型 operate:     0/修改资金密码;1/取消谷歌绑定;2/取消手机绑定;3/取消邮箱绑定;
            switch (apply.getOperate()) {
                case 0:
                    user.setSafePassword(apply.getSafeword());
                    break;
                case 1:
//                    if (!user.isGoogleAuthBind()) {
//                        throw new YamiShopBindException("User is not bound, no need to unbind");
//                    }
                    user.setGoogleAuthBind(false);
                case 2:
                    user.setUserMobileBind(false);
                    break;
                case 3:
                    user.setMailBind(false);
                    break;
            }
            userService.updateById(user);
        }
        else {
            apply.setStatus(3);
            apply.setMsg(content);
        }
        updateById(apply);
        tipService.deleteTip(apply.getUuid());
 
    }
 
}