|
@@ -7,11 +7,13 @@ import com.ydd.app.ShopEditUtils;
|
|
|
import com.ydd.app.ShopEntityUtils;
|
|
|
import com.ydd.app.dto.ShopReq;
|
|
|
import com.ydd.app.service.ApiShopService;
|
|
|
+import com.ydd.app.service.ApiWaimaiService;
|
|
|
import com.ydd.common.enums.DeliveryTypeEnums;
|
|
|
import com.ydd.common.utils.SnCodeUtils;
|
|
|
import com.ydd.common.utils.StringUtils;
|
|
|
import com.ydd.ecloud.core.utils.JsonMapper;
|
|
|
import com.ydd.module.domain.*;
|
|
|
+import com.ydd.module.dto.DeliveryConfigDto;
|
|
|
import com.ydd.module.dto.DeliveryDto;
|
|
|
import com.ydd.module.dto.ShopDto;
|
|
|
import com.ydd.module.dto.WaimaiDto;
|
|
@@ -71,6 +73,8 @@ public class ApiShopServiceImpl implements ApiShopService {
|
|
|
|
|
|
private final IShopUserService iShopUserService;
|
|
|
|
|
|
+ private final ApiWaimaiService apiWaimaiService;
|
|
|
+
|
|
|
@Override
|
|
|
public List<ShopDto> findList(Long loginId) {
|
|
|
Member member = iMemberService.getById(loginId);
|
|
@@ -111,17 +115,25 @@ public class ApiShopServiceImpl implements ApiShopService {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Shop saveShop(Long loginId, ShopReq shopReq,boolean isMerchant) {
|
|
|
Member member = iMemberService.getById(loginId);
|
|
|
- if (member.getMerchantId() == null) {
|
|
|
- throw new CustomAppException("请先申请成为商家!");
|
|
|
- }
|
|
|
- Merchant merchant = iMerchantService.getById(member.getMerchantId());
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
- throw new CustomAppException("该商家已禁用!");
|
|
|
- }
|
|
|
- if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
- throw new CustomAppException("请等待商家通过认证!");
|
|
|
+
|
|
|
+ // 判断店铺名称是否重复
|
|
|
+ List<Shop> shops = iShopService.getShopByName(shopReq.getName(), null);
|
|
|
+ if (shops != null && shops.size() > 0) {
|
|
|
+ throw new CustomAppException("店铺名称重复!");
|
|
|
}
|
|
|
- Long categoryId = merchant.getCategoryId();
|
|
|
+
|
|
|
+// if (member.getMerchantId() == null) {
|
|
|
+// throw new CustomAppException("请先申请成为商家!");
|
|
|
+// }
|
|
|
+// Merchant merchant = iMerchantService.getById(member.getMerchantId());
|
|
|
+// if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
+// throw new CustomAppException("该商家已禁用!");
|
|
|
+// }
|
|
|
+// if (merchant.getStatus().equals(MerchantStatusEnum.TO_BE_CERTIFIED.status)) {
|
|
|
+// throw new CustomAppException("请等待商家通过认证!");
|
|
|
+// }
|
|
|
+// Long categoryId = merchant.getCategoryId();
|
|
|
+ Long categoryId = null;
|
|
|
if (null != shopReq.getCategoryId()){
|
|
|
categoryId = shopReq.getCategoryId();
|
|
|
}
|
|
@@ -129,6 +141,49 @@ public class ApiShopServiceImpl implements ApiShopService {
|
|
|
if (category == null){
|
|
|
throw new CustomAppException("门店分类不存在!");
|
|
|
}
|
|
|
+
|
|
|
+ Merchant merchant = new Merchant();
|
|
|
+ // 第一个店铺新增的时候创建默认商家
|
|
|
+ if (member.getMerchantId() == null) {
|
|
|
+ merchant.setCode(SnCodeUtils.createMerchantSn());
|
|
|
+ merchant.setMerchantName(shopReq.getName());
|
|
|
+ if (member.getAgentId() != null){
|
|
|
+ merchant.setAgentId(member.getAgentId());
|
|
|
+ }
|
|
|
+ if (member.getPersonnelId() != null){
|
|
|
+ merchant.setPersonnelId(member.getPersonnelId());
|
|
|
+ }
|
|
|
+ merchant.setProvinceName(shopReq.getProvinceName());
|
|
|
+ merchant.setCityName(shopReq.getCityName());
|
|
|
+ merchant.setDistrictName(shopReq.getDistrictName());
|
|
|
+ merchant.setCityCode(shopReq.getCityCode());
|
|
|
+ merchant.setCategoryId(shopReq.getCategoryId());
|
|
|
+ merchant.setContactName(shopReq.getContactName());
|
|
|
+ merchant.setMobile(shopReq.getMobile());
|
|
|
+ merchant.setBizLicense(shopReq.getBizLicense());
|
|
|
+ merchant.setBizLicenseNo(shopReq.getBizLicenseNo());
|
|
|
+ merchant.setLegalPerson(shopReq.getLegalPerson());
|
|
|
+ merchant.setIdcardNo(shopReq.getIdcardNo());
|
|
|
+ merchant.setIdcardFront(shopReq.getIdcardFront());
|
|
|
+ merchant.setIdcardBack(shopReq.getIdcardBack());
|
|
|
+ merchant.setBizLicenseIdcard(shopReq.getBizLicenseIdcard());
|
|
|
+ merchant.setLng(shopReq.getLng());
|
|
|
+ merchant.setLat(shopReq.getLat());
|
|
|
+ merchant.setAddress(shopReq.getAddress());
|
|
|
+ merchant.setStreet(shopReq.getStreet());
|
|
|
+ merchant.setFoodLicensePic(shopReq.getFoodLicensePic());
|
|
|
+ merchant.setStatus(MerchantStatusEnum.CERTIFIED.status);
|
|
|
+ iMerchantService.save(merchant);
|
|
|
+ member.setMerchantId(merchant.getId());
|
|
|
+ member.setMemberType(MemberTypeEnum.MERCHANT.type);
|
|
|
+ }else {
|
|
|
+ merchant = iMerchantService.getById(member.getMerchantId());
|
|
|
+ if (merchant.getStatus().equals(MerchantStatusEnum.STOP.status)) {
|
|
|
+ throw new CustomAppException("该商家已禁用!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
Shop shop = new Shop();
|
|
|
shop.setAddress(shopReq.getAddress());
|
|
|
shop.setCategoryId(categoryId);
|
|
@@ -153,7 +208,28 @@ public class ApiShopServiceImpl implements ApiShopService {
|
|
|
shop.setIdcardBack(shopReq.getIdcardBack());
|
|
|
shop.setBizLicenseIdcard(shopReq.getBizLicenseIdcard());
|
|
|
shop.setFoodLicensePic(shopReq.getFoodLicensePic());
|
|
|
+ shop.setHouseNo(shopReq.getHouseNo());
|
|
|
+ shop.setPoi(shopReq.getPoi());
|
|
|
iShopService.save(shop);
|
|
|
+
|
|
|
+ // 判断商家拥有几个门店
|
|
|
+ List<ShopDto> shopList = iShopService.findList(shop.getMerchantId());
|
|
|
+ if (shopList != null && shopList.size() == 1) {
|
|
|
+ member.setShopId(shop.getId());
|
|
|
+ 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);
|
|
|
+ apiWaimaiService.saveConfig(loginId,new DeliveryConfigDto());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
//绑定最新门店到账户
|
|
|
// member.setShopId(shop.getId());
|
|
|
// iMemberService.saveOrUpdate(member);
|