|
|
@@ -11,11 +11,16 @@ import com.sqx.common.utils.Result;
|
|
|
import com.sqx.modules.coupon.dao.TbCouponDao;
|
|
|
import com.sqx.modules.coupon.dao.TbCouponUserDao;
|
|
|
import com.sqx.modules.coupon.entity.TbCoupon;
|
|
|
+import com.sqx.modules.coupon.entity.TbCouponLog;
|
|
|
+import com.sqx.modules.coupon.service.TbCouponLogService;
|
|
|
import com.sqx.modules.coupon.service.TbCouponService;
|
|
|
import com.sqx.modules.datacentre.entity.SysUserShop;
|
|
|
+import com.sqx.modules.sys.entity.SysUserEntity;
|
|
|
import com.sqx.modules.sys.entity.SysUserRoleEntity;
|
|
|
import com.sqx.modules.sys.service.SysUserRoleService;
|
|
|
+import com.sqx.modules.sys.service.SysUserService;
|
|
|
import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -36,6 +41,12 @@ public class TbCouponServiceImpl extends ServiceImpl<TbCouponDao, TbCoupon> impl
|
|
|
@Autowired
|
|
|
private SysUserRoleService sysUserRoleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TbCouponLogService tbCouponLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserService sysUserService;
|
|
|
+
|
|
|
@Override
|
|
|
public Result seleteAllCoupon(Integer page, Integer limit,Long shopId,String shopName) {
|
|
|
if(page == null || limit==null){
|
|
|
@@ -51,25 +62,53 @@ public class TbCouponServiceImpl extends ServiceImpl<TbCouponDao, TbCoupon> impl
|
|
|
|
|
|
@Override
|
|
|
public Result issueCoupon(TbCoupon tbCoupon) {
|
|
|
- Integer sysUserId = tbCoupon.getSysUserId();
|
|
|
+ Long shopId = tbCoupon.getShopId();
|
|
|
+ if (shopId==0) {
|
|
|
+ Integer sysUserId = tbCoupon.getSysUserId();
|
|
|
// 判断是否是超级管理员
|
|
|
- LambdaQueryWrapper<SysUserRoleEntity> wrapper=new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(SysUserRoleEntity::getRoleId,3)
|
|
|
- .eq(SysUserRoleEntity::getUserId,sysUserId);
|
|
|
- SysUserRoleEntity sysUserRoleEntity = sysUserRoleService.getOne(wrapper);
|
|
|
- if (ObjectUtils.isEmpty(sysUserRoleEntity)) {
|
|
|
- tbCoupon.setState(0);
|
|
|
+ LambdaQueryWrapper<SysUserRoleEntity> wrapper=new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(SysUserRoleEntity::getRoleId,3)
|
|
|
+ .eq(SysUserRoleEntity::getUserId,sysUserId);
|
|
|
+ SysUserRoleEntity sysUserRoleEntity = sysUserRoleService.getOne(wrapper);
|
|
|
+ if (ObjectUtils.isEmpty(sysUserRoleEntity)) {
|
|
|
+ tbCoupon.setState(0);
|
|
|
+ }else {
|
|
|
+ tbCoupon.setState(1);
|
|
|
+ }
|
|
|
+ tbCoupon.setDeleteFlag(0);
|
|
|
+ tbCouponDao.insert(tbCoupon);
|
|
|
+
|
|
|
+ TbCouponLog tbCouponLog = new TbCouponLog();
|
|
|
+ BeanUtils.copyProperties(tbCoupon,tbCouponLog);
|
|
|
+ tbCouponLog.setContent("添加优惠券");
|
|
|
+ tbCouponLog.setCreateTime(new Date());
|
|
|
+ tbCouponLog.setCreateSysUserId(sysUserId);
|
|
|
+ tbCouponLogService.save(tbCouponLog);
|
|
|
+
|
|
|
}else {
|
|
|
- tbCoupon.setState(1);
|
|
|
+ tbCoupon.setDeleteFlag(0);
|
|
|
+ tbCouponDao.insert(tbCoupon);
|
|
|
}
|
|
|
|
|
|
- tbCoupon.setDeleteFlag(0);
|
|
|
- tbCouponDao.insert(tbCoupon);
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Result updateCoupon(TbCoupon tbCoupon) {
|
|
|
+ Long shopId = tbCoupon.getShopId();
|
|
|
+ if (shopId==0) {
|
|
|
+ Integer sysUserId = tbCoupon.getSysUserId();
|
|
|
+
|
|
|
+ TbCouponLog tbCouponLog = new TbCouponLog();
|
|
|
+ BeanUtils.copyProperties(tbCoupon,tbCouponLog);
|
|
|
+ tbCouponLog.setContent("修改优惠券");
|
|
|
+ tbCouponLog.setCreateTime(new Date());
|
|
|
+ tbCouponLog.setCreateSysUserId(sysUserId);
|
|
|
+ tbCouponLogService.save(tbCouponLog);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
tbCouponDao.updateById(tbCoupon);
|
|
|
return Result.success();
|
|
|
}
|
|
|
@@ -77,7 +116,7 @@ public class TbCouponServiceImpl extends ServiceImpl<TbCouponDao, TbCoupon> impl
|
|
|
@Override
|
|
|
public Result selectCouponList(Integer page, Integer limit,Long shopId) {
|
|
|
Page<TbCoupon> pages = new Page<>(page, limit);
|
|
|
- PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages, new QueryWrapper<TbCoupon>().eq(shopId!=null,"shop_id",shopId).eq("delete_flag", 0)));
|
|
|
+ PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages, new QueryWrapper<TbCoupon>().eq(shopId!=null,"shop_id",shopId).eq("delete_flag", 0).eq("state",1)));
|
|
|
return Result.success().put("data", pageUtils);
|
|
|
}
|
|
|
|
|
|
@@ -128,14 +167,59 @@ public class TbCouponServiceImpl extends ServiceImpl<TbCouponDao, TbCoupon> impl
|
|
|
}
|
|
|
tbCoupon.setState(state);
|
|
|
tbCouponDao.updateById(tbCoupon);
|
|
|
+
|
|
|
+ TbCouponLog tbCouponLog = new TbCouponLog();
|
|
|
+ BeanUtils.copyProperties(tbCoupon,tbCouponLog);
|
|
|
+ if (state==1) {
|
|
|
+ tbCouponLog.setContent("发布优惠券");
|
|
|
+ }else {
|
|
|
+ tbCouponLog.setContent("撤销优惠券");
|
|
|
+ }
|
|
|
+ tbCouponLog.setCreateTime(new Date());
|
|
|
+ tbCouponLog.setCreateSysUserId(sysUserId);
|
|
|
+ tbCouponLogService.save(tbCouponLog);
|
|
|
+
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Result deleteCoupon(Long couponId) {
|
|
|
+ public Result selectAdminCoupon(Integer page, Integer limit, Integer state) {
|
|
|
+ if(page == null || limit==null){
|
|
|
+ LambdaQueryWrapper<TbCoupon> wrapper=new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TbCoupon::getShopId,0)
|
|
|
+ .eq(ObjectUtils.isNotEmpty(state),TbCoupon::getState,state);
|
|
|
+ List<TbCoupon> tbCoupons = baseMapper.selectList(wrapper);
|
|
|
+ return Result.success().put("data",tbCoupons);
|
|
|
+ }else{
|
|
|
+ Page<TbCoupon> pages = new Page<>(page, limit);
|
|
|
+ LambdaQueryWrapper<TbCoupon> wrapper=new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(TbCoupon::getShopId,0)
|
|
|
+ .eq(ObjectUtils.isNotEmpty(state),TbCoupon::getState,state);
|
|
|
+ PageUtils pageUtils = new PageUtils(baseMapper.selectPage(pages,wrapper));
|
|
|
+ return Result.success().put("data", pageUtils);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Result deleteCoupon(Long couponId,Integer sysUserId) {
|
|
|
+ TbCoupon tbCoupon = tbCouponDao.selectById(couponId);
|
|
|
+ if (ObjectUtils.isEmpty(tbCoupon)) {
|
|
|
+ return Result.error("无该优惠券");
|
|
|
+ }
|
|
|
+ Long shopId = tbCoupon.getShopId();
|
|
|
+ if (shopId==0) {
|
|
|
+ TbCouponLog tbCouponLog = new TbCouponLog();
|
|
|
+ BeanUtils.copyProperties(tbCoupon,tbCouponLog);
|
|
|
+ tbCouponLog.setContent("删除优惠券");
|
|
|
+ tbCouponLog.setCreateTime(new Date());
|
|
|
+ tbCouponLog.setCreateSysUserId(sysUserId);
|
|
|
+ tbCouponLogService.save(tbCouponLog);
|
|
|
+
|
|
|
+ }
|
|
|
tbCouponDao.deleteById(couponId);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
}
|