zoujiajian 2 лет назад
Родитель
Сommit
629c827ecf

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/shop/YhShopApplyRecordMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper.shop;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.YhShopApplyRecord;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopApplyRecordMapper
+ *创建者: JavaZou
+ *创建时间:2023/9/21 10:38
+ */
+public interface YhShopApplyRecordMapper extends BaseMapper<YhShopApplyRecord> {
+}

+ 0 - 7
netflix-dao/src/main/java/com/cyksj/model/entity/YhShop.java

@@ -60,11 +60,6 @@ public class YhShop extends BaseEntity {
 	 */
 	 */
 	private String contact;
 	private String contact;
 
 
-	/**
-	 * 申请修改的 店铺名
-	 */
-	private String modifyName;
-
 	/**
 	/**
 	 * 备注
 	 * 备注
 	 */
 	 */
@@ -73,8 +68,6 @@ public class YhShop extends BaseEntity {
 	@Getter
 	@Getter
 	public enum Status {
 	public enum Status {
 		verify("审核中"),
 		verify("审核中"),
-		modify("申请修改"),
-		modify_fail("申请修改失败"),
 		success("审核通过"),
 		success("审核通过"),
 		fail("审核失败");
 		fail("审核失败");
 		String desc;
 		String desc;

+ 59 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopApplyRecord.java

@@ -0,0 +1,59 @@
+package com.cyksj.model.entity;
+
+import com.baomidou.mybatisplus.annotation.FieldStrategy;
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Date;
+
+/*
+ *项目名: yhlxj
+ *文件名: YhShopApplyRecord
+ *创建者: JavaZou
+ *创建时间:2023/9/21 10:36
+ */
+@Getter
+@Setter
+public class YhShopApplyRecord extends BaseEntity {
+	/**
+	 * 店主id
+	 */
+	private Long userId;
+
+	/**
+	 * 店铺名称
+	 */
+	private String name;
+
+	/**
+	 * 自定义id
+	 */
+	private String customId;
+
+	/**
+	 * 是否审核通过
+	 */
+	private Status verifyStatus;
+
+	/**
+	 * 审核失败原因
+	 */
+	@TableField(updateStrategy = FieldStrategy.IGNORED)
+	private String reason;
+
+	private Date verifyTime;
+
+	@Getter
+	public enum Status {
+		verify("审核中"),
+		modify("审核修改"),
+		success("审核通过"),
+		fail("审核失败");
+		String desc;
+
+		Status(String desc) {
+			this.desc = desc;
+		}
+	}
+}

+ 0 - 5
netflix-dao/src/main/java/com/cyksj/model/entity/YhShopUserDistributeShared.java

@@ -26,10 +26,5 @@ public class YhShopUserDistributeShared extends BaseEntity{
 	 * 邀请方式备注
 	 * 邀请方式备注
 	 */
 	 */
 	private String remark;
 	private String remark;
-
-	/**
-	 * cps后台自定义推广链接id
-	 */
-	private Long dsPopularizeId;
 }
 }
 
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/request/LoginReq.java

@@ -63,4 +63,9 @@ public class LoginReq {
 	private String callbackType;
 	private String callbackType;
 
 
 	private String subject;
 	private String subject;
+
+	/**
+	 * 店铺自定义id
+	 */
+	private String customId;
 }
 }

+ 2 - 2
netflix-dao/src/main/java/com/cyksj/model/request/YhShopVerifyReq.java

@@ -1,6 +1,6 @@
 package com.cyksj.model.request;
 package com.cyksj.model.request;
 
 
-import com.cyksj.model.entity.YhShop;
+import com.cyksj.model.entity.YhShopApplyRecord;
 import lombok.Getter;
 import lombok.Getter;
 import lombok.Setter;
 import lombok.Setter;
 
 
@@ -23,7 +23,7 @@ public class YhShopVerifyReq {
 	 * 是否审核通过
 	 * 是否审核通过
 	 */
 	 */
 	@NotNull
 	@NotNull
-	private YhShop.Status verifyStatus;
+	private YhShopApplyRecord.Status verifyStatus;
 
 
 	private String reason;
 	private String reason;
 
 

+ 3 - 19
netflix-dao/src/main/java/com/cyksj/model/views/YhShopView.java

@@ -1,6 +1,6 @@
 package com.cyksj.model.views;
 package com.cyksj.model.views;
 
 
-import com.cyksj.model.entity.YhShop;
+import com.cyksj.model.entity.YhShopApplyRecord;
 import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.DbField;
 import com.ejlchina.searcher.bean.SearchBean;
 import com.ejlchina.searcher.bean.SearchBean;
 import lombok.Getter;
 import lombok.Getter;
@@ -16,8 +16,7 @@ import java.util.Date;
  */
  */
 @Getter
 @Getter
 @Setter
 @Setter
-@SearchBean(tables = "yh_shop ys left user u on u.id = ys.user_id" +
-		" left join cms_user cu on cu.id = u.business_id")
+@SearchBean(tables = "yh_shop_apply_record ys left user u on u.id = ys.user_id")
 public class YhShopView {
 public class YhShopView {
 	@DbField("ys.id")
 	@DbField("ys.id")
 	private Long id;
 	private Long id;
@@ -41,26 +40,11 @@ public class YhShopView {
 	@DbField("ys.custom_id")
 	@DbField("ys.custom_id")
 	private String customId;
 	private String customId;
 
 
-	/**
-	 * 商务id
-	 */
-	@DbField("ys.business_id")
-	private Long businessId;
-
-	@DbField("cu.nickname")
-	private String businessName;
-
 	/**
 	/**
 	 * 是否审核通过
 	 * 是否审核通过
 	 */
 	 */
 	@DbField("ys.verify_status")
 	@DbField("ys.verify_status")
-	private YhShop.Status verifyStatus;
-
-	/**
-	 * 店铺开放状态
-	 */
-	@DbField("ys.status")
-	private Boolean status;
+	private YhShopApplyRecord.Status verifyStatus;
 
 
 	/**
 	/**
 	 * 审核失败原因
 	 * 审核失败原因

+ 24 - 11
netflix-service/src/main/java/com/cyksj/service/mange/goods/CmsYhShopCommonServiceImpl.java

@@ -48,6 +48,8 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 
 
 	private final YhShopMapper yhShopMapper;
 	private final YhShopMapper yhShopMapper;
 
 
+	private final YhShopApplyRecordMapper yhShopApplyRecordMapper;
+
 	private final UserBusinessRateService userBusinessRateService;
 	private final UserBusinessRateService userBusinessRateService;
 
 
 	private final YhShopUserPlatDistributeRateService yhShopUserPlatDistributeRateService;
 	private final YhShopUserPlatDistributeRateService yhShopUserPlatDistributeRateService;
@@ -82,33 +84,44 @@ public class CmsYhShopCommonServiceImpl implements CmsYhShopCommonService {
 	}
 	}
 
 
 	@Override
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public void verifyYhShopApply(YhShopVerifyReq verifyReq) {
 	public void verifyYhShopApply(YhShopVerifyReq verifyReq) {
 		Long id = verifyReq.getId();
 		Long id = verifyReq.getId();
-		YhShop.Status verifyStatus = verifyReq.getVerifyStatus();
+		YhShopApplyRecord.Status verifyStatus = verifyReq.getVerifyStatus();
 		String reason = verifyReq.getReason();
 		String reason = verifyReq.getReason();
-		YhShop yhShop = yhShopMapper.selectById(id);
-		Assert.notNull(yhShop, "开店申请不存在");
-		if (yhShop.getVerifyStatus() != YhShop.Status.verify && yhShop.getVerifyStatus() != YhShop.Status.modify) {
+		YhShopApplyRecord yhShopApplyRecord = yhShopApplyRecordMapper.selectById(id);
+		YhShop yhShop = yhShopMapper.selectOne(Wrappers.lambdaQuery(YhShop.class)
+				.eq(YhShop::getUserId, yhShopApplyRecord.getUserId()).last("limit 1"));
+		Assert.notNull(yhShopApplyRecord, "开店申请记录不存在");
+		Assert.notNull(yhShop, "开店申请记录不存在");
+		if (yhShopApplyRecord.getVerifyStatus() != YhShopApplyRecord.Status.verify || yhShopApplyRecord.getVerifyStatus() != YhShopApplyRecord.Status.modify) {
 			throw BusinessRuntimeException.getInstance("该开店申请已审核");
 			throw BusinessRuntimeException.getInstance("该开店申请已审核");
 		}
 		}
-		if (verifyStatus != YhShop.Status.success || verifyStatus != YhShop.Status.fail) {
+		if (verifyStatus != YhShopApplyRecord.Status.success || verifyStatus != YhShopApplyRecord.Status.fail) {
 			throw BusinessRuntimeException.getInstance("请选择正确的审核状态");
 			throw BusinessRuntimeException.getInstance("请选择正确的审核状态");
 		}
 		}
-		if (verifyStatus == YhShop.Status.fail) {
+		if (verifyStatus == YhShopApplyRecord.Status.fail) {
 			if (StrUtil.isEmpty(reason)) {
 			if (StrUtil.isEmpty(reason)) {
 				throw BusinessRuntimeException.getInstance("请输入审核失败原因");
 				throw BusinessRuntimeException.getInstance("请输入审核失败原因");
 			}
 			}
+			yhShopApplyRecord.setReason(reason);
 			yhShop.setReason(reason);
 			yhShop.setReason(reason);
-			//申请修改
-			if (yhShop.getVerifyStatus() == YhShop.Status.modify) {
-				yhShop.setVerifyStatus(YhShop.Status.modify_fail);
+			if (yhShop.getVerifyStatus() == YhShop.Status.verify) {
+				yhShop.setVerifyStatus(YhShop.Status.fail);
 			}
 			}
 		} else {
 		} else {
-			if (yhShop.getVerifyStatus() == YhShop.Status.modify) {
-				yhShop.setName(yhShop.getModifyName());
+			//申请修改
+			if (yhShopApplyRecord.getVerifyStatus() == YhShopApplyRecord.Status.modify) {
+				yhShop.setName(yhShopApplyRecord.getName());
 			}
 			}
 			yhShop.setReason(null);
 			yhShop.setReason(null);
+			if (yhShop.getVerifyStatus() == YhShop.Status.verify) {
+				yhShop.setVerifyStatus(YhShop.Status.success);
+			}
 		}
 		}
+		yhShopApplyRecord.setVerifyTime(DateTime.now());
+		yhShopApplyRecord.setVerifyStatus(verifyStatus);
+		yhShopApplyRecordMapper.updateById(yhShopApplyRecord);
 		yhShopMapper.updateById(yhShop);
 		yhShopMapper.updateById(yhShop);
 	}
 	}
 
 

+ 5 - 0
netflix-service/src/main/java/com/cyksj/service/shop/YhShopDistributeService.java

@@ -16,4 +16,9 @@ public interface YhShopDistributeService {
 	 * @param orderDon
 	 * @param orderDon
 	 */
 	 */
 	void deductDsMoney(OrderDon orderDon);
 	void deductDsMoney(OrderDon orderDon);
+
+	/**
+	 * 店铺分销 用户关系记录
+	 */
+	void saveDistributionInvitation(String customId, Long userId);
 }
 }

+ 21 - 0
netflix-service/src/main/java/com/cyksj/service/shop/impl/YhShopDistributeServiceImpl.java

@@ -12,6 +12,7 @@ import com.cyksj.service.shop.YhShopDistributeService;
 import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.user.UserBenefitsService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.math.BigDecimal;
 import java.math.BigDecimal;
@@ -141,4 +142,24 @@ public class YhShopDistributeServiceImpl implements YhShopDistributeService {
 			}
 			}
 		}
 		}
 	}
 	}
+
+	@Override
+	public void saveDistributionInvitation(String customId, Long userId) {
+		customId = customId.trim();
+		YhShop yhShop = yhShopMapper.selectOne(Wrappers.lambdaQuery(YhShop.class).eq(YhShop::getCustomId, customId).last("limit 1"));
+		if (yhShop.getVerifyStatus() != YhShop.Status.success) {
+			return;
+		}
+		if (!yhShop.getStatus()) {
+			return;
+		}
+		try {
+			Long shopUserId = yhShop.getUserId();
+			YhShopUserDistributeShared yhShopUserDistributeShared = new YhShopUserDistributeShared();
+			yhShopUserDistributeShared.setShopUserId(shopUserId);
+			yhShopUserDistributeShared.setUserId(userId);
+			yhShopUserDistributeSharedMapper.insert(yhShopUserDistributeShared);
+		} catch (DuplicateKeyException e) {
+		}
+	}
 }
 }

+ 34 - 1
netflix-service/src/main/java/com/cyksj/service/shop/impl/YhShopServiceImpl.java

@@ -7,13 +7,16 @@ import com.cyksj.common.constant.Constant;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.mapper.SysConfigMapper;
 import com.cyksj.mapper.SysConfigMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
+import com.cyksj.mapper.shop.YhShopApplyRecordMapper;
 import com.cyksj.mapper.shop.YhShopMapper;
 import com.cyksj.mapper.shop.YhShopMapper;
 import com.cyksj.model.dto.YhShopInfo;
 import com.cyksj.model.dto.YhShopInfo;
 import com.cyksj.model.entity.SysConfig;
 import com.cyksj.model.entity.SysConfig;
 import com.cyksj.model.entity.YhShop;
 import com.cyksj.model.entity.YhShop;
+import com.cyksj.model.entity.YhShopApplyRecord;
 import com.cyksj.service.shop.YhShopFrontService;
 import com.cyksj.service.shop.YhShopFrontService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 
 /*
 /*
  *项目名: yhlxj
  *项目名: yhlxj
@@ -26,11 +29,14 @@ import org.springframework.stereotype.Service;
 public class YhShopServiceImpl implements YhShopFrontService {
 public class YhShopServiceImpl implements YhShopFrontService {
 	private final YhShopMapper yhShopMapper;
 	private final YhShopMapper yhShopMapper;
 
 
+	private final YhShopApplyRecordMapper yhShopApplyRecordMapper;
+
 	private final SysConfigMapper sysConfigMapper;
 	private final SysConfigMapper sysConfigMapper;
 
 
 	private final UserDistributeMapper userDistributeMapper;
 	private final UserDistributeMapper userDistributeMapper;
 
 
 	@Override
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public void applyOpenShop(YhShop shopInfo) {
 	public void applyOpenShop(YhShop shopInfo) {
 		String customId = shopInfo.getCustomId();
 		String customId = shopInfo.getCustomId();
 		String name = shopInfo.getName();
 		String name = shopInfo.getName();
@@ -71,7 +77,14 @@ public class YhShopServiceImpl implements YhShopFrontService {
 			save.setName(name);
 			save.setName(name);
 			save.setUserId(userId);
 			save.setUserId(userId);
 			save.setCustomId(customId);
 			save.setCustomId(customId);
+			save.setVerifyStatus(YhShop.Status.verify);
 			yhShopMapper.insert(save);
 			yhShopMapper.insert(save);
+
+			YhShopApplyRecord yhShopApplyRecord = new YhShopApplyRecord();
+			yhShopApplyRecord.setName(name);
+			yhShopApplyRecord.setCustomId(customId);
+			yhShopApplyRecord.setVerifyStatus(YhShopApplyRecord.Status.verify);
+			yhShopApplyRecordMapper.insert(yhShopApplyRecord);
 		} catch (Exception e) {
 		} catch (Exception e) {
 			throw BusinessRuntimeException.getInstance("系统繁忙,请重试..");
 			throw BusinessRuntimeException.getInstance("系统繁忙,请重试..");
 		}
 		}
@@ -92,7 +105,7 @@ public class YhShopServiceImpl implements YhShopFrontService {
 		String db_cId = is_open.getCustomId();
 		String db_cId = is_open.getCustomId();
 		YhShop.Status verifyStatus = is_open.getVerifyStatus();
 		YhShop.Status verifyStatus = is_open.getVerifyStatus();
 		if (verifyStatus == YhShop.Status.verify) {
 		if (verifyStatus == YhShop.Status.verify) {
-			throw BusinessRuntimeException.getInstance("您的开店申请审核中.");
+			throw BusinessRuntimeException.getInstance("您的开店申请正在审核中.");
 		}
 		}
 		if (verifyStatus == YhShop.Status.success) {
 		if (verifyStatus == YhShop.Status.success) {
 			throw BusinessRuntimeException.getInstance("您的开店申请已通过.");
 			throw BusinessRuntimeException.getInstance("您的开店申请已通过.");
@@ -112,6 +125,26 @@ public class YhShopServiceImpl implements YhShopFrontService {
 				.set(YhShop::getName, name)
 				.set(YhShop::getName, name)
 				.set(YhShop::getCustomId, customId)
 				.set(YhShop::getCustomId, customId)
 				.eq(YhShop::getId, is_open.getId()));
 				.eq(YhShop::getId, is_open.getId()));
+
+		try {
+			int update = yhShopMapper.update(null, Wrappers.lambdaUpdate(YhShop.class)
+					.eq(YhShop::getId, is_open.getId())
+					.eq(YhShop::getVerifyStatus, YhShop.Status.fail)
+					.set(YhShop::getName, name)
+					.set(YhShop::getCustomId, customId)
+					.set(YhShop::getVerifyStatus, YhShop.Status.verify)
+					.set(YhShop::getReason, null));
+			if (update != 1) {
+				throw BusinessRuntimeException.getInstance("系统繁忙,请重试..");
+			}
+			YhShopApplyRecord yhShopApplyRecord = new YhShopApplyRecord();
+			yhShopApplyRecord.setName(name);
+			yhShopApplyRecord.setCustomId(customId);
+			yhShopApplyRecord.setVerifyStatus(YhShopApplyRecord.Status.verify);
+			yhShopApplyRecordMapper.insert(yhShopApplyRecord);
+		} catch (Exception e) {
+			throw BusinessRuntimeException.getInstance("系统繁忙,请重试..");
+		}
 	}
 	}
 
 
 	@Override
 	@Override

+ 8 - 0
netflix-service/src/main/java/com/cyksj/service/user/impl/UserServiceImpl.java

@@ -28,6 +28,7 @@ import com.cyksj.service.distribute.DistributeService;
 import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
 import com.cyksj.service.distribute.equipment.EquipmentDistributeService;
 import com.cyksj.service.mange.coupon.CouponCommonService;
 import com.cyksj.service.mange.coupon.CouponCommonService;
 import com.cyksj.service.market.task.BindTaskService;
 import com.cyksj.service.market.task.BindTaskService;
+import com.cyksj.service.shop.YhShopDistributeService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.sys.SysConfigService;
 import com.cyksj.service.user.UserService;
 import com.cyksj.service.user.UserService;
 import com.cyksj.service.wechat.WeChatService;
 import com.cyksj.service.wechat.WeChatService;
@@ -76,6 +77,8 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 
 
 	private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
 	private final WxOpenPlatYHLXLoginConfig wxOpenPlatYHLXLoginConfig;
 
 
+	private final YhShopDistributeService yhShopDistributeService;
+
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 	private static final GlobalThreadPoolTaskExecutor TASK_POOL = GlobalThreadPoolTaskExecutor.getInstance();
 
 
 	@Override
 	@Override
@@ -384,6 +387,7 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 		Long sharedId = loginReq.getSharedId();
 		Long sharedId = loginReq.getSharedId();
 		Long dsPopularizeId = null;
 		Long dsPopularizeId = null;
 		Integer dsType = loginReq.getDsType();
 		Integer dsType = loginReq.getDsType();
+		String customId = loginReq.getCustomId();
 		Boolean isNewUser = false;
 		Boolean isNewUser = false;
 		if (StrUtil.isNotBlank(dsCode)) {
 		if (StrUtil.isNotBlank(dsCode)) {
 			dsCode = dsCode.trim();
 			dsCode = dsCode.trim();
@@ -434,6 +438,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
 			if (sharedId != null) {
 			if (sharedId != null) {
 				distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
 				distributeService.saveDistributionInvitation(sharedId, user.getId(), dsPopularizeId);
 			}
 			}
+			//店铺注册用户 关联
+			if (StrUtil.isNotBlank(customId)) {
+				yhShopDistributeService.saveDistributionInvitation(customId, user.getId());
+			}
 			//缓存用户注册 回传信息
 			//缓存用户注册 回传信息
 			String callback = loginReq.getCallback();
 			String callback = loginReq.getCallback();
 			String callbackType = loginReq.getCallbackType();
 			String callbackType = loginReq.getCallbackType();

+ 1 - 1
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/shop/CmsYhShopGoodsController.java

@@ -407,7 +407,7 @@ public class CmsYhShopGoodsController {
     @GetMapping("/get/apply")
     @GetMapping("/get/apply")
     public Result<SearchResult<YhShopView>> getUserShopApply() {
     public Result<SearchResult<YhShopView>> getUserShopApply() {
         SearchResult<YhShopView> search = beanSearcher.search(YhShopView.class, MapUtils.flatBuilder(request.getParameterMap())
         SearchResult<YhShopView> search = beanSearcher.search(YhShopView.class, MapUtils.flatBuilder(request.getParameterMap())
-                .field(YhShopView::getVerifyStatus, List.of(YhShop.Status.verify.name(), YhShop.Status.modify.name())).op(Operator.InList)
+                .field(YhShopView::getVerifyStatus, List.of(YhShopApplyRecord.Status.verify.name(), YhShopApplyRecord.Status.modify.name()))
                 .build());
                 .build());
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
         return GatewayResponse.SUCCESS.newBuilder().toResult(search);
     }
     }

+ 34 - 10
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/shop/YhShopUserController.java

@@ -8,6 +8,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
 import com.cyksj.dto.Result;
 import com.cyksj.dto.Result;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.enums.GatewayResponse;
 import com.cyksj.mapper.GoodsDonMapper;
 import com.cyksj.mapper.GoodsDonMapper;
+import com.cyksj.mapper.shop.YhShopApplyRecordMapper;
 import com.cyksj.mapper.shop.YhShopMapper;
 import com.cyksj.mapper.shop.YhShopMapper;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.entity.*;
 import com.cyksj.model.request.YhShopApplyMoneyReq;
 import com.cyksj.model.request.YhShopApplyMoneyReq;
@@ -19,6 +20,7 @@ import com.ejlchina.searcher.SearchResult;
 import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapBuilder;
 import com.ejlchina.searcher.util.MapUtils;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequest;
@@ -47,6 +49,8 @@ public class YhShopUserController {
 
 
 	private final YhShopMapper yhShopMapper;
 	private final YhShopMapper yhShopMapper;
 
 
+	private final YhShopApplyRecordMapper yhShopApplyRecordMapper;
+
 	/**
 	/**
 	 * 店铺 信息详情
 	 * 店铺 信息详情
 	 */
 	 */
@@ -81,22 +85,42 @@ public class YhShopUserController {
 	 * 申请修改
 	 * 申请修改
 	 */
 	 */
 	@PutMapping("/update/shop")
 	@PutMapping("/update/shop")
-	public Result<String> updateShop(@RequestBody YhShop yhShop) {
-		Long id = yhShop.getId();
-		String name = yhShop.getName();
-		YhShop dbShop = yhShopMapper.selectById(id);
-		if (dbShop == null) {
+	@Transactional(rollbackFor = Throwable.class)
+	public Result<String> updateShop(@RequestBody YhShopApplyRecord record) {
+		long userId = StpYhShopManageUser.getLoginIdAsLong();
+		YhShop yhShop = yhShopMapper.selectOne(Wrappers.lambdaQuery(YhShop.class)
+				.eq(YhShop::getUserId, userId).last("limit 1"));
+		String name = record.getName();
+		if (yhShop == null) {
 			throw BusinessRuntimeException.getInstance("店铺不存在");
 			throw BusinessRuntimeException.getInstance("店铺不存在");
 		}
 		}
 		if (StrUtil.isEmpty(name)) {
 		if (StrUtil.isEmpty(name)) {
 			throw BusinessRuntimeException.getInstance("请输入申请修改的店铺名");
 			throw BusinessRuntimeException.getInstance("请输入申请修改的店铺名");
 		}
 		}
-		if (dbShop.getVerifyStatus() == YhShop.Status.modify) {
-			throw BusinessRuntimeException.getInstance("您已提交修改申请.");
+		//是否存在正在修改的提交记录
+		YhShopApplyRecord yhShopApplyRecord = yhShopApplyRecordMapper.selectOne(Wrappers.lambdaQuery(YhShopApplyRecord.class)
+				.eq(YhShopApplyRecord::getUserId, userId)
+				.eq(YhShopApplyRecord::getVerifyStatus, YhShopApplyRecord.Status.modify).last("limit 1"));
+
+		if (yhShopApplyRecord != null) {
+			throw BusinessRuntimeException.getInstance("您提交的修改申请正在审核中..");
+		}
+		//三个月可修改一次
+		Integer count = yhShopApplyRecordMapper.selectCount(Wrappers.lambdaQuery(YhShopApplyRecord.class)
+				.eq(YhShopApplyRecord::getUserId, userId)
+				.ge(YhShopApplyRecord::getCreatedTime, DateUtil.offsetMonth(DateTime.now(), -3)));
+		if (count > 0) {
+			throw BusinessRuntimeException.getInstance("近三个月只可修改一次");
+		}
+		yhShopApplyRecord = new YhShopApplyRecord();
+		yhShopApplyRecord.setVerifyStatus(YhShopApplyRecord.Status.modify);
+		yhShopApplyRecord.setName(name);
+		yhShopApplyRecordMapper.insert(yhShopApplyRecord);
+
+		if (StrUtil.isNotBlank(yhShop.getReason())) {
+			yhShop.setReason(null);
+			yhShopMapper.updateById(yhShop);
 		}
 		}
-		yhShop.setVerifyStatus(YhShop.Status.modify);
-		yhShop.setModifyName(name);
-		yhShopMapper.updateById(yhShop);
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
 	}