@ -16,9 +16,11 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import com.baomidou.mybatisplus.core.toolkit.Wrappers ;
import org.dromara.system.domain.BusinessCoupon ;
import org.dromara.system.domain.BusinessCoupon ;
import org.dromara.system.domain.ProductOrder ;
import org.dromara.system.domain.bo.* ;
import org.dromara.system.domain.bo.* ;
import org.dromara.system.domain.vo.* ;
import org.dromara.system.domain.vo.* ;
import org.dromara.system.mapper.BusinessCouponMapper ;
import org.dromara.system.mapper.BusinessCouponMapper ;
import org.dromara.system.mapper.ProductOrderMapper ;
import org.dromara.system.service.IAppBusinessProductService ;
import org.dromara.system.service.IAppBusinessProductService ;
import org.dromara.system.service.IAppBusinessTypeService ;
import org.dromara.system.service.IAppBusinessTypeService ;
import org.dromara.system.service.IBusinessCouponService ;
import org.dromara.system.service.IBusinessCouponService ;
@ -55,6 +57,8 @@ public class BusinessCouponTemplateServiceImpl implements IBusinessCouponTemplat
@Resource
@Resource
private IAppBusinessTypeService appBusinessTypeService ;
private IAppBusinessTypeService appBusinessTypeService ;
@Resource
private ProductOrderMapper productOrderMapper ;
//构造范围信息
//构造范围信息
private void buildProductScopeInfo ( BusinessCouponTemplateVo businessCouponVo ) {
private void buildProductScopeInfo ( BusinessCouponTemplateVo businessCouponVo ) {
if ( StringUtils . isNotBlank ( businessCouponVo . getProductScope ( ) ) ) {
if ( StringUtils . isNotBlank ( businessCouponVo . getProductScope ( ) ) ) {
@ -150,8 +154,23 @@ public class BusinessCouponTemplateServiceImpl implements IBusinessCouponTemplat
lqw . apply ( bo . getEffective ( ) ! = null & & bo . getEffective ( ) ,
lqw . apply ( bo . getEffective ( ) ! = null & & bo . getEffective ( ) ,
"date_format(valid_start_time , '%y-%m-%d') <= date_format(now(), '%y-%m-%d') and date_format(valid_end_time , '%y-%m-%d') >= date_format(now(), '%y-%m-%d') and (total_count >= take_count or total_count = -1) " ) ;
"date_format(valid_start_time , '%y-%m-%d') <= date_format(now(), '%y-%m-%d') and date_format(valid_end_time , '%y-%m-%d') >= date_format(now(), '%y-%m-%d') and (total_count >= take_count or total_count = -1) " ) ;
//用户可领取
//用户可领取
lqw . apply ( bo . getCanTake ( ) ! = null & & bo . getCanTake ( ) & & bo . getUserId ( ) ! = null ,
lqw . apply ( bo . getCanTake ( ) ! = null & & bo . getCanTake ( ) ,
" (total_count = -1 or total_count > 0) and (take_limit_count = -1 or take_limit_count >= (select count(bc.id) from business_coupon bc where bc.template_id = id and bc.user_id = {0} and bc.del_flag = '0' )) " , bo . getUserId ( ) ) ;
" (total_count = -1 or total_count > 0)" ) ;
if ( bo . getUserId ( ) ! = null & & bo . getUserId ( ) ! = 0L ) {
LambdaQueryWrapper < ProductOrder > queryWrapper = new LambdaQueryWrapper < > ( ) ;
queryWrapper . eq ( ProductOrder : : getBusinessId , bo . getBusinessId ( ) ) ;
queryWrapper . eq ( ProductOrder : : getIsPay , "1" ) ;
Long count = productOrderMapper . selectCount ( queryWrapper ) ;
lqw . apply ( bo . getCanTake ( ) ! = null & & bo . getCanTake ( ) ,
" (take_limit_count = -1 or take_limit_count >= (select count(bc.id) from business_coupon bc where bc.template_id = id and bc.user_id = {0} and bc.del_flag = '0' )) " +
" and ( product_scope_type in (1, 2, 3, 4) or ( product_scope_type = 5 and 0 = {1}))" , bo . getUserId ( ) , count ) ;
} else if ( bo . getUserId ( ) ! = null ) {
lqw . apply ( bo . getCanTake ( ) ! = null & & bo . getCanTake ( ) ,
" (take_limit_count = -1 )" ) ;
}
if ( bo . getLimit ( ) ! = null & & bo . getLimit ( ) > 0 ) {
if ( bo . getLimit ( ) ! = null & & bo . getLimit ( ) > 0 ) {
lqw . last ( "limit " + bo . getLimit ( ) ) ;
lqw . last ( "limit " + bo . getLimit ( ) ) ;
}
}