AgentServiceImpl.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. package com.ydd.module.service.impl;
  2. import com.aliyun.oss.OSSClient;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  6. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  7. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  8. import com.google.zxing.common.BitMatrix;
  9. import com.ydd.common.constant.UserConstants;
  10. import com.ydd.common.core.domain.entity.SysUser;
  11. import com.ydd.common.enums.UserTypeEnums;
  12. import com.ydd.common.enums.UserTypeJoinRoleEnums;
  13. import com.ydd.common.exception.CustomException;
  14. import com.ydd.common.oss.cloud.CloudStorageConfig;
  15. import com.ydd.common.oss.cloud.OSSFactory;
  16. import com.ydd.common.utils.SecurityUtils;
  17. import com.ydd.ecloud.core.utils.OSSHelper;
  18. import com.ydd.module.domain.*;
  19. import com.ydd.module.dto.BaseConfgMinDto;
  20. import com.ydd.module.enums.PackageCityConfigPackageTypeEnum;
  21. import com.ydd.module.enums.StatusEnum;
  22. import com.ydd.module.expection.CustomWebException;
  23. import com.ydd.module.mapper.AgentMapper;
  24. import com.ydd.module.request.AgentBindRulePackageRequest;
  25. import com.ydd.module.service.*;
  26. import com.ydd.module.utils.BarCodeUtils;
  27. import com.ydd.module.utils.QRCodeUtil;
  28. import com.ydd.system.service.ISysUserService;
  29. import lombok.RequiredArgsConstructor;
  30. import org.apache.commons.lang3.StringUtils;
  31. import org.springframework.beans.factory.annotation.Autowired;
  32. import org.springframework.stereotype.Service;
  33. import org.springframework.transaction.annotation.Transactional;
  34. import javax.annotation.Resource;
  35. import java.awt.image.BufferedImage;
  36. import java.io.InputStream;
  37. import java.math.BigDecimal;
  38. import java.util.ArrayList;
  39. import java.util.Date;
  40. import java.util.List;
  41. import java.util.Objects;
  42. /**
  43. * 代理商Service业务层处理
  44. *
  45. * @author douya
  46. * @date 2021-02-01
  47. */
  48. @RequiredArgsConstructor(onConstructor_ = @Autowired)
  49. @Service
  50. public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements IAgentService {
  51. @Resource
  52. private IDspConfigService iDspConfigService;
  53. @Resource
  54. private IAreaService iAreaService;
  55. @Resource
  56. private ISysUserService userService;
  57. @Resource
  58. private IAgentLevelService iAgentLevelService;
  59. private final CloudStorageConfig cloudStorageConfig;
  60. @Resource
  61. private IPackageDiscountService iPackageDiscountService;
  62. @Resource
  63. private IPackageCommissionService iPackageCommissionService;
  64. @Override
  65. public List<Agent> queryList(Agent agent, SysUser user) {
  66. LambdaQueryWrapper<Agent> lqw = Wrappers.lambdaQuery();
  67. //处理不同身份权限
  68. if (user.getType().equals(UserTypeEnums.DSP.getCode())) {
  69. agent.setDspId(user.getDspId().intValue());
  70. }
  71. if (agent.getDspId() != null) {
  72. lqw.eq(Agent::getDspId, agent.getDspId());
  73. }
  74. if (agent.getPid() != null) {
  75. lqw.eq(Agent::getPid, agent.getPid());
  76. } else {
  77. if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  78. lqw.eq(Agent::getPid, user.getAgentId()).or().eq(Agent::getId, user.getAgentId());
  79. }
  80. }
  81. if (StringUtils.isNotBlank(agent.getName())) {
  82. lqw.like(Agent::getName, agent.getName());
  83. }
  84. if (agent.getProvinceId() != null) {
  85. lqw.eq(Agent::getProvinceId, agent.getProvinceId());
  86. }
  87. if (agent.getCityId() != null) {
  88. lqw.eq(Agent::getCityId, agent.getCityId());
  89. }
  90. if (agent.getDistrictId() != null) {
  91. lqw.eq(Agent::getDistrictId, agent.getDistrictId());
  92. }
  93. if (agent.getAgentLevel() != null) {
  94. lqw.eq(Agent::getAgentLevel, agent.getAgentLevel());
  95. }
  96. if (agent.getCommissionRate() != null) {
  97. lqw.eq(Agent::getCommissionRate, agent.getCommissionRate());
  98. }
  99. if (StringUtils.isNotBlank(agent.getContactName())) {
  100. lqw.like(Agent::getContactName, agent.getContactName());
  101. }
  102. if (StringUtils.isNotBlank(agent.getAvatar())) {
  103. lqw.eq(Agent::getAvatar, agent.getAvatar());
  104. }
  105. if (StringUtils.isNotBlank(agent.getMobile())) {
  106. lqw.like(Agent::getMobile, agent.getMobile());
  107. }
  108. if (StringUtils.isNotBlank(agent.getAddress())) {
  109. lqw.eq(Agent::getAddress, agent.getAddress());
  110. }
  111. if (StringUtils.isNotBlank(agent.getProvinceName()) && StringUtils.isBlank(agent.getCityName()) && StringUtils.isBlank(agent.getDistrictName())){
  112. List<Agent> provinceList = baseMapper.selectList(new QueryWrapper<Agent>().like("province_name", agent.getProvinceName()).isNull("pid"));
  113. List<Long> provinceIds = new ArrayList<>();
  114. provinceList.forEach(province -> {
  115. provinceIds.add(province.getId());
  116. });
  117. if (provinceIds.size() > 0) {
  118. lqw.and(wrapper -> wrapper.in(Agent::getId, provinceIds).or().in(Agent::getPid, provinceIds));
  119. }else {
  120. lqw.eq(Agent::getId, - 1);
  121. }
  122. // lqw.like(Agent::getProvinceName ,agent.getProvinceName());
  123. }
  124. if (StringUtils.isNotBlank(agent.getCityName()) && StringUtils.isBlank(agent.getDistrictName())){
  125. List<Agent> cityList = baseMapper.selectList(new QueryWrapper<Agent>().like("province_name", agent.getProvinceName())
  126. .like("city_name", agent.getCityName()).isNull("pid"));
  127. List<Long> cityIds = new ArrayList<>();
  128. cityList.forEach(city -> {
  129. cityIds.add(city.getId());
  130. });
  131. if (cityIds.size() > 0) {
  132. lqw.and(wrapper -> wrapper.in(Agent::getId, cityIds).or().in(Agent::getPid, cityIds));
  133. }else {
  134. lqw.eq(Agent::getId, - 1);
  135. }
  136. // lqw.like(Agent::getCityName ,agent.getCityName());
  137. }
  138. if (StringUtils.isNotBlank(agent.getDistrictName())){
  139. List<Agent> districtList = baseMapper.selectList(new QueryWrapper<Agent>().like("province_name", agent.getProvinceName())
  140. .like("city_name", agent.getCityName())
  141. .like("district_name", agent.getDistrictName()).isNull("pid"));
  142. List<Long> districtIds = new ArrayList<>();
  143. districtList.forEach(district -> {
  144. districtIds.add(district.getId());
  145. });
  146. if (districtIds.size() > 0) {
  147. lqw.and(wrapper -> wrapper.in(Agent::getId, districtIds).or().in(Agent::getPid, districtIds));
  148. }else {
  149. lqw.eq(Agent::getId, - 1);
  150. }
  151. // lqw.like(Agent::getDistrictName ,agent.getDistrictName());
  152. }
  153. if (agent.getStartTime() != null) {
  154. lqw.ge(Agent::getCreateTime, agent.getStartTime());
  155. }
  156. if (agent.getEndTime() != null) {
  157. lqw.le(Agent::getCreateTime, agent.getEndTime());
  158. }
  159. lqw.orderByDesc(Agent::getCreateTime);
  160. List<Agent> list = this.list(lqw);
  161. List<AgentLevel> agentLevelList = iAgentLevelService.queryList(new AgentLevel(), user);
  162. list.stream().forEach(agent1 -> {
  163. agent1.setDspName(iDspConfigService.getById(agent1.getDspId()).getName());
  164. Agent parentAgent = this.getById(agent1.getPid());
  165. if (parentAgent != null) {
  166. agent1.setPAgentName(parentAgent.getName());
  167. }
  168. //判断查看代理商用户是否拥有编辑权限
  169. if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  170. // agent1.setIsEdit(agent1.getPid().equals(user.getAgentId()) ? 1 : 0);
  171. agent1.setIsEdit(agent1.getPid() == null ? 1 : 0);
  172. } else {
  173. //非代理商角色拥有所有编辑权限
  174. agent1.setIsEdit(1);
  175. }
  176. //遍历代理商等级名称
  177. for (AgentLevel agentLevel : agentLevelList) {
  178. if (agentLevel.getLevel().equals(agent1.getAgentLevel())) {
  179. agent1.setLevelName(agentLevel.getName());
  180. break;
  181. }
  182. }
  183. // 下级代理商省市区为上级
  184. if (agent1.getPid() != null) {
  185. Agent superAgent = baseMapper.getByPid(agent1.getPid());
  186. if (superAgent != null && superAgent.getPid() == null) {
  187. agent1.setProvinceName(superAgent.getProvinceName());
  188. agent1.setCityName(superAgent.getCityName());
  189. agent1.setDistrictName(superAgent.getDistrictName());
  190. }else if (superAgent != null && superAgent.getPid() != null) {
  191. Agent superLowAgent = this.getById(superAgent.getPid());
  192. agent1.setProvinceName(superLowAgent.getProvinceName());
  193. agent1.setCityName(superLowAgent.getCityName());
  194. agent1.setDistrictName(superLowAgent.getDistrictName());
  195. }
  196. }
  197. if (agent1.getPackageDiscountId() != null) {
  198. PackageDiscount discount = iPackageDiscountService.getById(agent1.getPackageDiscountId());
  199. if (discount != null) {
  200. agent1.setPackageDiscountName(discount.getName());
  201. }
  202. }
  203. if (agent1.getPackageCommissionId() != null) {
  204. PackageCommission commission = iPackageCommissionService.getById(agent1.getPackageCommissionId());
  205. if (commission != null) {
  206. agent1.setPackageCommissionName(commission.getName());
  207. }
  208. }
  209. });
  210. return list;
  211. }
  212. @Override
  213. public List<Agent> selectAgnetList(Agent agent, SysUser user) {
  214. List<Agent> list = new ArrayList<>();
  215. if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  216. list = baseMapper.getAgentAll(user.getAgentId());
  217. }else {
  218. list = baseMapper.selectAll();
  219. }
  220. return list;
  221. }
  222. @Override
  223. public List<Agent> getAgentAll( SysUser user) {
  224. return baseMapper.getAgentAll(user.getAgentId());
  225. }
  226. @Override
  227. @Transactional(rollbackFor = Exception.class)
  228. public Boolean createAgent(Agent agent, SysUser user) {
  229. Agent agents = baseMapper.selectByMobile(agent.getMobile(), null);
  230. // Integer gentLevel = null;
  231. if (agents != null) {
  232. throw new CustomException("代理商已存在,请勿重复创建!");
  233. }
  234. if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(agent.getMobile()))) {
  235. throw new CustomException("该手机号码为系统管理员账号,创建失败!");
  236. }
  237. if (agent.getMobile().length() > 11) {
  238. throw new CustomException("手机号过长,规定为11位!");
  239. }
  240. if (user.getType().equals(UserTypeEnums.DSP.getCode())) {
  241. agent.setDspId(user.getDspId().intValue());
  242. // gentLevel = iAgentLevelService.getMaxLevelByDspId(user.getDspId().intValue(),null);
  243. } else if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  244. Agent parentAgent = this.getById(user.getAgentId());
  245. if (parentAgent != null) {
  246. agent.setPid(parentAgent.getId());
  247. agent.setDspId(parentAgent.getDspId());
  248. agent.setType(parentAgent.getType());
  249. // gentLevel = iAgentLevelService.getMaxLevelByDspId(user.getDspId().intValue(),parentAgent.getAgentLevel().intValue());
  250. }
  251. } else {
  252. throw new CustomException("风险操作,已被系统拦截!");
  253. }
  254. // agent.setProvinceName(iAreaService.getName(agent.getProvinceId().intValue()));
  255. // agent.setCityName(iAreaService.getName(agent.getCityId().intValue()));
  256. // agent.setDistrictName(iAreaService.getName(agent.getDistrictId().intValue()));
  257. agent.setProvinceName(agent.getProvinceName());
  258. agent.setCityName(agent.getCityName());
  259. agent.setDistrictName(agent.getDistrictName());
  260. this.save(agent);
  261. String path = "http://h5.liebaoai.cn/register.html?id=" + agent.getId();
  262. if (!agent.getId().equals(null)) {
  263. BufferedImage bufferedImage = BarCodeUtils.generateBarcodeWithoutWhite(path, null);
  264. InputStream inputStream = BarCodeUtils.uploadFileToOss(bufferedImage, null);
  265. String url = OSSFactory.build(cloudStorageConfig).uploadSuffix(inputStream, "." + "jpg");
  266. if (StringUtils.isNotBlank(url)) {
  267. agent.setQrCode(url);
  268. baseMapper.updateById(agent);
  269. }
  270. }
  271. //创建代理商后台账号
  272. SysUser agentUser = new SysUser();
  273. agentUser.setUserName(agent.getMobile());
  274. agentUser.setNickName(agent.getMobile());
  275. agentUser.setType(UserTypeEnums.AGENT.getCode());
  276. agentUser.setPhonenumber(agent.getMobile());
  277. agentUser.setAgentId(agent.getId());
  278. agentUser.setDspId(agent.getDspId().longValue());
  279. agentUser.setPassword(agent.getMobile().substring(6));
  280. agentUser.setCreateBy(SecurityUtils.getUsername());
  281. agentUser.setPassword(SecurityUtils.encryptPassword(agentUser.getPassword()));
  282. Long[] roleIds = {UserTypeJoinRoleEnums.AGENT.getRoleId()};
  283. agentUser.setRoleIds(roleIds);
  284. userService.insertUser(agentUser);
  285. return true;
  286. }
  287. @Override
  288. @Transactional(rollbackFor = Exception.class)
  289. public Boolean updateAgent(Agent agent) {
  290. Agent agents = baseMapper.selectByMobile(agent.getMobile(), agent.getId());
  291. if (agents != null) {
  292. throw new CustomException("代理商已存在,请勿重复创建!");
  293. }
  294. this.updateById(agent);
  295. SysUser user = userService.selectUserByUserName(agent.getMobilePhone());
  296. if (user != null && !agent.getMobile().equals(agent.getMobilePhone())) {
  297. user.setUserName(agent.getMobile());
  298. user.setNickName(agent.getMobile());
  299. user.setPhonenumber(agent.getMobile());
  300. user.setPassword(agent.getMobile().substring(6));
  301. user.setCreateBy(SecurityUtils.getUsername());
  302. user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
  303. Long[] roleIds = {UserTypeJoinRoleEnums.AGENT.getRoleId()};
  304. user.setRoleIds(roleIds);
  305. userService.updateUser(user);
  306. }
  307. return true;
  308. }
  309. @Override
  310. public BigDecimal getMaxRete(SysUser user) {
  311. if (user.getType().equals(UserTypeEnums.PLATFORM.getCode())) {
  312. return new BigDecimal(100);
  313. } else if (user.getType().equals(UserTypeEnums.DSP.getCode())) {
  314. DspConfig dspConfig = iDspConfigService.getById(user.getDspId());
  315. if (dspConfig == null) {
  316. throw new CustomException("未找到登录信息,请您重新登录!");
  317. }
  318. return dspConfig.getCommissionRate();
  319. } else if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  320. Agent agent = this.getById(user.getAgentId());
  321. if (agent == null) {
  322. throw new CustomException("未找到登录信息,请您重新登录!");
  323. }
  324. return agent.getCommissionRate();
  325. }
  326. return null;
  327. }
  328. @Override
  329. public Agent getInfoById(Long id) {
  330. Agent agent = this.getById(id);
  331. if(agent != null) {
  332. if (agent.getPid() == null) {
  333. agent.setIsPid(0);
  334. }else {
  335. Agent superAgent = this.getById(agent.getPid());
  336. if (superAgent != null && superAgent.getPid() == null) {
  337. agent.setProvinceName(superAgent.getProvinceName());
  338. agent.setCityName(superAgent.getCityName());
  339. agent.setDistrictName(superAgent.getDistrictName());
  340. }else if (superAgent != null && superAgent.getPid() != null) {
  341. Agent superLowAgent = this.getById(superAgent.getPid());
  342. agent.setProvinceName(superLowAgent.getProvinceName());
  343. agent.setCityName(superLowAgent.getCityName());
  344. agent.setDistrictName(superLowAgent.getDistrictName());
  345. }
  346. agent.setIsPid(agent.getPid().intValue());
  347. }
  348. }
  349. if (agent != null) {
  350. AgentLevel level = iAgentLevelService.getByLevel(agent.getAgentLevel().intValue(), agent.getDspId());
  351. if (level != null) {
  352. agent.setLevelName(level.getName());
  353. }
  354. DspConfig dspConfig = iDspConfigService.getById(agent.getDspId());
  355. if (dspConfig != null) {
  356. agent.setDspName(dspConfig.getName());
  357. }
  358. }
  359. return agent;
  360. }
  361. @Override
  362. public Agent getInfo(Long id, SysUser user) {
  363. Agent agent = this.getById(id);
  364. if(agent != null) {
  365. if (agent.getPid() == null) {
  366. agent.setIsPid(0);
  367. }else {
  368. Agent superAgent = this.getById(agent.getPid());
  369. if (superAgent != null && superAgent.getPid() == null) {
  370. agent.setProvinceName(superAgent.getProvinceName());
  371. agent.setCityName(superAgent.getCityName());
  372. agent.setDistrictName(superAgent.getDistrictName());
  373. }else if (superAgent != null && superAgent.getPid() != null) {
  374. Agent superLowAgent = this.getById(superAgent.getPid());
  375. agent.setProvinceName(superLowAgent.getProvinceName());
  376. agent.setCityName(superLowAgent.getCityName());
  377. agent.setDistrictName(superLowAgent.getDistrictName());
  378. }
  379. agent.setIsPid(agent.getPid().intValue());
  380. }
  381. }
  382. if (agent != null) {
  383. AgentLevel level = iAgentLevelService.getByLevel(agent.getAgentLevel().intValue(), agent.getDspId());
  384. if (level != null) {
  385. agent.setLevelName(level.getName());
  386. }
  387. DspConfig dspConfig = iDspConfigService.getById(agent.getDspId());
  388. if (dspConfig != null) {
  389. agent.setDspName(dspConfig.getName());
  390. }
  391. }
  392. // 判断当前账号是否拥有查看详情权限
  393. if (user.getType().equals(UserTypeEnums.AGENT.getCode())) {
  394. List<Long> agentIds = baseMapper.listAgent(user.getAgentId());
  395. if (agentIds.size() > 0) {
  396. Boolean flag = false;
  397. List<Long> agentAllIds = baseMapper.listLowAgent(agentIds, user.getAgentId());
  398. for (Long agentId : agentAllIds) {
  399. if (agentId.longValue() == id.longValue()) {
  400. flag = true;
  401. }
  402. }
  403. if (flag == true) {
  404. agent.setIsPermission(true);
  405. }else {
  406. agent.setIsPermission(false);
  407. }
  408. }
  409. }
  410. if (agent != null && agent.getPid() != null) {
  411. Agent supper = baseMapper.getByPid(agent.getPid());
  412. agent.setBindingThirdMax(supper.getBindingThirdCommission());
  413. }
  414. return agent;
  415. }
  416. @Override
  417. public List<Agent> selectAgentListByStatus(Integer status) {
  418. return baseMapper.selectAgentListByStatus(status);
  419. }
  420. @Override
  421. public List<Agent> selectByPid(Integer id) {
  422. return baseMapper.selectByPid(id);
  423. }
  424. @Override
  425. public Integer getSAgentNum(Integer pid, String todayStartDate) {
  426. return baseMapper.getSAgentNum(pid, todayStartDate);
  427. }
  428. @Override
  429. public void updateAgentListAmount(List<Agent> list) {
  430. this.updateBatchById(list, list.size());
  431. }
  432. @Override
  433. public List<Integer> getAgentIdsByPid(Integer id) {
  434. return baseMapper.getAgentIdsByPid(id);
  435. }
  436. @Override
  437. public List<Long> listAgent(Long id) {
  438. return baseMapper.listAgent(id);
  439. }
  440. /**
  441. * 查询自己和下级以及下下级的id
  442. *
  443. * @param id
  444. * @return
  445. */
  446. @Override
  447. public List<Integer> getIds(Integer id) {
  448. List<Integer> agentIds = new ArrayList<>();
  449. List<Integer> ids = baseMapper.getAgentIdsByPid(id);
  450. for (int i = 0; i < ids.size(); i++) {
  451. agentIds.add(ids.get(i));
  452. agentIds.addAll(baseMapper.getAgentIdsByPid(ids.get(i)));
  453. }
  454. return agentIds;
  455. }
  456. /**
  457. * 根据渠道商查找代理商的id
  458. *
  459. * @param dspId
  460. * @return
  461. */
  462. @Override
  463. public List<Integer> getAgentIdsByDspId(Integer dspId) {
  464. return baseMapper.getAgentIdsByDspId(dspId);
  465. }
  466. /**
  467. * 按区域查询代理商(一级代理商)
  468. *
  469. * @param cityName 市
  470. * @param districtName 区
  471. * @return
  472. */
  473. @Override
  474. public Agent findByArea(String cityName, String districtName) {
  475. return baseMapper.findByArea(cityName, districtName);
  476. }
  477. /**
  478. * 根据pid查找一级代理商
  479. *
  480. * @param pid
  481. * @return
  482. */
  483. @Override
  484. public Agent getByPid(Long pid) {
  485. return baseMapper.getByPid(pid);
  486. }
  487. /**
  488. * 查询代理商的下级代理商
  489. * @param pid
  490. * @return
  491. */
  492. @Override
  493. public List<Long> selectByPid(Long pid) {
  494. return baseMapper.lowerAgent(pid);
  495. }
  496. @Override
  497. @Transactional(rollbackFor = Exception.class)
  498. public void updateAgentStatus(Integer id){
  499. Agent agent = this.getById(id);
  500. if (agent != null){
  501. if (agent.getPid() != null && agent.getStatus().equals(StatusEnum.SHOW.status)) {
  502. agent.setBindingThirdCommission(BigDecimal.ZERO);
  503. agent.setHuolalaCommission(BigDecimal.ZERO);
  504. agent.setCommissionRate(BigDecimal.ZERO);
  505. }
  506. agent.setStatus(agent.getStatus().equals(0) ? 1 : 0);
  507. this.updateById(agent);
  508. }
  509. }
  510. @Override
  511. public BaseConfgMinDto getBaseConfigMin(Integer type) {
  512. return baseMapper.getBaseConfigMin(type);
  513. }
  514. @Override
  515. public BigDecimal getMinBindFee(String cityId) {
  516. if (cityId.equals("0")) {
  517. return BigDecimal.ZERO;
  518. }else {
  519. return baseMapper.getMinBindFee(cityId);
  520. }
  521. }
  522. @Override
  523. public void bindValuationRulePackage(AgentBindRulePackageRequest request) {
  524. Agent agent = baseMapper.selectById(request.getAgentId());
  525. if (Objects.isNull(agent)) {
  526. throw new CustomWebException("代理商不存在!");
  527. }
  528. UpdateWrapper<Agent> updateWrapper = new UpdateWrapper<>();
  529. if (PackageCityConfigPackageTypeEnum.DISCOUNT.type.equals(request.getPackageType())) {
  530. updateWrapper.set("package_discount_id", request.getPackageId())
  531. .eq("id", agent.getId());
  532. // agent.setPackageDiscountId(request.getPackageId());
  533. } else if (PackageCityConfigPackageTypeEnum.COMMISSION.type.equals(request.getPackageType())) {
  534. updateWrapper.set("package_commission_id", request.getPackageId())
  535. .eq("id", agent.getId());
  536. // agent.setPackageCommissionId(request.getPackageId());
  537. } else {
  538. throw new CustomWebException("无效的包类型!");
  539. }
  540. baseMapper.update(agent, updateWrapper);
  541. }
  542. }