Authored by zhaoqing

Merge branch 'dev_180508_联盟红人推广' of http://git.yoho.cn/yoho30/yohobuy-union into dev_180508_联盟红人推广

Conflicts:
	server/src/main/java/com/yoho/unions/server/restapi/UnionShareRest.java
... ... @@ -77,6 +77,7 @@
<value>/UnionClickCountDayRest/count</value>
<value>/UnionShareRest/getShareInfoByUid</value>
<value>/UnionShareRest/addSettlement</value>
<value>/UnionShareRest/queryUnionShareOrder</value>
</list>
</property>
... ...
... ... @@ -7,6 +7,8 @@ public class UnionShareOrders {
private String orderCode;
private String settlementCode;
private Integer promoteUid;
private String status;
... ... @@ -102,4 +104,12 @@ public class UnionShareOrders {
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public String getSettlementCode() {
return settlementCode;
}
public void setSettlementCode(String settlementCode) {
this.settlementCode = settlementCode;
}
}
\ No newline at end of file
... ...
... ... @@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by mingdan.ge on 2018/5/10.
*/
... ... @@ -27,9 +29,12 @@ public class UnionSettleUpdateConsumer implements YhConsumer {
if (null == o) {
return;
}
ShareSettlementBo bo = JsonUtil.jsonToObject(o.toString(), ShareSettlementBo.class);
//TODO 提现结算单状态变更
unionShareService.updateSettlementStatus(bo);
List<Object> list = JsonUtil.jsonToObject(o.toString(), List.class);
list.forEach(l->{
ShareSettlementBo bo = JsonUtil.jsonToObject(l.toString(), ShareSettlementBo.class);
//TODO 提现结算单状态变更
unionShareService.updateSettlementStatus(bo);
});
} catch (Exception e) {
logger.warn("UnionSettleUpdateConsumer,handleMessage fail! obj is {}, e {}",o,e.getMessage());
... ...
... ... @@ -9,6 +9,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* Created by mingdan.ge on 2018/5/10.
*/
... ... @@ -28,10 +30,12 @@ public class UnionShareOrderConsumer implements YhConsumer {
return;
}
ShareOrderBo bo = JsonUtil.jsonToObject(o.toString(), ShareOrderBo.class);
//TODO 订单插入或更新
unionShareService.saveOrUpdateOrder(bo);
List<Object> list = JsonUtil.jsonToObject(o.toString(), List.class);
list.forEach(l->{
ShareOrderBo bo = JsonUtil.jsonToObject(l.toString(), ShareOrderBo.class);
//TODO 订单插入或更新
unionShareService.saveOrUpdateOrder(bo);
});
} catch (Exception e) {
logger.warn("UnionShareOrderConsumer,handleMessage fail! obj is {}, e {}",o,e.getMessage());
}
... ...
... ... @@ -12,9 +12,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.math.BigDecimal;
import java.util.List;
/**
... ... @@ -32,18 +34,18 @@ public class UnionShareRest {
@RequestMapping("/getShareInfoByUid")
@ResponseBody
public UnionResponse getShareInfoByUid(int uid){
public ShareUserSettlementInfoBo getShareInfoByUid(@RequestBody int uid){
log.info("getShareInfoByUid,uid is {}",uid);
ShareUserSettlementInfoBo result = unionShareService.getUserSettleMentInfo(uid);
return new UnionResponse(200, "getShareInfoByUid success", result);
return result;
}
@RequestMapping("/addSettlement")
@ResponseBody
public UnionResponse addSettlement(int uid){
public UnionResponse addSettlement(@RequestBody int uid){
log.info("addSettlement,uid is {}",uid);
unionShareService.addSettlement(uid);
return new UnionResponse(200, "addSettlement success", null);
BigDecimal result = unionShareService.addSettlement(uid);
return new UnionResponse(200, "addSettlement success", result);
}
/**
... ...
... ... @@ -10,6 +10,8 @@ import com.yoho.unions.dal.model.UnionShareUser;
import java.util.List;
import java.math.BigDecimal;
/**
* 联盟红人推广返利
* Created by mingdan.ge on 2018/5/10.
... ... @@ -29,7 +31,7 @@ public interface IUnionShareService {
/**
* 提现
*/
void addSettlement(Integer uid);
BigDecimal addSettlement(Integer uid);
/**
* 获取用户可提现金额、已提现金额、是否可以提现
... ...
... ... @@ -239,6 +239,7 @@ public class UnionShareServiceImpl implements IUnionShareService {
bo.getProductList().forEach(p->{
UnionShareOrdersProduct insertPro = new UnionShareOrdersProduct();
BeanUtils.copyProperties(p, insertPro);
insertPro.setOrderCode(bo.getOrderCode());
unionShareOrdersProductMapper.insertSelective(insertPro);
});
logger.info("insertOrder end,req is {}",bo);
... ... @@ -281,32 +282,32 @@ public class UnionShareServiceImpl implements IUnionShareService {
* 提现
*/
@Override
public void addSettlement(Integer uid) {
public BigDecimal addSettlement(Integer uid) {
logger.info("addSettlement enter,uid is {}",uid);
if (uid == null ) {
return;
return null;
}
//查询该用户是否为特邀用户
int count = unionShareUserMapper.selectCountByUid(uid);
if (count == 0) {
//不是特邀用户
return;
return null;
}
//查询是否有处理中的提现
if (hasSettlement(uid)) {
//有处理中的提现单,不可提现
return;
return null;
}
//查询当前是否有可提现的订单
int orderCount = unionShareOrdersMapper.selectCountByCondition(uid,ShareOrdersStatusEnum.CAN_SETTLE.getCode());
if (orderCount == 0 ) {
//没有可以提现的订单
return;
return null;
}
//todo 生成取现单,绑定订单,考虑是否异步操作
relateSettlementAndOrder(uid);
BigDecimal amount = relateSettlementAndOrder(uid);
return amount;
}
/**
... ... @@ -392,7 +393,7 @@ public class UnionShareServiceImpl implements IUnionShareService {
/**
* 提现关联订单
* */
public void relateSettlementAndOrder(int uid) {
public BigDecimal relateSettlementAndOrder(int uid) {
//生成提现编号
String settlementCode = createSettlementCode();
... ... @@ -401,7 +402,7 @@ public class UnionShareServiceImpl implements IUnionShareService {
int updateTime = DateUtil.getCurrentTimeSecond();
int count=unionShareOrdersMapper.updateStatusByUid(uid,settlementCode, ShareOrdersStatusEnum.CAN_SETTLE.getCode(), ShareOrdersStatusEnum.SETTLE.getCode(), updateTime);
if (count == 0) {
return;
return null;
}
//计算提现金额
BigDecimal totalAmount=unionShareOrdersMapper.selectAmountBySettleCode(uid, settlementCode);
... ... @@ -431,7 +432,7 @@ public class UnionShareServiceImpl implements IUnionShareService {
orderCodes.addAll(periodOrders);
}
if (orderCodes.size() == 0) {
return;
return null;
}
... ... @@ -443,6 +444,7 @@ public class UnionShareServiceImpl implements IUnionShareService {
BeanUtils.copyProperties(insertReq,bo);
bo.setOrderCodes(orderCodes);
yhProducer.send(SETTLEMENT_TOPIC, bo);
return totalAmount;
}
/**
... ...