Merge remote-tracking branch 'origin/dev' into dev

# Conflicts:
#	service/trade-service-source/trade-service-source-core/src/main/java/com/hchbox/controller/SellerAccountController.java
master
bynt 3 years ago
commit 897d33f582

@ -1,14 +1,19 @@
package com.hchbox.api; package com.hchbox.api;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import com.hchbox.module.entity.PayOrder;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/** /**
* @author wujingtao * @author wujingtao
* @date 2021/10/20 * @date 2021/10/20
@ -57,15 +62,51 @@ public class RequestCore {
/** /**
* *
* *
* @param childrenAccountId * @param parentAccountId
* @param nickName
* @param payTemplateId * @param payTemplateId
* @return * @return
*/ */
public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) { public CommonResult<Object> authorizeChildrenAccount(Long parentAccountId, String nickName, Long payTemplateId) {
String reqUrl = url + API_PREFIX + "/account/authorize" + "?" + "childrenAccountId=" + childrenAccountId + "&payTemplateId=" + payTemplateId; String reqUrl = url + API_PREFIX + "/account/authorize" + "?" + "parentAccountId=" + parentAccountId + "&nickName=" + nickName + "&payTemplateId=" + payTemplateId;
return requestApi(reqUrl); return requestApi(reqUrl);
} }
/**
*
* @param payOrder
* @return
*/
public CommonResult<Object> savePayOrder(PayOrder payOrder){
String reqUrl = url + API_PREFIX + "/pay/notify";
Map<String, Object> map = new HashMap<>();
map.put("templateId",payOrder.getTemplateId());
map.put("payType", payOrder.getPayType());
map.put("orderNumber",payOrder.getOrderNumber());
map.put("status",payOrder.getStatus());
map.put("orderTime",payOrder.getOrderTime());
map.put("payTime",payOrder.getPayTime());
map.put("amount",payOrder.getAmount());
map.put("nickName",payOrder.getNickName());
map.put("masterUserId",payOrder.getMasterUserId());
String post = HttpUtil.post(reqUrl,JSONUtil.parseObj(map).toString());
return new CommonResult<>().success(post);
}
/**
*
* @param payOrder
* @return
*/
public CommonResult<Object> updateSellerAccount(PayOrder payOrder){
String reqUrl = url + API_PREFIX + "/account/updateSellerAccount";
Map<String, Object> map = new HashMap<>();
map.put("accountBalance",payOrder.getAmount());
map.put("id",payOrder.getMasterUserId());
String post = HttpUtil.post(reqUrl,JSONUtil.parseObj(map).toString());
return new CommonResult<>().success(post);
}
private CommonResult<Object> requestApi(String url) { private CommonResult<Object> requestApi(String url) {
String getResult = HttpUtil String getResult = HttpUtil
.createGet(url) .createGet(url)

@ -68,10 +68,11 @@ public class AccountInfoController {
@GetMapping("/account/authorize") @GetMapping("/account/authorize")
@ApiOperation("对子账号授权") @ApiOperation("对子账号授权")
public CommonResult<Object> authorizeChildrenAccount(@RequestParam(value = "childrenAccountId") Long childrenAccountId, @RequestParam(value = "payTemplateId") Long payTemplateId) { public CommonResult<Object> authorizeChildrenAccount(@RequestParam(value = "parentAccountId") Long parentAccountId,@RequestParam(value = "nickName") String nickName,
if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) { @RequestParam(value = "payTemplateId") Long payTemplateId) {
if (parentAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) {
return new CommonResult<>().validateFailed("参数错误"); return new CommonResult<>().validateFailed("参数错误");
} }
return requestCore.authorizeChildrenAccount(childrenAccountId, payTemplateId); return requestCore.authorizeChildrenAccount(parentAccountId, nickName, payTemplateId);
} }
} }

@ -2,12 +2,14 @@ package com.hchbox.module.entity;
import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.hchbox.model.entity.BasePayOrder;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable;
import java.util.Date; import java.util.Date;
/** /**
@ -17,8 +19,9 @@ import java.util.Date;
@Data @Data
@Entity @Entity
@Table(name = "pay_order") @Table(name = "pay_order")
@EntityListeners(AuditingEntityListener.class) public class PayOrder extends BasePayOrder implements Serializable {
public class PayOrder {
private static final long serialVersionUID = 7788712870573889428L;
@Id @Id
@Column(name = "id") @Column(name = "id")
@ -26,47 +29,5 @@ public class PayOrder {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Integer id;
@Column(name = "template_id")
@ApiModelProperty(value = "购买模板id")
private Long templateId;
@Column(name = "pay_type")
@ApiModelProperty(value = "支付类型")
private Integer payType;
@Column(name = "order_number")
@ApiModelProperty(value = "订单编号")
private String orderNumber;
@Column(name = "status")
@ApiModelProperty(value = "订单状态")
private Integer status;
@Column(name = "purchaser")
@ApiModelProperty(value = "购买人")
private String purchaser;
@CreatedDate
@Column(name = "order_time")
@ApiModelProperty(value = "下单时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
private Date orderTime;
@Column(name = "pay_time")
@ApiModelProperty(value = "支付时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
private Date payTime;
@Column(name = "days")
@ApiModelProperty(value = "套餐天数")
private Integer days;
@Column(name = "amount")
@ApiModelProperty(value = "金额")
private Double amount;
@Column(name = "user_id")
@ApiModelProperty(value = "用户id")
private Long userId;
} }

@ -16,8 +16,12 @@ public class AliPayPcVo {
private Double amount; private Double amount;
@NotNull @NotNull
@ApiModelProperty(value = "账号id") @ApiModelProperty(value = "子账号nick")
private Long accountId; private String nickName;
@NotNull
@ApiModelProperty(value = "主账号id")
private Long masterAccountId;
@NotNull @NotNull
@ApiModelProperty(value = "模板id") @ApiModelProperty(value = "模板id")

@ -86,6 +86,7 @@ public class AccountRechargeServiceImpl implements AccountRechargeService {
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public CommonResult<String> aliPayPc(AliPayPcVo aliPayPcVo) { public CommonResult<String> aliPayPc(AliPayPcVo aliPayPcVo) {
AlipayTradePagePayResponse response; AlipayTradePagePayResponse response;
try { try {
@ -107,16 +108,18 @@ public class AccountRechargeServiceImpl implements AccountRechargeService {
private boolean savePayOrder(AliPayPcVo aliPayPcVo, String orderNo) { private boolean savePayOrder(AliPayPcVo aliPayPcVo, String orderNo) {
PayOrder order = new PayOrder(); PayOrder order = new PayOrder();
order.setUserId(aliPayPcVo.getAccountId()); order.setNickName(aliPayPcVo.getNickName());
order.setMasterUserId(aliPayPcVo.getMasterAccountId());
order.setOrderNumber(orderNo); order.setOrderNumber(orderNo);
order.setAmount(aliPayPcVo.getAmount()); order.setAmount(aliPayPcVo.getAmount());
order.setPayType(aliPayPcVo.getPayType()); order.setPayType(aliPayPcVo.getPayType());
order.setStatus(StatusEnum.UNPAID.getStatus());
order.setTemplateId(aliPayPcVo.getTemplateId()); order.setTemplateId(aliPayPcVo.getTemplateId());
order.setStatus(StatusEnum.UNPAID.getStatus());
return payOrderRepository.save(order).getId() != null; return payOrderRepository.save(order).getId() != null;
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public CommonResult<String> pcNotifyResponse(HttpServletRequest request) { public CommonResult<String> pcNotifyResponse(HttpServletRequest request) {
try { try {
//获取支付宝GET过来反馈信息 //获取支付宝GET过来反馈信息
@ -134,8 +137,12 @@ public class AccountRechargeServiceImpl implements AccountRechargeService {
order.setPayTime(DateUtil.date()); order.setPayTime(DateUtil.date());
order.setStatus(DefaultNumberConstants.ONE_NUMBER); order.setStatus(DefaultNumberConstants.ONE_NUMBER);
payOrderRepository.save(order); payOrderRepository.save(order);
//同步数据
requestCore.savePayOrder(order);
//子账号授权 //子账号授权
requestCore.authorizeChildrenAccount(order.getUserId(), order.getTemplateId()); requestCore.authorizeChildrenAccount(order.getMasterUserId(),order.getNickName(), order.getTemplateId());
// 修改账户信息 开通服务
requestCore.updateSellerAccount(order);
} }
} }
} catch (Exception e) { } catch (Exception e) {

@ -1,6 +1,7 @@
package com.hchbox.controller; package com.hchbox.controller;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.hchbox.entity.master.PayOrder;
import com.hchbox.entity.master.PayTemplate; import com.hchbox.entity.master.PayTemplate;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import com.hchbox.service.PayTemplateService; import com.hchbox.service.PayTemplateService;
@ -11,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Map;
/** /**
* @author wujingtao * @author wujingtao
@ -18,7 +20,6 @@ import javax.annotation.Resource;
*/ */
@Slf4j @Slf4j
@RestController @RestController
@AllArgsConstructor
@Api(tags = "套餐") @Api(tags = "套餐")
@RequestMapping("/source/pay") @RequestMapping("/source/pay")
public class PayTemplateController { public class PayTemplateController {
@ -40,5 +41,10 @@ public class PayTemplateController {
return payTemplateService.updatePayTemplate(payTemplate); return payTemplateService.updatePayTemplate(payTemplate);
} }
@ApiOperation(value = "支付回调同步数据")
@PostMapping(value = "/notify")
public CommonResult<Object> savePayOrder(@RequestBody PayOrder payOrder) {
return payTemplateService.savePayOrder(payOrder);
}
} }

@ -2,6 +2,7 @@
package com.hchbox.controller; package com.hchbox.controller;
import cn.hutool.core.convert.Convert; import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import com.hchbox.annotaion.SellerUser; import com.hchbox.annotaion.SellerUser;
import com.hchbox.constant.DefaultNumberConstants; import com.hchbox.constant.DefaultNumberConstants;
import com.hchbox.dto.SellerAccountDTO; import com.hchbox.dto.SellerAccountDTO;
@ -9,6 +10,9 @@ import com.hchbox.entity.master.SellerAccount;
import com.hchbox.enums.ResponseCode; import com.hchbox.enums.ResponseCode;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import com.hchbox.service.TaoBaoMessageService; import com.hchbox.service.TaoBaoMessageService;
import com.hchbox.vo.AccountSearchVo;
import com.hchbox.vo.SubAccountsVo;
import com.hchbox.vo.UpdateAccountsVo;
import com.hchbox.vo.UpdateSellerVo; import com.hchbox.vo.UpdateSellerVo;
import com.hchbox.service.SellerAccountService; import com.hchbox.service.SellerAccountService;
import com.hchbox.service.TaoBaoRdsPushService; import com.hchbox.service.TaoBaoRdsPushService;
@ -56,8 +60,8 @@ public class SellerAccountController {
@PostMapping("/updateSellerAccount") @PostMapping("/updateSellerAccount")
@ApiOperation("修改账号信息") @ApiOperation("修改账号信息")
public Boolean updateSellerAccount(@RequestBody UpdateSellerVo updateSellerVo) { public Boolean updateSellerAccount(@RequestBody UpdateAccountsVo updateAccountsVo) {
return sellerAccountService.updateAccountExpirationTime(updateSellerVo); return sellerAccountService.updateAccountExpirationTime(updateAccountsVo);
} }
@PostMapping("/subscribeService") @PostMapping("/subscribeService")
@ -72,19 +76,14 @@ public class SellerAccountController {
} }
@GetMapping("/subAccount") @GetMapping("/subAccount")
@ApiOperation("父类查找子类集合") @ApiOperation("父类查找子类集合")
public CommonResult<List<SellerAccount>> getSubAccount(@RequestParam Long accountId) { public CommonResult<List<SubAccountsVo>> getSubAccount(@RequestParam Long accountId) {
List<SellerAccount> sellerAccounts = sellerAccountService.queryAccountByParentId(accountId); List<SubAccountsVo> sellerAccounts = sellerAccountService.queryAccountByParentId(accountId);
// if (!CollectionUtils.isEmpty(sellerAccounts)) {
// return new CommonResult<List<SellerAccountDTO>>().success(Convert.toList(SellerAccountDTO.class, sellerAccounts));
// }
// return new CommonResult<List<SellerAccountDTO>>().success(new ArrayList<>());
if (!CollectionUtils.isEmpty(sellerAccounts)) { if (!CollectionUtils.isEmpty(sellerAccounts)) {
return new CommonResult<List<SellerAccount>>().success(sellerAccounts); return new CommonResult<List<SubAccountsVo>>().success(sellerAccounts);
} }
return new CommonResult<List<SellerAccount>>().success(new ArrayList<>()); return new CommonResult<List<SubAccountsVo>>().success(new ArrayList<>());
} }
@GetMapping("/parentAccounts") @GetMapping("/parentAccounts")
@ -96,11 +95,11 @@ public class SellerAccountController {
@GetMapping("/authorize") @GetMapping("/authorize")
@ApiOperation("子账号授权") @ApiOperation("子账号授权")
public CommonResult<Object> authorizeChildrenAccount(@RequestParam("childrenAccountId") Long childrenAccountId, @RequestParam("payTemplateId") Long payTemplateId) { public CommonResult<Object> authorizeChildrenAccount(@RequestParam("parentAccountId") Long parentAccountId, @RequestParam("nickName") String nickName, @RequestParam("payTemplateId") Long payTemplateId) {
if (childrenAccountId == DefaultNumberConstants.ZERO_NUMBER || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) { if (parentAccountId != null || StrUtil.isBlank(nickName) || payTemplateId == DefaultNumberConstants.ZERO_NUMBER) {
return new CommonResult<>().validateFailed("参数错误"); return new CommonResult<>().validateFailed("参数错误");
} }
return sellerAccountService.authorizeChildrenAccount(childrenAccountId, payTemplateId); return sellerAccountService.authorizeChildrenAccount(parentAccountId, nickName, payTemplateId);
} }
} }

@ -41,8 +41,8 @@ public class SlaverTest {
@Resource @Resource
private TopTradeService topTradeService; private TopTradeService topTradeService;
@Resource // @Resource
private UserService userService; // private UserService userService;
@Resource @Resource
private JdpTradeService jdpTradeService; private JdpTradeService jdpTradeService;
@ -59,11 +59,11 @@ public class SlaverTest {
private TaoBaoMessageService taoBaoMessageService; private TaoBaoMessageService taoBaoMessageService;
@Test // @Test
public void saveUser() { // public void saveUser() {
User user = new User(); // User user = new User();
userService.save(user); // userService.save(user);
} // }
@Test @Test
public void getAccount() { public void getAccount() {
sellerAccountService.getAccountByNick("usw电器旗舰店"); sellerAccountService.getAccountByNick("usw电器旗舰店");

@ -0,0 +1,33 @@
package com.hchbox.entity.master;
import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hchbox.model.entity.BasePayOrder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author Enzo
* @date : 2021/6/16
*/
@Data
@Entity
@Table(name = "pay_order")
public class PayOrder extends BasePayOrder implements Serializable {
private static final long serialVersionUID = 7788712870573889428L;
@Id
@Column(name = "id")
@ApiModelProperty(value = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
}

@ -68,20 +68,6 @@ public interface SellerAccountRepository extends JpaRepository<SellerAccount, Lo
*/ */
SellerAccount findSellerAccountById(Long childrenAccountId); SellerAccount findSellerAccountById(Long childrenAccountId);
/**
*
*
* @param authorizeStartTime
* @param authorizeEndTime
* @param authorizeDay
* @param id
* @param status
* @return
*/
@Modifying
@Query(value = "update SellerAccount set authorizeStartTime =?1 ,authorizeEndTime =?2,authorizeDay=?3 ,status =?5 where id=?4")
int updateSellerAccountByCondition(Date authorizeStartTime, Date authorizeEndTime, Integer authorizeDay, Long id, Integer status);
/** /**
* *
* *

@ -1,8 +1,11 @@
package com.hchbox.service; package com.hchbox.service;
import com.hchbox.entity.master.PayOrder;
import com.hchbox.entity.master.PayTemplate; import com.hchbox.entity.master.PayTemplate;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import java.util.Map;
/** /**
* @author wujingtao * @author wujingtao
* @date 2021/10/20 * @date 2021/10/20
@ -24,4 +27,11 @@ public interface PayTemplateService {
* @return * @return
*/ */
CommonResult<Object> updatePayTemplate(PayTemplate payTemplate); CommonResult<Object> updatePayTemplate(PayTemplate payTemplate);
/**
*
* @param payOrder
* @return
*/
CommonResult<Object> savePayOrder(PayOrder payOrder);
} }

@ -5,10 +5,7 @@ package com.hchbox.service;
import com.hchbox.dto.SellerAccountDTO; import com.hchbox.dto.SellerAccountDTO;
import com.hchbox.entity.master.SellerAccount; import com.hchbox.entity.master.SellerAccount;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import com.hchbox.vo.AccountSearchVo; import com.hchbox.vo.*;
import com.hchbox.vo.UpdateSellerVo;
import com.hchbox.vo.AppletsLoginVo;
import com.hchbox.vo.LoginVo;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
@ -43,10 +40,10 @@ public interface SellerAccountService {
/** /**
* *
* *
* @param updateSellerVo * @param updateAccountsVo
* @return * @return
*/ */
Boolean updateAccountExpirationTime(UpdateSellerVo updateSellerVo); Boolean updateAccountExpirationTime(UpdateAccountsVo updateAccountsVo);
/** /**
* 使 * 使
@ -103,7 +100,7 @@ public interface SellerAccountService {
* *
* @return * @return
*/ */
List<SellerAccount> queryAccountByParentId(Long accountId); List<SubAccountsVo> queryAccountByParentId(Long accountId);
/** /**
* *
@ -159,9 +156,9 @@ public interface SellerAccountService {
/** /**
* *
* *
* @param childrenAccountId * @param nickName
* @param payTemplateId * @param payTemplateId
* @return * @return
*/ */
CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId); CommonResult<Object> authorizeChildrenAccount(Long parentAccountId, String nickName, Long payTemplateId);
} }

@ -1,12 +1,17 @@
package com.hchbox.service.impl; package com.hchbox.service.impl;
import com.hchbox.entity.master.PayOrder;
import com.hchbox.entity.master.PayTemplate; import com.hchbox.entity.master.PayTemplate;
import com.hchbox.model.param.CommonResult; import com.hchbox.model.param.CommonResult;
import com.hchbox.repository.master.PayOrderRepository;
import com.hchbox.repository.master.PayTemplateRepository; import com.hchbox.repository.master.PayTemplateRepository;
import com.hchbox.service.PayTemplateService; import com.hchbox.service.PayTemplateService;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;
/** /**
* @author wujingtao * @author wujingtao
@ -16,6 +21,8 @@ import javax.annotation.Resource;
public class PayTemplateServiceImpl implements PayTemplateService { public class PayTemplateServiceImpl implements PayTemplateService {
@Resource @Resource
private PayTemplateRepository payTemplateRepository; private PayTemplateRepository payTemplateRepository;
@Resource
private PayOrderRepository payOrderRepository;
@Override @Override
public CommonResult<Object> getPayTemplate() { public CommonResult<Object> getPayTemplate() {
@ -26,4 +33,9 @@ public class PayTemplateServiceImpl implements PayTemplateService {
public CommonResult<Object> updatePayTemplate(PayTemplate payTemplate) { public CommonResult<Object> updatePayTemplate(PayTemplate payTemplate) {
return new CommonResult<>().success(payTemplateRepository.save(payTemplate)); return new CommonResult<>().success(payTemplateRepository.save(payTemplate));
} }
@Override
public CommonResult<Object> savePayOrder(PayOrder payOrder) {
return new CommonResult<>().success( payOrderRepository.save(payOrder));
}
} }

@ -2,6 +2,7 @@
package com.hchbox.service.impl; package com.hchbox.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateField; import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil; 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.core.util.StrUtil;
import cn.hutool.extra.emoji.EmojiUtil; import cn.hutool.extra.emoji.EmojiUtil;
import cn.hutool.http.HttpUtil; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import com.hchbox.config.MiProperties; import com.hchbox.config.MiProperties;
import com.hchbox.constant.AuthConstants; 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.PayTemplate;
import com.hchbox.entity.master.SellerAccount; import com.hchbox.entity.master.SellerAccount;
import com.hchbox.enums.ResponseCode; 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.model.param.CommonResult;
import com.hchbox.repository.master.PayTemplateRepository; import com.hchbox.repository.master.PayTemplateRepository;
import com.hchbox.repository.master.SellerAccountRepository; import com.hchbox.repository.master.SellerAccountRepository;
@ -29,7 +34,13 @@ import com.hchbox.util.CacheManagerUtil;
import com.hchbox.util.PageUtil; import com.hchbox.util.PageUtil;
import com.hchbox.util.QueryHelp; import com.hchbox.util.QueryHelp;
import com.hchbox.vo.*; 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.domain.Shop;
import com.taobao.api.request.SellercenterSubusersGetRequest;
import com.taobao.api.response.SellercenterSubusersGetResponse;
import javafx.scene.effect.Light;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -44,6 +55,9 @@ import org.springframework.util.CollectionUtils;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import static java.util.stream.Collectors.toMap;
/** /**
* @author Enzo * @author Enzo
@ -73,7 +87,6 @@ public class SellerAccountServiceImpl implements SellerAccountService {
private final SellerAccountRepository sellerAccountRepository; private final SellerAccountRepository sellerAccountRepository;
@Override @Override
public Long getAccountIdByNick(String sellerNick) { public Long getAccountIdByNick(String sellerNick) {
return sellerAccountRepository.findSellerAccountByNickname(sellerNick).getId(); return sellerAccountRepository.findSellerAccountByNickname(sellerNick).getId();
@ -147,13 +160,13 @@ public class SellerAccountServiceImpl implements SellerAccountService {
} }
@Override @Override
public Boolean updateAccountExpirationTime(UpdateSellerVo updateSellerVo) { public Boolean updateAccountExpirationTime(UpdateAccountsVo updateAccountsVo) {
if (updateSellerVo != null) { if (updateAccountsVo != null) {
SellerAccount account = sellerAccountRepository. SellerAccount account = sellerAccountRepository.
findSellerAccountByNickname(updateSellerVo.getPurchaser()); findSellerAccountById(updateAccountsVo.getId());
if (account != null) { if (account != null) {
log.info("=============== the account nickname as {} ===============", account.getNickname()); 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); Boolean aBoolean = taoBaoRdsPushService.turnOnPushService(account.getSessionKey(), (long) DefaultNumberConstants.NINETY);
taoBaoMessageService.openMessagePermit(account.getSessionKey()); taoBaoMessageService.openMessagePermit(account.getSessionKey());
log.info("================== the push service result as {} ==================", aBoolean); log.info("================== the push service result as {} ==================", aBoolean);
@ -307,13 +320,69 @@ public class SellerAccountServiceImpl implements SellerAccountService {
} }
@Override @Override
public List<SellerAccount> queryAccountByParentId(Long accountId) { public List<SubAccountsVo> queryAccountByParentId(Long accountId) {
// List<SellerAccount> byParentIdAndStatus = sellerAccountRepository.findByParentIdAndStatus(DefaultNumberConstants.ONE_NUMBER, accountId); List<SubAccountsVo> list = new ArrayList<>();
// if (CollectionUtils.isEmpty(byParentIdAndStatus)) { //查询主账号信息
// SellerAccount sellerAccount = sellerAccountRepository.findById(accountId).orElseGet(SellerAccount::new); SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountById(accountId);
// byParentIdAndStatus.add(sellerAccount); if (ObjectUtil.isEmpty(sellerAccount)) {
// } return new ArrayList<>();
return sellerAccountRepository.findAllByParentId(accountId); }
//获取授权的子账号列表
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 @Override
@ -359,20 +428,35 @@ public class SellerAccountServiceImpl implements SellerAccountService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public CommonResult<Object> authorizeChildrenAccount(Long childrenAccountId, Long payTemplateId) { public CommonResult<Object> authorizeChildrenAccount(Long parentAccountId, String nickName, Long payTemplateId) {
//验证是否为子账号
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountById(childrenAccountId);
if (sellerAccount.getParentId() == DefaultNumberConstants.ZERO_NUMBER) {
return new CommonResult<>().failed("授权的账号不是子账号");
}
//查询出套餐模板 //查询出套餐模板
PayTemplate payTemplateByTemplateId = payTemplateRepository.findPayTemplateByTemplateId(payTemplateId); PayTemplate payTemplateByTemplateId = payTemplateRepository.findPayTemplateByTemplateId(payTemplateId);
if (ObjectUtil.isEmpty(payTemplateByTemplateId)) { if (ObjectUtil.isEmpty(payTemplateByTemplateId)) {
return new CommonResult<>().failed("未查询到套餐"); return new CommonResult<>().failed("未查询到套餐");
} }
//验证是否为子账号
SellerAccount sellerAccount = sellerAccountRepository.findSellerAccountByNickname(nickName);
Date authorizeStartTime; Date authorizeStartTime;
Date authorizeEndTime; Date authorizeEndTime;
int authorizeDay; 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) { if (sellerAccount.getStatus() == DefaultNumberConstants.ONE_NUMBER) {
authorizeStartTime = sellerAccount.getAuthorizeStartTime(); authorizeStartTime = sellerAccount.getAuthorizeStartTime();
@ -385,16 +469,16 @@ public class SellerAccountServiceImpl implements SellerAccountService {
authorizeDay = payTemplateByTemplateId.getPackageDay(); authorizeDay = payTemplateByTemplateId.getPackageDay();
} }
authorizeEndTime = DateUtil.offset(authorizeStartTime, DateField.DAY_OF_MONTH, authorizeDay); authorizeEndTime = DateUtil.offset(authorizeStartTime, DateField.DAY_OF_MONTH, authorizeDay);
int flag; sellerAccount.setNickname(nickName);
try { sellerAccount.setStatus(DefaultNumberConstants.ONE_NUMBER);
flag = sellerAccountRepository.updateSellerAccountByCondition(authorizeStartTime, authorizeEndTime, authorizeDay, childrenAccountId,DefaultNumberConstants.ONE_NUMBER); sellerAccount.setAuthorizeStartTime(authorizeStartTime);
} catch (Exception e) { sellerAccount.setAuthorizeDay(authorizeDay);
log.error("子账号授权失败{}", e.getMessage()); sellerAccount.setAuthorizeEndTime(authorizeEndTime);
return new CommonResult<>().failed("子账号授权失败"); Long id = sellerAccountRepository.save(sellerAccount).getId();
} return id == null ? new CommonResult<>().failed("授权失败") : CommonResult.successfulOperation();
return flag == DefaultNumberConstants.ONE_NUMBER ? CommonResult.successfulOperation() : new CommonResult<>().failed("授权失败");
} }
private SellerAccount createSellerAccount(AuthTokenResponseDTO tokenDTO) { private SellerAccount createSellerAccount(AuthTokenResponseDTO tokenDTO) {
SellerAccount seller = new SellerAccount(); SellerAccount seller = new SellerAccount();
seller.setLastLoginTime(DateUtil.date()); seller.setLastLoginTime(DateUtil.date());

@ -0,0 +1,70 @@
package com.hchbox.model.entity;
import cn.hutool.core.date.DatePattern;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.util.Date;
@Getter
@Setter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BasePayOrder implements Serializable {
private static final long serialVersionUID = 2056458673691527927L;
@Column(name = "template_id")
@ApiModelProperty(value = "购买模板id")
private Long templateId;
@Column(name = "pay_type")
@ApiModelProperty(value = "支付类型")
private Integer payType;
@Column(name = "order_number")
@ApiModelProperty(value = "订单编号")
private String orderNumber;
@Column(name = "status")
@ApiModelProperty(value = "订单状态")
private Integer status;
@Column(name = "purchaser")
@ApiModelProperty(value = "购买人")
private String purchaser;
@CreatedDate
@Column(name = "order_time")
@ApiModelProperty(value = "下单时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
private Date orderTime;
@Column(name = "pay_time")
@ApiModelProperty(value = "支付时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = DatePattern.NORM_DATETIME_PATTERN, timezone = "GMT+8")
private Date payTime;
@Column(name = "days")
@ApiModelProperty(value = "套餐天数")
private Integer days;
@Column(name = "amount")
@ApiModelProperty(value = "金额")
private Double amount;
@Column(name = "nick_name")
@ApiModelProperty(value = "子账号nick")
private String nickName;
@Column(name = "master_user_id")
@ApiModelProperty(value = "主账号用户id")
private Long masterUserId;
}

@ -0,0 +1,20 @@
package com.hchbox.vo;
import lombok.Data;
import java.util.Date;
/**
* @author wujingtao
* @date 2021/10/25
*/
@Data
public class SubAccountsVo {
private String nickname;
private Integer status;
private Date authorizeStartTime;
private Date authorizeEndTime;
private Integer authorizeDay;
}

@ -0,0 +1,15 @@
package com.hchbox.vo;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
@Data
public class UpdateAccountsVo {
@NotNull
private BigDecimal accountBalance;
@NotNull
private Long id;
}

@ -4,55 +4,58 @@ import lombok.Getter;
/** /**
* @author q * @author q
*
*/ */
@Getter @Getter
public enum ResponseCode { public enum ResponseCode {
/**成功*/ /**
SUCCESS("1","成功"), *
*/
SUCCESS("1", "成功"),
UPDATE_ERROR("1015","修改失败"), UPDATE_ERROR("1015", "修改失败"),
PARAMETER_ERROR("1012","参数错误"), PARAMETER_ERROR("1012", "参数错误"),
PAYMENT_FAILED("1002","支付宝,下单失败"), PAYMENT_FAILED("1002", "支付宝,下单失败"),
CALLBACK_FAILED("1003","支付宝,回调失败"), CALLBACK_FAILED("1003", "支付宝,回调失败"),
DECRYPTION_FAILED("1012", "数据解析失败"), DECRYPTION_FAILED("1012", "数据解析失败"),
LOGIN_FAILED("1001","登录失败,请稍后重试"), LOGIN_FAILED("1001", "登录失败,请稍后重试"),
SAVE_INFORMATION_FAILED("1004", "保存信息失败"), SAVE_INFORMATION_FAILED("1004", "保存信息失败"),
USER_INFORMATION_EXPIRED("27","用户登录已经失效"), USER_INFORMATION_EXPIRED("27", "用户登录已经失效"),
TEMPLATE_NAME_CANNOT_BE_EMPTY("1014","模板不能为空"), TEMPLATE_NAME_CANNOT_BE_EMPTY("1014", "模板不能为空"),
ACCOUNT_HAS_EXPIRED("1005", "当前账号旺旺群发已过期"), ACCOUNT_HAS_EXPIRED("1005", "当前账号旺旺群发已过期"),
LEVEL_VERIFICATION_FAILED("1006","不同等级套餐无法直接续费"), LEVEL_VERIFICATION_FAILED("1006", "不同等级套餐无法直接续费"),
UPLOAD_INFORMATION_CANNOT_BE_EMPTY("1009","上传信息不能为空"), UPLOAD_INFORMATION_CANNOT_BE_EMPTY("1009", "上传信息不能为空"),
ACCOUNT_VERIFICATION_FAILED("1007","账号验证失败,请核实后提交"), ACCOUNT_VERIFICATION_FAILED("1007", "账号验证失败,请核实后提交"),
FILE_NAME_ALREADY_EXISTS("1008","文件名已存在,请核实后重新上传"), FILE_NAME_ALREADY_EXISTS("1008", "文件名已存在,请核实后重新上传"),
ACCOUNT_DOES_NOT_YET_HAVE_STORE("1011","该账号尚未拥有店铺,请申请后重试"), ACCOUNT_DOES_NOT_YET_HAVE_STORE("1011", "该账号尚未拥有店铺,请申请后重试"),
ACCOUNT_HAS_NOT_BEEN_OPENED_YET("1013","该账号尚未订购信息,请订购后重试"), ACCOUNT_HAS_NOT_BEEN_OPENED_YET("1013", "该账号尚未订购信息,请订购后重试"),
EXCEEDED_QUANTITY("1010", "提交任务数量超过当日限额,您可以订购提额包或升级套餐"), EXCEEDED_QUANTITY("1010", "提交任务数量超过当日限额,您可以订购提额包或升级套餐"),
; REQUEST_FAIL("500", "请求子账号列表失败"),
SESSION_EXPIRED("402", "session过期");
private final String code; private final String code;
private final String desc; private final String desc;
ResponseCode(String code, String desc){ ResponseCode(String code, String desc) {
this.code = code; this.code = code;
this.desc = desc; this.desc = desc;
} }

Loading…
Cancel
Save