|
@@ -1,21 +1,27 @@
|
|
|
package com.miaxis.wx.service.impl;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.miaxis.common.config.WxpayConfig;
|
|
|
+import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.sms.MD5Utils;
|
|
|
import com.miaxis.common.utils.StringUtils;
|
|
|
import com.miaxis.feign.dto.FilmDTO;
|
|
|
+import com.miaxis.feign.dto.FilmMcpData;
|
|
|
+import com.miaxis.feign.dto.FilmXdResult;
|
|
|
+import com.miaxis.feign.dto.fulu.FuluCommonApiDTO;
|
|
|
+import com.miaxis.feign.dto.fulu.FuluDTO;
|
|
|
+import com.miaxis.feign.dto.fulu.FuluGoodsInfo;
|
|
|
+import com.miaxis.feign.dto.fulu.FuluResult;
|
|
|
+import com.miaxis.feign.service.IFuluService;
|
|
|
import com.miaxis.wx.dto.*;
|
|
|
import com.miaxis.system.service.ISysConfigService;
|
|
|
+import com.miaxis.wx.service.IRefundRecordService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.HttpStatus;
|
|
@@ -27,6 +33,7 @@ import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.miaxis.wx.mapper.WxOrderMapper;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
@@ -34,6 +41,8 @@ import com.miaxis.wx.service.IWxOrderService;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
|
+
|
|
|
/**
|
|
|
* 电影订单Service业务层处理
|
|
|
*
|
|
@@ -49,6 +58,15 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
|
|
|
@Autowired
|
|
|
private ISysConfigService configService;
|
|
|
+ @Autowired
|
|
|
+ private IRefundRecordService refundRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IFuluService fuluService;
|
|
|
+ @Autowired
|
|
|
+ private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
+
|
|
|
+ @Value("${film.notifyUrl}")
|
|
|
+ private String notifyUrl ;
|
|
|
|
|
|
|
|
|
|
|
@@ -64,6 +82,12 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
private String v2Url ;
|
|
|
|
|
|
|
|
|
+ @Value("${fulu.appKey}")
|
|
|
+ private String fuluAppKey ;
|
|
|
+ @Value("${fulu.appSecret}")
|
|
|
+ private String fuluAppSecret ;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -202,4 +226,154 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
order.setOrderDataJson(JSONObject.toJSONString(filmWxOrderJsonData));
|
|
|
order.setTotal(price*number);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void createFuluOrder(WxOrder order, WxOrderCreateFuluDTO wxOrderCreateDTO) {
|
|
|
+ FuluWxOrderJsonData fuluWxOrderJsonData = new FuluWxOrderJsonData();
|
|
|
+ wxOrderCreateDTO.setCustomer_order_no(order.getOutTradeNo());
|
|
|
+ fuluWxOrderJsonData.setWxOrderCreateDTO(wxOrderCreateDTO);
|
|
|
+ order.setOrderDataJson(JSONObject.toJSONString(fuluWxOrderJsonData));
|
|
|
+ //调用福禄接口 获取产品详情对象
|
|
|
+ FuluDTO fuluDTO = new FuluDTO();
|
|
|
+ FuluCommonApiDTO fuluCommonApiDTO = new FuluCommonApiDTO();
|
|
|
+ fuluCommonApiDTO.setMethod("fulu.goods.info.get");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("product_id",wxOrderCreateDTO.getProduct_id());
|
|
|
+ fuluCommonApiDTO.setBiz_content(jsonObject.toJSONString());
|
|
|
+ FuluResult fuluResult = fuluService.fuluCommonApi(fuluDTO);
|
|
|
+ if (fuluResult.getCode()!= 0){
|
|
|
+ throw new CustomException("福禄接口调用失败:"+fuluResult.getMessage());
|
|
|
+ }
|
|
|
+ FuluGoodsInfo fuluGoodsInfo = JSONObject.parseObject(fuluResult.getResult(), FuluGoodsInfo.class);
|
|
|
+ fuluWxOrderJsonData.setFuluGoodsInfo(fuluGoodsInfo);
|
|
|
+ String fuluVipDiscount = configService.selectConfigByKey("fulu_vip_discount");
|
|
|
+ Double fuluVipDiscountDoubleValue = Double.valueOf(fuluVipDiscount);
|
|
|
+ Double v = fuluVipDiscountDoubleValue * wxOrderCreateDTO.getBuy_num() * 100;
|
|
|
+ order.setTotal(v.intValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(FuluDTO fuluDTO, FuluCommonApiDTO fuluCommonApiDTO) {
|
|
|
+ fuluDTO.setApp_key(fuluAppKey);
|
|
|
+ fuluDTO.setMethod(fuluCommonApiDTO.getMethod());
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ fuluDTO.setTimestamp(simpleDateFormat.format(new Date()));
|
|
|
+ fuluDTO.setVersion("2.0");
|
|
|
+ fuluDTO.setFormat("json");
|
|
|
+ fuluDTO.setCharset("utf-8");
|
|
|
+ fuluDTO.setSign_type("md5");
|
|
|
+ fuluDTO.setApp_auth_token("");
|
|
|
+ fuluDTO.setBiz_content(fuluCommonApiDTO.getBiz_content());
|
|
|
+ String str = JSONObject.toJSONString(fuluDTO);
|
|
|
+ char[] s = str.toCharArray();
|
|
|
+ Arrays.sort(s);
|
|
|
+ String outputSignOriginalStr = new String(s) + fuluAppSecret;
|
|
|
+ String sign = MD5Utils.MD5Encode(outputSignOriginalStr);
|
|
|
+ fuluDTO.setSign(sign);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void buyFilmOrder(WxOrder wxOrder) {
|
|
|
+ String orderDataJson = wxOrder.getOrderDataJson();
|
|
|
+ FilmWxOrderJsonData wxOrderJsonData = JSONObject.parseObject(orderDataJson, FilmWxOrderJsonData.class);
|
|
|
+ if (wxOrderJsonData != null && wxOrderJsonData.getWxOrderNotifyDTO() == null){
|
|
|
+ threadPoolTaskExecutor.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ WxOrderCreateDTO wxOrderCreateDTO = wxOrderJsonData.getWxOrderCreateDTO();
|
|
|
+ FilmDTO filmDTO = new FilmDTO();
|
|
|
+ if (wxOrderCreateDTO.getTicketType() ==1){
|
|
|
+ filmDTO.setUrl("api/order/create");
|
|
|
+ }else if (wxOrderCreateDTO.getTicketType() ==2){
|
|
|
+ filmDTO.setUrl("api/order/create-soon-order");
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuffer paramData = new StringBuffer();
|
|
|
+ paramData.append("showId="+wxOrderCreateDTO.getShowId()+"&");
|
|
|
+ paramData.append("seat="+wxOrderCreateDTO.getSeat()+"&");
|
|
|
+ if (wxOrderCreateDTO.getReservedPhone() != null){
|
|
|
+ paramData.append("reservedPhone="+wxOrderCreateDTO.getReservedPhone()+"&");
|
|
|
+ }
|
|
|
+ paramData.append("thirdOrderId="+wxOrderCreateDTO.getThirdOrderId()+"&");
|
|
|
+ paramData.append("notifyUrl="+notifyUrl+"&");
|
|
|
+ if (wxOrderCreateDTO.getSeatId() != null){
|
|
|
+ paramData.append("seatId="+wxOrderCreateDTO.getSeatId()+"&");
|
|
|
+ }
|
|
|
+ if (wxOrderCreateDTO.getSeatNo() != null){
|
|
|
+ paramData.append("seatNo="+wxOrderCreateDTO.getSeatNo()+"&");
|
|
|
+ }
|
|
|
+ paramData.append("acceptChangeSeat="+wxOrderCreateDTO.getAcceptChangeSeat());
|
|
|
+ filmDTO.setParamData(paramData.toString());
|
|
|
+
|
|
|
+ String s = excuteFilmApi(filmDTO);
|
|
|
+ log.info("电影下单返回值:"+s);
|
|
|
+ FilmXdResult filmXdResult = JSONObject.parseObject(s, FilmXdResult.class);
|
|
|
+ //如果返回值不是200 ,则调用退款流程
|
|
|
+ if (filmXdResult.getCode()!=200){
|
|
|
+ String refundCode = getOrderCode(null);
|
|
|
+ wxOrder.setOutRefundNo(refundCode);
|
|
|
+ try {
|
|
|
+ refundRecordService.refund(wxOrder,refundCode);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("退款失败");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ if (filmXdResult.getData().getTicket()!= null){
|
|
|
+ FilmMcpData filmMcpData = filmXdResult.getData();
|
|
|
+ wxOrderJsonData.setFilmMcpData(filmMcpData);
|
|
|
+ wxOrder.setOrderDataJson(JSONObject.toJSONString(wxOrderJsonData));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ updateById(wxOrder);
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void buyFuluOrder(WxOrder wxOrder) {
|
|
|
+ String orderDataJson = wxOrder.getOrderDataJson();
|
|
|
+ FuluWxOrderJsonData wxOrderJsonData = JSONObject.parseObject(orderDataJson, FuluWxOrderJsonData.class);
|
|
|
+ if (wxOrderJsonData != null && wxOrderJsonData.getWxFuluOrderDetailDTO()== null){
|
|
|
+ threadPoolTaskExecutor.execute(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ WxOrderCreateFuluDTO wxOrderCreateDTO = wxOrderJsonData.getWxOrderCreateDTO();
|
|
|
+ //调用福禄下单接口
|
|
|
+ FuluDTO fuluDTO = new FuluDTO();
|
|
|
+ FuluCommonApiDTO fuluCommonApiDTO = new FuluCommonApiDTO();
|
|
|
+ fuluCommonApiDTO.setMethod("fulu.order.direct.add");
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("product_id",wxOrderCreateDTO.getProduct_id());
|
|
|
+ jsonObject.put("customer_order_no",wxOrderCreateDTO.getCustomer_order_no());
|
|
|
+ jsonObject.put("charge_account",wxOrderCreateDTO.getCharge_account());
|
|
|
+ jsonObject.put("buy_num",wxOrderCreateDTO.getBuy_num());
|
|
|
+ fuluCommonApiDTO.setBiz_content(jsonObject.toJSONString());
|
|
|
+ FuluResult fuluResult = fuluService.fuluCommonApi(fuluDTO);
|
|
|
+ log.info("福禄下单返回值:"+JSONObject.toJSONString(fuluResult));
|
|
|
+ //如果返回值不是200 ,则调用退款流程
|
|
|
+ if (fuluResult.getCode() != 0){
|
|
|
+ String refundCode = getOrderCode(null);
|
|
|
+ wxOrder.setOutRefundNo(refundCode);
|
|
|
+ try {
|
|
|
+ refundRecordService.refund(wxOrder,refundCode);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new CustomException("退款失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //返回成功,则保存返回福禄订单详情到微信订单json传中
|
|
|
+ WxFuluOrderDetailDTO wxFuluOrderDetailDTO = JSONObject.parseObject(fuluResult.getResult(),WxFuluOrderDetailDTO.class);
|
|
|
+ wxOrderJsonData.setWxFuluOrderDetailDTO(wxFuluOrderDetailDTO);
|
|
|
+ wxOrder.setOrderDataJson(wxOrderJsonData.toString());
|
|
|
+ updateById(wxOrder);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|