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;
|
}
|
}
|