|
|
@@ -1,10 +1,38 @@
|
|
|
package com.kxs.product.biz.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
+import cn.hutool.core.util.IdcardUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.kxs.common.core.constant.SecurityConstants;
|
|
|
+import com.kxs.common.core.constant.enums.MachineTypeEnum;
|
|
|
+import com.kxs.common.core.util.R;
|
|
|
+import com.kxs.common.security.util.SecurityUtils;
|
|
|
+import com.kxs.product.api.dto.kxsapp.merchant.MerchantListDTO;
|
|
|
+import com.kxs.product.api.dto.kxsapp.merchant.ToMerchantMakerDTO;
|
|
|
+import com.kxs.product.api.model.KxsMachine;
|
|
|
+import com.kxs.product.api.model.KxsMachineTrack;
|
|
|
+import com.kxs.product.api.vo.kxsapp.merchant.MerchantDetailVO;
|
|
|
+import com.kxs.product.api.vo.kxsapp.merchant.MerchantListVO;
|
|
|
+import com.kxs.product.api.vo.kxsapp.merchant.MerchantTotalVO;
|
|
|
+import com.kxs.product.biz.mapper.KxsMachineMapper;
|
|
|
import com.kxs.product.biz.mapper.KxsMerchantMapper;
|
|
|
import com.kxs.product.api.model.KxsMerchant;
|
|
|
import com.kxs.product.biz.service.KxsMerchantService;
|
|
|
+import com.kxs.user.api.feign.RemoteKxsUserService;
|
|
|
+import com.kxs.user.api.model.KxsUser;
|
|
|
+import com.kxs.user.api.model.KxsUserReal;
|
|
|
+import com.kxs.user.api.vo.kxsapp.user.RealUserInfoVO;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import net.bytebuddy.implementation.bytecode.Throw;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
/**
|
|
|
* 客小爽商户表(KxsMerchant)表服务实现类
|
|
|
@@ -13,7 +41,123 @@ import org.springframework.stereotype.Service;
|
|
|
* @since 2023-12-20 10:09:35
|
|
|
*/
|
|
|
@Service("kxsMerchantService")
|
|
|
+@RequiredArgsConstructor
|
|
|
public class KxsMerchantServiceImpl extends ServiceImpl<KxsMerchantMapper, KxsMerchant> implements KxsMerchantService {
|
|
|
+ private final KxsMachineMapper kxsMachineMapper;
|
|
|
+ private final RemoteKxsUserService remoteKxsUserService;
|
|
|
+ private final KxsMerchantMapper kxsMerchantMapper;
|
|
|
+ @Override
|
|
|
+ public Object merchantList(Page<KxsMerchant> page, MerchantListDTO param) {
|
|
|
+ Long userId = SecurityUtils.getUser().getId();
|
|
|
+ param.setUserId(userId);
|
|
|
+ if (param.getSort() != null && param.getSort().equals("amount")){
|
|
|
+ param.setSort("thisMonthTrade");
|
|
|
+ }else if (param.getSort() != null && param.getSort().equals("time")){
|
|
|
+ param.setSort("create_time");
|
|
|
+ }else {
|
|
|
+ param.setSort(null);
|
|
|
+ }
|
|
|
+ return kxsMerchantMapper.merchantList(page,param);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object merchantDetail(Long merchantId) {
|
|
|
+ MerchantDetailVO merchantDetailVO = new MerchantDetailVO();
|
|
|
+ //商户信息
|
|
|
+ KxsMerchant byId = getById(merchantId);
|
|
|
+ BeanUtil.copyProperties(byId,merchantDetailVO);
|
|
|
+ //机具信息
|
|
|
+ KxsMachine kxsMachine = kxsMachineMapper.selectById(byId.getMachineId());
|
|
|
+ merchantDetailVO.setPosSn(kxsMachine.getPosSn());
|
|
|
+ merchantDetailVO.setBrand(kxsMachine.getBrandId().toString());
|
|
|
+ merchantDetailVO.setActTime(kxsMachine.getActTime().toString());
|
|
|
+ return merchantDetailVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R toMerchantMaker(ToMerchantMakerDTO param) {
|
|
|
+ Long parenUserId = SecurityUtils.getUser().getId();
|
|
|
+ //查询创客
|
|
|
+ R<KxsUser> kxsUserR = remoteKxsUserService.loadUserByCode(param.getUserCode(), SecurityConstants.FROM_IN);
|
|
|
+ if (kxsUserR.getData() == null){
|
|
|
+ return R.failed("用户不存在");
|
|
|
+ }
|
|
|
+ KxsUser kxsUser = kxsUserR.getData();
|
|
|
+ //查询实名信息
|
|
|
+ if (kxsUser.getRealStatus() == null || kxsUser.getRealStatus() == 0) {
|
|
|
+ return R.failed("用户未实名");
|
|
|
+ }
|
|
|
+ //查询是否是下级
|
|
|
+ String pidPath = kxsUser.getPidPath();
|
|
|
+ boolean isParent = pidPath.contains("," + parenUserId + ",");
|
|
|
+ if (!isParent) {
|
|
|
+ return R.failed("用户不在当前用户系统下");
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询机具所属商户
|
|
|
+ KxsMachine kxsMachine = kxsMachineMapper.selectOne(Wrappers.<KxsMachine>query().lambda().eq(KxsMachine::getPosSn,param.getPosSn()));
|
|
|
+ //机具所属不一致
|
|
|
+ if (!Long.valueOf(kxsMachine.getUserId()).equals(parenUserId)) {
|
|
|
+ return R.failed("非法参数:机具非当前用户所有");
|
|
|
+ }
|
|
|
+ //未激活
|
|
|
+ if (!kxsMachine.getIsAct().equals(MachineTypeEnum.ACT.getType())) {
|
|
|
+ return R.failed("机具未激活");
|
|
|
+ }
|
|
|
+ KxsMerchant kxsMerchant = getById(kxsMachine.getMerchantId());
|
|
|
+ if (kxsMerchant == null) {
|
|
|
+ return R.failed("机具商户不存在");
|
|
|
+ }
|
|
|
+ //判断机具所属商户和转换的用户数据能否一致 2要素
|
|
|
+ //商户实名信息
|
|
|
+ String idCard = kxsMerchant.getMerchantCard();
|
|
|
+ if (CharSequenceUtil.isEmpty(idCard)) {
|
|
|
+ return R.failed("商户未绑定身份信息");
|
|
|
+ }
|
|
|
+ //判断身份证是否脱敏
|
|
|
+ boolean validCard = IdcardUtil.isValidCard(idCard);
|
|
|
+ //用户实名信息
|
|
|
+ KxsUserReal userReal = remoteKxsUserService.loadUserRealById(kxsUser.getId(), SecurityConstants.FROM_IN).getData();
|
|
|
+ if (!validCard) {
|
|
|
+ //如果脱敏需要验证前6后4
|
|
|
+ String prefix = idCard.substring(0, 6);
|
|
|
+ String after = idCard.substring(idCard.length() - 4);
|
|
|
+ //
|
|
|
+ String realPrefix = userReal.getIdCard().substring(0, 6);
|
|
|
+ String realAfter = userReal.getIdCard().substring(userReal.getIdCard().length() - 4);
|
|
|
+ if (!prefix.equals(realPrefix) || !after.equalsIgnoreCase(realAfter)) {
|
|
|
+ return R.failed("当前商户身份信息与转换用户身份信息不一致,请重新核对后重试");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //未脱敏直接比对
|
|
|
+ if (!userReal.getIdCard().equalsIgnoreCase(idCard)) {
|
|
|
+ return R.failed("当前商户身份信息与转换用户身份信息不一致,请重新核对后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!userReal.getRealName().equals(kxsMerchant.getMerchantName())) {
|
|
|
+ return R.failed("当前商户身份信息与转换用户身份信息不一致,请重新核对后重试");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //可以转换为商户型创客
|
|
|
+ kxsUser.setIsMerchantMaker(1);
|
|
|
+ kxsUser.setUpdateTime(LocalDateTime.now());
|
|
|
+ remoteKxsUserService.updateById(kxsUser,SecurityConstants.FROM_IN);
|
|
|
+
|
|
|
+ //修改商户类型
|
|
|
+ kxsMerchant.setIsMaker(1);
|
|
|
+ kxsMerchant.setMakerUserId(kxsUser.getId());
|
|
|
+ updateById(kxsMerchant);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Object merchantTotal(Integer brandId) {
|
|
|
+ Long id = SecurityUtils.getUser().getId();
|
|
|
+ return kxsMerchantMapper.merchantTotal(brandId,id);
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|