/* * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. * * https://www.mall4j.com/ * * 未经允许,不可做商业用途! * * 版权所有,侵权必究! */ package com.yami.shop.api.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Maps; import com.yami.shop.bean.app.dto.ShopHeadInfoDto; import com.yami.shop.bean.enums.*; import com.yami.shop.bean.event.EsProductUpdateEvent; import com.yami.shop.bean.model.*; import com.yami.shop.bean.param.OfflineHandleEventAuditParam; import com.yami.shop.bean.param.ShopDetailParam; import com.yami.shop.bean.param.TechnicianShopDetailParam; import com.yami.shop.bean.vo.ShopStatusInfoVO; import com.yami.shop.common.bean.SysServiceConfig; import com.yami.shop.common.config.Constant; import com.yami.shop.common.exception.YamiShopBindException; import com.yami.shop.common.response.ServerResponseEntity; import com.yami.shop.security.api.util.SecurityUtils; import com.yami.shop.security.common.manager.PasswordManager; import com.yami.shop.service.*; import com.yami.shop.sys.common.model.ShopEmployee; import com.yami.shop.sys.common.service.ShopEmployeeService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import ma.glasnost.orika.MapperFacade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.Date; import java.util.Objects; /** * @author lgh on 2018/08/29. */ @RestController @RequestMapping("/p/shop/shopDetail") @Tag(name = "店铺基本信息接口") public class ShopDetailController { @Autowired private ShopDetailService shopDetailService; @Autowired private ShopEmployeeService shopEmployeeService; @Autowired private MapperFacade mapperFacade; @Autowired private OfflineHandleEventService offlineHandleEventService; @Autowired private SmsLogService smsLogService; @Autowired private ShopAuditingService shopAuditingService; @Autowired private SysConfigService sysConfigService; @Autowired private PasswordEncoder passwordEncoder; @Autowired private ApplicationEventPublisher eventPublisher; @Autowired private AgentService agentService; @Autowired private UserService userService; @Autowired private UserCollectionShopService userCollectionShopService; @Autowired private ShopRenovationService shopRenovationService; private static final Long SOLE_AGENT = 666L; @GetMapping("/headInfo") @Operation(summary = "店铺头部信息" , description = "获取的店铺头部信息") @Parameter(name = "shopId", description = "店铺id" , required = true) public ServerResponseEntity getShopHeadInfo(Long shopId) { ShopHeadInfoDto shopHeadInfoDto = new ShopHeadInfoDto(); // 粉丝数量 int fansCount = userCollectionShopService.count(new LambdaQueryWrapper().eq(UserCollectionShop::getShopId, shopId)); // TODO 先默认是移动端的装修页面,后续删除此处装修相关的代码 ShopRenovation shopRenovation = shopRenovationService.getOne(new LambdaQueryWrapper() .eq(ShopRenovation::getShopId, shopId).eq(ShopRenovation::getHomeStatus, 1).eq(ShopRenovation::getRenovationType, RenovationType.H5.value())); ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId); shopHeadInfoDto.setShopStatus(shopDetail.getShopStatus()); if (!Objects.equals(shopDetail.getShopStatus(), 1)) { return ServerResponseEntity.success(shopHeadInfoDto); } shopHeadInfoDto.setRenovationId(Objects.isNull(shopRenovation) ? null : shopRenovation.getRenovationId()); shopHeadInfoDto.setShopId(shopId); shopHeadInfoDto.setShopLogo(shopDetail.getShopLogo()); shopHeadInfoDto.setShopName(shopDetail.getShopName()); shopHeadInfoDto.setIntro(shopDetail.getIntro()); shopHeadInfoDto.setFansCount(fansCount); shopHeadInfoDto.setTel(shopDetail.getTel()); shopHeadInfoDto.setType(shopDetail.getType()); shopHeadInfoDto.setContractStartTime(shopDetail.getContractStartTime()); shopHeadInfoDto.setContractEndTime(shopDetail.getContractEndTime()); return ServerResponseEntity.success(shopHeadInfoDto); } @GetMapping("/info") @Operation(summary = "获取店铺基本信息" , description = "获取店铺基本信息") public ServerResponseEntity info() { String userId = SecurityUtils.getUser().getUserId(); User user = userService.getUserByUserId(userId); ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(userId); if (shopDetail != null) { ShopEmployee shopEmployee = shopEmployeeService.getOne(Wrappers.lambdaQuery(ShopEmployee.class).eq(ShopEmployee::getUserId, userId)); if (shopEmployee != null) { shopDetail.setUserName(user.getUserName()); shopDetail.setMerchantAccount(user.getUserMobile()); shopDetail.setAccountStatus(shopEmployee.getStatus()); shopDetail.setEmployeeId(shopEmployee.getEmployeeId()); return ServerResponseEntity.success(shopDetail); } } return ServerResponseEntity.success(); } @GetMapping("/getShopInfo") @Operation(summary = "店铺信息(装修)" , description = "获取的店铺信息(装修)") public ServerResponseEntity getShopInfo() { ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); if (Objects.isNull(shopDetail)){{ return ServerResponseEntity.success(); }} ShopHeadInfoDto shopHeadInfoDto = mapperFacade.map(shopDetail, ShopHeadInfoDto.class); return ServerResponseEntity.success(shopHeadInfoDto); } @GetMapping("/getStatusInfo") @Operation(summary = "获取店铺状态信息" , description = "获取店铺状态信息") public ServerResponseEntity getShopStatusInfo() { Long shopId = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId(); ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId); if (Objects.isNull(shopDetail)){{ return ServerResponseEntity.success(); }} ShopStatusInfoVO shopStatusInfoVO = new ShopStatusInfoVO(); shopStatusInfoVO.setShopStatus(shopDetail.getShopStatus()); shopStatusInfoVO.setContractStartTime(shopDetail.getContractStartTime()); shopStatusInfoVO.setContractEndTime(shopDetail.getContractEndTime()); if (Objects.equals(shopDetail.getShopStatus(), ShopStatus.OFFLINE.value())) { OfflineHandleEvent offlineHandleEventRes = offlineHandleEventService.getProcessingEventByHandleTypeAndHandleId(OfflineHandleEventType.SHOP.getValue(), shopId); shopStatusInfoVO.setOfflineStatus(offlineHandleEventRes.getStatus()); shopStatusInfoVO.setOfflineReason(offlineHandleEventRes.getOfflineReason()); } return ServerResponseEntity.success(shopStatusInfoVO); } @PutMapping @Operation(summary = "更新店铺基本信息" , description = "更新店铺基本信息") public ServerResponseEntity save(@Valid @RequestBody ShopDetailParam shopDetailParam) { String userId = SecurityUtils.getUser().getUserId(); User user = userService.getUserByUserId(userId); ShopDetail shopDetail = mapperFacade.map(shopDetailParam, ShopDetail.class); ShopDetail shopDetailByUserId = shopDetailService.getShopDetailByUserId(userId); if (shopDetailByUserId == null) { int count = shopEmployeeService.checkUserName(shopDetail.getShopId(), shopDetail.getMobile()); // 如果无代理商邀请码,匹配最近的代理商,如果没有最近的代理商,则默认为平台 String agentCode = shopDetailParam.getAgentCode(); Long agentId = agentService.getAgentIdByAgentCode(agentCode); if (agentCode.isEmpty()) { agentId = agentService.getAgentIdByNearAgent(shopDetailParam.getAreaId()); }else{ if (agentId == null) { throw new YamiShopBindException("邀请码错误"); } } if (agentId == null || agentId == 0) { agentId = SOLE_AGENT; } shopDetail.setAgentId(agentId); shopDetail.setUserId(userId); shopDetail.setShopOwner(userId); shopDetail.setPassword(user.getLoginPassword()); shopDetail.setShopStatus(-1); shopDetailService.insertDetail(shopDetail,count); // shopDetailService.applyShop(userId, shopDetailParam); if (shopEmployeeService.getOne(Wrappers.query().lambda().eq(ShopEmployee::getMobile, shopDetailParam.getMobile())) != null){ throw new YamiShopBindException("该手机号已注册或店铺已注销,请使用新手机号注册"); } shopEmployeeService.remove(Wrappers.lambdaQuery(ShopEmployee.class).eq(ShopEmployee::getUserId, userId)); // 创建商家账号 ShopEmployee shopEmployee = new ShopEmployee(); user.setUserType(1); //商家用户 shopEmployee.setShopId(shopDetailService.getShopDetailByUserId(userId).getShopId()); shopEmployee.setType(PositionType.ADMIN.value()); shopEmployee.setNickname(user.getNickName()); shopEmployee.setUserId(userId); shopEmployee.setUsername(user.getUserName()); shopEmployee.setPassword(user.getLoginPassword()); shopEmployee.setMobile(user.getUserMobile()); shopEmployee.setStatus(0); shopEmployee.setCreateTime(new Date()); shopEmployee.setPassword(passwordEncoder.encode(user.getUserMobile())); userService.updateById(user); shopEmployeeService.save(shopEmployee); return ServerResponseEntity.success(); } if (shopDetailByUserId.getAccountStatus() == 0){ throw new YamiShopBindException("该店铺已禁用"); } if (shopDetailByUserId.getAccountStatus() == -1){ throw new YamiShopBindException("该店铺已删除"); } // 如果无代理商邀请码,匹配最近的代理商,如果没有最近的代理商,则默认为平台 String agentCode = shopDetailParam.getAgentCode(); Long agentId; if (agentCode.isEmpty()) { agentId = agentService.getAgentIdByNearAgent(shopDetailParam.getAreaId()); if (agentId == null || agentId == 0) { agentId = SOLE_AGENT; } } else { agentId = agentService.getAgentIdByAgentCode(agentCode); } shopDetail.setAgentId(agentId); shopDetail.setShopId(shopDetailByUserId.getShopId()); shopDetail.setUpdateTime(new Date()); this.dealWithUpdateOrCreateInfo(shopDetail); // // 修改店铺接收手机号在专门的接口 // shopDetail.setReceiveMobile(null); shopDetailService.updateShopDetail(shopDetail); eventPublisher.publishEvent(new EsProductUpdateEvent(shopDetail.getShopId(), null, EsOperationType.UPDATE_BY_SHOP_ID)); return ServerResponseEntity.success(); } @PutMapping("/technician") @Operation(summary = "技师入驻申请" ,description = "技师入驻申请") public ServerResponseEntity saveTechnician(@Valid @RequestBody TechnicianShopDetailParam technicianShopDetailParam) { String userId = SecurityUtils.getUser().getUserId(); User user = userService.getUserByUserId(userId); user.setDiploma(technicianShopDetailParam.getDiploma()); user.setSex(technicianShopDetailParam.getSex()); user.setRealName(technicianShopDetailParam.getRealName()); user.setUserType(1); //商家用户 ShopDetail shopDetail = mapperFacade.map(technicianShopDetailParam, ShopDetail.class); ShopDetail shopDetailByUserId = shopDetailService.getShopDetailByUserId(userId); if (shopDetailByUserId == null){ int count = shopEmployeeService.checkUserName(shopDetail.getShopId(), shopDetail.getMobile()); // 如果无代理商邀请码,匹配最近的代理商,如果没有最近的代理商,则默认为平台 String agentCode = technicianShopDetailParam.getAgentCode(); Long agentId = agentService.getAgentIdByAgentCode(agentCode); if (agentCode.isEmpty()) { agentId = agentService.getAgentIdByNearAgent(technicianShopDetailParam.getAreaId()); } if (agentId == null || agentId == 0) { agentId = SOLE_AGENT; } shopDetail.setShopName(technicianShopDetailParam.getRealName()); shopDetail.setAgentId(agentId); shopDetail.setUserId(userId); shopDetail.setShopOwner(userId); shopDetail.setPassword(user.getLoginPassword()); userService.updateById(user); shopDetailService.insertDetail(shopDetail,count); ShopDetail sd = shopDetailService.getShopDetailByUserId(userId); ShopEmployee shopEmployee = new ShopEmployee(); user.setUserType(1); //商家用户 shopEmployee.setShopId(shopDetailService.getShopDetailByUserId(userId).getShopId()); shopEmployee.setType(PositionType.ADMIN.value()); shopEmployee.setNickname(user.getNickName()); shopEmployee.setUserId(userId); shopEmployee.setUsername(user.getUserName()); shopEmployee.setPassword(passwordEncoder.encode(user.getUserMobile())); shopEmployee.setMobile(user.getUserMobile()); shopEmployee.setStatus(0); //设置状态为正常 shopEmployee.setCreateTime(new Date()); userService.updateById(user); shopEmployeeService.save(shopEmployee); shopDetailService.applyTechnician(sd.getShopId(), userId); return ServerResponseEntity.success(); } User userP = mapperFacade.map(technicianShopDetailParam,User.class); userP.setUserId(userId); // 如果无代理商邀请码,匹配最近的代理商,如果没有最近的代理商,则默认为平台 String agentCode = technicianShopDetailParam.getAgentCode(); Long agentId; if (agentCode.isEmpty()) { agentId = agentService.getAgentIdByNearAgent(technicianShopDetailParam.getAreaId()); if (agentId == null || agentId == 0) { agentId = SOLE_AGENT; } } else { agentId = agentService.getAgentIdByAgentCode(agentCode); } shopDetail.setAgentId(agentId); shopDetail.setShopId(shopDetailByUserId.getShopId()); shopDetail.setUpdateTime(new Date()); shopDetail.setShopName(technicianShopDetailParam.getRealName()); this.dealWithUpdateOrCreateInfo(shopDetail); userService.updateById(userP); shopDetailService.updateShopDetail(shopDetail); eventPublisher.publishEvent(new EsProductUpdateEvent(shopDetail.getShopId(), null, EsOperationType.UPDATE_BY_SHOP_ID)); return ServerResponseEntity.success(); } @PutMapping("/updateMobile") @Operation(summary = "修改店铺接收手机号" , description = "修改店铺接收手机号") public ServerResponseEntity updateMobile(@RequestBody ShopDetail shopDetail) { shopDetail.setShopId(shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId()); shopDetail.setUpdateTime(new Date()); this.dealWithUpdateOrCreateInfo(shopDetail); shopDetailService.updateShopDetail(shopDetail); return ServerResponseEntity.success(); } @GetMapping("/getOfflineHandleEvent") @Operation(summary = "获取店铺下线信息" , description = "获取店铺下线信息") public ServerResponseEntity getOfflineHandleEventByShopId() { ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); if (Objects.isNull(shopDetail)){{ return ServerResponseEntity.success(); }} Long shopId = shopDetail.getShopId(); OfflineHandleEvent offlineHandleEvent = offlineHandleEventService.getProcessingEventByHandleTypeAndHandleId(OfflineHandleEventType.SHOP.getValue(), shopId); return ServerResponseEntity.success(offlineHandleEvent); } @PostMapping("/auditApply") @Operation(summary = "违规店铺重新提交审核" , description = "违规店铺重新提交审核") @PreAuthorize("@pms.hasPermission('shop:shopDetail:applyOnline')") public ServerResponseEntity auditApply(@RequestBody OfflineHandleEventAuditParam offlineHandleEventAuditParam) { ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); if (Objects.isNull(shopDetail)){{ return ServerResponseEntity.success(); }} Long shopId = shopDetail.getShopId(); shopDetailService.auditApply(offlineHandleEventAuditParam.getEventId(), shopId, offlineHandleEventAuditParam.getReapplyReason()); return ServerResponseEntity.success(); } @PostMapping("/sendCode") @Operation(summary = "给店长发送验证码" , description = "给店长发送验证码") public ServerResponseEntity sendLoginCode() { ShopDetail d = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); if (Objects.isNull(d)){{ return ServerResponseEntity.success(); }} Long shopId = d.getShopId(); // 查询店长信息 ShopDetail shopDetail = shopDetailService.getById(shopId); if (Objects.isNull(shopDetail.getReceiveMobile())) { throw new YamiShopBindException("请先为商家账号设置接受通知手机号"); } // if(Objects.equals(shopDetail.getShopId(), Constant.MAIN_SHOP)){ // // 自营店无法提现 // throw new YamiShopBindException("yami.my.store.no.cash"); // } smsLogService.sendSms(SendType.VALID, shopDetail.getShopId().toString(), shopDetail.getReceiveMobile(), Maps.newHashMap()); return ServerResponseEntity.success(shopDetail.getReceiveMobile()); } @GetMapping("/getAuditingInfo") @Operation(summary = "获取店铺审核状态信息" , description = "获取店铺审核状态信息") public ServerResponseEntity getAuditingInfo() { ShopDetail shop = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()); if (shop != null) { Long shopId = shop.getShopId(); ShopAuditing shopAuditing = shopAuditingService.getOne(Wrappers.lambdaQuery(ShopAuditing.class).eq(ShopAuditing::getShopId, shopId)); // ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId); // 开店协议开关 SysServiceConfig sysConfigObject = sysConfigService.getSysConfigObject(Constant.SERVICE_SWITCH_CONFIG, SysServiceConfig.class); if (Objects.isNull(shopAuditing)) { // 审核信息不存在,店铺未提交审核 shopAuditing = new ShopAuditing(); shopAuditing.setStatus(-2); shopAuditing.setShopProtocolSwitch(sysConfigObject.getShopProtocolSwitch()); return ServerResponseEntity.success(shopAuditing); } if (Objects.equals(shop.getShopStatus(), ShopStatus.OFFLINE.value())) { shopAuditing.setStatus(2); } else if (Objects.equals(shop.getShopStatus(), ShopStatus.OFFLINE_AUDIT.value())) { shopAuditing.setStatus(0); } return ServerResponseEntity.success(shopAuditing); } return ServerResponseEntity.success(); } /** * 处理店铺信息,这些信息商家无法直接修改 * @param shopDetail */ private void dealWithUpdateOrCreateInfo(ShopDetail shopDetail) { if (Objects.isNull(shopDetail)) { return; } shopDetail.setContractEndTime(null); shopDetail.setContractStartTime(null); shopDetail.setShopStatus(null); shopDetail.setType(null); } }