|
|
|
@@ -0,0 +1,116 @@ |
|
|
|
package com.iformall.controller; |
|
|
|
|
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.vo.WxCUserVo; |
|
|
|
import com.iformall.service.WxCUserBasicInfoService; |
|
|
|
import com.iformall.service.WxCUserService; |
|
|
|
import com.iformall.service.WxLevelConfigService; |
|
|
|
import com.iformall.service.WxMerchantService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
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 java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author Stormeye |
|
|
|
*/ |
|
|
|
@RestController |
|
|
|
@Api(description = "C端会员信息") |
|
|
|
@RequestMapping("/api/mem") |
|
|
|
public class WxMemController extends BaseController { |
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserService userService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxLevelConfigService wxLevelConfigService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCUserBasicInfoService wxCUserBasicInfoService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxMerchantService wxMerchantService; |
|
|
|
|
|
|
|
@ApiOperation(value = "扫C端会员码返回会员信息", notes = "params:{\"memCode\":\"String\"}\n") |
|
|
|
@PostMapping("mem_scan") |
|
|
|
public ResultData memScan(@RequestBody Map<String, String> paramMap) { |
|
|
|
logger.info("memScan" + getIpAddr() + ": " + paramMap.toString()); |
|
|
|
String memCode = paramMap.get("memCode"); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(memCode)) { |
|
|
|
logger.error("memCode不能为空"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "memCode不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
Long id = null; |
|
|
|
try { |
|
|
|
id = Long.valueOf(memCode); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("memCode convert failed"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "memCode转换失败"); |
|
|
|
} |
|
|
|
|
|
|
|
WxMerchantBUser bUser = getUser(); |
|
|
|
|
|
|
|
WxCUser cUser = userService.getById(id); |
|
|
|
if(cUser == null) { |
|
|
|
return new ResultData(ErrorCode.USER_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
WxCUserVo userVo = new WxCUserVo(); |
|
|
|
org.springframework.beans.BeanUtils.copyProperties(cUser, userVo); |
|
|
|
if (userVo.getScore() == null || userVo.getScore() == 0) { |
|
|
|
userVo.setLevelName("无"); |
|
|
|
userVo.setDiscountRate(1000); // 无折扣 |
|
|
|
} else { |
|
|
|
userVo.setLevelName("无"); |
|
|
|
|
|
|
|
Integer levelConfigDiscount = null; |
|
|
|
|
|
|
|
List<WxLevelConfig> levelList = wxLevelConfigService.getByTenantId(bUser.getTenantId()); |
|
|
|
for(WxLevelConfig levelConfig: levelList) { |
|
|
|
if (userVo.getScore() >= levelConfig.getPoints()) { |
|
|
|
userVo.setLevelId(levelConfig.getId()); |
|
|
|
userVo.setLevelName(levelConfig.getLevel()); |
|
|
|
levelConfigDiscount = levelConfig.getDiscountEnable(); |
|
|
|
} |
|
|
|
} |
|
|
|
WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(cUser.getId()); |
|
|
|
if (wxCUserBasicInfo != null) { |
|
|
|
userVo.setName(wxCUserBasicInfo.getName()); |
|
|
|
userVo.setBirthdate(wxCUserBasicInfo.getBirthdate()); |
|
|
|
userVo.setSex(wxCUserBasicInfo.getSex()); |
|
|
|
userVo.setAddress(wxCUserBasicInfo.getAddress()); |
|
|
|
} |
|
|
|
|
|
|
|
if(levelConfigDiscount > 0) { |
|
|
|
// 用户折扣率 |
|
|
|
WxMerchant wxMerchant = wxMerchantService.getById(bUser.getMerchantId()); |
|
|
|
if(wxMerchant != null) { |
|
|
|
if(levelConfigDiscount.equals(1)) { // first level |
|
|
|
userVo.setDiscountRate(wxMerchant.getVipDiscountRate1()); |
|
|
|
} else if(levelConfigDiscount.equals(2)) { // second level |
|
|
|
userVo.setDiscountRate(wxMerchant.getVipDiscountRate2()); |
|
|
|
} else if(levelConfigDiscount.equals(3)) { // third level |
|
|
|
userVo.setDiscountRate(wxMerchant.getVipDiscountRate3()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(userVo); |
|
|
|
} |
|
|
|
|
|
|
|
} |