删除优惠卷
新版优惠卷
This commit is contained in:
@@ -56,10 +56,6 @@ public class BuyOrderController {
|
||||
@Autowired
|
||||
private BuyOrderDetailService buyOrderDetailService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private OrderCartService orderCartService;
|
||||
@Autowired
|
||||
private MyUserService myUserService;
|
||||
@@ -241,7 +237,7 @@ public class BuyOrderController {
|
||||
totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(quantity)));
|
||||
}
|
||||
//商品价格减去优惠券的优惠金额
|
||||
totalPrice = totalPrice.subtract(useCouponAmount(buyOrder));
|
||||
// totalPrice = totalPrice.subtract(0);
|
||||
|
||||
//加上运费金额
|
||||
totalPrice = totalPrice.add(getShoppingAmount(buyOrder));
|
||||
@@ -467,12 +463,6 @@ public class BuyOrderController {
|
||||
if (buyOrder == null) {
|
||||
return R.error("订单不存在");
|
||||
}
|
||||
if (buyOrder.getCouponId() != null) {
|
||||
Integer couponId = buyOrder.getCouponId();
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
// 库存回滚
|
||||
QueryWrapper<BuyOrderProduct> buyOrderProductQueryWrapper = new QueryWrapper<>();
|
||||
buyOrderProductQueryWrapper.eq("order_id", buyOrder.getOrderId());
|
||||
@@ -519,14 +509,6 @@ public class BuyOrderController {
|
||||
//1. 判断订单状态
|
||||
BuyOrder byId = buyOrderService.getById(orderId);
|
||||
if (byId != null) {
|
||||
//2. 判断当前订单是否存在优惠券 进行 回显
|
||||
Integer couponId = byId.getCouponId();
|
||||
if (couponId != null) {
|
||||
|
||||
CouponHistoryEntity byId1 = couponHistoryService.getById(couponId);
|
||||
byId1.setUseStatus(0);
|
||||
couponHistoryService.updateById(byId1);
|
||||
}
|
||||
// 库存回滚
|
||||
List<BuyOrderDetail> buyOrderDetailEntities = buyOrderDetailService.getBaseMapper().selectList(new QueryWrapper<BuyOrderDetail>()
|
||||
.eq("order_id", byId.getOrderId()));
|
||||
@@ -832,26 +814,6 @@ public class BuyOrderController {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用优惠券
|
||||
*
|
||||
* @param buyOrder
|
||||
* @return
|
||||
*/
|
||||
private BigDecimal useCouponAmount(BuyOrder buyOrder) {
|
||||
Integer couponId = buyOrder.getCouponId();
|
||||
if (couponId != null&&couponId!=0) {
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(1);
|
||||
couponHistory.setUseTime(new Date());
|
||||
couponHistory.setOrderId(Long.valueOf(buyOrder.getOrderId()));
|
||||
couponHistory.setOrderSn(buyOrder.getOrderSn());
|
||||
CouponEntity coupon = couponService.getById(couponHistory.getCouponId());
|
||||
|
||||
return coupon.getCouponAmount();
|
||||
}
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.peanut.modules.book.service.CouponProductCategoryRelationService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.book.service.CouponService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("book/coupon")
|
||||
public class CouponController {
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponProductCategoryRelationService couponProductCategoryRelationService;
|
||||
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:coupon:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = couponService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:coupon:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
CouponEntity coupon = couponService.getById(id);
|
||||
|
||||
return R.ok().put("coupon", coupon);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
// @RequiresPermissions("book:coupon:save")
|
||||
public R save(@RequestBody CouponEntity coupon){
|
||||
|
||||
if(0 == coupon.getTakeEffectType()){
|
||||
coupon.setTakeEffectDate(new Date());
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
||||
coupon.setExpirationDate(cal.getTime());
|
||||
}else{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(coupon.getTakeEffectDate());
|
||||
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
||||
coupon.setExpirationDate(cal.getTime());
|
||||
}
|
||||
couponService.save(coupon);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
// @RequiresPermissions("book:coupon:update")
|
||||
public R update(@RequestBody CouponEntity coupon){
|
||||
|
||||
if(0 == coupon.getTakeEffectType()){
|
||||
coupon.setTakeEffectDate(new Date());
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
||||
coupon.setExpirationDate(cal.getTime());
|
||||
}else{
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(coupon.getTakeEffectDate());
|
||||
cal.add(Calendar.DATE,Integer.valueOf(coupon.getValidity()).intValue());
|
||||
coupon.setExpirationDate(cal.getTime());
|
||||
}
|
||||
couponService.updateById(coupon);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
// @RequiresPermissions("book:coupon:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
couponService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.book.service.CouponService;
|
||||
import com.peanut.modules.book.vo.UserCouponVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponHistoryEntity;
|
||||
import com.peanut.modules.book.service.CouponHistoryService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("book/couponhistory")
|
||||
public class CouponHistoryController {
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:couponhistory:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = couponHistoryService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:couponhistory:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(id);
|
||||
|
||||
return R.ok().put("couponHistory", couponHistory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
// @RequiresPermissions("book:couponhistory:save")
|
||||
public R save(@RequestBody CouponHistoryEntity couponHistory){
|
||||
|
||||
List<CouponHistoryEntity> ch = this.couponHistoryService.list(new QueryWrapper<CouponHistoryEntity>().eq("coupon_id", couponHistory.getCouponId()));
|
||||
|
||||
CouponEntity coupon = this.couponService.getById(couponHistory.getCouponId());
|
||||
|
||||
// 查询该用户领取几张该优惠券
|
||||
List<CouponHistoryEntity> historyList = this.couponHistoryService.list(new QueryWrapper<CouponHistoryEntity>()
|
||||
.eq("coupon_id", couponHistory.getCouponId())
|
||||
.eq("member_id",couponHistory.getMemberId())
|
||||
);
|
||||
// 领取次数小于等于限领
|
||||
if(historyList.size() >= coupon.getLimitedCollar()){
|
||||
return R.ok("每人限领" + coupon.getLimitedCollar() + "张,查看后操作!");
|
||||
}
|
||||
// 优惠券发行数量大于该优惠券领用次数
|
||||
if(ch.size() <= coupon.getTotalCirculation()){
|
||||
couponHistory.setCouponProType(coupon.getCouponProType());
|
||||
couponHistoryService.save(couponHistory);
|
||||
return R.ok("添加成功!");
|
||||
}
|
||||
return R.ok("购物券数量已超过发行总量,请查看后操作!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
// @RequiresPermissions("book:couponhistory:update")
|
||||
public R update(@RequestBody CouponHistoryEntity couponHistory){
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
// @RequiresPermissions("book:couponhistory:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
couponHistoryService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* app端获取优惠券
|
||||
*/
|
||||
@RequestMapping("/appGetCoupon")
|
||||
public R appGetCoupon(){
|
||||
List<CouponEntity> list = couponHistoryService.appGetCoupon();
|
||||
|
||||
return R.ok().put("list",list);
|
||||
}
|
||||
|
||||
/**
|
||||
* app端下单获取用户个人优惠券
|
||||
*/
|
||||
@RequestMapping("/appGetUserCoupon")
|
||||
public R appGetUserCoupon(@RequestParam("userId") Integer userId,
|
||||
@RequestParam("amount") String amount,
|
||||
@RequestParam("type")String type){
|
||||
List<UserCouponVo> userCoupons = couponHistoryService.appGetUserCoupon(userId,amount,type);
|
||||
|
||||
return R.ok().put("userCoupons",userCoupons);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* app端个人中心-用户个人优惠券
|
||||
*/
|
||||
@RequestMapping("/appGetUserCenterCoupon")
|
||||
public R appGetUserCenterCoupon(@RequestParam("userId") Integer userId,
|
||||
@RequestParam("useStatus") Integer useStatus){
|
||||
List<CouponHistoryEntity> couponHistoryEntities = couponHistoryService.getBaseMapper().selectList(new QueryWrapper<CouponHistoryEntity>()
|
||||
.eq("member_id", userId)
|
||||
.eq("use_status", useStatus));
|
||||
|
||||
List<UserCouponVo> couponVos = new ArrayList<>();
|
||||
for (CouponHistoryEntity couponHistoryEntity : couponHistoryEntities) {
|
||||
UserCouponVo userCouponVo = new UserCouponVo();
|
||||
Long couponId = couponHistoryEntity.getCouponId();
|
||||
CouponEntity couponEntity = couponService.getById(couponId);
|
||||
BeanUtils.copyProperties(couponHistoryEntity, userCouponVo);
|
||||
userCouponVo.setCoupons(couponEntity);
|
||||
couponVos.add(userCouponVo);
|
||||
}
|
||||
|
||||
|
||||
return R.ok().put("couponVos",couponVos).put("count",couponVos.size());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductCategoryRelationEntity;
|
||||
import com.peanut.modules.book.service.CouponProductCategoryRelationService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("book/couponproductcategoryrelation")
|
||||
public class CouponProductCategoryRelationController {
|
||||
@Autowired
|
||||
private CouponProductCategoryRelationService couponProductCategoryRelationService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:couponproductcategoryrelation:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = couponProductCategoryRelationService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:couponproductcategoryrelation:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
CouponProductCategoryRelationEntity couponProductCategoryRelation = couponProductCategoryRelationService.getById(id);
|
||||
|
||||
return R.ok().put("couponProductCategoryRelation", couponProductCategoryRelation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
// @RequiresPermissions("book:couponproductcategoryrelation:save")
|
||||
public R save(@RequestBody CouponProductCategoryRelationEntity couponProductCategoryRelation){
|
||||
|
||||
Integer integer = couponProductCategoryRelationService.getBaseMapper()
|
||||
.selectCount(new QueryWrapper<CouponProductCategoryRelationEntity>()
|
||||
.eq("coupon_id", couponProductCategoryRelation.getCouponId())
|
||||
.eq("product_category_id", couponProductCategoryRelation.getProductCategoryId()));
|
||||
if (integer != 0) {
|
||||
return R.error("请勿重复添加!");
|
||||
}
|
||||
couponProductCategoryRelationService.save(couponProductCategoryRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
// @RequiresPermissions("book:couponproductcategoryrelation:update")
|
||||
public R update(@RequestBody CouponProductCategoryRelationEntity couponProductCategoryRelation){
|
||||
couponProductCategoryRelationService.updateById(couponProductCategoryRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
// @RequiresPermissions("book:couponproductcategoryrelation:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
System.out.println("ids==============>"+ids);
|
||||
couponProductCategoryRelationService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
package com.peanut.modules.book.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductRelationEntity;
|
||||
import com.peanut.modules.book.service.CouponProductRelationService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("book/couponproductrelation")
|
||||
public class CouponProductRelationController {
|
||||
@Autowired
|
||||
private CouponProductRelationService couponProductRelationService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
@RequestMapping("/list")
|
||||
// @RequiresPermissions("book:couponproductrelation:list")
|
||||
public R list(@RequestParam Map<String, Object> params){
|
||||
PageUtils page = couponProductRelationService.queryPage(params);
|
||||
|
||||
return R.ok().put("page", page);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*/
|
||||
@RequestMapping("/info/{id}")
|
||||
// @RequiresPermissions("book:couponproductrelation:info")
|
||||
public R info(@PathVariable("id") Long id){
|
||||
CouponProductRelationEntity couponProductRelation = couponProductRelationService.getById(id);
|
||||
|
||||
return R.ok().put("couponProductRelation", couponProductRelation);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
// @RequiresPermissions("book:couponproductrelation:save")
|
||||
public R save(@RequestBody CouponProductRelationEntity couponProductRelation){
|
||||
|
||||
Integer integer = couponProductRelationService.getBaseMapper()
|
||||
.selectCount(new QueryWrapper<CouponProductRelationEntity>()
|
||||
.eq("coupon_id", couponProductRelation.getCouponId())
|
||||
.eq("product_id", couponProductRelation.getProductId()));
|
||||
if (integer != 0) {
|
||||
return R.error("请勿重复添加!");
|
||||
}
|
||||
|
||||
couponProductRelationService.save(couponProductRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@RequestMapping("/update")
|
||||
// @RequiresPermissions("book:couponproductrelation:update")
|
||||
public R update(@RequestBody CouponProductRelationEntity couponProductRelation){
|
||||
couponProductRelationService.updateById(couponProductRelation);
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@RequestMapping("/delete")
|
||||
// @RequiresPermissions("book:couponproductrelation:delete")
|
||||
public R delete(@RequestBody Long[] ids){
|
||||
couponProductRelationService.removeByIds(Arrays.asList(ids));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -53,8 +53,6 @@ public class MyUserController {
|
||||
@Autowired
|
||||
private SysUserTokenService sysUserTokenService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private BookBuyConfigService bookBuyConfigService;
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.common.entity.CouponHistoryEntity;
|
||||
import com.peanut.modules.book.vo.UserCouponVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
public interface CouponHistoryService extends IService<CouponHistoryEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 执行更新 用户已领取券超过有效期后设置状态为过期
|
||||
*/
|
||||
void runCouponsUserStatusTimeOutToExpired();
|
||||
|
||||
List<CouponEntity> appGetCoupon();
|
||||
|
||||
List<UserCouponVo> appGetUserCoupon(Integer userId , String amount,String type);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.common.entity.CouponProductCategoryRelationEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
public interface CouponProductCategoryRelationService extends IService<CouponProductCategoryRelationEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.common.entity.CouponProductRelationEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
public interface CouponProductRelationService extends IService<CouponProductRelationEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.peanut.modules.book.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
public interface CouponService extends IService<CouponEntity> {
|
||||
|
||||
PageUtils queryPage(Map<String, Object> params);
|
||||
|
||||
}
|
||||
|
||||
@@ -723,13 +723,6 @@ public class BuyOrderServiceImpl extends ServiceImpl<BuyOrderDao, BuyOrder> impl
|
||||
}
|
||||
responseVo.setUserInfo(userResponseVo);
|
||||
}
|
||||
CouponResponseVo couponResponseVo = new CouponResponseVo();
|
||||
if (buyOrder.getCouponId() != null) {
|
||||
couponResponseVo.setCouponName(buyOrder.getCouponName());
|
||||
couponResponseVo.setCouponId(buyOrder.getCouponId());
|
||||
couponResponseVo.setCouponAmount(new BigDecimal(0));
|
||||
}
|
||||
responseVo.setCoupon(couponResponseVo);
|
||||
responseVo.setOrderPrice(buyOrder.getOrderMoney());
|
||||
responseVo.setRealPrice(buyOrder.getRealMoney());
|
||||
responseVo.setShippingPrice(buyOrder.getShippingMoney());
|
||||
|
||||
@@ -1,242 +0,0 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.peanut.common.utils.DateUtil;
|
||||
import com.peanut.modules.book.service.*;
|
||||
import com.peanut.modules.book.vo.UserCouponVo;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||
|
||||
@Slf4j
|
||||
@Service("couponHistoryService")
|
||||
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryDao, CouponHistoryEntity> implements CouponHistoryService {
|
||||
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponProductCategoryRelationService categoryRelationService;
|
||||
@Autowired
|
||||
private CouponProductRelationService productRelationService;
|
||||
@Autowired
|
||||
private ShopProductServiceImpl shopProductService;
|
||||
@Autowired
|
||||
private BookService bookService;
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String userId = (String) params.get("userId");
|
||||
IPage<CouponHistoryEntity> page = this.page(
|
||||
new Query<CouponHistoryEntity>().getPage(params),
|
||||
new QueryWrapper<CouponHistoryEntity>()
|
||||
.eq(StringUtils.isNotBlank(userId), "member_id", Integer.parseInt(userId))
|
||||
);
|
||||
List<CouponHistoryEntity> records = page.getRecords();
|
||||
for (CouponHistoryEntity record : records) {
|
||||
Long couponId = record.getCouponId();
|
||||
CouponEntity byId = couponService.getById(couponId);
|
||||
if(byId != null) {
|
||||
record.setCouponName(byId.getCouponName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void runCouponsUserStatusTimeOutToExpired() {
|
||||
log.info("runCouponsUserStatusTimeOutToExpired start.......time={}", System.currentTimeMillis());
|
||||
Long startTime01 = System.currentTimeMillis();
|
||||
//查找到所有用户已领取,但未使用的用户券列表
|
||||
List<CouponHistoryEntity> couponsUserList = findListByUseStatus();
|
||||
log.info("runCouponsUserStatusTimeOutToExpired couponsUserList.size={}", couponsUserList.size());
|
||||
if (couponsUserList.size() > 0) {
|
||||
List<CouponHistoryEntity> needCouponsUserList = new ArrayList<>();
|
||||
Date currentDate = new Date();
|
||||
for (int i = 0; i < couponsUserList.size(); i++) {
|
||||
CouponHistoryEntity couponsUser = couponsUserList.get(i);
|
||||
Long couponId = couponsUser.getCouponId();
|
||||
CouponEntity couponEntity = couponService.getById(couponId);
|
||||
Date effDate = couponEntity.getTakeEffectDate();
|
||||
Date expDate = couponEntity.getExpirationDate();
|
||||
boolean isEffective = DateUtil.isEffectiveDate(currentDate, effDate, expDate);
|
||||
//券已失效 则修改用户券的状态为已过期
|
||||
if (!isEffective) {
|
||||
couponsUser.setUseStatus(2);
|
||||
needCouponsUserList.add(couponsUser); //需要更新状态的券
|
||||
couponEntity.setCurrentState("2");
|
||||
this.couponService.updateById(couponEntity);
|
||||
}
|
||||
}
|
||||
|
||||
if (needCouponsUserList.size() > 0) {
|
||||
log.info("runCouponsUserStatusTimeOutToExpired update needCouponsUserList.size={}", needCouponsUserList.size());
|
||||
saveOrUpdateBatch(needCouponsUserList);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Long endTime02 = System.currentTimeMillis();
|
||||
log.info("runCouponsUserStatusTimeOutToExpired end second={},mills={}", (endTime02 - startTime01) / 1000, (endTime02 - startTime01) % 1000);
|
||||
}
|
||||
|
||||
private List<CouponHistoryEntity> findListByUseStatus() {
|
||||
List<CouponHistoryEntity> list = this.getBaseMapper().selectList(new QueryWrapper<CouponHistoryEntity>().eq("use_status", 0));
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CouponEntity> appGetCoupon() {
|
||||
|
||||
//获取 当前时间 有效期内的优惠券
|
||||
|
||||
Date date = new Date();
|
||||
|
||||
List<CouponEntity> list = new ArrayList<>();
|
||||
|
||||
List<CouponEntity> couponEntityList = couponService.list(new QueryWrapper<CouponEntity>());
|
||||
|
||||
for (CouponEntity couponEntity : couponEntityList) {
|
||||
Date endTime = couponEntity.getTakeEffectDate();
|
||||
Date enableTime = couponEntity.getTakeEffectDate();
|
||||
// 判断结束日期 是否大于 当前 时间 以及 领取日期 是否 小于当前日期
|
||||
if (endTime.getTime() - date.getTime() > 0 && enableTime.getTime() - date.getTime() <= 0) {
|
||||
list.add(couponEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCouponVo> appGetUserCoupon(Integer userId, String amount,String type) {
|
||||
|
||||
// 查询用户当前 拥有的优惠券
|
||||
// 商品 :0 ,电子书 :1
|
||||
List<CouponHistoryEntity> couponHistoryEntities = null;
|
||||
if("0".equals(type)){
|
||||
couponHistoryEntities = this.getBaseMapper().selectList(new QueryWrapper<CouponHistoryEntity>()
|
||||
.eq("member_id", userId)
|
||||
.eq("use_status", 0)
|
||||
.eq("coupon_pro_type","0")
|
||||
);
|
||||
}else{
|
||||
couponHistoryEntities = this.getBaseMapper().selectList(new QueryWrapper<CouponHistoryEntity>()
|
||||
.eq("member_id", userId)
|
||||
.eq("use_status", 0)
|
||||
.eq("coupon_pro_type","1")
|
||||
);
|
||||
}
|
||||
|
||||
// 可使用优惠券列表
|
||||
ArrayList<UserCouponVo> list = new ArrayList<>();
|
||||
|
||||
for (CouponHistoryEntity couponHistoryEntity : couponHistoryEntities) {
|
||||
Long couponId = couponHistoryEntity.getCouponId();
|
||||
CouponEntity couponEntity = couponService.getById(couponId);
|
||||
// 判断当前优惠券是否过期
|
||||
Date startTime = couponEntity.getExpirationDate();
|
||||
// 判断结束日期 是否大于 当前 时间
|
||||
if (startTime.after(new Date())){
|
||||
if(Integer.parseInt(amount) >= couponEntity.getUseLevel()){
|
||||
UserCouponVo userCouponVo = new UserCouponVo();
|
||||
BeanUtils.copyProperties(couponHistoryEntity, userCouponVo);
|
||||
userCouponVo.setCoupons(couponEntity);
|
||||
list.add(userCouponVo);
|
||||
}
|
||||
// boolean result = couponCanUseCategory(products, couponId, String.valueOf(couponEntity.getCouponType()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
// 判断组合分类 是否 符合优惠券规则
|
||||
private boolean couponCanUseCategory(String products, Long couponId, String userType) {
|
||||
|
||||
List list1 = new ArrayList<>();
|
||||
|
||||
if (!userType.equals("0")) {
|
||||
|
||||
if (userType.equals("1")) {
|
||||
|
||||
List<CouponProductCategoryRelationEntity> couponC = categoryRelationService.getBaseMapper().selectList(new QueryWrapper<CouponProductCategoryRelationEntity>()
|
||||
.eq("coupon_id", couponId));
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
String[] split = products.split(",");
|
||||
for (CouponProductCategoryRelationEntity couponProductCategoryRelationEntity : couponC) {
|
||||
// platform 0 1.判断商品 是否为 同一分类下
|
||||
|
||||
for (String s : split) {
|
||||
// 多商品的 判断商品 是否为同一个分类 下
|
||||
ShopProduct spe = shopProductService.getById(Integer.parseInt(s));
|
||||
Integer productPid = spe.getProductPid();
|
||||
Long productCategoryId = couponProductCategoryRelationEntity.getProductCategoryId();
|
||||
if (productCategoryId.intValue() == productPid) {
|
||||
list.add(productCategoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (split.length == list.size()){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else if (userType.equals("2")) {
|
||||
|
||||
List<CouponProductRelationEntity> couponC = productRelationService.getBaseMapper().selectList(new QueryWrapper<CouponProductRelationEntity>()
|
||||
.eq("coupon_id", couponId));
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
String[] split = products.split(",");
|
||||
for (CouponProductRelationEntity couponProductCategoryRelationEntity : couponC) {
|
||||
// platform 0 1.判断商品 是否为 同一分类下
|
||||
for (String s : split) {
|
||||
// 多商品的 判断商品 是否为同一个分类 下
|
||||
// Long productId = couponProductCategoryRelationEntity.getProductId();
|
||||
Long productId = couponProductCategoryRelationEntity.getProductId();
|
||||
if (Long.parseLong(s) == productId) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (split.length == list.size()){
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.common.dao.CouponProductCategoryRelationDao;
|
||||
import com.peanut.modules.common.entity.CouponProductCategoryRelationEntity;
|
||||
import com.peanut.modules.book.service.CouponProductCategoryRelationService;
|
||||
|
||||
@Slf4j
|
||||
@Service("couponProductCategoryRelationService")
|
||||
public class CouponProductCategoryRelationServiceImpl extends ServiceImpl<CouponProductCategoryRelationDao, CouponProductCategoryRelationEntity> implements CouponProductCategoryRelationService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String couponId = (String) params.get("couponId");
|
||||
IPage<CouponProductCategoryRelationEntity> page = this.page(
|
||||
new Query<CouponProductCategoryRelationEntity>().getPage(params),
|
||||
new QueryWrapper<CouponProductCategoryRelationEntity>().eq("coupon_id",Integer.valueOf(couponId))
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.Map;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.common.dao.CouponProductRelationDao;
|
||||
import com.peanut.modules.common.entity.CouponProductRelationEntity;
|
||||
import com.peanut.modules.book.service.CouponProductRelationService;
|
||||
|
||||
@Slf4j
|
||||
@Service("couponProductRelationService")
|
||||
public class CouponProductRelationServiceImpl extends ServiceImpl<CouponProductRelationDao, CouponProductRelationEntity> implements CouponProductRelationService {
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
String couponId = (String) params.get("couponId");
|
||||
IPage<CouponProductRelationEntity> page = this.page(
|
||||
new Query<CouponProductRelationEntity>().getPage(params),
|
||||
new QueryWrapper<CouponProductRelationEntity>().eq("coupon_id",Integer.valueOf(couponId))
|
||||
);
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.peanut.modules.book.service.impl;
|
||||
|
||||
import com.peanut.common.utils.ExcludeEmptyQueryWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.PageUtils;
|
||||
import com.peanut.common.utils.Query;
|
||||
|
||||
import com.peanut.modules.common.dao.CouponDao;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.book.service.CouponService;
|
||||
|
||||
@Slf4j
|
||||
@Service("couponService")
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> implements CouponService {
|
||||
|
||||
|
||||
@Override
|
||||
public PageUtils queryPage(Map<String, Object> params) {
|
||||
IPage<CouponEntity> page = null;
|
||||
String cu = params.get("currentState").toString();
|
||||
if("0".equals(cu)){
|
||||
page = this.page(
|
||||
new Query<CouponEntity>().getPage(params),
|
||||
new ExcludeEmptyQueryWrapper<CouponEntity>().like("coupon_name",params.get("key"))
|
||||
);
|
||||
}else{
|
||||
page = this.page(
|
||||
new Query<CouponEntity>().getPage(params),
|
||||
new ExcludeEmptyQueryWrapper<CouponEntity>().eq("current_state",cu).like("coupon_name",params.get("key"))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return new PageUtils(page);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -52,10 +52,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
||||
@Autowired
|
||||
private AuthorService authorService;
|
||||
@Autowired
|
||||
private CouponService couponService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
@Autowired
|
||||
private MyUserDao myUserDao;
|
||||
@Autowired
|
||||
private BookForumArticlesService bookForumArticlesService;
|
||||
@@ -272,7 +268,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
||||
return "余额不足,请充值!";
|
||||
}
|
||||
|
||||
CouponEntity coupon = this.couponService.getById(couponId);
|
||||
|
||||
BigDecimal salePrice = new BigDecimal(0);
|
||||
|
||||
@@ -281,21 +276,11 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
||||
BookEntity book = bookService.getById(Integer.valueOf(bookId));
|
||||
|
||||
// 是否为秒杀
|
||||
|
||||
Integer isSale = book.getIsSale();
|
||||
|
||||
if(!ObjectUtils.isEmpty(coupon)){
|
||||
if (isSale == 1) {
|
||||
salePrice = book.getSalePrice().subtract(coupon.getCouponAmount());
|
||||
}else {
|
||||
salePrice = book.getPrice().subtract(coupon.getCouponAmount());
|
||||
}
|
||||
}else{
|
||||
if (isSale == 1) {
|
||||
salePrice = book.getSalePrice();
|
||||
}else {
|
||||
salePrice = book.getPrice();
|
||||
}
|
||||
if (isSale == 1) {
|
||||
salePrice = book.getSalePrice();
|
||||
}else {
|
||||
salePrice = book.getPrice();
|
||||
}
|
||||
|
||||
//查询用户
|
||||
@@ -343,13 +328,6 @@ public class MyUserServiceImpl extends ServiceImpl<MyUserDao, MyUserEntity> impl
|
||||
userEbookBuyEntity.setPayType("point");
|
||||
userEbookBuyEntity.setPayTime(new Date());
|
||||
userEbookBuyService.save(userEbookBuyEntity);
|
||||
if(!ObjectUtils.isEmpty(coupon)){
|
||||
CouponHistoryEntity historyEntity = this.couponHistoryService.getOne(new QueryWrapper<CouponHistoryEntity>().eq("member_id", userId).eq("coupon_id", couponId));
|
||||
historyEntity.setUseStatus(1);
|
||||
this.couponHistoryService.updateById(historyEntity);
|
||||
}
|
||||
|
||||
|
||||
return "购买成功!";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.peanut.modules.book.task;
|
||||
|
||||
import com.peanut.modules.book.service.CouponHistoryService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class CouponsUserScheduleTask {
|
||||
|
||||
@Autowired
|
||||
private CouponHistoryService couponsUserService;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CouponsUserScheduleTask.class);
|
||||
|
||||
// @Scheduled(cron = "0 0/1 * * * ?")//每3分 //crontab -e 动态代替应用命令
|
||||
// public void handlerCouponsUserStatusTimeOutToExpired(){
|
||||
// log.info("handlerCouponsUserStatusTimeOutToExpired start.......time={}",System.currentTimeMillis());
|
||||
// Long startTime01 = System.currentTimeMillis();
|
||||
// couponsUserService.runCouponsUserStatusTimeOutToExpired();
|
||||
// Long endTime02 = System.currentTimeMillis();
|
||||
// log.info("handlerCouponsUserStatusTimeOutToExpired end second={},mills={}",(endTime02-startTime01)/1000,(endTime02-startTime01)%1000);
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.peanut.modules.book.vo;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
@Data
|
||||
public class UserCouponVo {
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
private Long memberId;
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 优惠券码
|
||||
*/
|
||||
private String couponCode;
|
||||
/**
|
||||
* 领取人昵称
|
||||
*/
|
||||
private String memberNickname;
|
||||
/**
|
||||
* 获取类型:0->后台赠送;1->主动获取
|
||||
*/
|
||||
private Integer getType;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private Date createTime;
|
||||
/**
|
||||
* 使用状态:0->未使用;1->已使用;2->已过期
|
||||
*/
|
||||
private Integer useStatus;
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private Date useTime;
|
||||
/**
|
||||
* 订单号码
|
||||
*/
|
||||
private String orderSn;
|
||||
|
||||
private CouponEntity coupons;
|
||||
}
|
||||
@@ -71,10 +71,6 @@ public class BuyOrderResponseVo {
|
||||
* 收货人信息
|
||||
*/
|
||||
private ConsigneeVo consignee;
|
||||
/**
|
||||
* 优惠券
|
||||
*/
|
||||
private CouponResponseVo coupon;
|
||||
/**
|
||||
* 用户信息
|
||||
*/
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
package com.peanut.modules.book.vo.response;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Description: 优惠券 Value Object
|
||||
* @Author: Cauchy
|
||||
* @CreateTime: 2023/10/20
|
||||
*/
|
||||
@Data
|
||||
public class CouponResponseVo {
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
String couponName;
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
Integer couponId;
|
||||
|
||||
BigDecimal couponAmount;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponDao extends BaseMapper<CouponEntity> {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,9 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponHistoryEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponHistoryDao extends BaseMapper<CouponHistoryEntity> {
|
||||
|
||||
public interface CouponHistoryDao extends BaseMapper<CouponHistory> {
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductCategoryRelationEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponProductCategoryRelationDao extends BaseMapper<CouponProductCategoryRelationEntity> {
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.peanut.modules.common.dao;
|
||||
|
||||
import com.peanut.modules.common.entity.CouponProductRelationEntity;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Mapper
|
||||
public interface CouponProductRelationDao extends BaseMapper<CouponProductRelationEntity> {
|
||||
|
||||
}
|
||||
@@ -4,105 +4,69 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon")
|
||||
public class CouponEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@TableName("coupon")
|
||||
public class CouponEntity {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 优惠券类型 0:现金,1:折扣
|
||||
*/
|
||||
private Integer couponType;
|
||||
//优惠券类型 0现金 1折扣
|
||||
private Integer couponType;
|
||||
|
||||
/**
|
||||
* 优惠券名称
|
||||
*/
|
||||
private String couponName;
|
||||
//优惠卷范围 0无限制 1课程卷 2课程品类卷
|
||||
private Integer couponRange;
|
||||
|
||||
/**
|
||||
* 优惠券面额
|
||||
*/
|
||||
private BigDecimal couponAmount;
|
||||
//范围详情(课程卷是课程id,分割;课程品类卷是课程分类根id)
|
||||
private String rangeInfo;
|
||||
|
||||
/**
|
||||
* 优惠券封面图
|
||||
*/
|
||||
private String couponUrl;
|
||||
//优惠券名称
|
||||
private String couponName;
|
||||
|
||||
/**
|
||||
* 每人限领
|
||||
*/
|
||||
private Integer limitedCollar;
|
||||
//优惠券面额
|
||||
private BigDecimal couponAmount;
|
||||
|
||||
/**
|
||||
* 时效
|
||||
*/
|
||||
private String validity;
|
||||
//优惠券封面
|
||||
private String couponUrl;
|
||||
|
||||
/**
|
||||
* 生效方式 0:领取日生效 1: 设置生效日期
|
||||
*/
|
||||
private Integer takeEffectType;
|
||||
//每人限领
|
||||
private Integer limitedCollar;
|
||||
|
||||
/**
|
||||
* 生效日期
|
||||
*/
|
||||
private Date takeEffectDate;
|
||||
//生效方式 0长期有效 1领取生效 2自定义
|
||||
private Integer effectType;
|
||||
|
||||
/**
|
||||
* 截止日期
|
||||
*/
|
||||
private Date expirationDate;
|
||||
//时效(天)
|
||||
private Integer validity;
|
||||
|
||||
/**
|
||||
* 总发行数量
|
||||
*/
|
||||
public Integer totalCirculation;
|
||||
//生效日期
|
||||
private Date effectTime;
|
||||
|
||||
/**
|
||||
* 当前状态 0:全部,1:生效,2:已过期
|
||||
*/
|
||||
private String currentState;
|
||||
//截止日期
|
||||
private Date expireTime;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
//总发行数量
|
||||
private Integer totalCirculation;
|
||||
|
||||
/**
|
||||
* 删除标志
|
||||
*/
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
//当前状态 0 发放中 1结束
|
||||
private Integer currentState;
|
||||
|
||||
/**
|
||||
* 商品类型 0: 商品 ,1电子书
|
||||
*/
|
||||
private Integer couponProType;
|
||||
//备注
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 使用门槛
|
||||
*/
|
||||
private Integer useLevel;
|
||||
//使用门槛
|
||||
private Integer useLevel;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<Object> rangeList;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@TableName("coupon_history")
|
||||
public class CouponHistory {
|
||||
|
||||
@TableId
|
||||
private Integer id;
|
||||
|
||||
//优惠券id
|
||||
private Integer couponId;
|
||||
|
||||
//用户id
|
||||
private Integer userId;
|
||||
|
||||
//订单id
|
||||
private Integer orderId;
|
||||
|
||||
//获取类型 0 后台赠送 1 主动获取
|
||||
private Integer getType;
|
||||
|
||||
//使用状态 0 未使用 1 已使用 2 已过期
|
||||
private Integer status;
|
||||
|
||||
//生效方式 0长期有效 1领取生效 2自定义
|
||||
private Integer effectType;
|
||||
|
||||
//生效时间
|
||||
private Date startTime;
|
||||
|
||||
//失效时间
|
||||
private Date endTime;
|
||||
|
||||
//使用时间
|
||||
private Date useTime;
|
||||
|
||||
private Date createTime;
|
||||
|
||||
@TableLogic
|
||||
private Integer delFlag;
|
||||
|
||||
@TableField(exist = false)
|
||||
private CouponEntity couponEntity;
|
||||
@TableField(exist = false)
|
||||
private MyUserEntity userEntity;
|
||||
@TableField(exist = false)
|
||||
private BuyOrder buyOrder;
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_history")
|
||||
public class CouponHistoryEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 会员id
|
||||
*/
|
||||
private Long memberId;
|
||||
/**
|
||||
* 订单id
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 优惠券码
|
||||
*/
|
||||
private String couponCode;
|
||||
/**
|
||||
* 领取人昵称
|
||||
*/
|
||||
private String memberNickname;
|
||||
/**
|
||||
* 获取类型:0->后台赠送;1->主动获取
|
||||
*/
|
||||
private Integer getType;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)//创建注解
|
||||
private Date createTime;
|
||||
/**
|
||||
* 使用状态:0->未使用;1->已使用;2->已过期
|
||||
*/
|
||||
private Integer useStatus;
|
||||
/**
|
||||
* 使用时间
|
||||
*/
|
||||
private Date useTime;
|
||||
/**
|
||||
* 订单号码
|
||||
*/
|
||||
private String orderSn;
|
||||
|
||||
@TableField(exist = false)
|
||||
private String couponName;
|
||||
|
||||
|
||||
/**
|
||||
* 商品类型 0: 商品 ,1电子书
|
||||
*/
|
||||
private Integer couponProType;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_product_category_relation")
|
||||
public class CouponProductCategoryRelationEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 商品分类id
|
||||
*/
|
||||
private Long productCategoryId;
|
||||
/**
|
||||
* 商品分类名称
|
||||
*/
|
||||
private String productCategoryName;
|
||||
/**
|
||||
* 父分类名称
|
||||
*/
|
||||
private String parentCategoryName;
|
||||
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.peanut.modules.common.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author yl
|
||||
* @email yl328572838@163.com
|
||||
* @date 2022-10-28 17:38:29
|
||||
*/
|
||||
@Data
|
||||
@TableName("sms_coupon_product_relation")
|
||||
public class CouponProductRelationEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 优惠券id
|
||||
*/
|
||||
private Long couponId;
|
||||
/**
|
||||
* 商品id
|
||||
*/
|
||||
private Long productId;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String productName;
|
||||
/**
|
||||
* 商品条码
|
||||
*/
|
||||
private String productSn;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
|
||||
public interface CouponHistoryService extends IService<CouponHistory> {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.common.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
|
||||
public interface CouponService extends IService<CouponEntity> {
|
||||
|
||||
CouponEntity setRangeList(CouponEntity couponEntity);
|
||||
|
||||
R insertCouponHistory(int couponId, int userId,int getType);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonCouponHistoryService")
|
||||
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryDao, CouponHistory> implements CouponHistoryService {
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.peanut.modules.common.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.peanut.common.utils.DateUtil;
|
||||
import com.peanut.common.utils.DateUtils;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.config.DelayQueueConfig;
|
||||
import com.peanut.modules.common.dao.CouponDao;
|
||||
import com.peanut.modules.common.dao.CouponHistoryDao;
|
||||
import com.peanut.modules.common.dao.CourseDao;
|
||||
import com.peanut.modules.common.dao.CourseMedicineDao;
|
||||
import com.peanut.modules.common.entity.CouponEntity;
|
||||
import com.peanut.modules.common.entity.CouponHistory;
|
||||
import com.peanut.modules.common.service.CouponService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.amqp.core.MessagePostProcessor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service("commonCouponService")
|
||||
public class CouponServiceImpl extends ServiceImpl<CouponDao, CouponEntity> implements CouponService {
|
||||
|
||||
@Autowired
|
||||
private CouponDao couponDao;
|
||||
@Autowired
|
||||
private CouponHistoryDao couponHistoryDao;
|
||||
@Autowired
|
||||
private CourseDao courseDao;
|
||||
@Autowired
|
||||
private CourseMedicineDao courseMedicineDao;
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Override
|
||||
public CouponEntity setRangeList(CouponEntity couponEntity) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
if (StringUtils.isNotEmpty(couponEntity.getRangeInfo())){
|
||||
String[] arr = couponEntity.getRangeInfo().split(",");
|
||||
for (String str : arr) {
|
||||
if (couponEntity.getCouponRange()==1){
|
||||
list.add(courseDao.selectById(Integer.parseInt(str)));
|
||||
}else {
|
||||
list.add(courseMedicineDao.selectById(Integer.parseInt(str)));
|
||||
}
|
||||
}
|
||||
}
|
||||
couponEntity.setRangeList(list);
|
||||
return couponEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public R insertCouponHistory(int couponId, int userId,int getType) {
|
||||
CouponEntity couponEntity = couponDao.selectById(couponId);
|
||||
int historyCount = couponHistoryDao.selectCount(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (historyCount<couponEntity.getTotalCirculation()){
|
||||
List<CouponHistory> historyList = couponHistoryDao.selectList(new LambdaQueryWrapper<CouponHistory>()
|
||||
.eq(CouponHistory::getUserId,userId)
|
||||
.eq(CouponHistory::getCouponId,couponId));
|
||||
if (historyList.size()<couponEntity.getLimitedCollar()){
|
||||
CouponHistory couponHistory = new CouponHistory();
|
||||
couponHistory.setCouponId(couponId);
|
||||
couponHistory.setUserId(userId);
|
||||
couponHistory.setGetType(getType);
|
||||
couponHistory.setEffectType(couponEntity.getEffectType());
|
||||
if (couponEntity.getEffectType()==1){
|
||||
couponHistory.setStartTime(new Date());
|
||||
couponHistory.setEndTime(DateUtils.addDateDays(new Date(),couponEntity.getValidity()));
|
||||
}else if (couponEntity.getEffectType()==2){
|
||||
couponHistory.setStartTime(couponEntity.getEffectTime());
|
||||
couponHistory.setEndTime(couponEntity.getExpireTime());
|
||||
}
|
||||
couponHistoryDao.insert(couponHistory);
|
||||
//发放完优惠卷设置过期
|
||||
rabbitTemplate.convertAndSend(
|
||||
DelayQueueConfig.COMMON_EXCHANGE,
|
||||
DelayQueueConfig.COMMON_ROUTING_KEY,
|
||||
"couponExpire"+","+couponHistory.getId(),
|
||||
messagePostProcessor(couponHistory.getEndTime().getTime()-new Date().getTime())
|
||||
);
|
||||
return R.ok();
|
||||
}else {
|
||||
return R.error("每人限领"+couponEntity.getLimitedCollar()+"张");
|
||||
}
|
||||
}else {
|
||||
return R.error("优惠卷已放完");
|
||||
}
|
||||
}
|
||||
|
||||
private MessagePostProcessor messagePostProcessor(long date) {
|
||||
return message -> {
|
||||
message.getMessageProperties().setDelay((int)date);
|
||||
return message;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,9 +28,9 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
String endYear,String endMonth,String endDay) {
|
||||
String url = "";
|
||||
if ("A".equals(type)){
|
||||
url = generateACertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
url = generateACertificate(certificateNo, iconUrl, realName, des, endYear+"年"+endMonth+"月"+endDay+"日");
|
||||
}else if ("B".equals(type)) {
|
||||
url = generateBCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
url = generateBCertificate(certificateNo, iconUrl, realName, des, endYear+"年"+endMonth+"月"+endDay+"日");
|
||||
}else if ("ZK".equals(type)){
|
||||
url = generateZKCertificate(certificateNo, iconUrl, realName, des, endYear, endMonth, endDay);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
public String generateBCertificate(String no,String iconUrl,String name,String[] des,String endy,String endm,String endd) {
|
||||
public String generateBCertificate(String no,String iconUrl,String name,String[] des,String endYMD) {
|
||||
try {
|
||||
Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/B.png"));
|
||||
// 获取图片的高和宽
|
||||
@@ -137,14 +137,14 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
|
||||
if (StringUtils.isNotBlank(iconUrl)){
|
||||
Image images = ImageIO.read(new URL(iconUrl));
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,400,245,280,null);
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,400,245,275,null);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("宋体", Font.BOLD, 40));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 730;
|
||||
int namey = 720;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
String[] str = {"自","年","月","日至","年","月","日在太湖学堂","学习,修完","课程,共计","学时,确认合格。"};
|
||||
@@ -178,10 +178,8 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
g.setFont(new Font("黑体", Font.BOLD, 28));
|
||||
g.drawString(endy,600,1158);
|
||||
g.drawString(endm,695,1158);
|
||||
g.drawString(endd,748,1158);
|
||||
g.setFont(new Font("黑体", Font.BOLD, 30));
|
||||
g.drawString(endYMD,630,1188);
|
||||
// 释放资源
|
||||
g.dispose();
|
||||
File tempFile = File.createTempFile("tempfile_"+UUID.randomUUID().toString(), ".jpg");
|
||||
@@ -194,7 +192,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
}
|
||||
}
|
||||
|
||||
public String generateACertificate(String no,String iconUrl,String name,String[] des,String endy,String endm,String endd) {
|
||||
public String generateACertificate(String no,String iconUrl,String name,String[] des,String endYMD) {
|
||||
try {
|
||||
Image src = ImageIO.read(new URL("https://ehh-private-01.oss-cn-beijing.aliyuncs.com/certificate/A.png"));
|
||||
// 获取图片的高和宽
|
||||
@@ -216,14 +214,14 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
|
||||
if (StringUtils.isNotBlank(iconUrl)){
|
||||
Image images = ImageIO.read(new URL(iconUrl));
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,480,245,280,null);
|
||||
g.drawImage(images,(wideth-images.getWidth(null))/2,490,245,280,null);
|
||||
}
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("宋体", Font.BOLD, 50));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 815;
|
||||
int namey = 840;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
String[] str = {"自","年","月","日至","年","月","日在太湖学堂","学习,修完","课程,共计","学时,确认合格。"};
|
||||
@@ -241,7 +239,7 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
desTotalWidth = oneWordWidth;
|
||||
}
|
||||
g.setFont(new Font("宋体", Font.PLAIN, 32));
|
||||
g.drawString(str[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,860+alreadyWriteLine*(dess.getHeight()+20));
|
||||
g.drawString(str[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,890+alreadyWriteLine*(dess.getHeight()+20));
|
||||
}
|
||||
if (j<des.length){
|
||||
for (int k=0;k<des[j].length(); k++){
|
||||
@@ -252,15 +250,13 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
desTotalWidth = oneWordWidth;
|
||||
}
|
||||
g.setFont(new Font("黑体", Font.BOLD, 32));
|
||||
g.drawString(des[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,860+alreadyWriteLine*(dess.getHeight()+20));
|
||||
g.drawString(des[j].charAt(k)+"",180+desTotalWidth-oneWordWidth,890+alreadyWriteLine*(dess.getHeight()+20));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.setFont(new Font("黑体", Font.BOLD, 28));
|
||||
g.drawString(endy,605,1185);
|
||||
g.drawString(endm,715,1185);
|
||||
g.drawString(endd,780,1185);
|
||||
g.setFont(new Font("黑体", Font.BOLD, 32));
|
||||
g.drawString(endYMD,605,1255);
|
||||
|
||||
// 释放资源
|
||||
g.dispose();
|
||||
@@ -290,19 +286,19 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
g.setFont(new Font("Arial", Font.BOLD, 48));
|
||||
FontMetrics metrics = g.getFontMetrics();
|
||||
int nox = (wideth - metrics.stringWidth(no))/2;
|
||||
int noy = 500;
|
||||
int noy = 460;
|
||||
g.drawString(no, nox, noy);
|
||||
|
||||
g.setColor(Color.BLACK);
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 58));
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 60));
|
||||
FontMetrics metricss = g.getFontMetrics();
|
||||
//转换成拼音
|
||||
name = nameToPinyin(name);
|
||||
int namex = (wideth - metricss.stringWidth(name))/2;
|
||||
int namey = 660;
|
||||
int namey = 580;
|
||||
g.drawString(name, namex, namey);
|
||||
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 30));
|
||||
g.setFont(new Font("Arial", Font.PLAIN, 32));
|
||||
FontMetrics dess = g.getFontMetrics();
|
||||
int alreadyWriteLine = 0; //已经写了多少行
|
||||
int nowWidth = 0; //目前一行的长度
|
||||
@@ -317,13 +313,13 @@ public class UserCertificateServiceImpl extends ServiceImpl<UserCertificateDao,
|
||||
int oneWordWidth = dess.charWidth(des.charAt(i)); //获取单个字符的长度
|
||||
if (nowWidth+oneWordWidth>700){//换行画
|
||||
alreadyWriteLine++;
|
||||
int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
g.drawString(des.charAt(i) + "", 155, writeY);
|
||||
nowWidth = 0;
|
||||
space = false;
|
||||
nowWidth += oneWordWidth;
|
||||
}else {//一字一字画
|
||||
int writeY = 780 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
int writeY = 700 + alreadyWriteLine * (dess.getHeight()+10);//10是行间距
|
||||
if (nowWidth==0&&space){//首行空一格
|
||||
g.drawString(des.charAt(i)+"", 155+oneWordWidth, writeY);
|
||||
nowWidth += oneWordWidth*2;
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.peanut.modules.common.dao.*;
|
||||
import com.peanut.modules.common.entity.*;
|
||||
import com.peanut.modules.common.service.ClassEntityService;
|
||||
import com.peanut.modules.common.service.ClassExamService;
|
||||
import com.peanut.modules.common.service.CouponHistoryService;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -34,6 +35,8 @@ public class CommonConsumer {
|
||||
private UserCourseBuyDao userCourseBuyDao;
|
||||
@Autowired
|
||||
private ClassEntityService classEntityService;
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@RabbitListener(queues = DelayQueueConfig.COMMON_QUEUE)
|
||||
public void commonConsumer(String typeAndParam) {
|
||||
@@ -76,11 +79,14 @@ public class CommonConsumer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
//优惠卷过期
|
||||
if ("couponExpire".equals(typeAndParams[0])){
|
||||
CouponHistory couponHistory = couponHistoryService.getById(typeAndParams[1]);
|
||||
if (couponHistory != null&&couponHistory.getStatus()==0) {
|
||||
couponHistory.setStatus(2);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class AppController {
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(order.getId());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
transactionDetailsEntity.setRemark("苹果充值:"+order.getTransactionId());
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
transactionDetailsEntity.setUserBalance(peanutCoin);
|
||||
|
||||
@@ -193,7 +193,7 @@ public class AliPayServiceImpl implements AliPayService {
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(oldPayZfbOrderEntity.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
transactionDetailsEntity.setRemark("支付宝充值:"+oldPayZfbOrderEntity.getRelevanceoid());
|
||||
|
||||
MyUserEntity user = userService.getById(Integer.valueOf(customerid));
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
|
||||
@@ -25,9 +25,6 @@ public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderDao, Pa
|
||||
@Autowired
|
||||
private BuyOrderService buyOrderService;
|
||||
|
||||
@Autowired
|
||||
private CouponHistoryService couponHistoryService;
|
||||
|
||||
@Autowired
|
||||
private BuyOrderProductService buyOrderProductService;
|
||||
|
||||
@@ -84,13 +81,6 @@ public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderDao, Pa
|
||||
|
||||
@Override
|
||||
public void businessOpt(BuyOrder order) {
|
||||
//优惠卷回滚
|
||||
if (order.getCouponId() != null) {
|
||||
Integer couponId = order.getCouponId();
|
||||
CouponHistoryEntity couponHistory = couponHistoryService.getById(couponId);
|
||||
couponHistory.setUseStatus(0);
|
||||
couponHistoryService.updateById(couponHistory);
|
||||
}
|
||||
//查询订单所有商品
|
||||
QueryWrapper<BuyOrderProduct> w1 = new QueryWrapper<>();
|
||||
w1.eq("order_id", order.getOrderId());
|
||||
|
||||
@@ -264,7 +264,7 @@ public class WxpayServiceImpl extends ServiceImpl<PayWechatOrderDao, PayWechatOr
|
||||
transactionDetailsEntity.setChangeAmount(new BigDecimal(money));
|
||||
transactionDetailsEntity.setOrderType("充值");
|
||||
transactionDetailsEntity.setRelationId(buy_order_id.getId().intValue());
|
||||
transactionDetailsEntity.setRemark("充值");
|
||||
transactionDetailsEntity.setRemark("微信充值:"+order.getOrderSn());
|
||||
|
||||
MyUserEntity user = userService.getById(order.getUserId());
|
||||
BigDecimal peanutCoin = user.getPeanutCoin();
|
||||
|
||||
Reference in New Issue
Block a user