ForwardController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * 供货商冲销凭证接口
  4. * 用途:创建/按原单列表/详情;方案A凭证,不是负销售单。ssh 冲销单功能
  5. */
  6. namespace ghs\controllers;
  7. use bizGhs\forward\services\ForwardService;
  8. use bizGhs\order\classes\OrderClass;
  9. use bizGhs\order\classes\RefundOrderClass;
  10. use common\components\util;
  11. use Yii;
  12. class ForwardController extends BaseController
  13. {
  14. /**
  15. * 创建冲销凭证
  16. * POST: orderId|refundId|customId, fundType, forwardStock, items[], amount?, remark?
  17. */
  18. public function actionCreate()
  19. {
  20. $shopAdmin = $this->shopAdmin;
  21. if (!isset($shopAdmin->super) || intval($shopAdmin->super) !== 1) {
  22. util::fail('请超管操作冲销');
  23. }
  24. util::checkRepeatCommit($this->shopAdminId, 5);
  25. $post = Yii::$app->request->post();
  26. $post['shopId'] = $this->shopId;
  27. $post['mainId'] = $this->mainId;
  28. $post['sjId'] = $this->sjId;
  29. $post['shopAdminId'] = $this->shopAdminId;
  30. $post['shopAdminName'] = $shopAdmin->name ?? '';
  31. $connection = Yii::$app->db;
  32. $transaction = $connection->beginTransaction();
  33. try {
  34. $result = ForwardService::create($post);
  35. $transaction->commit();
  36. util::success($result, '冲销成功');
  37. } catch (\Exception $e) {
  38. $transaction->rollBack();
  39. Yii::info('冲销失败:' . $e->getMessage());
  40. util::fail($e->getMessage() ?: '冲销失败');
  41. }
  42. }
  43. /**
  44. * 按原销售单查冲销凭证列表
  45. * GET: orderId
  46. */
  47. public function actionListByOrder()
  48. {
  49. $orderId = Yii::$app->request->get('orderId', 0);
  50. $data = ForwardService::listByOrder($orderId, $this->mainId);
  51. util::success($data);
  52. }
  53. /**
  54. * 冲销凭证详情
  55. * GET: id
  56. */
  57. public function actionDetail()
  58. {
  59. $id = Yii::$app->request->get('id', 0);
  60. $data = ForwardService::detail($id, $this->mainId);
  61. util::success($data);
  62. }
  63. /**
  64. * 原单是否可冲销(售后页预检)
  65. * GET: orderId
  66. */
  67. public function actionCheckEligible()
  68. {
  69. $orderId = Yii::$app->request->get('orderId', 0);
  70. $order = OrderClass::getById($orderId, true);
  71. if (empty($order) || intval($order->mainId) !== intval($this->mainId)) {
  72. util::fail('没有找到订单');
  73. }
  74. $check = ForwardService::checkEligible($order);
  75. $check['hasForward'] = intval($order->hasForward ?? 0);
  76. $check['forwardPrice'] = $order->forwardPrice ?? '0.00';
  77. $check['actPrice'] = $order->actPrice ?? '0.00';
  78. $check['payWay'] = $order->payWay ?? 0;
  79. $check['onlinePay'] = $order->onlinePay ?? 0;
  80. $check['debtPrice'] = $order->debtPrice ?? '0.00';
  81. $check['remainDebtPrice'] = $order->remainDebtPrice ?? '0.00';
  82. util::success($check);
  83. }
  84. /**
  85. * 售后是否可转冲销
  86. * GET: refundId
  87. */
  88. public function actionCheckRefundEligible()
  89. {
  90. $refundId = Yii::$app->request->get('refundId', 0);
  91. $refund = RefundOrderClass::getById($refundId, true);
  92. RefundOrderClass::valid($refund, $this->mainId);
  93. if (intval($refund->status) !== RefundOrderClass::STATUS_UN_COMPLETE) {
  94. util::success(['ok' => false, 'reason' => '仅待审核售后可转冲销']);
  95. }
  96. if (!empty($refund->forwardId)) {
  97. util::success(['ok' => false, 'reason' => '该售后已转冲销']);
  98. }
  99. $order = OrderClass::getByCondition(['orderSn' => $refund->relateOrderSn], true);
  100. if (empty($order)) {
  101. util::fail('没有找到原订单');
  102. }
  103. $check = ForwardService::checkEligible($order);
  104. $check['refundId'] = $refund->id;
  105. $check['refundPrice'] = $refund->refundPrice ?? '0.00';
  106. $check['payWay'] = $order->payWay ?? 0;
  107. $check['onlinePay'] = $order->onlinePay ?? 0;
  108. $check['orderId'] = $order->id;
  109. util::success($check);
  110. }
  111. }