修改优惠券面额逻辑
This commit is contained in:
@@ -7,17 +7,18 @@ import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
//分配金额
|
||||
public class TbSplitAccounts implements Serializable {
|
||||
private Integer id;
|
||||
|
||||
private Integer merchantId;
|
||||
private Integer merchantId;//商户ID
|
||||
|
||||
private Integer shopId;
|
||||
private Integer shopId;//店铺ID
|
||||
|
||||
private BigDecimal couponsPrice;
|
||||
private BigDecimal couponsPrice;//优惠券价值
|
||||
|
||||
private BigDecimal conponsAmount;
|
||||
private BigDecimal originAmount;
|
||||
private BigDecimal conponsAmount;//优惠券面额
|
||||
private BigDecimal originAmount;//
|
||||
|
||||
private String isSplit;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chaozhanggui.system.cashierservice.entity.vo;
|
||||
|
||||
import com.chaozhanggui.system.cashierservice.config.FieldDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -59,6 +59,15 @@ public class CartConsumer {
|
||||
if (array.size() > 0){
|
||||
cartService.createOrder(jsonObject);
|
||||
}
|
||||
}else if(jsonObject.getString("type").equals("pendingOrder")){
|
||||
String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
|
||||
if (StringUtils.isEmpty(cartDetail)){
|
||||
throw new MsgException("购物车为空无法下单");
|
||||
}
|
||||
JSONArray array = JSON.parseArray(cartDetail);
|
||||
if (array.size() > 0){
|
||||
cartService.pendingOrder(jsonObject);
|
||||
}
|
||||
}else if(jsonObject.getString("type").equals("clearCart")){
|
||||
cartService.clearCart(jsonObject);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class RedisCst {
|
||||
public static final String ONLINE_APP_USER = "ONLINE_APP_USER:";
|
||||
public static final String LDBL_APP_VERSION = "LDBL_APP_VERSION:";
|
||||
public static final String TABLE_CART = "TABLE:CART:";
|
||||
public static final String TABLE_ORDER = "TABLE:ORDER:";
|
||||
public static final String PRODUCT = "PRODUCT:";
|
||||
|
||||
public static final String INTEGRAL_COIN_KEY = "INTEGRAL:COIN:KEY";
|
||||
|
||||
@@ -482,4 +482,223 @@ public class CartService {
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("tableId").concat("-").concat(shopId), false);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void pendingOrder(JSONObject jsonObject) throws IOException {
|
||||
try {
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal originAmount = BigDecimal.ZERO;
|
||||
BigDecimal saleAmount = BigDecimal.ZERO;
|
||||
String couponId = "";
|
||||
BigDecimal couponAmount = BigDecimal.ZERO;
|
||||
Map<Integer, TbProductSku> skuMap = new HashMap<>();
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
Integer orderId = 0;
|
||||
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId"));
|
||||
if (tbMerchantAccount == null) {
|
||||
throw new MsgException("生成订单错误");
|
||||
}
|
||||
|
||||
String userId = jsonObject.getString("userId");
|
||||
TbUserInfo tbUserInfo = userInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
if (tbUserInfo == null) {
|
||||
throw new MsgException("生成订单失败");
|
||||
}
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
TbProductSkuWithBLOBs tbProduct = productSkuMapper.selectByPrimaryKey(Integer.valueOf(cashierCart.getSkuId()));
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
originAmount = originAmount.add(cashierCart.getTotalAmount());
|
||||
if (Objects.nonNull(tbProduct)) {
|
||||
saleAmount = saleAmount.add(tbProduct.getSalePrice());
|
||||
}
|
||||
skuMap.put(tbProduct.getId(), tbProduct);
|
||||
TbOrderDetail orderDetail = new TbOrderDetail();
|
||||
orderDetail.setCreateTime(new Date());
|
||||
orderDetail.setNum(cashierCart.getNumber());
|
||||
orderDetail.setPrice(cashierCart.getSalePrice());
|
||||
if (cashierCart.getIsPack().equals("true")) {
|
||||
orderDetail.setPriceAmount(cashierCart.getTotalAmount().add(cashierCart.getPackFee()));
|
||||
} else {
|
||||
orderDetail.setPriceAmount(cashierCart.getTotalAmount());
|
||||
}
|
||||
orderDetail.setProductId(Integer.valueOf(cashierCart.getProductId()));
|
||||
orderDetail.setProductSkuId(Integer.valueOf(cashierCart.getSkuId()));
|
||||
orderDetail.setProductSkuName(tbProduct.getSpecSnap());
|
||||
orderDetail.setProductName(cashierCart.getName());
|
||||
orderDetail.setShopId(jsonObject.getInteger("shopId"));
|
||||
orderDetail.setPackAmount(cashierCart.getPackFee());
|
||||
orderDetail.setProductImg(cashierCart.getCoverImg());
|
||||
orderDetail.setStatus("unpaid");
|
||||
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cashierCart.getOrderId());
|
||||
|
||||
}
|
||||
orderDetails.add(orderDetail);
|
||||
if (StringUtils.isNotEmpty(cashierCart.getOrderId())) {
|
||||
orderId = Integer.valueOf(cashierCart.getOrderId());
|
||||
}
|
||||
}
|
||||
//总金额
|
||||
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", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, 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", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, 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", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, 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", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, 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())) {
|
||||
log.info("开始处理订单");
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "订单正在支付中,请稍后再试");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", "");
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
log.info("消息推送");
|
||||
return;
|
||||
}
|
||||
|
||||
orderDetailMapper.deleteByOUrderId(orderId);
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
orderInfo.setSettlementAmount(totalAmount);
|
||||
orderInfo.setUserCouponId(couponId);
|
||||
orderInfo.setUserCouponAmount(couponAmount);
|
||||
orderInfo.setAmount(totalAmount);
|
||||
orderInfo.setOriginAmount(originAmount);
|
||||
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);
|
||||
orderInfoMapper.insert(orderInfo);
|
||||
orderId = orderInfo.getId();
|
||||
}
|
||||
for (TbOrderDetail orderDetail : orderDetails) {
|
||||
orderDetail.setOrderId(orderId);
|
||||
orderDetailMapper.insert(orderDetail);
|
||||
}
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
cashierCart.setUpdatedAt(System.currentTimeMillis());
|
||||
cashierCart.setOrderId(orderId + "");
|
||||
cashierCart.setStatus("closed");
|
||||
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
object.put("updatedAt", System.currentTimeMillis());
|
||||
object.put("orderId", orderId + "");
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
orderInfo.setDetailList(orderDetails);
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", orderInfo);
|
||||
redisUtil.deleteByKey(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId));
|
||||
redisUtil.saveMessage(RedisCst.TABLE_ORDER.concat(orderInfo.getOrderNo()),JSONObject.toJSONString(orderInfo),24*60*60);
|
||||
AppWebSocketServer.AppSendInfo(jsonObject1, jsonObject.getString("userId"), true);
|
||||
JSONObject jsonObject12 = new JSONObject();
|
||||
jsonObject12.put("status", "success");
|
||||
jsonObject12.put("msg", "成功");
|
||||
jsonObject12.put("type", "order");
|
||||
jsonObject12.put("amount", BigDecimal.ZERO);
|
||||
|
||||
jsonObject12.put("data", new JSONArray());
|
||||
AppWebSocketServer.AppSendInfo(jsonObject12, jsonObject.getString("tableId").concat("-").concat(shopId), false);
|
||||
} catch (Exception e) {
|
||||
e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class IntegralService {
|
||||
TbParams params = tbShopUserMapper.selectParams();
|
||||
TbUserCoupons userCoupons = new TbUserCoupons();
|
||||
userCoupons.setUserId(orderInfo.getUserId());
|
||||
userCoupons.setCouponsAmount(orderInfo.getPayAmount().multiply(params.getIntegralRatio()));
|
||||
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")));
|
||||
|
||||
Reference in New Issue
Block a user