|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
package com.hchbox.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
@ -9,6 +10,8 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.extra.emoji.EmojiUtil;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.hchbox.config.MiProperties;
|
|
|
|
|
import com.hchbox.constant.AuthConstants;
|
|
|
|
@ -21,6 +24,8 @@ import com.hchbox.dto.SellerAccountDTO;
|
|
|
|
|
import com.hchbox.entity.master.PayTemplate;
|
|
|
|
|
import com.hchbox.entity.master.SellerAccount;
|
|
|
|
|
import com.hchbox.enums.ResponseCode;
|
|
|
|
|
import com.hchbox.exception.TaoMiCommException;
|
|
|
|
|
import com.hchbox.model.entity.BaseSellerAccount;
|
|
|
|
|
import com.hchbox.model.param.CommonResult;
|
|
|
|
|
import com.hchbox.repository.master.PayTemplateRepository;
|
|
|
|
|
import com.hchbox.repository.master.SellerAccountRepository;
|
|
|
|
@ -29,7 +34,13 @@ import com.hchbox.util.CacheManagerUtil;
|
|
|
|
|
import com.hchbox.util.PageUtil;
|
|
|
|
|
import com.hchbox.util.QueryHelp;
|
|
|
|
|
import com.hchbox.vo.*;
|
|
|
|
|
import com.taobao.api.ApiException;
|
|
|
|
|
import com.taobao.api.DefaultTaobaoClient;
|
|
|
|
|
import com.taobao.api.TaobaoClient;
|
|
|
|
|
import com.taobao.api.domain.Shop;
|
|
|
|
|
import com.taobao.api.request.SellercenterSubusersGetRequest;
|
|
|
|
|
import com.taobao.api.response.SellercenterSubusersGetResponse;
|
|
|
|
|
import javafx.scene.effect.Light;
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
@ -44,6 +55,9 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static java.util.stream.Collectors.toMap;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author Enzo
|
|
|
|
@ -73,7 +87,6 @@ public class SellerAccountServiceImpl implements SellerAccountService {
|
|
|
|
|
private final SellerAccountRepository sellerAccountRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Long getAccountIdByNick(String sellerNick) {
|
|
|
|
|
return sellerAccountRepository.findSellerAccountByNickname(sellerNick).getId();
|
|
|
|
@ -147,13 +160,13 @@ public class SellerAccountServiceImpl implements SellerAccountService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean updateAccountExpirationTime(UpdateSellerVo updateSellerVo) {
|
|
|
|
|
if (updateSellerVo != null) {
|
|
|
|
|
public Boolean updateAccountExpirationTime(UpdateAccountsVo updateAccountsVo) {
|
|
|
|
|
if (updateAccountsVo != null) {
|
|
|
|
|
SellerAccount account = sellerAccountRepository.
|
|
|
|
|
findSellerAccountByNickname(updateSellerVo.getPurchaser());
|
|
|
|
|
findSellerAccountById(updateAccountsVo.getId());
|
|
|
|
|
if (account != null) {
|
|
|
|
|
log.info("=============== the account nickname as {} ===============", account.getNickname());
|
|
|
|
|
account.setAccountBalance(updateSellerVo.getAccountBalance());
|
|
|
|
|
account.setAccountBalance(updateAccountsVo.getAccountBalance());
|
|
|
|
|
Boolean aBoolean = taoBaoRdsPushService.turnOnPushService(account.getSessionKey(), (long) DefaultNumberConstants.NINETY);
|
|
|
|
|
taoBaoMessageService.openMessagePermit(account.getSessionKey());
|
|
|
|
|
log.info("================== the push service result as {} ==================", aBoolean);
|
|
|
|
@ -307,13 +320,69 @@ public class SellerAccountServiceImpl implements SellerAccountService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<SellerAccount> queryAccountByParentId(Long accountId) {
|
|
|
|
|
// List<SellerAccount> byParentIdAndStatus = sellerAccountRepository.findByParentIdAndStatus(DefaultNumberConstants.ONE_NUMBER, accountId);
|
|
|
|
|
// if (CollectionUtils.isEmpty(byParentIdAndStatus)) {
|
|
|
|
|
// SellerAccount sellerAccount = sellerAccountRepository.findById(accountId).orElseGet(SellerAccount::new);
|
|
|
|
|
// byParentIdAndStatus.add(sellerAccount);
|
|
|
|
|
// }
|
|
|
|
|
return sellerAccountRepository.findAllByParentId(accountId);
|
|
|
|
|
public List<SubAccountsVo> queryAccountByParentId(Long accountId) {
|
|
|
|
|
List<SubAccountsVo> list = new ArrayList<>();
|
|
|
|
|
//查询主账号信息
|
|
|
|
|
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountById(accountId);
|
|
|
|
|
if (ObjectUtil.isEmpty(sellerAccount)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
//获取授权的子账号列表
|
|
|
|
|
List<SubAccountsVo> authorizeSubAccounts = Convert.toList(SubAccountsVo.class, sellerAccountRepository.findAllByParentId(accountId));
|
|
|
|
|
if (ObjectUtil.isEmpty(authorizeSubAccounts)) {
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
Map<String, SubAccountsVo> map = authorizeSubAccounts.stream().collect(toMap(SubAccountsVo::getNickname, p -> p, (key1, key2) -> key2));
|
|
|
|
|
|
|
|
|
|
//获取淘宝子账号列表
|
|
|
|
|
List<SubAccountsVo> notAuthorizeList = getTaoBaoSubAccounts(sellerAccount.getNickname(), sellerAccount.getSessionKey());
|
|
|
|
|
for (SubAccountsVo subAccountsVo : notAuthorizeList) {
|
|
|
|
|
if (!map.containsKey(subAccountsVo.getNickname())) {
|
|
|
|
|
map.put(subAccountsVo.getNickname(), subAccountsVo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (Map.Entry<String, SubAccountsVo> entry : map.entrySet()) {
|
|
|
|
|
list.add(entry.getValue());
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<SubAccountsVo> getTaoBaoSubAccounts(String nickname, String sessionKey) {
|
|
|
|
|
List<SubAccountsVo> list = new ArrayList<>();
|
|
|
|
|
TaobaoClient client = new DefaultTaobaoClient(miProperties.getServerUrl(), miProperties.getAppKey(), miProperties.getAppSecret());
|
|
|
|
|
SellercenterSubusersGetRequest req = new SellercenterSubusersGetRequest();
|
|
|
|
|
req.setNick(nickname);
|
|
|
|
|
SellercenterSubusersGetResponse rsp = null;
|
|
|
|
|
try {
|
|
|
|
|
rsp = client.execute(req, sessionKey);
|
|
|
|
|
} catch (ApiException e) {
|
|
|
|
|
log.error("根据主账号请求子账号列表失败,{}", e.getMessage());
|
|
|
|
|
throw new TaoMiCommException(ResponseCode.REQUEST_FAIL.getDesc());
|
|
|
|
|
}
|
|
|
|
|
JSONObject jsonObject = JSONUtil.parseObj(rsp.getBody());
|
|
|
|
|
try {
|
|
|
|
|
//将淘宝查询的数据 转为自己数据的格式
|
|
|
|
|
JSONArray jsonArray = jsonObject.getJSONObject("sellercenter_subusers_get_response").getJSONObject("subusers").getJSONArray("sub_user_info");
|
|
|
|
|
if (jsonArray != null) {
|
|
|
|
|
for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
|
|
JSONObject json = jsonArray.getJSONObject(i);
|
|
|
|
|
if (json != null && json.getInt("status") == DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
SubAccountsVo subAccountsVo = new SubAccountsVo();
|
|
|
|
|
subAccountsVo.setNickname(json.getStr("nick"));
|
|
|
|
|
subAccountsVo.setStatus(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
subAccountsVo.setAuthorizeStartTime(null);
|
|
|
|
|
subAccountsVo.setAuthorizeDay(DefaultNumberConstants.ZERO_NUMBER);
|
|
|
|
|
subAccountsVo.setAuthorizeEndTime(null);
|
|
|
|
|
list.add(subAccountsVo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("请求错误,{}", jsonObject);
|
|
|
|
|
throw new TaoMiCommException(ResponseCode.SESSION_EXPIRED.getDesc());
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -359,20 +428,35 @@ public class SellerAccountServiceImpl implements SellerAccountService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) {
|
|
|
|
|
//验证是否为子账号
|
|
|
|
|
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountById(childrenAccountId);
|
|
|
|
|
if (sellerAccount.getParentId() == DefaultNumberConstants.ZERO_NUMBER) {
|
|
|
|
|
return new CommonResult<>().failed("授权的账号不是子账号");
|
|
|
|
|
}
|
|
|
|
|
public CommonResult<Object> authorizeChildrenAccount(Long parentAccountId, String nickName, Long payTemplateId) {
|
|
|
|
|
//查询出套餐模板
|
|
|
|
|
PayTemplate payTemplateByTemplateId = payTemplateRepository.findPayTemplateByTemplateId(payTemplateId);
|
|
|
|
|
if (ObjectUtil.isEmpty(payTemplateByTemplateId)) {
|
|
|
|
|
return new CommonResult<>().failed("未查询到套餐");
|
|
|
|
|
}
|
|
|
|
|
//验证是否为子账号
|
|
|
|
|
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountByNickname(nickName);
|
|
|
|
|
Date authorizeStartTime;
|
|
|
|
|
Date authorizeEndTime;
|
|
|
|
|
int authorizeDay;
|
|
|
|
|
if (ObjectUtil.isEmpty(sellerAccount)) {
|
|
|
|
|
authorizeStartTime = DateUtil.date();
|
|
|
|
|
authorizeDay = payTemplateByTemplateId.getPackageDay();
|
|
|
|
|
authorizeEndTime = DateUtil.offset(authorizeStartTime, DateField.DAY_OF_MONTH, authorizeDay);
|
|
|
|
|
sellerAccount.setNickname(nickName);
|
|
|
|
|
sellerAccount.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
sellerAccount.setAuthorizeStartTime(authorizeStartTime);
|
|
|
|
|
sellerAccount.setAuthorizeDay(authorizeDay);
|
|
|
|
|
sellerAccount.setAuthorizeEndTime(authorizeEndTime);
|
|
|
|
|
sellerAccount.setParentId(parentAccountId);
|
|
|
|
|
Long id = sellerAccountRepository.save(sellerAccount).getId();
|
|
|
|
|
return id == null ? new CommonResult<>().failed("授权失败") : CommonResult.successfulOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sellerAccount.getParentId() == DefaultNumberConstants.ZERO_NUMBER) {
|
|
|
|
|
return new CommonResult<>().failed("授权的账号不是子账号");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断账号之前的套餐时间
|
|
|
|
|
if (sellerAccount.getStatus() == DefaultNumberConstants.ONE_NUMBER) {
|
|
|
|
|
authorizeStartTime = sellerAccount.getAuthorizeStartTime();
|
|
|
|
@ -385,16 +469,16 @@ public class SellerAccountServiceImpl implements SellerAccountService {
|
|
|
|
|
authorizeDay = payTemplateByTemplateId.getPackageDay();
|
|
|
|
|
}
|
|
|
|
|
authorizeEndTime = DateUtil.offset(authorizeStartTime, DateField.DAY_OF_MONTH, authorizeDay);
|
|
|
|
|
int flag;
|
|
|
|
|
try {
|
|
|
|
|
flag = sellerAccountRepository.updateSellerAccountByCondition(authorizeStartTime, authorizeEndTime, authorizeDay, childrenAccountId,DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("子账号授权失败{}", e.getMessage());
|
|
|
|
|
return new CommonResult<>().failed("子账号授权失败");
|
|
|
|
|
}
|
|
|
|
|
return flag == DefaultNumberConstants.ONE_NUMBER ? CommonResult.successfulOperation() : new CommonResult<>().failed("授权失败");
|
|
|
|
|
sellerAccount.setNickname(nickName);
|
|
|
|
|
sellerAccount.setStatus(DefaultNumberConstants.ONE_NUMBER);
|
|
|
|
|
sellerAccount.setAuthorizeStartTime(authorizeStartTime);
|
|
|
|
|
sellerAccount.setAuthorizeDay(authorizeDay);
|
|
|
|
|
sellerAccount.setAuthorizeEndTime(authorizeEndTime);
|
|
|
|
|
Long id = sellerAccountRepository.save(sellerAccount).getId();
|
|
|
|
|
return id == null ? new CommonResult<>().failed("授权失败") : CommonResult.successfulOperation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SellerAccount createSellerAccount(AuthTokenResponseDTO tokenDTO) {
|
|
|
|
|
SellerAccount seller = new SellerAccount();
|
|
|
|
|
seller.setLastLoginTime(DateUtil.date());
|
|
|
|
|