|
|
@@ -94,25 +94,76 @@ class OrderController extends BaseController
|
|
|
//取消订单 ssh 20221231
|
|
|
public function actionCancel()
|
|
|
{
|
|
|
+ $shopAdmin = $this->shopAdmin;
|
|
|
//避免重复提交
|
|
|
$adminId = $this->adminId;
|
|
|
- util::checkRepeatCommit($adminId, 8);
|
|
|
+ util::checkRepeatCommit($adminId, 3);
|
|
|
|
|
|
$get = Yii::$app->request->get();
|
|
|
+ $cashier = $get['cashier'] ?? 0;
|
|
|
+ //是否强制取消订单 0不要强制 1强制,没有关单成功也要取消
|
|
|
+ $forceCancel = $get['forceCancel'] ?? 0;
|
|
|
$id = $get['id'] ?? 0;
|
|
|
$order = OrderClass::getById($id, true);
|
|
|
if ($order->mainId != $this->mainId) {
|
|
|
util::fail('不是你的订单');
|
|
|
}
|
|
|
+ //如果收银台的订单,取消时要关闭拉卡拉的订单
|
|
|
+ if ($cashier == 1) {
|
|
|
+ //已取消,不需要再走下面的流程
|
|
|
+ if ($order->status == 5) {
|
|
|
+ util::complete('已取消');
|
|
|
+ }
|
|
|
+ $orderSn = $order->orderSn ?? '';
|
|
|
+
|
|
|
+ $shop = $this->shop;
|
|
|
+ $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
|
|
|
+ $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
|
|
|
+ $params = [
|
|
|
+ 'appid' => 'OP00002119',
|
|
|
+ 'serial_no' => '018b08cfddbd',
|
|
|
+ 'merchant_no' => $shop->lklSjNo,
|
|
|
+ 'term_no' => $shop->lklScanTermNo,
|
|
|
+ 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
|
|
|
+ 'lklCertificatePath' => $lklCertificatePath,
|
|
|
+ ];
|
|
|
+ $laResource = new Lakala($params);
|
|
|
+
|
|
|
+ // 1. 先查询拉卡拉侧订单状态
|
|
|
+ $queryResponse = $laResource->query(['orderSn' => $orderSn]);
|
|
|
+ //响应CODE为BBS00000,仅表示查到了这笔交易。交易本身的成功与否状态,要查看响应报文中的trade_state这个值
|
|
|
+ if (isset($queryResponse['code']) && $queryResponse['code'] == 'BBS00000') {
|
|
|
+ $tradeState = $queryResponse['resp_data']['trade_state'] ?? '';
|
|
|
+
|
|
|
+ // 订单已支付,拦截取消操作
|
|
|
+ if ($tradeState == 'SUCCESS') {
|
|
|
+ util::fail('已付款,不能取消');
|
|
|
+ }
|
|
|
|
|
|
- $staff = $this->shopAdmin;
|
|
|
+ // 根据拉卡拉聚合支付文档(id=116)及实际情况,判断是否为非终态
|
|
|
+ // INIT:初始化, CREATE:下单成功, DEAL:交易处理中, USERPAYING:支付中, NOTPAY:未支付
|
|
|
+ $pendingStates = ['INIT', 'CREATE', 'DEAL', 'USERPAYING', 'NOTPAY'];
|
|
|
+ if (in_array($tradeState, $pendingStates)) {
|
|
|
+ $closeParams = ['orderSn' => $orderSn];
|
|
|
+ $closeResponse = $laResource->close($closeParams);
|
|
|
+ if (!isset($closeResponse['code']) || $closeResponse['code'] != 'BBS00000') {
|
|
|
+ $msg = $closeResponse['msg'] ?? '关闭失败';
|
|
|
+ noticeUtil::push("拉卡拉聚合支付关单失败:{$orderSn},原因:{$msg} 原单状态:{$tradeState}", '15280215347');
|
|
|
+ if ($forceCancel == 0) {
|
|
|
+ //返回禁止关单
|
|
|
+ util::success(['returnStatus' => 'FORBID']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|
|
|
- OrderClass::setExpire($order, true, $staff);
|
|
|
+ OrderClass::setExpire($order, true, $shopAdmin);
|
|
|
$transaction->commit();
|
|
|
- util::complete();
|
|
|
+ util::complete('已取消');
|
|
|
} catch (\Exception $exception) {
|
|
|
$transaction->rollBack();
|
|
|
Yii::info("取消原因:" . $exception->getMessage());
|