|
@@ -5,20 +5,26 @@ import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.domain.User;
|
|
import com.izouma.dingdong.domain.User;
|
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
import com.izouma.dingdong.domain.merchant.Merchant;
|
|
|
|
|
+import com.izouma.dingdong.domain.merchant.MerchantClassification;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
import com.izouma.dingdong.domain.merchant.MerchantSettings;
|
|
|
import com.izouma.dingdong.dto.MerchantDTO;
|
|
import com.izouma.dingdong.dto.MerchantDTO;
|
|
|
import com.izouma.dingdong.enums.ApplyStatus;
|
|
import com.izouma.dingdong.enums.ApplyStatus;
|
|
|
import com.izouma.dingdong.enums.Identity;
|
|
import com.izouma.dingdong.enums.Identity;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
import com.izouma.dingdong.repo.UserRepo;
|
|
|
|
|
+import com.izouma.dingdong.repo.merchant.MerchantClassificationRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
|
|
|
+import com.izouma.dingdong.security.Authority;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Pageable;
|
|
|
|
|
+import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.transaction.Transactional;
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -31,22 +37,30 @@ public class MerchantService {
|
|
|
|
|
|
|
|
private UserRepo userRepo;
|
|
private UserRepo userRepo;
|
|
|
|
|
|
|
|
|
|
+ private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
商户注册申请
|
|
商户注册申请
|
|
|
*/
|
|
*/
|
|
|
|
|
+ @Transactional
|
|
|
public MerchantDTO registerApply(MerchantDTO merchantDTO) {
|
|
public MerchantDTO registerApply(MerchantDTO merchantDTO) {
|
|
|
//用于商家登录
|
|
//用于商家登录
|
|
|
User user = userRepo.findByPhone(merchantDTO.getPhone());
|
|
User user = userRepo.findByPhone(merchantDTO.getPhone());
|
|
|
if (ObjectUtil.isNull(user)) {
|
|
if (ObjectUtil.isNull(user)) {
|
|
|
user = User.builder().username(merchantDTO.getPhone())
|
|
user = User.builder().username(merchantDTO.getPhone())
|
|
|
- .password(merchantDTO.getPassword())
|
|
|
|
|
|
|
+ .password(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()))
|
|
|
.blacklist(false)
|
|
.blacklist(false)
|
|
|
.enabled(true)
|
|
.enabled(true)
|
|
|
.identity(Identity.MERCHANT)
|
|
.identity(Identity.MERCHANT)
|
|
|
.phone(merchantDTO.getPhone())
|
|
.phone(merchantDTO.getPhone())
|
|
|
|
|
+ .nickname(merchantDTO.getShowName())
|
|
|
|
|
+ .avatar(merchantDTO.getLogo())
|
|
|
|
|
+ .authorities(Collections.singleton(new Authority(Authority.NAMES.ROLE_USER.name())))
|
|
|
.build();
|
|
.build();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ user.setPassword(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()));
|
|
|
}
|
|
}
|
|
|
- user.setPassword(merchantDTO.getPassword());
|
|
|
|
|
|
|
+ user = userRepo.save(user);
|
|
|
|
|
|
|
|
//查看商家是否已存在
|
|
//查看商家是否已存在
|
|
|
Merchant merchant1 = merchantRepo.findByPhone(merchantDTO.getPhone());
|
|
Merchant merchant1 = merchantRepo.findByPhone(merchantDTO.getPhone());
|
|
@@ -60,7 +74,6 @@ public class MerchantService {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/* if (ObjectUtil.isEmpty(merchantDTO.getBusinessNature())) {
|
|
/* if (ObjectUtil.isEmpty(merchantDTO.getBusinessNature())) {
|
|
|
throw new BusinessException("商家性质未填");
|
|
throw new BusinessException("商家性质未填");
|
|
|
}*/
|
|
}*/
|
|
@@ -69,30 +82,34 @@ public class MerchantService {
|
|
|
Merchant merchant = new Merchant();
|
|
Merchant merchant = new Merchant();
|
|
|
MerchantSettings merchantSettings = new MerchantSettings();
|
|
MerchantSettings merchantSettings = new MerchantSettings();
|
|
|
|
|
|
|
|
- //dto转实体
|
|
|
|
|
|
|
+ //dto转merchant实体
|
|
|
BeanUtil.copyProperties(merchantDTO, merchant);
|
|
BeanUtil.copyProperties(merchantDTO, merchant);
|
|
|
merchant.setUserId(user.getId());
|
|
merchant.setUserId(user.getId());
|
|
|
merchant.setStatus(ApplyStatus.PENDING);
|
|
merchant.setStatus(ApplyStatus.PENDING);
|
|
|
-
|
|
|
|
|
- //dto转实体
|
|
|
|
|
|
|
+// merchant.setGoodNum(0);
|
|
|
|
|
+// merchant.setBadNum(0);
|
|
|
|
|
+// merchant.setMonthSales(0);
|
|
|
|
|
+ merchant.setEnabled(true);
|
|
|
|
|
+ merchant.setBlacklist(false);
|
|
|
|
|
+ merchant = merchantRepo.save(merchant);
|
|
|
|
|
+
|
|
|
|
|
+ //dto转merchantSettings实体
|
|
|
BeanUtil.copyProperties(merchantDTO, merchantSettings);
|
|
BeanUtil.copyProperties(merchantDTO, merchantSettings);
|
|
|
merchantSettings.setMerchantId(merchant.getId());
|
|
merchantSettings.setMerchantId(merchant.getId());
|
|
|
-
|
|
|
|
|
- userRepo.save(user);
|
|
|
|
|
- merchantRepo.save(merchant);
|
|
|
|
|
|
|
+ merchantSettings.setEnabled(true);
|
|
|
merchantSettingsRepo.save(merchantSettings);
|
|
merchantSettingsRepo.save(merchantSettings);
|
|
|
|
|
+
|
|
|
return merchantDTO;
|
|
return merchantDTO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- 商户修改
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商户修改信息
|
|
|
|
|
+ * @param merchantDTO 修改的信息
|
|
|
|
|
+ * @return 修改
|
|
|
*/
|
|
*/
|
|
|
public MerchantDTO change(MerchantDTO merchantDTO) {
|
|
public MerchantDTO change(MerchantDTO merchantDTO) {
|
|
|
- Merchant merchant = merchantRepo.findById(merchantDTO.getId()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
- MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchantDTO.getId());
|
|
|
|
|
- if (ObjectUtil.isNull(merchantSettings)) {
|
|
|
|
|
- throw new BusinessException("商户不存在");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ Merchant merchant = merchantRepo.findById(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
+ MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
|
|
|
//dto转实体
|
|
//dto转实体
|
|
|
BeanUtil.copyProperties(merchantDTO, merchant);
|
|
BeanUtil.copyProperties(merchantDTO, merchant);
|
|
@@ -102,22 +119,22 @@ public class MerchantService {
|
|
|
return merchantDTO;
|
|
return merchantDTO;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- 商户删除
|
|
|
|
|
- */
|
|
|
|
|
- public void del(Long id) {
|
|
|
|
|
- merchantRepo.deleteById(id);
|
|
|
|
|
- merchantSettingsRepo.deleteByMerchantId(id);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
- 商户过审
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 商家过审
|
|
|
|
|
+ * @param merchantId 商户ID
|
|
|
|
|
+ * @param pass 是否过审
|
|
|
*/
|
|
*/
|
|
|
- public void audit(Long id, Boolean pass) {
|
|
|
|
|
- Merchant merchant = merchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
|
|
+ public void audit(Long merchantId, Boolean pass) {
|
|
|
|
|
+ Merchant merchant = merchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
if (pass) {
|
|
if (pass) {
|
|
|
merchant.setStatus(ApplyStatus.PASS);
|
|
merchant.setStatus(ApplyStatus.PASS);
|
|
|
merchant.setIsPass(true);
|
|
merchant.setIsPass(true);
|
|
|
|
|
+ //新建一好评热销分类
|
|
|
|
|
+ merchantClassificationRepo.save(MerchantClassification.builder()
|
|
|
|
|
+ .merchantId(merchantId)
|
|
|
|
|
+ .name("好评热销")
|
|
|
|
|
+ .sort(1)
|
|
|
|
|
+ .build());
|
|
|
} else {
|
|
} else {
|
|
|
merchant.setStatus(ApplyStatus.DENY);
|
|
merchant.setStatus(ApplyStatus.DENY);
|
|
|
merchant.setIsPass(false);
|
|
merchant.setIsPass(false);
|
|
@@ -126,26 +143,38 @@ public class MerchantService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- 显示所有
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 显示所有商家信息
|
|
|
|
|
+ * @param pageable 分页
|
|
|
|
|
+ * @return 分页列表
|
|
|
*/
|
|
*/
|
|
|
public Page<MerchantDTO> showAll(Pageable pageable) {
|
|
public Page<MerchantDTO> showAll(Pageable pageable) {
|
|
|
List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
|
|
List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
|
|
|
List<Merchant> merchants = merchantRepo.findAll();
|
|
List<Merchant> merchants = merchantRepo.findAll();
|
|
|
- List<MerchantSettings> merchantSettings = merchantSettingsRepo.findAll();
|
|
|
|
|
for (int i = 0; i < merchants.size(); i++) {
|
|
for (int i = 0; i < merchants.size(); i++) {
|
|
|
- merchantDTOS.add(new MerchantDTO(merchants.get(i), merchantSettings.get(i)));
|
|
|
|
|
|
|
+ MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchants.get(i).getId()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
+ merchantDTOS.add(new MerchantDTO(merchants.get(i), merchantSettings));
|
|
|
}
|
|
}
|
|
|
return new PageImpl<>(merchantDTOS, pageable, merchantDTOS.size());
|
|
return new PageImpl<>(merchantDTOS, pageable, merchantDTOS.size());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /*
|
|
|
|
|
- 显示个人
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 显示个人的商户信息
|
|
|
|
|
+ * @param userId 用户的ID
|
|
|
|
|
+ * @return 个人的商户信息
|
|
|
*/
|
|
*/
|
|
|
- public MerchantDTO my(Long id) {
|
|
|
|
|
- Merchant merchant = merchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
- MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(id);
|
|
|
|
|
|
|
+ public MerchantDTO my(Long userId) {
|
|
|
|
|
+ Merchant merchant = merchantRepo.findByUserId(userId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
+ MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchant.getId()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
return new MerchantDTO(merchant, merchantSettings);
|
|
return new MerchantDTO(merchant, merchantSettings);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /*
|
|
|
|
|
+ 用户查找商家
|
|
|
|
|
+ */
|
|
|
|
|
+ public Long findMerchantId(Long userId){
|
|
|
|
|
+ Merchant merchant = merchantRepo.findByUserId(userId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
+ return merchant.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|