参数校验
This commit is contained in:
@@ -3,6 +3,7 @@ package com.czg.service.market.service.impl;
|
|||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.market.dto.MkCouponGiftDTO;
|
import com.czg.market.dto.MkCouponGiftDTO;
|
||||||
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
import com.czg.market.dto.MkShopConsumerCouponDTO;
|
||||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||||
@@ -115,7 +116,7 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
|||||||
@Transactional
|
@Transactional
|
||||||
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
public void addConsumerCoupon(MkShopConsumerCouponDTO param) {
|
||||||
if (CollUtil.isEmpty(param.getCouponGiftList())) {
|
if (CollUtil.isEmpty(param.getCouponGiftList())) {
|
||||||
throw new ValidateException("优惠券信息不能为空");
|
throw new CzgException("优惠券信息不能为空");
|
||||||
}
|
}
|
||||||
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
MkShopConsumerCoupon bean = BeanUtil.toBean(param, MkShopConsumerCoupon.class);
|
||||||
save(bean);
|
save(bean);
|
||||||
@@ -132,7 +133,7 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
|||||||
param.setLeftNum(-10086);
|
param.setLeftNum(-10086);
|
||||||
} else {
|
} else {
|
||||||
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
|
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
|
||||||
throw new ValidateException("修改失败 总发放数量必须大于已发放数量");
|
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
|
||||||
} else {
|
} else {
|
||||||
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
|
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ public class MkShopConsumerCouponServiceImpl extends ServiceImpl<MkShopConsumerC
|
|||||||
param.setLeftNum(-10086);
|
param.setLeftNum(-10086);
|
||||||
} else {
|
} else {
|
||||||
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
|
if (param.getGiveNum() < consumerCoupon.getGiftNum()) {
|
||||||
throw new ValidateException("修改失败 总发放数量必须大于已发放数量");
|
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
|
||||||
} else {
|
} else {
|
||||||
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
|
param.setLeftNum(param.getGiveNum() - consumerCoupon.getGiftNum());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.czg.account.service.ShopUserService;
|
|||||||
import com.czg.account.vo.ShopInfoCouponVO;
|
import com.czg.account.vo.ShopInfoCouponVO;
|
||||||
import com.czg.account.vo.UserCouponFoodVo;
|
import com.czg.account.vo.UserCouponFoodVo;
|
||||||
import com.czg.account.vo.UserCouponVo;
|
import com.czg.account.vo.UserCouponVo;
|
||||||
|
import com.czg.exception.CzgException;
|
||||||
import com.czg.market.dto.MkShopCouponGiftDTO;
|
import com.czg.market.dto.MkShopCouponGiftDTO;
|
||||||
import com.czg.market.dto.ShopCouponDTO;
|
import com.czg.market.dto.ShopCouponDTO;
|
||||||
import com.czg.market.entity.MkShopCouponRecord;
|
import com.czg.market.entity.MkShopCouponRecord;
|
||||||
@@ -191,7 +192,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||||||
if (tbShopCoupon.getGiveNum() == -10086) {
|
if (tbShopCoupon.getGiveNum() == -10086) {
|
||||||
if (param.getGiveNum() != -10086) {
|
if (param.getGiveNum() != -10086) {
|
||||||
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
|
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
|
||||||
throw new ValidateException("修改失败 总发放数量必须大于已发放数量");
|
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
|
||||||
} else {
|
} else {
|
||||||
param.setLeftNum(param.getGiveNum() - tbShopCoupon.getGiftNum());
|
param.setLeftNum(param.getGiveNum() - tbShopCoupon.getGiftNum());
|
||||||
}
|
}
|
||||||
@@ -201,7 +202,7 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||||||
param.setLeftNum(-10086);
|
param.setLeftNum(-10086);
|
||||||
} else {
|
} else {
|
||||||
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
|
if (param.getGiveNum() < tbShopCoupon.getGiftNum()) {
|
||||||
throw new ValidateException("修改失败 总发放数量必须大于已发放数量");
|
throw new CzgException("修改失败 总发放数量必须大于已发放数量");
|
||||||
} else {
|
} else {
|
||||||
param.setLeftNum(param.getGiveNum() - tbShopCoupon.getGiftNum());
|
param.setLeftNum(param.getGiveNum() - tbShopCoupon.getGiftNum());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -221,10 +221,10 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
@Override
|
@Override
|
||||||
public HistoryOrderVo historyOrder(Long orderId, String tableCode) {
|
public HistoryOrderVo historyOrder(Long orderId, String tableCode) {
|
||||||
if (orderId == null && StrUtil.isBlank(tableCode)) {
|
if (orderId == null && StrUtil.isBlank(tableCode)) {
|
||||||
throw new ValidateException("订单id或台桌码不可为空");
|
throw new CzgException("订单id或台桌码不可为空");
|
||||||
}
|
}
|
||||||
if (orderId == null && ("null".equals(tableCode) || "undefined".equals(tableCode))) {
|
if (orderId == null && ("null".equals(tableCode) || "undefined".equals(tableCode))) {
|
||||||
throw new ValidateException("台桌码不可用");
|
throw new CzgException("台桌码不可用");
|
||||||
}
|
}
|
||||||
HistoryOrderVo historyOrderVo;
|
HistoryOrderVo historyOrderVo;
|
||||||
if (orderId == null) {
|
if (orderId == null) {
|
||||||
@@ -267,7 +267,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
ShopInfo shopInfo = shopInfoService.getById(param.getShopId());
|
ShopInfo shopInfo = shopInfoService.getById(param.getShopId());
|
||||||
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
|
AssertUtil.isNull(shopInfo, "生成订单失败,店铺信息不存在");
|
||||||
if (!shopInfo.getEatModel().contains(param.getDineMode())) {
|
if (!shopInfo.getEatModel().contains(param.getDineMode())) {
|
||||||
throw new ValidateException("生成订单失败,店铺不支持该用餐模式");
|
throw new CzgException("生成订单失败,店铺不支持该用餐模式");
|
||||||
}
|
}
|
||||||
if (param.getUserId() != null) {
|
if (param.getUserId() != null) {
|
||||||
UserInfo userInfo = userInfoService.getById(param.getUserId());
|
UserInfo userInfo = userInfoService.getById(param.getUserId());
|
||||||
@@ -545,11 +545,11 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
@Override
|
@Override
|
||||||
public CzgResult<Object> mergeOrder(MergeOrderDTO param) {
|
public CzgResult<Object> mergeOrder(MergeOrderDTO param) {
|
||||||
if (param.getTargetOrderId() == null && StrUtil.isBlank(param.getTargetTableCode())) {
|
if (param.getTargetOrderId() == null && StrUtil.isBlank(param.getTargetTableCode())) {
|
||||||
throw new ValidateException("转台失败,请选择目标台桌后转台");
|
throw new CzgException("转台失败,请选择目标台桌后转台");
|
||||||
}
|
}
|
||||||
OrderInfo sourceOrder = getById(param.getSourceOrderId());
|
OrderInfo sourceOrder = getById(param.getSourceOrderId());
|
||||||
if (sourceOrder == null || !sourceOrder.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
if (sourceOrder == null || !sourceOrder.getStatus().equals(OrderStatusEnums.UNPAID.getCode())) {
|
||||||
throw new ValidateException("转台失败,无可转订单");
|
throw new CzgException("转台失败,无可转订单");
|
||||||
}
|
}
|
||||||
OrderInfo targetOrder = queryChain()
|
OrderInfo targetOrder = queryChain()
|
||||||
.eq(OrderInfo::getId, param.getTargetOrderId())
|
.eq(OrderInfo::getId, param.getTargetOrderId())
|
||||||
@@ -578,7 +578,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
if (CollUtil.isEmpty(param.getDetailIds())) {
|
if (CollUtil.isEmpty(param.getDetailIds())) {
|
||||||
long count = orderDetailService.queryChain().eq(OrderDetail::getOrderId, sourceOrder.getId()).count();
|
long count = orderDetailService.queryChain().eq(OrderDetail::getOrderId, sourceOrder.getId()).count();
|
||||||
if (count < 1) {
|
if (count < 1) {
|
||||||
throw new ValidateException("转台失败,该订单无可转商品");
|
throw new CzgException("转台失败,该订单无可转商品");
|
||||||
}
|
}
|
||||||
orderDetailService.updateChain()
|
orderDetailService.updateChain()
|
||||||
.eq(OrderDetail::getOrderId, sourceOrder.getId())
|
.eq(OrderDetail::getOrderId, sourceOrder.getId())
|
||||||
@@ -699,7 +699,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
ShopCoupon coupon = couponService.getById(record.getCouponId());
|
ShopCoupon coupon = couponService.getById(record.getCouponId());
|
||||||
AssertUtil.isNull(coupon, "生成支付订单失败,券信息不存在");
|
AssertUtil.isNull(coupon, "生成支付订单失败,券信息不存在");
|
||||||
// if (isVipPrice && coupon.getVipPriceShare() != 1) {
|
// if (isVipPrice && coupon.getVipPriceShare() != 1) {
|
||||||
// throw new ValidateException("生成支付订单失败,券:" + coupon.getTitle() + "与会员价不共享");
|
// throw new CzgException("生成支付订单失败,券:" + coupon.getTitle() + "与会员价不共享");
|
||||||
// }
|
// }
|
||||||
isUseLimit(coupon, record);
|
isUseLimit(coupon, record);
|
||||||
// isUseTime(coupon);
|
// isUseTime(coupon);
|
||||||
@@ -719,7 +719,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
.between(MkShopCouponRecord::getUseTime, LocalDateTime.now().with(LocalTime.MIN), LocalDateTime.now().with(LocalTime.MAX))
|
.between(MkShopCouponRecord::getUseTime, LocalDateTime.now().with(LocalTime.MIN), LocalDateTime.now().with(LocalTime.MAX))
|
||||||
);
|
);
|
||||||
if (useNum >= coupon.getUseLimit()) {
|
if (useNum >= coupon.getUseLimit()) {
|
||||||
throw new ValidateException("优惠券:" + coupon.getTitle() + " 已达到今日使用限量");
|
throw new CzgException("优惠券:" + coupon.getTitle() + " 已达到今日使用限量");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -729,7 +729,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
*/
|
*/
|
||||||
private void isUseTime(ShopCoupon coupon) {
|
private void isUseTime(ShopCoupon coupon) {
|
||||||
if (!coupon.getUseDays().contains(CzgStrUtils.getStrWeek())) {
|
if (!coupon.getUseDays().contains(CzgStrUtils.getStrWeek())) {
|
||||||
throw new ValidateException("生成支付订单失败," + coupon.getTitle() + " 今天不可用");
|
throw new CzgException("生成支付订单失败," + coupon.getTitle() + " 今天不可用");
|
||||||
}
|
}
|
||||||
if (!"all".equals(coupon.getUseTimeType())) {
|
if (!"all".equals(coupon.getUseTimeType())) {
|
||||||
// 获取当前时间(仅包含时分秒)
|
// 获取当前时间(仅包含时分秒)
|
||||||
@@ -738,13 +738,13 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
LocalTime endTime = coupon.getUseEndTime().toLocalTime();
|
LocalTime endTime = coupon.getUseEndTime().toLocalTime();
|
||||||
if (currentTime.isBefore(startTime)) {
|
if (currentTime.isBefore(startTime)) {
|
||||||
if (startTime.isBefore(endTime)) {
|
if (startTime.isBefore(endTime)) {
|
||||||
throw new ValidateException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
throw new CzgException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
||||||
} else if (currentTime.isAfter(endTime)) {
|
} else if (currentTime.isAfter(endTime)) {
|
||||||
throw new ValidateException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
throw new CzgException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
||||||
}
|
}
|
||||||
} else if (startTime.isBefore(endTime)) {
|
} else if (startTime.isBefore(endTime)) {
|
||||||
if (currentTime.isAfter(endTime)) {
|
if (currentTime.isAfter(endTime)) {
|
||||||
throw new ValidateException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
throw new CzgException("生成支付订单失败,优惠券:" + coupon.getTitle() + " 当前时段不可用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -784,7 +784,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (calculationAmount.compareTo(fullAmount) < 0) {
|
if (calculationAmount.compareTo(fullAmount) < 0) {
|
||||||
throw new ValidateException("生成支付订单失败," + title + "优惠券门槛金额不足");
|
throw new CzgException("生成支付订单失败," + title + "优惠券门槛金额不足");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -890,7 +890,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (foodsAmount.compareTo(thresholdAmount) < 0) {
|
if (foodsAmount.compareTo(thresholdAmount) < 0) {
|
||||||
throw new ValidateException("优惠券未达到门槛金额");
|
throw new CzgException("优惠券未达到门槛金额");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1393,7 +1393,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
|
|||||||
if (param.getOrderId() != null) {
|
if (param.getOrderId() != null) {
|
||||||
orderInfo = getById(param.getOrderId());
|
orderInfo = getById(param.getOrderId());
|
||||||
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
|
if (!OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus())) {
|
||||||
throw new ValidateException("生成订单失败,订单已结束,请重新下单");
|
throw new CzgException("生成订单失败,订单已结束,请重新下单");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
orderInfo.setOrderNo(param.getPlatformType() + IdUtil.getSnowflakeNextId());
|
orderInfo.setOrderNo(param.getPlatformType() + IdUtil.getSnowflakeNextId());
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
private boolean checkPayVip(VipPayParamDTO payParam) {
|
private boolean checkPayVip(VipPayParamDTO payParam) {
|
||||||
|
|
||||||
if (payParam.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
if (payParam.getAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
throw new ValidateException("充值金额不正确");
|
throw new CzgException("充值金额不正确");
|
||||||
}
|
}
|
||||||
if (payParam.getOrderId() != null) {
|
if (payParam.getOrderId() != null) {
|
||||||
FreeDineConfig freeConfig = freeConfigService.getById(shopInfoService.getMainIdByShopId(payParam.getShopId()));
|
FreeDineConfig freeConfig = freeConfigService.getById(shopInfoService.getMainIdByShopId(payParam.getShopId()));
|
||||||
@@ -691,7 +691,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
}
|
}
|
||||||
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(param.getRefundAmount()));
|
orderInfo.setRefundAmount(orderInfo.getRefundAmount().add(param.getRefundAmount()));
|
||||||
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) > 0) {
|
if (orderInfo.getRefundAmount().compareTo(orderInfo.getPayAmount()) > 0) {
|
||||||
throw new ValidateException("退单失败,可退金额不足");
|
throw new CzgException("退单失败,可退金额不足");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
|
if (CollUtil.isNotEmpty(param.getRefundDetails())) {
|
||||||
@@ -703,7 +703,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
//可退数量=订单数量-退单数量-退菜数量
|
//可退数量=订单数量-退单数量-退菜数量
|
||||||
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
|
BigDecimal returnNum = orderDetail.getNum().subtract(orderDetail.getRefundNum()).subtract(orderDetail.getReturnNum());
|
||||||
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
|
if (returnNum.compareTo(BigDecimal.ZERO) <= 0 || returnNum.compareTo(refundDetail.getNum()) < 0) {
|
||||||
throw new ValidateException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
throw new CzgException("退单失败," + orderDetail.getProductName() + "可退数量不足");
|
||||||
}
|
}
|
||||||
if (isPay) {
|
if (isPay) {
|
||||||
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
|
orderDetail.setRefundNum(orderDetail.getRefundNum().add(refNum));
|
||||||
@@ -916,7 +916,7 @@ public class PayServiceImpl implements PayService {
|
|||||||
//支付宝支付
|
//支付宝支付
|
||||||
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
|
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
|
||||||
} else {
|
} else {
|
||||||
throw new ValidateException("扫描码非法或暂不支持");
|
throw new CzgException("扫描码非法或暂不支持");
|
||||||
}
|
}
|
||||||
CzgResult<CzgMicroPayResp> czgScanPayResult = czgPayService.microPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
|
CzgResult<CzgMicroPayResp> czgScanPayResult = czgPayService.microPay(shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user