1.新增php推送订阅者openid接口

2.库存预警更改为公众号推送
3.sku商品上下架最低价不正确问题
This commit is contained in:
2024-07-25 10:10:54 +08:00
parent 954bfb00ac
commit e87537850a
12 changed files with 263 additions and 30 deletions

View File

@@ -15,6 +15,7 @@ import com.chaozhanggui.system.cashierservice.util.JSONUtil;
import com.chaozhanggui.system.cashierservice.util.LockUtils;
import com.chaozhanggui.system.cashierservice.util.N;
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -62,6 +63,8 @@ public class CartService {
private final TbUserShopMsgMapper tbUserShopMsgMapper;
private final WechatUtil wechatUtil;
private final WxAccountUtil wxAccountUtil;
private final TbShopOpenIdMapper shopOpenIdMapper;
@Autowired
@@ -77,9 +80,10 @@ public class CartService {
private final RedisTemplate<String, Object> redisTemplate;
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate) {
public CartService(TbUserShopMsgMapper tbUserShopMsgMapper, WechatUtil wechatUtil, WxAccountUtil wxAccountUtil, TbShopOpenIdMapper shopOpenIdMapper, ProductService productService, TbProductMapper tbProductMapper, RedisTemplate<String, Object> redisTemplate) {
this.tbUserShopMsgMapper = tbUserShopMsgMapper;
this.wechatUtil = wechatUtil;
this.wxAccountUtil = wxAccountUtil;
this.shopOpenIdMapper = shopOpenIdMapper;
this.productService = productService;
this.tbProductMapper = tbProductMapper;
@@ -478,9 +482,9 @@ public class CartService {
shopOpenIds.forEach(item -> {
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
if (message == null) {
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber() - num) : String.valueOf(productSku.getStockNumber() - num),
"商品库存不足,请及时补充。", item.getOpenId());
wxAccountUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber() - num) : String.valueOf(productSku.getStockNumber() - num)
, item.getOpenId());
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
}else {
log.info("{}已在30分钟内推送过消息跳过发送", item.getOpenId());

View File

@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.PostConstruct;
import java.io.InputStream;
import java.util.UUID;
@Service
@@ -51,6 +52,19 @@ public class FileService {
return "https://" + bucketName + "." + endpoint + "/" + path;
}
public String uploadFileByInputStream(String suffix, InputStream inputStream) throws Exception {
String path = getPath("upload", suffix);
OSS client = new OSSClientBuilder().build(endpoint, credentialsProvider);
try {
client.putObject(bucketName, path, inputStream);
client.shutdown();
} catch (Exception e) {
throw new Exception("上传异常");
}
return "https://" + bucketName + "." + endpoint + "/" + path;
}
public String getPath(String prefix, String suffix) {
//生成uuid
String uuid = UUID.randomUUID().toString().replaceAll("-", "");

View File

@@ -64,6 +64,28 @@ public class LoginService {
this.shopOpenIdMapper = shopOpenIdMapper;
}
public void addShopId(String openId,String shopId) {
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
if(Objects.isNull(shopMsg)){
shopMsg=new TbUserShopMsg();
shopMsg.setShopId(Integer.valueOf(shopId));
shopMsg.setOpenId(openId);
shopMsg.setCreateTime(new Date());
shopMsg.setStatus("1");
tbUserShopMsgMapper.insert(shopMsg);
}
// 为商家绑定openid
if (shopOpenIdMapper.countByOpenId(openId, Integer.valueOf(shopId)) == null) {
TbShopOpenId shopOpenId = new TbShopOpenId();
shopOpenId.setOpenId(openId);
shopOpenId.setCreateTime(DateUtil.date());
shopOpenId.setShopId(Integer.valueOf(shopId));
shopOpenId.setStatus(1);
shopOpenIdMapper.insert(shopOpenId);
}
}
public Result wxBusinessLogin(String openId,String shopId){
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);

View File

@@ -151,12 +151,25 @@ public class ProductService {
// 上下架对应的sku
HashSet<String> specSet = new HashSet<>();
tbProductSkus.forEach(item -> {
BigDecimal lowerPrice = null;
for (TbProductSku item : tbProductSkus) {
if (lowerPrice == null || lowerPrice.compareTo(item.getSalePrice()) > 0) {
lowerPrice = item.getSalePrice();
}
String specSnap = item.getSpecSnap();
if (specSnap != null) {
specSet.addAll(Arrays.asList(specSnap.split(",")));
}
});
}
if (lowerPrice == null) {
lowerPrice = BigDecimal.ZERO;
}
it.setLowPrice(lowerPrice);
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
if (tagSnap != null) {
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);

View File

@@ -1,7 +1,10 @@
package com.chaozhanggui.system.cashierservice.service;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.hutool.extra.qrcode.QrConfig;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chaozhanggui.system.cashierservice.dao.*;
@@ -14,13 +17,18 @@ 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.*;
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -41,6 +49,17 @@ public class UserService {
private TbSystemCouponsMapper systemCouponsMapper;
@Autowired
RedisUtils redisUtils;
@Qualifier("tbShopInfoMapper")
@Autowired
private TbShopInfoMapper tbShopInfoMapper;
private final FileService fileService;
private final WxAccountUtil wxAccountUtil;
public UserService(FileService fileService, WxAccountUtil wxAccountUtil) {
this.fileService = fileService;
this.wxAccountUtil = wxAccountUtil;
}
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
@@ -228,4 +247,15 @@ public class UserService {
int sysNum = systemCouponsMapper.selectByAmount(orderNum);
return userNum+sysNum;
}
public String getSubQrCode(String shopId) throws Exception {
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
if (shopInfo == null) {
throw new MsgException("店铺不存在");
}
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId)), new QrConfig(100, 100), "png", outputStream);
return fileService.uploadFileByInputStream(".png", new ByteArrayInputStream(outputStream.toByteArray()));
}
}