...
|
...
|
@@ -5,11 +5,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.yoho.core.config.ConfigReader;
|
|
|
import com.yoho.core.rabbitmq.YhProducer;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yoho.service.model.union.bo.ShareOrderBo;
|
|
|
import com.yoho.service.model.union.bo.ShareSettlementBo;
|
|
|
import com.yoho.service.model.union.bo.ShareUserSettlementInfoBo;
|
|
|
import com.yoho.service.model.union.bo.UnionShareOrderSearchBo;
|
|
|
import com.yoho.service.model.union.request.UnionOrderReqBO;
|
|
|
import com.yoho.service.model.union.bo.*;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderReqBO;
|
|
|
import com.yoho.service.model.union.request.UnionShareOrderSearchReqBO;
|
|
|
import com.yoho.service.model.union.response.PageUnionShareOrderRspBO;
|
...
|
...
|
@@ -22,6 +18,8 @@ import com.yoho.unions.common.redis.RedisValueCache; |
|
|
import com.yoho.unions.common.service.IBusinessExportService;
|
|
|
import com.yoho.unions.common.utils.DateUtil;
|
|
|
import com.yoho.unions.common.utils.RandomUtil;
|
|
|
import com.yoho.unions.convert.BeanConvert;
|
|
|
import com.yoho.unions.convert.Convert;
|
|
|
import com.yoho.unions.dal.*;
|
|
|
import com.yoho.unions.dal.model.*;
|
|
|
import com.yoho.unions.server.service.IUnionShareService;
|
...
|
...
|
@@ -30,6 +28,7 @@ import org.apache.commons.lang3.StringUtils; |
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
...
|
...
|
@@ -39,6 +38,7 @@ import java.util.*; |
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 联盟红人推广返利
|
|
|
* Created by mingdan.ge on 2018/5/10.
|
...
|
...
|
@@ -69,6 +69,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
|
|
|
private AtomicInteger atomicInt = new AtomicInteger(0);
|
|
|
|
|
|
private Convert convert = new BeanConvert();
|
|
|
|
|
|
private String SETTLEMENT_TOPIC = "front.union.shareSettleAdd";
|
|
|
private String NEW_USER_REBATES_RATIO_KEY = "union.newUserRebatesRatio";
|
|
|
private String OLD_USER_REBATES_RATIO_KEY = "union.oldUserRebatesRatio";
|
...
|
...
|
@@ -94,7 +96,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
result.setCanSettlement(canSettlement);
|
|
|
result.setHistorySettlementAmount(historySettlementAmount);
|
|
|
result.setSettlementAmount(settlementAmount);
|
|
|
logger.info("getUserSettleMentInfo enter,uid is {},result is {}",uid,result);
|
|
|
logger.info("getUserSettleMentInfo end,uid is {},result is {}",uid,result);
|
|
|
return result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -205,6 +207,68 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
return userOrderDatailBOMap;
|
|
|
}
|
|
|
/**
|
|
|
* 用户登录时获取对应的渠道号
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public UnionShareUser queryUnionTypeByUid(int uid) {
|
|
|
//先从缓存获取
|
|
|
String key = "unionType";
|
|
|
UnionShareUser cacheResult = getFromRedis(ShareOrdersKeyEnum.UNION_TYPE, uid, UnionShareUser.class, key);
|
|
|
if (cacheResult != null) {
|
|
|
logger.info("UnionShareServiceImpl :: queryUnionTypeByUid get redis cache ,uid is {},cacheResult is {}",uid,cacheResult);
|
|
|
return cacheResult;
|
|
|
}
|
|
|
//获取数据库
|
|
|
UnionShareUser unionShareUser = unionShareUserMapper.selectByUid(uid);
|
|
|
//设置返回文案
|
|
|
unionShareUser.setNote("邀请新客购买返点" + configReader.getDouble(NEW_USER_REBATES_RATIO_KEY, 0.1) + ",老客" + configReader.getDouble(OLD_USER_REBATES_RATIO_KEY, 0.03));
|
|
|
//设置缓存
|
|
|
addToRedis(ShareOrdersKeyEnum.UNION_TYPE, uid, unionShareUser, key);
|
|
|
return unionShareUser;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 用户前台获取个人推广近期订单(10个)
|
|
|
* @param uid
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public UnionShareOrders queryRecentlyOrderLimitTen(int uid) {
|
|
|
UnionShareOrders unionShareOrders = unionShareOrdersMapper.selectRecentlyOrderLimitTen(uid);
|
|
|
return unionShareOrders;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ShareOrderBo queryOrderDetail(String orderCode) {
|
|
|
UnionShareOrders unionShareOrders = unionShareOrdersMapper.selectByCode(orderCode);
|
|
|
if (null == unionShareOrders){
|
|
|
return null;
|
|
|
}
|
|
|
List<UnionShareOrdersProduct> unionShareOrdersProductlist = unionShareOrdersProductMapper.selectOrdersProductByOrderCode(orderCode);
|
|
|
List<ShareOrdersProductBo> shareOrdersProductBoList = convert.convertFromList(unionShareOrdersProductlist, ShareOrdersProductBo.class);
|
|
|
ShareOrderBo shareOrderBo = new ShareOrderBo();
|
|
|
shareOrderBo = convert.convertFrom(unionShareOrders,shareOrderBo,ShareOrderBo.class);
|
|
|
shareOrderBo.setIsNew(unionShareOrders.getIsNew().toString());
|
|
|
shareOrderBo.setProductList(shareOrdersProductBoList);
|
|
|
return shareOrderBo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UnionShareSettlement> querySettlementRecord(int uid, Integer start, Integer size) {
|
|
|
List<UnionShareSettlement> unionShareSettlement = unionShareSettlementMapper.selectSettlementRecordByUid(uid, start, size);
|
|
|
return unionShareSettlement;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<UnionShareOrders> queryOrderList(UnionShareOrderReqBO unionShareOrderReqBO) {
|
|
|
//tab1表示1、全部订单;2、有效订单;3、无效订单 tab2表示1、已付款;2、待结算;3、结算中
|
|
|
List<UnionShareOrders> unionShareOrdersList = unionShareOrdersMapper.selectOrderList(unionShareOrderReqBO);
|
|
|
return unionShareOrdersList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单插入或更新
|
|
|
*/
|
|
|
@Override
|
...
|
...
|
@@ -227,18 +291,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
//判断是否可以进行状态变更
|
|
|
if (!checkOrderStatusChangePass(unionShareOrders.getStatus(), bo.getStatus())) {
|
|
|
//订单状态不可变更
|
|
|
logger.info("saveOrUpdateOrder end,status can not be change,oldStatus is {} ,req is {}",unionShareOrders.getStatus(),bo);
|
|
|
return;
|
|
|
}
|
|
|
int result = unionShareOrdersMapper.updateStatusById(unionShareOrders.getId(), unionShareOrders.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
|
|
|
if (result == 0) {
|
|
|
logger.info("saveOrUpdateOrder enter,update nothing,req is {}",bo);
|
|
|
//没有更新到数据,应该有并发更新事件,查询新的再试一下
|
|
|
UnionShareOrders unionShareOrdersNew = unionShareOrdersMapper.selectByCode(bo.getOrderCode());
|
|
|
if (unionShareOrdersNew == null) {
|
|
|
logger.info("saveOrUpdateOrder end,can not find the orderCode,req is {}",bo);
|
|
|
//查不到数据,不该出现的情况,目前没有硬删数据的途径
|
|
|
return;
|
|
|
}
|
|
|
if (!checkOrderStatusChangePass(unionShareOrdersNew.getStatus(), bo.getStatus())) {
|
|
|
//订单状态不可变更
|
|
|
logger.info("saveOrUpdateOrder end,Second try,status can not be change,oldStatus is {} ,req is {}",unionShareOrdersNew.getStatus(),bo);
|
|
|
return;
|
|
|
}
|
|
|
unionShareOrdersMapper.updateStatusById(unionShareOrdersNew.getId(), unionShareOrdersNew.getStatus(), bo.getStatus(), DateUtil.getCurrentTimeSecond());
|
...
|
...
|
@@ -254,13 +322,15 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
logger.info("insertOrder,req is {}",bo);
|
|
|
//检查参数
|
|
|
if (!checkParam(bo)) {
|
|
|
//缺少参数 todo logger
|
|
|
//缺少参数
|
|
|
logger.warn("insertOrder end,param is invaild,req is {}",bo);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//检查状态
|
|
|
if (!canInsertStatus(bo.getStatus())) {
|
|
|
//该状态数据不可插入 todo logger
|
|
|
//该状态数据不可插入
|
|
|
logger.warn("insertOrder end,status can not be change,req is {}",bo);
|
|
|
return;
|
|
|
}
|
|
|
//新增订单信息
|
...
|
...
|
@@ -286,10 +356,14 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
unionShareOrdersMapper.insertSelective(insertReq);
|
|
|
//新增订单商品信息
|
|
|
bo.getProductList().forEach(p->{
|
|
|
UnionShareOrdersProduct insertPro = new UnionShareOrdersProduct();
|
|
|
BeanUtils.copyProperties(p, insertPro);
|
|
|
insertPro.setOrderCode(bo.getOrderCode());
|
|
|
unionShareOrdersProductMapper.insertSelective(insertPro);
|
|
|
try {
|
|
|
UnionShareOrdersProduct insertPro = new UnionShareOrdersProduct();
|
|
|
BeanUtils.copyProperties(p, insertPro);
|
|
|
insertPro.setOrderCode(bo.getOrderCode());
|
|
|
unionShareOrdersProductMapper.insertSelective(insertPro);
|
|
|
} catch (BeansException e) {
|
|
|
logger.info("insertOrder product error,orderCode is {},product is {}",bo.getOrderCode(), p);
|
|
|
}
|
|
|
});
|
|
|
logger.info("insertOrder end,req is {}",bo);
|
|
|
}
|
...
|
...
|
@@ -340,11 +414,13 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int count = unionShareUserMapper.selectCountByUid(uid);
|
|
|
if (count == 0) {
|
|
|
//不是特邀用户
|
|
|
logger.info("addSettlement end,can not find unionType,uid is {}",uid);
|
|
|
return null;
|
|
|
}
|
|
|
//查询是否有处理中的提现
|
|
|
if (hasSettlement(uid)) {
|
|
|
//有处理中的提现单,不可提现
|
|
|
logger.info("addSettlement end,hasSettlement,uid is {}",uid);
|
|
|
return null;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -352,10 +428,12 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
int orderCount = unionShareOrdersMapper.selectCountByCondition(uid,ShareOrdersStatusEnum.CAN_SETTLE.getCode());
|
|
|
if (orderCount == 0 ) {
|
|
|
//没有可以提现的订单
|
|
|
logger.info("addSettlement end,has not remaining settlement,uid is {}",uid);
|
|
|
return null;
|
|
|
}
|
|
|
//todo 生成取现单,绑定订单,考虑是否异步操作
|
|
|
BigDecimal amount = relateSettlementAndOrder(uid);
|
|
|
logger.info("addSettlement end,remaining settlement is {},uid is {}",amount,uid);
|
|
|
return amount;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -407,7 +485,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
return cacheResult;
|
|
|
}
|
|
|
int count = unionShareSettlementMapper.selectCountByUid(uid,(byte) 1);//是否打款成功:1-处理中,2-已打款
|
|
|
logger.info("hasSettlement ,uid is {},result is {},count is {}",uid,count);
|
|
|
logger.info("hasSettlement ,uid is {},count is {}",uid,count);
|
|
|
if (count > 0) {
|
|
|
addToRedis(ShareOrdersKeyEnum.USER_SETTLEMENT,uid,true,type);
|
|
|
return true;
|
...
|
...
|
@@ -444,17 +522,22 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
* */
|
|
|
public BigDecimal relateSettlementAndOrder(int uid) {
|
|
|
|
|
|
logger.info("relateSettlementAndOrder enter,uid is {}",uid);
|
|
|
|
|
|
//生成提现编号
|
|
|
String settlementCode = createSettlementCode();
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {}",uid,settlementCode);
|
|
|
|
|
|
//更新订单状态,由可结算变为打款中
|
|
|
int updateTime = DateUtil.getCurrentTimeSecond();
|
|
|
int count=unionShareOrdersMapper.updateStatusByUid(uid,settlementCode, ShareOrdersStatusEnum.CAN_SETTLE.getCode(), ShareOrdersStatusEnum.SETTLE.getCode(), updateTime);
|
|
|
if (count == 0) {
|
|
|
logger.info("relateSettlementAndOrder end,uid is {},settlementCode is {},There are no available orders.",uid,settlementCode);
|
|
|
return null;
|
|
|
}
|
|
|
//计算提现金额
|
|
|
BigDecimal totalAmount=unionShareOrdersMapper.selectAmountBySettleCode(uid, settlementCode);
|
|
|
logger.info("relateSettlementAndOrder,uid is {},settlementCode is {},totalAmount is {}",uid,settlementCode,totalAmount);
|
|
|
|
|
|
//生成提现单
|
|
|
UnionShareSettlement insertReq = new UnionShareSettlement();
|
...
|
...
|
@@ -466,7 +549,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
insertReq.setStatus((byte)1);//是否打款成功:1-处理中,2-已打款
|
|
|
int num=unionShareSettlementMapper.insertSelective(insertReq);
|
|
|
if (num < 1) {
|
|
|
//todo 插入失败
|
|
|
//插入失败
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},insert nothing.",uid,settlementCode,totalAmount);
|
|
|
}
|
|
|
|
|
|
Set<String> orderCodes = new HashSet<>();
|
...
|
...
|
@@ -481,6 +565,8 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
orderCodes.addAll(periodOrders);
|
|
|
}
|
|
|
if (orderCodes.size() == 0) {
|
|
|
//不该查不到订单
|
|
|
logger.warn("relateSettlementAndOrder end,uid is {},settlementCode is {},totalAmount is {},can not find orders.",uid,settlementCode,totalAmount);
|
|
|
return null;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -492,6 +578,7 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
ShareSettlementBo bo = new ShareSettlementBo();
|
|
|
BeanUtils.copyProperties(insertReq,bo);
|
|
|
bo.setOrderCodes(orderCodes);
|
|
|
logger.info("relateSettlementAndOrder,send mq {} to erp,uid is {},settlementCode is {},bo is {}", SETTLEMENT_TOPIC, uid, settlementCode, bo);
|
|
|
yhProducer.send(SETTLEMENT_TOPIC, bo);
|
|
|
return totalAmount;
|
|
|
}
|
...
|
...
|
@@ -584,6 +671,6 @@ public class UnionShareServiceImpl implements IUnionShareService,IBusinessExport |
|
|
}
|
|
|
ordersDOMap=this.unionShareOrdersMapper.selectAllListByUids(bo.getBeginTime(), bo.getEndTime(), uids, bo.getOrderCode());
|
|
|
}
|
|
|
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
|
|
|
return ordersDOMap.isEmpty()?null:queryUnionShareOrderRsp(ordersDOMap);
|
|
|
}
|
|
|
} |
...
|
...
|
|