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.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.dao.business.dto.YwCustomerRechargeRecordVO;
|
import com.doumee.dao.business.dto.h5.*;
|
import com.doumee.dao.business.model.YwContract;
|
import com.doumee.dao.business.model.YwContractBill;
|
import com.doumee.dao.business.model.YwH5Banner;
|
import com.doumee.dao.business.model.YwWxPayOrder;
|
import com.doumee.dao.system.dto.LoginPhoneDTO;
|
import com.doumee.service.business.SmsEmailService;
|
import com.doumee.service.business.YwCustomerH5AuthService;
|
import com.doumee.service.business.YwCustomerH5BizService;
|
import com.doumee.service.business.YwCustomerWxPayService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.List;
|
import java.util.Map;
|
|
@Api(tags = "【公众号】商户H5")
|
@RestController
|
@Slf4j
|
@RequestMapping(Constants.CLOUD_SERVICE_URL_INDEX + "/web/customer")
|
public class YwCustomerH5Controller extends BaseController {
|
|
@Autowired
|
private YwCustomerH5BizService ywCustomerH5BizService;
|
@Autowired
|
private YwCustomerWxPayService ywCustomerWxPayService;
|
@Autowired
|
private YwCustomerH5AuthService ywCustomerH5AuthService;
|
@Autowired
|
private SmsEmailService smsEmailService;
|
|
private LoginUserInfo requireCustomerUser(String token) {
|
LoginUserInfo user = getLoginUser(token);
|
if (user == null || !Constants.equalsInteger(user.getH5UserType(), LoginUserInfo.H5_USER_CUSTOMER)) {
|
throw new RuntimeException("登录已失效");
|
}
|
return user;
|
}
|
|
@LoginNoRequired
|
@PreventRepeat
|
@ApiOperation("商户登录发送验证码")
|
@PostMapping("/sendLoginSms")
|
public ApiResponse<Integer> sendLoginSms(@RequestBody(required = false) LoginPhoneDTO dto) {
|
try {
|
if (dto == null || StringUtils.isBlank(dto.getPhone())) {
|
return ApiResponse.failed(ResponseStatus.BAD_REQUEST.getCode(), "手机号不能为空");
|
}
|
return ApiResponse.success(smsEmailService.sendMerchantLoginSms(dto.getPhone().trim()));
|
} catch (BusinessException e) {
|
return ApiResponse.failed(e.getCode(), e.getMessage());
|
} catch (Throwable e) {
|
log.error("sendLoginSms failed", e);
|
return ApiResponse.failed(ResponseStatus.SERVER_ERROR.getCode(), "发送验证码失败,请稍后重试");
|
}
|
}
|
|
@LoginNoRequired
|
@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(), user.getMemberId()));
|
}
|
|
@ApiOperation("商户退出登录")
|
@PostMapping("/logout")
|
public ApiResponse<String> logout(@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
try {
|
LoginUserInfo user = requireCustomerUser(token);
|
ywCustomerH5AuthService.logout(user, token);
|
return ApiResponse.success("退出成功");
|
} catch (Exception e) {
|
log.error("customer logout failed", e);
|
return ApiResponse.failed(ResponseStatus.SERVER_ERROR.getCode(), "退出失败");
|
}
|
}
|
|
@ApiOperation("工作台轮播图")
|
@GetMapping("/banners")
|
@LoginNoRequired
|
public ApiResponse<List<YwH5Banner>> banners() {
|
return ApiResponse.success(ywCustomerH5BizService.listBanners());
|
}
|
|
@ApiOperation("工作台首页")
|
@GetMapping("/home")
|
public ApiResponse<Map<String, Object>> home(@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.home(user.getCustomerId(), user.getMemberId()));
|
}
|
|
@ApiOperation("交电费设备列表")
|
@PostMapping("/device/page")
|
public ApiResponse<PageData<CustomerDeviceH5VO>> devicePage(
|
@RequestBody PageWrap<CustomerDeviceQueryDTO> pageWrap,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.devicePage(pageWrap, user.getCustomerId()));
|
}
|
|
@ApiOperation("设备详情")
|
@GetMapping("/device/detail")
|
public ApiResponse<CustomerDeviceH5VO> deviceDetail(
|
@RequestParam Integer deviceType,
|
@RequestParam Integer deviceId,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.deviceDetail(deviceType, deviceId, user.getCustomerId()));
|
}
|
|
@ApiOperation("充值记录")
|
@PostMapping("/rechargeRecord/page")
|
public ApiResponse<PageData<YwCustomerRechargeRecordVO>> rechargeRecordPage(
|
@RequestBody PageWrap<CustomerRechargeRecordH5QueryDTO> pageWrap,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.rechargeRecordPage(pageWrap, user.getCustomerId()));
|
}
|
|
@ApiOperation("合同列表")
|
@PostMapping("/contract/page")
|
public ApiResponse<PageData<YwContract>> contractPage(
|
@RequestBody PageWrap<CustomerContractQueryDTO> pageWrap,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.contractPage(pageWrap, user.getCustomerId()));
|
}
|
|
@ApiOperation("合同详情")
|
@GetMapping("/contract/{id}")
|
public ApiResponse<Map<String, Object>> contractDetail(
|
@PathVariable("id") Integer id,
|
@RequestParam(value = "billType", required = false, defaultValue = "0") Integer billType,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.contractDetail(id, user.getCustomerId(), billType));
|
}
|
|
@ApiOperation("账单列表")
|
@PostMapping("/bill/page")
|
public ApiResponse<PageData<YwContractBill>> billPage(
|
@RequestBody PageWrap<CustomerBillQueryDTO> pageWrap,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.billPage(pageWrap, user.getCustomerId()));
|
}
|
|
@ApiOperation("账单详情")
|
@GetMapping("/bill/{id}")
|
public ApiResponse<Map<String, Object>> billDetail(
|
@PathVariable("id") Integer id,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerH5BizService.billDetail(id, user.getCustomerId()));
|
}
|
|
@ApiOperation("创建支付订单")
|
@PostMapping("/pay/createOrder")
|
public ApiResponse<Map<String, String>> createOrder(
|
@RequestBody CustomerPayCreateDTO dto,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token,
|
HttpServletRequest request) {
|
LoginUserInfo user = requireCustomerUser(token);
|
String ip = request.getHeader("X-Forwarded-For");
|
if (ip != null && ip.contains(",")) {
|
ip = ip.split(",")[0].trim();
|
}
|
if (ip == null) {
|
ip = request.getRemoteAddr();
|
}
|
return ApiResponse.success(ywCustomerWxPayService.createOrder(dto, user, ip));
|
}
|
|
@ApiOperation("查询支付结果")
|
@GetMapping("/pay/query/{orderNo}")
|
public ApiResponse<YwWxPayOrder> queryPay(
|
@PathVariable String orderNo,
|
@RequestHeader(Constants.HEADER_USER_TOKEN) String token) {
|
LoginUserInfo user = requireCustomerUser(token);
|
return ApiResponse.success(ywCustomerWxPayService.queryOrder(orderNo, user.getCustomerId()));
|
}
|
|
@ApiOperation("微信支付回调")
|
@PostMapping("/pay/notify")
|
@LoginNoRequired
|
public String payNotify(@RequestBody String xmlBody) {
|
return ywCustomerWxPayService.handleNotify(xmlBody);
|
}
|
}
|