Toggle navigation
Toggle navigation
This project
Loading...
Sign in
YOHOBUY
/
yohobuy-union
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
zhengwen.ge
8 years ago
Commit
e7820cf87f182ed928947b3b97d3f32c51582380
1 parent
9044fba2
update
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
146 deletions
server/src/main/java/com/yoho/unions/server/service/impl/DuomaiServiceImpl.java
server/src/main/java/com/yoho/unions/server/service/impl/OrderPushServiceImpl.java
server/src/main/java/com/yoho/unions/server/service/impl/DuomaiServiceImpl.java
View file @
e7820cf
package
com
.
yoho
.
unions
.
server
.
service
.
impl
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yoho.unions.common.utils.HttpUtils
;
import
com.yoho.unions.common.utils.MathUtils
;
import
com.yoho.unions.dal.IUserOrdersDAO
;
import
com.yoho.unions.server.service.IOrderPushService
;
import
com.yoho.unions.vo.OrderInfo
;
import
com.yoho.unions.vo.OrdersGood
;
import
net.spy.memcached.compat.log.Logger
;
import
net.spy.memcached.compat.log.LoggerFactory
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.math.BigDecimal
;
import
java.net.URLEncoder
;
import
java.util.*
;
/**
* 多麦推送订单数据
* Created by yoho on 2016/12/15.
*/
public
class
DuomaiServiceImpl
implements
IOrderPushService
{
@Autowired
private
IUserOrdersDAO
userOrdersDAO
;
static
Logger
logger
=
LoggerFactory
.
getLogger
(
DuomaiServiceImpl
.
class
);
@Override
public
void
pushOrder
(
List
<
OrderInfo
>
orderInfoList
)
{
List
<
String
>
successCodes
=
new
ArrayList
<>();
String
duomaiContext
=
getDuomaiContext
(
orderInfoList
);
OrderInfo
orderInfo
=
orderInfoList
.
get
(
0
);
int
clientId
=
orderInfo
.
getClientId
();
String
duomaiPushUrl
=
null
;
if
(
clientId
==
3017
)
{
duomaiPushUrl
=
"http://www.duomai.com/api/push/yohobuy.php1"
;
}
else
if
(
clientId
==
3019
)
{
duomaiPushUrl
=
"http://www.duomai.com/api/push/myohobuy.php1"
;
}
else
{
duomaiPushUrl
=
"http://www.duomai.com/api/push/yohobuyroi.php1"
;
}
Pair
<
Integer
,
String
>
pair
=
null
;
Map
param
=
new
HashMap
<>();
param
.
put
(
"content"
,
duomaiContext
);
try
{
logger
.
info
(
"pushOrder: url is {}, param is {}"
,
duomaiPushUrl
,
param
);
pair
=
HttpUtils
.
httpPost
(
duomaiPushUrl
,
param
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"duomai order post fail,orderCode is {}"
,
orderInfo
.
getParentOrderCode
());
}
JSONObject
json
=
JSONObject
.
parseObject
(
pair
.
getRight
());
if
(((
String
)
json
.
get
(
"code"
)).
equals
(
"200"
))
{
logger
.
info
(
"duomai pushOrder success,orderCode is {}"
,
orderInfo
.
getParentOrderCode
());
successCodes
.
add
(
orderInfo
.
getParentOrderCode
());
}
else
{
logger
.
warn
(
"duomai pushOrder fail,orderCode is {},message is {}"
,
orderInfo
.
getParentOrderCode
(),
(
String
)
json
.
get
(
"msg"
));
}
//批量更新推送成功的订单状态为1
userOrdersDAO
.
batchUpdatePush
(
successCodes
);
}
private
String
getDuomaiContext
(
List
<
OrderInfo
>
orderInfoList
)
{
String
urlContext
=
null
;
for
(
OrderInfo
orderInfo
:
orderInfoList
)
{
//联盟id
int
client_id
=
orderInfo
.
getClientId
();
String
hash
=
""
;
int
channel
=
0
;
if
(
client_id
==
3017
)
{
hash
=
"96613bf38393aa3d16451218f22344a8"
;
channel
=
0
;
}
else
if
(
client_id
==
3019
)
{
hash
=
"d54be2dbc75753eb863ba6139950656b"
;
channel
=
1
;
}
else
if
(
client_id
==
3057
)
{
hash
=
"bbf70bcaf5c52947ad26853f7cc1176d"
;
channel
=
0
;
}
//多麦在YOHO上的网站主标识
String
euid
=
orderInfo
.
getMbrName
();
String
orderCode
=
orderInfo
.
getOrderCode
();
int
orderTime
=
orderInfo
.
getOrderTime
();
BigDecimal
orderAmount
=
orderInfo
.
getOrderAmount
();
String
orderStatus
=
orderInfo
.
getOrderStatus
();
List
<
OrdersGood
>
goods
=
orderInfo
.
getOrdersGoods
();
List
<
String
>
goodsIdList
=
new
ArrayList
<>();
List
<
String
>
goodsNameList
=
new
ArrayList
<>();
List
<
BigDecimal
>
goodsPriceList
=
new
ArrayList
<>();
//商品结算金额 price*num-优惠&折扣
List
<
BigDecimal
>
goodsTotalPriceList
=
new
ArrayList
<>();
// 商品分类编号
List
<
Integer
>
small_sort_idList
=
new
ArrayList
<>();
List
<
Integer
>
goodsNumList
=
new
ArrayList
<>();
for
(
OrdersGood
ordersGood:
goods
){
goodsIdList
.
add
(
ordersGood
.
getProductSkn
());
goodsNameList
.
add
(
ordersGood
.
getProductName
());
goodsPriceList
.
add
(
ordersGood
.
getLastPrice
());
goodsNumList
.
add
(
ordersGood
.
getBuyNumber
());
small_sort_idList
.
add
(
ordersGood
.
getSortId
());
goodsTotalPriceList
.
add
(
ordersGood
.
getLastPrice
());
}
LinkedHashMap
<
String
,
Object
>
linkedHashMap
=
new
LinkedHashMap
<>();
linkedHashMap
.
put
(
"hash"
,
hash
);
linkedHashMap
.
put
(
"euid"
,
euid
);
linkedHashMap
.
put
(
"order_sn"
,
orderCode
);
linkedHashMap
.
put
(
"order_time"
,
orderTime
);
linkedHashMap
.
put
(
"orders_price"
,
orderAmount
);
linkedHashMap
.
put
(
"promotion_code"
,
0
);
//@TODO需要订单传过来,是否新用户
linkedHashMap
.
put
(
"is_new_custom"
,
0
);
linkedHashMap
.
put
(
"channel"
,
channel
);
linkedHashMap
.
put
(
"status"
,
orderStatus
);
linkedHashMap
.
put
(
"goods_id"
,
CollectionUtils
.
isEmpty
(
goodsIdList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
goodsIdList
,
"|"
));
linkedHashMap
.
put
(
"goods_name"
,
CollectionUtils
.
isEmpty
(
goodsNameList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
goodsNameList
,
"|"
));
linkedHashMap
.
put
(
"goods_price"
,
CollectionUtils
.
isEmpty
(
goodsPriceList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
goodsPriceList
,
"|"
));
linkedHashMap
.
put
(
"goods_ta"
,
CollectionUtils
.
isEmpty
(
goodsNumList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
goodsNumList
,
"|"
));
linkedHashMap
.
put
(
"goods_cate"
,
CollectionUtils
.
isEmpty
(
small_sort_idList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
small_sort_idList
,
"|"
));
linkedHashMap
.
put
(
"goods_cate_name"
,
0
);
linkedHashMap
.
put
(
"totalPrice"
,
CollectionUtils
.
isEmpty
(
goodsTotalPriceList
)
?
""
:
org
.
apache
.
commons
.
lang
.
StringUtils
.
join
(
goodsTotalPriceList
,
"|"
));
//佣金计算,月底计算一次,7%计算,数据库比例已经老的
linkedHashMap
.
put
(
"rate"
,
0
);
linkedHashMap
.
put
(
"commission"
,
""
);
linkedHashMap
.
put
(
"commission_type"
,
0
);
double
coupon
=
12
d
;
linkedHashMap
.
put
(
"coupon"
,
MathUtils
.
roundPrice
(
coupon
));
Set
<
String
>
keys
=
linkedHashMap
.
keySet
();
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
key
:
keys
)
{
builder
.
append
(
key
).
append
(
"="
).
append
(
linkedHashMap
.
get
(
key
)).
append
(
"&"
);
}
try
{
urlContext
=
URLEncoder
.
encode
(
builder
.
substring
(
0
,
builder
.
length
()
-
1
),
"UTF-8"
);
}
catch
(
Exception
e
)
{
logger
.
warn
(
"send duomai error"
,
e
.
getMessage
());
}
}
return
urlContext
;
}
}
//package com.yoho.unions.server.service.impl;
//
//import com.alibaba.fastjson.JSONObject;
//import com.yoho.unions.common.utils.HttpUtils;
//import com.yoho.unions.common.utils.MathUtils;
//import com.yoho.unions.dal.IUserOrdersDAO;
//import com.yoho.unions.server.service.IOrderPushService;
//import com.yoho.unions.vo.OrderInfo;
//import com.yoho.unions.vo.OrdersGood;
//import net.spy.memcached.compat.log.Logger;
//import net.spy.memcached.compat.log.LoggerFactory;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang3.tuple.Pair;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import java.math.BigDecimal;
//import java.net.URLEncoder;
//import java.util.*;
//
///**
// * 多麦走通用的,不单独走定制的
// * 多麦推送订单数据
// * Created by yoho on 2016/12/15.
// */
//public class DuomaiServiceImpl implements IOrderPushService {
//
// @Autowired
// private IUserOrdersDAO userOrdersDAO;
//
// static Logger logger = LoggerFactory.getLogger(DuomaiServiceImpl.class);
//
// @Override
// public void pushOrder(List<OrderInfo> orderInfoList) {
// List<String> successCodes = new ArrayList<>();
// String duomaiContext = getDuomaiContext(orderInfoList);
// OrderInfo orderInfo = orderInfoList.get(0);
// int clientId = orderInfo.getClientId();
// String duomaiPushUrl = null;
// if (clientId == 3017) {
// duomaiPushUrl = "http://www.duomai.com/api/push/yohobuy.php";
// } else if (clientId == 3019) {
// duomaiPushUrl = "http://www.duomai.com/api/push/myohobuy.php";
// } else {
// duomaiPushUrl = "http://www.duomai.com/api/push/yohobuyroi.php";
// }
// Pair<Integer, String> pair = null;
// Map param = new HashMap<>();
// param.put("content", duomaiContext);
// try {
// logger.info("pushOrder: url is {}, param is {}", duomaiPushUrl, param);
// pair = HttpUtils.httpPost(duomaiPushUrl, param);
// } catch (Exception e) {
// logger.error("duomai order post fail,orderCode is {}", orderInfo.getParentOrderCode());
// }
// JSONObject json = JSONObject.parseObject(pair.getRight());
// if (((String) json.get("code")).equals("200")) {
// logger.info("duomai pushOrder success,orderCode is {}", orderInfo.getParentOrderCode());
// successCodes.add(orderInfo.getParentOrderCode());
// } else {
// logger.warn("duomai pushOrder fail,orderCode is {},message is {}", orderInfo.getParentOrderCode(), (String) json.get("msg"));
// }
// //批量更新推送成功的订单状态为1
// userOrdersDAO.batchUpdatePush(successCodes);
// }
//
// private String getDuomaiContext(List<OrderInfo> orderInfoList) {
// String urlContext = null;
// for (OrderInfo orderInfo : orderInfoList) {
// //联盟id
// int client_id = orderInfo.getClientId();
// String hash = "";
// int channel = 0;
// if (client_id == 3017) {
// hash = "96613bf38393aa3d16451218f22344a8";
// channel = 0;
// } else if (client_id == 3019) {
// hash = "d54be2dbc75753eb863ba6139950656b";
// channel = 1;
// } else if (client_id == 3057) {
// hash = "bbf70bcaf5c52947ad26853f7cc1176d";
// channel = 0;
// }
// //多麦在YOHO上的网站主标识
// String euid = orderInfo.getMbrName();
// String orderCode = orderInfo.getOrderCode();
// int orderTime = orderInfo.getOrderTime();
// BigDecimal orderAmount = orderInfo.getOrderAmount();
// String orderStatus = orderInfo.getOrderStatus();
// List<OrdersGood> goods = orderInfo.getOrdersGoods();
// List<String> goodsIdList = new ArrayList<>();
// List<String> goodsNameList = new ArrayList<>();
// List<BigDecimal> goodsPriceList = new ArrayList<>();
// //商品结算金额 price*num-优惠&折扣
// List<BigDecimal> goodsTotalPriceList = new ArrayList<>();
// // 商品分类编号
// List<Integer> small_sort_idList = new ArrayList<>();
// List<Integer> goodsNumList = new ArrayList<>();
//
// for(OrdersGood ordersGood:goods){
// goodsIdList.add(ordersGood.getProductSkn());
// goodsNameList.add(ordersGood.getProductName());
// goodsPriceList.add(ordersGood.getLastPrice());
// goodsNumList.add(ordersGood.getBuyNumber());
// small_sort_idList.add(ordersGood.getSortId());
// goodsTotalPriceList.add(ordersGood.getLastPrice());
// }
//
// LinkedHashMap<String, Object> linkedHashMap = new LinkedHashMap<>();
// linkedHashMap.put("hash", hash);
// linkedHashMap.put("euid", euid);
// linkedHashMap.put("order_sn", orderCode);
// linkedHashMap.put("order_time", orderTime);
// linkedHashMap.put("orders_price", orderAmount);
// linkedHashMap.put("promotion_code", 0);
// //@TODO需要订单传过来,是否新用户
// linkedHashMap.put("is_new_custom", 0);
// linkedHashMap.put("channel", channel);
// linkedHashMap.put("status", orderStatus);
// linkedHashMap.put("goods_id", CollectionUtils.isEmpty(goodsIdList) ? "" : org.apache.commons.lang.StringUtils.join(goodsIdList, "|"));
// linkedHashMap.put("goods_name", CollectionUtils.isEmpty(goodsNameList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNameList, "|"));
// linkedHashMap.put("goods_price", CollectionUtils.isEmpty(goodsPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsPriceList, "|"));
// linkedHashMap.put("goods_ta", CollectionUtils.isEmpty(goodsNumList) ? "" : org.apache.commons.lang.StringUtils.join(goodsNumList, "|"));
// linkedHashMap.put("goods_cate", CollectionUtils.isEmpty(small_sort_idList) ? "" : org.apache.commons.lang.StringUtils.join(small_sort_idList, "|"));
// linkedHashMap.put("goods_cate_name", 0);
// linkedHashMap.put("totalPrice", CollectionUtils.isEmpty(goodsTotalPriceList) ? "" : org.apache.commons.lang.StringUtils.join(goodsTotalPriceList, "|"));
// //佣金计算,月底计算一次,7%计算,数据库比例已经老的
// linkedHashMap.put("rate", 0);
// linkedHashMap.put("commission", "");
// linkedHashMap.put("commission_type", 0);
// double coupon = 12d;
// linkedHashMap.put("coupon", MathUtils.roundPrice(coupon));
// Set<String> keys = linkedHashMap.keySet();
// StringBuilder builder = new StringBuilder();
// for (String key : keys) {
// builder.append(key).append("=").append(linkedHashMap.get(key)).append("&");
// }
// try {
// urlContext = URLEncoder.encode(builder.substring(0, builder.length() - 1), "UTF-8");
// } catch (Exception e) {
// logger.warn("send duomai error", e.getMessage());
// }
// }
// return urlContext;
// }
//
//}
...
...
server/src/main/java/com/yoho/unions/server/service/impl/OrderPushServiceImpl.java
View file @
e7820cf
...
...
@@ -9,6 +9,7 @@ import com.yoho.unions.vo.OrderInfo;
import
com.yoho.unions.vo.OrdersGood
;
import
net.spy.memcached.compat.log.Logger
;
import
net.spy.memcached.compat.log.LoggerFactory
;
import
org.apache.commons.lang.StringUtils
;
import
org.apache.commons.lang3.tuple.Pair
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -100,7 +101,11 @@ public class OrderPushServiceImpl implements IOrderPushService{
//根据不同的厂商,发送不同的URL
int
clientId
=
orderInfo
.
getClientId
();
UnionOrderPush
unionOrderPush
=
unionOrderPushDAO
.
selectByChannelId
(
clientId
);
String
commRate
=
unionOrderPush
.
getCommRate
();
String
commRate
=
null
;
if
(
null
!=
unionOrderPush
&&
StringUtils
.
isNotEmpty
(
unionOrderPush
.
getCommRate
())){
commRate
=
unionOrderPush
.
getCommRate
();
}
param
.
put
(
"commRate"
,
commRate
==
null
?
0
:
commRate
);
Pair
<
Integer
,
String
>
pair
=
null
;
try
{
...
...
Please
register
or
login
to post a comment