|
@@ -1,19 +1,26 @@
|
|
|
package com.iamberry.wechat.handles.order;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.iamberry.app.tool.log.RatFWLogger;
|
|
|
import com.iamberry.wechat.core.entity.activity.ActivityDate;
|
|
|
import com.iamberry.wechat.core.entity.cart.*;
|
|
|
import com.iamberry.wechat.core.entity.product.Product;
|
|
|
import com.iamberry.wechat.core.entity.product.SalesUserGift;
|
|
|
import com.iamberry.wechat.face.cart.SettlementGiftService;
|
|
|
+import com.iamberry.wechat.face.order.AdminOrderService;
|
|
|
import com.iamberry.wechat.service.ActivityUtil;
|
|
|
import com.iamberry.wechat.tools.*;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import org.apache.commons.lang3.StringEscapeUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
@@ -96,6 +103,12 @@ public class OrderHandler {
|
|
|
@Autowired
|
|
|
private ActivityUtil activityUtil;
|
|
|
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private AdminOrderService adminOrderService;
|
|
|
+ @Autowired
|
|
|
+ private RatFWLogger logger;
|
|
|
+
|
|
|
/**
|
|
|
* 支付前,调用方法
|
|
|
* @param request
|
|
@@ -258,6 +271,16 @@ public class OrderHandler {
|
|
|
msg.setMessage(ResultInfo.loginOutError);
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ if("收货人".equals(temp.getOrderAddressName())){
|
|
|
+ msg.setMessage("收货人信息有误,请重新选择地址信息!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if("收货人电话".equals(temp.getOrderAddressMoblie())){
|
|
|
+ msg.setMessage("收货人电话信息有误,请重新选择地址信息!");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
member=memberService.getMemberByUserId(member.getUserId());
|
|
|
if (!validatorUtil.validatorObject(temp)) { // 校验订单信息是否输入有误
|
|
@@ -702,4 +725,153 @@ public class OrderHandler {
|
|
|
cartDtoList.addAll(newGiftList);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 支付前,调用方法
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping(value = "/syncOrder", method = RequestMethod.POST)
|
|
|
+ public ResultMsg syncOrder(HttpServletRequest request,String orderId) throws Exception {
|
|
|
+ // orderInfo
|
|
|
+ Order order = adminOrderService.getShopOrderByOrderId(orderId);
|
|
|
+ if (order == null || order.getSalesOrderid() == null) {
|
|
|
+ return new ResultMsg();
|
|
|
+ }
|
|
|
+
|
|
|
+ List<OrderItem> items = adminOrderService.getShopOrderItemByOrderId(order.getSalesOrderid());
|
|
|
+
|
|
|
+ // request url
|
|
|
+ String url = NameUtils.getConfig("rst_efast_base_url");
|
|
|
+
|
|
|
+ // set Requeset Data
|
|
|
+ Map<String, String> requestData = new HashMap<String, String>();
|
|
|
+
|
|
|
+ int money = order.getSalesYetAmount();
|
|
|
+
|
|
|
+ if (order.getCouponId() != null && !"".equals(order.getCouponId())) {
|
|
|
+ CouponItem couponItem = new CouponItem();
|
|
|
+ couponItem.setCouponItemId(order.getCouponId());
|
|
|
+ couponItem.setCouponItemUseropenid(order.getSalesOpenid());
|
|
|
+ CouponType couponType = cartService.getCouponReduceByItemId(couponItem);
|
|
|
+ if (null != couponType) {
|
|
|
+ switch (couponType.getCouponType()) {
|
|
|
+ case 1:
|
|
|
+ money += couponType.getCouponReduce();
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ money += order.getSalesAmount() * couponType.getCouponReduce()/100;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ requestData.put("app_act", "rst.trade.new.add");
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单基本信息
|
|
|
+ */
|
|
|
+ String [] addressDesc = order.getSalesAddressInfo().split("-");
|
|
|
+
|
|
|
+ String address = addressDesc[3];
|
|
|
+ if (addressDesc[3]!=null) {
|
|
|
+ Pattern p = Pattern.compile("\\s*|\t|\r|\n");
|
|
|
+ Matcher m = p.matcher(addressDesc[3]);
|
|
|
+ if (m.find()) {
|
|
|
+ address = m.replaceAll("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String provinceName = addressDesc[0];
|
|
|
+ if (addressDesc[0].indexOf("北京") != -1) {
|
|
|
+ provinceName = "北京";
|
|
|
+ } else if (addressDesc[0].indexOf("上海") != -1) {
|
|
|
+ provinceName = "上海";
|
|
|
+ } else if (addressDesc[0].indexOf("天津") != -1) {
|
|
|
+ provinceName = "天津";
|
|
|
+ } else if (addressDesc[0].indexOf("重庆") != -1) {
|
|
|
+ provinceName = "重庆";
|
|
|
+ }
|
|
|
+ Map<String, Object> orderData = new HashMap<String, Object>();
|
|
|
+ orderData.put("add_time", DateTimeUtil.format(order.getSalesCreateDate())); // 时间
|
|
|
+ orderData.put("address", address); // 收货地址
|
|
|
+ orderData.put("city_name", addressDesc[1]); // 城市
|
|
|
+ orderData.put("consignee", order.getSalesAddressName()); // 收货人
|
|
|
+ orderData.put("district_name", addressDesc[2]); // 区域
|
|
|
+ orderData.put("email", ""); // email
|
|
|
+ orderData.put("goods_amount", order.getSalesAmount()); // 产品总价
|
|
|
+ orderData.put("goods_count", items.size()); // 产品数量
|
|
|
+ orderData.put("mobile", order.getSalesAddressTel()); // 手机号码
|
|
|
+ orderData.put("money_paid", money); // 已付款
|
|
|
+ orderData.put("oid", order.getSalesOrderid()); // 订单号
|
|
|
+ orderData.put("order_amount", order.getSalesAmount()); // 订单金额
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品信息
|
|
|
+ */
|
|
|
+ List<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
|
|
|
+ for (OrderItem item : items) {
|
|
|
+ Map<String, Object> orders1 = new HashMap<String, Object>();
|
|
|
+ orders1.put("goods_name", item.getItemProductName()); // 产品名称
|
|
|
+ orders1.put("goods_number", item.getItemNum()); // 产品数量
|
|
|
+ orders1.put("goods_price", item.getItemProductPrice()); // 产品原价
|
|
|
+ orders1.put("outer_sku", item.getProduectRemark()); // 产品SKU
|
|
|
+ orders1.put("payment_ft", item.getItemProductDiscount()); // 产品分摊价
|
|
|
+ maps.add(orders1);
|
|
|
+ }
|
|
|
+
|
|
|
+ orderData.put("orders", maps); // 订单产品
|
|
|
+ orderData.put("pay_name", "weixinpay"); // 支付方式
|
|
|
+ if(order.getSalesTransactionDate() != null){
|
|
|
+ orderData.put("pay_time", DateTimeUtil.format(order.getSalesTransactionDate()));// 支付时间
|
|
|
+ }else{
|
|
|
+ orderData.put("pay_time", "");
|
|
|
+ }
|
|
|
+ orderData.put("postscript", order.getSalesUserRemark()); // 买家留言
|
|
|
+ orderData.put("province_name", provinceName); // 省份
|
|
|
+ orderData.put("sd_id", "001"); // 对应 efast 店铺 id
|
|
|
+ orderData.put("shipping_fee", 0); // 快递费
|
|
|
+ orderData.put("shipping_name", "yto"); // 快递公司代码
|
|
|
+ orderData.put("tel", order.getSalesAddressTel()); // 我司电话
|
|
|
+ orderData.put("to_buyer", ""); // 商家备注
|
|
|
+ orderData.put("total_amount", order.getSalesAmount()); // 商家备注
|
|
|
+ orderData.put("user_name", order.getSalesOpenid()); // 买家账户 百胜根据user_name来判断是否有重复,传openId是为了防止重复
|
|
|
+ orderData.put("zipcode", order.getSalesAddressPostnum()); // 邮编
|
|
|
+
|
|
|
+
|
|
|
+ com.fasterxml.jackson.databind.ObjectMapper mapper = new ObjectMapper();
|
|
|
+ String orderDataStr = null;;
|
|
|
+ try {
|
|
|
+ orderDataStr = mapper.writeValueAsString(orderData);
|
|
|
+ } catch (JsonProcessingException e2) {
|
|
|
+ e2.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ requestData.put("info", orderDataStr);
|
|
|
+
|
|
|
+ logger.info("推送订单:" + requestData);
|
|
|
+
|
|
|
+ try {
|
|
|
+ String result = HttpClient431Util.doPost(requestData, url);
|
|
|
+ result = StringEscapeUtils.unescapeJava(result); // unicode 编码
|
|
|
+ logger.info("add-推送订单号为:" + order.getSalesOrderid() + "的订单,RST返回信息:" + result);
|
|
|
+ // parse JSON String to Object
|
|
|
+ JSONObject jsonObject = JSONObject.fromObject(result);
|
|
|
+ //JSONObject respData = JSONObject.fromObject(jsonObject.get("resp_data"));
|
|
|
+ String oderSn = jsonObject.getString("oder_sn");
|
|
|
+ if (oderSn != null) {
|
|
|
+ String msg = jsonObject.getString("msg");
|
|
|
+ if ("success".equals(msg)) {
|
|
|
+ return new ResultMsg();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.error(this, "add-推送订单失败,订单号为:" + order.getSalesOrderid() + "的订单,RST返回信息:" + result);
|
|
|
+ throw new Exception(jsonObject.getString("msg"));
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw e;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|