删除优惠卷
新版优惠卷
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.entity.MyUserEntity;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@RestController("commonCoupon")
|
||||
@RequestMapping("common/coupon")
|
||||
public class CouponController {
|
||||
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
//优惠卷列表
|
||||
@RequestMapping("/getCouponList")
|
||||
public R getCouponList(@RequestBody Map params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
LambdaQueryWrapper<CouponEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotEmpty(params.get("couponType").toString())){
|
||||
wrapper.eq(CouponEntity::getCouponType,params.get("couponType"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("couponRange").toString())){
|
||||
wrapper.eq(CouponEntity::getCouponRange,params.get("couponRange"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("couponName").toString())){
|
||||
wrapper.like(CouponEntity::getCouponName,params.get("couponName"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("currentState").toString())){
|
||||
wrapper.eq(CouponEntity::getCurrentState,params.get("currentState"));
|
||||
}
|
||||
wrapper.orderByDesc(CouponEntity::getCreateTime);
|
||||
Page<CouponEntity> couponPage = couponService.page(new Page<>(page, limit), wrapper);
|
||||
for (CouponEntity couponEntity : couponPage.getRecords()) {
|
||||
couponService.setRangeList(couponEntity);
|
||||
}
|
||||
return R.ok().put("couponPage",couponPage);
|
||||
}
|
||||
|
||||
//用户优惠卷列表
|
||||
@RequestMapping("/getCouponHistoryList")
|
||||
public R getCouponHistoryList(@RequestBody Map params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
MPJLambdaWrapper<CouponHistory> wrapper = new MPJLambdaWrapper<>();
|
||||
wrapper.leftJoin(CouponEntity.class,CouponEntity::getId,CouponHistory::getCouponId);
|
||||
wrapper.leftJoin(MyUserEntity.class,MyUserEntity::getId,CouponHistory::getUserId);
|
||||
wrapper.selectAll(CouponHistory.class);
|
||||
if (StringUtils.isNotEmpty(params.get("getType").toString())){
|
||||
wrapper.eq(CouponHistory::getGetType,params.get("getType"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("status").toString())){
|
||||
wrapper.eq(CouponHistory::getStatus,params.get("status"));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("userInfo").toString())) {
|
||||
wrapper.and(t->t.like(MyUserEntity::getName,params.get("userInfo")).or().like(MyUserEntity::getNickname,params.get("userInfo"))
|
||||
.or().like(MyUserEntity::getTel,params.get("userInfo")).or().like(MyUserEntity::getEmail,params.get("userInfo")));
|
||||
}
|
||||
if (StringUtils.isNotEmpty(params.get("userId").toString())){
|
||||
wrapper.eq(MyUserEntity::getId,params.get("userId"));
|
||||
}
|
||||
wrapper.orderByAsc(CouponHistory::getStatus);
|
||||
wrapper.orderByDesc(CouponHistory::getCreateTime);
|
||||
Page<CouponHistory> couponList = couponHistoryService.page(new Page<>(page, limit), wrapper);
|
||||
return R.ok().put("couponList",couponList);
|
||||
}
|
||||
|
||||
//优惠劵详情
|
||||
@RequestMapping("/getCouponInfo")
|
||||
public R getCouponInfo(@RequestBody Map<String,Object> params){
|
||||
CouponEntity couponEntity = couponService.getById(Integer.parseInt(params.get("id").toString()));
|
||||
couponService.setRangeList(couponEntity);
|
||||
return R.ok().put("couponEntity",couponEntity);
|
||||
}
|
||||
|
||||
//修改优惠劵
|
||||
@RequestMapping("/updateCoupon")
|
||||
public R updateCoupon(@RequestBody CouponEntity couponEntity){
|
||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponEntity.getId()));
|
||||
if (count>0){
|
||||
return R.error("已有用户拥有优惠卷");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponEntity.getId());
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再修改");
|
||||
}
|
||||
couponService.updateById(couponEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//删除优惠劵
|
||||
@RequestMapping("/delCoupon")
|
||||
public R delCoupon(@RequestBody Map<String,Object> params){
|
||||
int couponId = Integer.parseInt(params.get("id").toString());
|
||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (count>0){
|
||||
return R.error("已有用户拥有优惠卷");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponId);
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再删除");
|
||||
}
|
||||
couponService.removeById(couponId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//新建优惠劵
|
||||
@RequestMapping("/addCoupon")
|
||||
public R addCoupon(@RequestBody CouponEntity couponEntity){
|
||||
couponService.save(couponEntity);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//发放优惠劵
|
||||
@RequestMapping("/insertCouponHistory")
|
||||
public R insertCouponHistory(@RequestBody Map<String,Object> params){
|
||||
int couponId = (int)params.get("couponId");
|
||||
int userId = (int)params.get("userId");
|
||||
int getType = (int)params.get("getType");
|
||||
return couponService.insertCouponHistory(couponId,userId,getType);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user