zyy
2025-12-06 ab7e92d5154b5acf05699bd527c4d8b5fff10550
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
package com.yami.trading.api.controller;
 
import cn.hutool.core.util.StrUtil;
import com.yami.trading.admin.facade.MachineTranslationService;
import com.yami.trading.api.dto.RealNameAuthRecordDto;
import com.yami.trading.api.model.ApplyRealNameAuthModel;
import com.yami.trading.api.service.UserCacheService;
import com.yami.trading.bean.model.RealNameAuthRecord;
import com.yami.trading.bean.model.User;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.constants.TipConstants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.service.AwsS3OSSFileService;
import com.yami.trading.service.IdentifyingCodeTimeWindowService;
import com.yami.trading.service.RealNameAuthRecordService;
import com.yami.trading.service.system.TipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
@RestController
@CrossOrigin
@RequestMapping("api/realNameAuth")
@Api(tags = "安全认证")
public class ApiRealNameAuthContoller {
    @Autowired
    RealNameAuthRecordService realNameAuthRecordService;
    @Autowired
    UserCacheService userCacheService;
    @Autowired
    TipService tipService;
    @Autowired
    AwsS3OSSFileService awsS3OSSFileService;
    @Autowired
     MachineTranslationService translationService;
 
    @Autowired
    IdentifyingCodeTimeWindowService identifyingCodeTimeWindowService;
 
    @PostMapping("/apply")
    @ApiOperation(value = "实名认证申请")
    public Result<User> applyRealNameAuth(@Valid ApplyRealNameAuthModel model) {
 
        User user = userCacheService.currentUser();
        RealNameAuthRecord realNameAuthRecord = realNameAuthRecordService.getByUserId(user.getUserId());
        String msg="";
        if (realNameAuthRecord != null) {
            switch (realNameAuthRecord.getStatus()) {
                case 0:
                    msg = "已经提交申请,请等待审核";
                    break;
                case 1:
                    msg = "审核中";
                    break;
                case 2:
                    msg = "审核已通过";
                    break;
                case 3:
                    realNameAuthRecord.setStatus(1);
                    tipService.deleteTip(realNameAuthRecord.getUuid());
                    realNameAuthRecordService.removeById(realNameAuthRecord.getUuid());
                    realNameAuthRecord=null;
            }
            if (StrUtil.isNotBlank(msg)) {
                throw new YamiShopBindException(msg);
            }
        }
        if (realNameAuthRecord == null) {
            realNameAuthRecord = new RealNameAuthRecord();
        }
 
        if (model.getIdBackImg() == null || model.getIdBackImg().isEmpty()) {
            throw new YamiShopBindException("请上传完整证件信息");
        }
        if (model.getIdFrontImg() == null || model.getIdFrontImg().isEmpty()) {
            throw new YamiShopBindException("请上传完整证件信息");
        }
 
        if (model.getIdNumber().length() > 50) {
            throw new YamiShopBindException("证件号码长度超过50");
        }
        if (model.getName().length()  >50) {
            throw new YamiShopBindException("实名姓名长度超过50");
        }
        if (model.getPhone() == null || model.getPhone().isEmpty()) {
            throw new YamiShopBindException("请输入手机号");
        }
 
        /*String authcode = identifyingCodeTimeWindowService.getAuthCode(model.getPhone());
        if (authcode == null || !authcode.equals(model.getCode())) {
            throw new YamiShopBindException("验证码不正确");
        }*/
 
        Date now = new Date();
        BeanUtils.copyProperties(model, realNameAuthRecord);
        realNameAuthRecord.setUserId(user.getUserId());
        realNameAuthRecord.setCreateTime(now);
        realNameAuthRecord.setUpdateTime(now);
        realNameAuthRecord.setCreateTimeTs(now.getTime() / 1000L);
        realNameAuthRecord.setUpdateTimeTs(now.getTime() / 1000L);
        realNameAuthRecord.setStatus(1);
        realNameAuthRecord.setPhone(model.getPhone());
        realNameAuthRecordService.saveOrUpdate(realNameAuthRecord);
 
        if (Constants.SECURITY_ROLE_MEMBER.equals(user.getRoleName())) {
            tipService.saveTip(realNameAuthRecord.getUuid(), TipConstants.KYC, realNameAuthRecord.getUserId());
        }
 
        return Result.succeed();
    }
 
    @ApiOperation(value = "获取认证信息")
    @GetMapping("get")
    public Result get() {
        User user = userCacheService.currentUser();
        RealNameAuthRecord record = realNameAuthRecordService.getByUserId(user.getUserId());
        if (record == null) {
            return Result.succeed(new RealNameAuthRecordDto());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("id", record.getUuid());
 
        map.put("nationality", record.getNationality());
        map.put("idName", record.getIdName());
        map.put("idNumber", record.getIdNumber());
        map.put("name", record.getName());
        map.put("idFrontImg", record.getIdFrontImg());
        map.put("idBackImg", record.getIdBackImg());
        map.put("status", record.getStatus());
        map.put("kyc_status", record.getStatus());
        map.put("msg", record.getMsg());
        map.put("handheldPhoto", record.getHandheldPhoto());
        map.put("idname", record.getIdName());
        map.put("idnumber", record.getIdNumber());
        map.put("idimg_1_path", Constants.IMAGES_HTTP+record.getIdFrontImg());
        map.put("idimg_2_path", Constants.IMAGES_HTTP+record.getIdBackImg());
        map.put("idimg_3_path", Constants.IMAGES_HTTP+record.getHandheldPhoto());
        map.put("idimg_1", record.getIdFrontImg());
        map.put("idimg_2", record.getIdBackImg());
        map.put("idimg_3", record.getHandheldPhoto());
        map.put("phone", record.getPhone());
        return Result.succeed(map);
    }
 
}