CgRefundController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\cg\classes\CgRefundClass;
  4. use bizGhs\cg\classes\CgRefundItemClass;
  5. use bizGhs\cg\services\CgRefundService;
  6. use bizGhs\order\classes\PurchaseOrderClass;
  7. use common\components\imgUtil;
  8. use common\components\util;
  9. use Yii;
  10. class CgRefundController extends BaseController
  11. {
  12. //详情 ssh 20220910
  13. public function actionGetRefundFullInfo()
  14. {
  15. $get = Yii::$app->request->get();
  16. $id = $get['id'] ?? 0;
  17. $refund = CgRefundClass::getById($id, true);
  18. CgRefundClass::valid($refund, $this->mainId);
  19. $refundSn = $refund->refundSn ?? '';
  20. $itemList = CgRefundItemClass::getAllByCondition(['refundSn' => $refundSn], null, '*');
  21. if (!empty($itemList)) {
  22. foreach ($itemList as $key => $item) {
  23. $shortCover = $item['cover'] ?? '';
  24. $itemList[$key]['cover'] = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  25. }
  26. }
  27. util::success(['info' => $refund, 'itemList' => $itemList]);
  28. }
  29. //记录,有重复方法,需要同步修改cg_refund_list ssh 20240817
  30. public function actionGetRefundList()
  31. {
  32. $get = Yii::$app->request->get();
  33. $where = [];
  34. $where['mainId'] = $this->mainId;
  35. $relateOrderSn = $get['relateOrderSn'] ?? '';
  36. if (!empty($relateOrderSn)) {
  37. $where['relateOrderSn'] = $relateOrderSnf;
  38. }
  39. $list = CgRefundClass::getRefundList($where);
  40. util::success($list);
  41. }
  42. //记录,有重复方法,需要同步修改cg_refund_list ssh 20240817
  43. public function actionList()
  44. {
  45. $get = Yii::$app->request->get();
  46. $where = [];
  47. $where['mainId'] = $this->mainId;
  48. $relateOrderSn = $get['relateOrderSn'] ?? '';
  49. if (!empty($relateOrderSn)) {
  50. $where['relateOrderSn'] = $relateOrderSn;
  51. }
  52. $list = CgRefundClass::getRefundList($where);
  53. util::success($list);
  54. }
  55. //退款 ssh 20220909
  56. public function actionCreateOrder()
  57. {
  58. $shopAdmin = $this->shopAdmin;
  59. if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
  60. util::fail('超管才能操作退款');
  61. }
  62. $connection = Yii::$app->db;
  63. $transaction = $connection->beginTransaction();
  64. try {
  65. $post = Yii::$app->request->post();
  66. $id = isset($post['id']) ? $post['id'] : 0;
  67. $order = PurchaseOrderClass::getLockById($id);
  68. if ($order->mainId != $this->mainId) {
  69. util::fail('没有权限');
  70. }
  71. if ($order->status != PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  72. util::fail('已完成订单才能申请退货退款');
  73. }
  74. if ($order->debt != 1) {
  75. util::fail('欠款单才能申请退货退款');
  76. }
  77. //退款类型 1退货并退款 2 仅退款
  78. $refundType = $post['refundType'] ?? 1;
  79. if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
  80. //花材列表结构
  81. // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
  82. $productJson = $post['product'] ?? '';
  83. if (empty($productJson)) {
  84. util::fail('请选择花材');
  85. }
  86. $productList = json_decode($productJson, true);
  87. if (!is_array($productList)) {
  88. util::fail('请选择花材哦');
  89. }
  90. $post['product'] = $productList;
  91. } else {
  92. //仅退款花材直接设置为空
  93. $post['product'] = [];
  94. }
  95. $post['price'] = $post['price'] ?? 0;
  96. if ($post['price'] <= 0) {
  97. util::fail("退款金额不能小于0");
  98. }
  99. if (bccomp($post['price'], $order->realPrice, 2) == 1) {
  100. util::fail("退款金额超过订单金额");
  101. }
  102. $post['shopId'] = $this->shopId;
  103. $post['shop'] = $this->shop;
  104. $post['sjId'] = $this->sjId;
  105. $post['shopAdminId'] = $this->shopAdminId;
  106. $post['mainId'] = $this->mainId;
  107. $shopAdmin = $this->shopAdmin;
  108. $adminName = $shopAdmin['name'] ?? '';
  109. $post['shopAdminName'] = $adminName;
  110. CgRefundService::addRefund($order, $post);
  111. $transaction->commit();
  112. } catch (\Exception $exception) {
  113. $transaction->rollBack();
  114. Yii::info("退款申请出错了,报错信息:" . $exception->getMessage());
  115. util::fail('操作失败');
  116. }
  117. util::complete();
  118. }
  119. }