|
@@ -1,23 +1,38 @@
|
|
|
package com.ylx.order.service.impl;
|
|
package com.ylx.order.service.impl;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.core.domain.R;
|
|
import com.ylx.common.core.domain.R;
|
|
|
|
|
+import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
|
|
+import com.ylx.common.exception.ServiceException;
|
|
|
|
|
+import com.ylx.common.utils.DateUtils;
|
|
|
|
|
+import com.ylx.common.utils.SecurityUtils;
|
|
|
|
|
+import com.ylx.massage.domain.MaTechnician;
|
|
|
|
|
+import com.ylx.massage.domain.TAddress;
|
|
|
import com.ylx.massage.domain.TWxUser;
|
|
import com.ylx.massage.domain.TWxUser;
|
|
|
import com.ylx.massage.domain.vo.HomeBlock;
|
|
import com.ylx.massage.domain.vo.HomeBlock;
|
|
|
import com.ylx.massage.domain.vo.OrderVerificationVo;
|
|
import com.ylx.massage.domain.vo.OrderVerificationVo;
|
|
|
import com.ylx.massage.domain.vo.TechnicianAvailabilityVo;
|
|
import com.ylx.massage.domain.vo.TechnicianAvailabilityVo;
|
|
|
|
|
+import com.ylx.massage.service.IMaTechnicianService;
|
|
|
|
|
+import com.ylx.massage.service.TAddressService;
|
|
|
|
|
+import com.ylx.massage.utils.OrderNumberGenerator;
|
|
|
import com.ylx.order.domain.TOrder;
|
|
import com.ylx.order.domain.TOrder;
|
|
|
|
|
+import com.ylx.order.domain.dto.OrderSubmitDTO;
|
|
|
import com.ylx.order.mapper.TOrderMapper;
|
|
import com.ylx.order.mapper.TOrderMapper;
|
|
|
import com.ylx.order.service.TOrderService;
|
|
import com.ylx.order.service.TOrderService;
|
|
|
|
|
+import com.ylx.project.domain.Project;
|
|
|
|
|
+import com.ylx.project.service.ProjectService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.Collections;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -27,6 +42,15 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
@Slf4j
|
|
|
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
|
|
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ProjectService projectService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TAddressService addressService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private IMaTechnicianService maTechnicianService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private OrderNumberGenerator orderNumberGenerator;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public TOrder addOrder(TOrder order) {
|
|
public TOrder addOrder(TOrder order) {
|
|
|
return null;
|
|
return null;
|
|
@@ -156,4 +180,116 @@ public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> impleme
|
|
|
public List<Map<String, Object>> myIncomeDetail(TWxUser user, Integer wStatus) {
|
|
public List<Map<String, Object>> myIncomeDetail(TWxUser user, Integer wStatus) {
|
|
|
return Collections.emptyList();
|
|
return Collections.emptyList();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public void submitOrder(OrderSubmitDTO dto) {
|
|
|
|
|
+
|
|
|
|
|
+ TOrder order = new TOrder();
|
|
|
|
|
+ String orderNo = orderNumberGenerator.generateNextOrderNumber("");
|
|
|
|
|
+ order.setOrderNo(orderNo);
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 获取当前用户
|
|
|
|
|
+ WxLoginUser wxLoginUser = SecurityUtils.getWxLoginUser();
|
|
|
|
|
+ if (ObjectUtil.isNull(wxLoginUser)) {
|
|
|
|
|
+ throw new ServiceException("用户未登录");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ order.setUserId(Long.parseLong(wxLoginUser.getId()));
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 获取项目信息
|
|
|
|
|
+ Project project = this.projectService.getById(dto.getProjectId());
|
|
|
|
|
+ if (ObjectUtil.isNull(project)) {
|
|
|
|
|
+ throw new ServiceException("项目不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ order.setProjectId(dto.getProjectId());
|
|
|
|
|
+ order.setProjectType(project.getType());
|
|
|
|
|
+ order.setProjectName(project.getTitle());
|
|
|
|
|
+ order.setProjectCover(project.getCover());
|
|
|
|
|
+ order.setHighlight(project.getHighlight());
|
|
|
|
|
+ order.setAppointmentStartTime(dto.getAppointmentStartTime());
|
|
|
|
|
+ order.setProjectDuration(project.getStandardDuration());
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 获取商户信息
|
|
|
|
|
+ MaTechnician maTechnician = this.maTechnicianService.getById(dto.getMerchantId());
|
|
|
|
|
+ if (ObjectUtil.isNull(maTechnician)) {
|
|
|
|
|
+ throw new ServiceException("商户不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<TAddress> merchantAddresslist = this.addressService.list(new LambdaQueryWrapper<TAddress>()
|
|
|
|
|
+ .eq(TAddress::getMerchantId, dto.getMerchantId())
|
|
|
|
|
+ .eq(TAddress::getUserType, 2)
|
|
|
|
|
+ .eq(TAddress::getIsDelete, 0));
|
|
|
|
|
+ if (CollUtil.isEmpty(merchantAddresslist)) {
|
|
|
|
|
+ throw new ServiceException("商户地址不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ order.setMerchantId(dto.getMerchantId());
|
|
|
|
|
+ order.setMerchantType(maTechnician.getTechType());
|
|
|
|
|
+ order.setMerchantNickName(maTechnician.getTeNickName());
|
|
|
|
|
+ order.setMerchantAvatar(maTechnician.getTeAvatar());
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 获取联系人信息
|
|
|
|
|
+ TAddress address = this.addressService.getById(dto.getAddressId());
|
|
|
|
|
+ if (ObjectUtil.isNull(address)) {
|
|
|
|
|
+ throw new ServiceException("客户联系地址不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ order.setContactPersonName(address.getUserName());
|
|
|
|
|
+ order.setContactPhoneNumber(address.getPhone());
|
|
|
|
|
+ order.setContactAddressInfo(address.getDetailAddress());
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 设置价格信息
|
|
|
|
|
+ LocalDateTime appointmentStartTime = dto.getAppointmentStartTime();
|
|
|
|
|
+
|
|
|
|
|
+ Integer paymentMethod = dto.getPaymentMethod();
|
|
|
|
|
+ // 优惠券优惠
|
|
|
|
|
+ BigDecimal couponDiscount = Optional.ofNullable(dto.getCouponDiscount()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ // 车费
|
|
|
|
|
+ BigDecimal trafficFee = Optional.ofNullable(dto.getTrafficFee()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+ // 商品原价
|
|
|
|
|
+ BigDecimal price = Optional.ofNullable(project.getPrice()).orElse(BigDecimal.ZERO);
|
|
|
|
|
+
|
|
|
|
|
+ // 实付金额 = 商品原价 - 优惠券优惠 + 车费
|
|
|
|
|
+ BigDecimal finalAmount = price.subtract(couponDiscount).add(trafficFee);
|
|
|
|
|
+
|
|
|
|
|
+ order.setBasePrice(price);
|
|
|
|
|
+ order.setCouponDiscount(couponDiscount);
|
|
|
|
|
+ order.setTrafficFee(trafficFee);
|
|
|
|
|
+ order.setFinalAmount(finalAmount);
|
|
|
|
|
+ order.setPaymentMethod(paymentMethod);
|
|
|
|
|
+
|
|
|
|
|
+ order.setCreateTime(DateUtils.getNowDate());
|
|
|
|
|
+ order.setAppointmentStartTime(appointmentStartTime);
|
|
|
|
|
+ order.setStatus(0);
|
|
|
|
|
+ order.setExecStatus(0);
|
|
|
|
|
+ order.setDispatchedStatus(0);
|
|
|
|
|
+
|
|
|
|
|
+ // 6.经纬度信息
|
|
|
|
|
+ order.setUserLatitude(new BigDecimal(address.getLatitude()));
|
|
|
|
|
+ order.setUserLongitude(new BigDecimal(address.getLongitude()));
|
|
|
|
|
+ //取默认真实地址(type=1)
|
|
|
|
|
+ Optional<TAddress> realAddrOpt = merchantAddresslist.stream()
|
|
|
|
|
+ .filter(a -> a.getType() == 1)
|
|
|
|
|
+ .findFirst();
|
|
|
|
|
+ //取默认虚拟地址(type=2)
|
|
|
|
|
+ Optional<TAddress> virtualAddrOpt = merchantAddresslist.stream()
|
|
|
|
|
+ .filter(a -> a.getType() == 2)
|
|
|
|
|
+ .findFirst();
|
|
|
|
|
+
|
|
|
|
|
+ realAddrOpt.ifPresent(addr -> {
|
|
|
|
|
+ order.setMerchantLongitude(new BigDecimal(addr.getLongitude()));
|
|
|
|
|
+ order.setMerchantLatitude(new BigDecimal(addr.getLatitude()));
|
|
|
|
|
+ });
|
|
|
|
|
+ virtualAddrOpt.ifPresent(addr -> {
|
|
|
|
|
+ order.setVirtualLongitude(new BigDecimal(addr.getLongitude()));
|
|
|
|
|
+ order.setVirtualLatitude(new BigDecimal(addr.getLatitude()));
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ boolean saveResult = this.save(order);
|
|
|
|
|
+ if (!saveResult) {
|
|
|
|
|
+ throw new ServiceException("添加订单失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|