|
@@ -4,22 +4,17 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.ydd.api.DeliveryService;
|
|
|
import com.ydd.app.QueryAmountEntityUtils;
|
|
|
+import com.ydd.app.ShopEntityUtils;
|
|
|
import com.ydd.app.service.ApiDeliveryBindService;
|
|
|
import com.ydd.common.enums.DeliveryTypeEnums;
|
|
|
import com.ydd.common.utils.StringUtils;
|
|
|
import com.ydd.ecloud.core.utils.JsonMapper;
|
|
|
-import com.ydd.module.domain.DspDelivery;
|
|
|
-import com.ydd.module.domain.Member;
|
|
|
-import com.ydd.module.domain.Merchant;
|
|
|
-import com.ydd.module.domain.ShopDeliveryBind;
|
|
|
+import com.ydd.module.domain.*;
|
|
|
import com.ydd.module.dto.DeliveryInfo;
|
|
|
import com.ydd.module.dto.ShopBindDto;
|
|
|
import com.ydd.module.dto.ShopDeliveryBindDto;
|
|
|
import com.ydd.module.dto.UpdateDadaShopNoDto;
|
|
|
-import com.ydd.module.enums.BindStatusEnum;
|
|
|
-import com.ydd.module.enums.DadaBindTypeEnum;
|
|
|
-import com.ydd.module.enums.IsDeleteEnum;
|
|
|
-import com.ydd.module.enums.MemberTypeEnum;
|
|
|
+import com.ydd.module.enums.*;
|
|
|
import com.ydd.module.expection.CustomAppException;
|
|
|
import com.ydd.module.service.IDspDeliveryService;
|
|
|
import com.ydd.module.service.IMerchantService;
|
|
@@ -31,9 +26,12 @@ import com.ydd.third.common.vo.ResObject;
|
|
|
import com.ydd.third.common.vo.callback.ShansongTokenVo;
|
|
|
import com.ydd.third.common.vo.shop.AmountResultVo;
|
|
|
import com.ydd.third.common.vo.shop.QueryAmount;
|
|
|
+import com.ydd.third.common.vo.shop.ShopResultVo;
|
|
|
+import com.ydd.third.common.vo.shop.ShopVo;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.compress.utils.Lists;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -314,6 +312,36 @@ public class ApiDeliveryBindServiceImpl implements ApiDeliveryBindService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void bindShunfeng(String outShopId, Integer shopId, Integer type) {
|
|
|
+ log.info("绑定顺丰回调: outShopId: {}, shopId: {}, type: {}", outShopId, shopId, type);
|
|
|
+ Shop shop = iShopService.getOne(new QueryWrapper<Shop>().eq("deleted", 0).eq("code", outShopId));
|
|
|
+
|
|
|
+ Merchant merchant = null;
|
|
|
+ if (shop.getMerchantId() != null) {
|
|
|
+ merchant = iMerchantService.getById(shop.getMerchantId());
|
|
|
+ }
|
|
|
+ if (merchant == null) {
|
|
|
+ log.info("顺丰绑定商家为空");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DspDelivery delivery = iDspDeliveryService.findOne(type);
|
|
|
+ ShopDeliveryBind shopDeliveryBind = iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>().eq("merchant_id", merchant.getId()).
|
|
|
+ eq("delivery_id", delivery.getId()).eq("shop_id", shop.getId()).eq("deleted",0));
|
|
|
+ if (shopDeliveryBind == null) {
|
|
|
+ shopDeliveryBind = new ShopDeliveryBind();
|
|
|
+ }
|
|
|
+ shopDeliveryBind.setThirdShopId(shopId.toString());
|
|
|
+ shopDeliveryBind.setMerchantId(merchant.getId());
|
|
|
+ shopDeliveryBind.setShopId(shop.getId());
|
|
|
+ shopDeliveryBind.setBindStatus(BindStatusEnum.BIND.status);
|
|
|
+ shopDeliveryBind.setDeliveryId(delivery.getId());
|
|
|
+ iShopDeliveryBindService.saveOrUpdate(shopDeliveryBind);
|
|
|
+ // 更新余额
|
|
|
+ this.changeShunfengBalance(shopDeliveryBind, delivery.getType());
|
|
|
+ }
|
|
|
+
|
|
|
private void changeDadaBalance(ShopDeliveryBind shopDeliveryBind, Integer deliveryType){
|
|
|
QueryAmount queryAmount = new QueryAmount();
|
|
|
queryAmount.setIsDirectDelivery(0);
|
|
@@ -332,6 +360,19 @@ public class ApiDeliveryBindServiceImpl implements ApiDeliveryBindService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void changeShunfengBalance(ShopDeliveryBind shopDeliveryBind, Integer deliveryType){
|
|
|
+ QueryAmount queryAmount = new QueryAmount();
|
|
|
+ // 查询余额
|
|
|
+ queryAmount.setMerchantId(shopDeliveryBind.getThirdShopId());
|
|
|
+ queryAmount.setShopType(1);
|
|
|
+ ResObject<AmountResultVo> res = client.queryAmount(queryAmount);
|
|
|
+ if(res.getCode() == 0) {
|
|
|
+ BigDecimal balanceAmount = res.getData().getBalanceAmount();
|
|
|
+ // 变更余额
|
|
|
+ iShopDeliveryBindService.updateShopAmount(shopDeliveryBind.getMerchantId(), shopDeliveryBind.getDeliveryId(), shopDeliveryBind.getThirdShopId(), balanceAmount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void updateDadaShopNo(Member member, UpdateDadaShopNoDto updateDadaShopNoDto) {
|
|
|
int merchantCount = iShopDeliveryBindService.count(new QueryWrapper<ShopDeliveryBind>()
|
|
@@ -641,4 +682,141 @@ public class ApiDeliveryBindServiceImpl implements ApiDeliveryBindService {
|
|
|
return list.stream().sorted(Comparator.comparing(ShopBindDto::getShopId)).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Shop sfBind(Long shopId, String accountContactName, String accountContactPhone, String accountIdCard, String businessLicense, String healthPermits) {
|
|
|
+ Shop shop = iShopService.getById(shopId);
|
|
|
+ if (Objects.isNull(shop)) {
|
|
|
+ throw new CustomAppException("门店不存在或被删除!");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shop.getMerchantId() == null) {
|
|
|
+ throw new CustomAppException("请先申请成为商家!");
|
|
|
+ }
|
|
|
+ Merchant merchant = iMerchantService.getById(shop.getMerchantId());
|
|
|
+ if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
+ throw new CustomAppException("该商家已禁用!");
|
|
|
+ }
|
|
|
+ if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
+ throw new CustomAppException("请等待商家通过认证!");
|
|
|
+ }
|
|
|
+
|
|
|
+ DspDelivery dspDelivery = iDspDeliveryService.findOne(DeliveryTypeEnums.SHUN_FENG.getType());
|
|
|
+ List<ShopDeliveryBind> deliveryBindList = iShopDeliveryBindService.list(new QueryWrapper<ShopDeliveryBind>().eq("deleted", 0).eq("shop_id", shopId)
|
|
|
+ .eq("delivery_id", dspDelivery.getId()).eq("bind_status", BindStatusEnum.BIND.getStatus()));
|
|
|
+ if (CollectionUtils.isNotEmpty(deliveryBindList)) {
|
|
|
+ throw new CustomAppException("该门店已经绑定顺丰!");
|
|
|
+ }
|
|
|
+
|
|
|
+ shop.setLegalPerson(accountContactName);
|
|
|
+ shop.setDirectorMobile(accountContactPhone);
|
|
|
+ shop.setIdcardNo(accountIdCard);
|
|
|
+ shop.setBizLicenseIdcard(businessLicense);
|
|
|
+ shop.setFoodLicensePic(healthPermits);
|
|
|
+ iShopService.updateById(shop);
|
|
|
+
|
|
|
+ ShopVo shopVo = ShopEntityUtils.createShopVo(shop, dspDelivery, merchant);
|
|
|
+ log.info("门店信息:" + JsonMapper.nonEmptyMapper().toJson(shopVo));
|
|
|
+ ResObject<ShopResultVo> res = client.createShop(shopVo);
|
|
|
+ // 顺丰自运力绑定插入数据
|
|
|
+ if ("shunfeng".equals(shopVo.getLbClient())) {
|
|
|
+ ShopDeliveryBind deliveryBind= iShopDeliveryBindService.getOne(new QueryWrapper<ShopDeliveryBind>()
|
|
|
+ .eq("deleted", 0)
|
|
|
+ .eq("merchant_id", merchant.getId())
|
|
|
+ .eq("shop_id", shop.getId())
|
|
|
+ .eq("delivery_id", dspDelivery.getId()));
|
|
|
+
|
|
|
+ if (Objects.isNull(deliveryBind)) {
|
|
|
+ deliveryBind = new ShopDeliveryBind();
|
|
|
+ }
|
|
|
+
|
|
|
+ deliveryBind.setMerchantId(merchant.getId());
|
|
|
+ deliveryBind.setShopId(shop.getId());
|
|
|
+ deliveryBind.setDeliveryId(dspDelivery.getId());
|
|
|
+ if (res.getCode() == 0) {
|
|
|
+ deliveryBind.setBindStatus(BindStatusEnum.CHECK.getStatus());
|
|
|
+ }else {
|
|
|
+ deliveryBind.setAuthMsg(res.getMsg());
|
|
|
+ deliveryBind.setBindStatus(BindStatusEnum.REFUND.getStatus());
|
|
|
+ }
|
|
|
+ iShopDeliveryBindService.saveOrUpdate(deliveryBind);
|
|
|
+ }
|
|
|
+ return shop;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ShopBindDto> sfShopList(Member member, Long deliveryId) {
|
|
|
+ List<ShopBindDto> list = Lists.newArrayList();
|
|
|
+ if (MemberTypeEnum.MERCHANT.type.equals(member.getMemberType())) {
|
|
|
+ list = iShopService.findListByMerchantId(member.getMerchantId());
|
|
|
+ } else if (MemberTypeEnum.SHOP.type.equals(member.getMemberType())) {
|
|
|
+ list = iShopService.findListById(member.getShopId());
|
|
|
+ } else {
|
|
|
+ throw new CustomAppException("无效的用户类型!");
|
|
|
+ }
|
|
|
+ List<Shop> shopList = iShopService.list(new QueryWrapper<Shop>()
|
|
|
+ .eq("merchant_id", member.getMerchantId())
|
|
|
+ .eq("deleted", 0));
|
|
|
+
|
|
|
+ // 已经绑定的顺丰店铺
|
|
|
+ List<ShopDeliveryBind> shopDeliveryBindList = iShopDeliveryBindService.list(new QueryWrapper<ShopDeliveryBind>()
|
|
|
+ .eq("merchant_id", member.getMerchantId())
|
|
|
+ .eq("delivery_id", deliveryId)
|
|
|
+ .eq("deleted", 0)
|
|
|
+ .isNotNull("third_shop_id"));
|
|
|
+ List<Long> shopBinds = shopDeliveryBindList.stream().map(ShopDeliveryBind::getShopId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<Shop> newShopList = null;
|
|
|
+ if (CollectionUtils.isNotEmpty(shopBinds)) {
|
|
|
+ newShopList = shopList.stream().filter(shop -> !shopBinds.contains(shop.getId())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(newShopList)) {
|
|
|
+ newShopList = shopList;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Shop shop : newShopList) {
|
|
|
+ ShopBindDto dto = new ShopBindDto();
|
|
|
+ dto.setShopId(shop.getId());
|
|
|
+ dto.setShopName(shop.getName());
|
|
|
+ list.add(dto);
|
|
|
+ }
|
|
|
+
|
|
|
+ return list.stream().sorted(Comparator.comparing(ShopBindDto::getShopId)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ShopDeliveryBindDto> sfList(Member member) {
|
|
|
+ List<ShopDeliveryBindDto> bindList = iShopDeliveryBindService.sfList(member.getMerchantId());
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(bindList)) {
|
|
|
+ for (ShopDeliveryBindDto dto : bindList) {
|
|
|
+ Shop shop = iShopService.getById(dto.getShopId());
|
|
|
+ dto.setShopCode(shop.getCode());
|
|
|
+ if (BindStatusEnum.BIND.getStatus().equals(dto.getBindStatus())) {
|
|
|
+ dto.setAccountContactPhone(shop.getDirectorMobile());
|
|
|
+ // 查询余额
|
|
|
+ DeliveryInfo delivery = new DeliveryInfo();
|
|
|
+ delivery.setThirdShopId(dto.getThirdShopId());
|
|
|
+ delivery.setShopId(dto.getThirdShopId());
|
|
|
+ delivery.setAuthToken(dto.getAuthToken());
|
|
|
+ delivery.setPhone(dto.getAccount());
|
|
|
+ delivery.setType(dto.getDeliveryType());
|
|
|
+ DspDelivery dspDelivery = iDspDeliveryService.getById(dto.getDeliveryId());
|
|
|
+ QueryAmount queryAmount = QueryAmountEntityUtils.queryAmount(delivery, member.getMerchantId(),1);
|
|
|
+ ResObject<AmountResultVo> amountRes = client.queryAmount(queryAmount);
|
|
|
+ if (amountRes.getCode() == 0) {
|
|
|
+ // 更新余额
|
|
|
+ AmountResultVo vo = amountRes.getData();
|
|
|
+ this.updateAmount(dspDelivery, member.getMerchantId(), dto.getShopId(), vo.getBalanceAmount());
|
|
|
+ dto.setBalance(vo.getBalanceAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return bindList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|