收银行查询逻辑

This commit is contained in:
Vinjor 2024-09-22 14:57:08 +08:00
parent 76407ff2ca
commit f71acc410c
24 changed files with 1185 additions and 24 deletions

View File

@ -0,0 +1,58 @@
package com.fuint.business.marketingActivity.activePrice.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
* 分时优惠显示特价活动用户参与记录表
* @author : vinjor-m
* @date : 2024-9-21
*/
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("active_price_record")
public class ActivePriceRecord extends Model<ActivePriceRecord> {
/** 主键id */
@TableId(type = IdType.AUTO)
private Integer id ;
/** 活动id */
private Integer actId ;
/** 活动规则id */
private Integer ruleId ;
/** 所属店铺id */
private Integer storeId ;
/** 用户id */
private Integer userId ;
/** 订单id主订单表 */
private Integer orderId ;
/** 活动名称,冗余字段 */
private String actName ;
/** 活动规则名称,冗余字段 */
private String ruleName ;
/** 活动类型1分时优惠|2限时特价 */
private String actType ;
/** 优惠金额(元) */
private Double disAmount ;
/** 创建人 */
private String createBy ;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
private Date createTime ;
/** 更新人 */
private String updateBy ;
/** 更新时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss" , timezone = "GMT+8")
private Date updateTime ;
public static final String ACT_TYPE_1 = "1";
public static final String ACT_TYPE_2 = "2";
public static final String ACT_TYPE_1_TEXT = "分时优惠";
public static final String ACT_TYPE_2_TEXT = "限时特价";
}

View File

@ -0,0 +1,23 @@
package com.fuint.business.marketingActivity.activePrice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePrice;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceReqVO;
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRespVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 分时优惠显示特价活动用户参与记录表数据库访问层
*
* @author : vinjor-m
* @date : 2024-9-21
*/
@Mapper
public interface ActivePriceRecordMapper extends BaseMapper<ActivePriceRecord> {
}

View File

@ -9,6 +9,9 @@ import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* 价格营销活动规则;(active_price_rule)表数据库访问层
* @author : pqz
@ -35,4 +38,14 @@ public interface ActivePriceRuleMapper extends BaseMapper<ActivePriceRule> {
* @return com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO
**/
ActivePriceRuleRespVO getRuleById(@Param("id") int id);
/**
* 查店铺生效中的活动规则
* @author vinjor-M
* @date 14:11 2024/9/21
* @param storeId 店铺Id
* @param nowDate 结算时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO>
**/
List<ActivePriceRuleRespVO> selectActiveByStoreId(@Param("storeId")Integer storeId,@Param("nowDate") String nowDate);
}

View File

@ -3,7 +3,13 @@ package com.fuint.business.marketingActivity.activePrice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil;
import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPrice;
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* 立减营销活动规则
@ -12,5 +18,13 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ActiveSubPriceMapper extends BaseMapper<ActiveSubPrice> {
/**
* 查店铺生效中的活动规则
* @author vinjor-M
* @date 14:11 2024/9/21
* @param storeId 店铺Id
* @param nowDate 结算时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO>
**/
List<ActiveSubPriceRespVO> selectActiveByStoreId(@Param("storeId")Integer storeId, @Param("nowDate") String nowDate);
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuint.business.marketingActivity.activePrice.mapper.ActivePriceRecordMapper">
</mapper>

View File

@ -12,7 +12,13 @@
<collection select="getLabel" property="labelList" javaType="list"
column="babelIds"
ofType="com.fuint.business.userManager.entity.UserLabel"/>
</resultMap>
<resultMap id="ActivePriceRuleAndOilMap" type="com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO">
<id column="id" property="id"/>
<collection property="oilList"
ofType="com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil" columnPrefix="oil_">
<id column="id" property="id"/>
</collection>
</resultMap>
<select id="pageActivePriceRule" resultType="com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO">
SELECT
@ -59,4 +65,28 @@
LEFT JOIN active_price ap ON main.active_id = ap.id
where main.id = #{id}
</select>
<select id="selectActiveByStoreId"
resultMap="ActivePriceRuleAndOilMap">
SELECT
main.*,
ap.active_type,
ap.title AS activeTitle,
ap.category AS activeCategory,
ap.dis_value AS activeDisValue,
apo.id AS oil_id,
apo.oil_id AS oil_oil_id,
apo.oil_type AS oil_oil_type,
apo.oil_name AS oil_oil_name,
apo.oil_price AS oil_oil_price,
apo.price AS oil_price
FROM
active_price_rule main
LEFT JOIN active_price ap ON main.active_id = ap.id
LEFT JOIN active_price_oil apo ON ap.id=apo.active_id
WHERE main.store_id= #{storeId}
AND main.`status` ='1'
AND apo.type='0'
AND main.active_start_time &lt;=#{nowDate}
AND main.active_end_time &gt;=#{nowDate}
</select>
</mapper>

View File

@ -1,5 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuint.business.marketingActivity.activePrice.mapper.ActiveSubPriceMapper">
<resultMap id="ActivePriceRuleMap" type="com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO">
<id column="id" property="id"/>
<collection property="ruleList"
ofType="com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule" columnPrefix="rule_">
<id column="id" property="id"/>
</collection>
</resultMap>
<select id="selectActiveByStoreId" resultMap="ActivePriceRuleMap">
SELECT
main.*,
aspr.id AS rule_id,
aspr.store_id AS rule_store_id,
aspr.active_id AS rule_active_id,
aspr.active_manner AS rule_active_manner,
aspr.FULL AS rule_full,
aspr.sub AS rule_sub,
aspr.random_front AS rule_random_front,
aspr.random_after AS rule_random_after,
aspr.max_preferential AS rule_max_preferential,
aspr.enjoy_discount AS rule_enjoy_discount
FROM
active_sub_price main
LEFT JOIN active_sub_price_rule aspr ON main.id = aspr.active_id
LEFT JOIN active_applet ap ON main.id = ap.active_id AND ap.type ='3'
WHERE
main.store_id = #{storeId}
AND ap.isonline = '0'
AND ap.active_status = '1'
AND (
main.active_time_type = '0'
OR ( main.active_time_type = '1' AND main.active_start_time &lt;= #{nowDate} AND main.active_end_time &gt;= ${nowDate} ))
</select>
</mapper>

View File

@ -0,0 +1,28 @@
package com.fuint.business.marketingActivity.activePrice.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
import java.util.List;
/**
* 分时优惠显示特价活动用户参与记录表服务接口
*
* @author : vinjor-m
* @date : 2024-9-21
*/
public interface ActivePriceRecordService extends IService<ActivePriceRecord> {
/**
* 根据用户Id和活动ids查询所有参与的记录
* @author vinjor-M
* @date 13:55 2024/9/21
* @param userId 用户Id
* @param ruleIdList 活动规则ids
* @param actIdList 活动ids
* @param actTypeList 活动类型
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord>
**/
List<ActivePriceRecord> selectListByUserIdAndActIds(Integer userId,List<Integer> ruleIdList,List<Integer> actIdList,List<String> actTypeList);
}

View File

@ -8,6 +8,9 @@ import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule;
import com.fuint.business.marketingActivity.activePrice.vo.*;
import com.fuint.framework.exception.BusinessCheckException;
import java.util.Date;
import java.util.List;
/**
* 价格营销活动规则;(active_price_rule)表服务接口
*
@ -55,5 +58,15 @@ public interface ActivePriceRuleService extends IService<ActivePriceRule> {
**/
void removeByActId(Integer actId);
/**
* 查店铺生效中的活动规则
* @author vinjor-M
* @date 10:55 2024/9/21
* @param storeId 店铺id
* @param nowDate 当前时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule>
**/
List<ActivePriceRuleRespVO> selectAllAct(Integer storeId, Date nowDate);
}

View File

@ -6,6 +6,9 @@ import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceSaveVO;
import com.fuint.framework.exception.BusinessCheckException;
import java.util.Date;
import java.util.List;
/**
* 立减营销;
*
@ -46,5 +49,15 @@ public interface ActiveSubPriceService extends IService<ActiveSubPrice> {
*/
int deleteActiveSubPriceById(Integer id);
/**
* 查某店铺某时间节点可用的立减营销活动
* @author vinjor-M
* @date 18:13 2024/9/21
* @param storeId 店铺Id
* @param nowDate 结算时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO>
**/
List<ActiveSubPriceRespVO> selectAllAct(Integer storeId, Date nowDate);
}

View File

@ -0,0 +1,47 @@
package com.fuint.business.marketingActivity.activePrice.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
import com.fuint.business.marketingActivity.activePrice.mapper.ActivePriceRecordMapper;
import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRecordService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 分时优惠显示特价活动用户参与记录表服务接口
*
* @author : vinjor-m
* @date : 2024-9-2
*/
@Service("ActivePriceRecordService")
public class ActivePriceRecordServiceImpl extends ServiceImpl<ActivePriceRecordMapper, ActivePriceRecord> implements ActivePriceRecordService {
/**
* 根据用户Id和活动ids查询所有参与的记录
*
* @param userId 用户Id
* @param ruleIdList 活动规则ids
* @param actIdList 活动ids
* @param actTypeList 活动类型
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord>
* @author vinjor-M
* @date 13:55 2024/9/21
**/
@Override
public List<ActivePriceRecord> selectListByUserIdAndActIds(Integer userId, List<Integer> ruleIdList, List<Integer> actIdList, List<String> actTypeList) {
LambdaQueryWrapper<ActivePriceRecord> lambdaQueryWrapper = new LambdaQueryWrapper<ActivePriceRecord>()
.eq(ActivePriceRecord::getUserId, userId);
if (null != ruleIdList && !ruleIdList.isEmpty()) {
lambdaQueryWrapper.in(ActivePriceRecord::getRuleId, ruleIdList);
}
if (null != actIdList && !actIdList.isEmpty()) {
lambdaQueryWrapper.in(ActivePriceRecord::getActId, actIdList);
}
if (null != actTypeList && !actTypeList.isEmpty()) {
lambdaQueryWrapper.in(ActivePriceRecord::getActType, actTypeList);
}
return this.list(lambdaQueryWrapper);
}
}

View File

@ -1,5 +1,6 @@
package com.fuint.business.marketingActivity.activePrice.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -220,4 +221,18 @@ public class ActivePriceRuleServiceImpl extends ServiceImpl<ActivePriceRuleMappe
remove(lambdaQueryWrapper);
}
/**
* 查店铺生效中的活动规则
*
* @param storeId 店铺id
* @param nowDate 当前时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule>
* @author vinjor-M
* @date 10:55 2024/9/21
**/
@Override
public List<ActivePriceRuleRespVO> selectAllAct(Integer storeId, Date nowDate) {
return activePriceRuleMapper.selectActiveByStoreId(storeId,DateUtil.formatDate(nowDate));
}
}

View File

@ -1,5 +1,6 @@
package com.fuint.business.marketingActivity.activePrice.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -40,6 +41,8 @@ public class ActiveSubPriceServiceImpl extends ServiceImpl<ActiveSubPriceMapper,
private ActPriceUtil actPriceUtil;
@Autowired
private ActiveAppletService activeAppletService;
@Autowired
private ActiveSubPriceMapper activeSubPriceMapper;
/**
* 根据立减优惠活动id查询详细内容
@ -157,5 +160,19 @@ public class ActiveSubPriceServiceImpl extends ServiceImpl<ActiveSubPriceMapper,
activeSubPriceRuleService.removeByActId(id);
return row;
}
/**
* 查某店铺某时间节点可用的立减营销活动
*
* @param storeId 店铺Id
* @param nowDate 结算时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO>
* @author vinjor-M
* @date 18:13 2024/9/21
**/
@Override
public List<ActiveSubPriceRespVO> selectAllAct(Integer storeId, Date nowDate) {
return activeSubPriceMapper.selectActiveByStoreId(storeId, DateUtil.formatDate(nowDate));
}
}

View File

@ -1,5 +1,6 @@
package com.fuint.business.marketingActivity.activePrice.vo;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule;
import com.fuint.business.userManager.entity.UserLabel;
import com.fuint.repository.model.MtUserGrade;
@ -33,10 +34,23 @@ public class ActivePriceRuleRespVO extends ActivePriceRule {
/**标签集合*/
private List<String> labelIdList;
/** 活动名称 分时优惠 类型 */
/** 价格营销活动类型(1-分时优惠|2-限时特价) */
private String activeType ;
/**
* 创建人
*/
private String createName;
/**
* 活动优惠类型1-固定价格|2-折扣|3-减价
**/
private String activeCategory;
/**
* 折扣/减价金额两个字段合用一个
**/
private Double activeDisValue;
/**
* 活动适用的油号
**/
private List<ActivePriceOil> oilList;
}

View File

@ -3,10 +3,23 @@ package com.fuint.business.userGroup.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import com.fuint.business.userGroup.entity.UserDiscount;
import com.fuint.business.userGroup.vo.UserDiscountVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface UserDiscountMapper extends BaseMapper<UserDiscount> {
IPage<UserDiscountVo> queryPage(Page page, @Param("entity") UserDiscountVo userDiscountVo);
/**
* 查店铺生效中的活动规则
* @author vinjor-M
* @date 14:11 2024/9/21
* @param storeId 店铺Id
* @param nowDate 结算时间
* @return java.util.List<com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO>
**/
List<UserDiscount> selectActiveByStoreId(@Param("storeId")Integer storeId, @Param("nowDate") String nowDate);
}

View File

@ -25,5 +25,17 @@
</where>
ORDER BY create_time DESC
</select>
<select id="selectActiveByStoreId" resultType="com.fuint.business.userGroup.entity.UserDiscount">
SELECT
main.*
FROM
user_discount main
WHERE
main.store_id = #{storeId}
AND (
main.suit_date_type = '0'
OR ( main.suit_date_type = '1' AND main.suit_date_front &lt;= ${nowDate} AND main.suit_date_after &gt;= ${nowDate} )
)
</select>
</mapper>

View File

@ -2,9 +2,13 @@ package com.fuint.business.userGroup.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import com.fuint.business.userGroup.entity.UserDiscount;
import com.fuint.business.userGroup.vo.UserDiscountVo;
import java.util.Date;
import java.util.List;
/**
* 会员折扣表(UserDiscount)表服务接口
*
@ -52,4 +56,13 @@ public interface UserDiscountService {
*/
int deleteById(Integer id);
/**
* 查某店铺某时间节点可用的会员折扣营销活动
* @author vinjor-M
* @date 18:13 2024/9/22
* @param storeId 店铺Id
* @param nowDate 结算时间
**/
List<UserDiscount> selectAllAct(Integer storeId, Date nowDate);
}

View File

@ -1,5 +1,6 @@
package com.fuint.business.userGroup.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -9,10 +10,17 @@ import com.fuint.business.userGroup.service.UserDiscountService;
import com.fuint.business.userGroup.vo.UserDiscountVo;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class UserDiscountServiceImpl extends ServiceImpl<UserDiscountMapper, UserDiscount> implements UserDiscountService {
@Autowired
private UserDiscountMapper userDiscountMapper;
@Override
public IPage<UserDiscountVo> queryPage(Page page, UserDiscountVo userDiscountVo) {
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
@ -42,4 +50,17 @@ public class UserDiscountServiceImpl extends ServiceImpl<UserDiscountMapper, Use
public int deleteById(Integer id) {
return baseMapper.deleteById(id);
}
/**
* 查某店铺某时间节点可用的会员折扣营销活动
*
* @param storeId 店铺Id
* @param nowDate 结算时间
* @author vinjor-M
* @date 18:13 2024/9/22
**/
@Override
public List<UserDiscount> selectAllAct(Integer storeId, Date nowDate) {
return userDiscountMapper.selectActiveByStoreId(storeId, DateUtil.formatDate(nowDate));
}
}

View File

@ -58,6 +58,14 @@ public interface UserBalanceService extends IService<UserBalance> {
* @return
*/
public UserBalance selectUserBalance(int userId, int chainStoreId);
/**
* 根据店铺Id和会员Id查询正在使用的会员卡信息
* @author vinjor-M
* @date 10:07 2024/9/21
* @param userId 用户Id
* @param storeId 店铺Id
* @return com.fuint.business.userManager.entity.UserBalance
**/
public UserBalance selectUserBalanceByStorId(int userId, int storeId);
/**

View File

@ -4,8 +4,10 @@ import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.pay.service.PayCenterService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@ -20,7 +22,8 @@ import java.util.Map;
@RequestMapping("/pay/paycenter")
public class PayCenterController extends BaseController {
private Logger logger = LoggerFactory.getLogger(PayCenterController.class);
@Autowired
private PayCenterService payCenterService;
/**
* 收银台获取可用优惠券和可以参加的优惠活动
* @author vinjor-M
@ -32,21 +35,7 @@ public class PayCenterController extends BaseController {
@GetMapping("/getActivityAndCoupon")
public ResponseObject getActivityAndCoupon(Map<String,String> map,HttpServletRequest request) throws Exception {
logger.info("收银台获取可用优惠券和可以参加的优惠活动参数:{}", map);
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
//会员的用户id
String userId = map.get("userId");
//油号
String oil = map.get("oil");
//加油金额不含商品金额
String oilAmount = map.get("oilAmount");
//订单总额含商品金额
String orderAmount = map.get("orderAmount");
//油升数
String oilLiter = map.get("oilLiter");
//当前店铺id
Integer storeId = nowAccountInfo.getStoreId();
return getSuccessResult("查询成功",);
return getSuccessResult("查询成功",payCenterService.getActivityAndCoupon(map));
}
}

View File

@ -1,16 +1,54 @@
package com.fuint.pay.service.impl;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRule;
import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPrice;
import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRecordService;
import com.fuint.business.marketingActivity.activePrice.service.ActivePriceRuleService;
import com.fuint.business.marketingActivity.activePrice.service.ActivePriceService;
import com.fuint.business.marketingActivity.activePrice.service.ActiveSubPriceService;
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import com.fuint.business.userGroup.entity.UserDiscount;
import com.fuint.business.userGroup.service.UserDiscountService;
import com.fuint.business.userManager.entity.UserBalance;
import com.fuint.business.userManager.service.UserBalanceService;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.util.StringUtils;
import com.fuint.common.util.TokenUtil;
import com.fuint.module.AlipayApi.service.impl.AlipayServiceImpl1;
import com.fuint.pay.service.PayCenterService;
import com.fuint.pay.util.CheckUtil;
import com.fuint.pay.vo.ActivityVO;
import com.fuint.pay.vo.CouponVO;
import com.google.common.collect.ImmutableList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class PayCenterServiceImpl implements PayCenterService {
private static final Logger logger = LoggerFactory.getLogger(PayCenterServiceImpl.class);
@Autowired
private CheckUtil checkUtil;
@Autowired
private UserBalanceService userBalanceService;
@Autowired
private ActivePriceRuleService activePriceRuleService;
@Autowired
private ActivePriceRecordService activePriceRecordService;
@Autowired
private ActiveSubPriceService activeSubPriceService;
@Autowired
private UserDiscountService userDiscountService;
/**
* 收银台获取可用优惠券和可以参加的优惠活动
*
@ -21,6 +59,224 @@ public class PayCenterServiceImpl implements PayCenterService {
**/
@Override
public Object getActivityAndCoupon(Map<String, String> map) {
return null;
JSONObject rtnObj = new JSONObject();
//可参加的营销活动
List<ActivityVO> activityVOList = new ArrayList<>();
//可用的优惠券
List<CouponVO> couponVOList = new ArrayList<>();
/*1.先把所有用到的值取出来 */
//当前时间从点击结算的这一刻算
Date nowDate = new Date();
//当前店铺id
AccountInfo nowAccountInfo = TokenUtil.getNowAccountInfo();
Integer storeId = nowAccountInfo.getStoreId();
int userId = Integer.parseInt(map.get("userId"));
//查会员等级
UserBalance userBalance = userBalanceService.selectUserBalanceByStorId(userId,storeId);
if(null==userBalance){
//非会员不能参加任何活动
rtnObj.put("activity",activityVOList);
rtnObj.put("coupon",couponVOList);
return rtnObj;
}
//会员等级
int gradeId = userBalance.getGradeId();
//会员标签会有多个一个集和
List<Integer> labelIdList = new ArrayList<>();
if(StringUtils.isNotEmpty(userBalance.getUserLabelId())){
List<String> labelIdStrList = Arrays.asList(userBalance.getUserLabelId().split(StrUtil.COMMA));
labelIdStrList.forEach(str->labelIdList.add(Integer.parseInt(str)));
}
//油号id
Integer oilId = Integer.valueOf(map.get("oilId"));
//油单价
Double oilPrice = Double.valueOf(map.get("oilPrice"));
//加油金额不含商品金额
Double oilAmount = Double.valueOf(map.get("oilAmount"));
//订单总额含商品金额
Double orderAmount = Double.valueOf(map.get("orderAmount"));
//油升数
Double oilLiter = Double.valueOf(map.get("oilLiter"));
/*2.查询所有可参加的营销活动 */
List<ActivityVO> actList = new ArrayList<>();
//2.1 查可参加的分时优惠和限时特价
actList.addAll(this.getFenshiAndTejiaAct(nowDate,userId,gradeId,storeId,labelIdList,oilAmount,oilLiter,oilId,oilPrice));
//2.2 查可参加的立减营销
actList.addAll(this.getLijianAct(nowDate,userId,gradeId,storeId,labelIdList,oilAmount,oilLiter,oilId));
//2.3 查可参加的折扣营销会员折扣
actList.addAll(this.getZhekouAct(nowDate,gradeId,storeId,oilAmount));
/*3.查询所有可用的优惠券 TODO 需要等待优惠券表修改完以后再处理 */
List<CouponVO> couponList = new ArrayList<>();
rtnObj.put("activity",actList);
rtnObj.put("coupon",couponList);
return rtnObj;
}
/**
* 获取当前会员可以参加的分时优惠和限时特价活动
* @author vinjor-M
* @date 10:15 2024/9/21
* @param nowDate 结算那一刻的时间
* @param userId 用户Id
* @param gradeId 会员等级
* @param storeId 店铺id
* @param labelIdList 会员标签id集和
* @param oilAmount 当前加油金额
* @param oilLiter 当前加油升数
* @param oilId 当前加油选择的油号id
* @param oilPrice 油单价
* @return java.util.List<com.fuint.pay.vo.ActivityVO>
**/
private List<ActivityVO> getFenshiAndTejiaAct(Date nowDate,Integer userId,Integer gradeId,Integer storeId,
List<Integer> labelIdList,Double oilAmount,Double oilLiter,
Integer oilId,Double oilPrice){
/*1.先查满足条件的所有生效中的活动规则*/
List<ActivePriceRuleRespVO> activePriceRuleList = activePriceRuleService.selectAllAct(storeId, nowDate);
/*2.进行初步过滤,这里只过滤活动硬性的限制*/
List<ActivePriceRuleRespVO> filteredList = activePriceRuleList.stream()
//适用当前会员等级的
.filter(rule->rule.getLevelId().equals(gradeId.toString()))
//适用当前会员标签的
.filter(rule->checkUtil.checkLabelId(rule.getBabelIds(),labelIdList))
//适用当前加油金额或加油升数的
.filter(rule -> checkUtil.checkConsume(rule,oilAmount,oilLiter))
//适用当前时间段的
.filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),rule.getDayStartTime(),rule.getDayEndTime(),nowDate))
//适用当前油号的
.filter(rule-> checkUtil.checkOil(rule.getOilList(),oilId)).collect(Collectors.toList());
if(filteredList.isEmpty()){
return new ArrayList<>();
}
/*3.再次过滤,这里过滤掉用户已经超出参加次数限制的*/
//符合条件的活动规则查询当前会员已经参与的记录此处查分时特价和限时特价的
List<String> actTypeList = Arrays.asList("1,2".split(StrUtil.COMMA));
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
filteredList.stream().map(ActivePriceRuleRespVO::getId).collect(Collectors.toList()),null,actTypeList);
filteredList = filteredList.stream()
//过滤掉超过每日参加次数限制的
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList, "day"))
//过滤掉超过累计参加次数限制的
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
List<ActivityVO> rtnList = new ArrayList<>();
if(!filteredList.isEmpty()){
for(ActivePriceRuleRespVO rule:filteredList){
ActivityVO activityVO = new ActivityVO();
activityVO.setActId(rule.getActiveId());
activityVO.setRuleId(rule.getId());
activityVO.setType(rule.getActiveType());
activityVO.setActName(rule.getActiveTitle());
activityVO.setRuleName(rule.getRuleName());
activityVO.setPayTypes(rule.getPaymentType());
activityVO.setDisAmount(checkUtil.computeDisAmount(rule,oilId,oilPrice,oilAmount,oilLiter));
}
}
return rtnList;
}
/**
* 获取当前会员可以参加的立减营销活动
* @author vinjor-M
* @date 17:28 2024/9/21
* @param nowDate 结算那一刻的时间
* @param userId 用户Id
* @param gradeId 会员等级
* @param storeId 店铺id
* @param labelIdList 会员标签id集和
* @param oilAmount 当前加油金额
* @param oilLiter 当前加油升数
* @param oilId 当前加油选择的油号id
* @return java.util.List<com.fuint.pay.vo.ActivityVO>
**/
private List<ActivityVO> getLijianAct(Date nowDate,Integer userId,Integer gradeId,Integer storeId,
List<Integer> labelIdList,Double oilAmount,Double oilLiter,
Integer oilId){
/*1.先查满足条件的所有生效中的活动规则*/
List<ActiveSubPriceRespVO> activeSubPriceList = activeSubPriceService.selectAllAct(storeId,nowDate);
/*2.进行初步过滤,这里只过滤活动硬性的限制*/
List<ActiveSubPriceRespVO> filteredList = activeSubPriceList.stream()
//适用当前会员等级的
.filter(rule->Arrays.asList(rule.getLevelId().split(StrUtil.COMMA)).contains(gradeId.toString()))
//适用当前会员标签的
.filter(rule->checkUtil.checkLabelId(rule.getBabelIds(),labelIdList))
//适用当前时间段的
.filter(rule -> checkUtil.checkTime(rule.getTimeSlots(),checkUtil.getTimeFromDate(rule.getTimeApplyStart()),checkUtil.getTimeFromDate(rule.getTimeApplyEnd()),nowDate))
//适用当前油号的
.filter(rule-> checkUtil.checkOilLijian(rule.getApplyOilType(),rule.getApplyOil(),oilId)).collect(Collectors.toList());
/*3.再次过滤,这里过滤掉用户已经超出参加次数限制的*/
//符合条件的活动规则查询当前会员已经参与的记录此处查立减营销的参与记录
List<String> actTypeList = Arrays.asList("3".split(StrUtil.COMMA));
List<ActivePriceRecord> recordAllList = activePriceRecordService.selectListByUserIdAndActIds(userId,
null,filteredList.stream().map(ActiveSubPriceRespVO::getId).collect(Collectors.toList()),actTypeList);
filteredList = filteredList.stream()
//过滤掉超过每日参加次数限制的
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getDayLimitNum(),nowDate,recordAllList,"day"))
//过滤掉超过每月参加次数限制的
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getMonthLimitNum(),nowDate,recordAllList,"month"))
//过滤掉超过累计参加次数限制的
.filter(rule -> checkUtil.checkUseNum(rule.getId(),rule.getLimitNum(),null,recordAllList,null)).collect(Collectors.toList());
/*4.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
List<ActivityVO> rtnList = new ArrayList<>();
if(!filteredList.isEmpty()){
for(ActiveSubPriceRespVO rule:filteredList){
ActivityVO activityVO = new ActivityVO();
activityVO.setActId(rule.getId());
activityVO.setType("3");
activityVO.setActName(rule.getActiveName());
activityVO.setPayTypes(rule.getPaymentType());
activityVO.setDisAmount(checkUtil.computeDisAmountLijian(rule,oilAmount,oilLiter));
}
}
return rtnList;
}
/**
* 获取当前会员可以参加的折扣营销活动
* @author vinjor-M
* @date 11:46 2024/9/22
* @param nowDate 结算那一刻的时间
* @param gradeId 会员等级
* @param storeId 店铺id
* @param oilAmount 当前加油金额
* @return java.util.List<com.fuint.pay.vo.ActivityVO>
**/
private List<ActivityVO> getZhekouAct(Date nowDate,Integer gradeId,Integer storeId,Double oilAmount){
/*1.先查满足条件的所有生效中的活动规则*/
List<UserDiscount> userDiscountList = userDiscountService.selectAllAct(storeId,nowDate);
/*2.进行初步过滤,这里只过滤活动硬性的限制*/
List<UserDiscount> filteredList = userDiscountList.stream()
//适用当前会员等级的
.filter(rule->rule.getGradeId().equals(gradeId))
//节假日要求是否满足
.filter(rule->checkUtil.checkTimeJiejiari(rule.getHolidayIsUse(),nowDate))
//适用当前时间段的
.filter(rule -> checkUtil.checkTime(rule.getSuitDate(),checkUtil.getTimeFromDate(rule.getSuitTimeSlotFront()),checkUtil.getTimeFromDate(rule.getSuitDateAfter()),nowDate))
//是否满足最低消费金额
.filter(rule-> rule.getConsumeAmount() <=oilAmount).collect(Collectors.toList());
/*3.得到用户最终可以参加的活动,计算优惠金额并转换成统一的对象*/
List<ActivityVO> rtnList = new ArrayList<>();
if(!filteredList.isEmpty()){
UserDiscount discount;
if(filteredList.size()==1){
discount = filteredList.get(0);
}else{
//取折扣最大的也就是折扣数值最小的正序排列取第一个
discount = filteredList.stream().sorted(Comparator.comparingDouble(UserDiscount::getDiscount)).collect(Collectors.toList()).get(0);
}
ActivityVO activityVO = new ActivityVO();
activityVO.setActId(discount.getId());
activityVO.setType("4");
activityVO.setActName("折扣营销");
activityVO.setPayTypes(discount.getUsePaymentWay());
//计算优惠金额
double disAmount = 0.0;
if(null!=discount.getDiscount()){
Double newOilAmount = oilAmount*discount.getDiscount();
disAmount = oilAmount-newOilAmount;
}
activityVO.setDisAmount(disAmount);
rtnList.add(activityVO);
}
return rtnList;
}
}

View File

@ -0,0 +1,518 @@
package com.fuint.pay.util;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.StrUtil;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceOil;
import com.fuint.business.marketingActivity.activePrice.entity.ActivePriceRecord;
import com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule;
import com.fuint.business.marketingActivity.activePrice.vo.ActivePriceRuleRespVO;
import com.fuint.business.marketingActivity.activePrice.vo.ActiveSubPriceRespVO;
import com.fuint.business.userGroup.entity.UserDiscount;
import com.fuint.common.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 收银台判断使用的util
* @author vinjor-M
* @date 11:25 2024/9/21
**/
@Component
@Slf4j
public class CheckUtil {
/**
* 判断某活动设置的可用会员标签当前会员标签是否可用
* @author vinjor-M
* @date 11:12 2024/9/21
* @param labelIds 活动适用的会员标签Ids
* @param labelIdList 当前会员的标签集和
* @return java.lang.Boolean
**/
public Boolean checkLabelId(String labelIds, List<Integer> labelIdList){
if(StringUtils.isEmpty(labelIds)){
//活动没有会员标签显示可用
return true;
}else if(labelIdList.isEmpty()){
//活动设置的会员标签但是当前用户没有会员标签不可用
return false;
}else{
//活动设置了会员标签当前用户也有会员标签判断是否有重叠的标签
List<String> actLabelIdStrList = Arrays.asList(labelIds.split(StrUtil.COMMA));
List<Integer> actLabelIdList = actLabelIdStrList.stream().map(Integer::parseInt).collect(Collectors.toList());
//比较两个list是否有重叠如果有则可用
return actLabelIdList.stream().anyMatch(labelIdList::contains);
}
}
/**
* 判断当前加油金额或加油升数是否符合某活动的消费条件限制
* @author vinjor-M
* @date 11:31 2024/9/21
* @param rule 活动规则
* @param oilAmount 当前加油金额
* @param oilLiter 当前加油升数
* @return java.lang.Boolean
**/
public Boolean checkConsume(ActivePriceRuleRespVO rule, Double oilAmount, Double oilLiter){
if("0".equals(rule.getConsumeType())){
//活动规则设置的消费规则是根据实收金额判断
return isBetween(oilAmount,rule.getMoneyMin(),rule.getMoneyMax());
}else if("1".equals(rule.getConsumeType())){
//活动规则设置的消费规则是根据加油升数判断
return isBetween(oilLiter,rule.getLiterMin(),rule.getLiterMax());
}else {
//超出预设值返回默认不满足
return false;
}
}
/**
* 判断结算时间是否符合活动设置的适用时间
* @author vinjor-M
* @date 11:41 2024/9/21
* @param timeSlots 适用时间
* @param startTime 某天适用的开始时间
* @param endTime 某天适用的结束时间
* @param nowDate 结算时间
* @return java.lang.Boolean
**/
public Boolean checkTime(String timeSlots,String startTime,String endTime, Date nowDate){
String timeSlotsStr = timeSlots;
if(timeSlots.contains("")){
//周几汉字转数字
timeSlotsStr = changeWeekNumber(timeSlots);
}
List<String> timeSlotStrList = Arrays.asList(timeSlotsStr.split(StrUtil.COMMA));
//转换为int类型
List<Integer> timeSlotList = timeSlotStrList.stream().map(Integer::parseInt).collect(Collectors.toList());
if(timeSlotStrList.isEmpty() && (StringUtils.isNotEmpty(startTime) || StringUtils.isNotEmpty(endTime))){
//没有设置时间段但是生效时间又设置了代表每天的某个时间范围
return checkDayTime(nowDate,startTime,endTime);
}else{
//设置了时间段需要判断时间段是否符合
if(timeSlots.contains("")){
//活动设置的适用时间类型是每周
//结算时间是周几,特殊情况0是周日需要转换为7 方便判断
int nowWeek = DateUtil.dayOfWeek(nowDate)-1;
if(0==nowWeek){
nowWeek =7;
}
if(timeSlotList.contains(nowWeek)){
//周几是符合的进而判断时间是否符合
return checkDayTime(nowDate,startTime,endTime);
}else{
return false;
}
}else{
//活动设置的适用时间类型是每月
//结算时间是每月几号
int nowDay = DateUtil.dayOfMonth(nowDate);
if(timeSlotList.contains(nowDay)){
//每月几号是符合的进而判断时间是否符合
return checkDayTime(nowDate,startTime,endTime);
}else{
return false;
}
}
}
}
/**
* 判断结算时间是否符合活动设置的不适用时间注意判断是否处在不适用的时间范围内
* @author vinjor-M
* @date 11:41 2024/9/21
* @param timeSlots 适用时间
* @param startTime 某天适用的开始时间
* @param endTime 某天适用的结束时间
* @param nowDate 结算时间
* @return java.lang.Boolean
**/
public Boolean checkTimeReverse(String timeSlots,String startTime,String endTime, Date nowDate){
String timeSlotsStr = timeSlots;
if(timeSlots.contains("")){
//周几汉字转数字
timeSlotsStr = changeWeekNumber(timeSlots);
}
List<String> timeSlotStrList = Arrays.asList(timeSlotsStr.split(StrUtil.COMMA));
//转换为int类型
List<Integer> timeSlotList = timeSlotStrList.stream().map(Integer::parseInt).collect(Collectors.toList());
if(timeSlotStrList.isEmpty() && (StringUtils.isNotEmpty(startTime) || StringUtils.isNotEmpty(endTime))){
//没有设置时间段但是生效时间又设置了代表每天的某个时间范围
return checkDayTimeReverse(nowDate,startTime,endTime);
}else{
//设置了时间段需要判断时间段是否符合
if(timeSlots.contains("")){
//活动设置的适用时间类型是每周
//结算时间是周几,特殊情况0是周日需要转换为7 方便判断
int nowWeek = DateUtil.dayOfWeek(nowDate)-1;
if(0==nowWeek){
nowWeek =7;
}
if(timeSlotList.contains(nowWeek)){
//周几是符合的返回不可用
return false;
}else{
//周几是不符合的进而判断时间是否符合
return checkDayTimeReverse(nowDate,startTime,endTime);
}
}else{
//活动设置的适用时间类型是每月
//结算时间是每月几号
int nowDay = DateUtil.dayOfMonth(nowDate);
if(timeSlotList.contains(nowDay)){
//每月几号是符合的返回不可用
return false;
}else{
//每月几号是不符合的进而判断时间是否符合
return checkDayTimeReverse(nowDate,startTime,endTime);
}
}
}
}
/**
* 判断结算时间是否符合活动设置的适用时间
* @author vinjor-M
* @date 12:08 2024/9/22
* @param holidayIsUse 节假日是否可用
* @param nowDate 结算日期
* @return boolean
**/
public boolean checkTimeJiejiari(String holidayIsUse,Date nowDate){
if("1".equals(holidayIsUse)){
//节假日不可用需要判断当前日期是否为节假日 TODO
return true;
}else{
//节假日可用直接反回可用
return true;
}
}
/**
* 判断当前加油的油号是否符合活动规则预设的油号----限时特价和分时优惠使用
* @author vinjor-M
* @date 14:42 2024/9/21
* @param oilList 活动适用的油号集和
* @param oilId 当前加油选择的油号id
* @return java.lang.Boolean
**/
public Boolean checkOil(List<ActivePriceOil> oilList, Integer oilId){
List<Integer> oilIdList = oilList.stream().map(ActivePriceOil::getOilId).collect(Collectors.toList());
return oilIdList.contains(oilId);
}
/**
* 判断当前加油的油号是否符合活动规则预设的油号----立减营销使用
* @author vinjor-M
* @date 14:42 2024/9/21
* @param applyOilType 适用油品油号类型0不限1自定义
* @param applyOil 适用油品油号
* @param oilId 当前加油选择的油号id
* @return java.lang.Boolean
**/
public Boolean checkOilLijian(String applyOilType,String applyOil, Integer oilId){
if("0".equals(applyOilType)){
return true;
}else{
if(StringUtils.isNotEmpty(applyOil)){
List<String> oilIdList = Arrays.asList(applyOil.split(StrUtil.COMMA));
return oilIdList.contains(oilId.toString());
}else{
//没有配置可用油号不满足
return false;
}
}
}
/**
* 判断当前加油的油号是否符合活动规则预设的油号
* @author vinjor-M
* @date 14:51 2024/9/21
* @param ruleId 活动规则Id或活动Id
* @param maxNum 最大次数限制
* @param nowDate 结算日期
* @param recordAllList 所有参加记录
* @param filterType 过滤类型 day | month | null 累计
* @return java.lang.Boolean
**/
public Boolean checkUseNum(Integer ruleId,Integer maxNum,Date nowDate,List<ActivePriceRecord> recordAllList,String filterType){
if(0==maxNum){
//最大次数限制为0代表不限制
return true;
}
int nowNum = 0;
if(!recordAllList.isEmpty()){
//有参与记录
if(null!=nowDate){
//有时间限制
if("day".equals(filterType)){
//过滤出当天的
LocalDate dateToFilter = LocalDate.of(DateUtil.year(nowDate), DateUtil.month(nowDate)+1, DateUtil.dayOfMonth(nowDate));
nowNum = (int) recordAllList.stream().filter(item->item.getCreateTime().equals(dateToFilter))
.filter(item->item.getRuleId().equals(ruleId)).count();
}else if("month".equals(filterType)){
//过滤出当月的
int thisYear = DateUtil.year(nowDate);
int thisMonth = DateUtil.month(nowDate);
nowNum = (int) recordAllList.stream()
.filter(item->DateUtil.year(item.getCreateTime())==thisYear)
.filter(item->DateUtil.month(item.getCreateTime())==thisMonth)
.filter(item->item.getRuleId().equals(ruleId)).count();
}
}else{
//没时间限制,查累计的
nowNum = (int) recordAllList.stream().filter(item->item.getRuleId().equals(ruleId)).count();
}
}
return maxNum>nowNum;
}
/**
* 根据活动优惠规则计算优惠金额四舍五入保留2位小数--分时优惠和限时特价使用
* @author vinjor-M
* @date 16:35 2024/9/21
* @param rule 活动规则
* @param oilId 当前油号id
* @param oilPrice 当前油单价
* @param oilAmount 加油总价
* @param oilLiter 加油升数
* @return java.lang.Double
**/
public Double computeDisAmount(ActivePriceRuleRespVO rule,Integer oilId,Double oilPrice,Double oilAmount,Double oilLiter){
//默认优惠后总价等于原来的总价
Double newOilAmount = oilAmount;
//优惠金额
Double disAmount = 0.0;
DecimalFormat df = new DecimalFormat("#.00");
try {
if("1".equals(rule.getActiveCategory())){
//固定价格,取本活动设置的当前油号的活动价格
Double newOilPrice = rule.getOilList().stream().filter(oil->oil.getOilId().equals(oilId)).collect(Collectors.toList()).get(0).getPrice();
if(null!=newOilPrice && newOilPrice<oilPrice){
//新的活动价格小于原价格的情况下才去计算优惠金额
newOilAmount = oilLiter*newOilPrice;
}
}else if("2".equals(rule.getActiveCategory())){
//折扣总价直接折扣
if(null!=rule.getActiveDisValue() && 0.0!=rule.getActiveDisValue()){
//这里规避风险不能0折
newOilAmount = oilAmount*rule.getActiveDisValue();
}
}else if("3".equals(rule.getActiveCategory())){
//减价
if(null!=rule.getActiveDisValue() && oilPrice>rule.getActiveDisValue()){
//减价必须有值且小于单价
Double newOilPrice = oilPrice-rule.getActiveDisValue();
newOilAmount = newOilPrice*oilLiter;
}
}else{
//超出预设值范围不打折
}
//计算优惠金额
disAmount = newOilAmount-oilAmount;
if(disAmount>rule.getDisMax()){
//超出最大优惠金额
disAmount = rule.getDisMax();
}
}catch (Exception e){
log.error("分时优惠和限时特价优惠金额计算失败:"+e.getMessage(),e);
}
return Double.valueOf(df.format(disAmount));
}
/**
* 根据活动优惠规则计算优惠金额四舍五入保留2位小数--立减营销专用
* @author vinjor-M
* @date 16:35 2024/9/21
* @param act 活动
* @param oilAmount 加油总价
* @param oilLiter 加油升数
* @return java.lang.Double
**/
public Double computeDisAmountLijian(ActiveSubPriceRespVO act, Double oilAmount, Double oilLiter){
//默认优惠后总价等于原来的总价
Double newOilAmount = oilAmount;
//优惠金额
Double disAmount = 0.0;
DecimalFormat df = new DecimalFormat("#.00");
try {
//本订单满足的优惠规则
ActiveSubPriceRule rule = null;
if ("0".equals(act.getActiveManner())) {
//活动优惠方式按订单金额优惠
rule = getRuleLijian(act.getRuleList(), oilAmount, null);
} else if ("1".equals(act.getActiveManner())) {
//活动优惠方式按加油升数优惠
rule = getRuleLijian(act.getRuleList(), null, oilLiter);
} else {
//超出预设值范围不优惠
}
if (null != rule) {
//匹配到优惠规则计算优惠金额
if ("0".equals(act.getOfferType())) {
//立减优惠
if ("0".equals(act.getActiveType())) {
//固定满减
disAmount = rule.getSub().doubleValue();
} else if ("1".equals(act.getActiveType())) {
//随机满减
Random random = new Random();
disAmount = Math.round((random.nextDouble() * (rule.getRandomAfter().doubleValue() - rule.getRandomFront().doubleValue()) + rule.getRandomFront().doubleValue()) * 100.0) / 100.0;
} else if ("2".equals(act.getActiveType())) {
//每满,这里需要判断下是按油升数还是按订单金额
Double thisValue = "0".equals(act.getActiveManner()) ? oilAmount : oilLiter;
//计算能除尽多少次就减多少次
int thisInt = (int) (thisValue / rule.getFull().doubleValue());
//计算优惠金额
disAmount = thisInt * rule.getSub().doubleValue();
if (disAmount > rule.getMaxPreferential().doubleValue()) {
//超出最大优惠金额
disAmount = rule.getMaxPreferential().doubleValue();
}
}
} else if ("1".equals(act.getOfferType())) {
//折扣优惠
newOilAmount = oilAmount * rule.getEnjoyDiscount().doubleValue();
//计算优惠金额
disAmount = oilAmount - newOilAmount;
if (disAmount > rule.getMaxPreferential().doubleValue()) {
//超出最大优惠金额
disAmount = rule.getMaxPreferential().doubleValue();
}
}
}
}catch (Exception e){
log.error("立减营销优惠金额计算失败:"+e.getMessage(),e);
}
return Double.valueOf(df.format(disAmount));
}
/**
* 从一个日期里面获取时间00:00格式
* @author vinjor-M
* @date 19:12 2024/9/21
* @param date 日期
* @return java.lang.String
**/
public String getTimeFromDate(Date date){
String rtn = "";
if(null!=date){
rtn = DateUtil.formatTime(date).substring(0,5);
}
return rtn;
}
/**
* 获取最符合条件的优惠规则--立减营销
* @author vinjor-M
* @date 10:41 2024/9/22
* @param ruleList 所有规则
* @param oilAmount 加油金额
* @param oilLiter 加油升数
* @return com.fuint.business.marketingActivity.activePrice.entity.ActiveSubPriceRule
**/
private static ActiveSubPriceRule getRuleLijian(List<ActiveSubPriceRule> ruleList,Double oilAmount,Double oilLiter){
ActiveSubPriceRule thisRule = new ActiveSubPriceRule();
if(null!=oilAmount){
//按加油金额
ruleList = ruleList.stream()
.filter(rule-> checkNumber(BigDecimal.valueOf(oilAmount),rule.getFull())).collect(Collectors.toList());
}else{
//按加油升数
ruleList = ruleList.stream()
.filter(rule-> checkNumber(BigDecimal.valueOf(oilLiter),rule.getFull())).collect(Collectors.toList());
}
if(!ruleList.isEmpty()){
//取出最大限度符合条件的一个,也就是按full字段倒叙排列取第一个
thisRule = ruleList.stream().sorted(Comparator.comparing(ActiveSubPriceRule::getFull).reversed()).collect(Collectors.toList()).get(0);
}
return thisRule;
}
/**
* 比较一个数是否大于或等于另一个数
* @author vinjor-M
* @date 10:46 2024/9/22
* @param thisNumber 要比较的数
* @param toNumber 另一个数
* @return boolean
**/
private static boolean checkNumber(BigDecimal thisNumber,BigDecimal toNumber){
int comparisonResult =thisNumber.compareTo(toNumber);
return comparisonResult>=0;
}
/**
* 判断结算时间是否在活动设置的时间范围内
* @author vinjor-M
* @date 12:18 2024/9/21
* @param nowDate 结算时间
* @param dayStartTime 活动设置的开始时间时分秒
* @param dayEndTime 活动设置的结束时间时分秒
* @return boolean
**/
private static boolean checkDayTime(Date nowDate,String dayStartTime,String dayEndTime){
String dayStr = DateUtil.date(nowDate).toString();
//时间范围区间
Date startTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayStartTime)?(dayStartTime+":00"):"00:00:00"));
Date endTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayEndTime)?(dayEndTime+":59"):"23:59:59"));
return DateUtil.isIn(nowDate,startTime,endTime);
}
/**
* 判断结算时间是否在活动设置的 不适用时间注意判断是否处在不适用的时间范围内
* @author vinjor-M
* @date 12:18 2024/9/21
* @param nowDate 结算时间
* @param dayStartTime 活动设置的不适用开始时间时分秒
* @param dayEndTime 活动设置的不适用结束时间时分秒
* @return boolean
**/
private static boolean checkDayTimeReverse(Date nowDate,String dayStartTime,String dayEndTime){
String dayStr = DateUtil.date(nowDate).toString();
//时间范围区间
Date startTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayStartTime)?(dayStartTime+":00"):"00:00:00"));
Date endTime = DateUtil.parse(dayStr+" "+(StringUtils.isNotEmpty(dayEndTime)?(dayEndTime+":59"):"23:59:59"));
return !DateUtil.isIn(nowDate,startTime,endTime);
}
/**
* 判断某值是否处于一个区间值范围等于也算
* @author vinjor-M
* @date 11:36 2024/9/21
* @param value 要判断的值
* @param min 区间下限
* @param max 区间上限
* @return boolean
**/
private static boolean isBetween(double value, double min, double max) {
return value > min && value < max;
}
/**
* 周几汉字转换成数字1至7
* @author vinjor-M
* @date 17:22 2024/9/21
* @param timesStr 周几
* @return java.lang.String
**/
private static String changeWeekNumber(String timesStr){
timesStr = timesStr.replace("周一","1");
timesStr = timesStr.replace("周二","2");
timesStr = timesStr.replace("周三","3");
timesStr = timesStr.replace("周四","4");
timesStr = timesStr.replace("周五","5");
timesStr = timesStr.replace("周六","6");
timesStr = timesStr.replace("周日","7");
return timesStr;
}
}

View File

@ -12,7 +12,17 @@ import java.io.Serializable;
@Data
public class ActivityVO implements Serializable {
/** 活动id */
private Integer id;
/** 活动类别 */
private Integer actId;
/** 活动规则id */
private Integer ruleId;
/** 活动类别(1-分时优惠|2-限时特价|3-立减营销|4-折扣营销) */
private String type;
/** 活动名称 */
private String actName;
/** 活动规则名称 */
private String ruleName;
/** 可使用支付方式 直接存的汉字-数据字典 */
private String payTypes;
/** 优惠金额 */
private Double disAmount;
}