ApiMerchantServiceImpl.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package com.ydd.app.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.ydd.app.dto.MerchantDto;
  4. import com.ydd.app.dto.ShopReq;
  5. import com.ydd.app.service.ApiMerchantService;
  6. import com.ydd.app.service.ApiShopService;
  7. import com.ydd.app.service.ApiWaimaiPlatformService;
  8. import com.ydd.app.service.ApiWaimaiService;
  9. import com.ydd.common.utils.SnCodeUtils;
  10. import com.ydd.module.domain.*;
  11. import com.ydd.module.dto.DeliveryConfigDto;
  12. import com.ydd.module.dto.ShopUserDto;
  13. import com.ydd.module.enums.MemberTypeEnum;
  14. import com.ydd.module.enums.MerchantStatusEnum;
  15. import com.ydd.module.enums.ShopUserTypeEnum;
  16. import com.ydd.module.expection.CustomAppException;
  17. import com.ydd.module.service.*;
  18. import lombok.RequiredArgsConstructor;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.transaction.annotation.Transactional;
  24. import java.util.List;
  25. /**
  26. * Project:lb-server
  27. * Class:ApiMerchantServiceImpl
  28. * Description:TODO
  29. * Time:2021/2/25 18:10
  30. *
  31. * @author zoe
  32. */
  33. @Slf4j
  34. @Service
  35. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  36. public class ApiMerchantServiceImpl implements ApiMerchantService {
  37. private final IMerchantCategoryService iMerchantCategoryService;
  38. private final IMerchantService iMerchantService;
  39. private final IMemberService iMemberService;
  40. private final ApiShopService apiShopService;
  41. private final IShopUserService iShopUserService;
  42. private final IShopService iShopService;
  43. // private final ApiWaimaiService apiWaimaiService;
  44. private final IAgentService iAgentService;
  45. private final ApiWaimaiPlatformService apiWaimaiPlatformService;
  46. @Override
  47. @Transactional(rollbackFor = Exception.class)
  48. public void saveMerchant(Long loginId, MerchantDto merchantDto) {
  49. MerchantCategory category = iMerchantCategoryService.getById(merchantDto.getCategoryId());
  50. if (category == null) {
  51. throw new CustomAppException("商家分类不存在!");
  52. }
  53. Member member = iMemberService.getById(loginId);
  54. if (member.getMemberType().equals(MemberTypeEnum.MERCHANT.type)) {
  55. throw new CustomAppException("已申请成为商家!");
  56. }
  57. Merchant merchant = new Merchant();
  58. BeanUtils.copyProperties(merchantDto, merchant);
  59. merchant.setStatus(MerchantStatusEnum.CERTIFIED.getStatus());
  60. merchant.setCode(SnCodeUtils.createMerchantSn());
  61. if (member.getAgentId() != null) {
  62. Agent agent = iAgentService.getInfoById(member.getAgentId());
  63. if (agent.getDistrictName().contains(merchantDto.getDistrictName())) {
  64. merchant.setAgentId(member.getAgentId());
  65. }
  66. }
  67. if (member.getPersonnelId() != null) {
  68. merchant.setPersonnelId(member.getPersonnelId());
  69. }
  70. if (member.getDadaDspId() != null) {
  71. merchant.setDadaDspId(member.getDadaDspId());
  72. }
  73. iMerchantService.save(merchant);
  74. member.setMerchantId(merchant.getId());
  75. member.setMemberType(MemberTypeEnum.MERCHANT.type);
  76. //默认创建一个门店(消息推送)
  77. ShopReq shopReq = new ShopReq();
  78. BeanUtils.copyProperties(merchantDto, shopReq);
  79. shopReq.setName(merchant.getMerchantName());
  80. iMemberService.updateById(member);
  81. Shop shop = apiShopService.saveShop(loginId, shopReq, true);
  82. member.setShopId(shop.getId());
  83. if (member.getAgentId() != null && merchant.getAgentId() == null) {
  84. member.setAgentId(null);
  85. }
  86. iMemberService.updateById(member);
  87. //创建默认管理员
  88. ShopUser shopUser = new ShopUser();
  89. shopUser.setShopId(shop.getId());
  90. shopUser.setMemberId(loginId);
  91. shopUser.setName(member.getNickname());
  92. shopUser.setMerchantId(member.getMerchantId());
  93. shopUser.setType(ShopUserTypeEnum.DINA_ZHANG.type);
  94. iShopUserService.save(shopUser);
  95. apiWaimaiPlatformService.saveConfig(loginId, new DeliveryConfigDto());
  96. }
  97. @Override
  98. public MerchantDto findDetail(Long loginId, Integer merchantId) {
  99. Merchant merchant = iMerchantService.getById(merchantId);
  100. MerchantDto dto = new MerchantDto();
  101. BeanUtils.copyProperties(merchant, dto);
  102. dto.setMerchantId(merchant.getId());
  103. MerchantCategory category = iMerchantCategoryService.getById(merchant.getCategoryId());
  104. dto.setCategoryName(category.getName());
  105. dto.setFnProductType(category.getFnProductType());
  106. return dto;
  107. }
  108. @Override
  109. @Transactional(rollbackFor = Exception.class)
  110. public void modify(Long loginId, MerchantDto merchantDto) {
  111. MerchantCategory category = iMerchantCategoryService.getById(merchantDto.getCategoryId());
  112. if (category == null) {
  113. throw new CustomAppException("商家分类不存在!");
  114. }
  115. // Member member = iMemberService.getById(loginId);
  116. // if (!member.getMerchantId().equals(merchantDto.getMerchantId())){
  117. // throw new CustomAppException("账号与商家不符!!");
  118. // }
  119. Merchant merchant = iMerchantService.getById(merchantDto.getMerchantId());
  120. if (!merchant.getCategoryId().equals(merchantDto.getCategoryId())) {
  121. Shop shop = new Shop();
  122. shop.setCategoryId(merchantDto.getCategoryId());
  123. iShopService.update(shop, new UpdateWrapper<Shop>().eq("merchant_id", merchant.getId()));
  124. }
  125. BeanUtils.copyProperties(merchantDto, merchant);
  126. iMerchantService.updateById(merchant);
  127. }
  128. @Override
  129. public List<MerchantCategory> category(Long loginId) {
  130. return iMerchantCategoryService.list();
  131. }
  132. }