zjk
昨天 f8c73a38709f7120d11b04bd70c6af3ccc53014d
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
package com.ruoyi.user.controller;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.system.api.domain.AccountMember;
import com.ruoyi.system.api.model.AccountRegisterRequest;
import com.ruoyi.user.domain.AccountUser;
import com.ruoyi.user.service.IAccountUserService;
 
/**
 * C端会员 内部接口(仅服务间调用)
 *
 * 供认证服务(ruoyi-auth)在 C 端手机号一键登录 / 注册流程中调用,
 * 通过 @InnerAuth 限制仅内部来源(from-source=inner)可访问。
 *
 * @author hugray
 */
@RestController
@RequestMapping("/member")
public class AccountMemberInnerController
{
    @Autowired
    private IAccountUserService accountUserService;
 
    /**
     * 按手机号查询C端会员
     *
     * @param phone 手机号
     * @return 会员信息(不存在时 data 为空)
     */
    @InnerAuth
    @GetMapping("/info/{phone}")
    public R<AccountMember> info(@PathVariable("phone") String phone)
    {
        AccountUser accountUser = accountUserService.selectAccountUserByPhone(phone);
        if (StringUtils.isNull(accountUser))
        {
            return R.ok();
        }
        return R.ok(toAccountMember(accountUser));
    }
 
    /**
     * 注册C端会员
     *
     * @param request 注册请求(手机号、推荐码)
     * @return 注册成功后的会员信息
     */
    @InnerAuth
    @PostMapping("/register")
    public R<AccountMember> register(@Validated @RequestBody AccountRegisterRequest request)
    {
        AccountUser accountUser = accountUserService.registerMember(request.getPhone(), request.getReferralCode());
        return R.ok(toAccountMember(accountUser));
    }
 
    /**
     * 会员实体转换为跨服务契约对象
     */
    private AccountMember toAccountMember(AccountUser accountUser)
    {
        AccountMember member = new AccountMember();
        member.setUserId(accountUser.getUserId());
        member.setUserName(accountUser.getUserName());
        member.setPhone(accountUser.getPhone());
        member.setNickname(accountUser.getNickname());
        member.setAvatar(accountUser.getAvatar());
        member.setMyReferralCode(accountUser.getMyReferralCode());
        member.setReferrerId(accountUser.getReferrerId());
        member.setStatus(accountUser.getStatus());
        return member;
    }
}