|
|
@@ -17,6 +17,8 @@ import com.izouma.dingdong.repo.merchant.MerchantClassificationRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
|
|
|
import com.izouma.dingdong.security.Authority;
|
|
|
+import com.izouma.dingdong.service.UserService;
|
|
|
+import com.izouma.dingdong.utils.ObjUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
@@ -25,6 +27,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -40,36 +44,16 @@ public class MerchantService {
|
|
|
|
|
|
private MerchantClassificationRepo merchantClassificationRepo;
|
|
|
|
|
|
+ private UserService userService;
|
|
|
|
|
|
- /*
|
|
|
- 创建User
|
|
|
- */
|
|
|
- public User reg(){
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
/*
|
|
|
商户注册申请
|
|
|
*/
|
|
|
@Transactional
|
|
|
public MerchantDTO registerApply(MerchantDTO merchantDTO) {
|
|
|
- //用于商家登录
|
|
|
- User user = userRepo.findByPhone(merchantDTO.getPhone());
|
|
|
- if (ObjectUtil.isNull(user)) {
|
|
|
- user = User.builder().username(merchantDTO.getPhone())
|
|
|
- .password(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()))
|
|
|
- .blacklist(false)
|
|
|
- .enabled(true)
|
|
|
- .identity(Identity.MERCHANT)
|
|
|
- .phone(merchantDTO.getPhone())
|
|
|
- .nickname(merchantDTO.getShowName())
|
|
|
- .avatar(merchantDTO.getLogo())
|
|
|
- .authorities(Collections.singleton(new Authority(Authority.NAMES.ROLE_USER.name())))
|
|
|
- .build();
|
|
|
- } else {
|
|
|
- user.setPassword(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()));
|
|
|
- }
|
|
|
- user = userRepo.save(user);
|
|
|
+ //注册商家用户
|
|
|
+ User user = userService.register(merchantDTO.getPhone(), merchantDTO.getPassword());
|
|
|
|
|
|
//查看商家是否已存在
|
|
|
Merchant merchant1 = merchantRepo.findByPhone(merchantDTO.getPhone());
|
|
|
@@ -83,6 +67,31 @@ public class MerchantService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ user.setAvatar(merchantDTO.getLogo());
|
|
|
+ user.setNickname(merchantDTO.getShowName());
|
|
|
+ user.setIdentity(Identity.MERCHANT);
|
|
|
+ userRepo.save(user);
|
|
|
+
|
|
|
+// //用于商家登录
|
|
|
+// User user = userRepo.findByPhone(merchantDTO.getPhone());
|
|
|
+// if (ObjectUtil.isNull(user)) {
|
|
|
+// user = User.builder().username(merchantDTO.getPhone())
|
|
|
+// .password(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()))
|
|
|
+// .blacklist(false)
|
|
|
+// .enabled(true)
|
|
|
+// .identity(Identity.MERCHANT)
|
|
|
+// .phone(merchantDTO.getPhone())
|
|
|
+// .nickname(merchantDTO.getShowName())
|
|
|
+// .avatar(merchantDTO.getLogo())
|
|
|
+// .authorities(Collections.singleton(new Authority(Authority.NAMES.ROLE_USER.name())))
|
|
|
+// .build();
|
|
|
+// } else {
|
|
|
+// user.setPassword(new BCryptPasswordEncoder().encode(merchantDTO.getPassword()));
|
|
|
+// }
|
|
|
+// user = userRepo.save(user);
|
|
|
+
|
|
|
+
|
|
|
/* if (ObjectUtil.isEmpty(merchantDTO.getBusinessNature())) {
|
|
|
throw new BusinessException("商家性质未填");
|
|
|
}*/
|
|
|
@@ -95,9 +104,9 @@ public class MerchantService {
|
|
|
BeanUtil.copyProperties(merchantDTO, merchant);
|
|
|
merchant.setUserId(user.getId());
|
|
|
merchant.setStatus(ApplyStatus.PENDING);
|
|
|
-// merchant.setGoodNum(0);
|
|
|
-// merchant.setBadNum(0);
|
|
|
-// merchant.setMonthSales(0);
|
|
|
+ merchant.setGoodNum(0);
|
|
|
+ merchant.setBadNum(0);
|
|
|
+ merchant.setMonthSales(0);
|
|
|
merchant.setEnabled(true);
|
|
|
merchant.setBlacklist(false);
|
|
|
merchant = merchantRepo.save(merchant);
|
|
|
@@ -113,16 +122,23 @@ public class MerchantService {
|
|
|
|
|
|
/**
|
|
|
* 商户修改信息
|
|
|
+ *
|
|
|
* @param merchantDTO 修改的信息
|
|
|
* @return 修改
|
|
|
*/
|
|
|
public MerchantDTO change(MerchantDTO merchantDTO) {
|
|
|
+ if (merchantDTO.getMid() == null) {
|
|
|
+ return registerApply(merchantDTO);
|
|
|
+ }
|
|
|
Merchant merchant = merchantRepo.findById(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(merchantDTO.getMid()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
|
|
|
+ MerchantDTO dto = new MerchantDTO(merchant, merchantSettings);
|
|
|
+ ObjUtils.merge(dto, merchantDTO);
|
|
|
+
|
|
|
//dto转实体
|
|
|
- BeanUtil.copyProperties(merchantDTO, merchant);
|
|
|
- BeanUtil.copyProperties(merchantDTO, merchantSettings);
|
|
|
+ BeanUtil.copyProperties(dto, merchant);
|
|
|
+ BeanUtil.copyProperties(dto, merchantSettings);
|
|
|
merchantRepo.save(merchant);
|
|
|
merchantSettingsRepo.save(merchantSettings);
|
|
|
return merchantDTO;
|
|
|
@@ -130,21 +146,34 @@ public class MerchantService {
|
|
|
|
|
|
/**
|
|
|
* 商家过审
|
|
|
+ *
|
|
|
* @param merchantId 商户ID
|
|
|
- * @param pass 是否过审
|
|
|
+ * @param pass 是否过审
|
|
|
*/
|
|
|
public void audit(Long merchantId, Boolean pass) {
|
|
|
Merchant merchant = merchantRepo.findById(merchantId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
if (pass) {
|
|
|
merchant.setStatus(ApplyStatus.PASS);
|
|
|
merchant.setIsPass(true);
|
|
|
- //新建一好评热销分类
|
|
|
+ merchant.setEstablishTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ //新建 系统预制分类:好评热销
|
|
|
merchantClassificationRepo.save(MerchantClassification.builder()
|
|
|
.merchantId(merchantId)
|
|
|
.name(Constants.CLASSIFICATION_NAME)
|
|
|
.sort(1)
|
|
|
.isOpen(false)
|
|
|
+ .isShow(true)
|
|
|
.build());
|
|
|
+ merchantClassificationRepo.save(MerchantClassification.builder()
|
|
|
+ .merchantId(merchantId)
|
|
|
+ .name(Constants.CLASSIFICATION_NAME2)
|
|
|
+ .sort(2)
|
|
|
+ .isOpen(true)
|
|
|
+ .isShow(false)
|
|
|
+ .build());
|
|
|
+
|
|
|
+
|
|
|
} else {
|
|
|
merchant.setStatus(ApplyStatus.DENY);
|
|
|
merchant.setIsPass(false);
|
|
|
@@ -155,6 +184,7 @@ public class MerchantService {
|
|
|
|
|
|
/**
|
|
|
* 显示所有商家信息
|
|
|
+ *
|
|
|
* @param pageable 分页
|
|
|
* @return 分页列表
|
|
|
*/
|
|
|
@@ -170,6 +200,7 @@ public class MerchantService {
|
|
|
|
|
|
/**
|
|
|
* 显示个人的商户信息
|
|
|
+ *
|
|
|
* @param userId 用户的ID
|
|
|
* @return 个人的商户信息
|
|
|
*/
|
|
|
@@ -181,14 +212,14 @@ public class MerchantService {
|
|
|
|
|
|
/**
|
|
|
* 用户查找商家
|
|
|
+ *
|
|
|
* @param userId 用户ID
|
|
|
* @return 商家ID
|
|
|
*/
|
|
|
- public Long findMerchantId(Long userId){
|
|
|
+ public Long findMerchantId(Long userId) {
|
|
|
Merchant merchant = merchantRepo.findByUserId(userId).orElseThrow(new BusinessException("商户不存在"));
|
|
|
return merchant.getId();
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|