离线核销
This commit is contained in:
@ -159,4 +159,12 @@ public class AppStoreOrderController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/complete")
|
||||
@Operation(summary = "离线核销")
|
||||
public CommonResult<Boolean> complete(@RequestBody List<Integer> orderIds) {
|
||||
storeOrderService.completeList(orderIds);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
@ -41,5 +41,9 @@ public interface DeductionService {
|
||||
*/
|
||||
void deduct(Long userId, BigDecimal money,String type,Long storeId);
|
||||
|
||||
/**
|
||||
* 超市离线扣款
|
||||
*/
|
||||
void storeOfflineDeduction(BigDecimal total, Long userId,Long storeId);
|
||||
|
||||
}
|
||||
|
@ -521,5 +521,64 @@ public class DeductionServiceImpl implements DeductionService {
|
||||
updateRedis(userId, name, wxNewMoney);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeOfflineDeduction(BigDecimal total, Long userId, Long storeId) {
|
||||
BigDecimal wxNewMoney;
|
||||
BigDecimal giftNewMoney;
|
||||
BigDecimal cashNewMoney;
|
||||
String name;
|
||||
synchronized (getUserLock(userId)) {
|
||||
MemberUserDO user = userService.getUser(userId);
|
||||
MoneyDO moneyDO = moneyService.getMoney(userId, storeId);
|
||||
|
||||
BigDecimal wxAmount = user.getWxAmount();
|
||||
BigDecimal giftAmount = user.getGiftAmount();
|
||||
BigDecimal cashAmount = moneyDO.getCashAmount();
|
||||
|
||||
//计算金额
|
||||
if (total.compareTo(cashAmount) <= 0) {
|
||||
moneyDO.setCashAmount(cashAmount.subtract(total));
|
||||
} else {
|
||||
moneyDO.setCashAmount(BigDecimal.ZERO);
|
||||
BigDecimal total1 = total.subtract(cashAmount);
|
||||
if (total1.compareTo(giftAmount) <= 0) {
|
||||
user.setGiftAmount(giftAmount.subtract(total1));
|
||||
} else {
|
||||
user.setGiftAmount(BigDecimal.ZERO);
|
||||
BigDecimal total2 = total1.subtract(giftAmount);
|
||||
|
||||
if(total2.compareTo(wxAmount) <= 0) {
|
||||
user.setWxAmount(wxAmount.subtract(total2));
|
||||
}else {
|
||||
user.setWxAmount(BigDecimal.ZERO);
|
||||
moneyDO.setDebtAmount(wxAmount.subtract(total2).add(moneyDO.getDebtAmount()));
|
||||
}
|
||||
}
|
||||
}
|
||||
userService.updateById(user);
|
||||
moneyService.updateById(moneyDO);
|
||||
|
||||
wxNewMoney = user.getWxAmount();
|
||||
giftNewMoney = user.getGiftAmount();
|
||||
cashNewMoney = moneyDO.getCashAmount();
|
||||
name = user.getNickname();
|
||||
}
|
||||
|
||||
CardDO cardDO = new CardDO();
|
||||
cardDO.setUserId(userId);
|
||||
cardDO.setChangeMoney(total);
|
||||
cardDO.setFlag(CardDO.MINUS);
|
||||
cardDO.setType(CostTypeEnum.SHOPPING.getCode());
|
||||
cardDO.setWxAmount(wxNewMoney);
|
||||
cardDO.setCashAmount(cashNewMoney);
|
||||
cardDO.setGiftAmount(giftNewMoney);
|
||||
cardDO.setCarteenId(storeId);
|
||||
cardService.insertOne(cardDO);
|
||||
|
||||
|
||||
//更新redis
|
||||
updateRedis(userId, name, wxNewMoney);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -96,4 +96,6 @@ public interface StoreOrderService {
|
||||
List<StoreOrderDO> selectPayOrder();
|
||||
|
||||
AddReqVO refundAdmin(Integer orderId);
|
||||
|
||||
void completeList(List<Integer> orderIds);
|
||||
}
|
@ -651,6 +651,33 @@ public class StoreOrderServiceImpl implements StoreOrderService {
|
||||
return addReqVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completeList(List<Integer> orderIds) {
|
||||
for (Integer orderId : orderIds){
|
||||
StoreOrderDO storeOrderDO = storeOrderMapper.selectById(orderId);
|
||||
if(ObjectUtil.isEmpty(storeOrderDO)){
|
||||
continue;
|
||||
}
|
||||
if(storeOrderDO.getStatus().equals(StoreOrderStatusEnum.PAY.getCode())){
|
||||
storeOrderDO.setStatus(StoreOrderStatusEnum.COMPLETE.getCode());
|
||||
storeOrderMapper.updateById(storeOrderDO);
|
||||
}else {
|
||||
//扣款
|
||||
deductionService.storeDeduction(BigDecimal.valueOf(storeOrderDO.getTotalPrice()), storeOrderDO.getUserId(),storeOrderDO.getCarteenId());
|
||||
//营业数据
|
||||
StatisticsVo statisticsVo = new StatisticsVo();
|
||||
statisticsVo.setCarteenId(storeOrderDO.getCarteenId());
|
||||
statisticsVo.setTotalMoney(BigDecimal.valueOf(storeOrderDO.getTotalPrice()));
|
||||
statisticsVo.setOrderSum(1);
|
||||
statisticsVo.setTime(storeOrderDO.getCreateTime());
|
||||
statisticsVo.setOrderId(storeOrderDO.getOrderId().longValue());
|
||||
storeBusinessService.updateStatistics(statisticsVo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void test() {
|
||||
//计算金额
|
||||
//if (total.compareTo(wxAmount) <= 0) {
|
||||
|
Reference in New Issue
Block a user