Commit dbe80723 by caiyt

修复优惠券支付未同步机器问题

parent d0b07205
......@@ -8,15 +8,18 @@ import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.common.enums.MachineState;
import com.soss.common.exception.ServiceException;
import com.soss.framework.web.service.TokenService;
import com.soss.framework.web.service.WeixinServiceImpl;
import com.soss.system.constants.OrderStatusConstant;
import com.soss.system.domain.Machine;
import com.soss.system.domain.Order;
import com.soss.system.domain.vo.CouponVo;
import com.soss.system.domain.vo.OrderQuery;
import com.soss.system.service.ICouponUserService;
import com.soss.system.service.IGoodsService;
import com.soss.system.service.IMachineService;
import com.soss.system.service.impl.OrderServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -28,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
......@@ -45,6 +49,8 @@ public class OrderController extends BaseController {
@Autowired
private OrderServiceImpl orderService;
@Autowired
private IMachineService machineService;
@Autowired
private TokenService tokenService;
@Autowired
private WeixinServiceImpl weixinService;
......@@ -124,6 +130,22 @@ public class OrderController extends BaseController {
return AjaxResult.error(e.getMessage());
}
if (StringUtils.isEmpty(order.getMachineId())) {
Machine machine = new Machine();
machine.setShopId(order.getShopId());
List<Machine> machines = machineService.selectMachineList(machine);
if (machines != null && !machines.isEmpty()) {
Machine machine1 = machines.get(0);
if (!MachineState.RUNNING.getState().equals(machine1.getState())) {
return AjaxResult.error("机器暂时不可用");
}
String machineId = machine1.getId();
order.setMachineId(machineId);
} else {
return AjaxResult.error("该店铺暂无绑定机器");
}
}
Integer couponUserId = order.getCouponId();
if (couponUserId != null) {
List<CouponVo> couponVos = couponUserService.listCustAvailableCoupon(loginUser.getOpenId(), couponUserId);
......@@ -143,17 +165,17 @@ public class OrderController extends BaseController {
couponUserService.orderDetailCheckAndAssign(order.getOrderDetails());
}
int amount = order.getPaidAmount().movePointRight(2).intValue();
if (amount == 0) {
order.setPickCode(weixinService.generatePickCode(order));
}
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order, couponUserId);
if (HttpStatus.SUCCESS != (int) ajaxResult.get(AjaxResult.CODE_TAG)) {
return ajaxResult;
}
int amount = order.getPaidAmount().movePointRight(2).intValue();
if (amount == 0) {
order.setPickCode(weixinService.generatePickCode(order));
order.setPayTime(new Date());
order.setState(OrderStatusConstant.Paid);
orderService.updateOrder(order);
return AjaxResult.success(order.getId());
}
......
......@@ -192,7 +192,7 @@ public class CouponController extends BaseController {
/**
* 获取当前有效的规则集合
*/
@PreAuthorize("@ss.hasPermi('coupon:list:effective')")
// @PreAuthorize("@ss.hasPermi('coupon:list:effective')")
@GetMapping("/list/effective")
@ApiOperation("获取当前有效的规则集合")
public TableDataInfo listEffective() {
......
......@@ -416,10 +416,10 @@ public class WeixinServiceImpl {
//处理重复的通知
//接口调用的幂等性:无论接口被调用多少次,产生的结果是一致的。
String orderStatus =order.getState();
if ("1".equals(orderStatus)) {
if (OrderStatusConstant.Unpaid.equals(orderStatus)) {
//更新订单状态
order.setPayTime(new Date());
order.setState("2");
order.setState(OrderStatusConstant.Paid);
order.setPickCode(generatePickCode(order));
orderService.updateOrder(order);
}
......
......@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.domain.model.LoginUser;
import com.soss.common.enums.CouponUserState;
import com.soss.common.enums.MachineState;
import com.soss.common.exception.ServiceException;
import com.soss.common.utils.DateUtils;
import com.soss.common.utils.StringUtils;
......@@ -142,11 +141,7 @@ public class OrderServiceImpl implements IOrderService {
@Override
@Transactional
public AjaxResult insertOrder(LoginUser loginUser, Order order, Integer couponUserId) {
if (order.getPaidAmount().compareTo(BigDecimal.ZERO) == 0) {
order.setState(OrderStatusConstant.Paid);
} else {
order.setState(OrderStatusConstant.Unpaid);
}
order.setState(OrderStatusConstant.Unpaid);
order.setUserId(loginUser.getOpenId());
order.setUserName(loginUser.getUsername());
order.setUserPhone(loginUser.getUser().getPhonenumber());
......@@ -154,32 +149,32 @@ public class OrderServiceImpl implements IOrderService {
order.setOrderNum(getOrderNum(order.getShopId()));
order.setOrderNo(getOrderNo(order.getSource()));
order.setUpdatedAt(new Date());
String machineId = null;
if (StringUtils.isEmpty(order.getMachineId())) {
Machine machine = new Machine();
machine.setShopId(order.getShopId());
List<Machine> machines = machineMapper.selectMachineList(machine);
if (machines != null && !machines.isEmpty()) {
Machine machine1 = machines.get(0);
if (!MachineState.RUNNING.getState().equals(machine1.getState())) {
return AjaxResult.error("机器暂时不可用");
}
machineId = machine1.getId();
order.setMachineId(machineId);
} else {
return AjaxResult.error("该店铺暂无绑定机器");
}
orderMapper.insertOrder(order);
this.orderDetailSplit(order);
orderDetailMapper.insertBatch(order.getOrderDetails());
// 更新用户的优惠券状态
if (couponUserId != null) {
CouponUser couponUser = new CouponUser(couponUserId, order.getId(), order.getOrderNo(), CouponUserState.USED.getState());
couponUserMapper.updateCouponUser(couponUser);
}
orderMapper.insertOrder(order);
orderOperationLogService.insertOrderOperationLog(order);
orderSnapshotService.saveOrderSnapshot(order);
//发送数据给机器
machineApiService.createOrder(order);
return AjaxResult.success(order.getOrderNo());
}
private void orderDetailSplit(Order order) {
List<OrderDetail> orderDetails = order.getOrderDetails();
List<OrderDetail> detailsSave = new LinkedList<>();
for (OrderDetail orderDetail : orderDetails) {
orderDetail.setOrderId(order.getId());
orderDetail.setCreatedAt(new Date());
orderDetail.setUpdatedAt(new Date());
orderDetail.setMachineId(machineId);
orderDetail.setMachineId(order.getMachineId());
BigDecimal amountShould = orderDetail.getAmountShould();
BigDecimal couponAmount = orderDetail.getCouponAmount();
......@@ -210,20 +205,6 @@ public class OrderServiceImpl implements IOrderService {
}
}
order.setOrderDetails(detailsSave);
orderDetailMapper.insertBatch(detailsSave);
// 更新用户的优惠券状态
if (couponUserId != null) {
CouponUser couponUser = new CouponUser(couponUserId, order.getId(), order.getOrderNo(), CouponUserState.USED.getState());
couponUserMapper.updateCouponUser(couponUser);
}
// }
//发送数据给机器
machineApiService.createOrder(order);
orderOperationLogService.insertOrderOperationLog(order);
orderSnapshotService.saveOrderSnapshot(order);
return AjaxResult.success(order.getOrderNo());
}
@Override
......
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