Commit 2867e4ef by huluobin

Merge branch 'master' into 3.8

parents 785eb06d 15d67332
...@@ -132,7 +132,12 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order ...@@ -132,7 +132,12 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
@Override @Override
public void updateOrderManage(OrderManage param) { public void updateOrderManage(OrderManage param) {
OrderManage orderManage = orderManageMapper.selectById(param.getId()); OrderManage orderManage = orderManageMapper.selectById(param.getId());
if (!orderManage.getStatus().equals(OrderManage.STATUS_SYSTEM_UN_CHECK)) {
throw new RRException("非待核算状态不能修改订单");
}
List<OrderServe> orderServeList = orderServeMapper.selectList(new LambdaQueryWrapper<OrderServe>().eq(OrderServe::getOrderId, param.getId())); List<OrderServe> orderServeList = orderServeMapper.selectList(new LambdaQueryWrapper<OrderServe>().eq(OrderServe::getOrderId, param.getId()));
ScheduleManage scheduleManage = scheduleManageMapper.selectById(orderManage.getScheduledId()); ScheduleManage scheduleManage = scheduleManageMapper.selectById(orderManage.getScheduledId());
...@@ -408,11 +413,6 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order ...@@ -408,11 +413,6 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
if (StringUtils.isNotEmpty(param.getCustomerPhone())) { if (StringUtils.isNotEmpty(param.getCustomerPhone())) {
wrapper.like(OrderManage::getTelephone, param.getCustomerPhone()); wrapper.like(OrderManage::getTelephone, param.getCustomerPhone());
} }
if (param.getCustomerId() != null) {
wrapper.and(wrapper2 -> wrapper.eq(OrderManage::getOrderUser, param.getCustomerId())
.or(wrapper3 -> wrapper3.eq(OrderManage::getPayUser, param.getCustomerId())));
}
if (param.getDepartmentId() != null) { if (param.getDepartmentId() != null) {
wrapper.eq(OrderManage::getDepartmentId, param.getDepartmentId()); wrapper.eq(OrderManage::getDepartmentId, param.getDepartmentId());
} }
...@@ -423,7 +423,11 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order ...@@ -423,7 +423,11 @@ public class OrderManageServiceImpl extends ServiceImpl<OrderManageMapper, Order
wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_SYSTEM_UN_CHECK); wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_SYSTEM_UN_CHECK);
} }
wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_DELETED); wrapper.ne(OrderManage::getStatus, OrderManage.STATUS_DELETED);
if (param.getCustomerId() != null) {
wrapper.and(wrapper2 -> wrapper.eq(OrderManage::getOrderUser, param.getCustomerId())
.or()
.eq(OrderManage::getPayUser, param.getCustomerId()));
}
//noinspection unchecked //noinspection unchecked
wrapper.orderByDesc(OrderManage::getCreateTime); wrapper.orderByDesc(OrderManage::getCreateTime);
......
...@@ -66,6 +66,9 @@ public class PayServiceImpl implements PayService { ...@@ -66,6 +66,9 @@ public class PayServiceImpl implements PayService {
throw new RRException("订单状态异常"); throw new RRException("订单状态异常");
} }
this.checkCustomerBalance(currentCustomerId, orderId);
/*1、扣除余额*/ /*1、扣除余额*/
ConsumerCommand consumerCmd = ConsumerCommand.builder() ConsumerCommand consumerCmd = ConsumerCommand.builder()
.amount(orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue()) .amount(orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue())
...@@ -136,6 +139,22 @@ public class PayServiceImpl implements PayService { ...@@ -136,6 +139,22 @@ public class PayServiceImpl implements PayService {
} }
private void checkCustomerBalance(Integer customerId, Integer orderId) throws RRException {
OrderManage orderManage = orderManageService.getById(orderId);
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, customerId));
if (customerBalance == null) {
throw new RRException("您不是会员,请直接使用pos支付");
}
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) {
throw new RRException("请使用余额支付");
}
if (customerBalance.getBalance() <= 0) {
throw new RRException("余额为0,请直接使用pos支付");
}
}
@Override @Override
public WxPayMpOrderResult balanceWxPay(BalanceWxPayQuery qry) throws UnknownHostException, WxPayException { public WxPayMpOrderResult balanceWxPay(BalanceWxPayQuery qry) throws UnknownHostException, WxPayException {
...@@ -146,15 +165,9 @@ public class PayServiceImpl implements PayService { ...@@ -146,15 +165,9 @@ public class PayServiceImpl implements PayService {
} }
//2、余额检查 //2、余额检查
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, orderManage.getOrderUser())); this.checkCustomerBalance(qry.getCustomerId(), qry.getOrderId());
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, qry.getCustomerId()));
if (customerBalance == null) {
throw new RRException("余额不存在");
}
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) {
throw new RRException("请使用余额支付");
}
//3、微信统一下单 //3、微信统一下单
BigDecimal leftTotalPaymentAmount = orderManage.getTotalPaymentAmount().subtract(new BigDecimal(customerBalance.getBalance()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP)); BigDecimal leftTotalPaymentAmount = orderManage.getTotalPaymentAmount().subtract(new BigDecimal(customerBalance.getBalance()).divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP));
...@@ -193,12 +206,8 @@ public class PayServiceImpl implements PayService { ...@@ -193,12 +206,8 @@ public class PayServiceImpl implements PayService {
throw new RRException("订单状态异常"); throw new RRException("订单状态异常");
} }
//2、余额检查
CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, currentCustomerId)); CustomerBalance customerBalance = customerBalanceMapper.selectOne(new LambdaQueryWrapper<CustomerBalance>().eq(CustomerBalance::getCustomerId, currentCustomerId));
if (orderManage.getTotalPaymentAmount().multiply(new BigDecimal(100)).intValue() < customerBalance.getBalance()) { this.checkCustomerBalance(currentCustomerId, orderId);
throw new RRException("请使用余额支付");
}
//3、更新订单 //3、更新订单
//支付类型:请余额pos支付 //支付类型:请余额pos支付
......
...@@ -894,6 +894,10 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper, ...@@ -894,6 +894,10 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
log.info("更新预约:{}", cmd); log.info("更新预约:{}", cmd);
ScheduleManage scheduleManage = this.setScheduleServe(cmd.getScheduleManageDTO(), cmd.getDefaultNodeList()); ScheduleManage scheduleManage = this.setScheduleServe(cmd.getScheduleManageDTO(), cmd.getDefaultNodeList());
if (scheduleManage.getStatus().equals(ScheduleManage.STATUS_KEEP_SCHEDULED)) {
throw new RRException("已完成预约,不能修改");
}
if (SessionUtils.isSourceFromCustomer()) { if (SessionUtils.isSourceFromCustomer()) {
this.validSubmit(scheduleManage); this.validSubmit(scheduleManage);
} }
...@@ -905,13 +909,21 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper, ...@@ -905,13 +909,21 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
List<ScheduleServe> scheduleServeList = scheduleManage.getScheduleServeList(); List<ScheduleServe> scheduleServeList = scheduleManage.getScheduleServeList();
scheduleServeList.forEach(scheduleServe -> scheduleServe.setSchId(scheduleManage.getId())); scheduleServeList.forEach(scheduleServe -> scheduleServe.setSchId(scheduleManage.getId()));
scheduleServeList.forEach(scheduleServe -> {
if (scheduleServe.getId() != null) { List<ScheduleServe> insertScheduleServeList = scheduleServeList.stream()
scheduleServeMapper.updateById(scheduleServe); .filter(scheduleServe -> scheduleServe.getId() == null).collect(Collectors.toList());
} else { List<ScheduleServe> updateScheduleServeList = scheduleServeList.stream().filter(scheduleServe -> scheduleServe.getId() != null).collect(Collectors.toList());
scheduleServeMapper.insert(scheduleServe);
} insertScheduleServeList.forEach(scheduleServeMapper::insert);
}); updateScheduleServeList.forEach(scheduleServeMapper::updateById);
// //数据库死锁
// scheduleServeList.forEach(scheduleServe -> {
// if (scheduleServe.getId() != null) {
// scheduleServeMapper.updateById(scheduleServe);
// } else {
// scheduleServeMapper.insert(scheduleServe);
// }
// });
List<Integer> removeIds = oldScheduleServeIds.stream().filter(id -> !scheduleServeList.stream().map(ScheduleServe::getId).collect(Collectors.toList()).contains(id)).collect(Collectors.toList()); List<Integer> removeIds = oldScheduleServeIds.stream().filter(id -> !scheduleServeList.stream().map(ScheduleServe::getId).collect(Collectors.toList()).contains(id)).collect(Collectors.toList());
if (ListUtil.isNotEmpty(removeIds)) { if (ListUtil.isNotEmpty(removeIds)) {
scheduleServeMapper.deleteBatchIds(removeIds); scheduleServeMapper.deleteBatchIds(removeIds);
...@@ -919,8 +931,10 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper, ...@@ -919,8 +931,10 @@ public class ScheduleManageServiceImpl extends ServiceImpl<ScheduleManageMapper,
scheduleManage.addScheduleServeList(scheduleServeList); scheduleManage.addScheduleServeList(scheduleServeList);
this.createOrder(scheduleManage); this.createOrder(scheduleManage);
if (SessionUtils.getSourceFrom().equals("customer")) {
technicianPushService.updateScheduledMsg(scheduleManage.getId()); technicianPushService.updateScheduledMsg(scheduleManage.getId());
} }
}
@Override @Override
public void checkBeforeUpdate(UpdateScheduleCommand cmd) { public void checkBeforeUpdate(UpdateScheduleCommand cmd) {
......
...@@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.security.InvalidParameterException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -230,7 +231,16 @@ public class OrderManageController { ...@@ -230,7 +231,16 @@ public class OrderManageController {
@PostMapping("/technician/ordermanage/updateOrderManage") @PostMapping("/technician/ordermanage/updateOrderManage")
public JsonResult<Void> updateOrderManage(@RequestHeader String token, public JsonResult<Void> updateOrderManage(@RequestHeader String token,
@RequestBody OrderManage param) { @RequestBody OrderManage param) {
OrderIdLock orderIdLock = OrderIdLock.getInstance();
if (param.getId() == null) {
throw new InvalidParameterException();
}
try {
orderIdLock.lock(param.getId());
orderManageService.updateOrderManage(param); orderManageService.updateOrderManage(param);
} finally {
orderIdLock.unlock(param.getId());
}
return JsonResult.success(); return JsonResult.success();
} }
......
...@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gogirl.application.market.discount.IVipServeService; import com.gogirl.application.market.discount.IVipServeService;
import com.gogirl.application.order.serve.ScheduleManageService; import com.gogirl.application.order.serve.ScheduleManageService;
import com.gogirl.application.order.serve.ScheduleServeService;
import com.gogirl.application.user.customer.CustomerBalanceService; import com.gogirl.application.user.customer.CustomerBalanceService;
import com.gogirl.application.xcx.GogirlTokenService; import com.gogirl.application.xcx.GogirlTokenService;
import com.gogirl.assembler.PurchaseSkuDTOAssembler; import com.gogirl.assembler.PurchaseSkuDTOAssembler;
import com.gogirl.assembler.ScheduleManageDTOAssembler; import com.gogirl.assembler.ScheduleManageDTOAssembler;
import com.gogirl.domain.market.discount.VipServe; import com.gogirl.domain.market.discount.VipServe;
import com.gogirl.domain.order.serve.ScheduleManage; import com.gogirl.domain.order.serve.ScheduleManage;
import com.gogirl.domain.order.serve.ScheduleServe;
import com.gogirl.domain.product.serve.BaseProduce; import com.gogirl.domain.product.serve.BaseProduce;
import com.gogirl.domain.store.store.StoreTechnician; import com.gogirl.domain.store.store.StoreTechnician;
import com.gogirl.domain.xcx.GogirlToken; import com.gogirl.domain.xcx.GogirlToken;
...@@ -21,7 +23,6 @@ import com.gogirl.infrastructure.mapper.product.purchase.PurchaseSkuMapper; ...@@ -21,7 +23,6 @@ import com.gogirl.infrastructure.mapper.product.purchase.PurchaseSkuMapper;
import com.gogirl.infrastructure.mapper.product.serve.BaseProduceMapper; import com.gogirl.infrastructure.mapper.product.serve.BaseProduceMapper;
import com.gogirl.infrastructure.util.SessionUtils; import com.gogirl.infrastructure.util.SessionUtils;
import com.gogirl.infrastructure.util.lock.CustomerIdLock; import com.gogirl.infrastructure.util.lock.CustomerIdLock;
import com.gogirl.infrastructure.util.lock.ScheduleServeIdLock;
import com.gogirl.infrastructure.util.lock.ScheduledLock; import com.gogirl.infrastructure.util.lock.ScheduledLock;
import com.gogirl.shared.order.*; import com.gogirl.shared.order.*;
import com.gogirl.shared.product.LeisureScheduleServeQuery; import com.gogirl.shared.product.LeisureScheduleServeQuery;
...@@ -36,6 +37,7 @@ import lombok.AllArgsConstructor; ...@@ -36,6 +37,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.security.InvalidParameterException;
import java.text.ParseException; import java.text.ParseException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -49,6 +51,7 @@ import java.util.stream.Collectors; ...@@ -49,6 +51,7 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class ScheduleManageController { public class ScheduleManageController {
private final ScheduleServeService scheduleServeService;
private final ScheduleManageService scheduleManageService; private final ScheduleManageService scheduleManageService;
private final GogirlTokenService gogirlTokenService; private final GogirlTokenService gogirlTokenService;
private final CustomerBalanceService customerBalanceService; private final CustomerBalanceService customerBalanceService;
...@@ -211,8 +214,22 @@ public class ScheduleManageController { ...@@ -211,8 +214,22 @@ public class ScheduleManageController {
@ApiOperation("更新预约") @ApiOperation("更新预约")
@PostMapping("/technician/schedule/updateSchedule") @PostMapping("/technician/schedule/updateSchedule")
public JsonResult<Void> updateSchedule(@RequestBody SubmitScheduleCommand cmd) throws ParseException, ExecutionException, InterruptedException { public JsonResult<Void> updateSchedule(@RequestBody SubmitScheduleCommand cmd) throws ParseException, ExecutionException, InterruptedException {
ScheduledLock scheduledLock = ScheduledLock.getInstance();
try {
log.info("店员更新预约:{}", cmd);
if (cmd.getScheduleManageDTO().getId() == null) {
throw new InvalidParameterException();
}
scheduledLock.lock(cmd.getScheduleManageDTO().getId());
cmd.getScheduleManageDTO().setDepartmentId(SessionUtils.getTechnicianToken().getDepartmentId()); cmd.getScheduleManageDTO().setDepartmentId(SessionUtils.getTechnicianToken().getDepartmentId());
scheduleManageService.updateSchedule(cmd); scheduleManageService.updateSchedule(cmd);
} finally {
scheduledLock.unlock(cmd.getScheduleManageDTO().getId());
}
return JsonResult.success(); return JsonResult.success();
} }
...@@ -231,12 +248,17 @@ public class ScheduleManageController { ...@@ -231,12 +248,17 @@ public class ScheduleManageController {
@RequestParam Integer scheduleServeId, @RequestParam Integer scheduleServeId,
@RequestParam Integer status, @RequestParam Integer status,
@RequestParam Integer forceLeisureConfig) { @RequestParam Integer forceLeisureConfig) {
ScheduleServeIdLock lock = ScheduleServeIdLock.getInstance(); ScheduleServe scheduleServe = scheduleServeService.getById(scheduleServeId);
if (scheduleServe.getSchId() == null) {
throw new InvalidParameterException();
}
int scheduleId = scheduleServe.getSchId();
ScheduledLock lock = ScheduledLock.getInstance();
try { try {
lock.lock(scheduleServeId); lock.lock(scheduleId);
scheduleManageService.updateScheduledServeStatus(scheduleServeId, status, forceLeisureConfig); scheduleManageService.updateScheduledServeStatus(scheduleServeId, status, forceLeisureConfig);
} finally { } finally {
lock.unlock(scheduleServeId); lock.unlock(scheduleId);
} }
return JsonResult.success(); return JsonResult.success();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment