doum
3 天以前 7ec3683c8e41460f4bb0bd3a6677198742313e2b
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
package com.doumee.cloud.web;
 
import com.doumee.api.BaseController;
import com.doumee.config.annotation.LoginNoRequired;
import com.doumee.core.annotation.pr.PreventRepeat;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.ApiResponse;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.utils.Constants;
import com.doumee.dao.system.dto.LoginPhoneDTO;
import com.doumee.service.business.YwCustomerH5AuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
@Api(tags = "【公众号】商户登录")
@RestController
@LoginNoRequired
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX + "/web/customer")
public class YwCustomerWebController extends BaseController {
 
    @Autowired
    private YwCustomerH5AuthService ywCustomerH5AuthService;
 
    @PreventRepeat
    @ApiOperation("商户短信验证码登录")
    @PostMapping("/loginByPhone")
    public ApiResponse<String> loginByPhone(@Validated @RequestBody LoginPhoneDTO dto) {
        try {
            return ApiResponse.success(ywCustomerH5AuthService.loginByPhone(dto));
        } catch (BusinessException e) {
            return ApiResponse.failed(e.getCode(), e.getMessage());
        } catch (Exception e) {
            return ApiResponse.failed(ResponseStatus.SERVER_ERROR);
        }
    }
 
    @ApiOperation("获取当前商户登录信息")
    @GetMapping("/getUserInfo")
    public ApiResponse<LoginUserInfo> getUserInfo(@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
        LoginUserInfo user = this.getLoginUser(token);
        if (user == null || !Constants.equalsInteger(user.getH5UserType(), LoginUserInfo.H5_USER_CUSTOMER)) {
            return ApiResponse.failed("登录已失效");
        }
        return ApiResponse.success(ywCustomerH5AuthService.buildLoginUserInfo(user.getCustomerId()));
    }
}