Merge branch 'ww' into test
This commit is contained in:
@@ -76,10 +76,6 @@ public class CartService {
|
||||
private TbOrderDetailMapper orderDetailMapper;
|
||||
@Autowired
|
||||
private TbShopTableMapper shopTableMapper;
|
||||
@Autowired
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
@Autowired
|
||||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||
private final WechatUtil wechatUtil;
|
||||
|
||||
@@ -843,27 +839,6 @@ public class CartService {
|
||||
cart.setPackFee(BigDecimal.ZERO);
|
||||
}
|
||||
|
||||
if (cart.getIsVip().equals((byte) 1)) {
|
||||
if (isVip) {
|
||||
int i1 = activateInRecordService.queryByVipIdAndShopIdAndProId(
|
||||
Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId), Integer.valueOf(cart.getProductId()));
|
||||
if (i1 < cart.getTotalNumber()) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "会员商品[" + cart.getName() + "],可下单数量为" + i1);
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "非会员用户不可下单会员商品");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
TbProductSkuWithBLOBs tbProduct;
|
||||
if (!"-999".equals(cart.getProductId())) {
|
||||
tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cart.getSkuId()));
|
||||
@@ -966,63 +941,6 @@ public class CartService {
|
||||
//生成订单
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
|
||||
//优惠卷
|
||||
String isBuyYhq = "false";
|
||||
String isuseYhq = "false";
|
||||
if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) {
|
||||
couponId = jsonObject.getString("couponsId");
|
||||
//1:购买优惠券,0:自己持有优惠券
|
||||
Integer couponsId = jsonObject.getInteger("couponsId");
|
||||
if (jsonObject.getString("isBuyYhq").equals("1")) {
|
||||
TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) {
|
||||
log.info("开始处理订单");
|
||||
responseData.put("status", "fail");
|
||||
responseData.put("msg", "优惠券已售空");
|
||||
responseData.put("type", jsonObject.getString("type"));
|
||||
responseData.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return Result.fail("优惠券已售空");
|
||||
}
|
||||
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
responseData.put("status", "fail");
|
||||
responseData.put("msg", "订单金额小于优惠价金额");
|
||||
responseData.put("type", jsonObject.getString("type"));
|
||||
responseData.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(responseData.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return Result.fail("订单金额小于优惠价金额");
|
||||
}
|
||||
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
|
||||
originAmount = originAmount.add(systemCoupons.getCouponsPrice());
|
||||
couponAmount = systemCoupons.getCouponsAmount();
|
||||
systemCoupons.setStatus("1");
|
||||
systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons);
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum()));
|
||||
userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount());
|
||||
userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setUserId(userId);
|
||||
userCoupons.setCreateTime(new Date());
|
||||
userCouponsMapper.insert(userCoupons);
|
||||
couponId = userCoupons.getId() + "";
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
} else {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
|
||||
totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30));
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
}
|
||||
isuseYhq = "true";
|
||||
|
||||
}
|
||||
|
||||
if (orderInfo != null) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
@@ -1044,8 +962,6 @@ public class CartService {
|
||||
orderInfo.setOrderAmount(totalAmount.add(packAMount));
|
||||
orderInfo.setFreightAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setIsUseCoupon(isuseYhq);
|
||||
orderInfo.setRemark(remark);
|
||||
orderInfo.setUserId(userId);
|
||||
if (hasNewInfo) {
|
||||
@@ -1061,8 +977,6 @@ public class CartService {
|
||||
orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId()));
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setIsUseCoupon(isuseYhq);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfo.setRemark(remark);
|
||||
orderInfo.setUserId(userId);
|
||||
@@ -1104,29 +1018,7 @@ public class CartService {
|
||||
}
|
||||
|
||||
// 去除餐位费信息
|
||||
|
||||
List<TbActivateOutRecord> outRecords = new ArrayList<>();
|
||||
for (TbCashierCart cashierCart : cashierCartList) {
|
||||
if (!cashierCart.getProductId().equals("-999") && cashierCart.getIsVip().equals((byte) 1)) {
|
||||
List<TbActivateInRecord> actInRecords = activateInRecordService.queryAllByVipIdAndShopIdAndProId(
|
||||
Integer.valueOf(tbShopUser.getId()), Integer.valueOf(orderInfo.getShopId()), Integer.valueOf(cashierCart.getProductId()));
|
||||
Integer totalNumber = cashierCart.getTotalNumber();
|
||||
for (TbActivateInRecord actInRecord : actInRecords) {
|
||||
if (totalNumber > 0) {
|
||||
if (actInRecord.getOverNum() > totalNumber) {
|
||||
TbActivateOutRecord outRecord = new TbActivateOutRecord(actInRecord.getId(), actInRecord.getProId(), totalNumber, orderInfo.getId().toString(), "create");
|
||||
outRecords.add(outRecord);
|
||||
activateInRecordService.updateOverNumById(actInRecord.getId(), actInRecord.getOverNum() - totalNumber);
|
||||
break;
|
||||
} else {
|
||||
TbActivateOutRecord outRecord = new TbActivateOutRecord(actInRecord.getId(), actInRecord.getProId(), actInRecord.getOverNum(), orderInfo.getId().toString(), "create");
|
||||
outRecords.add(outRecord);
|
||||
activateInRecordService.updateOverNumById(actInRecord.getId(), 0);
|
||||
totalNumber = totalNumber - actInRecord.getOverNum();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||
cashierCart.setOrderId(orderId + "");
|
||||
if ((!TableConstant.CART_SEAT_ID.equals(cashierCart.getProductId()) && !shopEatTypeInfoDTO.isDineInAfter())
|
||||
@@ -1145,7 +1037,6 @@ public class CartService {
|
||||
// cashierCartMapper.deleteByPrimaryKey(seatCartInfo.getId());
|
||||
// }
|
||||
|
||||
if (!CollectionUtils.isEmpty(outRecords)) outRecordMapper.insertBatch(outRecords);
|
||||
|
||||
// 打印票据
|
||||
if (!addOrderDetail.isEmpty() && shopEatTypeInfoDTO.isDineInAfter()) {
|
||||
@@ -1354,84 +1245,6 @@ public class CartService {
|
||||
TbShopTable shopTable = shopTableMapper.selectQRcode(jsonObject.getString("tableId"));
|
||||
//生成订单
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
String isBuyYhq = "false";
|
||||
String isuseYhq = "false";
|
||||
if (jsonObject.containsKey("isYhq") && jsonObject.getString("isYhq").equals("1")) {
|
||||
couponId = jsonObject.getString("couponsId");
|
||||
//1:购买优惠券,0:自己持有优惠券
|
||||
Integer couponsId = jsonObject.getInteger("couponsId");
|
||||
if (jsonObject.getString("isBuyYhq").equals("1")) {
|
||||
TbSystemCoupons systemCoupons = systemCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
if (Objects.isNull(systemCoupons) || !systemCoupons.getStatus().equals("0")) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "优惠券已售空");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
if (N.gt(systemCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "订单金额小于优惠价金额");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
totalAmount = totalAmount.add(systemCoupons.getCouponsPrice()).subtract(systemCoupons.getCouponsAmount());
|
||||
originAmount = originAmount.add(systemCoupons.getCouponsPrice());
|
||||
couponAmount = systemCoupons.getCouponsAmount();
|
||||
systemCoupons.setStatus("1");
|
||||
systemCouponsMapper.updateByPrimaryKeySelective(systemCoupons);
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 3, systemCoupons.getDayNum()));
|
||||
userCoupons.setCouponsAmount(systemCoupons.getCouponsAmount());
|
||||
userCoupons.setCouponsPrice(systemCoupons.getCouponsPrice());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setUserId(userId);
|
||||
userCoupons.setCreateTime(new Date());
|
||||
userCouponsMapper.insert(userCoupons);
|
||||
couponId = userCoupons.getId() + "";
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
} else {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(couponsId);
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "优惠券已使用");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
if (N.gt(userCoupons.getCouponsAmount(), totalAmount)) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "订单金额小于优惠价金额");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), tableCartKey, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
totalAmount = totalAmount.subtract(userCoupons.getCouponsAmount());
|
||||
userCoupons.setStatus("1");
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(), 5, 30));
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
couponAmount = userCoupons.getCouponsAmount();
|
||||
}
|
||||
isuseYhq = "true";
|
||||
|
||||
}
|
||||
if (Objects.nonNull(orderInfo)) {
|
||||
log.info("订单状态:" + orderInfo.getStatus());
|
||||
if (!"unpaid".equals(orderInfo.getStatus())) {
|
||||
@@ -1456,16 +1269,12 @@ public class CartService {
|
||||
orderInfo.setOrderAmount(totalAmount.add(packAMount));
|
||||
orderInfo.setFreightAmount(BigDecimal.ZERO);
|
||||
orderInfo.setProductAmount(saleAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setIsUseCoupon(isuseYhq);
|
||||
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
} else {
|
||||
orderInfo = getOrder(totalAmount, packAMount, shopTable, tbMerchantAccount.getId().toString(), jsonObject, originAmount);
|
||||
orderInfo.setMerchantId(String.valueOf(tbMerchantAccount.getId()));
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
orderInfo.setIsBuyCoupon(isBuyYhq);
|
||||
orderInfo.setIsUseCoupon(isuseYhq);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
|
||||
JSONObject object = new JSONObject();
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
//package com.chaozhanggui.system.cashierservice.service;
|
||||
//
|
||||
//import com.chaozhanggui.system.cashierservice.dao.TbCashierCartMapper;
|
||||
//import com.chaozhanggui.system.cashierservice.dao.TbProductMapper;
|
||||
//import com.chaozhanggui.system.cashierservice.dao.TbProductSkuMapper;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbCashierCart;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbProduct;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.TbProductSku;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.dto.ProductCartDto;
|
||||
//import com.chaozhanggui.system.cashierservice.entity.vo.CashierCarVo;
|
||||
//import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
//import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
//import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//import org.springframework.beans.BeanUtils;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//import org.springframework.transaction.annotation.Transactional;
|
||||
//
|
||||
//import javax.annotation.Resource;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.time.Instant;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.List;
|
||||
//
|
||||
///**
|
||||
// * @author lyf
|
||||
// */
|
||||
//@Service
|
||||
//@Slf4j
|
||||
//public class CashierCartService {
|
||||
// @Resource
|
||||
// private TbCashierCartMapper cashierCartMapper;
|
||||
// @Resource
|
||||
// private TbProductMapper productMapper;
|
||||
// @Resource
|
||||
// private TbProductSkuMapper productSkuMapper;
|
||||
//
|
||||
// /**
|
||||
// * 增加购物车
|
||||
// * @param productCartDto
|
||||
// * @return
|
||||
// */
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public Result batchAdd(ProductCartDto productCartDto){
|
||||
// //首先确认金额
|
||||
// TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productCartDto.getProductId()));
|
||||
// if (tbProduct == null){
|
||||
// return Result.fail("商品信息不存在");
|
||||
// }
|
||||
//
|
||||
// TbCashierCart cashierCart = cashierCartMapper.selectByProduct(productCartDto.getProductId(), productCartDto.getTableId());
|
||||
// if (cashierCart != null){
|
||||
// if ("add".equals(productCartDto.getType())){
|
||||
// TbCashierCart cashierCartNow = new TbCashierCart();
|
||||
// cashierCartNow.setNumber(cashierCart.getNumber()+1F);
|
||||
// cashierCartNow.setId(cashierCart.getId());
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }else if ("minus".equals(productCartDto.getType())){
|
||||
// TbCashierCart cashierCartNow = new TbCashierCart();
|
||||
// cashierCartNow.setNumber(cashierCart.getNumber()-1F);
|
||||
// cashierCartNow.setId(cashierCart.getId());
|
||||
// if (cashierCartNow.getNumber() == 0F){
|
||||
// cashierCartNow.setStatus("clear");
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }else {
|
||||
// throw new MsgException("添加购物车失败");
|
||||
// }
|
||||
// }
|
||||
// //增加新的购物车
|
||||
// TbCashierCart tbCashierCart = new TbCashierCart();
|
||||
// BeanUtils.copyProperties(productCartDto,tbCashierCart);
|
||||
// tbCashierCart.setSalePrice(tbProduct.getLowPrice());
|
||||
// tbCashierCart.setCreatedAt(Instant.now().toEpochMilli());
|
||||
// tbCashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
// tbCashierCart.setTotalNumber(0.00F);
|
||||
// tbCashierCart.setRefundNumber(0.00F);
|
||||
// tbCashierCart.setType((byte) 0);
|
||||
// tbCashierCart.setSkuId(productCartDto.getSkuInfo());
|
||||
// //购物车状态打开
|
||||
// tbCashierCart.setStatus("open");
|
||||
//
|
||||
// int insert = cashierCartMapper.insertSelective(tbCashierCart);
|
||||
// if (insert>0){
|
||||
// return Result.success(CodeEnum.SUCCESS);
|
||||
// }
|
||||
// throw new MsgException("添加购物车失败");
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public Result cartList(Integer tableId){
|
||||
// HashMap<String, Object> map = new HashMap<>();
|
||||
// List<TbCashierCart> tbCashierCarts = cashierCartMapper.selectByTableId(tableId);
|
||||
// BigDecimal total = new BigDecimal("0.00");
|
||||
// for (TbCashierCart date :tbCashierCarts) {
|
||||
// Float number = date.getNumber();
|
||||
// BigDecimal bigDecimalValue = new BigDecimal(number.toString());
|
||||
// total=total.add(bigDecimalValue.multiply(date.getSalePrice()));
|
||||
// }
|
||||
//
|
||||
// map.put("cartList",tbCashierCarts);
|
||||
// map.put("total",total);
|
||||
//
|
||||
// return Result.success(CodeEnum.ENCRYPT,map);
|
||||
//
|
||||
// }
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public Result updateNumber(Integer tableId,String type){
|
||||
// TbCashierCart cashierCart = cashierCartMapper.selectByPrimaryKey(tableId);
|
||||
// if (cashierCart == null){
|
||||
// return Result.fail("商品不存在");
|
||||
// }
|
||||
// if ("add".equals(type)){
|
||||
// TbCashierCart cashierCartNow = new TbCashierCart();
|
||||
// cashierCartNow.setNumber(cashierCart.getNumber()+1F);
|
||||
// cashierCartNow.setId(cashierCart.getId());
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }else if ("minus".equals(type)){
|
||||
// TbCashierCart cashierCartNow = new TbCashierCart();
|
||||
// cashierCartNow.setNumber(cashierCart.getNumber()-1F);
|
||||
// cashierCartNow.setId(cashierCart.getId());
|
||||
// if (cashierCartNow.getNumber() == 0F){
|
||||
// cashierCartNow.setStatus("clear");
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCartNow);
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }else {
|
||||
// throw new MsgException("更改商品失败");
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public Result clearCart(Integer tableId){
|
||||
// List<CashierCarVo> cashierCarVos = cashierCartMapper.selectByTableIdOpen(tableId);
|
||||
// if (cashierCarVos.isEmpty()){
|
||||
// return Result.fail("购物车内无商品");
|
||||
// }
|
||||
// List<Integer> ids = new ArrayList<>();
|
||||
// for (CashierCarVo date :cashierCarVos) {
|
||||
// ids.add(date.getId());
|
||||
// }
|
||||
// int i = cashierCartMapper.updateByIdsStatus(ids, Instant.now().toEpochMilli());
|
||||
// if (i != ids.size()){
|
||||
// throw new MsgException("清空购物车失败");
|
||||
// }
|
||||
// return Result.success(CodeEnum.ENCRYPT);
|
||||
// }
|
||||
//}
|
||||
@@ -1,117 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class IntegralService {
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private TbOrderInfoMapper orderInfoMapper;
|
||||
@Autowired
|
||||
private TbUserInfoMapper userInfoMapper;
|
||||
@Autowired
|
||||
private TbProductMapper productMapper;
|
||||
@Autowired
|
||||
private TbProductSkuMapper productSkuMapper;
|
||||
@Autowired
|
||||
private TbShopInfoMapper shopInfoMapper;
|
||||
@Autowired
|
||||
private TbShopUserMapper tbShopUserMapper;
|
||||
@Resource
|
||||
private TbReleaseFlowMapper integralFlowMapper;
|
||||
@Autowired
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
@Autowired
|
||||
private TbSplitAccountsMapper splitAccountsMapper;
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void integralAdd(JSONObject jsonObject) throws ParseException {
|
||||
String type = jsonObject.getString("type");
|
||||
if (type.equals("trade")){
|
||||
//优惠券兑换积分
|
||||
Integer integralId = jsonObject.getInteger("integralId");
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(integralId);
|
||||
if (Objects.isNull(userCoupons) || !"0".equals(userCoupons.getStatus())){
|
||||
throw new MsgException("优惠券已被使用");
|
||||
}
|
||||
userCoupons.setStatus("trade");
|
||||
userCoupons.setUpdateTime(new Date());
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
TbParams params = tbShopUserMapper.selectParams();
|
||||
TbReleaseFlow integralFlow = new TbReleaseFlow();
|
||||
integralFlow.setNum(userCoupons.getCouponsAmount().multiply(params.getTradeRatio()));
|
||||
integralFlow.setCreateTime(new Date());
|
||||
integralFlow.setFromSource(userCoupons.getId()+"");
|
||||
integralFlow.setType("TRADEADD");
|
||||
integralFlow.setUserId(userCoupons.getUserId());
|
||||
integralFlowMapper.insert(integralFlow);
|
||||
TbUserInfo userInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userCoupons.getUserId()));
|
||||
if (Objects.nonNull(userInfo)){
|
||||
userInfo.setTotalScore(userInfo.getTotalScore() + integralFlow.getNum().intValue());
|
||||
userInfoMapper.updateByPrimaryKeySelective(userInfo);
|
||||
}
|
||||
}else {
|
||||
Integer orderId = jsonObject.getInteger("orderId");
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
if (StringUtils.isNotBlank(orderInfo.getUserCouponId())){
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getUserCouponId()));
|
||||
if (Objects.nonNull(userCoupons)){
|
||||
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||
TbSplitAccounts splitAccounts = new TbSplitAccounts();
|
||||
splitAccounts.setConponsAmount(userCoupons.getCouponsAmount());
|
||||
splitAccounts.setCreateTime(new Date());
|
||||
splitAccounts.setIsSplit("false");
|
||||
splitAccounts.setMerchantId(Integer.valueOf(shopInfo.getMerchantId()));
|
||||
splitAccounts.setShopId(shopInfo.getId());
|
||||
splitAccounts.setOrderAmount(orderInfo.getPayAmount());
|
||||
splitAccounts.setTradeDay(DateUtils.getDay());
|
||||
splitAccounts.setOriginAmount(orderInfo.getOriginAmount());
|
||||
splitAccountsMapper.insert(splitAccounts);
|
||||
}
|
||||
}
|
||||
if (Objects.isNull(orderInfo)) {
|
||||
log.error("该订单不存在");
|
||||
return;
|
||||
}
|
||||
TbShopInfo shopInfo = shopInfoMapper.selectByPrimaryKey(Integer.valueOf(orderInfo.getShopId()));
|
||||
if (Objects.isNull(shopInfo) || !"true".equals(shopInfo.getIsOpenYhq())){
|
||||
log.error("该店铺未开启优惠券功能");
|
||||
return;
|
||||
}
|
||||
|
||||
TbParams params = tbShopUserMapper.selectParams();
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setUserId(orderInfo.getUserId());
|
||||
userCoupons.setCouponsAmount(orderInfo.getOrderAmount().subtract(orderInfo.getUserCouponAmount()).multiply(params.getIntegralRatio()));
|
||||
userCoupons.setStatus("0");
|
||||
userCoupons.setOrderId(orderId);
|
||||
userCoupons.setCouponsPrice(userCoupons.getCouponsAmount().multiply(new BigDecimal("0.5")));
|
||||
userCoupons.setCreateTime(new Date());
|
||||
userCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30));
|
||||
//执行插入方法
|
||||
userCouponsMapper.insert(userCoupons);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,40 +3,35 @@ package com.chaozhanggui.system.cashierservice.service;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.chaozhanggui.system.cashierservice.constant.TableConstant;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.ShopEatTypeInfoDTO;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopTableMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbOrderInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopTable;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpCashierCartMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderDetailMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpOrderInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.mapper.MpShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.N;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -46,8 +41,6 @@ import java.util.stream.Collectors;
|
||||
@Service
|
||||
public class OrderService {
|
||||
|
||||
@Resource
|
||||
private RabbitProducer producer;
|
||||
|
||||
@Resource
|
||||
private TbOrderInfoMapper orderInfoMapper;
|
||||
@@ -57,36 +50,10 @@ public class OrderService {
|
||||
|
||||
@Resource
|
||||
private TbShopTableMapper shopTableMapper;
|
||||
@Resource
|
||||
private TbProductSkuMapper productSkuMapper;
|
||||
|
||||
@Resource
|
||||
private TbUserInfoMapper userInfoMapper;
|
||||
@Autowired
|
||||
private TbWiningUserMapper tbWiningUserMapper;
|
||||
|
||||
@Resource
|
||||
private TbOrderDetailMapper tbOrderDetailMapper;
|
||||
@Autowired
|
||||
private TbReleaseFlowMapper releaseFlowMapper;
|
||||
@Resource
|
||||
private TbParamsMapper paramsMapper;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private RedisUtils redisUtils;
|
||||
@Resource
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
@Resource
|
||||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
@Autowired
|
||||
private TbYhqParamsMapper yhqParamsMapper;
|
||||
@Autowired
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
|
||||
|
||||
@Autowired
|
||||
private TbOrderInfoMapper tbOrderInfoMapper;
|
||||
@Autowired
|
||||
private MpCashierCartMapper mpCashierCartMapper;
|
||||
@Autowired
|
||||
@@ -280,181 +247,6 @@ public class OrderService {
|
||||
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result tradeIntegral(String userId, String id) throws ParseException {
|
||||
updateIntegral(userId, id);
|
||||
return Result.success(CodeEnum.ENCRYPT);
|
||||
}
|
||||
|
||||
private void updateIntegral(String userId, String id) throws ParseException {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(Integer.valueOf(id));
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0")) {
|
||||
throw new MsgException("该优惠券已被使用");
|
||||
}
|
||||
TbParams params = paramsMapper.selectByPrimaryKey(1);
|
||||
BigDecimal jfAmount = params.getTradeRatio().multiply(userCoupons.getCouponsAmount());
|
||||
TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore()+jfAmount.intValue());
|
||||
userInfoMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
userCoupons.setStatus("2");
|
||||
userCoupons.setUpdateTime(new Date());
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
TbSystemCoupons systemCoupons = new TbSystemCoupons();
|
||||
systemCoupons.setEndTime(DateUtils.getNewDate(new Date(),3,30));
|
||||
systemCoupons.setCouponsAmount(userCoupons.getCouponsAmount());
|
||||
systemCoupons.setCouponsPrice(userCoupons.getCouponsPrice());
|
||||
systemCoupons.setStatus("0");
|
||||
systemCoupons.setName(userCoupons.getCouponsAmount()+"无门槛优惠券");
|
||||
systemCoupons.setCreateTime(new Date());
|
||||
String typeName = findName(userCoupons.getCouponsAmount());
|
||||
systemCoupons.setTypeName(typeName);
|
||||
systemCouponsMapper.insert(systemCoupons);
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(jfAmount);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setUserId(userId);
|
||||
releaseFlow.setOperationType("ADD");
|
||||
releaseFlow.setType("EXCHANGEADD");
|
||||
releaseFlow.setRemark("兑换增加");
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
} else {
|
||||
updateIntegral(userId, id);
|
||||
}
|
||||
}
|
||||
|
||||
private String findName(BigDecimal amount) {
|
||||
List<TbYhqParams> list = yhqParamsMapper.selectAll();
|
||||
String typeName = "";
|
||||
for (TbYhqParams yhqParams:list){
|
||||
if (N.egt(amount,yhqParams.getMinPrice()) && N.gt(yhqParams.getMaxPrice(),amount)){
|
||||
typeName = yhqParams.getName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return typeName;
|
||||
}
|
||||
|
||||
|
||||
public Result mineCoupons(String userId, String orderId,String status, Integer page, Integer size) {
|
||||
BigDecimal amount=null;
|
||||
if(ObjectUtil.isNotNull(orderId)&&ObjectUtil.isNotEmpty(orderId)){
|
||||
TbOrderInfo orderInfo= tbOrderInfoMapper.selectByPrimaryKey(Integer.valueOf(orderId));
|
||||
amount=orderInfo.getOriginAmount();
|
||||
}
|
||||
|
||||
|
||||
PageHelper.startPage(page, size);
|
||||
List<TbUserCoupons> list = userCouponsMapper.selectByUserId(userId,status,amount);
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||
}
|
||||
|
||||
public Result findCoupons(String type, Integer page, Integer size) {
|
||||
PageHelper.startPage(page, size);
|
||||
List<TbSystemCoupons> list = systemCouponsMapper.selectAll(type);
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||
}
|
||||
|
||||
public Result findWiningUser() {
|
||||
String day = DateUtils.getDay();
|
||||
List<TbWiningUser> list = tbWiningUserMapper.selectAllByTrade(day);
|
||||
return Result.success(CodeEnum.SUCCESS, list);
|
||||
}
|
||||
|
||||
public Result getYhqPara() {
|
||||
List<TbYhqParams> list = yhqParamsMapper.selectAll();
|
||||
return Result.success(CodeEnum.SUCCESS, list);
|
||||
}
|
||||
|
||||
public Result testPay(Integer orderId) {
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayType("wx_lite");
|
||||
orderInfo.setPayOrderNo("test");
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("token",0);
|
||||
jsonObject.put("type","wxcreate");
|
||||
jsonObject.put("orderId",orderId.toString());
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
JSONObject coupons = new JSONObject();
|
||||
coupons.put("type","buy");
|
||||
coupons.put("orderId",orderId);
|
||||
producer.printCoupons(coupons.toJSONString());
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
public Result getYhqDouble(Integer orderId) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByOrderId(orderId);
|
||||
if (Objects.nonNull(userCoupons)){
|
||||
TbOrderInfo orderInfo = orderInfoMapper.selectByPrimaryKey(orderId);
|
||||
userCoupons.setOrderInfo(orderInfo);
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS,userCoupons);
|
||||
}
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result yhqDouble(Integer conponsId) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId);
|
||||
if (Objects.isNull(userCoupons) || userCoupons.getIsDouble().equals("true")){
|
||||
throw new MsgException("该优惠券翻倍已领取");
|
||||
}
|
||||
modityDouble(conponsId);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
private void modityDouble(Integer conponsId) {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.COUPONS_COIN_KEY + conponsId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbUserCoupons userCoupons = userCouponsMapper.selectByPrimaryKey(conponsId);
|
||||
if (Objects.isNull(userCoupons) || !userCoupons.getStatus().equals("0") || userCoupons.getIsDouble().equals("true")) {
|
||||
throw new MsgException("该优惠券已翻倍");
|
||||
}
|
||||
TbParams params = shopUserMapper.selectParams();
|
||||
userCoupons.setIsDouble("true");
|
||||
userCoupons.setCouponsAmount(userCoupons.getCouponsAmount().multiply(params.getTwoRatio()));
|
||||
userCoupons.setCouponsPrice(userCoupons.getCouponsPrice().multiply(params.getTwoRatio()));
|
||||
userCoupons.setUpdateTime(new Date());
|
||||
userCouponsMapper.updateByPrimaryKeySelective(userCoupons);
|
||||
redisUtils.releaseLock(RedisCst.COUPONS_COIN_KEY + conponsId);
|
||||
} else {
|
||||
modityDouble(conponsId);
|
||||
}
|
||||
}
|
||||
|
||||
public Result mineWinner(Integer userId, Integer page, Integer size) {
|
||||
PageHelper.startPage(page, size);
|
||||
List<TbOrderInfo> list = orderInfoMapper.selectWinnerByUserId(userId);
|
||||
for (TbOrderInfo tbOrderInfo:list){
|
||||
if (StringUtils.isNotEmpty(tbOrderInfo.getWinnnerNo())){
|
||||
tbOrderInfo.setIsWinner("true");
|
||||
}else {
|
||||
tbOrderInfo.setIsWinner("false");
|
||||
}
|
||||
}
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
if (page > pageInfo.getPages()) {
|
||||
pageInfo.setList(Collections.emptyList());
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS, pageInfo);
|
||||
}
|
||||
|
||||
public Result kc() {
|
||||
List<TbProductSku> list = productSkuMapper.selectAll();
|
||||
for (TbProductSku productSku:list){
|
||||
redisUtil.saveMessage(RedisCst.PRODUCT + productSku.getShopId() + ":" +productSku.getId(),"10000");
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
public Object orderDetail(Integer orderId) {
|
||||
|
||||
TbOrderInfo orderInfo = mpOrderInfoMapper.selectOne(new LambdaQueryWrapper<TbOrderInfo>()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
@@ -82,7 +83,9 @@ public class PayService {
|
||||
@Autowired
|
||||
TbShopPayTypeMapper tbShopPayTypeMapper;
|
||||
@Autowired
|
||||
private TbActivateProductMapper actProductMapper;
|
||||
private TbCouponProductMapper couProductMapper;
|
||||
@Autowired
|
||||
private TbShopCouponMapper couponMapper;
|
||||
@Resource
|
||||
private TbActivateInRecordMapper activateInRecordMapper;
|
||||
|
||||
@@ -475,7 +478,6 @@ public class PayService {
|
||||
.eq(TbOrderDetail::getStatus, "unpaid")
|
||||
.set(TbOrderDetail::getStatus, "closed"));
|
||||
|
||||
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
@@ -1013,7 +1015,6 @@ public class PayService {
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(orderInfo.getId(), "closed");
|
||||
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
||||
//修改主单状态
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayType("wx_lite");
|
||||
@@ -1098,7 +1099,6 @@ public class PayService {
|
||||
orderInfo.setPayAmount(orderInfo.getOrderAmount());
|
||||
orderInfo.setPaidTime(System.currentTimeMillis());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
outRecordMapper.updateByOrderIdAndStatus(orderInfo.getId(), "closed");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", 0);
|
||||
@@ -1176,8 +1176,18 @@ public class PayService {
|
||||
PageHelper.startPage(page, pageSize);
|
||||
List<TbActivate> list = tbActivateMapper.selectByShopId(shopId);
|
||||
for (TbActivate tbActivate : list) {
|
||||
if (tbActivate.getIsGiftPro() == 1) {
|
||||
tbActivate.setGives(actProductMapper.queryProsByActivateId(tbActivate.getId()));
|
||||
if (tbActivate.getIsUseCoupon() == 1) {
|
||||
TbShopCoupon coupon = couponMapper.queryById(tbActivate.getCouponId());
|
||||
if(coupon!=null){
|
||||
if(coupon.getType()==1){
|
||||
//满减
|
||||
tbActivate.setCouponDesc("满"+coupon.getFullAmount() + "减" + coupon.getDiscountAmount()+" * "+tbActivate.getNum()+"张");
|
||||
} else if (coupon.getType() == 2) {
|
||||
//商品
|
||||
tbActivate.setCouponDesc("商品券");
|
||||
tbActivate.setGives(couProductMapper.queryProsByActivateId(coupon.getId(),tbActivate.getNum()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
@@ -1292,25 +1302,68 @@ public class PayService {
|
||||
public BigDecimal giveActivate(TbShopUser tbShopUser, BigDecimal memAmount, Integer flowId) {
|
||||
TbActivate activate = tbActivateMapper.selectByAmount(tbShopUser.getShopId(), memAmount);
|
||||
if (ObjectUtil.isNotEmpty(activate) && ObjectUtil.isNotNull(activate)) {
|
||||
if (activate.getIsGiftPro() != null && activate.getIsGiftPro() == 1) {
|
||||
List<TbActivateProduct> tbActivateProducts = actProductMapper.queryAllByActivateId(activate.getId());
|
||||
List<TbActivateInRecord> actGiveRecords = new ArrayList<>();
|
||||
for (TbActivateProduct actPro : tbActivateProducts) {
|
||||
TbActivateInRecord record = new TbActivateInRecord(Integer.valueOf(tbShopUser.getId()), actPro.getProductId(), actPro.getNum(), Integer.valueOf(tbShopUser.getShopId()), activate.getId(), flowId);
|
||||
actGiveRecords.add(record);
|
||||
if (activate.getIsUseCoupon() == 1) {
|
||||
TbShopCoupon tbShopCoupon = couponMapper.queryById(activate.getCouponId());
|
||||
Date start = new Date();
|
||||
Date end = new Date();
|
||||
if ("fixed".equals(tbShopCoupon.getValidityType())) {
|
||||
//固定时间
|
||||
end = DateUtil.offsetDay(new Date(),tbShopCoupon.getValidDays());
|
||||
} else if ("custom".equals(tbShopCoupon.getValidityType())) {
|
||||
//自定义时间
|
||||
start = tbShopCoupon.getValidStartTime();
|
||||
end = tbShopCoupon.getValidEndTime();
|
||||
}
|
||||
if (tbShopCoupon != null) {
|
||||
List<TbActivateInRecord> actGiveRecords = new ArrayList<>();
|
||||
if(tbShopCoupon.getType() == 1) {
|
||||
//满减
|
||||
TbActivateInRecord record = new TbActivateInRecord();
|
||||
record.setVipUserId(Integer.valueOf(tbShopUser.getId()));
|
||||
record.setCouponId(tbShopCoupon.getId());
|
||||
record.setName("满" + tbShopCoupon.getFullAmount() + "减" + tbShopCoupon.getDiscountAmount());
|
||||
record.setFullAmount(tbShopCoupon.getFullAmount());
|
||||
record.setDiscountAmount(tbShopCoupon.getDiscountAmount());
|
||||
record.setType(1);
|
||||
record.setNum(activate.getNum());
|
||||
record.setOverNum(activate.getNum());
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setCouponJson(activateInRecordService.getCouponJson(activate,tbShopCoupon,null));
|
||||
actGiveRecords.add(record);
|
||||
} else if (tbShopCoupon.getType() == 2) {
|
||||
//商品卷
|
||||
List<TbCouponProduct> tbCouponProducts = couProductMapper.queryAllByCouponId(tbShopCoupon.getId());
|
||||
for (TbCouponProduct actPro : tbCouponProducts) {
|
||||
TbActivateInRecord record = new TbActivateInRecord();
|
||||
record.setVipUserId(Integer.valueOf(tbShopUser.getId()));
|
||||
record.setCouponId(tbShopCoupon.getId());
|
||||
record.setName("商品卷");
|
||||
record.setType(2);
|
||||
record.setProId(actPro.getProductId());
|
||||
record.setNum(actPro.getNum()*tbShopCoupon.getNumber());
|
||||
record.setOverNum(actPro.getNum()*tbShopCoupon.getNumber());
|
||||
record.setShopId(Integer.valueOf(tbShopUser.getShopId()));
|
||||
record.setSourceActId(activate.getId());
|
||||
record.setSourceFlowId(flowId);
|
||||
record.setUseStartTime(start);
|
||||
record.setUseEndTime(end);
|
||||
record.setCouponJson(activateInRecordService.getCouponJson(activate,tbShopCoupon,actPro));
|
||||
actGiveRecords.add(record);
|
||||
}
|
||||
}
|
||||
activateInRecordMapper.insertBatch(actGiveRecords);
|
||||
tbShopCoupon.setLeftNumber(tbShopCoupon.getLeftNumber()-activate.getNum());
|
||||
couponMapper.update(tbShopCoupon);
|
||||
}
|
||||
activateInRecordMapper.insertBatch(actGiveRecords);
|
||||
}
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
switch (activate.getHandselType()) {
|
||||
case "GD":
|
||||
amount = activate.getHandselNum();
|
||||
break;
|
||||
case "RATIO":
|
||||
amount = memAmount.multiply(activate.getHandselNum());
|
||||
break;
|
||||
}
|
||||
|
||||
BigDecimal amount = activate.getGiftAmount() == null ?
|
||||
BigDecimal.ZERO : new BigDecimal(activate.getGiftAmount());
|
||||
|
||||
tbShopUser.setAmount(tbShopUser.getAmount().add(amount));
|
||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
||||
tbShopUserMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
|
||||
@@ -234,16 +234,6 @@ public class ProductService {
|
||||
}
|
||||
});
|
||||
groupList.sort(Comparator.comparingInt(TbProductGroup::getIsSale).reversed());
|
||||
TbShopUser tbShopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId);
|
||||
if (tbShopUser != null) {
|
||||
TbProductGroup vipProGroup = new TbProductGroup();
|
||||
vipProGroup.setName("会员商品");
|
||||
List<TbProduct> vipPros = activateInRecordService.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), Integer.valueOf(shopId));
|
||||
if(!CollectionUtils.isEmpty(vipPros)){
|
||||
vipProGroup.setProducts(handleDate(vipPros, true, 1, true));
|
||||
groupList.add(0, vipProGroup);
|
||||
}
|
||||
}
|
||||
groupList.add(0, hot);
|
||||
concurrentMap.put("productInfo", groupList);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbProduct;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import java.util.List;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivate;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbCouponProduct;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopCoupon;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 活动商品赠送表(TbActivateInRecord)表服务接口
|
||||
@@ -13,44 +12,14 @@ import java.util.List;
|
||||
* @author ww
|
||||
* @since 2024-08-22 11:13:40
|
||||
*/
|
||||
public interface TbActivateInRecordService {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateInRecord queryById(Integer id);
|
||||
|
||||
List<TbProduct> queryByVipIdAndShopId(Integer vipUserId, Integer shopId);
|
||||
int queryByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId);
|
||||
List<TbActivateInRecord> queryAllByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbActivateInRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateInRecord insert(TbActivateInRecord tbActivateInRecord);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbActivateInRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateInRecord update(TbActivateInRecord tbActivateInRecord);
|
||||
|
||||
int updateOverNumById(Integer id,Integer overNum);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteById(Integer id);
|
||||
@Service
|
||||
public class TbActivateInRecordService {
|
||||
|
||||
public String getCouponJson(TbActivate activate, TbShopCoupon tbShopCoupon, TbCouponProduct couProduct){
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("activate",JSONObject.toJSON(activate));
|
||||
result.put("coupon",JSONObject.toJSON(tbShopCoupon));
|
||||
result.put("couProduct",JSONObject.toJSON(couProduct));
|
||||
return result.toJSONString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
|
||||
|
||||
/**
|
||||
* 活动赠送商品使用记录表(TbActivateOutRecord)表服务接口
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-22 11:21:56
|
||||
*/
|
||||
public interface TbActivateOutRecordService {
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateOutRecord queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbActivateOutRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateOutRecord insert(TbActivateOutRecord tbActivateOutRecord);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbActivateOutRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbActivateOutRecord update(TbActivateOutRecord tbActivateOutRecord);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteById(Integer id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
/**
|
||||
* 优惠券(TbShopCoupon)表服务接口
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-10-23 15:37:37
|
||||
*/
|
||||
public interface TbShopCouponService {
|
||||
Result find(CouponDto param);
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
|
||||
/**
|
||||
* (TbUserCoupons)表服务接口
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-09-02 13:38:20
|
||||
*/
|
||||
public interface TbUserCouponsService {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param tbUserCoupons 筛选条件
|
||||
* @return 查询结果
|
||||
*/
|
||||
Result queryByPage(UserCouponDto tbUserCoupons);
|
||||
|
||||
}
|
||||
@@ -4,23 +4,18 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.extra.qrcode.QrConfig;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbReleaseFlow;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.OpenMemberVo;
|
||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -35,8 +30,6 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
@@ -45,14 +38,8 @@ public class UserService {
|
||||
@Autowired
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
@Autowired
|
||||
private TbReleaseFlowMapper releaseFlowMapper;
|
||||
@Autowired
|
||||
private TbUserInfoMapper userInfoMapper;
|
||||
@Autowired
|
||||
private TbUserCouponsMapper userCouponsMapper;
|
||||
@Autowired
|
||||
private TbSystemCouponsMapper systemCouponsMapper;
|
||||
@Autowired
|
||||
RedisUtils redisUtils;
|
||||
@Qualifier("tbShopInfoMapper")
|
||||
@Autowired
|
||||
@@ -69,192 +56,8 @@ public class UserService {
|
||||
this.resourceLoader = resourceLoader;
|
||||
}
|
||||
|
||||
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
|
||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
|
||||
if (N.gt(BigDecimal.ZERO, integralVo.getNum())) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "积分数量不允许小于0");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
object.put("userSign", userSign);
|
||||
|
||||
JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map);
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
if (!sign.equals(integralVo.getSign())) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "签名验证失败");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
TbShopUser shopUser = shopUserMapper.selectByOpenId(integralVo.getOpenId());
|
||||
if (Objects.isNull(shopUser)) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "用户不存在");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
boolean falg = updateIntegral(shopUser.getUserId(), integralVo.getNum(), integralVo.getType());
|
||||
if (!falg) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "余额不足");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
IntegralVo integralVo = new IntegralVo();
|
||||
integralVo.setNum(new BigDecimal("5254"));
|
||||
integralVo.setOpenId("or1l864NBOoJZhC5x_yeziZ26j6c");
|
||||
integralVo.setType("sub");
|
||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
|
||||
object.put("userSign", "02c03d79c36b4c01b217ffb1baef9009");
|
||||
JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map);
|
||||
System.out.println("加密前字符串:" + jsonObject.toJSONString());
|
||||
String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
System.out.println("加密后签名:" + sign);
|
||||
}
|
||||
|
||||
private Boolean updateIntegral(String userId, BigDecimal num, String type) {
|
||||
|
||||
boolean lock_coin = redisUtils.lock(RedisCst.INTEGRAL_COIN_KEY + userId, 5000, TimeUnit.MILLISECONDS);
|
||||
if (lock_coin) {
|
||||
TbUserInfo tbShopUser = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
boolean flag = true;
|
||||
if (type.equals("sub")) {
|
||||
if (num.intValue() < tbShopUser.getTotalScore()) {
|
||||
flag = false;
|
||||
} else {
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore() - num.intValue());
|
||||
}
|
||||
} else if (type.equals("add")) {
|
||||
tbShopUser.setTotalScore(tbShopUser.getTotalScore() + num.intValue());
|
||||
}
|
||||
if (flag) {
|
||||
TbReleaseFlow releaseFlow = new TbReleaseFlow();
|
||||
releaseFlow.setNum(num);
|
||||
releaseFlow.setCreateTime(new Date());
|
||||
releaseFlow.setFromSource("OWER");
|
||||
releaseFlow.setUserId(userId);
|
||||
if (type.equals("sub")) {
|
||||
releaseFlow.setType("BUYSUB");
|
||||
releaseFlow.setOperationType("SUB");
|
||||
releaseFlow.setRemark("购买商品扣除");
|
||||
} else if (type.equals("sub")) {
|
||||
releaseFlow.setType("THREEADD");
|
||||
releaseFlow.setOperationType("ADD");
|
||||
releaseFlow.setRemark("退货增加");
|
||||
}
|
||||
releaseFlowMapper.insert(releaseFlow);
|
||||
userInfoMapper.updateByPrimaryKeySelective(tbShopUser);
|
||||
}
|
||||
redisUtils.releaseLock(RedisCst.INTEGRAL_COIN_KEY + userId);
|
||||
return flag;
|
||||
} else {
|
||||
return updateIntegral(userId, num, type);
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject userIntegral(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
object.put("userSign", userSign);
|
||||
JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.map);
|
||||
System.out.println(jsonObject.toJSONString());
|
||||
String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
if (!sign.equals(integralFlowVo.getSign())) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "签名验证失败");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
TbUserInfo shopUser = userInfoMapper.selectByOpenId(integralFlowVo.getOpenId());
|
||||
if (Objects.isNull(shopUser)) {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "fail");
|
||||
result.put("msg", "用户不存在");
|
||||
result.put("data", "");
|
||||
return result;
|
||||
}
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbReleaseFlow> list = releaseFlowMapper.selectByUserId(shopUser.getId().toString());
|
||||
for (TbReleaseFlow tbReleaseFlow:list){
|
||||
tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime()));
|
||||
}
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject userAllIntegral(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
// object.put("userSign", userSign);
|
||||
// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap);
|
||||
// System.out.println(jsonObject.toJSONString());
|
||||
// String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
// if (!sign.equals(integralFlowVo.getSign())) {
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("status", "fail");
|
||||
// result.put("msg", "签名验证失败");
|
||||
// result.put("data", "");
|
||||
// return result;
|
||||
// }
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbReleaseFlow> list = releaseFlowMapper.selectAll();
|
||||
for (TbReleaseFlow tbReleaseFlow:list){
|
||||
tbReleaseFlow.setCreateTr(DateUtils.getStrTime(tbReleaseFlow.getCreateTime()));
|
||||
}
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data", pageInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject userAll(IntegralFlowVo integralFlowVo, String userSign) {
|
||||
// JSONObject object = (JSONObject) JSONObject.toJSON(integralFlowVo);
|
||||
// object.put("userSign", userSign);
|
||||
// JSONObject jsonObject = JSONUtil.sortJSONObject(object, CacheMap.notOpenMap);
|
||||
// System.out.println(jsonObject.toJSONString());
|
||||
// String sign = MD5Util.encrypt(jsonObject.toJSONString());
|
||||
// if (!sign.equals(integralFlowVo.getSign())) {
|
||||
// JSONObject result = new JSONObject();
|
||||
// result.put("status", "fail");
|
||||
// result.put("msg", "签名验证失败");
|
||||
// result.put("data", "");
|
||||
// return result;
|
||||
// }
|
||||
PageHelper.startPage(integralFlowVo.getPage(), integralFlowVo.getPageSize());
|
||||
PageHelper.orderBy("id DESC");
|
||||
List<TbUserInfo> list = userInfoMapper.selectAll();
|
||||
PageInfo pageInfo = new PageInfo(list);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("status", "success");
|
||||
result.put("msg", "成功");
|
||||
result.put("data", pageInfo);
|
||||
return result;
|
||||
}
|
||||
|
||||
public int userCoupon(String userId, BigDecimal orderNum) {
|
||||
int userNum = userCouponsMapper.selectByUserIdAndAmount(userId,orderNum);
|
||||
int sysNum = systemCouponsMapper.selectByAmount(orderNum);
|
||||
return userNum+sysNum;
|
||||
}
|
||||
|
||||
public String getSubQrCode(String shopId) throws Exception {
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbActivateInRecordMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateInRecord;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbProduct;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbActivateInRecordService;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 活动商品赠送表(TbActivateInRecord)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-22 11:13:40
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class TbActivateInRecordServiceImpl implements TbActivateInRecordService {
|
||||
@Resource
|
||||
private TbActivateInRecordMapper tbActivateInRecordMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateInRecord queryById(Integer id) {
|
||||
return this.tbActivateInRecordMapper.queryById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbProduct> queryByVipIdAndShopId(Integer vipUserId, Integer shopId) {
|
||||
return tbActivateInRecordMapper.queryByVipIdAndShopId(vipUserId, shopId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId){
|
||||
return tbActivateInRecordMapper.queryByVipIdAndShopIdAndProId(vipUserId,shopId,productId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TbActivateInRecord> queryAllByVipIdAndShopIdAndProId(Integer vipUserId, Integer shopId,Integer productId){
|
||||
return tbActivateInRecordMapper.queryAllByVipIdAndShopIdAndProId(vipUserId,shopId,productId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbActivateInRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateInRecord insert(TbActivateInRecord tbActivateInRecord) {
|
||||
this.tbActivateInRecordMapper.insert(tbActivateInRecord);
|
||||
return tbActivateInRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbActivateInRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateInRecord update(TbActivateInRecord tbActivateInRecord) {
|
||||
this.tbActivateInRecordMapper.update(tbActivateInRecord);
|
||||
return this.queryById(tbActivateInRecord.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateOverNumById(Integer id,Integer overNum){
|
||||
return tbActivateInRecordMapper.updateOverNumById(id,overNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Integer id) {
|
||||
return this.tbActivateInRecordMapper.deleteById(id) > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateOutRecord;
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbActivateOutRecordMapper;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbActivateOutRecordService;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 活动赠送商品使用记录表(TbActivateOutRecord)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-22 11:21:56
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class TbActivateOutRecordServiceImpl implements TbActivateOutRecordService {
|
||||
@Resource
|
||||
private TbActivateOutRecordMapper tbActivateOutRecordMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateOutRecord queryById(Integer id) {
|
||||
return this.tbActivateOutRecordMapper.queryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbActivateOutRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateOutRecord insert(TbActivateOutRecord tbActivateOutRecord) {
|
||||
this.tbActivateOutRecordMapper.insert(tbActivateOutRecord);
|
||||
return tbActivateOutRecord;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbActivateOutRecord 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateOutRecord update(TbActivateOutRecord tbActivateOutRecord) {
|
||||
this.tbActivateOutRecordMapper.update(tbActivateOutRecord);
|
||||
return this.queryById(tbActivateOutRecord.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Integer id) {
|
||||
return this.tbActivateOutRecordMapper.deleteById(id) > 0;
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.dao.TbActivateProductMapper;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbActivateProduct;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbActivateProductService;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 活动赠送商品表(TbActivateProduct)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-08-20 15:15:02
|
||||
*/
|
||||
@Service
|
||||
@Primary
|
||||
public class TbActivateProductServiceImpl implements TbActivateProductService {
|
||||
@Resource
|
||||
private TbActivateProductMapper tbActivateProductMapper;
|
||||
|
||||
/**
|
||||
* 通过ID查询单条数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateProduct queryById(Integer id) {
|
||||
return this.tbActivateProductMapper.queryById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param tbActivateProduct 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateProduct insert(TbActivateProduct tbActivateProduct) {
|
||||
this.tbActivateProductMapper.insert(tbActivateProduct);
|
||||
return tbActivateProduct;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
* @param tbActivateProduct 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbActivateProduct update(TbActivateProduct tbActivateProduct) {
|
||||
this.tbActivateProductMapper.update(tbActivateProduct);
|
||||
return this.queryById(tbActivateProduct.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
*
|
||||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Integer id) {
|
||||
return this.tbActivateProductMapper.deleteById(id) > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.CouponDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.TbUserCouponVo;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbShopCouponService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券(TbShopCoupon)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-10-23 15:37:37
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class TbShopCouponServiceImpl implements TbShopCouponService {
|
||||
@Resource
|
||||
private TbOrderDetailMapper orderDetailMapper;
|
||||
@Resource
|
||||
private TbShopUserMapper shopUserMapper;
|
||||
@Resource
|
||||
private TbShopCouponMapper couponMapper;
|
||||
@Resource
|
||||
private TbOrderInfoMapper orderInfoMapper;
|
||||
@Resource
|
||||
private TbActivateInRecordMapper inRecordMapper;
|
||||
@Resource
|
||||
private TbActivateOutRecordMapper outRecordMapper;
|
||||
|
||||
@Override
|
||||
public Result find(CouponDto param) {
|
||||
TbShopUser tbShopUser = shopUserMapper.selectByUserIdAndShopId(param.getUserId().toString(), param.getShopId().toString());
|
||||
if (param.getOrderId() != null) {
|
||||
TbOrderInfo tbOrderInfo = orderInfoMapper.selectByPrimaryKey(param.getOrderId());
|
||||
List<TbOrderDetail> tbOrderDetails = orderDetailMapper.selectAllByOrderId(param.getOrderId());
|
||||
Set<Integer> pros = tbOrderDetails.stream().map(TbOrderDetail::getProductId).collect(Collectors.toSet());
|
||||
if (CollectionUtil.isNotEmpty(tbOrderDetails)) {
|
||||
List<TbUserCouponVo> tbUserCouponVos = inRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId());
|
||||
if (CollectionUtil.isNotEmpty(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())) {
|
||||
JsonObject json=new JsonObject();
|
||||
boolean isUse = true;
|
||||
TbShopCoupon tbShopCoupon = couponMapper.queryById(tbUserCouponVo.getCouponId());
|
||||
StringBuilder useRestrictions = new StringBuilder("每天 ");
|
||||
if(tbShopCoupon.getType().equals(1)){
|
||||
if(tbOrderInfo.getOrderAmount().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);
|
||||
}
|
||||
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(!pros.contains(tbUserCouponVo.getProId())){
|
||||
tbUserCouponVo.setUse(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
tbUserCouponVos.sort(Comparator.comparing(TbUserCouponVo::isUse).reversed().thenComparing(TbUserCouponVo::getExpireTime));
|
||||
return new Result(CodeEnum.SUCCESS, tbUserCouponVos);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (param.getStatus().equals(1)) {
|
||||
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
|
||||
} else if (param.getStatus().equals(-1)) {
|
||||
return new Result(CodeEnum.SUCCESS, inRecordMapper.queryByVipIdAndShopIdExpire(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
|
||||
} else if (param.getStatus().equals(2)) {
|
||||
return new Result(CodeEnum.SUCCESS, outRecordMapper.queryByVipIdAndShopId(Integer.valueOf(tbShopUser.getId()), param.getShopId()));
|
||||
}
|
||||
}
|
||||
return new Result(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.chaozhanggui.system.cashierservice.service.impl;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.dto.UserCouponDto;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.ShopUserListVo;
|
||||
import com.chaozhanggui.system.cashierservice.entity.vo.UserCouponVo;
|
||||
import com.chaozhanggui.system.cashierservice.service.TbUserCouponsService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (TbUserCoupons)表服务实现类
|
||||
*
|
||||
* @author ww
|
||||
* @since 2024-09-02 13:38:20
|
||||
*/
|
||||
@Primary
|
||||
@Service
|
||||
public class TbUserCouponsServiceImpl implements TbUserCouponsService {
|
||||
@Resource
|
||||
private TbUserCouponsMapper tbUserCouponsMapper;
|
||||
@Resource
|
||||
private TbActivateInRecordMapper inRecordMapper;
|
||||
@Resource
|
||||
private TbActivateOutRecordMapper outRecordMapper;
|
||||
@Autowired
|
||||
private TbShopUserMapper tbShopUserMapper;
|
||||
@Autowired
|
||||
private TbShopInfoMapper tbShopInfoMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @return 查询结果
|
||||
*/
|
||||
@Override
|
||||
public Result queryByPage(UserCouponDto couponDto) {
|
||||
// PageHelper.startPage(couponDto.getPage(), couponDto.getSize());
|
||||
// List<TbUserCoupons> result = tbUserCouponsMapper.queryAllSelective(couponDto);
|
||||
// return new Result(CodeEnum.SUCCESS, new PageInfo<>(result));
|
||||
// List<UserCouponVo> result = tbUserCouponsMapper.queryAllSelective(couponDto);
|
||||
List<UserCouponVo> result = new ArrayList<>();
|
||||
List<ShopUserListVo> tbShopUsers = tbShopUserMapper.selectByUserId(couponDto.getUserId().toString(), couponDto.getShopId()==null?null:couponDto.getShopId().toString());
|
||||
if (!CollectionUtils.isEmpty(tbShopUsers)) {
|
||||
tbShopUsers.forEach(s -> {
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(s.getShopId().intValue());
|
||||
if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() == 0)) {
|
||||
List<UserCouponVo> unuseCoupon = inRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue(),shopInfo.getShopName());
|
||||
result.addAll(unuseCoupon);
|
||||
}
|
||||
if (couponDto.getStatus()==null || (couponDto.getStatus() != null && couponDto.getStatus() == 1)) {
|
||||
List<UserCouponVo> useCoupon = outRecordMapper.queryVipPro(s.getMemberId().intValue(), s.getShopId().intValue(),shopInfo.getShopName());
|
||||
result.addAll(useCoupon);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return new Result(CodeEnum.SUCCESS, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user