|
|
|
package com.bweb.controller;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
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.security.SessionObject;
|
|
|
|
import com.hai.common.security.UserCenter;
|
|
|
|
import com.hai.common.utils.ResponseMsgUtil;
|
|
|
|
import com.hai.entity.*;
|
|
|
|
import com.hai.model.ResponseData;
|
|
|
|
import com.hai.model.UserInfoModel;
|
|
|
|
import com.hai.service.HighCouponService;
|
|
|
|
import com.hai.service.HighDiscountPackageDetailsService;
|
|
|
|
import com.hai.service.HighDiscountPackageService;
|
|
|
|
import com.hai.service.HighDiscountService;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import io.swagger.models.auth.In;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author Sum1Dream
|
|
|
|
* @ClassName HighDiscountPackageController
|
|
|
|
* @Description // 优惠券包接口
|
|
|
|
* @Date 2021/11/25 4:32 下午
|
|
|
|
**/
|
|
|
|
@Controller
|
|
|
|
@RequestMapping(value = "/highDiscountPackage")
|
|
|
|
@Api(value = "优惠券包接口")
|
|
|
|
public class HighDiscountPackageController {
|
|
|
|
|
|
|
|
private static Logger log = LoggerFactory.getLogger(HighOrderPreController.class);
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private UserCenter userCenter;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private HighDiscountPackageService highDiscountPackageService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private HighDiscountPackageDetailsService highDiscountPackageDetailsService;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
private HighDiscountService highDiscountService;
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getDiscountPackageList", method = RequestMethod.GET)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "获取优惠券包列表")
|
|
|
|
public ResponseData getDiscountPackageList(@RequestParam(name = "usingAttribution", required = false) Integer usingAttribution,
|
|
|
|
@RequestParam(name = "title", required = false) String title,
|
|
|
|
@RequestParam(name = "salesType", required = false) Integer salesType,
|
|
|
|
@RequestParam(name = "status", required = false) Integer status,
|
|
|
|
@RequestParam(name = "pageNum", required = true) Integer pageNum,
|
|
|
|
@RequestParam(name = "pageSize", required = true) Integer pageSize,
|
|
|
|
HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
map.put("companyId", userInfoModel.getBsCompany().getId());
|
|
|
|
map.put("usingAttribution", usingAttribution);
|
|
|
|
map.put("title" , title);
|
|
|
|
map.put("salesType" , salesType);
|
|
|
|
map.put("status" , status);
|
|
|
|
PageHelper.startPage(pageNum,pageSize);
|
|
|
|
return ResponseMsgUtil.success(new PageInfo<>(highDiscountPackageService.getDiscountPackageList(map)));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighOrderController --> getUserOrderList() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/insertCouponPackageInfo", method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "新增优惠券包基本信息")
|
|
|
|
public ResponseData insertCouponPackageInfo(@RequestBody HighDiscountPackage highDiscountPackage, HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
//发布人员
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(highDiscountPackage.getTitle())
|
|
|
|
|| highDiscountPackage.getUsingAttribution() == null
|
|
|
|
|| highDiscountPackage.getSalesType() == null
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getBannerImg())
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getListImg())
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getDetailsImg())
|
|
|
|
) {
|
|
|
|
log.error("HighAgentController -> insertCouponPackageInfo() error!","参数错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userInfoModel.getBsCompany() == null) {
|
|
|
|
log.error("highCouponPackage -> insertCouponPackageInfo() error!","该主角色没有权限");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (highDiscountPackage.getSalesType() == 1) {
|
|
|
|
if (highDiscountPackage.getPurchaseNum() == null
|
|
|
|
|| highDiscountPackage.getPrice() == null
|
|
|
|
) {
|
|
|
|
log.error("HighAgentController -> insertCouponPackageInfo() error!","参数错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
highDiscountPackage.setCompanyId(userInfoModel.getBsCompany().getId().intValue());
|
|
|
|
highDiscountPackage.setStatus(3);
|
|
|
|
highDiscountPackage.setCreatedTime(new Date());
|
|
|
|
highDiscountPackage.setCreatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
highDiscountPackage.setUpdatedTime(new Date());
|
|
|
|
highDiscountPackage.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
|
|
|
|
highDiscountPackageService.insertDiscountPackage(highDiscountPackage);
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(highDiscountPackage);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighAgentController --> insertAgent() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/updateCouponPackageInfo", method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "修改优惠券包基本信息")
|
|
|
|
public ResponseData updateCouponPackageInfo(@RequestBody HighDiscountPackage highDiscountPackage, HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
//发布人员
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
if (StringUtils.isBlank(highDiscountPackage.getTitle())
|
|
|
|
|| highDiscountPackage.getUsingAttribution() == null
|
|
|
|
|| highDiscountPackage.getSalesType() == null
|
|
|
|
|| highDiscountPackage.getId() == null
|
|
|
|
|| highDiscountPackage.getEffectiveTiem() == null
|
|
|
|
|| highDiscountPackage.getPurchaseNum() == null
|
|
|
|
|| highDiscountPackage.getPrice() == null
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getBannerImg())
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getListImg())
|
|
|
|
|| StringUtils.isBlank(highDiscountPackage.getDetailsImg())
|
|
|
|
) {
|
|
|
|
log.error("HighAgentController -> insertAgent() error!","参数错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userInfoModel.getBsCompany() == null) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","该主角色没有权限");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
HighDiscountPackage highDiscountPackages = highDiscountPackageService.findDiscountPackageById(highDiscountPackage.getId());
|
|
|
|
|
|
|
|
if (highDiscountPackages == null || highDiscountPackage.getStatus() == 1) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","状态错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
highDiscountPackages.setStatus(3);
|
|
|
|
highDiscountPackages.setUpdatedTime(new Date());
|
|
|
|
highDiscountPackages.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
|
|
|
|
highDiscountPackageService.insertDiscountPackage(highDiscountPackage);
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(highDiscountPackage);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighAgentController --> insertAgent() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/highCouponPackageRule", method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "新增优惠券包规则信息")
|
|
|
|
public ResponseData highCouponPackageRule(@RequestBody HighDiscountPackageDetails highDiscountPackageDetails, HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
//发布人员
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
if ( highDiscountPackageDetails.getDiscountPackageId() == null
|
|
|
|
|| highDiscountPackageDetails.getDiscountId() == null
|
|
|
|
|| highDiscountPackageDetails.getNum() == null
|
|
|
|
) {
|
|
|
|
log.error("HighAgentController -> insertAgent() error!","参数错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userInfoModel.getBsCompany() == null) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","该主角色没有权限");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
HighDiscount discount = highDiscountService.getDiscountById(highDiscountPackageDetails.getDiscountId().longValue());
|
|
|
|
|
|
|
|
if (discount == null || highDiscountPackageService.findDiscountPackageById(highDiscountPackageDetails.getDiscountPackageId()) == null) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","优惠券 或者 优惠券包不存在");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, "优惠券 或者 优惠券包不存在");
|
|
|
|
}
|
|
|
|
|
|
|
|
highDiscountPackageDetails.setStatus(1);
|
|
|
|
highDiscountPackageDetails.setDiscountName(discount.getDiscountName());
|
|
|
|
highDiscountPackageDetails.setCreatedTime(new Date());
|
|
|
|
highDiscountPackageDetails.setCreatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
highDiscountPackageDetails.setUpdatedTime(new Date());
|
|
|
|
highDiscountPackageDetails.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
|
|
|
|
highDiscountPackageDetailsService.insertDiscountPackageDetails(highDiscountPackageDetails);
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(null);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighAgentController --> insertAgent() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getDiscountPackageRuleList", method = RequestMethod.GET)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "获取优惠券包规则列表")
|
|
|
|
public ResponseData getDiscountPackageRuleList(@RequestParam(name = "discountPackageId", required = true) Integer discountPackageId,
|
|
|
|
HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
//发布人员
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
if (userInfoModel.getBsCompany() == null) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","该主角色没有权限");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
map.put("discountPackageId", discountPackageId);
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(highDiscountPackageDetailsService.getDiscountPackageDetailsList(map));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighOrderController --> getUserOrderList() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequestMapping(value = "/deleteDiscountPackageRule", method = RequestMethod.POST)
|
|
|
|
@ResponseBody
|
|
|
|
@ApiOperation(value = "删除优惠券包规则")
|
|
|
|
public ResponseData deleteDiscountPackageRule(@RequestBody JSONObject object, HttpServletRequest request) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
|
|
|
|
//发布人员
|
|
|
|
SessionObject sessionObject = userCenter.getSessionObject(request);
|
|
|
|
UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject();
|
|
|
|
|
|
|
|
if (userInfoModel.getBsCompany() == null) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","该主角色没有权限");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
HighDiscountPackageDetails highDiscountPackageDetails = highDiscountPackageDetailsService.findDetailsById(object.getInteger("discountPackageId"));
|
|
|
|
|
|
|
|
if (highDiscountPackageDetails == null || highDiscountPackageDetails.getStatus() == 2) {
|
|
|
|
log.error("highCouponPackage -> highCouponPackageInfo() error!","状态错误");
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
highDiscountPackageDetails.setStatus(2);
|
|
|
|
highDiscountPackageDetails.setUpdatedTime(new Date());
|
|
|
|
highDiscountPackageDetails.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue());
|
|
|
|
|
|
|
|
highDiscountPackageDetailsService.updateDiscountPackageDetails(highDiscountPackageDetails);
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success("删除成功");
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
log.error("HighOrderController --> getUserOrderList() error!", e);
|
|
|
|
return ResponseMsgUtil.exception(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|