Merge remote-tracking branch 'origin/dev' into hph
This commit is contained in:
@@ -61,8 +61,11 @@ public class LoginFilter implements Filter {
|
|||||||
"/cashierService/song/detail",
|
"/cashierService/song/detail",
|
||||||
"/cashierService/song/record",
|
"/cashierService/song/record",
|
||||||
"/cashierService/song",
|
"/cashierService/song",
|
||||||
|
"/cashierService/song/**",
|
||||||
"/cashierService/song/singing",
|
"/cashierService/song/singing",
|
||||||
"/cashierService/login/test"
|
"/cashierService/login/test",
|
||||||
|
"cashierService/subMsg",
|
||||||
|
"cashierService/user/subQrCode"
|
||||||
);
|
);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package com.chaozhanggui.system.cashierservice.controller;
|
|||||||
|
|
||||||
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
|
import com.chaozhanggui.system.cashierservice.dao.TbPlatformDictMapper;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
|
import com.chaozhanggui.system.cashierservice.entity.TbPlatformDict;
|
||||||
|
import com.chaozhanggui.system.cashierservice.entity.dto.WxMsgSubDTO;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.DistrictVo;
|
||||||
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
import com.chaozhanggui.system.cashierservice.redis.RedisCst;
|
||||||
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
||||||
import com.chaozhanggui.system.cashierservice.service.FileService;
|
import com.chaozhanggui.system.cashierservice.service.FileService;
|
||||||
|
import com.chaozhanggui.system.cashierservice.service.LoginService;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.LocationUtils;
|
import com.chaozhanggui.system.cashierservice.util.LocationUtils;
|
||||||
@@ -44,6 +46,10 @@ public class CommonController {
|
|||||||
private TbPlatformDictMapper platformDictMapper;
|
private TbPlatformDictMapper platformDictMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private FileService fileService;
|
private FileService fileService;
|
||||||
|
|
||||||
|
private final LoginService loginService;;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一分钟
|
* 一分钟
|
||||||
*/
|
*/
|
||||||
@@ -198,4 +204,19 @@ public class CommonController {
|
|||||||
// 将手机号码的请求次数加1
|
// 将手机号码的请求次数加1
|
||||||
redisUtil.getIncrNum(key, "2");
|
redisUtil.getIncrNum(key, "2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 订阅消息
|
||||||
|
* @param wxMsgSubDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/subMsg")
|
||||||
|
public Result subscribeWxAccount(@RequestBody WxMsgSubDTO wxMsgSubDTO) {
|
||||||
|
if (wxMsgSubDTO.getOpenId() == null || wxMsgSubDTO.getShopId() == null) {
|
||||||
|
return Result.fail("shopId或openId缺失");
|
||||||
|
}
|
||||||
|
loginService.addShopId(wxMsgSubDTO.getOpenId(), wxMsgSubDTO.getShopId());
|
||||||
|
return Result.success(CodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,28 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.controller;
|
package com.chaozhanggui.system.cashierservice.controller;
|
||||||
|
|
||||||
|
|
||||||
import cn.binarywang.wx.miniapp.util.crypt.WxMaCryptUtils;
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.TbMerchantAccountMapper;
|
|
||||||
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
import com.chaozhanggui.system.cashierservice.dao.TbShopInfoMapper;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
|
import com.chaozhanggui.system.cashierservice.dao.TbShopUserMapper;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper;
|
import com.chaozhanggui.system.cashierservice.dao.TbUserInfoMapper;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbMerchantAccount;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
import com.chaozhanggui.system.cashierservice.entity.TbShopInfo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
|
import com.chaozhanggui.system.cashierservice.entity.TbShopUser;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
|
import com.chaozhanggui.system.cashierservice.entity.TbUserInfo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.AuthUserDto;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.dto.OnlineUserDto;
|
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralFlowVo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
|
import com.chaozhanggui.system.cashierservice.entity.vo.IntegralVo;
|
||||||
import com.chaozhanggui.system.cashierservice.entity.vo.OrderVo;
|
|
||||||
import com.chaozhanggui.system.cashierservice.service.LoginService;
|
|
||||||
import com.chaozhanggui.system.cashierservice.service.OnlineUserService;
|
|
||||||
import com.chaozhanggui.system.cashierservice.service.UserService;
|
import com.chaozhanggui.system.cashierservice.service.UserService;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.IpUtil;
|
|
||||||
import com.chaozhanggui.system.cashierservice.util.MD5Utils;
|
|
||||||
import com.chaozhanggui.system.cashierservice.util.StringUtil;
|
|
||||||
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
import com.chaozhanggui.system.cashierservice.util.TokenUtil;
|
||||||
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import java.io.IOException;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@CrossOrigin(origins = "*")
|
@CrossOrigin(origins = "*")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -164,4 +144,17 @@ public class UserContoller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取订阅当前用户店库存预警消息的二维码
|
||||||
|
*
|
||||||
|
* @param shopId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/subQrCode")
|
||||||
|
public Result getSubQrCode(String shopId) throws Exception {
|
||||||
|
String url = userService.getSubQrCode(shopId);
|
||||||
|
return Result.successWithData(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.entity.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxMsgSubDTO {
|
||||||
|
private String shopId;
|
||||||
|
private String openId;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.service;
|
package com.chaozhanggui.system.cashierservice.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.thread.ThreadUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
@@ -15,6 +16,7 @@ import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
|||||||
import com.chaozhanggui.system.cashierservice.util.LockUtils;
|
import com.chaozhanggui.system.cashierservice.util.LockUtils;
|
||||||
import com.chaozhanggui.system.cashierservice.util.N;
|
import com.chaozhanggui.system.cashierservice.util.N;
|
||||||
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
|
import com.chaozhanggui.system.cashierservice.wxUtil.WechatUtil;
|
||||||
|
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -29,6 +31,7 @@ import java.math.BigDecimal;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lyf
|
* @author lyf
|
||||||
@@ -62,6 +65,8 @@ public class CartService {
|
|||||||
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
private final TbUserShopMsgMapper tbUserShopMsgMapper;
|
||||||
private final WechatUtil wechatUtil;
|
private final WechatUtil wechatUtil;
|
||||||
|
|
||||||
|
private final WxAccountUtil wxAccountUtil;
|
||||||
|
|
||||||
private final TbShopOpenIdMapper shopOpenIdMapper;
|
private final TbShopOpenIdMapper shopOpenIdMapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -77,9 +82,10 @@ public class CartService {
|
|||||||
|
|
||||||
private final RedisTemplate<String, Object> redisTemplate;
|
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.tbUserShopMsgMapper = tbUserShopMsgMapper;
|
||||||
this.wechatUtil = wechatUtil;
|
this.wechatUtil = wechatUtil;
|
||||||
|
this.wxAccountUtil = wxAccountUtil;
|
||||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
this.shopOpenIdMapper = shopOpenIdMapper;
|
||||||
this.productService = productService;
|
this.productService = productService;
|
||||||
this.tbProductMapper = tbProductMapper;
|
this.tbProductMapper = tbProductMapper;
|
||||||
@@ -457,6 +463,10 @@ public class CartService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (product.getIsStock() == null || product.getIsStock() != 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(product.getShopId()));
|
TbShopInfo shopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(product.getShopId()));
|
||||||
if (shopInfo == null) {
|
if (shopInfo == null) {
|
||||||
log.info("商品库存预警发送失败,店铺不存在,店铺id:{}", product.getShopId());
|
log.info("商品库存预警发送失败,店铺不存在,店铺id:{}", product.getShopId());
|
||||||
@@ -478,9 +488,9 @@ public class CartService {
|
|||||||
shopOpenIds.forEach(item -> {
|
shopOpenIds.forEach(item -> {
|
||||||
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
|
String message = redisUtil.getMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId());
|
||||||
if (message == null) {
|
if (message == null) {
|
||||||
wechatUtil.sendStockWarnMsg(shopInfo.getShopName(), product.getName(),
|
wxAccountUtil.sendStockWarnMsg("商品库存不足", product.getName(),
|
||||||
product.getIsDistribute() == 1 ? String.valueOf(product.getStockNumber() - num) : String.valueOf(productSku.getStockNumber() - num),
|
product.getIsDistribute() == 1 ? product.getStockNumber() - num : (int) (productSku.getStockNumber() - num)
|
||||||
"商品库存不足,请及时补充。", item.getOpenId());
|
, item.getOpenId());
|
||||||
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
|
redisUtil.saveMessage(RedisCst.SEND_STOCK_WARN_MSG + product.getId() + ":" + item.getOpenId(), product.getId().toString(), 60 * 30L);
|
||||||
}else {
|
}else {
|
||||||
log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId());
|
log.info("{}已在30分钟内推送过消息,跳过发送", item.getOpenId());
|
||||||
@@ -639,11 +649,6 @@ public class CartService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送判断耗材是否耗尽消息
|
|
||||||
JSONObject objectMsg = new JSONObject();
|
|
||||||
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
|
|
||||||
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
|
|
||||||
producer.con_msg(objectMsg.toString());
|
|
||||||
|
|
||||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||||
@@ -864,6 +869,18 @@ public class CartService {
|
|||||||
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
// PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), jsonObject.getString("userId"));
|
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject12.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), jsonObject.getString("userId"));
|
||||||
redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L);
|
redisUtil.saveMessage(RedisCst.ORDER_EXPIRED.concat(orderId.toString()), orderId.toString(), 60 * 16L);
|
||||||
|
ThreadUtil.execAsync(() -> {
|
||||||
|
ThreadUtil.sleep(5, TimeUnit.SECONDS);
|
||||||
|
for (int i = 0; i < array.size(); i++) {
|
||||||
|
JSONObject object = array.getJSONObject(i);
|
||||||
|
TbCashierCart cashierCart = JSONUtil.parseJSONStr2T(object.toJSONString(), TbCashierCart.class);
|
||||||
|
// 发送判断耗材是否耗尽消息
|
||||||
|
JSONObject objectMsg = new JSONObject();
|
||||||
|
objectMsg.put("skuId", Integer.valueOf(cashierCart.getSkuId()));
|
||||||
|
objectMsg.put("shopId", Integer.valueOf(cashierCart.getShopId()));
|
||||||
|
producer.con_msg(objectMsg.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -51,6 +52,19 @@ public class FileService {
|
|||||||
return "https://" + bucketName + "." + endpoint + "/" + path;
|
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) {
|
public String getPath(String prefix, String suffix) {
|
||||||
//生成uuid
|
//生成uuid
|
||||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||||
|
|||||||
@@ -64,6 +64,28 @@ public class LoginService {
|
|||||||
this.shopOpenIdMapper = shopOpenIdMapper;
|
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){
|
public Result wxBusinessLogin(String openId,String shopId){
|
||||||
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
|
TbUserShopMsg shopMsg= tbUserShopMsgMapper.selectByShopIdAndOpenId(Integer.valueOf(shopId),openId);
|
||||||
@@ -414,28 +436,20 @@ public class LoginService {
|
|||||||
@Transactional
|
@Transactional
|
||||||
public Result upPhone(String openId, String phone, String shopId) {
|
public Result upPhone(String openId, String phone, String shopId) {
|
||||||
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
|
TbUserInfo userInfo = tbUserInfoMapper.selectByOpenId(openId);
|
||||||
boolean isup = false;
|
// 同一个手机号 同一个店 userId 不为空
|
||||||
if(StringUtils.isNotBlank(userInfo.getTelephone())){
|
TbShopUser tbShopUserPC = tbShopUserMapper.selectPCByPhoneAndShopId(userInfo.getTelephone(),shopId);
|
||||||
List<TbShopUser> tbShopUsers = tbShopUserMapper.selectByPhone(userInfo.getTelephone());
|
if (tbShopUserPC != null) {
|
||||||
for (TbShopUser tbShopUser : tbShopUsers) {
|
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||||
if (tbShopUser.getShopId().equals(shopId)) {
|
tbShopUserMapper.deleteByPrimaryKey(tbShopUserSM.getId());
|
||||||
isup = true;
|
tbShopUserPC.setUserId(userInfo.getId().toString());
|
||||||
}
|
tbShopUserMapper.updateByPrimaryKey(tbShopUserPC);
|
||||||
tbShopUser.setTelephone(phone);
|
|
||||||
tbShopUser.setUpdatedAt(System.currentTimeMillis());
|
|
||||||
tbShopUserMapper.updateByPrimaryKey(tbShopUser);
|
|
||||||
}
|
|
||||||
if(!isup){
|
|
||||||
registerShopUser(userInfo,shopId);
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
TbShopUser shopUser = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(), shopId);
|
TbShopUser tbShopUserSM = tbShopUserMapper.selectByUserIdAndShopId(userInfo.getId().toString(),shopId);
|
||||||
if (shopUser != null) {
|
if (tbShopUserSM != null) {
|
||||||
shopUser.setTelephone(phone);
|
tbShopUserSM.setIsVip(Byte.parseByte("1"));
|
||||||
shopUser.setUpdatedAt(System.currentTimeMillis());
|
tbShopUserSM.setTelephone(phone);
|
||||||
tbShopUserMapper.updateByPrimaryKey(shopUser);
|
tbShopUserSM.setUpdatedAt(System.currentTimeMillis());
|
||||||
}else {
|
tbShopUserMapper.updateByPrimaryKey(tbShopUserSM);
|
||||||
registerShopUser(userInfo,shopId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userInfo.setTelephone(phone);
|
userInfo.setTelephone(phone);
|
||||||
@@ -454,7 +468,7 @@ public class LoginService {
|
|||||||
shopUser.setCode(dynamicCode);
|
shopUser.setCode(dynamicCode);
|
||||||
shopUser.setTelephone(userInfo.getTelephone());
|
shopUser.setTelephone(userInfo.getTelephone());
|
||||||
shopUser.setAmount(BigDecimal.ZERO);
|
shopUser.setAmount(BigDecimal.ZERO);
|
||||||
shopUser.setIsVip(Byte.parseByte("0"));
|
shopUser.setIsVip(Byte.parseByte("1"));
|
||||||
shopUser.setCreditAmount(BigDecimal.ZERO);
|
shopUser.setCreditAmount(BigDecimal.ZERO);
|
||||||
shopUser.setConsumeAmount(BigDecimal.ZERO);
|
shopUser.setConsumeAmount(BigDecimal.ZERO);
|
||||||
shopUser.setConsumeNumber(0);
|
shopUser.setConsumeNumber(0);
|
||||||
|
|||||||
@@ -405,6 +405,12 @@ public class PayService {
|
|||||||
|
|
||||||
producer.printMechine(orderId);
|
producer.printMechine(orderId);
|
||||||
sendOrderToClient(orderInfo);
|
sendOrderToClient(orderInfo);
|
||||||
|
|
||||||
|
// 发送mq消息并保存库存记录
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("orderId", orderInfo.getId());
|
||||||
|
data.put("plat", "miniApp");
|
||||||
|
mQUtils.sendStockSaleMsg(data);
|
||||||
return Result.success(CodeEnum.SUCCESS, "1");
|
return Result.success(CodeEnum.SUCCESS, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,24 +149,39 @@ public class ProductService {
|
|||||||
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
List<TbProductSku> tbProductSkus = tbProductSkuMapper.selectGroundingByProId(it.getId());
|
||||||
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
TbProductSkuResult skuResult = tbProductSkuResultMapper.selectByPrimaryKey(it.getId());
|
||||||
|
|
||||||
|
// 上下架对应的sku
|
||||||
HashSet<String> specSet = new HashSet<>();
|
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();
|
String specSnap = item.getSpecSnap();
|
||||||
if (specSnap != null) {
|
if (specSnap != null) {
|
||||||
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
specSet.addAll(Arrays.asList(specSnap.split(",")));
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
|
if (lowerPrice == null) {
|
||||||
|
lowerPrice = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
it.setLowPrice(lowerPrice);
|
||||||
|
|
||||||
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
String tagSnap = skuResult != null ? skuResult.getTagSnap() : null;
|
||||||
if (tagSnap != null) {
|
if (tagSnap != null) {
|
||||||
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
JSONArray tagSnaps = JSONObject.parseArray(tagSnap);
|
||||||
JSONObject snapJSON;
|
JSONObject snapJSON;
|
||||||
|
|
||||||
JSONArray finalSnap = new JSONArray();
|
JSONArray finalSnap = new JSONArray();
|
||||||
String finalValues = "";
|
|
||||||
|
|
||||||
for (Object snap : tagSnaps) {
|
for (Object snap : tagSnaps) {
|
||||||
snapJSON = (JSONObject) snap;
|
snapJSON = (JSONObject) snap;
|
||||||
String values = snapJSON.getString("value");
|
String values = snapJSON.getString("value");
|
||||||
|
String finalValues = "";
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(values)) {
|
if (StrUtil.isNotBlank(values)) {
|
||||||
String[] valueList = values.split(",");
|
String[] valueList = values.split(",");
|
||||||
for (String value : valueList) {
|
for (String value : valueList) {
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.service;
|
package com.chaozhanggui.system.cashierservice.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
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.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.chaozhanggui.system.cashierservice.dao.*;
|
import com.chaozhanggui.system.cashierservice.dao.*;
|
||||||
@@ -14,13 +17,23 @@ import com.chaozhanggui.system.cashierservice.redis.RedisUtil;
|
|||||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||||
import com.chaozhanggui.system.cashierservice.util.*;
|
import com.chaozhanggui.system.cashierservice.util.*;
|
||||||
|
import com.chaozhanggui.system.cashierservice.wxUtil.WxAccountUtil;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.core.io.Resource;
|
||||||
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -41,6 +54,20 @@ public class UserService {
|
|||||||
private TbSystemCouponsMapper systemCouponsMapper;
|
private TbSystemCouponsMapper systemCouponsMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
RedisUtils redisUtils;
|
RedisUtils redisUtils;
|
||||||
|
@Qualifier("tbShopInfoMapper")
|
||||||
|
@Autowired
|
||||||
|
private TbShopInfoMapper tbShopInfoMapper;
|
||||||
|
private final FileService fileService;
|
||||||
|
|
||||||
|
private final WxAccountUtil wxAccountUtil;
|
||||||
|
|
||||||
|
private final ResourceLoader resourceLoader;
|
||||||
|
|
||||||
|
public UserService(FileService fileService, WxAccountUtil wxAccountUtil, ResourceLoader resourceLoader) {
|
||||||
|
this.fileService = fileService;
|
||||||
|
this.wxAccountUtil = wxAccountUtil;
|
||||||
|
this.resourceLoader = resourceLoader;
|
||||||
|
}
|
||||||
|
|
||||||
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
|
public JSONObject modityIntegral(IntegralVo integralVo, String userSign) {
|
||||||
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
|
JSONObject object = (JSONObject) JSONObject.toJSON(integralVo);
|
||||||
@@ -228,4 +255,19 @@ public class UserService {
|
|||||||
int sysNum = systemCouponsMapper.selectByAmount(orderNum);
|
int sysNum = systemCouponsMapper.selectByAmount(orderNum);
|
||||||
return userNum+sysNum;
|
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();
|
||||||
|
Resource resource = resourceLoader.getResource("classpath:/static/logo.jpg");
|
||||||
|
InputStream inputStream = resource.getInputStream();
|
||||||
|
QrCodeUtil.generate(wxAccountUtil.getRadarQrCode(Integer.valueOf(shopId)), new QrConfig(500, 500).
|
||||||
|
setImg(ImageIO.read(inputStream)).setErrorCorrection(ErrorCorrectionLevel.H).setRatio(4), "png", outputStream);
|
||||||
|
|
||||||
|
|
||||||
|
return fileService.uploadFileByInputStream("png", new ByteArrayInputStream(outputStream.toByteArray()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,4 +160,6 @@ public class WechatUtil {
|
|||||||
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
package com.chaozhanggui.system.cashierservice.wxUtil;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.chaozhanggui.system.cashierservice.exception.MsgException;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Slf4j
|
||||||
|
@Component
|
||||||
|
public class WxAccountUtil {
|
||||||
|
@Value("${wx.ysk.appId}")
|
||||||
|
private static String appId = "wx212769170d2c6b2a";
|
||||||
|
@Value("${wx.ysk.secrete}")
|
||||||
|
private static String secrete = "8492a7e8d55bbb1b57f5c8276ea1add0";
|
||||||
|
@Value("${wx.ysk.warnMsgTmpId}")
|
||||||
|
private static String msgTmpId = "C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0";
|
||||||
|
|
||||||
|
static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
|
||||||
|
linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID");
|
||||||
|
linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口");
|
||||||
|
linkedHashMap.put("40037","不合法的 template_id");
|
||||||
|
linkedHashMap.put("43101","用户未订阅消息");
|
||||||
|
linkedHashMap.put("43107","订阅消息能力封禁");
|
||||||
|
linkedHashMap.put("43108","并发下发消息给同一个粉丝");
|
||||||
|
linkedHashMap.put("45168","命中敏感词");
|
||||||
|
linkedHashMap.put("47003","参数错误");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// sendStockWarnMsg("13213", "31123", "234", "ojC-S6n2DDlpj52iVMoiLL0Ry4HI");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getRadarQrCode(Integer shopId) {
|
||||||
|
HashMap<String, Object> req = new HashMap<>();
|
||||||
|
req.put("expire_seconds", 300);
|
||||||
|
req.put("action_name", "QR_STR_SCENE");
|
||||||
|
HashMap<Object, Object> actionInfo = new HashMap<>();
|
||||||
|
HashMap<String, Object> scene = new HashMap<>();
|
||||||
|
scene.put("scene_str", "msg" + shopId);
|
||||||
|
actionInfo.put("scene", scene);
|
||||||
|
req.put("action_info", actionInfo);
|
||||||
|
log.info("开始获取公众号二维码, 请求数据: {}", req);
|
||||||
|
String resp = HttpUtil.post("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + getAccessToken(), JSONObject.toJSONString(req));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
log.warn("获取微信公众号二维码结束,响应: {}", resp);
|
||||||
|
if (!respInfo.containsKey("url")) {
|
||||||
|
log.warn("获取微信公众号二维码失败,响应: {}", resp);
|
||||||
|
throw new MsgException(resp);
|
||||||
|
}
|
||||||
|
return respInfo.getString("url");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static String getAccessToken() {
|
||||||
|
String resp = HttpUtil.get(StrUtil.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={}&secret={}", appId, secrete));
|
||||||
|
JSONObject respInfo = JSONObject.parseObject(resp);
|
||||||
|
if (!respInfo.containsKey("access_token")) {
|
||||||
|
log.warn("公众号获取token失败, 响应内容: {}", resp);
|
||||||
|
throw new MsgException(resp);
|
||||||
|
}
|
||||||
|
return respInfo.getString("access_token");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject sendTemplateMsg(String templateId, String toUserOpenId, Map<String, Object> data) {
|
||||||
|
log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||||
|
String accessToken = getAccessToken();
|
||||||
|
|
||||||
|
JSONObject object1=new JSONObject();
|
||||||
|
|
||||||
|
object1.put("template_id", templateId);
|
||||||
|
object1.put("touser", toUserOpenId);
|
||||||
|
object1.put("data",data);
|
||||||
|
|
||||||
|
String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
|
||||||
|
log.info("微信模板消息发送成功,响应内容:{}",response);
|
||||||
|
JSONObject resObj=JSONObject.parseObject(response);
|
||||||
|
if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
|
||||||
|
return resObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONObject sendStockWarnMsg(String shopName, String productName, Integer stock, String toUserOpenId) {
|
||||||
|
stock = stock < 0 ? 0 : stock;
|
||||||
|
Integer finalStock = stock;
|
||||||
|
Map<String, Object> data = new HashMap<String, Object>() {{
|
||||||
|
put("thing22", new HashMap<String, Object>(){{
|
||||||
|
put("value", shopName);
|
||||||
|
}});
|
||||||
|
put("thing4", new HashMap<String, Object>(){{
|
||||||
|
put("value", productName);
|
||||||
|
}});
|
||||||
|
put("number5", new HashMap<String, Object>(){{
|
||||||
|
put("value", finalStock);
|
||||||
|
}});
|
||||||
|
}};
|
||||||
|
log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||||
|
try {
|
||||||
|
return sendTemplateMsg(msgTmpId, toUserOpenId, data);
|
||||||
|
}catch (Exception e) {
|
||||||
|
log.error("发送失败: {}", e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,12 @@ wx:
|
|||||||
appId: wxcf0fe8cdba153fd6
|
appId: wxcf0fe8cdba153fd6
|
||||||
secrete: c33e06467c6879a62af633d50ed6b720
|
secrete: c33e06467c6879a62af633d50ed6b720
|
||||||
warnMsgTmpId: IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY
|
warnMsgTmpId: IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY
|
||||||
|
|
||||||
|
ysk:
|
||||||
|
appId: wx212769170d2c6b2a
|
||||||
|
secrete: 8492a7e8d55bbb1b57f5c8276ea1add0
|
||||||
|
warnMsgTmpId: C08OUr80x6wGmUN1zpFhSQ3Sv7VF5vksdZigiEx2pD0
|
||||||
|
|
||||||
#
|
#
|
||||||
spring:
|
spring:
|
||||||
profiles:
|
profiles:
|
||||||
|
|||||||
BIN
src/main/resources/static/logo.jpg
Normal file
BIN
src/main/resources/static/logo.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 26 KiB |
BIN
src/main/resources/static/logo.png
Normal file
BIN
src/main/resources/static/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
Reference in New Issue
Block a user