|
|
@@ -9,16 +9,12 @@ import com.dderp.common.api.flycat.OrderStepService
|
|
|
import com.dderp.common.datas.BusinessOrderStatus
|
|
|
import com.dderp.common.datas.ERPModule
|
|
|
import com.dderp.common.datas.ESKeys
|
|
|
-import com.dderp.common.datas.ReadOrderOption
|
|
|
-import com.dderp.common.datas.business.PlatformType
|
|
|
import com.dderp.common.entity.base.InvokeCallParams
|
|
|
import com.dderp.common.entity.base.InvokeCallResult
|
|
|
-import com.dderp.common.entity.base.ProcessStringItem
|
|
|
-import com.dderp.common.entity.geo.GeoPoiLocation
|
|
|
-import com.dderp.common.entity.order.*
|
|
|
+import com.dderp.common.entity.order.BusinessOrder
|
|
|
+import com.dderp.common.entity.order.OrderStep
|
|
|
import com.dderp.common.entity.site.ERPTokenUser
|
|
|
import com.dderp.common.entity.store.StorePlatform
|
|
|
-import com.dderp.common.entity.store.ViewStoreInfo
|
|
|
import com.dySweetFishPlugin.elasticsearch.ESClient
|
|
|
import com.dySweetFishPlugin.sql.TableIdService
|
|
|
import com.dySweetFishPlugin.sql.dao.TunaService
|
|
|
@@ -35,14 +31,13 @@ import org.elasticsearch.action.update.UpdateRequestBuilder
|
|
|
import org.elasticsearch.common.xcontent.XContentType
|
|
|
|
|
|
import javax.annotation.Resource
|
|
|
-import java.math.RoundingMode
|
|
|
import java.time.LocalDateTime
|
|
|
import java.time.ZoneOffset
|
|
|
|
|
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
-class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
|
|
|
+class BE_Order_CancelOrder implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
|
|
|
|
|
|
private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
|
|
|
|
|
|
@@ -73,6 +68,9 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
@Resource
|
|
|
private DouyinService douyinService
|
|
|
|
|
|
+ @Resource(name = "APP_HOME")
|
|
|
+ private String appHome
|
|
|
+
|
|
|
@Resource
|
|
|
private TunaService tunaService
|
|
|
|
|
|
@@ -80,7 +78,7 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
|
|
|
@Override
|
|
|
String scriptName() {
|
|
|
- return "订单商户接单"
|
|
|
+ return "商户发起取消订单"
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -92,7 +90,7 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
RetResult<InvokeCallParams> beforeExecute(InvokeCallParams source) {
|
|
|
return super.beforeExecute(source)
|
|
|
}
|
|
|
-//params:{idOrder:xxx}
|
|
|
+ //params:{idOrder:xxx, refundReason:[501,502], description:"超出配送范围"}
|
|
|
RetResult<InvokeCallResult> execute(InvokeCallParams source) {
|
|
|
//秒级时间戳,groovy里面不让用system
|
|
|
long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
|
|
|
@@ -106,34 +104,56 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
RetResult<BusinessOrder> orderResult = orderSearchService.getBusinessOrder(idOrder, currentUser, dataSourceId, supplierCode, null)
|
|
|
if (!orderResult.isSuccess()) return RetResult.<InvokeCallResult> errorT().retinfo(orderResult.retinfo)
|
|
|
|
|
|
+ def refundCodeJsonFile = new File(appHome + File.separator +
|
|
|
+ "conf" + File.separator +
|
|
|
+ "script" + File.separator +
|
|
|
+ supplierCode + File.separator +
|
|
|
+ "scriptFiles" + File.separator +
|
|
|
+ "refundOrderReason.json")
|
|
|
+ def refundCodeArray = jsonSlurper.parse(refundCodeJsonFile)
|
|
|
+
|
|
|
BusinessOrder esOrder = orderResult.result
|
|
|
- esOrder.setOrderStatus(BusinessOrderStatus.accept.value)
|
|
|
+ def legalReasons = (refundCodeArray.find { it["orderStatus"] == esOrder.orderStatus })["refundReason"] as ArrayList
|
|
|
+
|
|
|
+ for (Integer reason in invokeOrder["refundReason"] as ArrayList<Integer>) {
|
|
|
+ if (legalReasons.find { it["code"] as Integer == reason } == null) {
|
|
|
+ return RetResult.<InvokeCallResult> errorT().retinfo("订单状态[" + BusinessOrderStatus.getName(esOrder.orderStatus) +
|
|
|
+ "],不允许以[" + reason + "]取消订单")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ esOrder.setVoidFlag(1)
|
|
|
BusinessOrder.update(esOrder, currentUser.id)
|
|
|
|
|
|
StorePlatform storePlatform = storeService.getStorePlatformInfo(esOrder.incomePlatformId, supplierCode)
|
|
|
if (storePlatform == null) return RetResult.<InvokeCallResult> errorT().retinfo("订单来源平台未知!")
|
|
|
|
|
|
- OrderStep orderStep = orderStepService.parseOrderStep(esOrder.id, 0, "[" + storePlatform.platformName + "]商家接单完成", storePlatform.platformCode, currentUser)
|
|
|
+ OrderStep orderStep = orderStepService.parseOrderStep(esOrder.id, 0,
|
|
|
+ "[" + storePlatform.platformName + "]商家取消订单: " + invokeOrder["description"], storePlatform.platformCode, currentUser)
|
|
|
|
|
|
+ //todo 判断订单目前状态,如果已生成配送单据,则要同步将配送单据取消
|
|
|
|
|
|
- def callSuccess = ["success": false, "errorMsg": ""]
|
|
|
+ def callSuccess = [success: false, errorMsg: ""]
|
|
|
//根据订单来源平台,回调平台的接单接口
|
|
|
switch (storePlatform.platformCode) {
|
|
|
case "DYLK": {
|
|
|
//抖音来客
|
|
|
- def postBody = {
|
|
|
- order_id:
|
|
|
- esOrder.incomePlatformOrderCode
|
|
|
- }
|
|
|
- String responseStr = douyinService.postInvoker("/goodlife/v1/trade/buy/merchant_confirm_order/", jsonConvert.convertTo(postBody))
|
|
|
+ def postBody = [
|
|
|
+ order_id : esOrder.incomePlatformOrderCode,
|
|
|
+ refund_reason: [
|
|
|
+ reason_code: invokeOrder["refundReason"],
|
|
|
+ desc : invokeOrder["description"]
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ String responseStr = douyinService.postInvoker("/goodlife/v1/after_sale/order/apply_refund/", jsonConvert.convertTo(postBody))
|
|
|
def response = jsonSlurper.parseText(responseStr)
|
|
|
- if (response["data"]["error_code"] as Integer == 0) {
|
|
|
+ if (response["extra"]["error_code"] as Integer == 0) {
|
|
|
callSuccess["success"] = true
|
|
|
} else {
|
|
|
//todo 抖音侧调用失败,怎么处理?
|
|
|
- logger.error("[抖音来客]商户接单平台接口调用失败:" + response["data"]["description"] as String)
|
|
|
+ logger.error("[抖音来客]商户接单平台接口调用失败:" + response["extra"]["description"] as String)
|
|
|
callSuccess["success"] = false
|
|
|
- callSuccess["errorMsg"] = "[抖音来客]商户接单平台接口调用失败:" + response["data"]["description"] as String
|
|
|
+ callSuccess["errorMsg"] = "[抖音来客]商户接单平台接口调用失败:" + response["extra"]["description"] as String
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
@@ -151,7 +171,7 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
String.valueOf(esOrder.getId()))
|
|
|
.setDoc(jsonBuilder()
|
|
|
.startObject()
|
|
|
- .field("orderStatus", esOrder.orderStatus)
|
|
|
+ .field("voidFlag", esOrder.voidFlag)
|
|
|
.field("updateBy", esOrder.getUpdateBy())
|
|
|
.field("updateTimeLong", esOrder.getUpdateTimeLong())
|
|
|
.endObject())
|
|
|
@@ -168,12 +188,12 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
BulkResponse bulkResponse = bulkRequest.get();
|
|
|
orderDao = tunaService.generate(OrderDao.class)
|
|
|
if (bulkResponse.hasFailures()) {
|
|
|
- logger.error("商户接单出错:" + bulkResponse.buildFailureMessage());
|
|
|
- return RetResult.<InvokeCallResult> errorT().retinfo("商户接单出错:" + esOrder.orderName);
|
|
|
+ logger.error("商户取消订单出错:" + bulkResponse.buildFailureMessage());
|
|
|
+ return RetResult.<InvokeCallResult> errorT().retinfo("商户取消订单出错:" + esOrder.orderName);
|
|
|
} else {
|
|
|
- logger.info("商户接单成功");
|
|
|
+ logger.info("商户取消订单成功");
|
|
|
//写数据库
|
|
|
- orderDao.acceptBusinessOrder(esOrder,
|
|
|
+ orderDao.voidBusinessOrder(esOrder,
|
|
|
[orderStep],
|
|
|
dataSourceId,
|
|
|
String.valueOf(supplierCode))
|
|
|
@@ -182,7 +202,7 @@ class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeC
|
|
|
return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(jsonConvert.convertTo(esOrder)))
|
|
|
}
|
|
|
} else {
|
|
|
- return RetResult.<InvokeCallResult> errorT().retinfo("商户接单出错:" + callSuccess["errorMsg"]);
|
|
|
+ return RetResult.<InvokeCallResult> errorT().retinfo("商户取消订单出错:" + callSuccess["errorMsg"]);
|
|
|
}
|
|
|
}
|
|
|
}
|