|
@@ -1,5 +1,6 @@
|
|
|
package zs.payment.controller;
|
|
package zs.payment.controller;
|
|
|
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -7,12 +8,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
-import zs.payment.req.OrderCheckReq;
|
|
|
|
|
-import zs.payment.req.OrderReq;
|
|
|
|
|
-import zs.payment.req.ProductDetailReq;
|
|
|
|
|
-import zs.payment.dto.OrdersDTO;
|
|
|
|
|
-import zs.payment.req.ProductPageReq;
|
|
|
|
|
|
|
+import zs.payment.dao.OrderCallbackDao;
|
|
|
|
|
+import zs.payment.entity.OrderCallback;
|
|
|
|
|
+import zs.payment.req.*;
|
|
|
|
|
+import zs.payment.entity.Orders;
|
|
|
|
|
+import zs.payment.req.aftersales.AfterSalesOrderReq;
|
|
|
import zs.payment.resp.Result;
|
|
import zs.payment.resp.Result;
|
|
|
|
|
+import zs.payment.service.OrdersService;
|
|
|
import zs.payment.utils.HttpUtil;
|
|
import zs.payment.utils.HttpUtil;
|
|
|
import zs.payment.utils.RedisUtils;
|
|
import zs.payment.utils.RedisUtils;
|
|
|
|
|
|
|
@@ -24,7 +26,7 @@ import java.util.Map;
|
|
|
/**
|
|
/**
|
|
|
* 芸信 供应链平台
|
|
* 芸信 供应链平台
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/supply")
|
|
@RequestMapping("/supply")
|
|
|
public class YxSupplyChannelManualController {
|
|
public class YxSupplyChannelManualController {
|
|
@@ -40,6 +42,12 @@ public class YxSupplyChannelManualController {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisUtils redisUtils;
|
|
private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OrdersService ordersService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private OrderCallbackDao callbackDao;
|
|
|
|
|
+
|
|
|
public static final String SUPPLY_TOKEN = "supply:token";
|
|
public static final String SUPPLY_TOKEN = "supply:token";
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -170,8 +178,77 @@ public class YxSupplyChannelManualController {
|
|
|
|
|
|
|
|
return Result.success(respJson.getJSONObject("data"));
|
|
return Result.success(respJson.getJSONObject("data"));
|
|
|
}
|
|
}
|
|
|
|
|
+ //仅下单
|
|
|
|
|
+ @PostMapping("/orderConfirmOnly")
|
|
|
|
|
+ public Result orderConfirmOnly(@Valid @RequestBody OrderReq req){
|
|
|
|
|
+ String token = redisUtils.get(SUPPLY_TOKEN);
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
|
+ Result tokenResult = fetchAndCacheToken();
|
|
|
|
|
+ if (!tokenResult.isSuccess()) {
|
|
|
|
|
+ return tokenResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ token = (String) tokenResult.getBody().get("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("spu", req.getSpu());
|
|
|
|
|
+ params.put("address", req.getAddress());
|
|
|
|
|
+ params.put("order_sn", req.getOrderSn());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("x-token", token);
|
|
|
|
|
+
|
|
|
|
|
+ String resp = HttpUtil.restTemplatePost(prefixUrl + "/supplyapi/app/order/orderConfirmOnly", params, headers);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
|
+ if (respJson.getIntValue("code") != 0) {
|
|
|
|
|
+ return Result.fail(respJson.getString("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Orders> orders = JSONObject.parseArray(
|
|
|
|
|
+ respJson.getJSONObject("data").getJSONArray("Orders").toJSONString(),
|
|
|
|
|
+ Orders.class
|
|
|
|
|
+ );
|
|
|
|
|
+ log.info("仅下单,存储订单");
|
|
|
|
|
+ ordersService.addBatchOrder(orders);
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success(orders);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 下单
|
|
|
|
|
|
|
+ //订单支付(单独下单之后使用这个支付)
|
|
|
|
|
+ @PostMapping("/orderPayOnly")
|
|
|
|
|
+ public Result orderPayOnly(@Valid @RequestBody OrderPayReq req){
|
|
|
|
|
+ String token = redisUtils.get(SUPPLY_TOKEN);
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
|
+ Result tokenResult = fetchAndCacheToken();
|
|
|
|
|
+ if (!tokenResult.isSuccess()) {
|
|
|
|
|
+ return tokenResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ token = (String) tokenResult.getBody().get("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("order_sn", req.getOrderSn());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("x-token", token);
|
|
|
|
|
+
|
|
|
|
|
+ String resp = HttpUtil.restTemplatePost(prefixUrl + "/supplyapi/app/order/orderPayOnly", params, headers);
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
|
+ if (respJson.getIntValue("code") != 0) {
|
|
|
|
|
+ return Result.fail(respJson.getString("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<Orders> orders = JSONObject.parseArray(
|
|
|
|
|
+ respJson.getJSONObject("data").getJSONArray("Orders").toJSONString(),
|
|
|
|
|
+ Orders.class
|
|
|
|
|
+ );
|
|
|
|
|
+ return Result.success(orders);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ // 生成订单同时支付,如果已生成订单则是直接支付
|
|
|
@PostMapping("/order")
|
|
@PostMapping("/order")
|
|
|
public Result order(@Valid @RequestBody OrderReq req) {
|
|
public Result order(@Valid @RequestBody OrderReq req) {
|
|
|
String token = redisUtils.get(SUPPLY_TOKEN);
|
|
String token = redisUtils.get(SUPPLY_TOKEN);
|
|
@@ -186,7 +263,7 @@ public class YxSupplyChannelManualController {
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
params.put("spu", req.getSpu());
|
|
params.put("spu", req.getSpu());
|
|
|
params.put("address", req.getAddress());
|
|
params.put("address", req.getAddress());
|
|
|
- params.put("order_sn", req.getOrder_sn());
|
|
|
|
|
|
|
+ params.put("order_sn", req.getOrderSn());
|
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("x-token", token);
|
|
headers.put("x-token", token);
|
|
@@ -198,12 +275,131 @@ public class YxSupplyChannelManualController {
|
|
|
return Result.fail(respJson.getString("msg"));
|
|
return Result.fail(respJson.getString("msg"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- List<OrdersDTO> orders = JSONObject.parseArray(
|
|
|
|
|
|
|
+ List<Orders> orders = JSONObject.parseArray(
|
|
|
respJson.getJSONObject("data").getJSONArray("Orders").toJSONString(),
|
|
respJson.getJSONObject("data").getJSONArray("Orders").toJSONString(),
|
|
|
- OrdersDTO.class
|
|
|
|
|
|
|
+ Orders.class
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
|
|
+ log.info("下单并支付,存储订单");
|
|
|
|
|
+ ordersService.addBatchOrder(orders);
|
|
|
return Result.success(orders);
|
|
return Result.success(orders);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // 取消订单
|
|
|
|
|
+ @PostMapping("/appCloseOrder")
|
|
|
|
|
+ public Result appCloseOrder(@Valid @RequestBody CloseOrderReq req){
|
|
|
|
|
+
|
|
|
|
|
+ String token = redisUtils.get(SUPPLY_TOKEN);
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
|
+ Result tokenResult = fetchAndCacheToken();
|
|
|
|
|
+ if (!tokenResult.isSuccess()) {
|
|
|
|
|
+ return tokenResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ token = (String) tokenResult.getBody().get("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("order_id", req.getOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("x-token", token);
|
|
|
|
|
+
|
|
|
|
|
+ String resp = HttpUtil.restTemplatePost(prefixUrl + "/supplyapi/app/order/appCloseOrder", params, headers);
|
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
|
+ if (respJson.getIntValue("code") != 0) {
|
|
|
|
|
+ return Result.fail(respJson.getString("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+ //{
|
|
|
|
|
+ // "body": {
|
|
|
|
|
+ // "MSG": "SUCCESS",
|
|
|
|
|
+ // "CODE": 200,
|
|
|
|
|
+ // "data": {
|
|
|
|
|
+ // "errorOrdersSNs": null,
|
|
|
|
|
+ // "successOrdersSNs": [
|
|
|
|
|
+ // 195319850638
|
|
|
|
|
+ // ]
|
|
|
|
|
+ // }
|
|
|
|
|
+ // },
|
|
|
|
|
+ // "success": true
|
|
|
|
|
+ //}
|
|
|
|
|
+ return Result.success(respJson.getJSONObject("data"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // =======================售后==========================================
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 获取订单支持的售后方式
|
|
|
|
|
+ * @param req
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/getAfterSalesTypeNameMap")
|
|
|
|
|
+ public Result getAfterSalesTypeNameMap(@Valid @RequestBody AfterSalesOrderReq req){
|
|
|
|
|
+
|
|
|
|
|
+ String token = redisUtils.get(SUPPLY_TOKEN);
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
|
+ Result tokenResult = fetchAndCacheToken();
|
|
|
|
|
+ if (!tokenResult.isSuccess()) {
|
|
|
|
|
+ return tokenResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ token = (String) tokenResult.getBody().get("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("order_id", req.getOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("x-token", token);
|
|
|
|
|
+
|
|
|
|
|
+ String resp = HttpUtil.restTemplateGet(prefixUrl + "/supplyapi/app/afterSales/getAfterSalesTypeNameMap", params, headers);
|
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
|
+ if (respJson.getIntValue("code") != 0) {
|
|
|
|
|
+ return Result.fail(respJson.getString("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success(respJson.getJSONObject("data"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //申请售后
|
|
|
|
|
+ @PostMapping("/afterSalesCreate")
|
|
|
|
|
+ public Result afterSalesCreate(@Valid @RequestBody AfterSalesOrderReq req){
|
|
|
|
|
+ String token = redisUtils.get(SUPPLY_TOKEN);
|
|
|
|
|
+ if (token == null || token.isEmpty()) {
|
|
|
|
|
+ Result tokenResult = fetchAndCacheToken();
|
|
|
|
|
+ if (!tokenResult.isSuccess()) {
|
|
|
|
|
+ return tokenResult;
|
|
|
|
|
+ }
|
|
|
|
|
+ token = (String) tokenResult.getBody().get("token");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
|
|
+ params.put("order_id", req.getOrderId());
|
|
|
|
|
+ params.put("is_received",req.getIsReceived());
|
|
|
|
|
+ params.put("order_item_id",req.getOrderItemId());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
|
|
+ headers.put("x-token", token);
|
|
|
|
|
+
|
|
|
|
|
+ String resp = HttpUtil.restTemplatePost(prefixUrl + "/supplyapi/app/afterSales/create", params, headers);
|
|
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
|
|
+ if (respJson.getIntValue("code") != 0) {
|
|
|
|
|
+ return Result.fail(respJson.getString("msg"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return Result.success(respJson.getJSONObject("data"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //回调接口,拿到回调数据后,再对数据做处理
|
|
|
|
|
+ @PostMapping("/callback")
|
|
|
|
|
+ public Map<String, Object> callback(@Valid @RequestBody Object req) {
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ result.put("code", 0);
|
|
|
|
|
+
|
|
|
|
|
+ OrderCallback callback=new OrderCallback();
|
|
|
|
|
+ callback.setMessage(req);
|
|
|
|
|
+ callbackDao.save(callback);
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|