扫码点餐部分
This commit is contained in:
parent
5ad0eea854
commit
cf62b19179
|
|
@ -3,11 +3,11 @@ package com.chaozhanggui.system.cashierservice.controller;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.chaozhanggui.system.cashierservice.service.CartService;
|
||||
import com.chaozhanggui.system.cashierservice.service.ProductService;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -22,6 +22,8 @@ public class ProductController {
|
|||
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
@Autowired
|
||||
private CartService cartService;
|
||||
|
||||
/**
|
||||
* 通过桌码获取shopId
|
||||
|
|
@ -29,12 +31,15 @@ public class ProductController {
|
|||
* @param code
|
||||
* @return shopid
|
||||
*/
|
||||
@RequestMapping("queryShopIdByTableCode")
|
||||
@RequestMapping("queryShop")
|
||||
public Result queryShopIdByTableCode(
|
||||
@RequestHeader("openId") String openId,
|
||||
@RequestHeader("id") String userId,
|
||||
@RequestParam("code") String code) {
|
||||
return productService.queryShopIdByTableCode(userId, openId, code);
|
||||
@RequestParam String lat,
|
||||
@RequestParam String lng,
|
||||
@RequestParam("code") String code
|
||||
) {
|
||||
return productService.queryShopIdByTableCode(userId, openId, code,lat,lng);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -46,24 +51,39 @@ public class ProductController {
|
|||
@RequestMapping("queryProduct")
|
||||
public Result queryProduct(@RequestBody Map<String, String> map) {
|
||||
|
||||
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("code")) {
|
||||
if (ObjectUtil.isEmpty(map) || map.size() <= 0 || !map.containsKey("shopId")) {
|
||||
return Result.fail("参数错误");
|
||||
}
|
||||
return productService.queryProduct(
|
||||
map.get("code").toString(),
|
||||
map.get("shopId").toString(),
|
||||
(map.containsKey("productGroupId") && ObjectUtil.isNotEmpty(map.get("productGroupId"))) ? map.get("productGroupId").toString() : "");
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("queryProductSku")
|
||||
public Result queryProductSku(
|
||||
@RequestParam(value = "code", required = false) String code,
|
||||
@RequestParam("shopId") String shopId,
|
||||
@RequestParam("productId") String productId,
|
||||
@RequestParam("spec_tag") String spec_tag
|
||||
) {
|
||||
return productService.queryProductSku(shopId, productId, spec_tag);
|
||||
return productService.queryProductSku(code,shopId, productId, spec_tag);
|
||||
}
|
||||
|
||||
@PostMapping("addCart")
|
||||
public Result addCart(@RequestBody JSONObject jsonObject) {
|
||||
log.info("添加购物车数据:{}", jsonObject);
|
||||
return cartService.createCart(jsonObject);
|
||||
}
|
||||
|
||||
@PostMapping("cleanCart")
|
||||
public Result cleanCart(@RequestBody JSONObject jsonObject) {
|
||||
log.info("清空购物车数据:{}", jsonObject);
|
||||
cartService.clearCart(jsonObject);
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 团购商品详情/商品类型为 套餐商品
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,9 +20,13 @@ public interface TbProductMapper {
|
|||
|
||||
List<TbProduct> selectByIdIn(@Param("ids") String ids);
|
||||
List<TbProduct> selectByIdInAndCheck(@Param("ids") String ids);
|
||||
List<TbProduct> selectHot(@Param("shopId") String shopId);
|
||||
|
||||
List<TbProduct> selectIsSpecialty(@Param("shopId") Integer shopId);
|
||||
|
||||
List<TbProduct> selectByIds(@Param("list") List<String> ids);
|
||||
Integer selectByQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId);
|
||||
Integer selectByCodeAndSkuId(@Param("code") String code,@Param("skuId") Integer skuId,@Param("shopId") String shopId);
|
||||
Integer selectByNewQcode(@Param("code") String code,@Param("productId") Integer productId,@Param("shopId") String shopId,@Param("list") List<String> list);
|
||||
|
||||
List<ShopGroupInfoVo> selGroups(@Param("proName") String proName,@Param("type") String type,
|
||||
|
|
|
|||
|
|
@ -7,8 +7,18 @@ public class TbProductSkuWithBLOBs extends TbProductSku implements Serializable
|
|||
|
||||
private String specSnap;
|
||||
|
||||
private Integer number;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public Integer getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Integer number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public String getSpecInfo() {
|
||||
return specInfo;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,12 +36,14 @@ public class CartConsumer {
|
|||
String shopId = jsonObject.getString("shopId");
|
||||
if (jsonObject.getString("type").equals("initCart") ) {
|
||||
cartService.initCart(jsonObject);
|
||||
}else if (jsonObject.getString("type").equals("addcart") ) {
|
||||
if (!jsonObject.containsKey("num")) {
|
||||
throw new MsgException("商品数量错误");
|
||||
}
|
||||
cartService.createCart(jsonObject);
|
||||
}else if (jsonObject.getString("type").equals("queryCart") ) {
|
||||
}
|
||||
// else if (jsonObject.getString("type").equals("addcart") ) {
|
||||
// if (!jsonObject.containsKey("num")) {
|
||||
// throw new MsgException("商品数量错误");
|
||||
// }
|
||||
// cartService.createCart(jsonObject);
|
||||
// }
|
||||
else if (jsonObject.getString("type").equals("queryCart") ) {
|
||||
cartService.queryCart(jsonObject);
|
||||
} else if(jsonObject.getString("type").equals("createOrder")){
|
||||
String cartDetail = redisUtil.getMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId));
|
||||
|
|
@ -54,9 +56,9 @@ public class CartConsumer {
|
|||
cartService.createOrder(jsonObject);
|
||||
}
|
||||
}
|
||||
else if(jsonObject.getString("type").equals("clearCart")){
|
||||
cartService.clearCart(jsonObject);
|
||||
}
|
||||
// else if(jsonObject.getString("type").equals("clearCart")){
|
||||
// cartService.clearCart(jsonObject);
|
||||
// }
|
||||
} catch (Exception e) {
|
||||
log.info("数据处理失败:{}",e.getMessage());
|
||||
e.printStackTrace();
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ import com.chaozhanggui.system.cashierservice.netty.PushToAppChannelHandlerAdapt
|
|||
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.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.LockUtils;
|
||||
|
|
@ -130,300 +132,150 @@ public class CartService {
|
|||
* 加入购物车
|
||||
* @param jsonObject 商品信息
|
||||
*/
|
||||
// @Transactional(rollbackFor = Exception.class)
|
||||
// public void createCart(JSONObject jsonObject) {
|
||||
// try {
|
||||
// String tableId = jsonObject.getString("tableId");
|
||||
// String shopId = jsonObject.getString("shopId");
|
||||
// String productId = jsonObject.getString("productId");
|
||||
//
|
||||
// String key = tableId + "-" + shopId;
|
||||
// TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
|
||||
// if (tbProduct == null) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "fail");
|
||||
// jsonObject1.put("msg", "该商品不存在");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
// log.error("该商品不存在 productId:{}", productId);
|
||||
// throw new MsgException("该商品不存在");
|
||||
// }
|
||||
//
|
||||
// String skuId = jsonObject.getString("skuId");
|
||||
// JSONArray jsonArray = new JSONArray();
|
||||
// BigDecimal amount = BigDecimal.ZERO;
|
||||
// TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// JSONObject objectMsg=new JSONObject();
|
||||
// objectMsg.put("skuId",tbProductSkuWithBLOBs.getId());
|
||||
// objectMsg.put("shopId",Integer.valueOf(shopId));
|
||||
//
|
||||
//
|
||||
// producer.con_msg(objectMsg.toString());
|
||||
//
|
||||
//
|
||||
// if (Integer.valueOf(tbProduct.getIsPauseSale()).equals(1)) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "fail");
|
||||
// jsonObject1.put("msg", "该商品已售罄");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
// log.error("该商品已售罄 productId:{}", productId);
|
||||
// throw new MsgException("该商品已售罄");
|
||||
// }
|
||||
//
|
||||
// String skuNum;
|
||||
//
|
||||
// // 1:共享库存 0:独立库存
|
||||
// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
|
||||
// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":product" + productId);
|
||||
// if (!exist) {
|
||||
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, tbProduct.getStockNumber() + "");
|
||||
// }
|
||||
// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":product" + productId);
|
||||
//
|
||||
// if (!skuNum.equals(tbProduct.getStockNumber() + "")) {
|
||||
// skuNum = tbProduct.getStockNumber() + "";
|
||||
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum);
|
||||
// }
|
||||
// } else {
|
||||
// boolean exist = redisUtil.exists(RedisCst.PRODUCT + shopId + ":" + skuId);
|
||||
// if (!exist) {
|
||||
// Double stock = tbProductSkuWithBLOBs.getStockNumber();
|
||||
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":" + skuId, Math.round(stock) + "");
|
||||
// }
|
||||
// skuNum = redisUtil.getMessage(RedisCst.PRODUCT + shopId + ":" + skuId);
|
||||
//
|
||||
// if (!skuNum.equals(Math.round(tbProductSkuWithBLOBs.getStockNumber()) + "")) {
|
||||
// skuNum = Math.round(tbProductSkuWithBLOBs.getStockNumber()) + "";
|
||||
// redisUtil.saveMessage(RedisCst.PRODUCT + shopId + ":product" + productId, skuNum);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Integer buyNum = jsonObject.getInteger("num");
|
||||
// if (tbProduct.getIsStock() == 1) {
|
||||
// boolean flag = false;
|
||||
//
|
||||
// String id = skuId;
|
||||
// if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
|
||||
// if (tbProduct.getStockNumber() < 1 && buyNum > 0) {
|
||||
// flag = true;
|
||||
// id = productId;
|
||||
// }
|
||||
// } else {
|
||||
// if (tbProductSkuWithBLOBs.getIsPauseSale().equals(1)) {
|
||||
// flag = true;
|
||||
// } else if (Integer.valueOf(skuNum) < 1 && buyNum > 0) {
|
||||
// flag = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (flag) {
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "fail");
|
||||
// jsonObject1.put("msg", "该商品库存已售罄");
|
||||
// jsonObject1.put("data", new ArrayList<>());
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
// log.error("该商品库存已售罄 skuId:{}", id);
|
||||
// throw new MsgException("该商品库存已售罄");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
|
||||
// JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
// if (Objects.isNull(array) || array.isEmpty()) {
|
||||
// if (buyNum > 0) {
|
||||
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
// jsonObject.getInteger("userId"), buyNum, tableId, shopId);
|
||||
// jsonArray.add(cashierCart);
|
||||
// amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
//
|
||||
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
|
||||
// }
|
||||
// } else {
|
||||
// boolean flag = true;
|
||||
// for (int i = 0; i < array.size(); i++) {
|
||||
// JSONObject object = array.getJSONObject(i);
|
||||
// TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
// if (cashierCart.getSkuId().equals(skuId)) {
|
||||
// cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
|
||||
// cashierCart.setNumber(cashierCart.getNumber() + buyNum);
|
||||
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
|
||||
// if (cashierCart.getNumber() > 0) {
|
||||
// cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
// cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
// cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
// } else {
|
||||
// cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
// continue;
|
||||
// }
|
||||
// flag = false;
|
||||
// }
|
||||
// jsonArray.add(cashierCart);
|
||||
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
// }
|
||||
// if (flag && buyNum > 0) {
|
||||
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
|
||||
// jsonArray.add(cashierCart);
|
||||
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// if (buyNum > 0) {
|
||||
// TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
// jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
|
||||
// jsonArray.add(cashierCart);
|
||||
// amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
// updateProductStock(tbProduct, tbProductSkuWithBLOBs, buyNum);
|
||||
// }
|
||||
// }
|
||||
// redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString());
|
||||
// JSONObject jsonObject1 = new JSONObject();
|
||||
// jsonObject1.put("status", "success");
|
||||
// jsonObject1.put("msg", "成功");
|
||||
// jsonObject1.put("type", jsonObject.getString("type"));
|
||||
// jsonObject1.put("data", jsonArray);
|
||||
// jsonObject1.put("amount", amount);
|
||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
// } catch (Exception e) {
|
||||
// log.error("长链接错误 createCart{}", e.getMessage());
|
||||
// }
|
||||
// }
|
||||
public void createCart(JSONObject jsonObject) {
|
||||
public Result createCart(JSONObject jsonObject) {
|
||||
try {
|
||||
String tableId = jsonObject.getString("tableId");
|
||||
String shopId = jsonObject.getString("shopId");
|
||||
String productId = jsonObject.getString("productId");
|
||||
String skuId = jsonObject.getString("skuId");
|
||||
Integer type = jsonObject.getInteger("type");
|
||||
Integer buyNum = jsonObject.getInteger("num");
|
||||
if (StringUtils.isBlank(tableId) || StringUtils.isBlank(shopId) || StringUtils.isBlank(productId)
|
||||
|| StringUtils.isBlank(skuId) || type==null || buyNum == null) {
|
||||
return Result.fail("参数缺失");
|
||||
}
|
||||
String key = tableId + "-" + shopId;
|
||||
TbProduct tbProduct = productMapper.selectById(Integer.valueOf(productId));
|
||||
if (tbProduct == null) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品不存在");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品不存在 productId:{}", productId);
|
||||
throw new MsgException("该商品不存在");
|
||||
return Result.fail("该商品不存在");
|
||||
}
|
||||
|
||||
Integer buyNum = jsonObject.getInteger("num");
|
||||
|
||||
String skuId = jsonObject.getString("skuId");
|
||||
// 判断商品是否已下架
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
if (tbProductSkuWithBLOBs ==null || tbProductSkuWithBLOBs.getIsGrounding().equals(0)) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "此商品已下架");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("商品已下架 skuId:{}", skuId);
|
||||
return;
|
||||
rmCart(jsonObject,skuId,key);
|
||||
return Result.fail("商品已下架");
|
||||
}
|
||||
|
||||
if (tbProduct.getIsStock() == 1) {
|
||||
// 1:共享库存 0:独立库存
|
||||
if (Integer.valueOf(tbProduct.getIsDistribute()).equals(1)) {
|
||||
if (tbProduct.getIsPauseSale() == 1 || tbProduct.getStockNumber() < buyNum ) {//是否售罄
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品已售罄");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品已售罄 productId:{}", productId);
|
||||
throw new MsgException("该商品已售罄");
|
||||
if (tbProduct.getIsPauseSale() == 1) {//是否售罄
|
||||
rmCart(jsonObject,skuId,key);
|
||||
return Result.fail("该商品已售罄");
|
||||
}
|
||||
} else {
|
||||
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1 || tbProductSkuWithBLOBs.getStockNumber() < buyNum ) {//是否售罄
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品已售罄");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品已售罄 productId:{}", productId);
|
||||
throw new MsgException("该商品已售罄");
|
||||
if (tbProductSkuWithBLOBs.getIsPauseSale() == 1) {//是否售罄
|
||||
rmCart(jsonObject,skuId,key);
|
||||
return Result.fail("该商品已售罄");
|
||||
}
|
||||
}
|
||||
}
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId)))) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
if (Objects.isNull(array) || array.isEmpty()) {
|
||||
if (buyNum > 0) {
|
||||
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
try{
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
if (Objects.isNull(array) || array.isEmpty()) {
|
||||
if (type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
} else {
|
||||
boolean flag = true;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
if (cashierCart.getSkuId().equals(skuId)) {
|
||||
cashierCart.setTotalNumber(buyNum);
|
||||
cashierCart.setNumber(buyNum);
|
||||
if (type == 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
|
||||
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
continue;
|
||||
}
|
||||
if (cashierCart.getNumber() > 0) {
|
||||
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
} else {
|
||||
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
continue;
|
||||
}
|
||||
flag = false;
|
||||
}
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
if (flag && type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
boolean flag = true;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
if (cashierCart.getSkuId().equals(skuId)) {
|
||||
cashierCart.setTotalNumber(cashierCart.getTotalNumber() + buyNum);
|
||||
cashierCart.setNumber(cashierCart.getNumber() + buyNum);
|
||||
if (buyNum < 0 && tbProductSkuWithBLOBs.getSuit() != null && tbProductSkuWithBLOBs.getSuit() > 1 && cashierCart.getNumber() < tbProductSkuWithBLOBs.getSuit()) {
|
||||
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
continue;
|
||||
}
|
||||
if (cashierCart.getNumber() > 0) {
|
||||
cashierCart.setTotalAmount(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
cashierCart.setUpdatedAt(Instant.now().toEpochMilli());
|
||||
cashierCartMapper.updateByPrimaryKeySelective(cashierCart);
|
||||
} else {
|
||||
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
continue;
|
||||
}
|
||||
flag = false;
|
||||
}
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
if (flag && buyNum > 0) {
|
||||
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
|
||||
if (type == 1) {
|
||||
TbCashierCart cashierCart = addCart(productId, skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, shopId);
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (buyNum > 0) {
|
||||
TbCashierCart cashierCart = addCart(jsonObject.getString("productId"), skuId,
|
||||
jsonObject.getInteger("userId"), buyNum, tableId, jsonObject.getString("shopId"));
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}catch (MsgException e){
|
||||
if(e.getMessage().equals("商品起售库存不足")){
|
||||
return Result.fail("商品起售库存不足");
|
||||
}
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(tableId).concat("-").concat(shopId), jsonArray.toJSONString());
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("type", "addcart");
|
||||
jsonObject1.put("data", jsonArray);
|
||||
jsonObject1.put("amount", amount);
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false);
|
||||
} catch (Exception e) {
|
||||
log.error("长链接错误 createCart{}", e.getMessage());
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
private void rmCart(JSONObject jsonObject,String skuId, String key) {
|
||||
JSONArray jsonArray = new JSONArray();
|
||||
BigDecimal amount = BigDecimal.ZERO;
|
||||
if (redisUtil.exists(RedisCst.TABLE_CART.concat(key))) {
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
if (!Objects.isNull(array) && !array.isEmpty()) {
|
||||
boolean flag = false;
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
JSONObject object = array.getJSONObject(i);
|
||||
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||
if (cashierCart.getSkuId().equals(skuId)) {
|
||||
cashierCartMapper.deleteByPrimaryKey(cashierCart.getId());
|
||||
flag = true;
|
||||
continue;
|
||||
}
|
||||
jsonArray.add(cashierCart);
|
||||
amount = amount.add(new BigDecimal(cashierCart.getTotalNumber()).multiply(cashierCart.getSalePrice().add(cashierCart.getPackFee())));
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(key), jsonArray.toJSONString());
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", "addcart");
|
||||
jsonObject1.put("data", jsonArray);
|
||||
jsonObject1.put("amount", amount);
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
if(flag){
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, "", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改库存并根据警告线发送消息
|
||||
*
|
||||
|
|
@ -500,51 +352,40 @@ public class CartService {
|
|||
}
|
||||
}
|
||||
|
||||
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws RuntimeException {
|
||||
private TbCashierCart addCart(String productId, String skuId, Integer userId, Integer num, String tableId, String shopId) throws Exception{
|
||||
try {
|
||||
TbProduct product = productMapper.selectById(Integer.valueOf(productId));
|
||||
String key = tableId + "-" + shopId;
|
||||
if (Objects.isNull(product)) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品不存在");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
|
||||
log.error("购物车添加商品异常,该商品不存在:{}", productId);
|
||||
throw new MsgException("该商品不存在");
|
||||
}
|
||||
TbProductSkuWithBLOBs productSku = productSkuMapper.selectByPrimaryKey(Integer.valueOf(skuId));
|
||||
if (Objects.isNull(productSku)) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品规格不存在");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
|
||||
log.error("购物车添加商品异常,该商品sku不存在:{}", productId);
|
||||
throw new MsgException("该商品规格不存在");
|
||||
}
|
||||
TbCashierCart cashierCart = new TbCashierCart();
|
||||
if (productSku.getSuit() != null && productSku.getSuit() > 1) {
|
||||
if (product.getIsStock() == 1) {
|
||||
boolean isSale = false;
|
||||
// 1:共享库存 0:独立库存
|
||||
if (Integer.valueOf(product.getIsDistribute()).equals(1)) {
|
||||
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
|
||||
if (num > productSku.getSuit()) {
|
||||
if (num > product.getStockNumber()) isSale = true;
|
||||
}else {
|
||||
if (productSku.getSuit() > product.getStockNumber()) isSale = true;
|
||||
}
|
||||
} else {
|
||||
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
|
||||
if (num > productSku.getSuit()) {
|
||||
if (num > productSku.getStockNumber()) isSale = true;
|
||||
}else {
|
||||
if (productSku.getSuit() > productSku.getStockNumber()) isSale = true;
|
||||
}
|
||||
}
|
||||
if (isSale) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品库存不足");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, userId.toString(), true);
|
||||
log.error("购物车添加商品异常,该商品起售库存不足:{}", productId);
|
||||
throw new MsgException("该商品起售库存不足");
|
||||
throw new MsgException("商品起售库存不足");
|
||||
}
|
||||
}
|
||||
cashierCart.setNumber(productSku.getSuit());
|
||||
cashierCart.setTotalNumber(productSku.getSuit());
|
||||
if(num > productSku.getSuit()){
|
||||
cashierCart.setNumber(num);
|
||||
cashierCart.setTotalNumber(num);
|
||||
}else {
|
||||
cashierCart.setNumber(productSku.getSuit());
|
||||
cashierCart.setTotalNumber(productSku.getSuit());
|
||||
}
|
||||
} else {
|
||||
cashierCart.setNumber(num);
|
||||
cashierCart.setTotalNumber(num);
|
||||
|
|
@ -592,8 +433,7 @@ public class CartService {
|
|||
String tableId = jsonObject.getString("tableId");
|
||||
String remark = StringUtils.isBlank(jsonObject.getString("remark"))?"":jsonObject.getString("remark");
|
||||
String key = tableId + "-" + shopId;
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId").concat("-").concat(shopId))));
|
||||
List<Integer> ids = new ArrayList<>();
|
||||
JSONArray array = JSON.parseArray(redisUtil.getMessage(RedisCst.TABLE_CART.concat(key)));
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
BigDecimal packAMount = BigDecimal.ZERO;
|
||||
BigDecimal originAmount = BigDecimal.ZERO;
|
||||
|
|
@ -602,7 +442,7 @@ public class CartService {
|
|||
BigDecimal couponAmount = BigDecimal.ZERO;
|
||||
List<TbOrderDetail> orderDetails = new ArrayList<>();
|
||||
Integer orderId = 0;
|
||||
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(jsonObject.getString("shopId"));
|
||||
TbMerchantAccount tbMerchantAccount = merchantAccountMapper.selectByShopId(shopId);
|
||||
if (tbMerchantAccount == null) {
|
||||
MsgException.throwException("生成订单错误");
|
||||
}
|
||||
|
|
@ -643,7 +483,7 @@ public class CartService {
|
|||
} catch (Exception e) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "商品库存不足" + tbProduct1.getName());
|
||||
jsonObject1.put("msg", tbProduct1.getName() + "库存不足");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
return;
|
||||
|
|
@ -949,7 +789,7 @@ public class CartService {
|
|||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "success");
|
||||
jsonObject1.put("msg", "成功");
|
||||
jsonObject1.put("type", "clearCart");
|
||||
jsonObject1.put("type", "addcart");
|
||||
jsonObject1.put("amount", BigDecimal.ZERO);
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
// //修改耗材数据
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.sign.Result;
|
|||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -68,13 +69,25 @@ public class ProductService {
|
|||
@Autowired
|
||||
private TbUserInfoMapper tbUserInfoMapper;
|
||||
|
||||
public Result queryShopIdByTableCode(String userId,String openId,String code) {
|
||||
String shopId = tbShopTableMapper.queryShopIdByTableCode(code);
|
||||
if (StringUtils.isBlank(shopId)) {
|
||||
public Result queryShopIdByTableCode(String userId,String openId,String code,String lat,String lng) {
|
||||
if(StringUtils.isBlank(code)) return Result.fail("桌码信息为空");
|
||||
if (StringUtils.isBlank(lat) || lat.equals("undefined")) {
|
||||
lat = "34.343207";
|
||||
lng = "108.939645";
|
||||
}
|
||||
TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code);
|
||||
if (tbShopTable == null) {
|
||||
return Result.fail("台桌信息不存在");
|
||||
}
|
||||
|
||||
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, shopId);
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(tbShopTable.getShopId());
|
||||
String distance = LocationUtils.getDistanceString(
|
||||
Double.parseDouble(lng), Double.parseDouble(lat),
|
||||
Double.parseDouble(shopInfo.getLng()), Double.parseDouble(shopInfo.getLat()));
|
||||
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
|
||||
concurrentMap.put("shopTableInfo", tbShopTable);
|
||||
concurrentMap.put("storeInfo", shopInfo);
|
||||
concurrentMap.put("distance", distance);
|
||||
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userId, tbShopTable.getShopId().toString());
|
||||
try{
|
||||
if (ObjectUtil.isEmpty(shopUser)) {
|
||||
TbUserInfo tbUserInfo = tbUserInfoMapper.selectByPrimaryKey(Integer.valueOf(userId));
|
||||
|
|
@ -95,7 +108,7 @@ public class ProductService {
|
|||
shopUser.setConsumeNumber(0);
|
||||
shopUser.setLevelConsume(BigDecimal.ZERO);
|
||||
shopUser.setStatus(Byte.parseByte("1"));
|
||||
shopUser.setShopId(shopId);
|
||||
shopUser.setShopId(tbShopTable.getShopId().toString());
|
||||
shopUser.setUserId(userId);
|
||||
shopUser.setMiniOpenId(openId);
|
||||
shopUser.setCreatedAt(System.currentTimeMillis());
|
||||
|
|
@ -114,27 +127,141 @@ public class ProductService {
|
|||
log.info("通过桌码获取shopId 进行用户绑定错误:{}",e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS, shopId);
|
||||
return Result.success(CodeEnum.SUCCESS, concurrentMap);
|
||||
}
|
||||
|
||||
public Result queryProduct(String code, String productGroupId) {
|
||||
|
||||
public Result queryProduct(String shopId, String productGroupId) {
|
||||
ConcurrentMap<String, Object> concurrentMap = new ConcurrentHashMap<>();
|
||||
|
||||
TbShopTable tbShopTable = tbShopTableMapper.selectQRcode(code);
|
||||
if (ObjectUtil.isEmpty(tbShopTable) || ObjectUtil.isNull(tbShopTable)) {
|
||||
return Result.fail("台桌信息不存在");
|
||||
}
|
||||
|
||||
|
||||
Integer id = ObjectUtil.isNotEmpty(productGroupId) ? Integer.valueOf(productGroupId) : null;
|
||||
List<TbProductGroup> groupList = tbProductGroupMapper.selectByQrcode(code, id);
|
||||
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
|
||||
//招牌菜
|
||||
List<TbProduct> tbProducts = tbProductMapper.selectIsSpecialty(Integer.valueOf(shopId));
|
||||
if (ObjectUtil.isNotEmpty(tbProducts) && tbProducts.size() > 0) {
|
||||
tbProducts.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():"");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
TbProductGroup group = groupList.get(0);
|
||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(group.getShopId());
|
||||
concurrentMap.put("shopTableInfo", tbShopTable);
|
||||
concurrentMap.put("storeInfo", shopInfo);
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
sum.addAndGet(item.getStockNumber());
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
}
|
||||
concurrentMap.put("hots", tbProducts);
|
||||
List<TbProductGroup> groupList = tbProductGroupMapper.selectByShopId(shopId, id);
|
||||
if (ObjectUtil.isNotEmpty(groupList) && groupList.size() > 0) {
|
||||
//热销
|
||||
TbProductGroup hot =new TbProductGroup();
|
||||
hot.setName("热销");
|
||||
List<TbProduct> hots = tbProductMapper.selectHot(shopId);
|
||||
hots.parallelStream().forEach(it -> {
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():"");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
sum.addAndGet(item.getStockNumber());
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
||||
String specSnap = item.getSpecSnap();
|
||||
if (specSnap != null) {
|
||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
it.setLowPrice(lowerPrice);
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
JSONObject snapJSON;
|
||||
|
||||
JSONArray finalSnap = new JSONArray();
|
||||
|
||||
for (Object snap : tagSnaps) {
|
||||
snapJSON = (JSONObject) snap;
|
||||
String values = snapJSON.getString("value");
|
||||
String finalValues = "";
|
||||
|
||||
if (StrUtil.isNotBlank(values)) {
|
||||
String[] valueList = values.split(",");
|
||||
for (String value : valueList) {
|
||||
if (specSet.contains(value)) {
|
||||
finalValues = finalValues + (value) + ",";
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(finalValues)) {
|
||||
finalValues = StrUtil.removeSuffix(finalValues, ",");
|
||||
snapJSON.put("value", finalValues);
|
||||
finalSnap.add(snapJSON);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
skuResult.setTagSnap(finalSnap.toJSONString());
|
||||
}
|
||||
|
||||
it.setProductSkuResult(skuResult);
|
||||
});
|
||||
hot.setProducts(hots);
|
||||
|
||||
//商品
|
||||
groupList.parallelStream().forEach(g -> {
|
||||
String in = g.getProductIds().substring(1, g.getProductIds().length() - 1);
|
||||
|
||||
|
|
@ -144,16 +271,18 @@ public class ProductService {
|
|||
List<TbProduct> products = tbProductMapper.selectByIdInAndCheck(in);
|
||||
if (ObjectUtil.isNotEmpty(products) && products.size() > 0) {
|
||||
products.parallelStream().forEach(it -> {
|
||||
Integer sum = tbProductMapper.selectByQcode(code, it.getId(), it.getShopId());
|
||||
it.setCartNumber(sum == null ? "0" : String.valueOf(sum));
|
||||
TbShopUnit tbShopUnit = unitMapper.selectByPrimaryKey(Integer.valueOf(it.getUnitId()));
|
||||
it.setUnitSnap(tbShopUnit!=null?tbShopUnit.getName():"");
|
||||
it.setCartNumber("0");
|
||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||
|
||||
// 上下架对应的sku
|
||||
HashSet<String> specSet = new HashSet<>();
|
||||
|
||||
AtomicDouble sum = new AtomicDouble(0.0);
|
||||
BigDecimal lowerPrice = null;
|
||||
for (TbProductSku item : tbProductSkus) {
|
||||
sum.addAndGet(item.getStockNumber());
|
||||
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
|
||||
lowerPrice = item.getSalePrice();
|
||||
}
|
||||
|
|
@ -163,13 +292,11 @@ public class ProductService {
|
|||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||
}
|
||||
}
|
||||
|
||||
it.setStockNumber(sum.intValue());
|
||||
if (lowerPrice == null) {
|
||||
lowerPrice = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
it.setLowPrice(lowerPrice);
|
||||
|
||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||
if (tagSnap != null) {
|
||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||
|
|
@ -221,12 +348,16 @@ public class ProductService {
|
|||
}
|
||||
|
||||
|
||||
public Result queryProductSku(String shopId, String productId, String spec_tag) {
|
||||
public Result queryProductSku(String code,String shopId, String productId, String spec_tag) {
|
||||
if (ObjectUtil.isEmpty(shopId) || ObjectUtil.isEmpty(productId)) {
|
||||
return Result.fail("参数错误");
|
||||
}
|
||||
|
||||
TbProductSkuWithBLOBs tbProductSkuWithBLOBs = tbProductSkuMapper.selectByShopIdAndProductIdAndSpec(shopId, productId, spec_tag);
|
||||
if(StringUtils.isNotBlank(code)) {
|
||||
Integer sum = tbProductMapper.selectByCodeAndSkuId(code, tbProductSkuWithBLOBs.getId(), shopId);
|
||||
tbProductSkuWithBLOBs.setNumber(sum);
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS, tbProductSkuWithBLOBs);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -229,9 +229,9 @@
|
|||
FROM
|
||||
tb_product_group
|
||||
where shop_id=#{shopId} and is_show=1
|
||||
<if test="groupId != null">
|
||||
<if test="groupId != null and groupId != ''">
|
||||
and id = #{groupId}
|
||||
</if>
|
||||
order by g.sort asc
|
||||
order by sort asc
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -932,11 +932,45 @@
|
|||
select min( sku.suit ) as suit,tb.*
|
||||
from tb_product tb
|
||||
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
|
||||
where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1
|
||||
where tb.id in (${ids}) and is_show_mall =1 and sku.is_del = 0 and sku.is_grounding=1 and tb.status = 1
|
||||
group by tb.id
|
||||
order by tb.sort asc
|
||||
</select>
|
||||
|
||||
<select id="selectHot" resultMap="BaseResultMap">
|
||||
select min(sku.suit) as suit, tb.*
|
||||
from tb_product tb
|
||||
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
|
||||
JOIN (SELECT product_id
|
||||
FROM tb_product_sku
|
||||
WHERE shop_id = #{shopId}
|
||||
GROUP BY product_id
|
||||
ORDER BY SUM(stock_number) DESC LIMIT 3) AS top_products ON tb.id = top_products.product_id
|
||||
where is_show_mall = 1
|
||||
and tb.status = 1
|
||||
and sku.is_del = 0
|
||||
and sku.is_grounding = 1
|
||||
group by tb.id
|
||||
order by tb.sort asc
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectIsSpecialty" resultMap="BaseResultMap">
|
||||
select min(sku.suit) as suit, tb.*
|
||||
from tb_product tb
|
||||
LEFT JOIN tb_product_sku sku ON tb.id = sku.product_id
|
||||
where is_hot = 1
|
||||
and is_show_mall = 1
|
||||
and tb.shop_id = #{shopId}
|
||||
and tb.status = 1
|
||||
and sku.is_del = 0
|
||||
and sku.is_grounding = 1
|
||||
group by tb.id
|
||||
order by tb.sort asc
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
<!-- <select id="selectByIdIn" resultMap="BaseResultMap">-->
|
||||
<!-- select *-->
|
||||
<!-- from tb_product-->
|
||||
|
|
@ -963,6 +997,17 @@
|
|||
t.shop_id,
|
||||
t.product_id
|
||||
</select>
|
||||
<select id="selectByCodeAndSkuId" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
IFNULL(t.number, 0 )
|
||||
FROM
|
||||
tb_cashier_cart t
|
||||
WHERE
|
||||
t.shop_id = #{shopId}
|
||||
AND t.sku_id = #{skuId}
|
||||
AND t.`status` = 'create'
|
||||
AND t.table_id = #{code}
|
||||
</select>
|
||||
<select id="selectByNewQcode" resultType="java.lang.Integer">
|
||||
SELECT
|
||||
IFNULL( sum( t.number ), 0 )
|
||||
|
|
|
|||
Loading…
Reference in New Issue