From 2ab42edae9d271f5f464b7be475e217752dacb38 Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期三, 22 四月 2026 09:24:47 +0800
Subject: [PATCH] 代码生成
---
server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java | 591 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 514 insertions(+), 77 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
index 5224b0f..01df4f5 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/OrdersServiceImpl.java
@@ -8,14 +8,16 @@
import com.doumee.biz.system.OperationConfigBiz;
import com.doumee.biz.system.SystemDictDataBiz;
import com.doumee.config.wx.WxMiniConfig;
-import com.doumee.config.wx.WxMiniUtilService;
+import com.doumee.config.wx.WxPayProperties;
+import com.doumee.config.wx.WxPayV3Service;
+import com.wechat.pay.java.service.refund.model.Refund;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.model.PageData;
import com.doumee.core.model.PageWrap;
import com.doumee.core.utils.DateUtil;
-import com.doumee.core.utils.Tencent.MapUtil;
+import com.doumee.core.utils.geocode.MapUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.business.*;
import com.doumee.dao.business.model.*;
@@ -30,10 +32,12 @@
import com.doumee.dao.dto.MyOrderDTO;
import com.doumee.dao.dto.OrderItemDTO;
import com.doumee.dao.vo.*;
+import com.doumee.service.business.NoticeService;
import com.doumee.service.business.OrderLogService;
import com.doumee.service.business.OrdersService;
+import com.doumee.dao.business.model.Notice;
import com.doumee.service.business.AreasService;
-import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
+import com.doumee.service.business.PricingRuleService;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
@@ -44,17 +48,11 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.context.request.RequestContextHolder;
-import org.springframework.web.context.request.ServletRequestAttributes;
-import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.RoundingMode;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
/**
* 瀵勫瓨璁㈠崟淇℃伅Service瀹炵幇
@@ -103,14 +101,17 @@
@Autowired
private RevenueMapper revenueMapper;
- @Autowired
- private WxMiniUtilService wxMiniUtilService;
+
@Autowired
private SystemUserMapper systemUserMapper;
@Autowired
private PricingRuleMapper pricingRuleMapper;
+
+ @Autowired
+ private PricingRuleService pricingRuleService;
+
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@@ -122,6 +123,15 @@
@Autowired
private AreasService areasService;
+
+ @Autowired
+ private NoticeService noticeService;
+
+ @Autowired
+ private WxPayV3Service wxPayV3Service;
+
+ @Autowired
+ private WxPayProperties wxPayProperties;
@Override
public Integer create(Orders orders) {
@@ -284,7 +294,7 @@
return BigDecimal.ZERO;
}
String rateStr = systemDictDataBiz.queryByCode(Constants.OPERATION_CONFIG, Constants.OP_INSURANCE_RATE).getCode();
- BigDecimal rate = new BigDecimal(rateStr);
+ BigDecimal rate = new BigDecimal(rateStr).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
return declaredValue.multiply(rate).setScale(2, BigDecimal.ROUND_HALF_UP);
}
@@ -303,9 +313,9 @@
*/
@Override
public PriceCalculateVO calculateLocalPrice(CalculateLocalPriceDTO dto) {
- // 澶╂暟鏍¢獙锛屾渶灏�1澶�
- int days = dto.getEstimatedDepositDays() != null && dto.getEstimatedDepositDays() > 0
- ? dto.getEstimatedDepositDays() : 1;
+ // 鏍规嵁寮�濮嬪拰缁撴潫鏃堕棿璁$畻澶╂暟锛屾渶灏�1澶�
+ long diffMs = dto.getDepositEndTime().getTime() - dto.getDepositStartTime().getTime();
+ int days = (int) Math.max(1, (diffMs / (1000 * 60 * 60 * 24)) + 1);
// 鏀堕泦鎵�鏈夌墿鍝佺被鍨婭D
List<Integer> categoryIds = new ArrayList<>();
@@ -332,9 +342,11 @@
List<Category> categories = categoryMapper.selectBatchIds(categoryIds);
Map<Integer, String> categoryNameMap = new HashMap<>();
Map<Integer, String> categoryDetailMap = new HashMap<>();
+ Map<Integer, String> categoryOtherFieldMap = new HashMap<>();
for (Category c : categories) {
categoryNameMap.put(c.getId(), c.getName());
categoryDetailMap.put(c.getId(), c.getDetail());
+ categoryOtherFieldMap.put(c.getId(),c.getOtherField());
}
// 璁$畻姣忛」鐗╁搧璐圭敤锛氬皬璁� = 鍗曚环 脳 鏁伴噺 脳 澶╂暟
@@ -354,7 +366,7 @@
ItemPriceVO vo = new ItemPriceVO();
vo.setCategoryId(item.getCategoryId());
vo.setCategoryName(categoryNameMap.getOrDefault(item.getCategoryId(), ""));
- vo.setDetail(categoryDetailMap.get(item.getCategoryId()));
+ vo.setDetail(categoryOtherFieldMap.get(item.getCategoryId()));
vo.setQuantity(item.getQuantity());
vo.setUnitPrice(unitPrice);
vo.setLocallyPrice(unitPrice);
@@ -364,9 +376,9 @@
itemPriceTotal += subtotal;
}
- // 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎
+ // 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎锛堜繚浠烽噾棰�>0鏃惰璐癸級
long insuranceFeeFen = 0L;
- if (Boolean.TRUE.equals(dto.getInsured()) && dto.getDeclaredAmount() != null) {
+ if (dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal insuranceFeeYuan = calculateInsuranceFee(dto.getDeclaredAmount());
insuranceFeeFen = insuranceFeeYuan.multiply(new BigDecimal(100)).longValue();
}
@@ -408,10 +420,13 @@
// 1. 璋冪敤鑵捐鍦板浘璺濈鐭╅樀API璁$畻椹捐溅璺濈
String from = dto.getFromLat() + "," + dto.getFromLgt();
String to = dto.getToLat() + "," + dto.getToLgt();
- JSONObject distanceResult = MapUtil.distanceSingle("driving", from, to);
+ JSONObject distanceResult = MapUtil.direction("driving", from, to);
BigDecimal distance = distanceResult.getBigDecimal("distance");
- // distance 鍗曚綅涓虹背锛岃浆涓哄叕閲�
+ // distance 鍗曚綅涓虹背锛岃浆涓哄叕閲岋紙涓嶈冻1鍏噷鎸�1鍏噷璁$畻锛�
BigDecimal distanceKm = distance.divide(new BigDecimal(1000), 2, RoundingMode.HALF_UP);
+ if (distanceKm.compareTo(BigDecimal.ONE) < 0) {
+ distanceKm = BigDecimal.ONE;
+ }
// 鏀堕泦鎵�鏈夌墿鍝佺被鍨婭D
List<Integer> categoryIds = new ArrayList<>();
@@ -449,9 +464,11 @@
List<Category> categories = categoryMapper.selectBatchIds(categoryIds);
Map<Integer, String> categoryNameMap = new HashMap<>();
Map<Integer, String> categoryDetailMap = new HashMap<>();
+ Map<Integer, String> categoryOtherFieldMap = new HashMap<>();
for (Category c : categories) {
categoryNameMap.put(c.getId(), c.getName());
categoryDetailMap.put(c.getId(), c.getDetail());
+ categoryOtherFieldMap.put(c.getId(),c.getOtherField());
}
// 3. 閫愰」璁$畻杩愯垂锛氳捣姝ヤ环 + 瓒呭嚭閮ㄥ垎闃舵浠�
@@ -490,7 +507,7 @@
ItemPriceVO vo = new ItemPriceVO();
vo.setCategoryId(item.getCategoryId());
vo.setCategoryName(categoryNameMap.getOrDefault(item.getCategoryId(), ""));
- vo.setDetail(categoryDetailMap.get(item.getCategoryId()));
+ vo.setDetail(categoryOtherFieldMap.get(item.getCategoryId()));
vo.setQuantity(item.getQuantity());
vo.setUnitPrice(unitPrice);
vo.setLocallyPrice(locallyPrice);
@@ -504,25 +521,26 @@
itemPriceTotal += subtotal;
}
- // 4. 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎
+ // 4. 淇濅环璐圭敤锛氭姤浠烽噾棰� 脳 淇濅环璐圭巼(瀛楀吀 INSURANCE_RATE)锛屽厓鈫掑垎锛堜繚浠烽噾棰�>0鏃惰璐癸級
long insuranceFeeFen = 0L;
- if (Boolean.TRUE.equals(dto.getInsured()) && dto.getDeclaredAmount() != null) {
+ if (dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0) {
BigDecimal insuranceFeeYuan = calculateInsuranceFee(dto.getDeclaredAmount());
insuranceFeeFen = insuranceFeeYuan.multiply(new BigDecimal(100)).longValue();
}
// 5. 鍔犳�ヨ垂鐢細鐗╁搧浠锋牸 脳 鍔犳�ョ郴鏁�(瀛楀吀 URGENT_COEFFICIENT)
long urgentFeeFen = 0L;
- if (Boolean.TRUE.equals(dto.getUrgent())) {
- String urgentRateStr = systemDictDataBiz.queryByCode(
- Constants.OPERATION_CONFIG, Constants.OP_URGENT_COEFFICIENT).getCode();
- BigDecimal urgentRate = new BigDecimal(urgentRateStr);
- urgentFeeFen = new BigDecimal(itemPriceTotal).multiply(urgentRate)
- .setScale(0, RoundingMode.HALF_UP).longValue();
- }
+ String urgentRateStr = systemDictDataBiz.queryByCode(
+ Constants.OPERATION_CONFIG, Constants.OP_URGENT_COEFFICIENT).getCode();
+ BigDecimal urgentRate = new BigDecimal(urgentRateStr);
+ urgentFeeFen = new BigDecimal(itemPriceTotal).multiply(urgentRate)
+ .setScale(0, RoundingMode.HALF_UP).longValue();
- // 6. 鎬讳环鏍� = 鐗╁搧浠锋牸 + 淇濅环璐圭敤 + 鍔犳�ヨ垂鐢�
- long totalPrice = itemPriceTotal + insuranceFeeFen + urgentFeeFen;
+ // 6. 鎬讳环鏍� = 鐗╁搧浠锋牸 + 淇濅环璐圭敤 + 鍔犳�ヨ垂鐢紙鍔犳�ユ椂鎵嶅寘鍚姞鎬ヨ垂锛�
+ long totalPrice = itemPriceTotal + insuranceFeeFen;
+ if (Boolean.TRUE.equals(dto.getUrgent())) {
+ totalPrice += urgentFeeFen;
+ }
PriceCalculateVO result = new PriceCalculateVO();
result.setItemList(itemList);
@@ -531,6 +549,33 @@
result.setUrgentFee(urgentFeeFen);
result.setTotalPrice(totalPrice);
result.setDistance(distanceKm);
+
+ // 7. 棰勮閫佽揪鏃堕暱锛歱ricing_rule type=2锛坒ieldA=1鏍囬�熻揪锛宖ieldA=2鏋侀�熻揪锛�
+ List<PricingRule> timeRules = pricingRuleMapper.selectList(new QueryWrapper<PricingRule>().lambda()
+ .eq(PricingRule::getDeleted, Constants.ZERO)
+ .eq(PricingRule::getType, Constants.TWO)
+ .eq(PricingRule::getCityId, dto.getCityId())
+ .in(PricingRule::getFieldA, Arrays.asList("1", "2")));
+ for (PricingRule tr : timeRules) {
+ BigDecimal baseKm = new BigDecimal(tr.getFieldB());
+ int baseHours = Integer.parseInt(tr.getFieldC());
+ BigDecimal extraKm = new BigDecimal(tr.getFieldD());
+ int extraHours = Integer.parseInt(tr.getFieldE());
+ int hours;
+ if (distanceKm.compareTo(baseKm) <= 0) {
+ hours = baseHours;
+ } else {
+ BigDecimal overDistance = distanceKm.subtract(baseKm);
+ int extraCount = overDistance.divide(extraKm, 0, RoundingMode.CEILING).intValue();
+ hours = baseHours + extraCount * extraHours;
+ }
+ if ("1".equals(tr.getFieldA())) {
+ result.setStandardHours(hours);
+ } else if ("2".equals(tr.getFieldA())) {
+ result.setUrgentHours(hours);
+ }
+ }
+
return result;
}
@@ -607,8 +652,11 @@
// ========== 3. 鏌ヨ瀵勪欢搴楅摵淇℃伅 ==========
ShopInfo depositShop = shopInfoMapper.selectById(dto.getDepositShopId());
- if (depositShop == null) {
+ if (depositShop == null || Constants.equalsInteger(depositShop.getDeleted(), Constants.ONE)) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵勪欢搴楅摵涓嶅瓨鍦�");
+ }
+ if (depositShop.getStatus() == null || !Constants.equalsInteger(depositShop.getStatus(), Constants.ZERO)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵勪欢搴楅摵宸插仠涓氾紝璇烽�夋嫨鍏朵粬闂ㄥ簵");
}
// ========== 4. 璁$畻璐圭敤 ==========
@@ -625,14 +673,25 @@
}
// 鍙栦欢鐐癸細搴楅摵 or 鑷�夌偣锛岃嚦灏戞彁渚涗竴缁�
if (dto.getTakeShopId() != null) {
+ if (dto.getTakeShopId().equals(dto.getDepositShopId())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "寮傚湴瀵勫瓨璁㈠崟瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴椾笉鑳界浉鍚�");
+ }
takeShop = shopInfoMapper.selectById(dto.getTakeShopId());
- if (takeShop == null) {
+ if (takeShop == null || Constants.equalsInteger(takeShop.getDeleted(), Constants.ONE)) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍙栦欢搴楅摵涓嶅瓨鍦�");
+ }
+ if (takeShop.getStatus() == null || !Constants.equalsInteger(takeShop.getStatus(), Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鍙栦欢搴楅摵宸插仠涓氾紝璇烽�夋嫨鍏朵粬闂ㄥ簵");
}
takeLat = BigDecimal.valueOf(takeShop.getLatitude());
takeLgt = BigDecimal.valueOf(takeShop.getLongitude());
takeLocationValue = takeShop.getAddress();
} else if (dto.getTakeLat() != null && dto.getTakeLgt() != null && StringUtils.isNotBlank(dto.getTakeLocation())) {
+ // 鏃犲彇浠堕棬搴楋紝鏍¢獙瀛樹欢鐐逛笌鑷�夊彇浠剁偣鏄惁鍦ㄥ悓涓�鍩庡競
+ if (!MapUtil.isSameCity(depositShop.getLatitude(), depositShop.getLongitude(),
+ dto.getTakeLat().doubleValue(), dto.getTakeLgt().doubleValue())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "寮傚湴瀵勫瓨璁㈠崟瀛樺彇鐐逛笉鍦ㄥ悓涓�鍩庡競锛屽闇�璇烽�夋嫨鍚屽煄闂ㄥ簵");
+ }
takeLat = dto.getTakeLat();
takeLgt = dto.getTakeLgt();
takeLocationValue = dto.getTakeLocation();
@@ -647,15 +706,12 @@
// ========== 3. 璁$畻璐圭敤 ==========
PriceCalculateVO priceResult;
if (Constants.ZERO.equals(dto.getType())) {
- // 灏卞湴瀵勫瓨锛氳绠楀ぉ鏁�
- long diffMs = takeTime.getTime() - depositTime.getTime();
- int days = (int) Math.max(1, (diffMs / (1000 * 60 * 60 * 24)) + 1);
-
+ // 灏卞湴瀵勫瓨
CalculateLocalPriceDTO priceDTO = new CalculateLocalPriceDTO();
priceDTO.setCityId(dto.getCityId());
- priceDTO.setEstimatedDepositDays(days);
+ priceDTO.setDepositStartTime(depositTime);
+ priceDTO.setDepositEndTime(takeTime);
priceDTO.setItems(dto.getItems());
- priceDTO.setInsured(dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0);
priceDTO.setDeclaredAmount(dto.getDeclaredAmount());
priceResult = calculateLocalPrice(priceDTO);
} else {
@@ -667,7 +723,6 @@
priceDTO.setToLat(takeLat);
priceDTO.setToLgt(takeLgt);
priceDTO.setItems(dto.getItems());
- priceDTO.setInsured(dto.getDeclaredAmount() != null && dto.getDeclaredAmount().compareTo(BigDecimal.ZERO) > 0);
priceDTO.setDeclaredAmount(dto.getDeclaredAmount());
priceDTO.setUrgent(Constants.ONE.equals(dto.getIsUrgent()));
priceResult = calculateRemotePrice(priceDTO);
@@ -725,6 +780,7 @@
orders.setTakeLat(takeLat);
orders.setTakeLgt(takeLgt);
orders.setIsUrgent(dto.getIsUrgent());
+ orders.setDistance(priceResult.getDistance());
} else {
// 灏卞湴锛氬彇浠剁偣鍚屽瘎浠跺簵閾�
orders.setTakeShopId(dto.getDepositShopId());
@@ -736,6 +792,12 @@
// 鐗╁搧淇℃伅
orders.setGoodType(dto.getGoodType());
+ // 鏌ヨ鐗╁搧绾у埆 type = 3
+ Category levelCategory = categoryMapper.selectById(goodTypeCategory.getRelationId());
+ if(Objects.isNull(levelCategory)){
+ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"鏈煡璇㈠埌鐗╁搧绛夌骇淇℃伅锛歿}"+goodTypeCategory.getName());
+ }
+ orders.setGoodLevel(Integer.valueOf(levelCategory.getDetail()));
// 鎷兼帴鐗╁搧淇℃伅锛氱墿鍝佺被鍨嬪悕绉般�佸昂瀵稿悕绉�*鏁伴噺锛堟暟缁勫瓧绗︿覆锛�
List<String> goodsParts = new ArrayList<>();
for (ItemPriceVO itemVO : priceResult.getItemList()) {
@@ -757,7 +819,6 @@
}
orders.setDeclaredFee(priceResult.getInsuranceFee());
orders.setPrice(priceResult.getItemPrice());
-
// 钖叕璁$畻涓庡崰姣斿瓨鍌�
calculateAndSetFeeAllocation(orders, depositShop, takeShop);
@@ -802,7 +863,8 @@
if (member == null || StringUtils.isBlank(member.getOpenid())) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鐢ㄦ埛淇℃伅寮傚父锛屾棤娉曞彂璧锋敮浠�");
}
- PayResponse payResponse = wxPay(orders, member.getOpenid(), Constants.OrdersAttach.STORAGE_ORDER);
+ PayResponse payResponse = wxPayV3(orders.getOutTradeNo(), orders.getTotalAmount(), orders.getId(),
+ member.getOpenid(), Constants.OrdersAttach.STORAGE_ORDER);
payResponse.setLockKey(lockKey);
return payResponse;
}
@@ -837,7 +899,8 @@
if (member == null || StringUtils.isBlank(member.getOpenid())) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "鐢ㄦ埛淇℃伅寮傚父锛屾棤娉曞彂璧锋敮浠�");
}
- return wxPay(orders, member.getOpenid(), Constants.OrdersAttach.STORAGE_ORDER);
+ return wxPayV3(orders.getOutTradeNo(), orders.getTotalAmount(), orders.getId(),
+ member.getOpenid(), Constants.OrdersAttach.STORAGE_ORDER);
}
/**
@@ -872,7 +935,32 @@
}
}
+ /**
+ * 鍞よ捣寰俊鏀粯V3
+ *
+ * @param outTradeNo 鍟嗘埛璁㈠崟鍙�
+ * @param totalCents 鏀粯閲戦锛堝垎锛�
+ * @param orderId 璁㈠崟涓婚敭
+ * @param openid 鐢ㄦ埛寰俊openid
+ * @param ordersAttach 璁㈠崟鏀粯绫诲瀷
+ * @return PayResponse 鍖呭惈寰俊璋冭捣鍙傛暟鍜岃鍗曚富閿�
+ */
+ private PayResponse wxPayV3(String outTradeNo, Long totalCents, Integer orderId,
+ String openid, Constants.OrdersAttach ordersAttach) {
+ Map<String, String> payParams = wxPayV3Service.createOrder(
+ outTradeNo,
+ ordersAttach.getName(),
+ totalCents != null ? totalCents : 0L,
+ openid,
+ wxPayProperties.getV3NotifyUrl(),
+ ordersAttach.getKey()
+ );
+ PayResponse payResponse = new PayResponse();
+ payResponse.setResponse(payParams);
+ payResponse.setOrderId(orderId);
+ return payResponse;
+ }
@@ -1105,9 +1193,9 @@
item.setLuggageName(d.getLuggageName());
item.setLuggageDetail(d.getLuggageDetail());
item.setNum(d.getNum());
- double unitPriceYuan = d.getUnitPrice() != null ? Constants.getFormatMoney(d.getUnitPrice()) : 0;
- item.setUnitPriceYuan(unitPriceYuan);
- item.setSubtotal(unitPriceYuan * (d.getNum() != null ? d.getNum() : 0));
+ long unitPriceFen = d.getUnitPrice() != null ? d.getUnitPrice() : 0L;
+ item.setUnitPrice(unitPriceFen);
+ item.setSubtotal(unitPriceFen * (d.getNum() != null ? d.getNum() : 0));
items.add(item);
}
}
@@ -1206,14 +1294,17 @@
// 瀵勪欢闂ㄥ簵鍗犳瘮锛歠ieldA=0(浼佷笟瀵�)/1(涓汉瀵�)
int depositFieldA = Constants.equalsInteger(depositShop.getCompanyType(), Constants.ONE) ? Constants.ZERO : Constants.ONE;
BigDecimal depositShopRata = getRevenueShareRata(cityId, depositFieldA);
- // 鍙栦欢闂ㄥ簵鍗犳瘮锛歠ieldA=2(浼佷笟鍙�)/3(涓汉鍙�)
- int takeFieldA = Constants.equalsInteger(takeShop.getCompanyType(), Constants.ONE) ? Constants.TWO : Constants.THREE;
- BigDecimal takeShopRata = getRevenueShareRata(cityId, takeFieldA);
+ // 鍙栦欢闂ㄥ簵鍗犳瘮锛氭棤鍙栦欢闂ㄥ簵鏃舵瘮渚嬩负0
+ BigDecimal takeShopRata = BigDecimal.ZERO;
+ if (takeShop != null) {
+ int takeFieldA = Constants.equalsInteger(takeShop.getCompanyType(), Constants.ONE) ? Constants.TWO : Constants.THREE;
+ takeShopRata = getRevenueShareRata(cityId, takeFieldA);
+ }
// 璁$畻钖叕锛堝垎锛夛細totalAmount 涓哄垎锛宺ata 涓烘瘮渚嬪�硷紙濡� 0.15 琛ㄧず 15%锛�
long driverFee = new BigDecimal(totalAmount).multiply(driverRata).longValue();
long depositShopFee = new BigDecimal(totalAmount).multiply(depositShopRata).longValue();
- long takeShopFee = totalAmount - driverFee - depositShopFee;
+ long takeShopFee = new BigDecimal(totalAmount).multiply(takeShopRata).longValue();
orders.setDriverFee(driverFee);
orders.setDepositShopFee(depositShopFee);
@@ -1237,8 +1328,9 @@
.eq(PricingRule::getCityId, cityId)
.eq(PricingRule::getFieldA, String.valueOf(fieldA))
.last("limit 1"));
- if (rule != null && StringUtils.isNotBlank(rule.getFieldC())) {
- return new BigDecimal(rule.getFieldC());
+ if (rule != null && StringUtils.isNotBlank(rule.getFieldB())) {
+ // fieldB 瀛樺偍鐨勬槸鐧惧垎姣旀暣鏁帮紙濡�15琛ㄧず15%锛夛紝杞崲涓哄皬鏁版瘮渚嬶紙0.15锛�
+ return new BigDecimal(rule.getFieldB()).divide(new BigDecimal("100"), 4, BigDecimal.ROUND_HALF_UP);
}
return BigDecimal.ZERO;
}
@@ -1287,16 +1379,22 @@
vo.setCode(o.getCode());
vo.setType(o.getType());
vo.setStatus(o.getStatus());
+ vo.setStatusName(Constants.OrderStatus.getDescByKey(o.getStatus(),
+ Constants.equalsInteger(o.getType(), Constants.ZERO)?o.getType():Objects.nonNull(o.getTakeShopId())?Constants.ONE:Constants.TWO)
+ );
vo.setCreateTime(o.getCreateTime());
vo.setExpectedTakeTime(o.getExpectedTakeTime());
+ vo.setMemberVerifyCode(o.getMemberVerifyCode());
// 瀛樹欢闂ㄥ簵锛堝叧鑱旀煡璇㈢洿鎺ュ彇鍊硷級
+ vo.setDepositShopId(o.getDepositShopId());
vo.setDepositShopName(o.getDepositShopName());
vo.setDepositShopLinkName(o.getDepositShopLinkName());
vo.setDepositShopPhone(o.getDepositShopLinkPhone());
// 鍙栦欢淇℃伅锛氭湁鍙栦欢闂ㄥ簵鍙栭棬搴楋紝鏃犲垯鍙栫敤鎴疯嚜閫夊彇浠剁偣
if (o.getTakeShopId() != null) {
+ vo.setTakeShopId(o.getTakeShopId());
vo.setTakeShopName(o.getTakeShopName());
vo.setTakeShopAddress(o.getTakeShopAddress());
} else {
@@ -1311,6 +1409,9 @@
// 璐圭敤锛堝垎锛�
vo.setDeclaredFee(o.getDeclaredFee());
vo.setEstimatedAmount(o.getEstimatedAmount());
+
+ // 璇勪环鐘舵��
+ vo.setCommentStatus(o.getCommentStatus());
// 鏌ヨ鐗╁搧鏄庣粏锛堜竴娆℃煡璇紝鍚屾椂鐢ㄤ簬鐗╁搧鍒楄〃鍜岄�炬湡璁$畻锛�
List<OrdersDetail> details = ordersDetailMapper.selectList(
@@ -1384,6 +1485,9 @@
vo.setCode(o.getCode());
vo.setType(o.getType());
vo.setStatus(o.getStatus());
+ vo.setStatusName(Constants.OrderStatus.getDescByKey(o.getStatus(),
+ Constants.equalsInteger(o.getType(), Constants.ZERO)?o.getType():Objects.nonNull(o.getTakeShopId())?Constants.ONE:Constants.TWO)
+ );
vo.setCreateTime(o.getCreateTime());
vo.setExpectedTakeTime(o.getExpectedTakeTime());
@@ -1599,11 +1703,6 @@
throw new BusinessException(ResponseStatus.DATA_EMPTY);
}
- // 浠呭紓鍦板瘎瀛樺彲鍙栨秷
- if (!Constants.equalsInteger(order.getType(), Constants.ONE)) {
- throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呭紓鍦板瘎瀛樿鍗曞彲鍙栨秷");
- }
-
Integer status = order.getStatus();
if (status == null) {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "璁㈠崟鐘舵�佸紓甯�");
@@ -1611,7 +1710,7 @@
Date now = new Date();
- // 寰呮敮浠橈細鐩存帴鍙栨秷
+ // 寰呮敮浠橈細鐩存帴鍙栨秷锛堜笉闄愯鍗曠被鍨嬶級
if (Constants.equalsInteger(status, Constants.OrderStatus.waitPay.getStatus())) {
order.setStatus(Constants.OrderStatus.cancelled.getStatus());
order.setCancelTime(now);
@@ -1620,7 +1719,7 @@
return;
}
- // 寰呭瘎瀛橈細鐩存帴鍙栨秷锛屽叏棰濋��娆�
+ // 寰呭瘎瀛橈細鐩存帴鍙栨秷锛屽叏棰濋��娆撅紙涓嶉檺璁㈠崟绫诲瀷锛�
if (Constants.equalsInteger(status, Constants.OrderStatus.waitDeposit.getStatus())) {
// 璁板綍閫�娆句俊鎭�
OrdersRefund refund = new OrdersRefund();
@@ -1630,10 +1729,11 @@
refund.setCreateTime(now);
refund.setDeleted(Constants.ZERO);
- // 璋冪敤寰俊閫�娆撅紝鍏ㄩ閫�娆�
- String refundCode = wxMiniUtilService.wxRefund(order.getOutTradeNo(), order.getPayAmount(), order.getPayAmount());
- refund.setRefundCode(refundCode);
- refund.setRefundTime(new Date());
+ // 璋冪敤寰俊閫�娆綱3锛屽叏棰濋��娆�
+ Refund refundResult = wxPayV3Service.refund(order.getOutTradeNo(), order.getPayAmount(), order.getPayAmount(),
+ "璁㈠崟閫�娆�", wxPayProperties.getV3RefundNotifyUrl());
+ refund.setRefundCode(refundResult.getOutRefundNo());
+ refund.setStatus(Constants.ZERO); // 閫�娆句腑
ordersRefundMapper.insert(refund);
order.setStatus(Constants.OrderStatus.cancelled.getStatus());
@@ -1642,7 +1742,15 @@
ordersMapper.updateById(order);
saveCancelLog(order, "浼氬憳鍙栨秷璁㈠崟锛堝緟瀵勫瓨锛屽叏棰濋��娆撅級", reason, memberId);
+ // 閫氱煡浼氬憳锛氶��娆句腑
+ sendOrderNotice(memberId, Constants.MemberOrderNotify.REFUNDING, orderId,
+ "orderNo", order.getCode());
return;
+ }
+
+ // 宸插瘎瀛�/宸叉帴鍗曪細浠呭紓鍦板瘎瀛樺彲鍙栨秷
+ if (!Constants.equalsInteger(order.getType(), Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呭紓鍦板瘎瀛樿鍗曞彲鍙栨秷");
}
// 宸插瘎瀛�/宸叉帴鍗曪細杩涘叆鍙栨秷涓姸鎬�
@@ -1652,6 +1760,16 @@
order.setCancelTime(now);
ordersMapper.updateById(order);
saveCancelLog(order, "浼氬憳鐢宠鍙栨秷璁㈠崟锛堝凡瀵勫瓨/宸叉帴鍗曪級", reason, memberId);
+ // 閫氱煡瀛樹欢闂ㄥ簵锛氶��娆剧敵璇�
+ if (order.getDepositShopId() != null) {
+ sendShopNotice(order.getDepositShopId(), Constants.ShopOrderNotify.REFUNDING, orderId,
+ "orderNo", order.getCode());
+ }
+ // 閫氱煡鍙告満锛氳鍗曢��娆句腑锛堝凡鎺ュ崟鎯呭喌涓嬪徃鏈洪渶鍋滄鏈嶅姟锛�
+ if (order.getAcceptDriver() != null && Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.accepted.getStatus())) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.REFUNDING, orderId,
+ "orderNo", order.getCode());
+ }
return;
}
@@ -1692,6 +1810,73 @@
orderLogService.create(log);
}
+ /**
+ * 鍙戦�佽鍗曠珯鍐呬俊閫氱煡
+ */
+ private void sendOrderNotice(Integer memberId, Constants.MemberOrderNotify notify, Integer orderId, String... params) {
+ Notice notice = new Notice();
+ notice.setUserType(0); // 0=浼氬憳
+ notice.setUserId(memberId);
+ notice.setTitle(notify.getTitle());
+ notice.setContent(notify.format(params));
+ notice.setObjId(orderId);
+ notice.setObjType(0); // 0=璁㈠崟
+ notice.setStatus(0); // 0=鏈
+ notice.setIsdeleted(Constants.ZERO);
+ notice.setCreateDate(new Date());
+ noticeService.create(notice);
+ }
+
+ /**
+ * 鍙戦�侀棬搴楃珯鍐呬俊閫氱煡
+ */
+ private void sendShopNotice(Integer shopId, Constants.ShopOrderNotify notify, Integer orderId, String... params) {
+ Notice notice = new Notice();
+ notice.setUserType(2); // 2=闂ㄥ簵
+ notice.setUserId(shopId);
+ notice.setTitle(notify.getTitle());
+ notice.setContent(notify.format(params));
+ notice.setObjId(orderId);
+ notice.setObjType(0); // 0=璁㈠崟
+ notice.setStatus(0); // 0=鏈
+ notice.setIsdeleted(Constants.ZERO);
+ notice.setCreateDate(new Date());
+ noticeService.create(notice);
+ }
+
+ /**
+ * 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴楋紙璁㈠崟瀹屾垚/璇勪环绛夛級
+ */
+ private void notifyBothShops(Orders order, Constants.ShopOrderNotify notify, String... params) {
+ if (order.getDepositShopId() != null) {
+ sendShopNotice(order.getDepositShopId(), notify, order.getId(), params);
+ }
+ if (order.getTakeShopId() != null) {
+ sendShopNotice(order.getTakeShopId(), notify, order.getId(), params);
+ }
+ }
+
+ /**
+ * 鍙戦�佸徃鏈虹珯鍐呬俊閫氱煡
+ */
+ private void sendDriverNotice(Integer driverId, Constants.DriverOrderNotify notify, Integer orderId, String... params) {
+ DriverInfo driver = driverInfoMapper.selectById(driverId);
+ if (driver == null || driver.getMemberId() == null) {
+ return;
+ }
+ Notice notice = new Notice();
+ notice.setUserType(1); // 1=鍙告満
+ notice.setUserId(driver.getMemberId());
+ notice.setTitle(notify.getTitle());
+ notice.setContent(notify.format(params));
+ notice.setObjId(orderId);
+ notice.setObjType(0); // 0=璁㈠崟
+ notice.setStatus(0); // 0=鏈
+ notice.setIsdeleted(Constants.ZERO);
+ notice.setCreateDate(new Date());
+ noticeService.create(notice);
+ }
+
@Override
@Transactional(rollbackFor = {Exception.class, BusinessException.class})
public void handleStorageOrderPayNotify(String outTradeNo, String wxTradeNo) {
@@ -1711,10 +1896,40 @@
order.setPayStatus(Constants.ONE); // 宸叉敮浠�
order.setPayTime(now);
order.setWxExternalNo(wxTradeNo);
+ order.setPayAmount(order.getTotalAmount());
order.setUpdateTime(now);
// 鐢熸垚浼氬憳鏍搁攢鐮�
order.setMemberVerifyCode(generateVerifyCode());
+ // 寮傚湴瀵勫瓨锛氳绠楅璁¢�佽揪鏃堕棿
+ if (Constants.ONE.equals(order.getType())
+ && order.getDepositLat() != null && order.getDepositLgt() != null
+ && order.getTakeLat() != null && order.getTakeLgt() != null) {
+ EstimatedDeliveryResultVO deliveryResult = calculateEstimatedDelivery(
+ Integer.valueOf(order.getCityId()),
+ order.getDepositLat().doubleValue(), order.getDepositLgt().doubleValue(),
+ order.getTakeLat().doubleValue(), order.getTakeLgt().doubleValue());
+ // isUrgent: 0=鏍囬�熻揪; 1=鏋侀�熻揪
+ BigDecimal hours = Constants.ONE.equals(order.getIsUrgent())
+ ? deliveryResult.getExpressHours()
+ : deliveryResult.getStandardHours();
+ if (hours != null) {
+ long millis = hours.multiply(new BigDecimal("3600000"))
+ .setScale(0, RoundingMode.HALF_UP).longValue();
+ order.setEstimatedDeliveryTime(new Date(now.getTime() + millis));
+ }
+ }
ordersMapper.updateById(order);
+
+ // 閫氱煡浼氬憳锛氳鍗曞緟鏍搁獙
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_VERIFY, order.getId(),
+ "orderNo", order.getCode(),
+ "storeCode", order.getMemberVerifyCode());
+
+ // 灏卞湴瀵勫瓨璁㈠崟锛氶�氱煡瀛樹欢闂ㄥ簵寰呮牳楠�
+ if (Constants.ZERO.equals(order.getType()) && order.getDepositShopId() != null) {
+ sendShopNotice(order.getDepositShopId(), Constants.ShopOrderNotify.WAIT_VERIFY, order.getId(),
+ "orderNo", order.getCode());
+ }
}
@Override
@@ -1758,8 +1973,9 @@
otherOrders.setCreateTime(now);
otherOrdersMapper.insert(otherOrders);
- // 5. 鍞よ捣寰俊鏀粯
- return wxPayForOtherOrder(otherOrders, member.getOpenid(), Constants.OrdersAttach.OVERDUE_FEE);
+ // 5. 鍞よ捣寰俊鏀粯V3
+ return wxPayV3(otherOrders.getOutTradeNo(), otherOrders.getPayAccount(), otherOrders.getId(),
+ member.getOpenid(), Constants.OrdersAttach.OVERDUE_FEE);
}
@Override
@@ -1826,9 +2042,10 @@
@Override
@Transactional(rollbackFor = {Exception.class, BusinessException.class})
- public PayResponse payShopDeposit(Integer shopId) {
+ public PayResponse payShopDeposit(Integer memberId) {
// 1. 鏌ヨ闂ㄥ簵淇℃伅
- ShopInfo shopInfo = shopInfoMapper.selectById(shopId);
+ ShopInfo shopInfo = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().lambda()
+ .eq(ShopInfo::getRegionMemberId,memberId));
if (shopInfo == null) {
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "闂ㄥ簵涓嶅瓨鍦�");
}
@@ -1852,14 +2069,15 @@
otherOrders.setMemberId(shopInfo.getRegionMemberId());
otherOrders.setPayAccount(shopInfo.getDepositAmount());
otherOrders.setPayStatus(Constants.ZERO);
- otherOrders.setCode("SD" + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(now) + shopId);
+ otherOrders.setCode("SD" + new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(now) + shopInfo.getId());
otherOrders.setOutTradeNo(outTradeNo);
otherOrders.setDeleted(Constants.ZERO);
otherOrders.setCreateTime(now);
otherOrdersMapper.insert(otherOrders);
- // 5. 鍞よ捣寰俊鏀粯
- return wxPayForOtherOrder(otherOrders, member.getOpenid(), Constants.OrdersAttach.SHOP_DEPOSIT);
+ // 5. 鍞よ捣寰俊鏀粯V3
+ return wxPayV3(otherOrders.getOutTradeNo(), otherOrders.getPayAccount(), otherOrders.getId(),
+ member.getOpenid(), Constants.OrdersAttach.SHOP_DEPOSIT);
}
@Override
@@ -1996,6 +2214,20 @@
}
}
}
+
+ // 閫氱煡鐩稿叧闂ㄥ簵锛氳鍗曞凡缁撶畻
+ notifyBothShops(order, Constants.ShopOrderNotify.SETTLED,
+ "orderNo", order.getCode(),
+ "amount", String.valueOf(Constants.getFormatMoney(
+ order.getTotalAmount() != null ? order.getTotalAmount() : 0L)));
+
+ // 閫氱煡鍙告満锛氳鍗曞凡缁撶畻
+ if (order.getAcceptDriver() != null) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.SETTLED, order.getId(),
+ "orderNo", order.getCode(),
+ "amount", String.valueOf(Constants.getFormatMoney(
+ order.getDriverFee() != null ? order.getDriverFee() : 0L)));
+ }
}
}
@@ -2091,6 +2323,20 @@
}
if (isRemote && order.getAcceptDriver() != null) {
updateTargetScore(Constants.THREE, order.getAcceptDriver());
+ }
+
+ // 閫氱煡浼氬憳锛氳鍗曞凡璇勪环
+ sendOrderNotice(memberId, Constants.MemberOrderNotify.EVALUATED, order.getId(),
+ "orderNo", order.getCode());
+
+ // 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴楋細璁㈠崟宸茶瘎浠�
+ notifyBothShops(order, Constants.ShopOrderNotify.EVALUATED,
+ "orderNo", order.getCode());
+
+ // 閫氱煡鍙告満锛氳鍗曞凡璇勪环
+ if (order.getAcceptDriver() != null) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.EVALUATED, order.getId(),
+ "orderNo", order.getCode());
}
}
@@ -2194,6 +2440,16 @@
saveVerifyImages(order.getId(), images, Constants.FileType.ORDER_DEPOSIT.getKey(), shopId);
// 璁板綍璁㈠崟鏃ュ織
saveShopVerifyLog(order, "闂ㄥ簵纭瀵勫瓨", "闂ㄥ簵銆�" + shopName + "銆戠‘璁ゅ瘎瀛�", remark, shopId);
+ // 閫氱煡浼氬憳锛氶棬搴楁牳閿�鎴愬姛
+ if (Constants.equalsInteger(order.getType(), Constants.ONE)) {
+ // 寮傚湴瀵勫瓨 鈫� 寰呮姠鍗�
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_GRAB, order.getId(),
+ "orderNo", order.getCode());
+ } else {
+ // 灏卞湴瀵勫瓨 鈫� 寰呭彇浠舵彁閱�
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.WAIT_PICKUP_REMIND, order.getId(),
+ "orderNo", order.getCode());
+ }
} else if (Constants.equalsInteger(status, Constants.OrderStatus.arrived.getStatus())) {
// 寮傚湴瀵勫瓨 + 鏃犲彇浠堕棬搴� 鈫� 鏃犳硶鏍搁攢锛堝鎴疯嚜鍙栵紝鏃犻棬搴楁搷浣滐級
if (Constants.equalsInteger(order.getType(), Constants.ONE) && order.getTakeShopId() == null) {
@@ -2216,6 +2472,20 @@
generateRevenueRecords(order.getId());
// 璁板綍璁㈠崟鏃ュ織
saveShopVerifyLog(order, "闂ㄥ簵纭鍙栦欢", "闂ㄥ簵銆�" + shopName + "銆戠‘璁ゅ彇浠讹紝璁㈠崟瀹屾垚", remark, shopId);
+ // 閫氱煡浼氬憳锛氳鍗曞凡瀹屾垚
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.FINISHED, order.getId(),
+ "orderNo", order.getCode());
+ // 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴楋細璁㈠崟宸插畬鎴�
+ String settleDays = operationConfigBiz.getConfig().getSettlementDate();
+ notifyBothShops(order, Constants.ShopOrderNotify.FINISHED,
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ // 閫氱煡鍙告満锛氳鍗曞凡瀹屾垚
+ if (order.getAcceptDriver() != null) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.FINISHED, order.getId(),
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ }
} else {
throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠璁㈠崟鐘舵�佷笉鍏佽鏍搁攢");
}
@@ -2292,13 +2562,14 @@
refundRecord.setDeleted(Constants.ZERO);
ordersRefundMapper.insert(refundRecord);
- // 璋冪敤寰俊閫�娆撅紙鏀惧湪鏈�鍚庯紝纭繚鍓嶇疆鎿嶄綔鍏ㄩ儴鎴愬姛锛�
- String refundCode = wxMiniUtilService.wxRefund(
- order.getOutTradeNo(), order.getPayAmount(), order.getRefundAmount());
+ // 璋冪敤寰俊閫�娆綱3锛堟斁鍦ㄦ渶鍚庯紝纭繚鍓嶇疆鎿嶄綔鍏ㄩ儴鎴愬姛锛�
+ Refund refundResult = wxPayV3Service.refund(
+ order.getOutTradeNo(), order.getPayAmount(), order.getRefundAmount(),
+ "璁㈠崟閫�娆�", wxPayProperties.getV3RefundNotifyUrl());
- // 閫�娆炬垚鍔熷悗鍥炲~閫�娆惧崟鍙峰拰鏃堕棿
- refundRecord.setRefundCode(refundCode);
- refundRecord.setRefundTime(new Date());
+ // 閫�娆炬垚鍔熷悗鍥炲~閫�娆惧崟鍙凤紝鏍囪閫�娆句腑
+ refundRecord.setRefundCode(refundResult.getOutRefundNo());
+ refundRecord.setStatus(Constants.ZERO); // 閫�娆句腑
ordersRefundMapper.updateById(refundRecord);
}
@@ -2312,6 +2583,72 @@
logInfo += "锛岄��娆�" + Constants.getFormatMoney(order.getRefundAmount()) + "鍏�";
}
saveShopVerifyLog(order, "闂ㄥ簵纭鍑哄簱", logInfo, remark, shopId);
+ // 閫氱煡浼氬憳锛氳鍗曞凡瀹屾垚
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.FINISHED, order.getId(),
+ "orderNo", order.getCode());
+ // 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴楋細璁㈠崟宸插畬鎴�
+ String settleDays = operationConfigBiz.getConfig().getSettlementDate();
+ notifyBothShops(order, Constants.ShopOrderNotify.FINISHED,
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ // 閫氱煡鍙告満锛氳鍗曞凡瀹屾垚
+ if (order.getAcceptDriver() != null) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.FINISHED, order.getId(),
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ }
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void memberConfirmReceipt(Integer orderId, Integer memberId) {
+ // 1. 鏌ヨ璁㈠崟
+ Orders order = ordersMapper.selectById(orderId);
+ if (order == null || Constants.equalsInteger(order.getDeleted(), Constants.ONE)) {
+ throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "璁㈠崟涓嶅瓨鍦�");
+ }
+ // 2. 鏍¢獙褰掑睘
+ if (!memberId.equals(order.getMemberId())) {
+ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "鏃犳潈鎿嶄綔璇ヨ鍗�");
+ }
+ // 3. 鏍¢獙璁㈠崟绫诲瀷锛氬紓鍦板瘎瀛�
+ if (!Constants.ONE.equals(order.getType())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "浠呭紓鍦板瘎瀛樿鍗曞彲鎿嶄綔");
+ }
+ // 4. 鏍¢獙鏃犲彇浠堕棬搴�
+ if (order.getTakeShopId() != null) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "璇ヨ鍗曟湁鍙栦欢闂ㄥ簵锛岄渶闂ㄥ簵纭鍑哄簱");
+ }
+ // 5. 鏍¢獙鐘舵�侊細宸查�佽揪(5)
+ if (!Constants.equalsInteger(order.getStatus(), Constants.OrderStatus.arrived.getStatus())) {
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "褰撳墠璁㈠崟鐘舵�佷笉鍏佽纭鏀惰揣");
+ }
+
+ // 6. 鏇存柊璁㈠崟鐘舵�佷负宸插畬鎴�
+ Date now = new Date();
+ order.setStatus(Constants.OrderStatus.finished.getStatus());
+ order.setFinishTime(now);
+ order.setUpdateTime(now);
+ ordersMapper.updateById(order);
+
+ // 7. 鐢熸垚鏀剁泭璁板綍
+ calculateAndSaveOrderFees(orderId);
+ generateRevenueRecords(orderId);
+
+ // 閫氱煡浼氬憳锛氳鍗曞凡瀹屾垚
+ sendOrderNotice(memberId, Constants.MemberOrderNotify.FINISHED, orderId,
+ "orderNo", order.getCode());
+ // 閫氱煡瀛樹欢闂ㄥ簵鍜屽彇浠堕棬搴楋細璁㈠崟宸插畬鎴�
+ String settleDays = operationConfigBiz.getConfig().getSettlementDate();
+ notifyBothShops(order, Constants.ShopOrderNotify.FINISHED,
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ // 閫氱煡鍙告満锛氳鍗曞凡瀹屾垚
+ if (order.getAcceptDriver() != null) {
+ sendDriverNotice(order.getAcceptDriver(), Constants.DriverOrderNotify.FINISHED, order.getId(),
+ "orderNo", order.getCode(),
+ "settleDays", settleDays != null ? settleDays : "7");
+ }
}
@Override
@@ -2463,6 +2800,26 @@
// 淇濆瓨闄勪欢锛坥bj_type=3 闂ㄥ簵鍏ュ簱鍥剧墖锛屾渶澶�3寮狅級
saveVerifyImages(order.getId(), images, Constants.FileType.ORDER_TAKE.getKey(), driverId);
+
+ // 閫氱煡浼氬憳锛氳鍗曞凡閫佽揪
+ String destination = order.getTakeShopAddress() != null ? order.getTakeShopAddress() : "";
+ if (order.getMemberVerifyCode() != null) {
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.ARRIVED_HAS_SHOP, order.getId(),
+ "orderNo", order.getCode(),
+ "destination", destination,
+ "pickupCode", order.getMemberVerifyCode());
+ } else {
+ sendOrderNotice(order.getMemberId(), Constants.MemberOrderNotify.ARRIVED_NO_SHOP, order.getId(),
+ "orderNo", order.getCode(),
+ "destination", destination);
+ }
+
+ // 閫氱煡鍙栦欢闂ㄥ簵锛氳鍗曞凡閫佽揪
+ if (order.getTakeShopId() != null) {
+ sendShopNotice(order.getTakeShopId(), Constants.ShopOrderNotify.ARRIVED, order.getId(),
+ "orderNo", order.getCode(),
+ "destination", destination);
+ }
}
/**
@@ -2857,4 +3214,84 @@
return Math.max(days, 0);
}
+ @Override
+ public ActiveOrderTipVO getActiveOrderTip(Integer memberId) {
+ // 鏌ヨ鐘舵�佷负 0~5 鐨勬渶鏂颁竴鏉¤鍗�
+ QueryWrapper<Orders> wrapper = new QueryWrapper<>();
+ wrapper.eq("MEMBER_ID", memberId)
+ .in("STATUS", 0, 1, 2, 3, 4, 5)
+ .orderByDesc("CREATE_TIME")
+ .last("LIMIT 1");
+ Orders order = ordersMapper.selectOne(wrapper);
+ if (order == null) {
+ return null;
+ }
+
+ ActiveOrderTipVO vo = new ActiveOrderTipVO();
+ vo.setOrderId(order.getId());
+ vo.setStatus(order.getStatus());
+
+ // 鏋勫缓鎻愮ず鏂囨
+ boolean isLocal = Constants.equalsInteger(order.getType(), Constants.ZERO);
+ Integer status = order.getStatus();
+ String tip = null;
+
+ if (Constants.equalsInteger(status, Constants.OrderStatus.waitPay.getStatus())) {
+ // 寰呮敮浠橈細鎻愮ず鏀粯鍊掕鏃�
+ String minutes = "";
+ try {
+ minutes = operationConfigBiz.getConfig().getAutoCancelTime();
+ } catch (Exception ignored) {}
+ tip = "璇峰湪" + (StringUtils.isNotBlank(minutes) ? minutes : "") + "鍒嗛挓鍐呭畬鎴愭敮浠橈紝瓒呮椂璁㈠崟灏嗚嚜鍔ㄥ彇娑�";
+
+ // 璁$畻鏀粯鍊掕鏃�
+ if (StringUtils.isNotBlank(minutes) && order.getCreateTime() != null) {
+ long timeoutMs = Long.parseLong(minutes) * 60 * 1000;
+ long deadline = order.getCreateTime().getTime() + timeoutMs;
+ long remain = deadline - System.currentTimeMillis();
+ vo.setPayCountdown(remain > 0 ? remain : -1L);
+ } else {
+ vo.setPayCountdown(-1L);
+ }
+ } else if (Constants.equalsInteger(status, Constants.OrderStatus.waitDeposit.getStatus())) {
+ tip = "璁㈠崟宸叉敮浠橈紝璇峰墠寰�闂ㄥ簵瀵勫瓨";
+ } else if (Constants.equalsInteger(status, Constants.OrderStatus.deposited.getStatus())) {
+ tip = isLocal ? "琛屾潕宸插瘎瀛橈紝璇峰嚟鍙栦欢鐮佸墠寰�鎸囧畾闂ㄥ簵鍙栦欢" : "闂ㄥ簵宸叉帴鍗曪紝姝e湪涓烘偍瀹夋帓鍙栦欢鍙告満";
+ } else if (Constants.equalsInteger(status, Constants.OrderStatus.accepted.getStatus())) {
+ tip = isLocal ? "琛屾潕宸插瘎瀛橈紝璇峰嚟鍙栦欢鐮佸墠寰�鎸囧畾闂ㄥ簵鍙栦欢" : "宸叉湁鍙告満鎶㈠崟锛屾鍓嶅線鍙栦欢鍦扮偣";
+ } else if (Constants.equalsInteger(status, Constants.OrderStatus.delivering.getStatus())) {
+ tip = "鍙告満宸插彇浠讹紝姝h繍寰�鐩殑鍦�";
+ } else if (Constants.equalsInteger(status, Constants.OrderStatus.arrived.getStatus())) {
+ tip = "琛屾潕宸查�佽揪鏈嶅姟鐐癸紝璇峰強鏃跺墠寰�鍙栦欢";
+ }
+
+ vo.setTip(tip);
+ return vo;
+ }
+
+ @Override
+ public EstimatedDeliveryResultVO calculateEstimatedDelivery(Integer cityId,
+ Double fromLat, Double fromLng,
+ Double toLat, Double toLng) {
+ // 鑵捐鍦板浘璺濈鐭╅樀API璁$畻瀹為檯璺濈
+ String from = fromLat + "," + fromLng;
+ String to = toLat + "," + toLng;
+ JSONObject distanceResult = MapUtil.direction("driving", from, to);
+
+ // 鑾峰彇璺濈锛堢背锛夛紝杞叕閲�
+ int distanceMeters = distanceResult.getIntValue("distance");
+ BigDecimal distanceKm = new BigDecimal(distanceMeters)
+ .divide(new BigDecimal("1000"), 2, RoundingMode.HALF_UP);
+
+ // 鏍规嵁pricing_rule type=2 璁$畻 鏍囬�熻揪(1) 鍜� 鏋侀�熻揪(2) 鏃舵晥
+ BigDecimal standardTime = pricingRuleService.calculateEstimatedTime(cityId, 1, distanceKm);
+ BigDecimal expressTime = pricingRuleService.calculateEstimatedTime(cityId, 2, distanceKm);
+
+ EstimatedDeliveryResultVO vo = new EstimatedDeliveryResultVO();
+ vo.setDistanceKm(distanceKm);
+ vo.setStandardHours(standardTime);
+ vo.setExpressHours(expressTime);
+ return vo;
+ }
+
}
--
Gitblit v1.9.3