123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- package com.ydd.app.service.impl;
- import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
- import com.ydd.app.dto.MerchantDto;
- import com.ydd.app.dto.ShopReq;
- import com.ydd.app.service.ApiMerchantService;
- import com.ydd.app.service.ApiShopService;
- import com.ydd.app.service.ApiWaimaiPlatformService;
- import com.ydd.app.service.ApiWaimaiService;
- import com.ydd.common.utils.SnCodeUtils;
- import com.ydd.module.domain.*;
- import com.ydd.module.dto.DeliveryConfigDto;
- import com.ydd.module.dto.ShopUserDto;
- import com.ydd.module.enums.MemberTypeEnum;
- import com.ydd.module.enums.MerchantStatusEnum;
- import com.ydd.module.enums.ShopUserTypeEnum;
- import com.ydd.module.expection.CustomAppException;
- import com.ydd.module.service.*;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.util.List;
- /**
- * Project:lb-server
- * Class:ApiMerchantServiceImpl
- * Description:TODO
- * Time:2021/2/25 18:10
- *
- * @author zoe
- */
- @Slf4j
- @Service
- @RequiredArgsConstructor(onConstructor_ = @Autowired)
- public class ApiMerchantServiceImpl implements ApiMerchantService {
- private final IMerchantCategoryService iMerchantCategoryService;
- private final IMerchantService iMerchantService;
- private final IMemberService iMemberService;
- private final ApiShopService apiShopService;
- private final IShopUserService iShopUserService;
- private final IShopService iShopService;
- // private final ApiWaimaiService apiWaimaiService;
- private final IAgentService iAgentService;
- private final ApiWaimaiPlatformService apiWaimaiPlatformService;
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void saveMerchant(Long loginId, MerchantDto merchantDto) {
- MerchantCategory category = iMerchantCategoryService.getById(merchantDto.getCategoryId());
- if (category == null) {
- throw new CustomAppException("商家分类不存在!");
- }
- Member member = iMemberService.getById(loginId);
- if (member.getMemberType().equals(MemberTypeEnum.MERCHANT.type)) {
- throw new CustomAppException("已申请成为商家!");
- }
- Merchant merchant = new Merchant();
- BeanUtils.copyProperties(merchantDto, merchant);
- merchant.setStatus(MerchantStatusEnum.CERTIFIED.getStatus());
- merchant.setCode(SnCodeUtils.createMerchantSn());
- if (member.getAgentId() != null) {
- Agent agent = iAgentService.getInfoById(member.getAgentId());
- if (agent.getDistrictName().contains(merchantDto.getDistrictName())) {
- merchant.setAgentId(member.getAgentId());
- }
- }
- if (member.getPersonnelId() != null) {
- merchant.setPersonnelId(member.getPersonnelId());
- }
- if (member.getDadaDspId() != null) {
- merchant.setDadaDspId(member.getDadaDspId());
- }
- iMerchantService.save(merchant);
- member.setMerchantId(merchant.getId());
- member.setMemberType(MemberTypeEnum.MERCHANT.type);
- //默认创建一个门店(消息推送)
- ShopReq shopReq = new ShopReq();
- BeanUtils.copyProperties(merchantDto, shopReq);
- shopReq.setName(merchant.getMerchantName());
- iMemberService.updateById(member);
- Shop shop = apiShopService.saveShop(loginId, shopReq, true);
- member.setShopId(shop.getId());
- if (member.getAgentId() != null && merchant.getAgentId() == null) {
- member.setAgentId(null);
- }
- iMemberService.updateById(member);
- //创建默认管理员
- ShopUser shopUser = new ShopUser();
- shopUser.setShopId(shop.getId());
- shopUser.setMemberId(loginId);
- shopUser.setName(member.getNickname());
- shopUser.setMerchantId(member.getMerchantId());
- shopUser.setType(ShopUserTypeEnum.DINA_ZHANG.type);
- iShopUserService.save(shopUser);
- apiWaimaiPlatformService.saveConfig(loginId, new DeliveryConfigDto());
- }
- @Override
- public MerchantDto findDetail(Long loginId, Integer merchantId) {
- Merchant merchant = iMerchantService.getById(merchantId);
- MerchantDto dto = new MerchantDto();
- BeanUtils.copyProperties(merchant, dto);
- dto.setMerchantId(merchant.getId());
- MerchantCategory category = iMerchantCategoryService.getById(merchant.getCategoryId());
- dto.setCategoryName(category.getName());
- dto.setFnProductType(category.getFnProductType());
- return dto;
- }
- @Override
- @Transactional(rollbackFor = Exception.class)
- public void modify(Long loginId, MerchantDto merchantDto) {
- MerchantCategory category = iMerchantCategoryService.getById(merchantDto.getCategoryId());
- if (category == null) {
- throw new CustomAppException("商家分类不存在!");
- }
- // Member member = iMemberService.getById(loginId);
- // if (!member.getMerchantId().equals(merchantDto.getMerchantId())){
- // throw new CustomAppException("账号与商家不符!!");
- // }
- Merchant merchant = iMerchantService.getById(merchantDto.getMerchantId());
- if (!merchant.getCategoryId().equals(merchantDto.getCategoryId())) {
- Shop shop = new Shop();
- shop.setCategoryId(merchantDto.getCategoryId());
- iShopService.update(shop, new UpdateWrapper<Shop>().eq("merchant_id", merchant.getId()));
- }
- BeanUtils.copyProperties(merchantDto, merchant);
- iMerchantService.updateById(merchant);
- }
- @Override
- public List<MerchantCategory> category(Long loginId) {
- return iMerchantCategoryService.list();
- }
- }
|