优惠卷
复读
This commit is contained in:
@@ -4,18 +4,18 @@ 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.book.service.BuyOrderProductService;
|
||||
import com.peanut.modules.book.service.ShopProductService;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.BuyOrderService;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import com.peanut.modules.common.service.CouponToProductService;
|
||||
import com.peanut.modules.master.service.CourseService;
|
||||
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.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -29,6 +29,12 @@ public class CouponController {
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private CourseService courseService;
|
||||
@Autowired
|
||||
private CouponToProductService couponToProductService;
|
||||
@Autowired
|
||||
private ShopProductService shopProductService;
|
||||
|
||||
//优惠卷列表
|
||||
@RequestMapping("/getCouponList")
|
||||
@@ -104,17 +110,26 @@ public class CouponController {
|
||||
return R.ok().put("couponEntity",couponEntity);
|
||||
}
|
||||
|
||||
//修改优惠劵状态
|
||||
@RequestMapping("/updateCouponState")
|
||||
public R updateCouponState(@RequestBody Map<String,Object> params){
|
||||
CouponEntity coupon = couponService.getById(params.get("id").toString());
|
||||
coupon.setCurrentState((int)params.get("currentState"));
|
||||
couponService.updateById(coupon);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//修改优惠劵
|
||||
@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("已有用户拥有优惠卷");
|
||||
return R.error("已有用户拥有优惠券");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponEntity.getId());
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再修改");
|
||||
return R.error("优惠券发放中,请先结束再修改");
|
||||
}
|
||||
couponService.updateById(couponEntity);
|
||||
return R.ok();
|
||||
@@ -127,11 +142,11 @@ public class CouponController {
|
||||
int count = couponHistoryService.count(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (count>0){
|
||||
return R.error("已有用户拥有优惠卷");
|
||||
return R.error("已有用户拥有优惠券");
|
||||
}
|
||||
CouponEntity c = couponService.getById(couponId);
|
||||
if (c.getCurrentState()==0){
|
||||
return R.error("优惠卷发放中,请先结束再删除");
|
||||
return R.error("优惠券发放中,请先结束再删除");
|
||||
}
|
||||
couponService.removeById(couponId);
|
||||
return R.ok();
|
||||
@@ -161,11 +176,17 @@ public class CouponController {
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
//当前优惠卷可用商品
|
||||
@RequestMapping("/getShopProductByCoupon")
|
||||
public R getShopProductByCoupon(@RequestBody Map<String,Object> params){
|
||||
Set<Integer> l = couponService.getShopProductByCoupon(Integer.parseInt(params.get("couponId").toString()));
|
||||
return R.ok().put("productIds",l);
|
||||
//优惠卷可绑定课程
|
||||
@RequestMapping("/getCourseList")
|
||||
public R getCourseList(@RequestBody Map<String,Object> params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
LambdaQueryWrapper<CourseEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.select(CourseEntity::getId,CourseEntity::getTitle);
|
||||
wrapper.like(CourseEntity::getTitle,params.get("title"));
|
||||
wrapper.orderByDesc(CourseEntity::getId);
|
||||
Page<CourseEntity> courses = courseService.page(new Page<>(page, limit), wrapper);
|
||||
return R.ok().put("courses",courses);
|
||||
}
|
||||
|
||||
//付款时优惠卷列表
|
||||
@@ -175,4 +196,42 @@ public class CouponController {
|
||||
return R.ok().put("couponHistoryList",couponHistoryList);
|
||||
}
|
||||
|
||||
//购买商品绑定优惠卷列表
|
||||
@RequestMapping("/couponToProductList")
|
||||
public R couponToShopproductList(@RequestBody Map<String,Object> params){
|
||||
Integer limit = Integer.valueOf(params.get("limit").toString());
|
||||
Integer page = Integer.valueOf(params.get("page").toString());
|
||||
LambdaQueryWrapper<CouponToProduct> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CouponToProduct::getProductId,params.get("productId"));
|
||||
wrapper.orderByDesc(CouponToProduct::getId);
|
||||
Page<CouponToProduct> couponToShopproductPage = couponToProductService.page(new Page<>(page, limit), wrapper);
|
||||
for (CouponToProduct couponToProduct : couponToShopproductPage.getRecords()) {
|
||||
couponToProduct.setCouponEntity(couponService.getById(couponToProduct.getCouponId()));
|
||||
couponToProduct.setShopProduct(shopProductService.getById(couponToProduct.getShopProduct()));
|
||||
}
|
||||
return R.ok().put("couponToShopproductPage",couponToShopproductPage);
|
||||
}
|
||||
|
||||
//商品绑定优惠卷
|
||||
@RequestMapping("/setCouponToProduct")
|
||||
public R setCouponToProduct(@RequestBody CouponToProduct couponToProduct){
|
||||
CouponToProduct c = couponToProductService.getOne(new LambdaQueryWrapper<CouponToProduct>()
|
||||
.eq(CouponToProduct::getCouponId, couponToProduct.getCouponId())
|
||||
.eq(CouponToProduct::getProductId, couponToProduct.getProductId()));
|
||||
if (c == null){
|
||||
couponToProductService.save(couponToProduct);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("已存在");
|
||||
}
|
||||
}
|
||||
|
||||
//解绑商品优惠卷
|
||||
@RequestMapping("/unbindCouponToProduct")
|
||||
public R unbindCouponToProduct(@RequestBody Map<String,Object> params){
|
||||
couponToProductService.removeById(params.get("id").toString());
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user