|
@@ -1,13 +1,18 @@
|
|
|
package com.ruoyi.app.mendian;
|
|
package com.ruoyi.app.mendian;
|
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
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.ruoyi.app.order.dto.OrderCreatItem;
|
|
|
|
|
+import com.ruoyi.app.order.dto.OrderCreateInput;
|
|
|
|
|
+import com.ruoyi.app.order.dto.OrderPushBodyDto;
|
|
|
import com.ruoyi.app.utils.DateUtil;
|
|
import com.ruoyi.app.utils.DateUtil;
|
|
|
import com.ruoyi.app.utils.ImageCompressUtils;
|
|
import com.ruoyi.app.utils.ImageCompressUtils;
|
|
|
import com.ruoyi.app.user.dto.StoreOutput;
|
|
import com.ruoyi.app.user.dto.StoreOutput;
|
|
|
|
|
+import com.ruoyi.app.utils.PayPush;
|
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
import com.ruoyi.common.annotation.Anonymous;
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
import com.ruoyi.common.core.controller.BaseController;
|
|
@@ -18,6 +23,7 @@ import com.ruoyi.common.exception.ServiceException;
|
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
|
|
+import com.ruoyi.framework.manager.AsyncManager;
|
|
|
import com.ruoyi.system.domain.*;
|
|
import com.ruoyi.system.domain.*;
|
|
|
import com.ruoyi.system.domain.vo.StoreOperatOutput;
|
|
import com.ruoyi.system.domain.vo.StoreOperatOutput;
|
|
|
import com.ruoyi.system.mapper.PosStoreMapper;
|
|
import com.ruoyi.system.mapper.PosStoreMapper;
|
|
@@ -34,10 +40,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Arrays;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
@@ -68,6 +71,118 @@ public class PosStoreController extends BaseController {
|
|
|
private PosStoreEnrichService posStoreEnrichService;
|
|
private PosStoreEnrichService posStoreEnrichService;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private SysConfigMapper sysConfigMapper;
|
|
private SysConfigMapper sysConfigMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IOrderParentService orderParentService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IPosOrderService posOrderService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商家端下单
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/createOrder")
|
|
|
|
|
+ @Auth
|
|
|
|
|
+ @Anonymous
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public AjaxResult createOrder(@RequestHeader String token, @RequestBody OrderCreateInput input)
|
|
|
|
|
+ {
|
|
|
|
|
+ JwtUtil jwtUtil = new JwtUtil();
|
|
|
|
|
+ String id = jwtUtil.getusid(token);
|
|
|
|
|
+ String shdz=null;
|
|
|
|
|
+ createOrderParent(input,Long.valueOf(id),shdz);
|
|
|
|
|
+ createOrderChild(input,Long.valueOf(id),Long.valueOf(id),shdz);
|
|
|
|
|
+
|
|
|
|
|
+ OrderParent result = orderParentService.getOne(new LambdaQueryWrapper<OrderParent>().eq(OrderParent::getDdId, input.getDdId().toString()));
|
|
|
|
|
+ System.out.println("创建返回信息:"+result);
|
|
|
|
|
+ return super.success(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //创建父订单
|
|
|
|
|
+ private void createOrderParent(OrderCreateInput input,Long UserId,String shdz){
|
|
|
|
|
+ OrderParent orderParent = new OrderParent();
|
|
|
|
|
+ orderParent.setUserId(UserId);
|
|
|
|
|
+ orderParent.setOrderStatus(0L);
|
|
|
|
|
+ orderParent.setTotalAmount(input.getTotalAmount());
|
|
|
|
|
+ orderParent.setActualPayAmount(input.getActualPayAmount());
|
|
|
|
|
+ orderParent.setPaymentMethod(input.getPaymentMethod());
|
|
|
|
|
+// orderParent.setPaymentTime(new Date());
|
|
|
|
|
+ orderParent.setCreateTime(new Date());
|
|
|
|
|
+// orderParent.setUpdateTime(new Date());
|
|
|
|
|
+ orderParent.setDdId(input.getDdId().toString());
|
|
|
|
|
+ orderParent.setTableId(input.getTableId());
|
|
|
|
|
+ orderParent.setShdzId(input.getShdzId());
|
|
|
|
|
+ orderParent.setShAddress(shdz);
|
|
|
|
|
+ orderParent.setType(input.getType());
|
|
|
|
|
+ orderParent.setRemarks(input.getRemarks());
|
|
|
|
|
+ orderParentService.save(orderParent);
|
|
|
|
|
+ }
|
|
|
|
|
+ //创建子订单
|
|
|
|
|
+ private void createOrderChild(OrderCreateInput input,Long orderParentId,Long userId,String shdz){
|
|
|
|
|
+ // 检查items是否为空
|
|
|
|
|
+ if (input.getItems() == null || input.getItems().isEmpty()) {
|
|
|
|
|
+ throw new ServiceException(MessageUtils.message("订单商品不能为空"));
|
|
|
|
|
+ }
|
|
|
|
|
+ String ddId = input.getDdId().toString();
|
|
|
|
|
+ List<Long> mdIdList = input.getItems().stream().map(OrderCreatItem::getMdId).collect(Collectors.toList());
|
|
|
|
|
+ // 将Long类型的门店ID转换为Integer类型用于查询(因为PosStore.getId()返回Integer)
|
|
|
|
|
+ List<Integer> mdIdIntegerList = mdIdList.stream().map(Long::intValue).collect(Collectors.toList());
|
|
|
|
|
+ List<PosStore> storeList = posStoreService.list(new LambdaQueryWrapper<PosStore>().in(PosStore::getId, mdIdIntegerList));
|
|
|
|
|
+ LambdaQueryWrapper<OperatingHours> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.in(OperatingHours::getMdId, mdIdList);
|
|
|
|
|
+ List<OperatingHours> hourslist = operatingHoursService.list(wrapper);
|
|
|
|
|
+ boolean isMultiStore = input.getItems().size() > 1;
|
|
|
|
|
+ // 循环items,为每个item创建一条PosOrder
|
|
|
|
|
+ int index = 0;
|
|
|
|
|
+ for (OrderCreatItem item : input.getItems()) {
|
|
|
|
|
+ index++;
|
|
|
|
|
+ // 单店铺:子订单号与父订单一致;多店铺:子订单号追加序号
|
|
|
|
|
+ String subddId = isMultiStore ? ddId + String.format("%03d", index) : ddId;
|
|
|
|
|
+ PosOrder posOrder = new PosOrder();
|
|
|
|
|
+ posOrder.setIsDisplay(true);
|
|
|
|
|
+ posOrder.setDisplayTime(new Date());
|
|
|
|
|
+ posOrder.setShdzId(input.getShdzId());
|
|
|
|
|
+ // 设置子订单的基本信息
|
|
|
|
|
+ posOrder.setDdId(subddId);
|
|
|
|
|
+ posOrder.setParentDdId(input.getDdId().toString()); // 设置父订单ID
|
|
|
|
|
+ posOrder.setCretim(new Date());
|
|
|
|
|
+ posOrder.setState(2L); // 初始状态
|
|
|
|
|
+ // 根据item设置订单信息
|
|
|
|
|
+ posOrder.setShId(item.getShId());
|
|
|
|
|
+ posOrder.setMdId(item.getMdId());
|
|
|
|
|
+ posOrder.setShdzId(input.getShdzId());
|
|
|
|
|
+ posOrder.setUserId(userId);
|
|
|
|
|
+ posOrder.setAmount(item.getAmount());
|
|
|
|
|
+ posOrder.setRemarks(item.getRemarks());
|
|
|
|
|
+ posOrder.setType(item.getType());
|
|
|
|
|
+ posOrder.setDelryTime(item.getDelryTime());
|
|
|
|
|
+ posOrder.setFood(JSON.toJSONString(item.getFood()));
|
|
|
|
|
+ // 设置支付相关信息(从父订单继承)
|
|
|
|
|
+ posOrder.setPayType(input.getPaymentMethod());
|
|
|
|
|
+ //设置桌号(从父订单继承)
|
|
|
|
|
+ posOrder.setTableId(input.getTableId());
|
|
|
|
|
+ posOrder.setLogo(item.getLogo());
|
|
|
|
|
+ posOrder.setPosName(item.getPosName());
|
|
|
|
|
+ posOrder.setJvli(item.getJvli());
|
|
|
|
|
+ posOrder.setFreight(item.getFreight());
|
|
|
|
|
+ posOrder.setShdzId(input.getShdzId());
|
|
|
|
|
+ posOrder.setShAddress(shdz);
|
|
|
|
|
+ posOrder.setFoodAmount(item.getFoodAmount());
|
|
|
|
|
+ Optional<PosStore> storeOptional = storeList.stream()
|
|
|
|
|
+ .filter(x -> item.getMdId().equals(Long.valueOf(x.getId())))
|
|
|
|
|
+ .findFirst();
|
|
|
|
|
+ if (storeOptional.isEmpty()) {
|
|
|
|
|
+ throw new ServiceException(MessageUtils.message("no.mendian.not.exist"));
|
|
|
|
|
+ }
|
|
|
|
|
+ PosStore store = storeOptional.get();
|
|
|
|
|
+ posOrder.setLongitude(store.getLongitude());
|
|
|
|
|
+ posOrder.setLatitude(store.getLatitude());
|
|
|
|
|
+ //设置订单分类
|
|
|
|
|
+ storeList.stream().filter(s -> Long.valueOf(s.getId()).equals(item.getMdId())).findFirst().ifPresent(st -> {
|
|
|
|
|
+ posOrder.setOrderCategory(String.valueOf(st.getType()));
|
|
|
|
|
+ });
|
|
|
|
|
+ posOrderService.save(posOrder);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|