|
|
@@ -5,15 +5,19 @@ import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.kxs.common.core.constant.CommonConstants;
|
|
|
import com.kxs.common.security.util.SecurityUtils;
|
|
|
import com.kxs.lhb.basic.api.constant.enums.ChannelCodeEnum;
|
|
|
+import com.kxs.lhb.basic.api.constant.enums.NotifyStatusEnum;
|
|
|
+import com.kxs.lhb.basic.api.constant.enums.OrderStatusEnum;
|
|
|
import com.kxs.lhb.basic.api.dto.tongyi.*;
|
|
|
import com.kxs.lhb.basic.api.dto.yiyang.YWOrderCancelReq;
|
|
|
import com.kxs.lhb.basic.api.dto.yiyang.YWPreNumbersReq;
|
|
|
-import com.kxs.lhb.basic.api.model.LhbArea;
|
|
|
-import com.kxs.lhb.basic.api.model.LhbGoods;
|
|
|
-import com.kxs.lhb.basic.api.model.LhbGoodsSku;
|
|
|
-import com.kxs.lhb.basic.api.model.LhbOrder;
|
|
|
+import com.kxs.lhb.basic.api.dto.yiyang.YWQueryFirstOrderReq;
|
|
|
+import com.kxs.lhb.basic.api.dto.yiyang.YWQueryOrderReq;
|
|
|
+import com.kxs.lhb.basic.api.model.*;
|
|
|
import com.kxs.lhb.basic.api.vo.tongyi.*;
|
|
|
import com.kxs.lhb.basic.api.vo.yiwang.YWCommRes;
|
|
|
import com.kxs.lhb.basic.biz.channel.BasicService;
|
|
|
@@ -22,10 +26,13 @@ import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* TY API调用服务
|
|
|
@@ -98,9 +105,7 @@ public class YWBasicService extends YiWangService implements BasicService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String orderSubmit(String orderSn) {
|
|
|
-
|
|
|
- LhbOrder order = orderService.getOrderSn(orderSn);
|
|
|
+ public String orderSubmit(LhbOrder order) {
|
|
|
|
|
|
LhbGoods goods = goodsService.getById(order.getGoodsId());
|
|
|
|
|
|
@@ -110,7 +115,9 @@ public class YWBasicService extends YiWangService implements BasicService {
|
|
|
|
|
|
LhbArea province = areaService.getById(city.getParentId());
|
|
|
|
|
|
- Map<String,Object> params = new HashMap<>();
|
|
|
+ List<LhbGoodsActivities> activities = goodsActivitiesService.list(Wrappers.lambdaQuery(LhbGoodsActivities.class).eq(LhbGoodsActivities::getSkuId, goodsSku.getId()));
|
|
|
+
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
params.put("seqId", IdUtil.simpleUUID());
|
|
|
// 不用 params.put("orderType", "15");
|
|
|
// 不用 params.put("channelId","SHENGFEN");
|
|
|
@@ -127,23 +134,32 @@ public class YWBasicService extends YiWangService implements BasicService {
|
|
|
params.put("phone", order.getMakeMobile());
|
|
|
// 不用 params.put("payWay","9");
|
|
|
// 不用 params.put("userIdType","1");
|
|
|
- params.put("userId", order.getUserId());
|
|
|
+ params.put("userId", String.valueOf(order.getUserId()));
|
|
|
params.put("payMoney", "0");
|
|
|
params.put("sendWay","1");
|
|
|
params.put("orderRemark", order.getRemark());
|
|
|
- Map<String,Object> goodsMap = new HashMap<>();
|
|
|
+ Map<String, Object> goodsMap = new HashMap<>();
|
|
|
goodsMap.put("goodsId", goods.getExternalId());
|
|
|
goodsMap.put("goodsSkuId", goodsSku.getExternalSkuId());
|
|
|
// goodsMap.put("goodsTypeId","C01");
|
|
|
goodsMap.put("orderNum","1");
|
|
|
|
|
|
+ if(!activities.isEmpty()){
|
|
|
+ List<Map<String,Object>> offerList = new ArrayList<>();
|
|
|
+ for (LhbGoodsActivities activity : activities) {
|
|
|
+ Map<String,Object> codes = new HashMap<>();
|
|
|
+ codes.put("offerCode", activity.getActivityCode());
|
|
|
+ offerList.add(codes);
|
|
|
+ }
|
|
|
+ goodsMap.put("offerList", offerList);
|
|
|
+ }
|
|
|
|
|
|
params.put("goodsParams", goodsMap);
|
|
|
|
|
|
- String[] split = order.getArea().split(StrUtil.COLON);
|
|
|
+ String[] split = order.getArea().split(StrUtil.COMMA);
|
|
|
LhbArea county = areaService.getAreaCode(split[2]);
|
|
|
|
|
|
- Map<String,Object> orderRecvAddr = new HashMap<>();
|
|
|
+ Map<String,String> orderRecvAddr = new HashMap<>();
|
|
|
orderRecvAddr.put("receiveName", order.getCustName());
|
|
|
orderRecvAddr.put("receiveCountry","中国");
|
|
|
orderRecvAddr.put("receiveProvince", province.getAreaCode());
|
|
|
@@ -156,15 +172,15 @@ public class YWBasicService extends YiWangService implements BasicService {
|
|
|
orderRecvAddr.put("receiveMobile", order.getContMobile());
|
|
|
params.put("orderRecvAddr",orderRecvAddr);
|
|
|
|
|
|
- Map<String,Object> custInfo = new HashMap<>();
|
|
|
+ Map<String,String> custInfo = new HashMap<>();
|
|
|
custInfo.put("custName", order.getCustName());
|
|
|
custInfo.put("idenType","1");
|
|
|
- custInfo.put("idenNr", order);
|
|
|
+ custInfo.put("idenNr", order.getIdCard());
|
|
|
custInfo.put("contNumber", order.getContMobile());
|
|
|
params.put("custInfo",custInfo);
|
|
|
|
|
|
params.put("outOrderId", order.getOrderSn());
|
|
|
- YWCommRes<Object> commRes = sendToUrl(order, "/gd/openapi/fenxiao/prov/openAcount/submitOrder");
|
|
|
+ YWCommRes<Object> commRes = sendToUrl(params, "/gd/openapi/fenxiao/prov/openAcount/submitOrder");
|
|
|
JSONObject entries = JSONUtil.parseObj(commRes.getResult());
|
|
|
return entries.getStr("orderId");
|
|
|
}
|
|
|
@@ -178,29 +194,76 @@ public class YWBasicService extends YiWangService implements BasicService {
|
|
|
.orderId(order.getOutOrderSn())
|
|
|
.returnCause(order.getRemark())
|
|
|
.applyPerson(SecurityUtils.getUser().getName()).build();
|
|
|
- sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/cancel");
|
|
|
+ sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/returnOrder");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public QueryLogisticsRes queryLogistics(QueryOrderReq req) {
|
|
|
|
|
|
- YWCommRes<Object> commRes = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/queryLogistics");
|
|
|
- YWCommRes<QueryLogisticsRes> res = JSONUtil.toBean(commRes.getResult().toString(), new TypeReference<>() {}, true);
|
|
|
- return JSONUtil.toBean(JSONUtil.toJsonStr(res.getResult()), QueryLogisticsRes.class);
|
|
|
+ YWCommRes<Object> res = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/qryorderLogistics");
|
|
|
+ JSONObject entries = JSONUtil.parseObj(res.getResult().toString());
|
|
|
+ return JSONUtil.toBean(entries.getStr("data"), new TypeReference<>() {}, true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String queryStatus(QueryOrderReq req) {
|
|
|
-
|
|
|
- YWCommRes<Object> commRes = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/queryStatus");
|
|
|
+ public String queryStatus(LhbOrder order) {
|
|
|
+
|
|
|
+ YWQueryOrderReq req = YWQueryOrderReq.builder().orderId(order.getOutOrderSn())
|
|
|
+ .phone(order.getMakeMobile())
|
|
|
+ .userId(String.valueOf(order.getUserId()))
|
|
|
+ .build();
|
|
|
+ YWCommRes<Object> commRes = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/qryOrderDetail");
|
|
|
+ JSONObject entries = JSONUtil.parseObj(commRes.getResult().toString());
|
|
|
+
|
|
|
+ String outStatus = entries.getStr("orderStatus");
|
|
|
+
|
|
|
+ //更新状态
|
|
|
+ LambdaUpdateWrapper<LhbOrder> updateWrapper = Wrappers.lambdaUpdate(LhbOrder.class).eq(LhbOrder::getId, order.getId()).set(LhbOrder::getOutStatus, outStatus);
|
|
|
+
|
|
|
+ switch (outStatus){
|
|
|
+ case "4","2":
|
|
|
+ //4-配送中,不可取消订单 2-订单成功结束
|
|
|
+ orderService.sendToOrder(order, "2".equals(outStatus) ? NotifyStatusEnum.ACT : NotifyStatusEnum.DISTRIBUTION);
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ //3-订单异常取消
|
|
|
+ orderService.sendToOrder(order, NotifyStatusEnum.CANCEL);
|
|
|
+ //如果是0服务费直接订单也变成已取消
|
|
|
+ if(order.getServerFee().compareTo(BigDecimal.ZERO) == 0){
|
|
|
+ updateWrapper.set(LhbOrder::getStatus, OrderStatusEnum.CANCEL.getCode());
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
return commRes.getResult().toString();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String queryFirstCharge(QueryOrderReq req) {
|
|
|
+ public void queryFirstCharge(LhbOrder order) {
|
|
|
|
|
|
- YWCommRes<Object> commRes = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/queryFirstCharge");
|
|
|
- return commRes.getResult().toString();
|
|
|
+ YWQueryFirstOrderReq req = YWQueryFirstOrderReq.builder().phoneNumber(order.getMakeMobile()).build();
|
|
|
+ YWCommRes<Object> commRes = sendToUrl(req, "/gd/openapi/fenxiao/prov/openAcount/queryFirstRecharge");
|
|
|
+ String firstCharge = commRes.getResult().toString();
|
|
|
+
|
|
|
+ if(firstCharge.contains("首充50元") || firstCharge.contains("首充100元")){
|
|
|
+
|
|
|
+ BigDecimal firstChargeAmt = firstCharge.contains("首充50元") ? new BigDecimal("5000") : new BigDecimal("10000");
|
|
|
+
|
|
|
+ //更新状态
|
|
|
+ orderService.update(Wrappers.lambdaUpdate(LhbOrder.class).eq(LhbOrder::getId, order.getId())
|
|
|
+ .set(LhbOrder::getIsAct, CommonConstants.SUCCESS)
|
|
|
+ .set(LhbOrder::getFirstCharge, firstChargeAmt)
|
|
|
+ .set(LhbOrder::getIsFirstRecharge, CommonConstants.SUCCESS));
|
|
|
+
|
|
|
+ order.setIsFirstRecharge(CommonConstants.SUCCESS);
|
|
|
+ order.setFirstCharge(firstChargeAmt);
|
|
|
+ order.setIsAct(CommonConstants.SUCCESS);
|
|
|
+ orderService.sendToOrder(order, NotifyStatusEnum.ACT);
|
|
|
+ }
|
|
|
+ //订单超过30天自动设置为已激活
|
|
|
+ if(order.getCreateTime().plusDays(30).isBefore(LocalDateTime.now())){
|
|
|
+ orderService.update(Wrappers.lambdaUpdate(LhbOrder.class).eq(LhbOrder::getId, order.getId())
|
|
|
+ .set(LhbOrder::getIsAct, CommonConstants.SUCCESS));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|