CgRefundController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. //记录 ssh 20220910
  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'] = $relateOrderSn;
  38. }
  39. $list = CgRefundClass::getRefundList($where);
  40. util::success($list);
  41. }
  42. //退款 ssh 20220909
  43. public function actionCreateOrder()
  44. {
  45. $shopAdmin = $this->shopAdmin;
  46. if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
  47. util::fail('超管才能操作退款');
  48. }
  49. $connection = Yii::$app->db;
  50. $transaction = $connection->beginTransaction();
  51. try {
  52. $post = Yii::$app->request->post();
  53. $id = isset($post['id']) ? $post['id'] : 0;
  54. $order = PurchaseOrderClass::getLockById($id);
  55. if ($order->mainId != $this->mainId) {
  56. util::fail('没有权限');
  57. }
  58. if ($order->status != PurchaseOrderClass::PURCHASE_ORDER_STATUS_COMPLETE) {
  59. util::fail('已完成订单才能申请退货退款');
  60. }
  61. if ($order->debt != 1) {
  62. util::fail('欠款单才能申请退货退款');
  63. }
  64. //退款类型 1退货并退款 2 仅退款
  65. $refundType = $post['refundType'] ?? 1;
  66. if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
  67. //花材列表结构
  68. // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
  69. $productJson = $post['product'] ?? '';
  70. if (empty($productJson)) {
  71. util::fail('请选择花材');
  72. }
  73. $productList = json_decode($productJson, true);
  74. if (!is_array($productList)) {
  75. util::fail('请选择花材哦');
  76. }
  77. $post['product'] = $productList;
  78. } else {
  79. //仅退款花材直接设置为空
  80. $post['product'] = [];
  81. }
  82. $post['price'] = $post['price'] ?? 0;
  83. if ($post['price'] <= 0) {
  84. util::fail("退款金额不能小于0");
  85. }
  86. if (bccomp($post['price'], $order->realPrice, 2) == 1) {
  87. util::fail("退款金额超过订单金额");
  88. }
  89. $post['shopId'] = $this->shopId;
  90. $post['sjId'] = $this->sjId;
  91. $post['shopAdminId'] = $this->shopAdminId;
  92. $post['mainId'] = $this->mainId;
  93. $shopAdmin = $this->shopAdmin;
  94. $adminName = $shopAdmin['name'] ?? '';
  95. $post['shopAdminName'] = $adminName;
  96. CgRefundService::addRefund($order, $post);
  97. $transaction->commit();
  98. } catch (\Exception $exception) {
  99. $transaction->rollBack();
  100. Yii::info("退款申请出错了,报错信息:" . $exception->getMessage());
  101. util::fail('操作失败');
  102. }
  103. util::complete();
  104. }
  105. }