OpenApiOrderValuationServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. package com.ydd.app.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.ydd.app.dto.OrderValuationDto;
  4. import com.ydd.app.dto.OrderValuationReq;
  5. import com.ydd.app.dto.ValuationRes;
  6. import com.ydd.app.response.OrderValuationResponse;
  7. import com.ydd.app.service.OpenApiOrderValuationService;
  8. import com.ydd.app.vo.OrderValuationVo;
  9. import com.ydd.common.constant.BillingConstant;
  10. import com.ydd.common.core.domain.ResponseResult;
  11. import com.ydd.common.enums.DeliveryTypeEnums;
  12. import com.ydd.common.enums.ResponseResultCodeEnum;
  13. import com.ydd.common.utils.SnCodeUtils;
  14. import com.ydd.common.utils.StringUtils;
  15. import com.ydd.ecloud.core.utils.BigDecimalUtils;
  16. import com.ydd.module.domain.*;
  17. import com.ydd.module.dto.*;
  18. import com.ydd.module.enums.*;
  19. import com.ydd.module.service.*;
  20. import lombok.RequiredArgsConstructor;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.collections4.CollectionUtils;
  23. import org.apache.commons.compress.utils.Lists;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import java.math.BigDecimal;
  28. import java.util.*;
  29. import java.util.stream.Collectors;
  30. /**
  31. * 开放接口-订单计价ServiceImpl
  32. * @author 叶君翔
  33. * @date 2022/04/08 15:51
  34. */
  35. @Slf4j
  36. @Service
  37. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  38. public class OpenApiOrderValuationServiceImpl implements OpenApiOrderValuationService {
  39. private final IShopService iShopService;
  40. private final IMemberService iMemberService;
  41. private final IProductService iProductService;
  42. private final IPackageCityConfigService iPackageCityConfigService;
  43. private final IPackageDeliveryService iPackageDeliveryService;
  44. private final IPackageDiscountService iPackageDiscountService;
  45. private final IPackageDiscountDetailService iPackageDiscountDetailService;
  46. private final IPackageCommissionService iPackageCommissionService;
  47. private final IPackageCommissionDetailService iPackageCommissionDetailService;
  48. private final IDspDeliveryService iDspDeliveryService;
  49. private final IShopDeliveryDisableService iShopDeliveryDisableService;
  50. private final IShopDeliveryService iShopDeliveryService;
  51. private final IMemberConfigService iMemberConfigService;
  52. @Override
  53. public ResponseResult valuation(OrderValuationReq valuationReq) {
  54. OrderValuationDto valuationDto = new OrderValuationDto();
  55. // 参数校验
  56. ResponseResult result = this.validParam(valuationReq, valuationDto);
  57. if (result.getCode() != ResponseResultCodeEnum.SUCCESS.getCode()) {
  58. return result;
  59. }
  60. Product product = iProductService.getById(valuationReq.getCategoryId());
  61. if (product == null) {
  62. return ResponseResult.error(ResponseResultCodeEnum.CATEGORY_NOT_EXIST);
  63. }
  64. valuationDto.setProduct(product);
  65. valuationDto.setOrderSn(SnCodeUtils.createSn());
  66. valuationDto.setTakeType(0);
  67. // 开放平台大商户对应的用户
  68. Member member = iMemberService.getOne(new QueryWrapper<Member>().eq("member_type", MemberTypeEnum.MERCHANT.type).eq("merchant_id", valuationDto.getMerchantId()));
  69. // 获取最匹配的运力包(门店 > 城市 > 全国)
  70. Long deliveryPackageId = iPackageCityConfigService.getPackageId(valuationDto.getShopId(), member, null, PackageCityConfigPackageTypeEnum.DELIVERY.type);
  71. List<Integer> types = Lists.newArrayList();
  72. PackageDeliveryDto packageDeliveryDto = null;
  73. if (deliveryPackageId != null) {
  74. packageDeliveryDto = iPackageDeliveryService.getDeliveryDtoByPackageIdAndDeliveryType(deliveryPackageId);
  75. List<PackageDeliveryDetailDto> deliveryDetailDtoList = packageDeliveryDto.getPackageDeliveryDetailDtoList();
  76. if (CollectionUtils.isNotEmpty(deliveryDetailDtoList)) {
  77. types = deliveryDetailDtoList.stream().map(PackageDeliveryDetailDto::getDeliveryType).collect(Collectors.toList());
  78. }
  79. }
  80. // 获取门店屏蔽运力
  81. List<Integer> disableDeliveryTypes = iShopDeliveryDisableService.list(new QueryWrapper<ShopDeliveryDisable>()
  82. .eq("shop_id", valuationDto.getShopId()).eq("deleted", 0))
  83. .stream().map(ShopDeliveryDisable::getDeliveryType).collect(Collectors.toList());
  84. if (CollectionUtils.isNotEmpty(disableDeliveryTypes)) {
  85. types.removeAll(disableDeliveryTypes);
  86. }
  87. // 获取可用发单运力
  88. List<DeliveryInfo> deliveryInfos = this.getDeliveryInfos(valuationDto, types);
  89. if (CollectionUtils.isEmpty(deliveryInfos)) {
  90. log.warn("无可用发单运力!");
  91. return ResponseResult.error(ResponseResultCodeEnum.NO_DELIVERY);
  92. }
  93. List<Integer> deliveryTypes = deliveryInfos.stream().map(DspDelivery::getType).collect(Collectors.toList());
  94. // 获取最匹配的优惠包(门店 > 代理商 > 全国)
  95. Long discountPackageId = iPackageCityConfigService.getPackageId(valuationDto.getShopId(), member, null, PackageCityConfigPackageTypeEnum.DISCOUNT.type);
  96. Map<Integer, List<PackageDiscountDetailDto>> packageDiscountMap = new HashMap<>();
  97. if (discountPackageId != null) {
  98. List<PackageDiscountDetailDto> discountDetailDtoList = iPackageDiscountDetailService.getDiscountListByPackageIdAndDeliveryType(discountPackageId, deliveryTypes);
  99. packageDiscountMap = discountDetailDtoList.stream().collect(Collectors.groupingBy(PackageDiscountDetailDto::getDeliveryType));
  100. }
  101. // 获取最匹配的佣金包(门店 > 代理商 > 全国)
  102. Long commissionPackageId = iPackageCityConfigService.getPackageId(valuationDto.getShopId(), member, null, PackageCityConfigPackageTypeEnum.COMMISSION.type);
  103. Map<Integer, List<PackageCommissionDetailDto>> packageCommissionMap = new HashMap<>();
  104. if (commissionPackageId != null) {
  105. List<PackageCommissionDetailDto> commissionDetailDtoList = iPackageCommissionDetailService.getCommissionListByPackageIdAndDeliveryType(commissionPackageId, deliveryTypes);
  106. packageCommissionMap = commissionDetailDtoList.stream().collect(Collectors.groupingBy(PackageCommissionDetailDto::getDeliveryType));
  107. }
  108. // 计价
  109. List<ValuationRes> list = this.getValuationResList(member, valuationDto, deliveryInfos, packageDeliveryDto, packageDiscountMap, packageCommissionMap);
  110. // 默认价格优先
  111. list.sort(Comparator.comparing(ValuationRes::getDeliveryAmount));
  112. // 运力包发单类型为自定义, 则先按照sort排,再按价格排
  113. if (packageDeliveryDto != null && PackageDeliveryTypeEnum.CUSTOM.type.equals(packageDeliveryDto.getType())) {
  114. Collections.sort(list);
  115. }
  116. // 处理发单运力
  117. List<ValuationRes> billList = this.handleBillList(member.getId(), list);
  118. // 设置发单时长
  119. if (packageDeliveryDto != null) {
  120. billList = this.setBillingDuration(packageDeliveryDto, billList);
  121. }
  122. // todo: 计价结果缓存到redis, 10分钟有效
  123. // 数据转换
  124. List<OrderValuationVo> valuationVos = this.convertResult(billList);
  125. OrderValuationResponse response = OrderValuationResponse.builder().valuationList(valuationVos).outOrderSn(valuationReq.getOutOrderSn()).build();
  126. return ResponseResult.success(response);
  127. }
  128. private List<OrderValuationVo> convertResult(List<ValuationRes> billList) {
  129. // todo: 数据转换
  130. return null;
  131. }
  132. private List<ValuationRes> handleBillList(Long memberId, List<ValuationRes> list) {
  133. // 查询下单设置推荐屏蔽运力
  134. List<ValuationRes> billList = Lists.newArrayList();
  135. MemberConfig config = iMemberConfigService.getOne(new QueryWrapper<MemberConfig>().eq("member_id", memberId));
  136. if (config != null) {
  137. if (StringUtils.isNotEmpty(config.getBillDeliveryIds())) {
  138. List<String> billDeliveryIds = Arrays.asList(config.getBillDeliveryIds().split(","));
  139. // 过滤出商家设置的推荐运力, 计价页面靠前显示
  140. billList = list.stream().filter(a -> billDeliveryIds.contains(a.getDeliveryId().toString())).collect(Collectors.toList());
  141. }
  142. if (StringUtils.isNotEmpty(config.getShieldDeliveryIds())) {
  143. List<String> shieldDeliveryIds = Arrays.asList(config.getShieldDeliveryIds().split(","));
  144. // 过滤掉商家设置的屏蔽运力
  145. list = list.stream().filter(a -> !shieldDeliveryIds.contains(a.getDeliveryId().toString())).collect(Collectors.toList());
  146. }
  147. }
  148. list.removeAll(billList);
  149. billList.addAll(list);
  150. // 闪送距离替换
  151. Optional<ValuationRes> optional = billList.stream().filter(item -> !item.getDeliveryType().equals(DeliveryTypeEnums.SHAN_SONG.getType())).findFirst();
  152. if (optional.isPresent()) {
  153. String desc = optional.get().getDesc();
  154. for (ValuationRes res1 : billList) {
  155. if (DeliveryTypeEnums.SHAN_SONG.getType().equals(res1.getDeliveryType())) {
  156. res1.setDesc(desc);
  157. break;
  158. }
  159. }
  160. }
  161. return billList;
  162. }
  163. private List<ValuationRes> getValuationResList(Member member, OrderValuationDto valuationDto, List<DeliveryInfo> deliveryInfos, PackageDeliveryDto packageDeliveryDto, Map<Integer, List<PackageDiscountDetailDto>> packageDiscountMap, Map<Integer, List<PackageCommissionDetailDto>> packageCommissionMap) {
  164. List<ValuationRes> valuationResList = Lists.newArrayList();
  165. for (DeliveryInfo info : deliveryInfos) {
  166. // 计价
  167. ValuationRes valuationRes = this.doValuation(valuationDto, info, valuationDto.getMerchantId(), valuationDto.getShopId());
  168. if (valuationRes == null) {
  169. continue;
  170. }
  171. valuationRes.setPreferredDelivery(info.getPreferredDelivery());
  172. valuationRes.setOriginalMoney(valuationRes.getDeliveryAmount());
  173. // 设置排序
  174. if (packageDeliveryDto != null && PackageDeliveryTypeEnum.CUSTOM.type.equals(packageDeliveryDto.getType())) {
  175. this.setBillingSort(packageDeliveryDto, valuationRes);
  176. }
  177. // 设置优惠
  178. if (packageDiscountMap.size() > 0) {
  179. this.setDiscountInfo(packageDiscountMap.get(info.getType()), valuationRes);
  180. }
  181. // 设置佣金
  182. if (packageCommissionMap.size() > 0) {
  183. this.setCommissionInfo(packageCommissionMap.get(info.getType()), valuationRes);
  184. }
  185. valuationRes.setIsMerchant(info.getIsMerchant());
  186. if (valuationRes.getIsMine() == 0) {
  187. // 校验余额是否充足
  188. if (member.getAmount().compareTo(valuationRes.getDeliveryAmount()) >= 0) {
  189. valuationRes.setIsEnough(StatusEnum.SHOW.status);
  190. }
  191. }
  192. valuationResList.add(valuationRes);
  193. }
  194. return valuationResList;
  195. }
  196. private ValuationRes doValuation(OrderValuationDto valuationDto, DeliveryInfo info, Long merchantId, Long shopId) {
  197. // todo: 计价主逻辑
  198. return null;
  199. }
  200. private void setBillingSort(PackageDeliveryDto packageDeliveryDto, ValuationRes valuationRes) {
  201. List<PackageDeliveryDetailDto> deliveryDetailDtoList = packageDeliveryDto.getPackageDeliveryDetailDtoList();
  202. if (CollectionUtils.isNotEmpty(deliveryDetailDtoList)) {
  203. Optional<PackageDeliveryDetailDto> optional = deliveryDetailDtoList.stream().filter(item -> valuationRes.getDeliveryType().equals(item.getDeliveryType())).findFirst();
  204. if (optional.isPresent()) {
  205. PackageDeliveryDetailDto packageDeliveryDetailDto = optional.get();
  206. valuationRes.setSort((packageDeliveryDetailDto.getSort() == null || packageDeliveryDetailDto.getSort() == 0) ? BillingConstant.DEFAULT_BILL_SORT : packageDeliveryDetailDto.getSort());
  207. }
  208. }
  209. }
  210. private List<ValuationRes> setBillingDuration(PackageDeliveryDto packageDeliveryDto, List<ValuationRes> billList) {
  211. String billDurationStr = packageDeliveryDto.getBillDurationStr();
  212. List<PackageDeliveryDetailDto> deliveryDetailList = packageDeliveryDto.getPackageDeliveryDetailDtoList();
  213. if (StringUtils.isNotEmpty(billDurationStr) && CollectionUtils.isNotEmpty(deliveryDetailList)) {
  214. String[] split = billDurationStr.split(",");
  215. if (PackageDeliveryTypeEnum.CUSTOM.type.equals(packageDeliveryDto.getType())) {
  216. deliveryDetailList = deliveryDetailList.stream().filter(item -> item.getSort() != null && item.getSort() > 0).collect(Collectors.toList());
  217. deliveryDetailList.sort(Comparator.comparing(PackageDeliveryDetailDto::getSort));
  218. for (int i = 0; i < deliveryDetailList.size(); i++) {
  219. PackageDeliveryDetailDto packageDeliveryDetailDto = deliveryDetailList.get(i);
  220. if (i < split.length) {
  221. packageDeliveryDetailDto.setBillDuration(Integer.parseInt(split[i]));
  222. }
  223. }
  224. for (ValuationRes valuationRes : billList) {
  225. int billDuration = BillingConstant.DEFAULT_BILL_DURATION;
  226. Optional<PackageDeliveryDetailDto> optional = deliveryDetailList.stream().filter(item -> item.getDeliveryType().equals(valuationRes.getDeliveryType())).findAny();
  227. if (optional.isPresent()) {
  228. PackageDeliveryDetailDto packageDeliveryDetailDto = optional.get();
  229. billDuration = packageDeliveryDetailDto.getBillDuration();
  230. }
  231. valuationRes.setBillDuration(billDuration == 0 ? BillingConstant.DEFAULT_BILL_DURATION : billDuration);
  232. }
  233. } else {
  234. for (int i = 0; i < billList.size(); i++) {
  235. ValuationRes valuationRes = billList.get(i);
  236. int billDuration = BillingConstant.DEFAULT_BILL_DURATION;
  237. if (i < split.length) {
  238. billDuration = Integer.parseInt(split[i]);
  239. }
  240. valuationRes.setBillDuration(billDuration);
  241. }
  242. }
  243. } else {
  244. billList = billList.stream().map(valuationRes -> valuationRes.setBillDuration(BillingConstant.DEFAULT_BILL_DURATION)).collect(Collectors.toList());
  245. }
  246. return billList;
  247. }
  248. private void setCommissionInfo(List<PackageCommissionDetailDto> packageCommissionDetailDtoList, ValuationRes valuationRes) {
  249. BigDecimal commission = BigDecimal.ZERO;
  250. if (valuationRes.getIsMine() == 1 || DeliveryTypeEnums.HUO_LA_LA.getType().equals(valuationRes.getDeliveryType())) {
  251. valuationRes.setCommission(commission);
  252. return;
  253. }
  254. if (CollectionUtils.isNotEmpty(packageCommissionDetailDtoList) && packageCommissionDetailDtoList.size() > 0) {
  255. PackageCommissionDetailDto packageCommissionDetailDto = packageCommissionDetailDtoList.get(0);
  256. if (PackageCommissionTypeEnum.RATE.type.equals(packageCommissionDetailDto.getCommissionType())) {
  257. if (packageCommissionDetailDto.getValue() != null) {
  258. commission = packageCommissionDetailDto.getValue().multiply(valuationRes.getDeliveryAmount())
  259. .divide(new BigDecimal("100"), BigDecimal.ROUND_HALF_UP).setScale(6, BigDecimal.ROUND_HALF_UP);
  260. }
  261. } else if (PackageDiscountDetailTypeEnum.GRADIENT.type.equals(packageCommissionDetailDto.getCommissionType())) {
  262. for (PackageCommissionDetailDto item : packageCommissionDetailDtoList) {
  263. boolean inRange = BigDecimalUtils.inRange(item.getLeftValue(), item.getRightValue(), valuationRes.getDeliveryAmount());
  264. if (inRange) {
  265. if (item.getValue() != null) {
  266. commission = item.getValue();
  267. }
  268. break;
  269. }
  270. }
  271. }
  272. }
  273. valuationRes.setCommission(commission);
  274. valuationRes.setDeliveryAmount(commission.add(valuationRes.getDeliveryAmount()));
  275. }
  276. private void setDiscountInfo(List<PackageDiscountDetailDto> discountDetailDtoList, ValuationRes valuationRes) {
  277. if (valuationRes.getIsMine() == 1) {
  278. return;
  279. }
  280. if (CollectionUtils.isNotEmpty(discountDetailDtoList) && discountDetailDtoList.size() > 0) {
  281. PackageDiscountDetailDto discountDetailDto = discountDetailDtoList.get(0);
  282. if (PackageDiscountDetailTypeEnum.ZHE_KOU.type.equals(discountDetailDto.getType())) {
  283. if (discountDetailDto.getValue() != null) {
  284. BigDecimal discountValue = discountDetailDto.getValue().multiply(valuationRes.getDeliveryAmount())
  285. .divide(BigDecimal.TEN, BigDecimal.ROUND_HALF_UP).setScale(6, BigDecimal.ROUND_HALF_UP);
  286. double abs = Math.abs(valuationRes.getDeliveryAmount().subtract(discountValue).doubleValue());
  287. if (discountDetailDto.getMaxValue() != null) {
  288. abs = Math.min(abs, discountDetailDto.getMaxValue().doubleValue());
  289. }
  290. // 判断是优惠还是提价
  291. boolean positiveNum = discountValue.subtract(valuationRes.getDeliveryAmount()).compareTo(BigDecimal.ZERO) >= 0;
  292. if (positiveNum) {
  293. valuationRes.setDeliveryAmount(valuationRes.getDeliveryAmount().add(new BigDecimal(abs)));
  294. } else {
  295. valuationRes.setDeliveryAmount(valuationRes.getDeliveryAmount().subtract(new BigDecimal(abs)));
  296. }
  297. valuationRes.setZk(discountDetailDto.getValue());
  298. }
  299. } else if (PackageDiscountDetailTypeEnum.GRADIENT.type.equals(discountDetailDto.getType())) {
  300. for (PackageDiscountDetailDto item : discountDetailDtoList) {
  301. boolean inRange = BigDecimalUtils.inRange(item.getLeftValue(), item.getRightValue(), valuationRes.getDeliveryAmount());
  302. if (inRange) {
  303. if (item.getValue() != null) {
  304. BigDecimal discountAmount = valuationRes.getDeliveryAmount().subtract(item.getValue());
  305. valuationRes.setDeliveryAmount(discountAmount.compareTo(BigDecimal.ZERO) > 0 ? discountAmount : BigDecimal.ZERO);
  306. valuationRes.setMj(item.getValue());
  307. }
  308. break;
  309. }
  310. }
  311. }
  312. }
  313. }
  314. private List<DeliveryInfo> getDeliveryInfos(OrderValuationDto valuationDto, List<Integer> types) {
  315. List<DspDelivery> list = iDspDeliveryService.list(new QueryWrapper<DspDelivery>()
  316. .isNotNull("parent_id")
  317. .eq("status", StatusEnum.SHOW.status)
  318. .eq("deleted", IsDeleteEnum.NORMAL.status)
  319. .ne("type", DeliveryTypeEnums.HUO_LA_LA.getType())
  320. .in(CollectionUtils.isNotEmpty(types), "type", types));
  321. List<DeliveryInfo> infos = Lists.newArrayList();
  322. List<Integer> deliveryTypes = Arrays.asList(DeliveryTypeEnums.DADA.getType(), DeliveryTypeEnums.DADA_YZ.getType(),
  323. DeliveryTypeEnums.DWD.getType(), DeliveryTypeEnums.FENG_NIAO.getType(), DeliveryTypeEnums.FENG_NIAO_PT.getType(),
  324. DeliveryTypeEnums.MEI_TUAN.getType(), DeliveryTypeEnums.SHAN_SONG.getType(), DeliveryTypeEnums.SHUN_FENG.getType());
  325. List<Long> deliveryIds = list.stream().map(DspDelivery::getId).collect(Collectors.toList());
  326. Map<String, List<ShopDelivery>> deliveryMap = new HashMap<>();
  327. if (CollectionUtils.isNotEmpty(deliveryIds)) {
  328. deliveryMap = iShopDeliveryService.list(new QueryWrapper<ShopDelivery>()
  329. .eq("merchant_id", valuationDto.getMerchantId())
  330. .in("delivery_id", deliveryIds)
  331. .eq("deleted", IsDeleteEnum.NORMAL.status)
  332. .eq("shop_id", valuationDto.getShopId())
  333. .eq("bind_status",1))
  334. .stream()
  335. .collect(Collectors.groupingBy(item -> item.getDeliveryId() + "-" + item.getMerchantId() + "-" + item.getShopId()));
  336. }
  337. for (DspDelivery delivery : list) {
  338. DeliveryInfo info = new DeliveryInfo();
  339. BeanUtils.copyProperties(delivery, info);
  340. if (deliveryTypes.contains(info.getType()) && valuationDto.getMerchantId() != null && valuationDto.getShopId() != null) {
  341. List<ShopDelivery> shopDeliveries = deliveryMap.get(info.getId() + "-" + valuationDto.getMerchantId() + "-" + valuationDto.getShopId());
  342. ShopDelivery sd = new ShopDelivery();
  343. if (CollectionUtils.isNotEmpty(shopDeliveries)) {
  344. sd = shopDeliveries.get(0);
  345. }
  346. if (sd.getThirdShopId() != null && (DeliveryTypeEnums.DADA.getType().equals(info.getType())
  347. || DeliveryTypeEnums.DADA_YZ.getType().equals(info.getType())
  348. || DeliveryTypeEnums.SHAN_SONG.getType().equals(info.getType()))) {
  349. info.setShopId(sd.getThirdShopId());
  350. }
  351. if(sd.getThirdShopId() != null && (DeliveryTypeEnums.FENG_NIAO.getType().equals(info.getType())
  352. || DeliveryTypeEnums.FENG_NIAO_PT.getType().equals(info.getType())
  353. || DeliveryTypeEnums.MEI_TUAN.getType().equals(info.getType()))) {
  354. info.setThirdShopId(sd.getThirdShopId());
  355. }
  356. }
  357. info.setIsMine(0);
  358. infos.add(info);
  359. }
  360. return infos;
  361. }
  362. private ResponseResult validParam(OrderValuationReq valuationReq, OrderValuationDto valuationDto) {
  363. ResponseResult result = ResponseResult.success();
  364. if (StringUtils.isBlank(valuationReq.getShopCode())) {
  365. if (StringUtils.isBlank(valuationReq.getSendName())) {
  366. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人名称", null);
  367. }
  368. if (StringUtils.isBlank(valuationReq.getSendPhone())) {
  369. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人联系电话", null);
  370. }
  371. if (StringUtils.isBlank(valuationReq.getSendProvinceName())) {
  372. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人所在省", null);
  373. }
  374. if (StringUtils.isBlank(valuationReq.getSendCityName())) {
  375. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人所在市", null);
  376. }
  377. if (StringUtils.isBlank(valuationReq.getSendAddress())) {
  378. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人详细地址", null);
  379. }
  380. if (StringUtils.isBlank(valuationReq.getSendLng())) {
  381. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人纬度", null);
  382. }
  383. if (StringUtils.isBlank(valuationReq.getSendLat())) {
  384. return ResponseResult.error(ResponseResultCodeEnum.FIELD_EMPTY, "发件人经度", null);
  385. }
  386. } else {
  387. Shop shop = iShopService.getByCode(valuationReq.getShopCode());
  388. if (shop == null) {
  389. return ResponseResult.error(ResponseResultCodeEnum.SHOP_NOT_EXIST);
  390. }
  391. valuationReq.setSendName(shop.getContactName());
  392. valuationReq.setSendPhone(shop.getMobile());
  393. valuationReq.setSendProvinceName(shop.getProvinceName());
  394. valuationReq.setSendCityName(shop.getCityName());
  395. valuationReq.setSendDistrictName(shop.getDistrictName());
  396. valuationReq.setSendAddress(shop.getAddress());
  397. valuationReq.setSendHouseNumber(shop.getStreet());
  398. valuationReq.setSendLat(shop.getLat());
  399. valuationReq.setSendLng(shop.getLng());
  400. valuationDto.setShopId(shop.getId());
  401. valuationDto.setShopName(shop.getName());
  402. valuationDto.setMerchantId(shop.getMerchantId());
  403. }
  404. BeanUtils.copyProperties(valuationReq, valuationDto);
  405. return result;
  406. }
  407. }