订单15分钟到期 状态监听 库存回滚
商品排序值 初始化 出入库 日志记录 酒品管理 购物车次日清空
This commit is contained in:
@@ -1,39 +1,37 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.service.impl.order;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoDto;
|
||||
import cn.ysk.cashier.dto.order.TbOrderInfoQueryCriteria;
|
||||
import cn.ysk.cashier.dto.order.TbPayCountQueryCriteria;
|
||||
import cn.ysk.cashier.mapper.order.TbOrderInfoMapper;
|
||||
import cn.ysk.cashier.mybatis.entity.TbOrderPayment;
|
||||
import cn.ysk.cashier.mybatis.service.TbOrderPaymentService;
|
||||
import cn.ysk.cashier.pojo.TbShopPayType;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderDetail;
|
||||
import cn.ysk.cashier.pojo.order.TbOrderInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantThirdApply;
|
||||
import cn.ysk.cashier.repository.TbShopPayTypeRepository;
|
||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderDetailRepository;
|
||||
import cn.ysk.cashier.repository.order.TbOrderInfoRepository;
|
||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbMerchantThirdApplyRepository;
|
||||
import cn.ysk.cashier.service.order.TbOrderInfoService;
|
||||
import cn.ysk.cashier.thirdpay.resp.OrderStatusQueryResp;
|
||||
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
||||
import cn.ysk.cashier.thirdpay.service.ThirdPayService;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import cn.ysk.cashier.vo.TbOrderInfoVo;
|
||||
import cn.ysk.cashier.vo.TbOrderPayCountVo;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -62,6 +60,15 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
|
||||
private final TbOrderDetailRepository tbOrderDetailRepository;
|
||||
private final TbShopPayTypeRepository payTypeRepository;
|
||||
private final TbProductSkuRepository skuRepository;
|
||||
private final TbOrderPaymentService paymentService;
|
||||
private final TbMerchantThirdApplyRepository thirdApplyRepository;
|
||||
private final RedisUtils redisUtils;
|
||||
private final ThirdPayService thirdPayService;
|
||||
private final TbCashierCartRepository cartRepository;
|
||||
|
||||
@Value("${thirdPay.url}")
|
||||
private String url;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> queryAllPage(TbOrderInfoQueryCriteria criteria) {
|
||||
@@ -214,6 +221,87 @@ public class TbOrderInfoServiceImpl implements TbOrderInfoService {
|
||||
return tbOrderInfoMapper.toDto(tbOrderInfoRepository.save(resources));
|
||||
}
|
||||
|
||||
@Async
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void expired(String orderId) {
|
||||
Optional<TbOrderInfo> byId = tbOrderInfoRepository.findById(Integer.valueOf(orderId));
|
||||
if (byId != null && byId.isPresent()) {
|
||||
TbOrderInfo tbOrderInfo = byId.get();
|
||||
if (tbOrderInfo.getStatus().equals("unpaid")) {
|
||||
upOrderStatus(tbOrderInfo);
|
||||
} else if (tbOrderInfo.getStatus().equals("paying") &&
|
||||
(StringUtils.isBlank(tbOrderInfo.getPayType()) ||
|
||||
!tbOrderInfo.getPayType().equals("deposit"))) {
|
||||
QueryWrapper<TbOrderPayment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_id", tbOrderInfo.getId());
|
||||
TbOrderPayment payment = paymentService.getOne(queryWrapper);
|
||||
if (payment != null && StringUtils.isNotBlank(payment.getTradeNumber())) {
|
||||
if (System.currentTimeMillis() - payment.getCreatedAt() < 60 * 2 * 1000L) {
|
||||
modfiyOrderInfo(tbOrderInfo);
|
||||
redisUtils.set(CacheKey.ORDER_EXPIRED + tbOrderInfo.getId(), tbOrderInfo.getId(), 60 * 2);
|
||||
} else {
|
||||
upOrderStatus(tbOrderInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void modfiyOrderInfo(TbOrderInfo tbOrderInfo) {
|
||||
QueryWrapper<TbOrderPayment> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("order_id", tbOrderInfo.getId());
|
||||
TbOrderPayment payment = paymentService.getOne(queryWrapper);
|
||||
if (ObjectUtil.isNotEmpty(payment) && ObjectUtil.isNotEmpty(payment.getTradeNumber())) {
|
||||
TbMerchantThirdApply thirdApply = thirdApplyRepository.getById(Integer.valueOf(tbOrderInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
//支付通道不存在
|
||||
}
|
||||
PublicResp<OrderStatusQueryResp> publicResp = thirdPayService.queryOrder(url, thirdApply.getAppId(), payment.getTradeNumber(), null, thirdApply.getAppToken());
|
||||
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
|
||||
if ("000000".equals(publicResp.getCode())) {
|
||||
String cartStatus = "";
|
||||
switch (publicResp.getObjData().getState()) {
|
||||
case "TRADE_SUCCESS":
|
||||
//修改数据库中购物车数据
|
||||
cartRepository.updateToFinal(tbOrderInfo.getId());
|
||||
//更新子单状态
|
||||
tbOrderDetailRepository.updateToClosed(tbOrderInfo.getId());
|
||||
//修改主单状态
|
||||
tbOrderInfo.setStatus("closed");
|
||||
tbOrderInfo.setPayType("wx_lite");
|
||||
tbOrderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfo.setPayAmount(tbOrderInfo.getOrderAmount());
|
||||
tbOrderInfoRepository.save(tbOrderInfo);
|
||||
// JSONObject jsonObject = new JSONObject();
|
||||
// jsonObject.put("token", 0);
|
||||
// jsonObject.put("type", "wxcreate");
|
||||
// jsonObject.put("orderId", orderInfo.getId().toString());
|
||||
// producer.putOrderCollect(jsonObject.toJSONString());
|
||||
// log.info("发送打印数据");
|
||||
// producer.printMechine(orderInfo.getId() + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void upOrderStatus(TbOrderInfo tbOrderInfo) {
|
||||
tbOrderInfo.setStatus("cancelled");
|
||||
List<TbOrderDetail> details = tbOrderDetailRepository.searchDetailByOrderId(tbOrderInfo.getId());
|
||||
Set<String> keys = new HashSet<>();
|
||||
for (TbOrderDetail detail : details) {
|
||||
detail.setStatus("cancelled");
|
||||
skuRepository.updateStockNumber(detail.getId(), new Double(detail.getNum()));
|
||||
tbOrderDetailRepository.save(detail);
|
||||
keys.add(CacheKey.PRODUCT_SKU + detail.getShopId() + ":" + detail.getId());
|
||||
}
|
||||
String[] keysArray = keys.toArray(new String[keys.size()]);
|
||||
redisUtils.del(keysArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(TbOrderInfo resources) {
|
||||
|
||||
@@ -341,7 +341,7 @@ public class TbProductServiceImpl implements TbProductService {
|
||||
throw new BadRequestException("添加商品失败");
|
||||
}
|
||||
save.setSort(save.getId());
|
||||
tbProductRepository.save(product);
|
||||
tbProductRepository.save(save);
|
||||
//sku
|
||||
if (resources.getSkuList() != null) {
|
||||
List<TbProductSku> skuList = new ArrayList<>();
|
||||
|
||||
@@ -244,13 +244,11 @@ public class TbProductStockOperateServiceImpl implements TbProductStockOperateSe
|
||||
productStockDetail.setUnitName(productListDto.getUnitName());
|
||||
entityManager.persist(productStockDetail);
|
||||
//sku数量
|
||||
TbProductSku sku = new TbProductSku();
|
||||
sku.setId(productListDto.getId());
|
||||
sku.setStockNumber(tbProductSku.getStockNumber()+productStockDetail.getStockNumber());
|
||||
productSkuService.update(sku);
|
||||
tbProductSku.setStockNumber(tbProductSku.getStockNumber()+productStockDetail.getStockNumber());
|
||||
productSkuService.update(tbProductSku);
|
||||
idStockMap.put(productListDto.getId(),productStockDetail.getStockNumber());
|
||||
}
|
||||
redisUtils.redisUp(1,resources.getShopId(),idStockMap);
|
||||
redisUtils.redisUp(2,resources.getShopId(),idStockMap);
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
|
||||
}
|
||||
tbShopInfo.setExpireAt(DateUtil.addMonthsAndGetTimestamp(tbMerchantRegister.getPeriodYear()));
|
||||
//向redis中存入key
|
||||
redisUtils.set(CacheKey.ACT_CODE+resources.getAccount(),tbShopInfo.getExpireAt()-Instant.now().toEpochMilli());
|
||||
redisUtils.set(CacheKey.ACT_CODE+resources.getAccount(),"1",tbShopInfo.getExpireAt()-Instant.now().toEpochMilli());
|
||||
}
|
||||
//增加商户详情
|
||||
TbShopInfo save = tbShopInfoRepository.save(tbShopInfo);
|
||||
|
||||
@@ -122,6 +122,13 @@ public class TbShopStorageServiceImpl implements TbShopStorageService {
|
||||
tbShopStorageRepository.save(tbShopStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void expStorage() {
|
||||
tbShopStorageRepository.expStorage();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteAll(Integer[] ids) {
|
||||
for (Integer id : ids) {
|
||||
|
||||
@@ -84,8 +84,10 @@ public class TbShopTableServiceImpl implements TbShopTableService {
|
||||
date.setQrcode(QRCODE+date.getQrcode().trim());
|
||||
}
|
||||
}
|
||||
int i = tbShopTableRepository.countAllByShopId(criteria.getShopId());
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("content",tbShopTableList);
|
||||
map.put("total",i);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ public interface TbOrderInfoService {
|
||||
*/
|
||||
TbOrderInfoDto create(TbOrderInfo resources);
|
||||
|
||||
void expired(String orderId);
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources /
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package cn.ysk.cashier.service.shop;
|
||||
|
||||
import cn.ysk.cashier.dto.shop.TbCountStorageDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopStorageDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopStorageNumDto;
|
||||
import cn.ysk.cashier.dto.shop.TbShopStorageQueryCriteria;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopStorage;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
@@ -54,6 +54,8 @@ public interface TbShopStorageService {
|
||||
*/
|
||||
void update(TbShopStorage resources);
|
||||
|
||||
void expStorage();
|
||||
|
||||
void updateNum(TbShopStorageNumDto resources);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user