| | |
| | | package com.ruoyi.account.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.AppUserShop; |
| | | import com.ruoyi.account.api.model.ApplyForAdmission; |
| | | import com.ruoyi.account.dto.ApplyForAdmissionDTO; |
| | | import com.ruoyi.account.dto.ApplyReviewDTO; |
| | | import com.ruoyi.account.mapper.AppUserMapper; |
| | | import com.ruoyi.account.mapper.ApplyForAdmissionMapper; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.AppUserShopService; |
| | | import com.ruoyi.account.service.UserApplyForAdmissionService; |
| | | import com.ruoyi.account.util.tencentMap.TencentMapUtil; |
| | | import com.ruoyi.account.vo.ApplyForAdmissionDetailVO; |
| | | import com.ruoyi.account.vo.ApplyForAdmissionListVO; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.other.api.domain.Phone; |
| | | import com.ruoyi.other.api.domain.Region; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.feignClient.PhoneClient; |
| | | import com.ruoyi.other.api.feignClient.RegionClient; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.system.api.model.UserShop; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | private AppUserService appUserService; |
| | | @Resource |
| | | private RegionClient regionClient; |
| | | @Resource |
| | | private ShopClient shopClient; |
| | | @Resource |
| | | private PhoneClient phoneClient; |
| | | |
| | | @Autowired |
| | | private AppUserShopService appUserShopService; |
| | | |
| | | |
| | | /** |
| | | * 申请入驻 |
| | |
| | | @Override |
| | | public R apply(ApplyForAdmissionDTO applyForAdmissionDTO) { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 3) |
| | | AppUser appUser = appUserService.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1) |
| | | .eq(AppUser::getPhone, applyForAdmissionDTO.getPhone())); |
| | | if (appUser == null){ |
| | | return R.fail("该手机号未注册"); |
| | |
| | | applyForAdmission.setCreateTime(LocalDateTime.now()); |
| | | applyForAdmission.setApplyUserId(userid); |
| | | applyForAdmission.setStatus(0); |
| | | String city = TencentMapUtil.inverseGeographicalAnalysis(applyForAdmission.getLongitude(), applyForAdmission.getLatitude(), false); |
| | | if(!StringUtils.hasLength(city)){ |
| | | city = "510100"; |
| | | } |
| | | applyForAdmission.setProvinceCode(city.substring(0, 2) + "0000"); |
| | | Region provinceRegion = regionClient.getRegionBiCode(applyForAdmission.getProvinceCode()).getData(); |
| | | applyForAdmission.setCityCode(city.substring(0, 4) + "00"); |
| | | Region cityRegion = regionClient.getRegionBiCode(applyForAdmission.getCityCode()).getData(); |
| | | applyForAdmission.setDistrictCode(city); |
| | | Region districtRegion = regionClient.getRegionBiCode(applyForAdmission.getDistrictCode()).getData(); |
| | | |
| | | applyForAdmission.setProvince(provinceRegion.getName()); |
| | | applyForAdmission.setCity(cityRegion.getName()); |
| | | applyForAdmission.setDistrict(districtRegion.getName()); |
| | | |
| | | this.save(applyForAdmission); |
| | | return R.ok(); |
| | |
| | | .orderByDesc(ApplyForAdmission::getCreateTime) // 按申请日期降序 |
| | | .last("LIMIT 1")); |
| | | } |
| | | |
| | | @Override |
| | | public IPage<ApplyForAdmissionListVO> getApplyList(Integer pageNum, Integer pageSize, String shopName, String shopManager, String phone, Integer status) { |
| | | Page<ApplyForAdmissionListVO> page = new Page<>(pageNum, pageSize); |
| | | return userApplyForAdmissionMapper.selectApplyList(page, shopName, shopManager, phone, status); |
| | | } |
| | | |
| | | @Override |
| | | public ApplyForAdmissionDetailVO getApplyDetail(Integer id) { |
| | | ApplyForAdmission apply = userApplyForAdmissionMapper.selectById(id); |
| | | if (apply == null) { |
| | | throw new RuntimeException("申请记录不存在"); |
| | | } |
| | | |
| | | ApplyForAdmissionDetailVO detail = new ApplyForAdmissionDetailVO(); |
| | | BeanUtils.copyProperties(apply, detail); |
| | | detail.setFullAddress(apply.getAddress() + apply.getDetailAddress()); |
| | | return detail; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor=Exception.class) |
| | | public void review(ApplyReviewDTO applyReviewDTO) { |
| | | ApplyForAdmission apply = userApplyForAdmissionMapper.selectById(applyReviewDTO.getId()); |
| | | if (apply == null) { |
| | | throw new RuntimeException("申请记录不存在"); |
| | | } |
| | | if (apply.getStatus() != 0) { |
| | | throw new RuntimeException("该记录已审核过"); |
| | | } |
| | | if(applyReviewDTO.getStatus()==2){ |
| | | //审核不通过 |
| | | apply.setStatus(2); |
| | | apply.setRemark(applyReviewDTO.getRemark()); |
| | | apply.setUpdateTime(LocalDateTime.now()); |
| | | this.updateById(apply); |
| | | return; |
| | | } |
| | | //审核通过 |
| | | apply.setStatus(1); |
| | | apply.setUpdateTime(LocalDateTime.now()); |
| | | apply.setRemark(applyReviewDTO.getRemark()); |
| | | this.updateById(apply); |
| | | |
| | | //先加入商店 |
| | | Shop shop = new Shop(); |
| | | BeanUtils.copyProperties(apply, shop); |
| | | shop.setId(null); |
| | | shop.setName(apply.getShopName()); |
| | | shop.setBusinessTime(apply.getBusinessTime()); |
| | | shop.setAppUserId(apply.getApplyUserId()); |
| | | shop.setCreateTime(LocalDateTime.now()); |
| | | R shopR = shopClient.insert(shop); |
| | | if (shopR.getCode()!=200){ |
| | | throw new RuntimeException("添加店铺失败"); |
| | | } |
| | | Integer shopId = (Integer) shopR.getData(); |
| | | //加入usershop |
| | | AppUserShop userShop = new AppUserShop(); |
| | | userShop.setAppUserId(apply.getApplyUserId()); |
| | | userShop.setShopId(shopId); |
| | | appUserShopService.save(userShop); |
| | | //加入客服手机号 |
| | | Phone phone = new Phone(); |
| | | phone.setType(2);//门店 |
| | | phone.setPhoneOne(apply.getServiceTel()); |
| | | phone.setShopId(shopId); |
| | | R phoneR = phoneClient.insert(phone); |
| | | if (phoneR.getCode()!=200){ |
| | | throw new RuntimeException("添加店铺客服电话失败"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | } |