|
@@ -8,10 +8,12 @@ import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
|
|
|
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
import com.leromro.common.core.domain.R;
|
|
|
+import com.leromro.common.core.domain.entity.SysDept;
|
|
|
import com.leromro.common.core.domain.entity.SysUser;
|
|
|
import com.leromro.common.enums.AreaSettlementStatusEnum;
|
|
|
import com.leromro.common.enums.ServiceCentreSettlementStatusEnum;
|
|
|
import com.leromro.common.exception.ServiceException;
|
|
|
+import com.leromro.common.utils.GeoUtils;
|
|
|
import com.leromro.common.utils.SecurityUtils;
|
|
|
import com.leromro.core.domain.*;
|
|
|
import com.leromro.core.domain.dto.OrderRequestDTO;
|
|
@@ -24,6 +26,7 @@ import com.leromro.core.service.IMainOrderService;
|
|
|
import com.leromro.core.service.IOrderSettlementApplicationService;
|
|
|
import com.leromro.core.utils.BigDecimalUtil;
|
|
|
import com.leromro.core.utils.DateTimeUtil;
|
|
|
+import com.leromro.core.utils.JsonParser;
|
|
|
import com.leromro.core.utils.NoUtil;
|
|
|
import com.leromro.system.mapper.SysDeptMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -37,10 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.Duration;
|
|
|
import java.time.LocalTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -78,6 +78,9 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
@Autowired
|
|
|
private SysDeptMapper sysDeptMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DeptRegionManagementMapper deptRegionManagementMapper;
|
|
|
+
|
|
|
/**
|
|
|
* @param userId
|
|
|
* @return
|
|
@@ -96,12 +99,11 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public R<OrderPaymentVO> createOrders(OrderRequestDTO orderRequest) {
|
|
|
+ public R<OrderPaymentVO> createOrders(OrderRequestDTO orderRequest) throws Exception {
|
|
|
//响应数据
|
|
|
OrderPaymentVO vo = new OrderPaymentVO();
|
|
|
//订单信息
|
|
|
MainOrders orders = orderRequest.getOrders();
|
|
|
- List<VolunteerWorkDate> workDateList1 = orderRequest.getWorkDateList();
|
|
|
//由于前端传过来的不是有序的,所以我们要将工作时间进行排序
|
|
|
List<VolunteerWorkDate> workDateList = orderRequest.getWorkDateList()
|
|
|
.stream()
|
|
@@ -123,7 +125,9 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
BigDecimal serviceOnePrice = info.getBusinessPrice();
|
|
|
Integer businessDurationMin = info.getBusinessDuration();
|
|
|
Long totalTimes = orders.getTotalTimes();
|
|
|
- BigDecimal totalPrice = serviceOnePrice.multiply(BigDecimal.valueOf(totalTimes));
|
|
|
+ Long singleQuantity = orders.getSingleQuantity();
|
|
|
+ //总价 = 服务单词价格*服务次数*单词服务数量
|
|
|
+ BigDecimal totalPrice = serviceOnePrice.multiply(BigDecimal.valueOf(totalTimes)).multiply(BigDecimal.valueOf(singleQuantity));
|
|
|
orders.setServiceTotalPrice(totalPrice);
|
|
|
// 判断支付方式,余额扣减余额。 1 余额 2 微信
|
|
|
String seconderStatus;
|
|
@@ -185,6 +189,9 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
//创建订单主表
|
|
|
//把地址信息也添加到数据里面
|
|
|
Address address = addressMapper.selectAddressByAddressId(orders.getAddressId());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//地址拼接信息+经纬度
|
|
|
String OrderAddress = String.join("",
|
|
|
Objects.toString(address.getProvinceName(), ""),
|
|
@@ -222,15 +229,67 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
List<VolunteerReservationTime> reservationTimes = new ArrayList<>();
|
|
|
|
|
|
//创建小订单模板
|
|
|
- //
|
|
|
- SecondOrder secondOrder = SecondOrder.builder().mainOrderId(orderId).volunteerId(orders.getVolunteerId()).
|
|
|
- serviceCategory(orders.getServiceCategory()).serviceDuration(orders.getServiceDuration()).addressId(orders.getAddressId())
|
|
|
+ SecondOrder secondOrder = SecondOrder.builder().mainOrderId(orderId).volunteerId(orders.getVolunteerId()).singleQuantity(singleQuantity)
|
|
|
+ .serviceCategory(orders.getServiceCategory()).serviceDuration(orders.getServiceDuration()).addressId(orders.getAddressId())
|
|
|
.serviceOnePrice(orders.getServiceOnePrice()).volunteerInfoId(orders.getVolunteerInfoId()).orderStatus(seconderStatus)
|
|
|
.provinceCode(address.getProvinceCode()).cityCode(address.getCityCode()).districtCode(address.getDistrictCode())
|
|
|
.provinceName(address.getProvinceName()).cityName(address.getCityName()).districtName(address.getDistrictName())
|
|
|
.outTradeNo(orderNo)
|
|
|
.build();
|
|
|
secondOrder.setRemark(orders.getRemark());
|
|
|
+ //根据下单的收货地址,来设置分账比例 先查这个订单是否在电子围栏中
|
|
|
+ //找到所有的部门的数据,然后把所有的数据遍历,并且统计出来
|
|
|
+ //用的是新版的部门区域 但是获取分账比例还是从老的中获取
|
|
|
+ /* List<DeptRegionManagement> deptRegionManagements = deptRegionManagementMapper.selectList(new LambdaQueryWrapper<DeptRegionManagement>().eq(DeptRegionManagement::getDelFlag, 2));
|
|
|
+ List<Long> deptIdsList = deptRegionManagements.stream().map(DeptRegionManagement::getDeptId).collect(Collectors.toList());*/
|
|
|
+
|
|
|
+ List<SysDept> sysDepts = sysDeptMapper.getAlldept();
|
|
|
+
|
|
|
+ List<Long> deptIdList = new ArrayList<>();
|
|
|
+ /*for (DeptRegionManagement deptRegionManagement : deptRegionManagements) {}*/
|
|
|
+ for (SysDept sysDept : sysDepts) {
|
|
|
+ //判断 服务中心分成比例
|
|
|
+ //真的
|
|
|
+ String pointList = sysDept.getPointList();
|
|
|
+ boolean insidePolygon ;
|
|
|
+ if (pointList != null){
|
|
|
+ List<double[]> doubles = JsonParser.parseCoordinates(pointList);
|
|
|
+ insidePolygon = GeoUtils.isInsidePolygon(Double.parseDouble(address.getLatitude()) , Double.parseDouble(address.getLongitude()), doubles);
|
|
|
+ }else {
|
|
|
+ insidePolygon = false;
|
|
|
+ }
|
|
|
+ if (insidePolygon){
|
|
|
+ //如果是true 将这个地址的区域id添加到集合中
|
|
|
+ deptIdList.add(sysDept.getDeptId());
|
|
|
+ }//如果false 则什么都不变
|
|
|
+ //区域公司的分成比例 因为没有区域公司,也不会有志愿者,所以这个区域公司一定会匹配上的
|
|
|
+ if (sysDept.getDistrictCode()== null){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (sysDept.getDistrictCode().equals(address.getDistrictCode())){
|
|
|
+ secondOrder.setAreaDistributionRatio(sysDept.getDistributionRatio());
|
|
|
+ secondOrder.setAreaDistributionId(sysDept.getDeptId());
|
|
|
+ }else {
|
|
|
+ throw new RuntimeException("当前地区缺少管理,请联系管理员");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据匹配数量,修改数值
|
|
|
+ if (deptIdList.size()==1){
|
|
|
+ //已分配到服务中心
|
|
|
+ secondOrder.setAllotStatus("20");
|
|
|
+ secondOrder.setServiceCenterId(deptIdList.get(0));
|
|
|
+ //设置服务中心的分成比例
|
|
|
+ sysDepts.forEach(sysDept -> {
|
|
|
+ if (sysDept.getDeptId().equals(deptIdList.get(0))) {
|
|
|
+ secondOrder.setServiceCentreDistributionRatio(sysDept.getDistributionRatio());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } else {
|
|
|
+ secondOrder.setAllotStatus("10");
|
|
|
+ }
|
|
|
+
|
|
|
List<SecondOrder> secondOrderList = new ArrayList<>();
|
|
|
|
|
|
|
|
@@ -252,11 +311,14 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
secondOrder1.setWorkEndTime(workDate.getWorkStartTime().plus(Duration.ofMinutes(orders.getServiceDuration())));
|
|
|
secondOrder1.setWorkNumber(number);
|
|
|
secondOrder1.setSecondOrderId(secondOrderIdL);
|
|
|
+
|
|
|
+ orders.setOutTradeNo(orderNo+"-"+number);
|
|
|
secondOrder1.setOutTradeNo(orderNo);
|
|
|
+
|
|
|
secondOrderList.add(secondOrder1);
|
|
|
|
|
|
//向志愿者预约时间表中添加数据
|
|
|
- int parts = businessDurationMin/30;
|
|
|
+ int parts = (int) (businessDurationMin * singleQuantity /30);
|
|
|
if (businessDurationMin % 30!=0){
|
|
|
parts++;
|
|
|
}
|
|
@@ -322,8 +384,8 @@ public class MainOrderServiceImpl extends ServiceImpl<MainOrdersMapper, MainOrde
|
|
|
}
|
|
|
|
|
|
public void changePlatformFinance ( List<Long> seconderIdList,MainOrders orders){
|
|
|
- //创建平台流水模板
|
|
|
- PlatformFinance platformFinance = PlatformFinance.builder().changeMoney(orders.getServiceOnePrice()).changeType(1).moneyType(1)
|
|
|
+ //创建平台流水模板 按照小订单,单价*件数 = 小订单价格 = 一条平台流水变动
|
|
|
+ PlatformFinance platformFinance = PlatformFinance.builder().changeMoney(orders.getServiceOnePrice().multiply(BigDecimal.valueOf(orders.getSingleQuantity()))).changeType(1).moneyType(1)
|
|
|
.sourceType(1).volunteerId(orders.getVolunteerId()).build();
|
|
|
platformFinance.setCreateTime(DateTimeUtil.getNowTime());
|
|
|
List<PlatformFinance> platformFinanceList = new ArrayList<>();
|