ApiDeliveryBindServiceImpl.java 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. package com.ydd.app.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.ydd.api.DeliveryService;
  5. import com.ydd.app.QueryAmountEntityUtils;
  6. import com.ydd.app.ShopEntityUtils;
  7. import com.ydd.app.service.ApiDeliveryBindService;
  8. import com.ydd.common.enums.DeliveryTypeEnums;
  9. import com.ydd.common.utils.StringUtils;
  10. import com.ydd.ecloud.core.utils.JsonMapper;
  11. import com.ydd.module.domain.*;
  12. import com.ydd.module.dto.DeliveryInfo;
  13. import com.ydd.module.dto.ShopBindDto;
  14. import com.ydd.module.dto.ShopDeliveryBindDto;
  15. import com.ydd.module.dto.UpdateDadaShopNoDto;
  16. import com.ydd.module.enums.*;
  17. import com.ydd.module.expection.CustomAppException;
  18. import com.ydd.module.service.IDspDeliveryService;
  19. import com.ydd.module.service.IMerchantService;
  20. import com.ydd.module.service.IShopDeliveryBindService;
  21. import com.ydd.module.service.IShopService;
  22. import com.ydd.system.service.ISysConfigService;
  23. import com.ydd.third.common.dto.*;
  24. import com.ydd.third.common.vo.ResObject;
  25. import com.ydd.third.common.vo.callback.ShansongTokenVo;
  26. import com.ydd.third.common.vo.shop.AmountResultVo;
  27. import com.ydd.third.common.vo.shop.QueryAmount;
  28. import com.ydd.third.common.vo.shop.ShopResultVo;
  29. import com.ydd.third.common.vo.shop.ShopVo;
  30. import lombok.RequiredArgsConstructor;
  31. import lombok.extern.slf4j.Slf4j;
  32. import org.apache.commons.collections4.CollectionUtils;
  33. import org.apache.commons.compress.utils.Lists;
  34. import org.springframework.beans.BeanUtils;
  35. import org.springframework.beans.factory.annotation.Autowired;
  36. import org.springframework.stereotype.Service;
  37. import org.springframework.transaction.annotation.Transactional;
  38. import java.math.BigDecimal;
  39. import java.util.*;
  40. import java.util.stream.Collectors;
  41. /**
  42. * 门店绑定运力Service
  43. * @author 叶君翔
  44. * @date 2021/12/05 09:53
  45. */
  46. @Slf4j
  47. @Service
  48. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  49. public class ApiDeliveryBindServiceImpl implements ApiDeliveryBindService {
  50. private final ISysConfigService iSysConfigService;
  51. private final IDspDeliveryService iDspDeliveryService;
  52. private final IShopDeliveryBindService iShopDeliveryBindService;
  53. private final IMerchantService iMerchantService;
  54. private final DeliveryService client;
  55. private final IShopService iShopService;
  56. @Override
  57. public List<ShopDeliveryBindDto> list(Member member) {
  58. List<ShopDeliveryBindDto> bindList = iShopDeliveryBindService.findBindList(member.getMerchantId(), member.getShopId(), member.getMemberType());
  59. if (CollectionUtils.isNotEmpty(bindList)) {
  60. bindList = bindList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
  61. () -> new TreeSet<>(Comparator.comparing(ShopDeliveryBindDto::getDeliveryId))), ArrayList::new));
  62. }
  63. // 查询余额
  64. for (ShopDeliveryBindDto bindDto : bindList){
  65. DeliveryInfo delivery = new DeliveryInfo();
  66. delivery.setThirdShopId(bindDto.getThirdShopId());
  67. delivery.setShopId(bindDto.getThirdShopId());
  68. delivery.setAuthToken(bindDto.getAuthToken());
  69. delivery.setPhone(bindDto.getAccount());
  70. delivery.setType(bindDto.getDeliveryType());
  71. DspDelivery dspDelivery = iDspDeliveryService.getById(bindDto.getDeliveryId());
  72. QueryAmount queryAmount = QueryAmountEntityUtils.queryAmount(delivery, member.getMerchantId(),1);
  73. if(StringUtils.isBlank(queryAmount.getLbClient())){
  74. continue;
  75. }
  76. ResObject<AmountResultVo> amountRes = client.queryAmount(queryAmount);
  77. if (amountRes.getCode() == 0) {
  78. // 更新余额
  79. AmountResultVo vo = amountRes.getData();
  80. this.updateAmount(dspDelivery, member.getMerchantId(), bindDto.getShopId(), vo.getBalanceAmount());
  81. bindDto.setBalance(vo.getBalanceAmount());
  82. }
  83. // 达达、达达优质是否已绑定开放平台模式
  84. if (DeliveryTypeEnums.DADA.getType().equals(dspDelivery.getType())
  85. || DeliveryTypeEnums.DADA_YZ.getType().equals(dspDelivery.getType())) {
  86. int count = iShopDeliveryBindService.count(new QueryWrapper<ShopDeliveryBind>()
  87. .eq("delivery_id", bindDto.getDeliveryId())
  88. .eq("merchant_id", bindDto.getMerchantId())
  89. .eq("dada_bind_type", DadaBindTypeEnum.OPEN.type)
  90. .eq("deleted", 0));
  91. bindDto.setDadaBindType(count > 0 ? DadaBindTypeEnum.OPEN.type : null);
  92. }
  93. // 同一猎豹商户的同一运力有多个运力商户编号,则不展示商户号和余额
  94. if (DeliveryTypeEnums.DADA.getType().equals(dspDelivery.getType())
  95. || DeliveryTypeEnums.DADA_YZ.getType().equals(dspDelivery.getType())
  96. || DeliveryTypeEnums.SHUN_FENG.getType().equals(dspDelivery.getType())
  97. || DeliveryTypeEnums.MEI_TUAN_ZB.getType().equals(dspDelivery.getType())
  98. || DeliveryTypeEnums.FENG_NIAO.getType().equals(dspDelivery.getType())) {
  99. int count = iShopDeliveryBindService.count(new QueryWrapper<ShopDeliveryBind>()
  100. .eq("delivery_id", bindDto.getDeliveryId())
  101. .eq("merchant_id", bindDto.getMerchantId())
  102. .eq(MemberTypeEnum.SHOP.type.equals(member.getMemberType()),"shop_id", member.getShopId())
  103. .ne("third_shop_id", bindDto.getThirdShopId())
  104. .eq("deleted", 0));
  105. if (count > 0) {
  106. bindDto.setThirdShopId(null);
  107. bindDto.setBalance(null);
  108. }
  109. }
  110. }
  111. List<Long> bindDeliveryIds = bindList.stream().map(ShopDeliveryBindDto::getDeliveryId).collect(Collectors.toList());
  112. List<ShopDeliveryBindDto> unbindList = iShopDeliveryBindService.findUnbindList(member.getMerchantId(), bindDeliveryIds, member.getShopId(), member.getMemberType());
  113. if (CollectionUtils.isNotEmpty(unbindList)) {
  114. unbindList = unbindList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(
  115. () -> new TreeSet<>(Comparator.comparing(ShopDeliveryBindDto::getDeliveryId))), ArrayList::new));
  116. for (ShopDeliveryBindDto unbindDto : unbindList) {
  117. if (unbindDto.getDeliveryType().equals(DeliveryTypeEnums.DADA.getType())
  118. || unbindDto.getDeliveryType().equals(DeliveryTypeEnums.DADA_YZ.getType())
  119. || unbindDto.getDeliveryType().equals(DeliveryTypeEnums.SHUN_FENG.getType())) {
  120. bindList.add(unbindDto);
  121. }
  122. }
  123. }
  124. List<ShopDeliveryBindDto> deliveryList = iDspDeliveryService.getDeliveryList();
  125. deliveryList.removeAll(bindList);
  126. for (ShopDeliveryBindDto dto : deliveryList) {
  127. if (!dto.getDeliveryType().equals(DeliveryTypeEnums.MEI_TUAN.getType()) &&
  128. !dto.getDeliveryType().equals(DeliveryTypeEnums.FENG_NIAO.getType()) &&
  129. !dto.getDeliveryType().equals(DeliveryTypeEnums.FENG_NIAO_KA.getType()) &&
  130. !dto.getDeliveryType().equals(DeliveryTypeEnums.FENG_NIAO_PT.getType()) &&
  131. !dto.getDeliveryType().equals(DeliveryTypeEnums.HUO_LA_LA.getType())) {
  132. dto.setBindStatus(BindStatusEnum.UNBIND.getStatus());
  133. bindList.add(dto);
  134. }
  135. }
  136. return bindList.stream().sorted(Comparator.comparing(ShopDeliveryBindDto::getDeliveryType)).collect(Collectors.toList());
  137. }
  138. private void updateAmount(DspDelivery delivery, Long merchantId, Long shopId, BigDecimal balanceAmount) {
  139. if (DeliveryTypeEnums.DADA.getType().equals(delivery.getType())
  140. || DeliveryTypeEnums.DADA_YZ.getType().equals(delivery.getType())
  141. || DeliveryTypeEnums.FENG_NIAO.getType().equals(delivery.getType())
  142. || DeliveryTypeEnums.FENG_NIAO_PT.getType().equals(delivery.getType())
  143. || DeliveryTypeEnums.SHUN_FENG.getType().equals(delivery.getType())
  144. || DeliveryTypeEnums.MEI_TUAN_ZB.getType().equals(delivery.getType())) {
  145. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>()
  146. .eq("merchant_id", merchantId).eq("shop_id", shopId).eq("delivery_id", delivery.getId())
  147. .eq("deleted", IsDeleteEnum.NORMAL.status).eq("bind_status", 1));
  148. if (shopDeliveryBind != null) {
  149. // 门店模式变更余额
  150. iShopDeliveryBindService.updateShopAmount(shopDeliveryBind.getMerchantId(), shopDeliveryBind.getDeliveryId(), shopDeliveryBind.getThirdShopId(), balanceAmount);
  151. }
  152. } else {
  153. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>()
  154. .eq("merchant_id", merchantId).eq("delivery_id", delivery.getId())
  155. .eq("deleted", IsDeleteEnum.NORMAL.status).isNull("shop_id")
  156. .eq("bind_status", 1));
  157. // 商户模式变更余额
  158. if (shopDeliveryBind != null) {
  159. iShopDeliveryBindService.updateMerchantAmount(shopDeliveryBind.getId(), balanceAmount);
  160. }
  161. }
  162. }
  163. @Override
  164. @Transactional(rollbackFor = Exception.class)
  165. public String bind(Member member, Long shopId, Long deliveryId, String thirdShopId, String dadaName) {
  166. if (member.getMerchantId() == null) {
  167. throw new CustomAppException("请先申请成为商家!");
  168. }
  169. Merchant merchant = iMerchantService.getById(member.getMerchantId());
  170. if (merchant == null) {
  171. throw new CustomAppException("商家信息异常,请联系管理员!");
  172. }
  173. DspDelivery delivery = iDspDeliveryService.getById(deliveryId);
  174. if (delivery == null) {
  175. throw new CustomAppException("暂不支持该运力绑定!");
  176. }
  177. Integer deliveryType = delivery.getType();
  178. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getShopDeliveryBindInfo(member.getMerchantId(), shopId, deliveryId, deliveryType);
  179. if (!DeliveryTypeEnums.DADA.getType().equals(deliveryType) && !DeliveryTypeEnums.DADA_YZ.getType().equals(deliveryType)
  180. && shopDeliveryBind != null && BindStatusEnum.BIND.status.equals(shopDeliveryBind.getBindStatus())) {
  181. throw new CustomAppException("已绑定成功!");
  182. }
  183. String url = null;
  184. if (delivery.getType().equals(DeliveryTypeEnums.SHAN_SONG.getType())){
  185. url = client.shansongAuthUrl(merchant.getCode());
  186. }
  187. if (delivery.getType().equals(DeliveryTypeEnums.FENG_NIAO.getType())){
  188. url = client.fengniaoAuthUrl();
  189. }
  190. if (delivery.getType().equals(DeliveryTypeEnums.FENG_NIAO_PT.getType())){
  191. url = client.fengniaoAuthUrl();
  192. }
  193. if (delivery.getType().equals(DeliveryTypeEnums.AIPT.getType())){
  194. url = client.aptAuthUrl(merchant.getCode());
  195. }
  196. if (delivery.getType().equals(DeliveryTypeEnums.HUO_LA_LA.getType())){
  197. url = client.hllAuthUrl();
  198. }
  199. if (delivery.getType().equals(DeliveryTypeEnums.KUAI_FU.getType())){
  200. url = client.kfAuthUrl(merchant.getCode());
  201. }
  202. if (DeliveryTypeEnums.MEI_TUAN_ZB.getType().equals(deliveryType)) {
  203. shopDeliveryBind = new ShopDeliveryBind();
  204. shopDeliveryBind.setAccount("sssss");
  205. shopDeliveryBind.setMerchantId(merchant.getId());
  206. shopDeliveryBind.setShopId(shopId);
  207. shopDeliveryBind.setDeliveryId(delivery.getId());
  208. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  209. iShopDeliveryBindService.save(shopDeliveryBind);
  210. }
  211. if (StringUtils.isBlank(thirdShopId) && (DeliveryTypeEnums.DADA.getType().equals(deliveryType)) || DeliveryTypeEnums.DADA_YZ.getType().equals(deliveryType)) {
  212. int type = 0;
  213. if (DeliveryTypeEnums.DADA_YZ.getType().equals(deliveryType)) {
  214. type = 1;
  215. }
  216. JSONObject jsonObject = client.partyTicket(type);
  217. if (jsonObject != null && jsonObject.getString("status").equals("success")) {
  218. String state = merchant.getCode();
  219. if (shopId != null) {
  220. state = state + "_" + shopId;
  221. }
  222. url = client.getPartyOauth(jsonObject.getString("result"), type, state);
  223. } else {
  224. throw new CustomAppException(jsonObject == null ? "获取渠道授权码异常!" : jsonObject.getString("msg"));
  225. }
  226. }
  227. if (DeliveryTypeEnums.SHUN_FENG.getType().equals(deliveryType) && StringUtils.isNotBlank(thirdShopId)) {
  228. if (shopDeliveryBind == null) {
  229. shopDeliveryBind = new ShopDeliveryBind();
  230. shopDeliveryBind.setAccount("sssss");
  231. if (StringUtils.isNotBlank(dadaName)) {
  232. shopDeliveryBind.setAccount(dadaName);
  233. }
  234. shopDeliveryBind.setShopId(shopId);
  235. shopDeliveryBind.setBalance(new BigDecimal("0"));
  236. shopDeliveryBind.setThirdShopId(thirdShopId);
  237. shopDeliveryBind.setMerchantId(merchant.getId());
  238. shopDeliveryBind.setDeliveryId(delivery.getId());
  239. shopDeliveryBind.setBindStatus(BindStatusEnum.CHECK.status);
  240. iShopDeliveryBindService.save(shopDeliveryBind);
  241. } else {
  242. // 更新
  243. shopDeliveryBind.setShopId(shopId);
  244. shopDeliveryBind.setThirdShopId(thirdShopId);
  245. shopDeliveryBind.setBindStatus(BindStatusEnum.CHECK.status);
  246. shopDeliveryBind.setAccount("sssss");
  247. if (StringUtils.isNotBlank(dadaName)) {
  248. shopDeliveryBind.setAccount(dadaName);
  249. }
  250. iShopDeliveryBindService.updateById(shopDeliveryBind);
  251. }
  252. }
  253. return url;
  254. }
  255. @Override
  256. @Transactional(rollbackFor = Exception.class)
  257. public void bindDaDa(String sourceId, String state, Integer type, String shopNo) {
  258. log.info("绑定达达回调: sourceId: {}, state: {}, type: {}, shopNo: {}", sourceId, state, type, shopNo);
  259. String merchantCode = state;
  260. Long shopId = null;
  261. if (StringUtils.isNotEmpty(state) && state.contains("_")) {
  262. String[] split = state.split("_");
  263. if (split.length == 2) {
  264. merchantCode = split[0];
  265. shopId = Long.valueOf(split[1]);
  266. }
  267. }
  268. Merchant merchant = iMerchantService.getOne(new QueryWrapper<Merchant>().eq("code", merchantCode));
  269. if (merchant == null) {
  270. log.info("达达绑定商家为空");
  271. return;
  272. }
  273. DspDelivery delivery = iDspDeliveryService.findOne(type);
  274. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
  275. eq("delivery_id", delivery.getId()).eq("shop_id", shopId).eq("deleted",0));
  276. if (shopDeliveryBind == null) {
  277. shopDeliveryBind = new ShopDeliveryBind();
  278. }
  279. shopDeliveryBind.setThirdShopId(sourceId);
  280. shopDeliveryBind.setMerchantId(merchant.getId());
  281. shopDeliveryBind.setShopId(shopId);
  282. shopDeliveryBind.setBindStatus(BindStatusEnum.WAIT_INFO.status);
  283. shopDeliveryBind.setDeliveryId(delivery.getId());
  284. shopDeliveryBind.setDadaBindType(DadaBindTypeEnum.OPEN.type);
  285. iShopDeliveryBindService.saveOrUpdate(shopDeliveryBind);
  286. if (StringUtils.isNotBlank(shopNo)) {
  287. shopDeliveryBind.setDadaBindType(DadaBindTypeEnum.APP.type);
  288. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  289. if (DeliveryTypeEnums.DADA.getType().equals(delivery.getType())) {
  290. shopDeliveryBind.setDadaShopNo(shopNo);
  291. } else if (DeliveryTypeEnums.DADA_YZ.getType().equals(delivery.getType())) {
  292. shopDeliveryBind.setDadaYzShopNo(shopNo);
  293. }
  294. // 更新门店编号
  295. iShopDeliveryBindService.updateById(shopDeliveryBind);
  296. // iShopDeliveryBindService.updateDaDaShopNo(type, shopDeliveryBind.getDeliveryId(), shopNo, merchant.getId(), shopId);
  297. // 更新余额
  298. this.changeDadaBalance(shopDeliveryBind, delivery.getType());
  299. }
  300. }
  301. @Override
  302. @Transactional(rollbackFor = Exception.class)
  303. public void bindShunfeng(String outShopId, Integer shopId, Integer type) {
  304. log.info("绑定顺丰回调: outShopId: {}, shopId: {}, type: {}", outShopId, shopId, type);
  305. Shop shop = iShopService.getOne(new QueryWrapper<Shop>().eq("deleted", 0).eq("code", outShopId));
  306. Merchant merchant = null;
  307. if (shop.getMerchantId() != null) {
  308. merchant = iMerchantService.getById(shop.getMerchantId());
  309. }
  310. if (merchant == null) {
  311. log.info("顺丰绑定商家为空");
  312. return;
  313. }
  314. DspDelivery delivery = iDspDeliveryService.findOne(type);
  315. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
  316. eq("delivery_id", delivery.getId()).eq("shop_id", shop.getId()).eq("deleted",0));
  317. if (shopDeliveryBind == null) {
  318. shopDeliveryBind = new ShopDeliveryBind();
  319. }
  320. shopDeliveryBind.setThirdShopId(shopId.toString());
  321. shopDeliveryBind.setMerchantId(merchant.getId());
  322. shopDeliveryBind.setShopId(shop.getId());
  323. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  324. shopDeliveryBind.setDeliveryId(delivery.getId());
  325. iShopDeliveryBindService.saveOrUpdate(shopDeliveryBind);
  326. // 更新余额
  327. this.changeShunfengBalance(shopDeliveryBind, delivery.getType());
  328. }
  329. private void changeDadaBalance(ShopDeliveryBind shopDeliveryBind, Integer deliveryType){
  330. QueryAmount queryAmount = new QueryAmount();
  331. queryAmount.setIsDirectDelivery(0);
  332. queryAmount.setLbClient(DeliveryTypeEnums.DADA.getName());
  333. if (DeliveryTypeEnums.DADA_YZ.getType().equals(deliveryType)) {
  334. queryAmount.setIsDirectDelivery(1);
  335. queryAmount.setLbClient(DeliveryTypeEnums.DADA_YZ.getName());
  336. }
  337. // 查询余额
  338. queryAmount.setMerchantId(shopDeliveryBind.getThirdShopId());
  339. ResObject<AmountResultVo> res = client.queryAmount(queryAmount);
  340. if(res.getCode() == 0) {
  341. BigDecimal balanceAmount = res.getData().getBalanceAmount();
  342. // 变更余额
  343. iShopDeliveryBindService.updateShopAmount(shopDeliveryBind.getMerchantId(), shopDeliveryBind.getDeliveryId(), shopDeliveryBind.getThirdShopId(), balanceAmount);
  344. }
  345. }
  346. private void changeShunfengBalance(ShopDeliveryBind shopDeliveryBind, Integer deliveryType){
  347. QueryAmount queryAmount = new QueryAmount();
  348. // 查询余额
  349. queryAmount.setMerchantId(shopDeliveryBind.getThirdShopId());
  350. queryAmount.setShopType(1);
  351. ResObject<AmountResultVo> res = client.queryAmount(queryAmount);
  352. if(res.getCode() == 0) {
  353. BigDecimal balanceAmount = res.getData().getBalanceAmount();
  354. // 变更余额
  355. iShopDeliveryBindService.updateShopAmount(shopDeliveryBind.getMerchantId(), shopDeliveryBind.getDeliveryId(), shopDeliveryBind.getThirdShopId(), balanceAmount);
  356. }
  357. }
  358. @Override
  359. public void updateDadaShopNo(Member member, UpdateDadaShopNoDto updateDadaShopNoDto) {
  360. int merchantCount = iShopDeliveryBindService.count(new QueryWrapper<ShopDeliveryBind>()
  361. .eq("merchant_id", member.getMerchantId())
  362. .eq("third_shop_id", updateDadaShopNoDto.getMerchantNo())
  363. .eq("delivery_id", updateDadaShopNoDto.getDeliveryId())
  364. .in("bind_status", Arrays.asList(BindStatusEnum.BIND.status, BindStatusEnum.WAIT_INFO.status))
  365. .eq("deleted",0));
  366. if (merchantCount == 0) {
  367. throw new CustomAppException("当前商户未授权猎豹AI,请重新绑定");
  368. }
  369. DspDelivery dspDelivery = iDspDeliveryService.findById(updateDadaShopNoDto.getDeliveryId());
  370. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getById(updateDadaShopNoDto.getBindId());
  371. if (shopDeliveryBind == null) {
  372. shopDeliveryBind = new ShopDeliveryBind();
  373. shopDeliveryBind.setMerchantId(member.getMerchantId());
  374. shopDeliveryBind.setShopId(updateDadaShopNoDto.getShopId());
  375. shopDeliveryBind.setDeliveryId(dspDelivery.getId());
  376. shopDeliveryBind.setAccount(updateDadaShopNoDto.getMobile());
  377. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  378. shopDeliveryBind.setThirdShopId(updateDadaShopNoDto.getMerchantNo());
  379. if (DeliveryTypeEnums.DADA.getType().equals(dspDelivery.getType())) {
  380. shopDeliveryBind.setDadaShopNo(updateDadaShopNoDto.getShopNo());
  381. } else if (DeliveryTypeEnums.DADA_YZ.getType().equals(dspDelivery.getType())) {
  382. shopDeliveryBind.setDadaYzShopNo(updateDadaShopNoDto.getShopNo());
  383. }
  384. shopDeliveryBind.setDadaBindType(DadaBindTypeEnum.OPEN.type);
  385. iShopDeliveryBindService.save(shopDeliveryBind);
  386. } else {
  387. if (DeliveryTypeEnums.DADA.getType().equals(dspDelivery.getType())) {
  388. shopDeliveryBind.setDadaShopNo(updateDadaShopNoDto.getShopNo());
  389. } else if (DeliveryTypeEnums.DADA_YZ.getType().equals(dspDelivery.getType())) {
  390. shopDeliveryBind.setDadaYzShopNo(updateDadaShopNoDto.getShopNo());
  391. }
  392. shopDeliveryBind.setThirdShopId(updateDadaShopNoDto.getMerchantNo());
  393. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  394. shopDeliveryBind.setAccount(updateDadaShopNoDto.getMobile());
  395. // 更新门店编号
  396. iShopDeliveryBindService.updateById(shopDeliveryBind);
  397. }
  398. // 变更余额
  399. this.changeDadaBalance(shopDeliveryBind, dspDelivery.getType());
  400. }
  401. @Override
  402. @Transactional(rollbackFor = Exception.class)
  403. public void release(Long bindId) {
  404. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getById(bindId);
  405. if (shopDeliveryBind == null) {
  406. throw new CustomAppException("解除绑定失败, 请联系客服人员处理!");
  407. }
  408. DspDelivery delivery =iDspDeliveryService.getById(shopDeliveryBind.getDeliveryId());
  409. Integer deliveryType = delivery.getType();
  410. if (DeliveryTypeEnums.SHUN_FENG.getType().equals(deliveryType)
  411. || DeliveryTypeEnums.DADA.getType().equals(deliveryType)
  412. || DeliveryTypeEnums.DADA_YZ.getType().equals(deliveryType)
  413. || DeliveryTypeEnums.MEI_TUAN_ZB.getType().equals(deliveryType)
  414. || DeliveryTypeEnums.KUAI_FU.getType().equals(deliveryType)) {
  415. iShopDeliveryBindService.removeById(bindId);
  416. }
  417. if (DeliveryTypeEnums.AIPT.getType().equals(deliveryType)) {
  418. AiptUnBindDto aiptUnBindDto = this.unBindAipt(bindId);
  419. if ("Fail".equals(aiptUnBindDto.getState())) {
  420. throw new CustomAppException("解除绑定失败, 请联系客服人员处理!");
  421. }
  422. } else if (DeliveryTypeEnums.SHAN_SONG.getType().equals(deliveryType)) {
  423. ResObject res = client.cancelToken(shopDeliveryBind.getAuthToken());
  424. log.info("===闪送解除绑定返回: {}", JsonMapper.nonEmptyMapper().toJson(res));
  425. if (res.getCode() == 0) {
  426. iShopDeliveryBindService.removeById(bindId);
  427. }
  428. }
  429. }
  430. @Override
  431. @Transactional(rollbackFor = Exception.class)
  432. public AiptUnBindDto unBindAipt(Long bindId) {
  433. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getById(bindId);
  434. if (shopDeliveryBind == null) {
  435. AiptUnBindDto bindDto = new AiptUnBindDto();
  436. bindDto.setState("Fail");
  437. bindDto.setInfo("该运力不存在");
  438. return bindDto;
  439. }
  440. // 解除绑定
  441. AiptUnBindDto bindDto = client.unBind(shopDeliveryBind.getAccount());
  442. log.info("===Aipt解除绑定返回: {}", JsonMapper.nonEmptyMapper().toJson(bindDto));
  443. if (bindDto != null && bindDto.getCode() != null && bindDto.getCode() == 1 && "Success".equals(bindDto.getState())) {
  444. iShopDeliveryBindService.removeById(bindId);
  445. } else {
  446. bindDto = new AiptUnBindDto();
  447. bindDto.setState("Fail");
  448. bindDto.setInfo("解除绑定失败, 请联系客服进行处理!");
  449. }
  450. return bindDto;
  451. }
  452. @Override
  453. public String explain() {
  454. return iSysConfigService.selectConfigByKey("BINDING_PROCESS");
  455. }
  456. @Override
  457. @Transactional(rollbackFor = Exception.class)
  458. public void bindShansong(ShansongTokenVo tokenVo) {
  459. Merchant merchant = iMerchantService.getOne(new QueryWrapper<Merchant>().eq("code", tokenVo.getShopId()));
  460. if (merchant == null) {
  461. throw new CustomAppException("商户不存在!");
  462. }
  463. DspDelivery delivery = iDspDeliveryService.findOne(DeliveryTypeEnums.SHAN_SONG.getType());
  464. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
  465. eq("delivery_id", delivery.getId()).eq("deleted",0).isNull("shop_id"));
  466. if (shopDeliveryBind == null) {
  467. shopDeliveryBind = new ShopDeliveryBind();
  468. shopDeliveryBind.setAccount("sssss");
  469. shopDeliveryBind.setMerchantId(merchant.getId());
  470. shopDeliveryBind.setDeliveryId(delivery.getId());
  471. }
  472. shopDeliveryBind.setThirdShopId(tokenVo.getShopId());
  473. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  474. // 获取余额
  475. try {
  476. QueryAmount queryAmount = new QueryAmount();
  477. queryAmount.setAccessToken(tokenVo.getAccessToken());
  478. queryAmount.setIsShansongSH(true);
  479. queryAmount.setLbClient(DeliveryTypeEnums.SHAN_SONG.getName());
  480. ResObject<AmountResultVo> res = client.queryAmount(queryAmount);
  481. if (res.getCode() == 0) {
  482. AmountResultVo vo = res.getData();
  483. shopDeliveryBind.setBalance(vo.getBalanceAmount());
  484. }
  485. } catch (Exception e) {
  486. e.printStackTrace();
  487. }
  488. shopDeliveryBind.setAuthToken(tokenVo.getAccessToken());
  489. shopDeliveryBind.setRefreshToken(tokenVo.getRefreshToken());
  490. shopDeliveryBind.setExpiresIn(tokenVo.getExpireIn());
  491. iShopDeliveryBindService.saveOrUpdate(shopDeliveryBind);
  492. }
  493. @Override
  494. @Transactional(rollbackFor = Exception.class)
  495. public void bindAipt(AiptAuthDto aiptAuthDto) {
  496. Merchant merchant = iMerchantService.getOne(new QueryWrapper<Merchant>().eq("code", aiptAuthDto.getUnique_id()));
  497. if (merchant == null) {
  498. throw new CustomAppException("商户不存在!");
  499. }
  500. DspDelivery delivery = iDspDeliveryService.findOne(DeliveryTypeEnums.AIPT.getType());
  501. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
  502. eq("delivery_id", delivery.getId()).eq("deleted",0).isNull("shop_id"));
  503. if (shopDeliveryBind == null) {
  504. shopDeliveryBind = new ShopDeliveryBind();
  505. shopDeliveryBind.setAccount(aiptAuthDto.getPhone());
  506. shopDeliveryBind.setThirdShopId(aiptAuthDto.getUnique_id());
  507. shopDeliveryBind.setMerchantId(merchant.getId());
  508. if ("bind".equals(aiptAuthDto.getState())){
  509. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  510. } else {
  511. shopDeliveryBind.setBindStatus(BindStatusEnum.UNBIND.status);
  512. }
  513. shopDeliveryBind.setDeliveryId(delivery.getId());
  514. // 获取余额
  515. try {
  516. QueryAmount queryAmount = new QueryAmount();
  517. queryAmount.setPhone(aiptAuthDto.getPhone());
  518. queryAmount.setLbClient(DeliveryTypeEnums.AIPT.getName());
  519. ResObject<AmountResultVo> res = client.queryAmount(queryAmount);
  520. if (res.getCode() == 0) {
  521. AmountResultVo vo = res.getData();
  522. shopDeliveryBind.setBalance(vo.getBalanceAmount());
  523. }
  524. } catch (Exception e) {
  525. e.printStackTrace();
  526. }
  527. iShopDeliveryBindService.save(shopDeliveryBind);
  528. }
  529. }
  530. @Override
  531. @Transactional(rollbackFor = Exception.class)
  532. public void bindKf(KfAuthDto kfAuthDto) {
  533. Merchant merchant = iMerchantService.getOne(new QueryWrapper<Merchant>().eq("code", kfAuthDto.getMerchantCode()));
  534. if (merchant == null) {
  535. throw new CustomAppException("商家不存在!");
  536. }
  537. DspDelivery delivery = iDspDeliveryService.findOne(DeliveryTypeEnums.KUAI_FU.getType());
  538. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
  539. eq("delivery_id", delivery.getId()).eq("deleted",0).isNull("shop_id"));
  540. if (shopDeliveryBind == null) {
  541. shopDeliveryBind = new ShopDeliveryBind();
  542. shopDeliveryBind.setThirdShopId(kfAuthDto.getOpenid());
  543. shopDeliveryBind.setMerchantId(merchant.getId());
  544. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  545. shopDeliveryBind.setDeliveryId(delivery.getId());
  546. shopDeliveryBind.setAuthToken(kfAuthDto.getAccess_token());
  547. // 表示该商家是首次绑定,不是yes则是下过订单后的账户
  548. shopDeliveryBind.setAccount("yes");
  549. iShopDeliveryBindService.save(shopDeliveryBind);
  550. }
  551. }
  552. @Override
  553. public boolean getUuptVerifyCode(String mobile, String ip) {
  554. ResObject<BindUserApplyResponse> resObject = client.bindUserApply(mobile, ip);
  555. return resObject.getCode() == 0;
  556. }
  557. @Override
  558. @Transactional(rollbackFor = Exception.class)
  559. public String bindUupt(Member member, String mobile, String validateCode, String cityName) {
  560. ResObject<BindUserSubmitResponse> resObject = client.bindUserSubmit(mobile, validateCode, cityName);
  561. if (resObject.getCode() != 0) {
  562. return resObject.getMsg();
  563. }
  564. BindUserSubmitResponse response = resObject.getData();
  565. DspDelivery delivery = iDspDeliveryService.findOne(DeliveryTypeEnums.UUPT.getType());
  566. ShopDeliveryBind shopDeliveryBind = new ShopDeliveryBind();
  567. shopDeliveryBind.setAccount(mobile);
  568. ResObject<GetBalanceDetailResponse> res = client.getBalance(response.getOpenid());
  569. if(res.getCode() == 0) {
  570. shopDeliveryBind.setBalance(new BigDecimal(res.getData().getAccountMoney()));
  571. }
  572. shopDeliveryBind.setThirdShopId(response.getOpenid());
  573. shopDeliveryBind.setMerchantId(member.getMerchantId());
  574. shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
  575. shopDeliveryBind.setDeliveryId(delivery.getId());
  576. iShopDeliveryBindService.save(shopDeliveryBind);
  577. return "ok";
  578. }
  579. @Override
  580. @Transactional(rollbackFor = Exception.class)
  581. public String unBindUupt(Member member, String mobile) {
  582. DspDelivery delivery = iDspDeliveryService.findOne(DeliveryTypeEnums.UUPT.getType());
  583. ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id",member.getMerchantId()).
  584. eq("delivery_id", delivery.getId()).eq("deleted",0).isNull("shop_id"));
  585. log.info("uupt解除绑定, shopDeliveryBind: {}", JSONObject.toJSONString(shopDeliveryBind));
  586. if (shopDeliveryBind == null) {
  587. throw new CustomAppException("UUPT解除绑定失败, 请联系客服人员处理!");
  588. }
  589. if (!mobile.equals(shopDeliveryBind.getAccount())) {
  590. throw new CustomAppException("请确认解绑手机号是否正确!");
  591. }
  592. if (StringUtils.isBlank(shopDeliveryBind.getThirdShopId())) {
  593. throw new CustomAppException("UUPT解除绑定失败, 请联系客服人员处理!");
  594. }
  595. ResObject<CancelBindResponse> resObject = client.cancelBind(shopDeliveryBind.getThirdShopId());
  596. log.info("uupt 解除绑定返回: {}", JSONObject.toJSONString(resObject));
  597. if (resObject.getCode() == 0) {
  598. iShopDeliveryBindService.removeById(shopDeliveryBind.getId());
  599. return "ok";
  600. }
  601. return resObject.getMsg();
  602. }
  603. @Override
  604. public List<ShopBindDto> shopList(Member member, Long deliveryId) {
  605. List<ShopBindDto> list;
  606. if (MemberTypeEnum.MERCHANT.type.equals(member.getMemberType())) {
  607. list = iShopService.findListByMerchantId(member.getMerchantId());
  608. } else if (MemberTypeEnum.SHOP.type.equals(member.getMemberType())) {
  609. list = iShopService.findListById(member.getShopId());
  610. } else {
  611. throw new CustomAppException("无效的用户类型!");
  612. }
  613. List<ShopDeliveryBind> shopDeliveryBindList = iShopDeliveryBindService.list(new QueryWrapper<ShopDeliveryBind>()
  614. .eq("merchant_id", member.getMerchantId())
  615. .eq("delivery_id", deliveryId)
  616. .eq("deleted", 0));
  617. Map<Long, List<ShopDeliveryBind>> shopBindMap = shopDeliveryBindList.stream().collect(Collectors.groupingBy(ShopDeliveryBind::getShopId));
  618. DspDelivery dspDelivery = iDspDeliveryService.getById(deliveryId);
  619. list.forEach(shopBindDto -> {
  620. // 达达、达达优质是否已绑定开放平台模式
  621. if (DeliveryTypeEnums.DADA.getType().equals(dspDelivery.getType())
  622. || DeliveryTypeEnums.DADA_YZ.getType().equals(dspDelivery.getType())) {
  623. int openCount = iShopDeliveryBindService.count(new QueryWrapper<ShopDeliveryBind>()
  624. .eq("delivery_id", dspDelivery.getId())
  625. .eq("merchant_id", member.getMerchantId())
  626. .eq("dada_bind_type", DadaBindTypeEnum.OPEN.type)
  627. .eq("deleted", 0));
  628. shopBindDto.setDadaBindType(openCount > 0 ? DadaBindTypeEnum.OPEN.type : null);
  629. }
  630. List<ShopDeliveryBind> shopDeliveryBinds = shopBindMap.get(shopBindDto.getShopId());
  631. if (CollectionUtils.isNotEmpty(shopDeliveryBinds)) {
  632. ShopDeliveryBind shopDeliveryBind = shopDeliveryBinds.get(0);
  633. BeanUtils.copyProperties(shopDeliveryBind, shopBindDto);
  634. shopBindDto.setBindId(shopDeliveryBind.getId());
  635. if (BindStatusEnum.BIND.status.equals(shopBindDto.getBindStatus())) {
  636. // 更新余额
  637. DeliveryInfo delivery = new DeliveryInfo();
  638. delivery.setThirdShopId(shopDeliveryBind.getThirdShopId());
  639. delivery.setShopId(shopDeliveryBind.getThirdShopId());
  640. delivery.setAuthToken(shopDeliveryBind.getAuthToken());
  641. delivery.setPhone(shopDeliveryBind.getAccount());
  642. delivery.setType(dspDelivery.getType());
  643. QueryAmount queryAmount = QueryAmountEntityUtils.queryAmount(delivery, member.getMerchantId(),1);
  644. ResObject<AmountResultVo> amountRes = client.queryAmount(queryAmount);
  645. if (amountRes.getCode() == 0) {
  646. // 更新余额
  647. AmountResultVo vo = amountRes.getData();
  648. this.updateAmount(dspDelivery, member.getMerchantId(), shopDeliveryBind.getShopId(), vo.getBalanceAmount());
  649. shopBindDto.setBalance(vo.getBalanceAmount());
  650. }
  651. }
  652. }
  653. });
  654. return list.stream().sorted(Comparator.comparing(ShopBindDto::getShopId)).collect(Collectors.toList());
  655. }
  656. @Override
  657. @Transactional(rollbackFor = Exception.class)
  658. public Shop sfBind(Long shopId, String accountContactName, String accountContactPhone, String accountIdCard, String businessLicense, String healthPermits) {
  659. Shop shop = iShopService.getById(shopId);
  660. if (Objects.isNull(shop)) {
  661. throw new CustomAppException("门店不存在或被删除!");
  662. }
  663. if (shop.getMerchantId() == null) {
  664. throw new CustomAppException("请先申请成为商家!");
  665. }
  666. Merchant merchant = iMerchantService.getById(shop.getMerchantId());
  667. if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
  668. throw new CustomAppException("该商家已禁用!");
  669. }
  670. if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
  671. throw new CustomAppException("请等待商家通过认证!");
  672. }
  673. DspDelivery dspDelivery = iDspDeliveryService.findOne(DeliveryTypeEnums.SHUN_FENG.getType());
  674. List<ShopDeliveryBind> deliveryBindList = iShopDeliveryBindService.list(new QueryWrapper<ShopDeliveryBind>().eq("deleted", 0).eq("shop_id", shopId)
  675. .eq("delivery_id", dspDelivery.getId()).eq("bind_status", BindStatusEnum.BIND.getStatus()));
  676. if (CollectionUtils.isNotEmpty(deliveryBindList)) {
  677. throw new CustomAppException("该门店已经绑定顺丰!");
  678. }
  679. shop.setLegalPerson(accountContactName);
  680. shop.setDirectorMobile(accountContactPhone);
  681. shop.setIdcardNo(accountIdCard);
  682. shop.setBizLicenseIdcard(businessLicense);
  683. shop.setFoodLicensePic(healthPermits);
  684. iShopService.updateById(shop);
  685. ShopVo shopVo = ShopEntityUtils.createShopVo(shop, dspDelivery, merchant);
  686. log.info("门店信息:" + JsonMapper.nonEmptyMapper().toJson(shopVo));
  687. ResObject<ShopResultVo> res = client.createShop(shopVo);
  688. // 顺丰自运力绑定插入数据
  689. if ("shunfeng".equals(shopVo.getLbClient())) {
  690. ShopDeliveryBind deliveryBind= iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>()
  691. .eq("deleted", 0)
  692. .eq("merchant_id", merchant.getId())
  693. .eq("shop_id", shop.getId())
  694. .eq("delivery_id", dspDelivery.getId()));
  695. if (Objects.isNull(deliveryBind)) {
  696. deliveryBind = new ShopDeliveryBind();
  697. }
  698. deliveryBind.setMerchantId(merchant.getId());
  699. deliveryBind.setShopId(shop.getId());
  700. deliveryBind.setDeliveryId(dspDelivery.getId());
  701. if (res.getCode() == 0) {
  702. deliveryBind.setBindStatus(BindStatusEnum.CHECK.getStatus());
  703. }else {
  704. deliveryBind.setAuthMsg(res.getMsg());
  705. deliveryBind.setBindStatus(BindStatusEnum.REFUND.getStatus());
  706. }
  707. iShopDeliveryBindService.saveOrUpdate(deliveryBind);
  708. }
  709. return shop;
  710. }
  711. @Override
  712. public List<ShopBindDto> sfShopList(Member member, Integer deliveryType) {
  713. List<ShopBindDto> list = Lists.newArrayList();
  714. if (MemberTypeEnum.MERCHANT.type.equals(member.getMemberType())) {
  715. list = iShopService.findListByMerchantId(member.getMerchantId());
  716. } else if (MemberTypeEnum.SHOP.type.equals(member.getMemberType())) {
  717. list = iShopService.findListById(member.getShopId());
  718. } else {
  719. throw new CustomAppException("无效的用户类型!");
  720. }
  721. DspDelivery delivery = iDspDeliveryService.findOne(deliveryType);
  722. List<Shop> shopList = iShopService.list(new QueryWrapper<Shop>()
  723. .eq("merchant_id", member.getMerchantId())
  724. .eq("deleted", 0));
  725. // 已经绑定的顺丰店铺
  726. List<ShopDeliveryBind> shopDeliveryBindList = iShopDeliveryBindService.list(new QueryWrapper<ShopDeliveryBind>()
  727. .eq("merchant_id", member.getMerchantId())
  728. .eq("delivery_id", delivery.getId())
  729. .eq("deleted", 0)
  730. .isNotNull("third_shop_id"));
  731. List<Long> shopBinds = shopDeliveryBindList.stream().map(ShopDeliveryBind::getShopId).collect(Collectors.toList());
  732. List<Shop> newShopList = null;
  733. if (CollectionUtils.isNotEmpty(shopBinds)) {
  734. newShopList = shopList.stream().filter(shop -> !shopBinds.contains(shop.getId())).collect(Collectors.toList());
  735. }
  736. if (CollectionUtils.isEmpty(newShopList)) {
  737. newShopList = shopList;
  738. }
  739. for (Shop shop : newShopList) {
  740. ShopBindDto dto = new ShopBindDto();
  741. dto.setShopId(shop.getId());
  742. dto.setShopName(shop.getName());
  743. list.add(dto);
  744. }
  745. return list.stream().sorted(Comparator.comparing(ShopBindDto::getShopId)).collect(Collectors.toList());
  746. }
  747. @Override
  748. public List<ShopDeliveryBindDto> sfList(Member member) {
  749. List<ShopDeliveryBindDto> bindList = iShopDeliveryBindService.sfList(member.getMerchantId());
  750. if (CollectionUtils.isNotEmpty(bindList)) {
  751. for (ShopDeliveryBindDto dto : bindList) {
  752. Shop shop = iShopService.getById(dto.getShopId());
  753. dto.setShopCode(shop.getCode());
  754. if (BindStatusEnum.BIND.getStatus().equals(dto.getBindStatus())) {
  755. dto.setAccountContactPhone(shop.getDirectorMobile());
  756. // 查询余额
  757. DeliveryInfo delivery = new DeliveryInfo();
  758. delivery.setThirdShopId(dto.getThirdShopId());
  759. delivery.setShopId(dto.getThirdShopId());
  760. delivery.setAuthToken(dto.getAuthToken());
  761. delivery.setPhone(dto.getAccount());
  762. delivery.setType(dto.getDeliveryType());
  763. DspDelivery dspDelivery = iDspDeliveryService.getById(dto.getDeliveryId());
  764. QueryAmount queryAmount = QueryAmountEntityUtils.queryAmount(delivery, member.getMerchantId(),1);
  765. ResObject<AmountResultVo> amountRes = client.queryAmount(queryAmount);
  766. if (amountRes.getCode() == 0) {
  767. // 更新余额
  768. AmountResultVo vo = amountRes.getData();
  769. this.updateAmount(dspDelivery, member.getMerchantId(), dto.getShopId(), vo.getBalanceAmount());
  770. dto.setBalance(vo.getBalanceAmount());
  771. }
  772. }
  773. }
  774. }
  775. return bindList;
  776. }
  777. }