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.util.StringUtils;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
|
@Slf4j
|
@Service
|
public class UserApplyForAdmissionServiceImpl extends ServiceImpl<ApplyForAdmissionMapper, ApplyForAdmission> implements UserApplyForAdmissionService {
|
@Autowired
|
private TokenService tokenService;
|
@Autowired
|
private ApplyForAdmissionMapper userApplyForAdmissionMapper;
|
@Autowired
|
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).eq(AppUser::getStatus, 1)
|
.eq(AppUser::getPhone, applyForAdmissionDTO.getPhone()));
|
if (appUser == null){
|
return R.fail("该手机号未注册");
|
}
|
ApplyForAdmission applyForAdmission = new ApplyForAdmission();
|
BeanUtils.copyProperties(applyForAdmissionDTO, applyForAdmission);
|
applyForAdmission.setCreateTime(LocalDateTime.now());
|
applyForAdmission.setApplyUserId(userid);
|
applyForAdmission.setStatus(0);
|
|
|
this.save(applyForAdmission);
|
return R.ok();
|
}
|
|
/**
|
* 查看
|
*/
|
@Override
|
public ApplyForAdmission read() {
|
Long userid = tokenService.getLoginUserApplet().getUserid();
|
return userApplyForAdmissionMapper
|
.selectOne(new LambdaQueryWrapper<ApplyForAdmission>()
|
.eq(ApplyForAdmission::getApplyUserId, userid)
|
.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
|
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());
|
this.updateById(apply);
|
|
//先加入商店
|
Shop shop = new Shop();
|
BeanUtils.copyProperties(apply, shop);
|
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(shop.getId());
|
R phoneR = phoneClient.insert(phone);
|
if (phoneR.getCode()!=200){
|
throw new RuntimeException("添加店铺客服电话失败");
|
}
|
|
|
}
|
|
}
|