| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- /**
- * 供货商冲销凭证接口
- * 用途:创建/按原单列表/详情;方案A凭证,不是负销售单。ssh 冲销单功能
- */
- namespace ghs\controllers;
- use bizGhs\forward\services\ForwardService;
- use bizGhs\order\classes\OrderClass;
- use bizGhs\order\classes\RefundOrderClass;
- use common\components\util;
- use Yii;
- class ForwardController extends BaseController
- {
- /**
- * 创建冲销凭证
- * POST: orderId|refundId|customId, fundType, forwardStock, items[], amount?, remark?
- */
- public function actionCreate()
- {
- $shopAdmin = $this->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);
- }
- }
|