|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.hfkj.service.order.Impl; |
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
|
import com.hfkj.common.exception.ErrorCode; |
|
|
|
|
import com.hfkj.common.exception.ErrorHelp; |
|
|
|
@ -15,6 +16,7 @@ import com.hfkj.entity.BsOrderExample; |
|
|
|
|
import com.hfkj.entity.BsUser; |
|
|
|
|
import com.hfkj.model.BsOrderModel; |
|
|
|
|
import com.hfkj.model.UserTeamModel; |
|
|
|
|
import com.hfkj.service.meituan.MeiTuanService; |
|
|
|
|
import com.hfkj.service.order.BsOrderService; |
|
|
|
|
import com.hfkj.service.order.OrderBusinessService; |
|
|
|
|
import com.hfkj.service.pdd.PddService; |
|
|
|
@ -150,8 +152,14 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void getOrderPddList(String startTime) throws Exception{ |
|
|
|
|
pddOrder(startTime); |
|
|
|
|
public void getOrderPddList(String startTime , String endTime) { |
|
|
|
|
try { |
|
|
|
|
pddOrder(startTime , endTime); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@ -164,6 +172,15 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void getOrderMeiTuanList(String startTime, String endTime) { |
|
|
|
|
try { |
|
|
|
|
meiTuanOrder(startTime , endTime); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println(e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public List<BsOrderModel> getOrderListParent(Map<String, Object> map) { |
|
|
|
|
|
|
|
|
@ -188,9 +205,18 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
orderModel.setGold(order.getPromotionAmount().multiply(goldCoinExchangeRate)); |
|
|
|
|
// 将订单模型添加到订单模型列表中
|
|
|
|
|
orderModels.add(orderModel); |
|
|
|
|
// 根据订单查询淘宝订单
|
|
|
|
|
getOrderTaoBaoList(DateUtil.format( new Date(new Date().getTime() - 300000) , DateUtil.Y_M_D_HMS) , DateUtil.format( new Date(new Date().getTime() + 300000) , DateUtil.Y_M_D_HMS)); |
|
|
|
|
if (order.getType() == 1) { |
|
|
|
|
// 根据订单查询淘宝订单
|
|
|
|
|
getOrderTaoBaoList(DateUtil.format( new Date(new Date().getTime() - 300000) , DateUtil.Y_M_D_HMS) , DateUtil.format( new Date(new Date().getTime() + 300000) , DateUtil.Y_M_D_HMS)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (order.getType() == 2) { |
|
|
|
|
// 根据订单查询拼多多订单
|
|
|
|
|
getOrderPddList(DateUtil.format( new Date(new Date().getTime() - 300000) , DateUtil.Y_M_D_HMS) , DateUtil.format( new Date(new Date().getTime() + 300000) , DateUtil.Y_M_D_HMS)); |
|
|
|
|
} |
|
|
|
|
if (order.getType() == 3) { |
|
|
|
|
getOrderMeiTuanList( String.valueOf(new Date().getTime()/1000 - 300) , String.valueOf(new Date().getTime()/1000 + 300)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return orderModels; |
|
|
|
|
} |
|
|
|
@ -222,22 +248,28 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void orderRebate(BsOrder bsOrder) throws Exception { |
|
|
|
|
Map<String,Object> otherParam = new HashMap<>(); |
|
|
|
|
otherParam.put("sourceId", bsOrder.getId()); |
|
|
|
|
otherParam.put("sourceOrderNo", bsOrder.getOrderNo()); |
|
|
|
|
userContributeService.purchase(bsOrder.getPromotionAmount(), bsOrder.getUserId(), otherParam); |
|
|
|
|
bsOrder.setStatus(8); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setFinishTime(new Date()); |
|
|
|
|
editData(bsOrder); |
|
|
|
|
public void orderRebate(BsOrder bsOrder){ |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
Map<String,Object> otherParam = new HashMap<>(); |
|
|
|
|
otherParam.put("sourceId", bsOrder.getId()); |
|
|
|
|
otherParam.put("sourceOrderNo", bsOrder.getOrderNo()); |
|
|
|
|
userContributeService.purchase(bsOrder.getPromotionAmount(), bsOrder.getUserId(), otherParam); |
|
|
|
|
bsOrder.setStatus(3); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setFinishTime(new Date()); |
|
|
|
|
editData(bsOrder); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 根据开始时间获取拼多多订单列表
|
|
|
|
|
private void pddOrder(String startTime) throws Exception{ |
|
|
|
|
private void pddOrder(String startTime , String endTime) throws Exception{ |
|
|
|
|
// 调用PddService的getOrderList方法获取订单列表
|
|
|
|
|
PddDdkOrderListRangeGetResponse rangeGetResponse = PddService.getOrderList(startTime); |
|
|
|
|
PddDdkOrderListRangeGetResponse rangeGetResponse = PddService.getOrderList(startTime , endTime); |
|
|
|
|
// 调用getOrderList方法获取本地订单列表
|
|
|
|
|
List<BsOrder> list = getOrderList(new HashMap<>()); |
|
|
|
|
List<BsUser> userList = userService.getList(new HashMap<>()); |
|
|
|
@ -281,7 +313,7 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
} |
|
|
|
|
bsOrder.setCreateTime(new Date()); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setStatus(orderListItem.getOrderStatus()); |
|
|
|
|
bsOrder.setStatus(pddStatus(Long.valueOf(orderListItem.getOrderStatus()))); |
|
|
|
|
bsOrder.setImg(orderListItem.getGoodsThumbnailUrl()); |
|
|
|
|
bsOrder.setType(2); |
|
|
|
|
bsOrder.setGoodsName(orderListItem.getGoodsName()); |
|
|
|
@ -308,7 +340,7 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
|
|
|
|
|
create(bsOrder); |
|
|
|
|
}else { |
|
|
|
|
if (bsOrder.getStatus() != 8) { |
|
|
|
|
if (bsOrder.getStatus() == 2) { |
|
|
|
|
// 如果BsOrder对象不为空,则更新BsOrder对象
|
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setStatus(orderListItem.getOrderStatus()); |
|
|
|
@ -339,7 +371,7 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 如果订单状态为5,则调用orderRebate方法
|
|
|
|
|
if (bsOrder.getStatus() == 5){ |
|
|
|
|
if (bsOrder.getStatus() == 2 && orderListItem.getOrderStatus().equals(5)){ |
|
|
|
|
orderRebate(bsOrder); |
|
|
|
|
} else { |
|
|
|
|
editData(bsOrder); |
|
|
|
@ -352,25 +384,31 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 淘宝
|
|
|
|
|
private void taoBaoOrder(String startTime , String endTime) throws Exception { |
|
|
|
|
// 调用TaoBaoService的getOrderList方法,获取淘宝订单列表
|
|
|
|
|
TaobaoTbkOrderDetailsGetResponse response = TaoBaoService.getOrderList(startTime , endTime); |
|
|
|
|
// 调用getOrderList方法,获取本地订单列表
|
|
|
|
|
List<BsOrder> list = getOrderList(new HashMap<>()); |
|
|
|
|
// 创建一个Map,用于存储relationId
|
|
|
|
|
Map<String , Object> reMap = new HashMap<>(); |
|
|
|
|
reMap.put("relationId" , 1); |
|
|
|
|
// 调用userService的getList方法,获取用户列表
|
|
|
|
|
List<BsUser> userList = userService.getList(reMap); |
|
|
|
|
|
|
|
|
|
// 获取淘宝订单列表中的订单信息
|
|
|
|
|
List<TaobaoTbkOrderDetailsGetPublisherOrderDto> results = response.getData().getResults(); |
|
|
|
|
if (results != null && !results.isEmpty()) { |
|
|
|
|
for (TaobaoTbkOrderDetailsGetPublisherOrderDto orderListItem : results) { |
|
|
|
|
|
|
|
|
|
// 根据订单号,从本地订单列表中查找订单
|
|
|
|
|
BsOrder bsOrder = list.stream().filter(s->s.getOrderNo().equals(orderListItem.getTradeParentId())).findFirst().orElse(null); |
|
|
|
|
// 根据relationId,从用户列表中查找用户
|
|
|
|
|
BsUser bsUser = userList.stream().filter(s->s.getRelationId().equals(orderListItem.getRelationId().toString())).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
// 如果本地订单列表中没有该订单,则创建一个新的订单
|
|
|
|
|
if (bsOrder == null) { |
|
|
|
|
bsOrder = new BsOrder(); |
|
|
|
|
bsOrder.setOrderNo(orderListItem.getTradeParentId()); |
|
|
|
@ -408,9 +446,11 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
if (orderListItem.getModifiedTime() != null) { |
|
|
|
|
bsOrder.setCancelTime(DateUtil.format(orderListItem.getModifiedTime() , "yyyy-MM-dd HH:mm:ss")); |
|
|
|
|
} |
|
|
|
|
// 调用create方法,将新订单保存到本地订单列表中
|
|
|
|
|
create(bsOrder); |
|
|
|
|
} else { |
|
|
|
|
if (bsOrder.getStatus() != 8) { |
|
|
|
|
// 如果本地订单列表中已有该订单,则更新订单信息
|
|
|
|
|
if (bsOrder.getStatus() == 2) { |
|
|
|
|
bsOrder.setOrderNo(orderListItem.getTradeParentId()); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setStatus(taoBaoStatus(orderListItem.getTkStatus())); |
|
|
|
@ -439,9 +479,10 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
bsOrder.setCancelTime(DateUtil.format(orderListItem.getModifiedTime() , "yyyy-MM-dd HH:mm:ss")); |
|
|
|
|
} |
|
|
|
|
// 如果订单状态为5,则调用orderRebate方法
|
|
|
|
|
if (bsOrder.getStatus() == 5){ |
|
|
|
|
if (bsOrder.getStatus() == 2 && orderListItem.getTkStatus() == 3){ |
|
|
|
|
orderRebate(bsOrder); |
|
|
|
|
} else { |
|
|
|
|
// 否则,调用editData方法,更新订单信息
|
|
|
|
|
editData(bsOrder); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -451,21 +492,154 @@ public class BsOrderServiceImpl implements BsOrderService { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void meiTuanOrder(String startTime , String endTime) throws Exception { |
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
|
jsonObject.put("startTime" , startTime); |
|
|
|
|
jsonObject.put("endTime" , endTime); |
|
|
|
|
JSONObject object = MeiTuanService.orderList(jsonObject); |
|
|
|
|
JSONArray meiTuanOrder = object.getJSONArray("dataList"); |
|
|
|
|
List<BsOrder> list = getOrderList(new HashMap<>()); |
|
|
|
|
List<BsUser> userList = userService.getList(new HashMap<>()); |
|
|
|
|
|
|
|
|
|
if (meiTuanOrder != null && !meiTuanOrder.isEmpty()) { |
|
|
|
|
for (int i = 0; i < meiTuanOrder.size(); i++) { |
|
|
|
|
JSONObject meiTuan = meiTuanOrder.getJSONObject(i); |
|
|
|
|
|
|
|
|
|
// 根据订单号,从本地订单列表中查找订单
|
|
|
|
|
BsOrder bsOrder = list.stream().filter(s->s.getOrderNo().equals(meiTuan.getString("orderid"))).findFirst().orElse(null); |
|
|
|
|
// 根据relationId,从用户列表中查找用户
|
|
|
|
|
BsUser bsUser = userList.stream().filter(s->s.getId().equals(meiTuan.getLong("sid"))).findFirst().orElse(null); |
|
|
|
|
|
|
|
|
|
// 如果本地订单列表中没有该订单,则创建一个新的订单
|
|
|
|
|
if (bsOrder == null) { |
|
|
|
|
bsOrder = new BsOrder(); |
|
|
|
|
bsOrder.setOrderNo(meiTuan.getString("orderid")); |
|
|
|
|
if (bsUser != null) { |
|
|
|
|
bsOrder.setUserId(bsUser.getId()); |
|
|
|
|
bsOrder.setUserPhone(bsUser.getPhone() == null ? "" : bsUser.getPhone()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bsOrder.setCreateTime(new Date()); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setStatus(meiTuanStatus(meiTuan.getLong("status"))); |
|
|
|
|
bsOrder.setType(3); |
|
|
|
|
bsOrder.setGoodsName(meiTuan.getString("smstitle")); |
|
|
|
|
bsOrder.setGoodsCount(1); |
|
|
|
|
bsOrder.setTotalPrice(meiTuan.getBigDecimal("payprice")); |
|
|
|
|
bsOrder.setPromotionAmount(meiTuan.getBigDecimal("profit")); |
|
|
|
|
|
|
|
|
|
if (meiTuan.getLong("paytime") != null) { |
|
|
|
|
bsOrder.setPayTime(DateUtil.long2Date(meiTuan.getLong("paytime")*1000)); |
|
|
|
|
bsOrder.setCreateTime(DateUtil.long2Date(meiTuan.getLong("paytime")*1000)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (meiTuan.getLong("modTime") != null) { |
|
|
|
|
bsOrder.setFinishTime(DateUtil.long2Date(meiTuan.getLong("modTime")*1000)); |
|
|
|
|
} |
|
|
|
|
if (meiTuan.getLong("refundtime") != null) { |
|
|
|
|
bsOrder.setRefundTime(DateUtil.long2Date(meiTuan.getLong("refundtime")*1000)); |
|
|
|
|
bsOrder.setCancelTime(DateUtil.long2Date(meiTuan.getLong("refundtime")*1000)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 调用create方法,将新订单保存到本地订单列表中
|
|
|
|
|
create(bsOrder); |
|
|
|
|
} else { |
|
|
|
|
// 如果本地订单列表中已有该订单,则更新订单信息
|
|
|
|
|
if (bsOrder.getStatus() == 2) { |
|
|
|
|
bsOrder.setOrderNo(meiTuan.getString("orderid")); |
|
|
|
|
if (bsUser != null) { |
|
|
|
|
bsOrder.setUserId(bsUser.getId()); |
|
|
|
|
bsOrder.setUserPhone(bsUser.getPhone() == null ? "" : bsUser.getPhone()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bsOrder.setCreateTime(new Date()); |
|
|
|
|
bsOrder.setUpdateTime(new Date()); |
|
|
|
|
bsOrder.setStatus(meiTuanStatus(meiTuan.getLong("status"))); |
|
|
|
|
bsOrder.setType(3); |
|
|
|
|
bsOrder.setGoodsName(meiTuan.getString("smstitle")); |
|
|
|
|
bsOrder.setGoodsCount(1); |
|
|
|
|
bsOrder.setTotalPrice(meiTuan.getBigDecimal("payprice")); |
|
|
|
|
bsOrder.setPromotionAmount(meiTuan.getBigDecimal("profit")); |
|
|
|
|
|
|
|
|
|
if (meiTuan.getLong("paytime") != null) { |
|
|
|
|
bsOrder.setPayTime(DateUtil.long2Date(meiTuan.getLong("paytime")*1000)); |
|
|
|
|
bsOrder.setCreateTime(DateUtil.long2Date(meiTuan.getLong("paytime")*1000)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (meiTuan.getLong("modTime") != null) { |
|
|
|
|
bsOrder.setFinishTime(DateUtil.long2Date(meiTuan.getLong("modTime")*1000)); |
|
|
|
|
} |
|
|
|
|
if (meiTuan.getLong("refundtime") != null) { |
|
|
|
|
bsOrder.setRefundTime(DateUtil.long2Date(meiTuan.getLong("refundtime")*1000)); |
|
|
|
|
bsOrder.setCancelTime(DateUtil.long2Date(meiTuan.getLong("refundtime")*1000)); |
|
|
|
|
} |
|
|
|
|
// 如果订单状态为5,则调用orderRebate方法
|
|
|
|
|
if (bsOrder.getStatus() == 2 && meiTuan.getInteger("status") == 8){ |
|
|
|
|
orderRebate(bsOrder); |
|
|
|
|
} else { |
|
|
|
|
// 否则,调用editData方法,更新订单信息
|
|
|
|
|
editData(bsOrder); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Integer pddStatus(Long status) { |
|
|
|
|
int result = 4; |
|
|
|
|
if (status == 0) { |
|
|
|
|
result = 1; |
|
|
|
|
} else if (status == 1) { |
|
|
|
|
result = 1; |
|
|
|
|
} else if (status == 2) { |
|
|
|
|
result = 2; |
|
|
|
|
} else if (status == 3) { |
|
|
|
|
result = 2; |
|
|
|
|
} else if (status == 4) { |
|
|
|
|
result = 4; |
|
|
|
|
} else if (status == 5) { |
|
|
|
|
result = 2; |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1 已下单 2 已收货 3 已结算 4 已失效
|
|
|
|
|
private Integer taoBaoStatus(Long status) { |
|
|
|
|
int result = 6; |
|
|
|
|
int result = 4; |
|
|
|
|
if (status == 3) { |
|
|
|
|
result = 3; |
|
|
|
|
result = 2; |
|
|
|
|
} else if (status == 12) { |
|
|
|
|
result = 0; |
|
|
|
|
result = 1; |
|
|
|
|
} else if (status == 13) { |
|
|
|
|
result = 4; |
|
|
|
|
} else if (status == 14) { |
|
|
|
|
result = 2; |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Integer meiTuanStatus(Long status) { |
|
|
|
|
int result = 4; |
|
|
|
|
if (status == 1) { |
|
|
|
|
result = 1; |
|
|
|
|
} else if (status == 8) { |
|
|
|
|
result = 2; |
|
|
|
|
} else if (status == 9) { |
|
|
|
|
result = 4; |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|