feat: 新增支付积分优惠券支持
This commit is contained in:
parent
8aad5da104
commit
7c572d7384
|
|
@ -57,12 +57,17 @@ public interface TableConstant {
|
|||
@Getter
|
||||
public enum Status {
|
||||
REFUNDING("refunding"), REFUND("refund"), CLOSED("closed"), CREATE("create"),
|
||||
UNPAID("unpaid"), PAYING("paying"), RETURN("return");
|
||||
UNPAID("unpaid"), PAYING("paying"), RETURN("return"), FINAL("final");
|
||||
private final String value;
|
||||
|
||||
Status(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean equalsVals(String value) {
|
||||
return this.value.equals(value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
|
|
|||
|
|
@ -90,5 +90,11 @@ public class TbShopCouponController {
|
|||
tbShopCouponService.deleteReceive(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping("activateByOrderId")
|
||||
@ApiOperation("根据订单id获取可用优惠券信息")
|
||||
public ResponseEntity<Object> activateByOrderIds(@RequestParam Integer shopId, @RequestParam Integer orderId, @RequestParam(required = false) Integer memberId) {
|
||||
return ResponseEntity.ok(tbShopCouponService.getActivateByOrderIds(shopId, orderId, memberId));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,8 +175,14 @@ public class TbPlaceController {
|
|||
JSONObject userInfo = JSON.parseObject(JSON.toJSONString(redisUtils.get("online-token-" + token)));
|
||||
String userName = userInfo.getString("userName");
|
||||
String shopId = userInfo.getString("shopId");
|
||||
TbPlussShopStaff shopStaff = staffRepository.queryByAccount(userName, shopId);
|
||||
TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.<TbMerchantAccount>lambdaQuery().eq(TbMerchantAccount::getAccount, shopStaff.getAccount()));
|
||||
TbPlussShopStaff shopStaff;
|
||||
if (userName.contains("@")) {
|
||||
shopStaff = staffRepository.queryMasterAccount(shopId);
|
||||
}else {
|
||||
shopStaff = staffRepository.queryByAccount(userName, shopId);
|
||||
}
|
||||
TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(Wrappers.<TbMerchantAccount>lambdaQuery()
|
||||
.eq(TbMerchantAccount::getAccount, shopStaff.getAccount()));
|
||||
Integer accountId = merchantAccount.getId();
|
||||
Integer staffId = shopStaff.getId();
|
||||
List<TbToken> onlineUserList = tbTokenRepository.findListByAccountIdAndStaffId(accountId, staffId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
package cn.ysk.cashier.dto.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderCartInfoDTO {
|
||||
private BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
private BigDecimal newAddTotalAmount = BigDecimal.ZERO;
|
||||
private List<TbCashierCart> newCashierCarts = new ArrayList<>();
|
||||
private List<TbCashierCart> cashierCarts = new ArrayList<>();
|
||||
private List<Integer> cashierCartIds = new ArrayList<>();
|
||||
private Integer orderId;
|
||||
private TbCashierCart seatCart;
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package cn.ysk.cashier.dto.order;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderCouponInfoDTO {
|
||||
private TbShopUser shopUser;
|
||||
private List<TbActivateOutRecord> outRecordList = new ArrayList<>();
|
||||
// 满减优惠券
|
||||
private HashMap<Integer, TbUserCouponVo> fullReductionCouponMap = new HashMap<>();
|
||||
// 商品优惠券
|
||||
private HashMap<Integer, TbUserCouponVo> productCouponMap = new HashMap<>();
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package cn.ysk.cashier.dto.order;
|
||||
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class OrderPriceDTO {
|
||||
private BigDecimal originAmount = BigDecimal.ZERO;
|
||||
private BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
private BigDecimal packAmount = BigDecimal.ZERO;
|
||||
private boolean hasNewInfo = false;
|
||||
private List<TbOrderDetail> newOrderDetailList = new ArrayList<>();
|
||||
private List<TbOrderDetail> removeOrderDetailList = new ArrayList<>();
|
||||
private List<Integer> removeOrderDetailIds = new ArrayList<>();
|
||||
private List<TbOrderDetail> orderDetailList = new ArrayList<>();
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
package cn.ysk.cashier.dto.order;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
|
||||
@Data
|
||||
public class UserCouponInfoDTO {
|
||||
private Integer userCouponId;
|
||||
@Min(1)
|
||||
private Integer num;
|
||||
}
|
||||
|
|
@ -1,7 +1,11 @@
|
|||
package cn.ysk.cashier.dto.shoptable;
|
||||
|
||||
import cn.ysk.cashier.dto.order.UserCouponInfoDTO;
|
||||
import lombok.Data;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -19,9 +23,11 @@ public class CreateOrderDTO {
|
|||
private Integer orderId;
|
||||
@NotEmpty
|
||||
private String useType;
|
||||
private String vipUserId;
|
||||
private Integer vipUserId;
|
||||
// 使用的优惠券
|
||||
private List<Integer> userCouponIds = new ArrayList<>();
|
||||
@Valid
|
||||
private List<UserCouponInfoDTO> userCouponInfos = new ArrayList<>();
|
||||
// 使用的积分抵扣数量
|
||||
private Integer pointsNum ;
|
||||
private Integer pointsNum;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
package cn.ysk.cashier.dto.shoptable;
|
||||
|
||||
import cn.ysk.cashier.dto.order.UserCouponInfoDTO;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class PayDTO {
|
||||
|
|
@ -20,6 +24,11 @@ public class PayDTO {
|
|||
private Double discount;
|
||||
private Integer vipUserId;
|
||||
private String code;
|
||||
|
||||
private String token;
|
||||
// 使用的优惠券
|
||||
@Valid
|
||||
private List<UserCouponInfoDTO> userCouponInfos = new ArrayList<>();
|
||||
// 使用的积分抵扣数量
|
||||
private Integer pointsNum;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ public class UpdateVipDTO {
|
|||
private String tableId;
|
||||
@NotNull
|
||||
private String masterId;
|
||||
|
||||
private Integer orderId;
|
||||
private Integer vipUserId;
|
||||
@NotNull
|
||||
@Range(min = 0, max = 1)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -17,7 +18,9 @@ import java.util.List;
|
|||
public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord> {
|
||||
|
||||
@Select("SELECT" +
|
||||
" inRecord.coupon_id as id," +
|
||||
" inRecord.id as id," +
|
||||
" inRecord.full_amount as fullAmount," +
|
||||
" inRecord.discount_amount as discountAmount," +
|
||||
" inRecord.coupon_id as couponId," +
|
||||
" pro.id as proId," +
|
||||
" CASE" +
|
||||
|
|
@ -34,14 +37,19 @@ public interface TbActivateInRecordMapper extends BaseMapper<TbActivateInRecord>
|
|||
" inRecord.vip_user_id = #{vipUserId}" +
|
||||
" and inRecord.shop_id = #{shopId}" +
|
||||
" and inRecord.over_num != 0" +
|
||||
" and inRecord.use_start_time < now()" +
|
||||
" and inRecord.use_end_time > now()" +
|
||||
" and inRecord.use_start_time < now()" +
|
||||
" and inRecord.use_end_time > now()" +
|
||||
" order by inRecord.use_end_time asc")
|
||||
List<TbUserCouponVo> queryByVipIdAndShopId(@Param("vipUserId") Integer vipUserId, @Param("shopId") Integer shopId);
|
||||
|
||||
@Select("update tb_activate_in_record" +
|
||||
@Update("update tb_activate_in_record" +
|
||||
" set over_num = #{overNum}" +
|
||||
" where id = #{id}")
|
||||
int updateOverNum(@Param("id") Integer id, @Param("overNum") Integer overNum);
|
||||
|
||||
@Update("update tb_activate_in_record" +
|
||||
" set over_num = over_num-#{overNum}" +
|
||||
" where id = #{id} and over_num-#{overNum} >= 0")
|
||||
int decrOverNum(@Param("id") Integer id, @Param("overNum") Integer decrOverNum);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
/**
|
||||
* 活动赠送商品使用记录表(TbActivateOutRecord)表数据库访问层
|
||||
|
|
@ -13,7 +14,7 @@ import org.apache.ibatis.annotations.Select;
|
|||
*/
|
||||
public interface TbActivateOutRecordMapper extends BaseMapper<TbActivateOutRecord> {
|
||||
|
||||
@Select("update tb_activate_out_record" +
|
||||
@Update("update tb_activate_out_record" +
|
||||
" set ref_num = ref_num + #{refNum}" +
|
||||
" where id = #{id}")
|
||||
int updateRefNum(@Param("id") Integer id, @Param("refNum") Integer refNum);
|
||||
|
|
|
|||
|
|
@ -64,5 +64,11 @@ public interface MpCashierCartService extends IService<TbCashierCart> {
|
|||
*/
|
||||
List<TbCashierCart> selectByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId);
|
||||
|
||||
/**
|
||||
* 根据订单id和状态获取购物车数据
|
||||
* @param orderId 订单id
|
||||
* @param status 状态 可为空
|
||||
*/
|
||||
List<TbCashierCart> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status status);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
import cn.ysk.cashier.pojo.order.TbFullOrderDetail;
|
||||
|
|
@ -42,6 +43,11 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
|||
*/
|
||||
List<TbOrderDetail> selectByOrderId(Integer orderId);
|
||||
|
||||
/**
|
||||
* 根据订单id和状态获取订单详情
|
||||
*/
|
||||
List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state);
|
||||
|
||||
/**
|
||||
* 根据购物车id和订单id查询订单详情
|
||||
* @param shopId 店铺id
|
||||
|
|
@ -49,6 +55,6 @@ public interface MpOrderDetailService extends IService<TbOrderDetail> {
|
|||
* @param orderId 订单id
|
||||
* @return 详情信息
|
||||
*/
|
||||
List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, ArrayList<Integer> cartIdList, Integer orderId);
|
||||
List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, List<Integer> cartIdList, Integer orderId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
|
|
@ -17,6 +18,7 @@ public interface MpOrderInfoService extends IService<TbOrderInfo> {
|
|||
|
||||
/**
|
||||
* 根据原始订单查询退款订单
|
||||
*
|
||||
* @param orderId 原始订单id
|
||||
* @return 对应的退款订单
|
||||
*/
|
||||
|
|
@ -24,10 +26,19 @@ public interface MpOrderInfoService extends IService<TbOrderInfo> {
|
|||
|
||||
/**
|
||||
* 修改订单的就餐类型和tableId
|
||||
*
|
||||
* @param orderId 订单id
|
||||
* @param useType 就餐类型
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateTableIdAndUseTypeById(Integer orderId, String useType, String tableId);
|
||||
|
||||
/**
|
||||
* 根据状态和id获取订单信息
|
||||
* @param orderId 订单id
|
||||
* @param status 状态枚举
|
||||
*/
|
||||
TbOrderInfo selectOrderByIdAndState(Integer orderId, TableConstant.OrderInfo.Status status);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.enums.TableStateEnum;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
public interface MpShopUserService extends IService<TbShopUser> {
|
||||
/**
|
||||
* 根据店铺id和用户id查询会员信息
|
||||
* @param userId 用户id
|
||||
* @param shopId 店铺id
|
||||
* @return 会员信息
|
||||
*/
|
||||
TbShopUser selectByUserIdAndShopId(Integer userId, Integer shopId);
|
||||
}
|
||||
|
|
@ -2,18 +2,26 @@ package cn.ysk.cashier.mybatis.service;
|
|||
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.dto.QueryReceiveDto;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCouponProduct;
|
||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import cn.ysk.cashier.vo.QueryReceiveVo;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
||||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 优惠券(TbShopCoupon)表服务接口
|
||||
|
|
@ -30,6 +38,16 @@ public interface TbShopCouponService extends IService<TbShopCoupon> {
|
|||
|
||||
boolean update(TbShopCouponVo param);
|
||||
boolean delete(Integer[] ids);
|
||||
|
||||
/**
|
||||
* 根据金额获取可用优惠券数据
|
||||
* @param tbShopUser 店铺id
|
||||
* @param orderAmount 用户id
|
||||
* @param productIds 商品id
|
||||
* @return 优惠券信息
|
||||
*/
|
||||
List<TbUserCouponVo> getActivateCoupon(TbShopUser tbShopUser, BigDecimal orderAmount, Integer shopId, Set<String> productIds);
|
||||
|
||||
boolean deleteReceive(Integer[] ids);
|
||||
|
||||
ResponseEntity<Object> find(CouponDto param);
|
||||
|
|
@ -39,5 +57,20 @@ public interface TbShopCouponService extends IService<TbShopCoupon> {
|
|||
boolean refund(List<TbActivateOutRecord> param);
|
||||
|
||||
List<TbCouponProduct> findActivatePros(Integer couponId);
|
||||
|
||||
/**
|
||||
* 根据优惠券id查询优惠券信息
|
||||
* @param couponIds 优惠券id
|
||||
*/
|
||||
List<TbShopCoupon> selectByIds(List<Integer> couponIds);
|
||||
|
||||
/**
|
||||
* 根据订单id获取当前用户可用优惠券信息
|
||||
* @param shopId 店铺id
|
||||
* @param orderId 订单id
|
||||
* @param memberId 会员id
|
||||
*/
|
||||
Object getActivateByOrderIds(Integer shopId, Integer orderId, Integer memberId);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
|||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
|
@ -122,5 +123,14 @@ public class MpCashierCartServiceImpl extends ServiceImpl<TbCashierCartMapper, T
|
|||
}
|
||||
return list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbCashierCart> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status status) {
|
||||
LambdaQueryChainWrapper<TbCashierCart> queryChainWrapper = lambdaQuery().eq(TbCashierCart::getOrderId, orderId);
|
||||
if (status != null) {
|
||||
queryChainWrapper.eq(TbCashierCart::getStatus, status.getValue());
|
||||
}
|
||||
return queryChainWrapper.list();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.dto.shoptable.ReturnOrderDTO;
|
||||
import cn.ysk.cashier.enums.OrderStatusEnums;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbOrderDetailMapper;
|
||||
|
|
@ -48,7 +49,14 @@ public class MpOrderDetailServiceImpl extends ServiceImpl<TbOrderDetailMapper, T
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, ArrayList<Integer> cartIdList, Integer orderId) {
|
||||
public List<TbOrderDetail> selectByOrderIdAndState(Integer orderId, TableConstant.OrderInfo.Status state) {
|
||||
return list(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.eq(TbOrderDetail::getStatus, state.getValue())
|
||||
.eq(TbOrderDetail::getOrderId, orderId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbOrderDetail> selectByCartIdOrOrderId(Integer shopId, List<Integer> cartIdList, Integer orderId) {
|
||||
return list(new LambdaQueryWrapper<TbOrderDetail>()
|
||||
.and(q -> q.in(TbOrderDetail::getCartId, cartIdList).or().eq(TbOrderDetail::getOrderId, orderId))
|
||||
.eq(TbOrderDetail::getShopId, shopId));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCashierCartMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbOrderInfoMapper;
|
||||
import cn.ysk.cashier.mybatis.service.MpCashierCartService;
|
||||
|
|
@ -33,5 +34,12 @@ public class MpOrderInfoServiceImpl extends ServiceImpl<TbOrderInfoMapper, TbOrd
|
|||
.set(TbOrderInfo::getUseType, useType)
|
||||
.set(TbOrderInfo::getTableId, tableId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbOrderInfo selectOrderByIdAndState(Integer orderId, TableConstant.OrderInfo.Status status) {
|
||||
return getOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
.eq(TbOrderInfo::getId, orderId)
|
||||
.eq(TbOrderInfo::getStatus, status.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import cn.ysk.cashier.enums.TableStateEnum;
|
||||
import cn.ysk.cashier.mybatis.mapper.MpShopTableMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.service.MpShopTableService;
|
||||
import cn.ysk.cashier.mybatis.service.MpShopUserService;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopTable;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MpShopUserServiceImpl extends ServiceImpl<TbShopUserMapper, TbShopUser> implements MpShopUserService {
|
||||
@Override
|
||||
public TbShopUser selectByUserIdAndShopId(Integer userId, Integer shopId) {
|
||||
return getOne(new LambdaQueryWrapper<TbShopUser>()
|
||||
.eq(TbShopUser::getUserId, userId)
|
||||
.eq(TbShopUser::getShopId, shopId));
|
||||
}
|
||||
}
|
||||
|
|
@ -4,17 +4,19 @@ import cn.hutool.core.bean.BeanUtil;
|
|||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.dto.QueryReceiveDto;
|
||||
import cn.ysk.cashier.dto.TbShopCouponQueryCriteria;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.*;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateInRecordMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbActivateOutRecordMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbMShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopCouponMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbActivateInRecordService;
|
||||
import cn.ysk.cashier.mybatis.service.TbCouponProductService;
|
||||
import cn.ysk.cashier.mybatis.service.TbShopCouponService;
|
||||
import cn.ysk.cashier.mybatis.service.*;
|
||||
import cn.ysk.cashier.mybatis.vo.TbShopCouponVo;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.product.TbProduct;
|
||||
|
|
@ -70,6 +72,19 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
private TbActivateInRecordMapper inRecordMapper;
|
||||
@Autowired
|
||||
private TbActivateOutRecordMapper outRecordMapper;
|
||||
private final TbMShopUserMapper shopUserMapper;
|
||||
private final MpShopUserService shopUserService;
|
||||
private final MpOrderInfoService mpOrderInfoService;
|
||||
private final MpOrderDetailService mpOrderDetailService;
|
||||
private final MpCashierCartService mpCashierCartService;
|
||||
|
||||
public TbShopCouponServiceImpl(TbMShopUserMapper shopUserMapper, MpShopUserService shopUserService, MpOrderInfoService mpOrderInfoService, MpOrderDetailService mpOrderDetailService, MpCashierCartService mpCashierCartService) {
|
||||
this.shopUserMapper = shopUserMapper;
|
||||
this.shopUserService = shopUserService;
|
||||
this.mpOrderInfoService = mpOrderInfoService;
|
||||
this.mpOrderDetailService = mpOrderDetailService;
|
||||
this.mpCashierCartService = mpCashierCartService;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
@ -77,7 +92,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
Page<TbShopCoupon> page = new Page<>(criteria.getPage(), criteria.getSize());
|
||||
QueryWrapper<TbShopCoupon> wrapper = new QueryWrapper<>();
|
||||
wrapper.eq("shop_id", criteria.getShopId());
|
||||
if (criteria.getType()!=null) {
|
||||
if (criteria.getType() != null) {
|
||||
wrapper.eq("type", criteria.getType());
|
||||
}
|
||||
wrapper.orderByDesc("create_time");
|
||||
|
|
@ -149,6 +164,72 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbUserCouponVo> getActivateCoupon(TbShopUser tbShopUser, BigDecimal orderAmount, Integer shopId, Set<String> productIds) {
|
||||
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(tbShopUser.getId(), shopId);
|
||||
if (tbUserCouponVos.isEmpty()) {
|
||||
return tbUserCouponVos;
|
||||
}
|
||||
String week = DateUtil.dayOfWeekEnum(new Date()).toChinese("周");
|
||||
LocalTime now = LocalTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
//券id 券使用描述
|
||||
Map<Integer, JsonObject> coupons = new HashMap<>();
|
||||
for (TbUserCouponVo tbUserCouponVo : tbUserCouponVos) {
|
||||
if (!coupons.containsKey(tbUserCouponVo.getCouponId())) {
|
||||
setCouponInfo(coupons, tbUserCouponVo, orderAmount, week, now, formatter);
|
||||
}
|
||||
JsonObject couponJson = coupons.get(tbUserCouponVo.getCouponId());
|
||||
tbUserCouponVo.setUseRestrictions(couponJson.get("useRestrictions").toString());
|
||||
if (tbUserCouponVo.getType().equals(1)) {
|
||||
tbUserCouponVo.setUse(couponJson.get("isUse").getAsBoolean());
|
||||
} else if (tbUserCouponVo.getType().equals(2) && couponJson.get("isUse").getAsBoolean()) {
|
||||
if (!productIds.contains(tbUserCouponVo.getProId().toString())) {
|
||||
tbUserCouponVo.setUse(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
||||
return tbUserCouponVos;
|
||||
}
|
||||
|
||||
private void setCouponInfo(Map<Integer, JsonObject> coupons, TbUserCouponVo tbUserCouponVo, BigDecimal amount, String week, LocalTime now, DateTimeFormatter formatter) {
|
||||
JsonObject json = new JsonObject();
|
||||
boolean isUse = true;
|
||||
TbShopCoupon tbShopCoupon = getById(tbUserCouponVo.getCouponId());
|
||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
if (tbShopCoupon.getType().equals(1)) {
|
||||
if (amount.compareTo(new BigDecimal(tbShopCoupon.getFullAmount())) < 0) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(tbShopCoupon.getUserDays())) {
|
||||
String[] split = tbShopCoupon.getUserDays().split(",");
|
||||
if (split.length != 7) {
|
||||
useRestrictions = new StringBuilder(tbShopCoupon.getUserDays() + " ");
|
||||
}
|
||||
if (!tbShopCoupon.getUserDays().contains(week)) {
|
||||
isUse = false;
|
||||
}
|
||||
}
|
||||
if (tbShopCoupon.getUseTimeType().equals("custom")) {
|
||||
if (now.isBefore(tbShopCoupon.getUseStartTime()) || now.isAfter(tbShopCoupon.getUseEndTime())) {
|
||||
isUse = false;
|
||||
}
|
||||
useRestrictions.append(
|
||||
tbShopCoupon.getUseStartTime().format(formatter)
|
||||
+ "-"
|
||||
+ tbShopCoupon.getUseEndTime().format(formatter));
|
||||
} else {
|
||||
useRestrictions.append("全时段");
|
||||
}
|
||||
useRestrictions.append(" 可用");
|
||||
json.addProperty("isUse", isUse);
|
||||
json.addProperty("useRestrictions", useRestrictions.toString());
|
||||
|
||||
coupons.put(tbUserCouponVo.getCouponId(), json);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ResponseEntity<Object> find(CouponDto param) {
|
||||
|
|
@ -225,6 +306,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
|
||||
/**
|
||||
* 使用券
|
||||
*
|
||||
* @param shopId
|
||||
* @param orderId
|
||||
* @param vipUserId
|
||||
|
|
@ -232,7 +314,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean use(Integer shopId,Integer orderId,Integer vipUserId,List<TbActivateOutRecord> param) {
|
||||
public boolean use(Integer shopId, Integer orderId, Integer vipUserId, List<TbActivateOutRecord> param) {
|
||||
for (TbActivateOutRecord outRecord : param) {
|
||||
TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId());
|
||||
inRecord.setOverNum(inRecord.getOverNum() - outRecord.getUseNum());
|
||||
|
|
@ -251,6 +333,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
|
||||
/**
|
||||
* 退还券
|
||||
*
|
||||
* @param param giveId和 refNum 必传
|
||||
* @return
|
||||
*/
|
||||
|
|
@ -258,7 +341,7 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
public boolean refund(List<TbActivateOutRecord> param) {
|
||||
for (TbActivateOutRecord outRecord : param) {
|
||||
outRecord.setUpdateTime(new Date());
|
||||
outRecordMapper.updateRefNum(outRecord.getId(),outRecord.getRefNum());
|
||||
outRecordMapper.updateRefNum(outRecord.getId(), outRecord.getRefNum());
|
||||
TbActivateInRecord inRecord = inRecordMapper.selectById(outRecord.getGiveId());
|
||||
inRecord.setOverNum(inRecord.getOverNum() + outRecord.getRefNum());
|
||||
inRecordMapper.updateOverNum(inRecord.getId(), inRecord.getOverNum());
|
||||
|
|
@ -284,5 +367,46 @@ public class TbShopCouponServiceImpl extends ServiceImpl<TbShopCouponMapper, TbS
|
|||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbShopCoupon> selectByIds(List<Integer> couponIds) {
|
||||
return listByIds(couponIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getActivateByOrderIds(Integer shopId, Integer orderId, Integer memberId) {
|
||||
TbOrderInfo orderInfo = mpOrderInfoService.selectOrderByIdAndState(orderId, TableConstant.OrderInfo.Status.UNPAID);
|
||||
if (orderInfo == null) {
|
||||
throw new BadRequestException("订单信息不存在");
|
||||
}
|
||||
|
||||
if (memberId == null) {
|
||||
memberId = Integer.valueOf(orderInfo.getMemberId());
|
||||
}
|
||||
|
||||
TbShopUser shopUser = shopUserService.getById(memberId);
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户信息不存在");
|
||||
}
|
||||
|
||||
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderId, TableConstant.OrderInfo.Status.UNPAID);
|
||||
List<TbUserCouponVo> activateCouponList = getActivateCoupon(shopUser, orderInfo.getOrderAmount(), shopId, cashierCarts.stream().map(TbCashierCart::getProductId).collect(Collectors.toSet()));
|
||||
// 将优惠券分类为满减和商品
|
||||
ArrayList<TbUserCouponVo> fullReductionCoupon = new ArrayList<>();
|
||||
ArrayList<TbUserCouponVo> productCoupon = new ArrayList<>();
|
||||
activateCouponList.forEach(item -> {
|
||||
if (TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.equalsVals(item.getType())) {
|
||||
fullReductionCoupon.add(item);
|
||||
} else {
|
||||
productCoupon.add(item);
|
||||
}
|
||||
});
|
||||
return new HashMap<String, Object>(){{
|
||||
put("fullReductionCoupon", fullReductionCoupon);
|
||||
put("productCoupon", productCoupon);
|
||||
}};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -163,6 +163,8 @@ public class TbCashierCart implements Serializable {
|
|||
private String useType;
|
||||
@Column(name = "platform_type")
|
||||
private String platformType;
|
||||
// 优惠券id
|
||||
private Integer userCouponId;
|
||||
|
||||
public void copy(TbCashierCart source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ public class TbOrderInfo implements Serializable {
|
|||
// 使用的积分数量
|
||||
private Integer pointsNum;
|
||||
// 用户优惠券id
|
||||
private String userCouponInfoList;
|
||||
private String couponInfoList;
|
||||
// 优惠券折扣金额
|
||||
private BigDecimal productCouponDiscountAmount;
|
||||
// 满减抵扣金额
|
||||
|
|
|
|||
|
|
@ -38,4 +38,7 @@ public interface TbPlussShopStaffRepository extends JpaRepository<TbPlussShopSta
|
|||
@Modifying
|
||||
@Query("update TbPlussShopStaff set name=:name where shopId = :shopId and type='master'")
|
||||
void updateNameById(String name, String shopId);
|
||||
|
||||
@Query("select staff from TbPlussShopStaff as staff where staff.shopId=:shopId and staff.type='master'")
|
||||
TbPlussShopStaff queryMasterAccount(String shopId);
|
||||
}
|
||||
|
|
@ -11,6 +11,11 @@ import cn.ysk.cashier.config.security.security.TokenProvider;
|
|||
import cn.ysk.cashier.cons.RedisConstant;
|
||||
import cn.ysk.cashier.cons.TableConstant;
|
||||
import cn.ysk.cashier.cons.rabbit.RabbitConstants;
|
||||
import cn.ysk.cashier.dto.CouponDto;
|
||||
import cn.ysk.cashier.dto.order.OrderCartInfoDTO;
|
||||
import cn.ysk.cashier.dto.order.OrderCouponInfoDTO;
|
||||
import cn.ysk.cashier.dto.order.OrderPriceDTO;
|
||||
import cn.ysk.cashier.dto.order.UserCouponInfoDTO;
|
||||
import cn.ysk.cashier.dto.points.OrderDeductionPointsDTO;
|
||||
import cn.ysk.cashier.dto.shop.TbShopTableDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopTableQueryCriteria;
|
||||
|
|
@ -18,6 +23,9 @@ import cn.ysk.cashier.dto.shoptable.*;
|
|||
import cn.ysk.cashier.enums.*;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mapper.shop.TbShopTableMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateInRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbActivateOutRecord;
|
||||
import cn.ysk.cashier.mybatis.entity.TbShopCoupon;
|
||||
import cn.ysk.cashier.mybatis.mapper.*;
|
||||
import cn.ysk.cashier.mybatis.service.*;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
|
|
@ -38,11 +46,15 @@ import cn.ysk.cashier.service.impl.TbPayServiceImpl;
|
|||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.service.shop.TbShopTableService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.ActivateInInfoVO;
|
||||
import cn.ysk.cashier.vo.CouponVO;
|
||||
import cn.ysk.cashier.vo.PendingCountVO;
|
||||
import cn.ysk.cashier.vo.TbUserCouponVo;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.dianguang.cloud.ossservice.model.DateUtils;
|
||||
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -118,6 +130,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
private final TbOrderInfoService orderInfoService;
|
||||
private final MpOrderInfoService mpOrderInfoService;
|
||||
private final TbShopUserMapper tbShopUserMapper;
|
||||
private final TbActivateInRecordService activateInRecordService;
|
||||
|
||||
private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO) {
|
||||
// 获取当前台桌最新订单,先付款模式不获取
|
||||
|
|
@ -129,7 +142,8 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.eq(TbOrderInfo::getUseType, eatTypeInfoDTO.getUseType())
|
||||
.eq(TbOrderInfo::getShopId, eatTypeInfoDTO.getShopId())
|
||||
.eq(TbOrderInfo::getTableId, eatTypeInfoDTO.getTableId())
|
||||
.eq(TbOrderInfo::getTradeDay, DateUtils.getDay())
|
||||
.gt(TbOrderInfo::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime())
|
||||
// .eq(TbOrderInfo::getTradeDay, DateUtils.getDay())
|
||||
.orderByDesc(TbOrderInfo::getId)).getRecords();
|
||||
return orderInfoList.isEmpty() ? null : orderInfoList.get(0);
|
||||
}
|
||||
|
|
@ -1107,85 +1121,274 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
TbShopInfo shopInfo = shopInfoRepository.findById(createOrderDTO.getShopId()).orElse(null);
|
||||
if (shopInfo == null) throw new BadRequestException("店铺信息不存在");
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
TbShopTable tbShopTable = null;
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.in(TbShopTable::getStatus, "idle", "using"));
|
||||
if (tbShopTable == null) {
|
||||
throw new BadRequestException("台桌未开台或不存在");
|
||||
}
|
||||
TbShopUser shopUser = null;
|
||||
if (createOrderDTO.getVipUserId() != null) {
|
||||
shopUser = tbShopUserMapper.selectById(createOrderDTO.getVipUserId());
|
||||
}
|
||||
|
||||
|
||||
TbShopTable shopTable = checkTableState(createOrderDTO);
|
||||
// 就餐模式信息
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(createOrderDTO.getShopId(), createOrderDTO.getTableId(), createOrderDTO.getUseType());
|
||||
// 传递orderId直接取否则取当前缓存id
|
||||
Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ?
|
||||
getCurrentOrderId(shopEatTypeInfoDTO) : null;
|
||||
|
||||
List<TbCashierCart> allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, createOrderDTO.getMasterId());
|
||||
List<TbCashierCart> cashierCarts = new ArrayList<>();
|
||||
TbCashierCart seatCart = null;
|
||||
for (TbCashierCart allCashierCart : allCashierCarts) {
|
||||
if (TableConstant.CART_SEAT_ID.equals(allCashierCart.getProductId())) {
|
||||
seatCart = allCashierCart;
|
||||
OrderCartInfoDTO cartInfoDTO = getCartForCreateOrder(shopEatTypeInfoDTO, createOrderDTO.getMasterId());
|
||||
if (cartInfoDTO.getOrderId() == null) {
|
||||
createOrderDTO.setOrderId(shopEatTypeInfoDTO.isDineInAfter() ?
|
||||
getCurrentOrderId(shopEatTypeInfoDTO) : null);
|
||||
}
|
||||
// if (OrderStatusEnums.CREATE.getValue().equals(allCashierCart.getStatus())) {
|
||||
// cashierCarts.add(allCashierCart);
|
||||
// 查询订单
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (cartInfoDTO.getOrderId() != null) {
|
||||
orderInfo = orderInfoMapper.selectById(cartInfoDTO.getOrderId());
|
||||
}
|
||||
|
||||
// OrderCouponInfoDTO couponInfo = null;
|
||||
// if (createOrderDTO.getUserCouponInfos().isEmpty() && createOrderDTO.getVipUserId() != null) {
|
||||
// // 获取优惠券信息
|
||||
// couponInfo = getCouponInfo(createOrderDTO, orderInfo, cartInfoDTO.getNewAddTotalAmount(), cartInfoDTO.getCashierCarts());
|
||||
//
|
||||
// // 根据优惠券信息重新计算购物车相关价格
|
||||
// calcCartPriceWithCoupon(cartInfoDTO.getNewCashierCarts(), couponInfo, couponInfo.getShopUser().getId());
|
||||
// }
|
||||
cashierCarts.add(allCashierCart);
|
||||
|
||||
// 创建订单详情
|
||||
OrderPriceDTO detailPriceDTO = createOrderDetailWithCoupon(cartInfoDTO.getCashierCarts(), cartInfoDTO.getOrderId(), createOrderDTO.getShopId(), true);
|
||||
|
||||
// 是否是第一次创建订单
|
||||
orderInfo = createOrderWithAction(createOrderDTO, detailPriceDTO, shopEatTypeInfoDTO,
|
||||
orderInfo, cartInfoDTO.getSeatCart(), shopUser, shopTable);
|
||||
|
||||
// 修改订单详情并打票
|
||||
updateDetailAndPrint(orderInfo, detailPriceDTO, shopEatTypeInfoDTO);
|
||||
|
||||
// 修改购物车状态和库存
|
||||
updateCartAndStock(cartInfoDTO.getNewCashierCarts(), orderInfo, shopEatTypeInfoDTO);
|
||||
|
||||
// 推送耗材信息
|
||||
pushConsMsg(orderInfo, cartInfoDTO.getNewCashierCarts());
|
||||
|
||||
updateTableState(shopEatTypeInfoDTO, orderInfo, cartInfoDTO.getCashierCarts(), cartInfoDTO.getSeatCart());
|
||||
|
||||
return orderInfo;
|
||||
}, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CREATE_ORDER, createOrderDTO.getShopId(),
|
||||
createOrderDTO.getTableId(), createOrderDTO.getMasterId(), createOrderDTO.getUseType()));
|
||||
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())
|
||||
&& (cashierCarts.isEmpty() ||
|
||||
(shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart != null && cashierCarts.size() < 2)
|
||||
private BigDecimal calcCartPriceWithCoupon(List<TbCashierCart> newCashierCarts, OrderCouponInfoDTO couponInfoDTO, Integer memberId, TbOrderInfo orderInfo) {
|
||||
ArrayList<TbCashierCart> balanceCartList = new ArrayList<>();
|
||||
BigDecimal discountAmount = BigDecimal.ZERO;
|
||||
HashMap<String, TbUserCouponVo> couponMap = new HashMap<>();
|
||||
couponInfoDTO.getProductCouponMap().values().forEach(item -> {
|
||||
couponMap.put(item.getProId().toString(), item);
|
||||
});
|
||||
HashMap<Integer, TbUserCouponVo> usedCouponMap = new HashMap<>();
|
||||
ArrayList<TbActivateOutRecord> outRecords = new ArrayList<>();
|
||||
for (TbCashierCart cashierCart : newCashierCarts) {
|
||||
TbUserCouponVo couponVo = couponMap.get(cashierCart.getProductId());
|
||||
boolean useCoupon;
|
||||
if (couponVo != null) {
|
||||
if (cashierCart.getNumber() < couponVo.getCurrentUseNum()) {
|
||||
throw new BadRequestException("商品数量: {},小于优惠券使用数量: {}", cashierCart.getNumber(), couponVo.getCurrentUseNum());
|
||||
}
|
||||
usedCouponMap.put(Integer.valueOf(cashierCart.getProductId()), couponVo);
|
||||
// 优惠券数量小于购物车数量,分割购物车数据
|
||||
if (cashierCart.getNumber() > couponVo.getCurrentUseNum()) {
|
||||
BigDecimal currentUseNum = BigDecimal.valueOf(couponVo.getCurrentUseNum());
|
||||
BigDecimal cartNum = BigDecimal.valueOf(cashierCart.getNumber());
|
||||
int balanceNum = cashierCart.getTotalNumber() - couponVo.getCurrentUseNum();
|
||||
BigDecimal singlePackFee = cashierCart.getPackFee().divide(cartNum, RoundingMode.HALF_UP);
|
||||
cashierCart.setPackFee(singlePackFee.multiply(currentUseNum));
|
||||
cashierCart.setTotalAmount(cashierCart.getSalePrice().multiply(currentUseNum).add(singlePackFee.multiply(currentUseNum)));
|
||||
cashierCart.setNumber(couponVo.getCurrentUseNum());
|
||||
cashierCart.setTotalNumber(couponVo.getCurrentUseNum());
|
||||
cashierCart.setUserCouponId(couponVo.getId());
|
||||
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
|
||||
|
||||
// 创建结余购物车
|
||||
TbCashierCart balanceCart = BeanUtil.copyProperties(cashierCart, TbCashierCart.class);
|
||||
BigDecimal num = BigDecimal.valueOf(balanceNum);
|
||||
balanceCart.setUserCouponId(null);
|
||||
balanceCart.setId(null);
|
||||
balanceCart.setNumber(balanceNum);
|
||||
balanceCart.setTotalNumber(balanceNum);
|
||||
balanceCart.setPackFee(singlePackFee.multiply(num));
|
||||
balanceCart.setTotalAmount(cashierCart.getSalePrice().multiply(num).add(balanceCart.getPackFee()));
|
||||
balanceCartList.add(balanceCart);
|
||||
} else {
|
||||
discountAmount = discountAmount.add(cashierCart.getTotalAmount());
|
||||
cashierCart.setUserCouponId(couponVo.getId());
|
||||
}
|
||||
// 消耗并返还商品优惠券
|
||||
Integer shopId = Integer.valueOf(cashierCart.getShopId());
|
||||
TbActivateOutRecord tbActivateOutRecord = new TbActivateOutRecord();
|
||||
tbActivateOutRecord.setShopId(shopId);
|
||||
tbActivateOutRecord.setGiveId(couponVo.getId());
|
||||
tbActivateOutRecord.setVipUserId(memberId);
|
||||
tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
|
||||
tbActivateOutRecord.setUseNum(couponVo.getCurrentUseNum());
|
||||
tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
|
||||
tbActivateOutRecord.setCreateTime(DateUtil.date());
|
||||
tbActivateOutRecord.setRefNum(0);
|
||||
outRecords.add(tbActivateOutRecord);
|
||||
}
|
||||
}
|
||||
|
||||
if (!balanceCartList.isEmpty()) {
|
||||
newCashierCarts.addAll(balanceCartList);
|
||||
mpCashierCartService.saveBatch(balanceCartList);
|
||||
}
|
||||
// 更新购物车信息
|
||||
mpCashierCartService.updateBatchById(newCashierCarts);
|
||||
|
||||
couponInfoDTO.setOutRecordList(outRecords);
|
||||
couponInfoDTO.setProductCouponMap(usedCouponMap);
|
||||
|
||||
return discountAmount;
|
||||
}
|
||||
|
||||
private OrderCouponInfoDTO getCouponInfo(Integer memberId, Integer shopId, List<UserCouponInfoDTO> userCouponInfoDTOList, BigDecimal orderAmount, Set<String> productIds) {
|
||||
OrderCouponInfoDTO infoDTO = new OrderCouponInfoDTO();
|
||||
// 查询优惠券信息
|
||||
TbShopUser shopUser = null;
|
||||
if (memberId != null) {
|
||||
shopUser = tbShopUserMapper.selectById(memberId);
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
}
|
||||
// 获取当前用户可用的优惠券
|
||||
List<TbUserCouponVo> activateCouponList = shopCouponService.getActivateCoupon(shopUser, orderAmount, shopId, productIds);
|
||||
// 将优惠券分类为满减和商品
|
||||
HashMap<Integer, TbUserCouponVo> fullReductionCoupon = new HashMap<>();
|
||||
HashMap<Integer, TbUserCouponVo> productCoupon = new HashMap<>();
|
||||
if (activateCouponList.isEmpty()) {
|
||||
throw new BadRequestException("未查询到相关优惠券");
|
||||
}
|
||||
activateCouponList.forEach(item -> {
|
||||
if (TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.equalsVals(item.getType())) {
|
||||
fullReductionCoupon.put(item.getId(), item);
|
||||
} else {
|
||||
productCoupon.put(item.getId(), item);
|
||||
}
|
||||
});
|
||||
|
||||
userCouponInfoDTOList.forEach(item -> {
|
||||
TbUserCouponVo couponVo = fullReductionCoupon.get(item.getUserCouponId());
|
||||
if (couponVo != null) {
|
||||
if (couponVo.getNum() < item.getNum()) {
|
||||
throw new BadRequestException(couponVo.getName() + "数量不足: " + couponVo.getNum());
|
||||
}
|
||||
couponVo.setCurrentUseNum(item.getNum());
|
||||
infoDTO.getFullReductionCouponMap().put(couponVo.getId(), couponVo);
|
||||
return;
|
||||
}
|
||||
couponVo = productCoupon.get(item.getUserCouponId());
|
||||
if (couponVo == null) {
|
||||
throw new BadRequestException("存在不可用优惠券");
|
||||
}
|
||||
couponVo.setCurrentUseNum(item.getNum());
|
||||
infoDTO.getProductCouponMap().put(item.getUserCouponId(), couponVo);
|
||||
});
|
||||
|
||||
}
|
||||
infoDTO.setShopUser(shopUser);
|
||||
|
||||
return infoDTO;
|
||||
}
|
||||
|
||||
private OrderCartInfoDTO getCartForCreateOrder(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId) {
|
||||
OrderCartInfoDTO cartInfoDTO = new OrderCartInfoDTO();
|
||||
|
||||
List<TbCashierCart> allCashierCarts = mpCashierCartService.selectByShopEatType(shopEatTypeInfoDTO, masterId);
|
||||
TbCashierCart seatCart = null;
|
||||
for (TbCashierCart cashierCart : allCashierCarts) {
|
||||
if (TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId())) {
|
||||
seatCart = cashierCart;
|
||||
cartInfoDTO.setSeatCart(cashierCart);
|
||||
}
|
||||
if (OrderStatusEnums.CREATE.getValue().equals(cashierCart.getStatus())) {
|
||||
cartInfoDTO.getNewCashierCarts().add(cashierCart);
|
||||
}
|
||||
cartInfoDTO.getCashierCarts().add(cashierCart);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())
|
||||
&& (cartInfoDTO.getCashierCarts().isEmpty() ||
|
||||
(shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart != null && cartInfoDTO.getCashierCarts().size() < 2)
|
||||
|| (shopEatTypeInfoDTO.isNeedSeatFee() && !shopEatTypeInfoDTO.isTakeout() && seatCart == null))) {
|
||||
throw new BadRequestException("购物车为空或未选择餐位费,请先添加商品或选择餐位费");
|
||||
}
|
||||
|
||||
if (cashierCarts.isEmpty()) {
|
||||
if (cartInfoDTO.getCashierCarts().isEmpty()) {
|
||||
throw new BadRequestException("购物车为空");
|
||||
}
|
||||
|
||||
ArrayList<Integer> cartIdList = new ArrayList<>();
|
||||
for (TbCashierCart tbCashierCart : cashierCarts) {
|
||||
// 订单总价
|
||||
for (TbCashierCart tbCashierCart : cartInfoDTO.getCashierCarts()) {
|
||||
if (tbCashierCart.getOrderId() != null) {
|
||||
orderId = tbCashierCart.getOrderId();
|
||||
cartInfoDTO.setOrderId(tbCashierCart.getOrderId());
|
||||
}
|
||||
cartIdList.add(tbCashierCart.getId());
|
||||
if (TableConstant.CashierCart.Status.CREATE.equalsVals(tbCashierCart.getStatus())) {
|
||||
cartInfoDTO.setNewAddTotalAmount(cartInfoDTO.getNewAddTotalAmount().add(tbCashierCart.getTotalAmount()));
|
||||
}
|
||||
// 查询历史orderDetail
|
||||
List<TbOrderDetail> oldOrderDetailList = mpOrderDetailService.selectByCartIdOrOrderId(createOrderDTO.getShopId(), cartIdList, orderId);
|
||||
|
||||
ArrayList<Integer> removeOrderDetailIds = new ArrayList<>();
|
||||
ArrayList<TbOrderDetail> removeOrderDetailList = new ArrayList<>();
|
||||
cartInfoDTO.setTotalAmount(cartInfoDTO.getTotalAmount().add(tbCashierCart.getTotalAmount()));
|
||||
}
|
||||
cartInfoDTO.setCashierCartIds(cartIdList);
|
||||
return cartInfoDTO;
|
||||
}
|
||||
|
||||
private boolean consumeAndReturnProductCoupon(List<TbActivateOutRecord> outRecordList, Integer memberId, TbOrderInfo orderInfo) {
|
||||
boolean use = shopCouponService.use(Integer.valueOf(orderInfo.getShopId()), orderInfo.getId(), memberId, outRecordList);
|
||||
if (!use) {
|
||||
throw new BadRequestException("消耗券失败");
|
||||
}
|
||||
|
||||
// 返还优惠券
|
||||
if (StrUtil.isNotBlank(orderInfo.getCouponInfoList())) {
|
||||
OrderCouponInfoDTO couponInfoDTO = JSONObject.parseObject(orderInfo.getCouponInfoList(), OrderCouponInfoDTO.class);
|
||||
// 券返还
|
||||
if (!couponInfoDTO.getOutRecordList().isEmpty()) {
|
||||
return shopCouponService.refund(couponInfoDTO.getOutRecordList());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商品优惠券
|
||||
*
|
||||
* @param fullCashierCarts
|
||||
* @param orderId
|
||||
* @param shopId
|
||||
* @param updateState
|
||||
* @return
|
||||
*/
|
||||
private OrderPriceDTO createOrderDetailWithCoupon(List<TbCashierCart> fullCashierCarts, Integer orderId, Integer shopId, boolean updateState) {
|
||||
OrderPriceDTO priceDTO = new OrderPriceDTO();
|
||||
|
||||
List<Integer> cartIds = fullCashierCarts.stream().map(TbCashierCart::getId).collect(Collectors.toList());
|
||||
// 查询历史orderDetail
|
||||
List<TbOrderDetail> oldOrderDetailList = mpOrderDetailService
|
||||
.selectByCartIdOrOrderId(shopId, cartIds, orderId);
|
||||
HashMap<String, TbOrderDetail> oldOrderDetailMap = new HashMap<>();
|
||||
oldOrderDetailList.forEach(item -> {
|
||||
if (cartIdList.contains(item.getCartId())) {
|
||||
if (cartIds.contains(item.getCartId())) {
|
||||
oldOrderDetailMap.put(item.getOrderId().toString() + item.getCartId(), item);
|
||||
} else {
|
||||
removeOrderDetailIds.add(item.getId());
|
||||
removeOrderDetailList.add(item);
|
||||
priceDTO.getRemoveOrderDetailIds().add(item.getId());
|
||||
priceDTO.getRemoveOrderDetailList().add(item);
|
||||
}
|
||||
});
|
||||
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal feeAmount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
// 当前下单次数
|
||||
int placeNum = getCurrentPlaceNum(shopEatTypeInfoDTO);
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
List<TbOrderDetail> addOrderDetails = new ArrayList<>();
|
||||
|
||||
boolean hasNewInfo = false;
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
if (!"return".equals(cashierCart.getStatus())) {
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
feeAmount = cashierCart.getPackFee();
|
||||
for (TbCashierCart cashierCart : fullCashierCarts) {
|
||||
// 已经退款和使用优惠券的商品不进行统计金额
|
||||
if (!"return".equals(cashierCart.getStatus()) && cashierCart.getUserCouponId() == null) {
|
||||
priceDTO.setTotalAmount(priceDTO.getTotalAmount().add(cashierCart.getTotalAmount()));
|
||||
priceDTO.setPackAmount(priceDTO.getPackAmount().add(cashierCart.getPackFee()));
|
||||
priceDTO.setOriginAmount(priceDTO.getOriginAmount().add(cashierCart.getTotalAmount()));
|
||||
}
|
||||
|
||||
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
||||
|
|
@ -1196,12 +1399,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
if (orderDetail == null) {
|
||||
orderDetail = new TbOrderDetail();
|
||||
hasNewInfo = true;
|
||||
addOrderDetails.add(orderDetail);
|
||||
priceDTO.setHasNewInfo(true);
|
||||
priceDTO.getNewOrderDetailList().add(orderDetail);
|
||||
}
|
||||
|
||||
if (Objects.nonNull(productSku)) {
|
||||
saleAmount = saleAmount.add(productSku.getSalePrice());
|
||||
orderDetail.setProductSkuName(productSku.getSpecSnap());
|
||||
}
|
||||
|
||||
|
|
@ -1215,97 +1417,39 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
orderDetail.setProductName(cashierCart.getName());
|
||||
orderDetail.setShopId(Integer.valueOf(cashierCart.getShopId()));
|
||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||
if (updateState) {
|
||||
orderDetail.setStatus(TableConstant.CashierCart.Status.RETURN.equalsVals(cashierCart.getStatus()) ? cashierCart.getStatus() : "unpaid");
|
||||
orderDetail.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
}
|
||||
orderDetail.setUseType(cashierCart.getUseType());
|
||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||
orderDetail.setCartId(cashierCart.getId());
|
||||
if (cashierCart.getOrderId() != null) {
|
||||
orderId = cashierCart.getOrderId();
|
||||
}
|
||||
orderDetail.setOrderId(orderId);
|
||||
orderDetails.add(orderDetail);
|
||||
priceDTO.getOrderDetailList().add(orderDetail);
|
||||
}
|
||||
return priceDTO;
|
||||
}
|
||||
|
||||
// 查询订单
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (orderId != null) {
|
||||
orderInfo = orderInfoMapper.selectById(orderId);
|
||||
}
|
||||
|
||||
TbShopUser shopUser = null;
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
|
||||
shopUser = tbShopUserMapper.selectById(createOrderDTO.getVipUserId());
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
}
|
||||
}
|
||||
|
||||
// 是否是第一次创建订单
|
||||
private TbOrderInfo createOrderWithAction(CreateOrderDTO createOrderDTO, OrderPriceDTO priceDTO, ShopEatTypeInfoDTO eatTypeInfoDTO,
|
||||
TbOrderInfo orderInfo, TbCashierCart seatCart, TbShopUser shopUser, TbShopTable shopTable) {
|
||||
int placeNum = getCurrentPlaceNum(eatTypeInfoDTO);
|
||||
boolean isFirst = false;
|
||||
// 修改订单信息
|
||||
if (orderInfo != null) {
|
||||
// 更新取餐号
|
||||
orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString());
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(totalAmount);
|
||||
orderInfo.setOrderAmount(totalAmount);
|
||||
orderInfo.setRemark(createOrderDTO.getNote());
|
||||
orderInfo.setFreightAmount(feeAmount);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setTradeDay(DateUtils.getDay());
|
||||
orderInfo.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
orderInfo.setCreatedAt(DateUtil.current());
|
||||
if (seatCart != null) {
|
||||
orderInfo.setSeatAmount(seatCart.getTotalAmount());
|
||||
orderInfo.setSeatCount(seatCart.getNumber());
|
||||
}
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
|
||||
orderInfo.setMemberId(createOrderDTO.getVipUserId());
|
||||
orderInfo.setUserId(shopUser.getUserId());
|
||||
}
|
||||
orderInfo.setSendType(shopEatTypeInfoDTO.getSendType());
|
||||
// 存在新添加的商品,增加下单次数
|
||||
if (hasNewInfo) {
|
||||
orderInfo.setPlaceNum(placeNum);
|
||||
}
|
||||
orderInfoMapper.updateById(orderInfo);
|
||||
} else {
|
||||
if (orderInfo == null) {
|
||||
isFirst = true;
|
||||
String orderNo = generateOrderNumber(null);
|
||||
orderInfo = new TbOrderInfo();
|
||||
orderInfo.setOrderNo(orderNo);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setPayAmount(BigDecimal.ZERO);
|
||||
orderInfo.setPackFee(packAMount);
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(totalAmount);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setOrderAmount(totalAmount);
|
||||
orderInfo.setFreightAmount(feeAmount);
|
||||
orderInfo.setTableId(createOrderDTO.getTableId());
|
||||
orderInfo.setSendType("table");
|
||||
orderInfo.setCreatedAt(DateUtil.current());
|
||||
orderInfo.setTradeDay(cn.ysk.cashier.utils.DateUtils.getDay());
|
||||
orderInfo.setRefundAble(1);
|
||||
orderInfo.setOrderType("cash");
|
||||
orderInfo.setShopId(createOrderDTO.getShopId().toString());
|
||||
orderInfo.setRefundAble(1);
|
||||
orderInfo.setTradeDay(cn.ysk.cashier.utils.DateUtils.getDay());
|
||||
orderInfo.setTableId(createOrderDTO.getTableId());
|
||||
orderInfo.setTableName(shopTable != null ? shopTable.getName() : null);
|
||||
orderInfo.setMasterId(createOrderDTO.getMasterId());
|
||||
orderInfo.setOutNumber(createOrderDTO.getMasterId());
|
||||
orderInfo.setRemark(createOrderDTO.getNote());
|
||||
orderInfo.setCreatedAt(DateUtil.current());
|
||||
orderInfo.setTableName(tbShopTable != null ? tbShopTable.getName() : null);
|
||||
orderInfo.setPlaceNum(placeNum);
|
||||
orderInfo.setUseType(shopEatTypeInfoDTO.getUseType());
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getVipUserId())) {
|
||||
orderInfo.setUserId(createOrderDTO.getVipUserId());
|
||||
orderInfo.setUserId(shopUser.getUserId());
|
||||
}
|
||||
if (seatCart != null) {
|
||||
orderInfo.setSeatAmount(seatCart.getTotalAmount());
|
||||
orderInfo.setSeatCount(seatCart.getNumber());
|
||||
}
|
||||
orderInfo.setSendType(shopEatTypeInfoDTO.getSendType());
|
||||
TbMerchantAccount merchantAccount = merchantAccountMapper.selectOne(new LambdaQueryWrapper<TbMerchantAccount>()
|
||||
.eq(TbMerchantAccount::getShopId, createOrderDTO.getShopId())
|
||||
.eq(TbMerchantAccount::getStatus, 1));
|
||||
|
|
@ -1313,24 +1457,81 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException("商户信息不存在");
|
||||
}
|
||||
orderInfo.setMerchantId(merchantAccount.getId().toString());
|
||||
orderInfoMapper.insert(orderInfo);
|
||||
}
|
||||
// 更新取餐号
|
||||
orderInfo.setOutNumber(updateOutNumber(String.valueOf(createOrderDTO.getShopId())).toString());
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(priceDTO.getTotalAmount());
|
||||
orderInfo.setAmount(priceDTO.getTotalAmount());
|
||||
orderInfo.setOriginAmount(priceDTO.getOriginAmount());
|
||||
orderInfo.setOrderAmount(priceDTO.getTotalAmount());
|
||||
orderInfo.setRemark(createOrderDTO.getNote());
|
||||
orderInfo.setFreightAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductAmount(BigDecimal.ZERO);
|
||||
orderInfo.setTradeDay(DateUtils.getDay());
|
||||
orderInfo.setUseType(eatTypeInfoDTO.getUseType());
|
||||
orderInfo.setCreatedAt(DateUtil.current());
|
||||
if (seatCart != null) {
|
||||
orderInfo.setSeatAmount(seatCart.getTotalAmount());
|
||||
orderInfo.setSeatCount(seatCart.getNumber());
|
||||
}
|
||||
if (createOrderDTO.getVipUserId() != null) {
|
||||
orderInfo.setMemberId(String.valueOf(shopUser.getId()));
|
||||
orderInfo.setUserId(shopUser.getUserId());
|
||||
}
|
||||
orderInfo.setSendType(eatTypeInfoDTO.getSendType());
|
||||
// 存在新添加的商品,增加下单次数
|
||||
if (priceDTO.isHasNewInfo()) {
|
||||
orderInfo.setPlaceNum(placeNum);
|
||||
}
|
||||
orderInfoMapper.insertOrUpdate(orderInfo);
|
||||
|
||||
if (isFirst) {
|
||||
// 后付费,不增加当前台桌取餐号
|
||||
if (!eatTypeInfoDTO.isIncrMaterId()) {
|
||||
addGlobalCode(cn.ysk.cashier.utils.DateUtils.getDay(), "pc", String.valueOf(createOrderDTO.getShopId()));
|
||||
}
|
||||
|
||||
if (eatTypeInfoDTO.isIncrMaterId() || "pending".equals(orderInfo.getStatus())) {
|
||||
String key = RedisConstant.getMasterIdKey(createOrderDTO.getShopId(), cn.ysk.cashier.utils.DateUtils.getDay(), orderInfo.getTableId());
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
private void updateDetailAndPrint(TbOrderInfo orderInfo, OrderPriceDTO priceDTO, ShopEatTypeInfoDTO shopEatTypeInfoDTO) {
|
||||
// 添加订单详细数据
|
||||
orderId = orderInfo.getId();
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
Integer orderId = orderInfo.getId();
|
||||
for (TbOrderDetail orderDetail : priceDTO.getOrderDetailList()) {
|
||||
orderDetail.setOrderId(orderId);
|
||||
if (orderDetail.getPlaceNum() == null) {
|
||||
orderDetail.setPlaceNum(placeNum);
|
||||
orderDetail.setPlaceNum(orderInfo.getPlaceNum());
|
||||
}
|
||||
}
|
||||
// 删除已经移除购物车的订单 修改并保存数据
|
||||
if (!orderDetails.isEmpty()) {
|
||||
mpOrderDetailService.saveOrUpdateBatch(orderDetails);
|
||||
if (!priceDTO.getOrderDetailList().isEmpty()) {
|
||||
mpOrderDetailService.saveOrUpdateBatch(priceDTO.getOrderDetailList());
|
||||
}
|
||||
|
||||
// 菜品票
|
||||
if (!priceDTO.getNewOrderDetailList().isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, priceDTO.getNewOrderDetailList().toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
|
||||
if (!priceDTO.getRemoveOrderDetailIds().isEmpty()) {
|
||||
// 退单票
|
||||
orderDetailMapper.deleteBatchIds(priceDTO.getRemoveOrderDetailIds());
|
||||
if (shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), true, priceDTO.getRemoveOrderDetailList().toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateCartAndStock(List<TbCashierCart> newAddCashierCarts, TbOrderInfo orderInfo, ShopEatTypeInfoDTO shopEatTypeInfoDTO) {
|
||||
// 更新购物车记录的orderId
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
for (TbCashierCart cashierCart : newAddCashierCarts) {
|
||||
if (!"-999".equals(cashierCart.getProductId())) {
|
||||
TbProduct product = productMapper.selectById(cashierCart.getProductId());
|
||||
TbProductSku productSku = productSkuRepository.findById(Integer.valueOf(cashierCart.getSkuId())).orElse(null);
|
||||
|
|
@ -1341,54 +1542,29 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
updateStock(cashierCart);
|
||||
}
|
||||
|
||||
cashierCart.setOrderId(orderId);
|
||||
cashierCart.setOrderId(orderInfo.getId());
|
||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||
cashierCart.setStatus("pending".equals(orderInfo.getStatus()) ? "refund" : cashierCart.getStatus());
|
||||
if (cashierCart.getPlaceNum() == null) {
|
||||
cashierCart.setPlaceNum(placeNum);
|
||||
cashierCart.setPlaceNum(orderInfo.getPlaceNum());
|
||||
}
|
||||
|
||||
// 先付费模式,结束购物车状态
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter() || StrUtil.isBlank(createOrderDTO.getTableId())) {
|
||||
if (!shopEatTypeInfoDTO.isDineInAfter() || StrUtil.isBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
cashierCart.setStatus("final");
|
||||
}
|
||||
cashierCartMapper.updateById(cashierCart);
|
||||
}
|
||||
|
||||
// 菜品票
|
||||
if (!addOrderDetails.isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), false, addOrderDetails.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
|
||||
if (!removeOrderDetailIds.isEmpty()) {
|
||||
// 退单票
|
||||
orderDetailMapper.deleteBatchIds(removeOrderDetailIds);
|
||||
if (shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
rabbitMsgUtils.printDishesTicket(orderInfo.getId(), true, removeOrderDetailList.toArray(new TbOrderDetail[0]));
|
||||
}
|
||||
}
|
||||
|
||||
if (isFirst) {
|
||||
// 后付费,不增加当前台桌取餐号
|
||||
if (!shopEatTypeInfoDTO.isIncrMaterId()) {
|
||||
addGlobalCode(cn.ysk.cashier.utils.DateUtils.getDay(), "pc", String.valueOf(createOrderDTO.getShopId()));
|
||||
}
|
||||
|
||||
if (shopEatTypeInfoDTO.isIncrMaterId() || "pending".equals(orderInfo.getStatus())) {
|
||||
String key = RedisConstant.getMasterIdKey(createOrderDTO.getShopId(), cn.ysk.cashier.utils.DateUtils.getDay(), orderInfo.getTableId());
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
}
|
||||
|
||||
// 推送耗材信息
|
||||
pushConsMsg(orderInfo, cashierCarts);
|
||||
|
||||
if (!shopEatTypeInfoDTO.isTakeout() && StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
private void updateTableState(ShopEatTypeInfoDTO shopEatTypeInfoDTO, TbOrderInfo orderInfo, List<TbCashierCart> fullCashierCarts, TbCashierCart seatCart) {
|
||||
if (!shopEatTypeInfoDTO.isTakeout() && StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
// 清空台桌信息
|
||||
if (shopEatTypeInfoDTO.isDineInBefore()) {
|
||||
mpShopTableMapper.update(null, new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.eq(TbShopTable::getShopId, shopEatTypeInfoDTO.getShopId())
|
||||
.eq(TbShopTable::getQrcode, shopEatTypeInfoDTO.getTableId())
|
||||
.set(TbShopTable::getProductNum, 0)
|
||||
.set(TbShopTable::getTotalAmount, 0)
|
||||
.set(TbShopTable::getRealAmount, 0)
|
||||
|
|
@ -1397,14 +1573,14 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
// 设置台桌信息
|
||||
} else {
|
||||
LambdaUpdateWrapper<TbShopTable> wrapper = new LambdaUpdateWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getShopId, createOrderDTO.getShopId())
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.set(TbShopTable::getProductNum, cashierCarts.size())
|
||||
.eq(TbShopTable::getShopId, shopEatTypeInfoDTO.getShopId())
|
||||
.eq(TbShopTable::getQrcode, shopEatTypeInfoDTO.getTableId())
|
||||
.set(TbShopTable::getProductNum, fullCashierCarts.size())
|
||||
.set(TbShopTable::getTotalAmount, orderInfo.getOrderAmount())
|
||||
.set(TbShopTable::getRealAmount, orderInfo.getOrderAmount())
|
||||
.set(TbShopTable::getUseNum, seatCart != null ? seatCart.getNumber() : null)
|
||||
.set(TbShopTable::getStatus, TableStateEnum.USING.getState());
|
||||
if (isFirst) {
|
||||
if (orderInfo.getPlaceNum() == 1) {
|
||||
wrapper.set(TbShopTable::getUseTime, DateUtil.date());
|
||||
}
|
||||
mpShopTableMapper.update(null, wrapper);
|
||||
|
|
@ -1412,18 +1588,28 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
String tableCartKey = RedisConstant.getTableCartKey(createOrderDTO.getTableId(), createOrderDTO.getShopId().toString());
|
||||
if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) {
|
||||
String tableCartKey = RedisConstant.getTableCartKey(shopEatTypeInfoDTO.getTableId(), shopEatTypeInfoDTO.getShopId().toString());
|
||||
redisTemplate.delete(tableCartKey);
|
||||
}
|
||||
return orderInfo;
|
||||
}, stringRedisTemplate, RedisConstant.getLockKey(RedisConstant.CREATE_ORDER, createOrderDTO.getShopId(),
|
||||
createOrderDTO.getTableId(), createOrderDTO.getMasterId(), createOrderDTO.getUseType()));
|
||||
|
||||
}
|
||||
|
||||
private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List<Integer> userCouponList, Integer pointsNum) {
|
||||
private TbShopTable checkTableState(CreateOrderDTO createOrderDTO) {
|
||||
|
||||
// 非堂食校验台桌状态
|
||||
TbShopTable tbShopTable = null;
|
||||
if (StrUtil.isNotBlank(createOrderDTO.getTableId())) {
|
||||
tbShopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper<TbShopTable>()
|
||||
.eq(TbShopTable::getQrcode, createOrderDTO.getTableId())
|
||||
.in(TbShopTable::getStatus, "idle", "using"));
|
||||
if (tbShopTable == null) {
|
||||
throw new BadRequestException("台桌未开台或不存在");
|
||||
}
|
||||
}
|
||||
return tbShopTable;
|
||||
}
|
||||
|
||||
private void calculateOrderCouponAndPoints(TbOrderInfo orderInfo, List<Integer> mineUserCouponList, Integer pointsNum) {
|
||||
BigDecimal shouldPayAmount = BigDecimal.ZERO;
|
||||
if (pointsNum != null) {
|
||||
Long memberId = Long.valueOf(orderInfo.getMemberId());
|
||||
|
|
@ -1442,8 +1628,42 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
memberPointsService.deductPoints(memberId, pointsNum, "霸王餐充值抵扣", Long.valueOf(orderInfo.getId()));
|
||||
}
|
||||
|
||||
if (!userCouponList.isEmpty()) {
|
||||
if (!mineUserCouponList.isEmpty()) {
|
||||
CouponDto couponDto = new CouponDto();
|
||||
couponDto.setShopId(Integer.valueOf(orderInfo.getShopId()));
|
||||
couponDto.setUserId(Integer.valueOf(orderInfo.getUserId()));
|
||||
couponDto.setStatus(1);
|
||||
couponDto.setOrderId(orderInfo.getId());
|
||||
List<TbUserCouponVo> userCouponList = (List<TbUserCouponVo>) shopCouponService.find(couponDto).getBody();
|
||||
if (userCouponList == null || userCouponList.isEmpty()) {
|
||||
throw new BadRequestException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
ArrayList<ActivateInInfoVO> activateInInfoVOS = new ArrayList<>();
|
||||
for (Integer userCouponId : mineUserCouponList) {
|
||||
TbUserCouponVo userCouponVo = userCouponList.stream().filter(item -> item.getId().equals(userCouponId)).findFirst().orElse(null);
|
||||
if (userCouponVo == null) {
|
||||
throw new BadRequestException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
shouldPayAmount = shouldPayAmount.subtract(userCouponVo.getDiscountAmount());
|
||||
ActivateInInfoVO activateInInfoVO = new ActivateInInfoVO()
|
||||
.setId(userCouponVo.getId())
|
||||
.setCouponId(userCouponVo.getCouponId())
|
||||
.setType(userCouponVo.getType())
|
||||
.setNum(1);
|
||||
activateInInfoVOS.add(activateInInfoVO);
|
||||
}
|
||||
|
||||
List<TbShopCoupon> tbShopCoupons = shopCouponService.listByIds(activateInInfoVOS.stream().map(ActivateInInfoVO::getCouponId).collect(Collectors.toList()));
|
||||
if (tbShopCoupons.size() != mineUserCouponList.size()) {
|
||||
throw new BadRequestException("存在不可用优惠券");
|
||||
}
|
||||
|
||||
// 设置优惠券信息
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(activateInInfoVOS));
|
||||
orderInfo.setUserCouponAmount(BigDecimal.valueOf(tbShopCoupons.stream().map(TbShopCoupon::getDiscountAmount).reduce(0, Integer::sum)));
|
||||
// record.setCouponInfo(JSONObject.toJSONString(userCouponList));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1588,7 +1808,115 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
return payTypeRepository.findByShopId(String.valueOf(shopId));
|
||||
}
|
||||
|
||||
private TbActivateOutRecord calcOrderInfoDiscount(PayDTO payDTO, TbOrderInfo orderInfo, OrderCouponInfoDTO couponInfo) {
|
||||
if (payDTO.getVipUserId() != null) {
|
||||
BigDecimal finalAmount = orderInfo.getOrderAmount();
|
||||
TbActivateOutRecord tbActivateOutRecord = null;
|
||||
if (!couponInfo.getFullReductionCouponMap().isEmpty()) {
|
||||
TbUserCouponVo couponVo = couponInfo.getFullReductionCouponMap().values().stream().findFirst().orElse(null);
|
||||
finalAmount =finalAmount.subtract(couponVo.getDiscountAmount());
|
||||
orderInfo.setFullCouponDiscountAmount(couponVo.getDiscountAmount());
|
||||
|
||||
tbActivateOutRecord = new TbActivateOutRecord();
|
||||
tbActivateOutRecord.setShopId(Integer.valueOf(orderInfo.getShopId()));
|
||||
tbActivateOutRecord.setGiveId(couponVo.getId());
|
||||
tbActivateOutRecord.setVipUserId(payDTO.getVipUserId());
|
||||
tbActivateOutRecord.setType(TableConstant.ActivateOutRecord.Type.FULL_REDUCTION.getValue());
|
||||
tbActivateOutRecord.setUseNum(couponVo.getCurrentUseNum());
|
||||
tbActivateOutRecord.setStatus(TableConstant.ActivateOutRecord.Status.CLOSED.getValue());
|
||||
tbActivateOutRecord.setCreateTime(DateUtil.date());
|
||||
tbActivateOutRecord.setRefNum(0);
|
||||
|
||||
}
|
||||
|
||||
// 计算积分优惠
|
||||
if (payDTO.getPointsNum() != null && payDTO.getPointsNum() != 0) {
|
||||
BigDecimal discountPointsAmount = calcPointsDiscountAndReturn(orderInfo, payDTO.getPointsNum());
|
||||
finalAmount = finalAmount.subtract(discountPointsAmount);
|
||||
orderInfo.setPointsDiscountAmount(discountPointsAmount);
|
||||
}
|
||||
|
||||
if (finalAmount.compareTo(BigDecimal.ZERO) < 0) {
|
||||
finalAmount = BigDecimal.ZERO;
|
||||
orderInfo.setFullCouponDiscountAmount(orderInfo.getOrderAmount());
|
||||
}
|
||||
|
||||
orderInfo.setSettlementAmount(finalAmount);
|
||||
orderInfo.setOrderAmount(finalAmount);
|
||||
orderInfo.setAmount(finalAmount);
|
||||
|
||||
return tbActivateOutRecord;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private BigDecimal calcPointsDiscountAndReturn(TbOrderInfo orderInfo, int pointsNum) {
|
||||
Long memberId = Long.valueOf(orderInfo.getMemberId());
|
||||
|
||||
if (orderInfo.getPointsNum() != null && orderInfo.getPointsNum() != 0) {
|
||||
memberPointsService.addPoints(memberId, orderInfo.getPointsNum(), "用户未支付订单积分返还: " + orderInfo.getPointsNum() + "积分", Long.valueOf(orderInfo.getId()));
|
||||
}
|
||||
|
||||
OrderDeductionPointsDTO memberUsablePoints = memberPointsService.getMemberUsablePoints(memberId, orderInfo.getOrderAmount());
|
||||
if (!memberUsablePoints.getUsable()) {
|
||||
throw new BadRequestException(memberUsablePoints.getUnusableReason());
|
||||
}
|
||||
if (pointsNum < memberUsablePoints.getMinDeductionPoints() || pointsNum > memberUsablePoints.getMaxUsablePoints()) {
|
||||
throw new BadRequestException("可抵扣积分区间为: [" + memberUsablePoints.getMinDeductionPoints() + "-" + memberUsablePoints.getMaxUsablePoints() + "]");
|
||||
}
|
||||
|
||||
BigDecimal discountAmount = memberPointsService.calcDeductionAmount(memberId, orderInfo.getOrderAmount(), pointsNum);
|
||||
orderInfo.setPointsNum(pointsNum);
|
||||
orderInfo.setPointsDiscountAmount(discountAmount);
|
||||
memberPointsService.deductPoints(memberId, pointsNum, "订单积分抵扣" + discountAmount + "元", Long.valueOf(orderInfo.getId()));
|
||||
return discountAmount;
|
||||
}
|
||||
|
||||
private void calcDiscountAndUpdateInfo(PayDTO payDTO, TbOrderInfo orderInfo) {
|
||||
Set<String> productIdSet = new HashSet<>();
|
||||
List<TbCashierCart> cashierCarts = mpCashierCartService.selectByOrderIdAndState(orderInfo.getId(), null);
|
||||
ArrayList<TbCashierCart> activateCartInfo = new ArrayList<>();
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
productIdSet.add(cashierCart.getProductId());
|
||||
if (TableConstant.OrderInfo.Status.CREATE.equalsVals(cashierCart.getStatus()) || TableConstant.OrderInfo.Status.FINAL.equalsVals(cashierCart.getStatus())) {
|
||||
activateCartInfo.add(cashierCart);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取优惠券信息
|
||||
OrderCouponInfoDTO couponInfo = new OrderCouponInfoDTO();
|
||||
if (!payDTO.getUserCouponInfos().isEmpty()) {
|
||||
couponInfo = getCouponInfo(payDTO.getVipUserId(), payDTO.getShopId(), payDTO.getUserCouponInfos(),
|
||||
orderInfo.getOrderAmount(), productIdSet);
|
||||
}
|
||||
|
||||
BigDecimal productDiscount = calcCartPriceWithCoupon(activateCartInfo, couponInfo, payDTO.getVipUserId(), orderInfo);
|
||||
orderInfo.setProductCouponDiscountAmount(productDiscount);
|
||||
|
||||
OrderPriceDTO priceDTO = createOrderDetailWithCoupon(activateCartInfo, orderInfo.getId(), payDTO.getShopId(), false);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(priceDTO.getTotalAmount());
|
||||
orderInfo.setAmount(priceDTO.getTotalAmount());
|
||||
orderInfo.setOrderAmount(priceDTO.getTotalAmount());
|
||||
|
||||
// 计算订单优惠
|
||||
TbActivateOutRecord outRecord = calcOrderInfoDiscount(payDTO, orderInfo, couponInfo);
|
||||
if (outRecord != null) {
|
||||
couponInfo.getOutRecordList().add(outRecord);
|
||||
}
|
||||
|
||||
// 消耗优惠券并返回上次未使用的券
|
||||
consumeAndReturnProductCoupon(couponInfo.getOutRecordList(), payDTO.getVipUserId(), orderInfo);
|
||||
|
||||
orderInfo.setCouponInfoList(JSONObject.toJSONString(couponInfo));
|
||||
// 更新订单信息
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Object pay(PayDTO payDTO) {
|
||||
return Utils.runFunAndCheckKey(() -> {
|
||||
long count = tbShopPayTypeMapper.selectCount(new LambdaQueryWrapper<TbShopPayType>()
|
||||
|
|
@ -1599,9 +1927,13 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
throw new BadRequestException("未知支付方式");
|
||||
}
|
||||
|
||||
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectById(payDTO.getOrderId());
|
||||
|
||||
// 计算优惠券价格信息
|
||||
if (payDTO.getVipUserId() != null) {
|
||||
calcDiscountAndUpdateInfo(payDTO, orderInfo);
|
||||
}
|
||||
|
||||
if (ObjectUtil.isEmpty(orderInfo)) {
|
||||
throw new BadRequestException("订单不存在");
|
||||
}
|
||||
|
|
@ -1770,7 +2102,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
|
||||
List<TbCashierCart> tbCashierCarts = cashierCartMapper.selectList(queryWrapper.isNotNull(TbCashierCart::getOrderId));
|
||||
if (!tbCashierCarts.isEmpty()) {
|
||||
Integer orderId = tbCashierCarts.get(0).getOrderId();
|
||||
Integer orderId = updateVipDTO.getOrderId();
|
||||
if (updateVipDTO.getType() == 0) {
|
||||
TbShopUser shopUser = tbShopUserMapper.selectById(updateVipDTO.getVipUserId());
|
||||
if (shopUser == null) {
|
||||
|
|
@ -2121,7 +2453,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
.add(returnPackFee));
|
||||
orderDetail.setPackAmount(returnPackFee);
|
||||
orderDetail.setRefundNumber(returnNum);
|
||||
orderDetail.setStatus("refunding");
|
||||
orderDetail.setStatus(isOnline ? "refunding" : "refund");
|
||||
}
|
||||
|
||||
if (returnAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
|
|
@ -2141,7 +2473,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
returnOrder.setOrderNo(orderNo);
|
||||
returnOrder.setRefundAmount(returnAmount);
|
||||
returnOrder.setOrderType("return");
|
||||
returnOrder.setStatus("refunding");
|
||||
returnOrder.setStatus(isOnline ? "refunding" : "refund");
|
||||
returnOrder.setUpdatedAt(null);
|
||||
returnOrder.setSystemTime(DateUtil.current());
|
||||
returnOrder.setCreatedAt(DateUtil.current());
|
||||
|
|
@ -2221,12 +2553,11 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
if ("1".equals(shopInfo.getIsReturn())) {
|
||||
// TODO 密码校验
|
||||
}
|
||||
|
||||
HashMap<String, Object> returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, true);
|
||||
String payType = orderInfo.getPayType();
|
||||
HashMap<String, Object> returnInfoData = updateReturnOrderInfo(returnOrderDTO, orderInfo, "scanCode".equals(payType) || "wx_lite".equals(payType));
|
||||
TbOrderInfo returnOrderInfo = (TbOrderInfo) returnInfoData.get("returnOrder");
|
||||
BigDecimal returnAmount = (BigDecimal) returnInfoData.get("returnAmount");
|
||||
String shopId = orderInfo.getShopId();
|
||||
String payType = orderInfo.getPayType();
|
||||
|
||||
// // 线上退款
|
||||
orderInfo.setRefundAmount(returnOrderInfo.getRefundAmount());
|
||||
|
|
@ -2264,6 +2595,20 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
|||
long cartCount = mpCashierCartService.countByTableId(shopId, tableId, OrderStatusEnums.CREATE, OrderStatusEnums.RETURN);
|
||||
Map<String, Object> map = BeanUtil.beanToMap(tbShopTable, false, false);
|
||||
map.put("cartCount", cartCount);
|
||||
|
||||
TbOrderInfo orderInfo = null;
|
||||
if (StrUtil.isNotBlank(tbShopTable.getQrcode())) {
|
||||
try {
|
||||
|
||||
ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(tbShopTable.getShopId(), tbShopTable.getQrcode());
|
||||
orderInfo = getCurrentOrder(shopEatTypeInfoDTO);
|
||||
} catch (Exception e) {
|
||||
log.info(e.getMessage());
|
||||
}
|
||||
}
|
||||
map.put("orderId", orderInfo == null ? null : orderInfo.getId());
|
||||
map.put("useType", orderInfo == null ? null : orderInfo.getUseType());
|
||||
map.put("masterId", orderInfo == null ? null : orderInfo.getMasterId());
|
||||
return map;
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class ActivateInInfoVO {
|
||||
private Integer id;
|
||||
private Integer couponId;
|
||||
private Integer num;
|
||||
// 1满减 2商品
|
||||
private Integer type;
|
||||
}
|
||||
|
||||
|
|
@ -2,11 +2,14 @@ package cn.ysk.cashier.vo;
|
|||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class TbUserCouponVo {
|
||||
private Integer id;
|
||||
private BigDecimal fullAmount;
|
||||
private BigDecimal discountAmount;
|
||||
private Integer couponId;
|
||||
private Integer proId;
|
||||
//优惠券名称
|
||||
|
|
@ -20,6 +23,8 @@ public class TbUserCouponVo {
|
|||
private Long expireTime;
|
||||
private String useRestrictions;
|
||||
private boolean isUse = false;
|
||||
//当前使用数量
|
||||
private Integer currentUseNum;
|
||||
|
||||
|
||||
public void setEndTime(Date endTime) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue