package com.bweb.controller; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.HighUser; import com.hai.model.ResponseData; import com.hai.service.HighOpenApiService; import com.hai.service.HighUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.Map; /** * @Author Sum1Dream * @ClassName HighOpenApiController * @Description // 开放接口 * @Date 2021/11/24 4:49 下午 **/ @Controller @RequestMapping(value = "/openApi") @Api(value = "开放接口") public class HighOpenApiController { private static Logger log = LoggerFactory.getLogger(HighOrderPreController.class); @Resource private HighOpenApiService highOpenApiService; @Resource private HighUserService highUserService; @RequestMapping(value = "/getUserExclusiveDiscount", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取专属优惠券") public ResponseData getUserExclusiveDiscount(@RequestParam(name = "useScope", required = false) Integer useScope, @RequestParam(name = "phone", required = true) String phone, @RequestParam(name = "year", required = false) String year) { try { HighUser highUser = highUserService.findByPhone(phone); if (highUser == null || highUser.getStatus() == 0) { log.error("getUserOrderPreList error!", "未找到用户"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前手机号暂无用户"); } Map map = new HashMap<>(); map.put("userId", highUser.getId()); map.put("useScope", useScope); if (year != null) { map.put("createTimeS", year + "-01-01 00:00:00"); map.put("createTimeE", year + "-12-31 23:59:59"); } return ResponseMsgUtil.success(highOpenApiService.getUserCouponsList(map)); } catch (Exception e) { log.error("HighOrderController --> getUserPreOrderList() error!", e); return ResponseMsgUtil.exception(e); } } }