元气优淘服务端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
youtao/cweb/src/main/java/com/hfkj/controller/UserGradeController.java

132 lines
4.8 KiB

package com.hfkj.controller;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.SessionObject;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.MemberValidateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsUser;
import com.hfkj.model.ResponseData;
import com.hfkj.model.UserSessionObject;
import com.hfkj.service.user.BsUserAccountRecordService;
import com.hfkj.service.user.BsUserAccountService;
import com.hfkj.service.user.BsUserGradeService;
import com.hfkj.service.user.BsUserService;
import com.hfkj.service.user.impl.BsUserServiceImpl;
import com.hfkj.sysenum.user.UserAccountRecordSourceTypeEnum;
import com.hfkj.sysenum.user.UserGradeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
/**
* @className: ClientController
* @author: HuRui
* @date: 2024/9/6
**/
@Controller
@RequestMapping(value="/userGrade")
@Api(value="客户端业务")
public class UserGradeController {
@Autowired
private UserCenter userCenter;
@Resource
private BsUserService userService;
@Resource
private BsUserGradeService userGradeService;
@RequestMapping(value = "/promote", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "等级晋升")
public ResponseData promote() {
try {
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
// 等级晋升
userGradeService.promote(userSession.getUser().getId());
// 更新session
UserSessionObject session = new UserSessionObject();
session.setUser(userService.getUser(userSession.getUser().getId()));
SessionObject sessionObject = new SessionObject(BsUserServiceImpl.userToken(userSession.getUser().getId()), session);
userCenter.save(sessionObject);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/payGrade2", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "购买【优淘会员】等级")
public ResponseData payGrade2() {
try {
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
// 购买
userGradeService.payGrade2(userSession.getUser().getId());
// 更新session
UserSessionObject session = new UserSessionObject();
session.setUser(userService.getUser(userSession.getUser().getId()));
SessionObject sessionObject = new SessionObject(BsUserServiceImpl.userToken(userSession.getUser().getId()), session);
userCenter.save(sessionObject);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/queryProgress", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询升级条件进度")
public ResponseData queryProgress() {
try {
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class);
// 查询用户
BsUser user = userService.getUser(userSession.getUser().getId());
Map<String,Object> map = new HashMap<>();
if (UserGradeEnum.grade1.getCode().equals(user.getGrade())) {
// 晋升优淘会员
map = userGradeService.promoteGrade2Progress(user.getId());
} else if (UserGradeEnum.grade2.getCode().equals(user.getGrade())) {
// 晋升团长渠道
map = userGradeService.promoteGrade3Progress(user.getId());
} else if (UserGradeEnum.grade3.getCode().equals(user.getGrade())) {
// 晋升渠道进度
map = userGradeService.promoteGrade4Progress(user.getId());
}
map.put("currentUserGrade", user.getGrade());
return ResponseMsgUtil.success(map);
} catch (Exception e) {
return ResponseMsgUtil.exception(e);
}
}
}