shopAdmin; if (!isset($shopAdmin->super) || intval($shopAdmin->super) !== 1) { util::fail('请超管操作冲销'); } util::checkRepeatCommit($this->shopAdminId, 5); $post = Yii::$app->request->post(); $post['shopId'] = $this->shopId; $post['mainId'] = $this->mainId; $post['sjId'] = $this->sjId; $post['shopAdminId'] = $this->shopAdminId; $post['shopAdminName'] = $shopAdmin->name ?? ''; $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $result = ForwardService::create($post); $transaction->commit(); util::success($result, '冲销成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info('冲销失败:' . $e->getMessage()); util::fail($e->getMessage() ?: '冲销失败'); } } /** * 按原销售单查冲销凭证列表 * GET: orderId */ public function actionListByOrder() { $orderId = Yii::$app->request->get('orderId', 0); $data = ForwardService::listByOrder($orderId, $this->mainId); util::success($data); } /** * 冲销凭证详情 * GET: id */ public function actionDetail() { $id = Yii::$app->request->get('id', 0); $data = ForwardService::detail($id, $this->mainId); util::success($data); } /** * 原单是否可冲销(售后页预检) * GET: orderId */ public function actionCheckEligible() { $orderId = Yii::$app->request->get('orderId', 0); $order = OrderClass::getById($orderId, true); if (empty($order) || intval($order->mainId) !== intval($this->mainId)) { util::fail('没有找到订单'); } $check = ForwardService::checkEligible($order); $check['hasForward'] = intval($order->hasForward ?? 0); $check['forwardPrice'] = $order->forwardPrice ?? '0.00'; $check['actPrice'] = $order->actPrice ?? '0.00'; $check['payWay'] = $order->payWay ?? 0; $check['onlinePay'] = $order->onlinePay ?? 0; $check['debtPrice'] = $order->debtPrice ?? '0.00'; $check['remainDebtPrice'] = $order->remainDebtPrice ?? '0.00'; util::success($check); } /** * 售后是否可转冲销 * GET: refundId */ public function actionCheckRefundEligible() { $refundId = Yii::$app->request->get('refundId', 0); $refund = RefundOrderClass::getById($refundId, true); RefundOrderClass::valid($refund, $this->mainId); if (intval($refund->status) !== RefundOrderClass::STATUS_UN_COMPLETE) { util::success(['ok' => false, 'reason' => '仅待审核售后可转冲销']); } if (!empty($refund->forwardId)) { util::success(['ok' => false, 'reason' => '该售后已转冲销']); } $order = OrderClass::getByCondition(['orderSn' => $refund->relateOrderSn], true); if (empty($order)) { util::fail('没有找到原订单'); } $check = ForwardService::checkEligible($order); $check['refundId'] = $refund->id; $check['refundPrice'] = $refund->refundPrice ?? '0.00'; $check['payWay'] = $order->payWay ?? 0; $check['onlinePay'] = $order->onlinePay ?? 0; $check['orderId'] = $order->id; util::success($check); } }