CgRefundController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\cg\classes\CgRefundClass;
  4. use bizHd\cg\classes\CgRefundItemClass;
  5. use bizHd\cg\services\CgRefundService;
  6. use bizHd\purchase\classes\PurchaseClass;
  7. use common\components\imgUtil;
  8. use Yii;
  9. use common\components\util;
  10. class CgRefundController extends BaseController
  11. {
  12. public $guestAccess = ['list', 'get-refund-data'];
  13. //申请退款 ssh 20230807
  14. public function actionCreateRefund()
  15. {
  16. $post = Yii::$app->request->post();
  17. $id = isset($post['id']) ? $post['id'] : 0;
  18. $cg = PurchaseClass::getById($id, true);
  19. if (empty($cg)) {
  20. util::fail('没有找到采购单');
  21. }
  22. if ($cg->mainId != $this->mainId) {
  23. util::fail('没有权限操作');
  24. }
  25. if ($cg->status != PurchaseClass::STATUS_COMPLETE) {
  26. util::fail("完成的订单才能申请退货退款");
  27. }
  28. $connection = Yii::$app->db;
  29. $transaction = $connection->beginTransaction();
  30. try {
  31. //退款类型 1退货并退款 2 仅退款
  32. $refundType = $post['refundType'] ?? 1;
  33. if ($refundType == CgRefundClass::REFUND_TYPE_MONEY_GOOD) {
  34. //花材列表结构
  35. // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}] productId 花材id num 退货数 unitType 大小单位0大1小 unitPrice 售价 unitName单位名称
  36. $productJson = $post['product'] ?? '';
  37. if (empty($productJson)) {
  38. util::fail('请选择要退款的花材');
  39. }
  40. $productList = json_decode($productJson, true);
  41. if (!is_array($productList)) {
  42. util::fail('请选择要退款的花材哦!');
  43. }
  44. $post['product'] = $productList;
  45. } else {
  46. //仅退款花材直接设置为空
  47. $post['product'] = [];
  48. }
  49. $post['price'] = $post['price'] ?? 0;
  50. if ($post['price'] <= 0) {
  51. util::fail("退款金额不能小于0");
  52. }
  53. if (bccomp($post['price'], $cg->realPrice, 2) == 1) {
  54. util::fail("退款金额超过订单金额");
  55. }
  56. $post['shopId'] = $this->shopId;
  57. $post['sjId'] = $this->sjId;
  58. $post['shopAdminId'] = $this->shopAdminId;
  59. $post['mainId'] = $this->mainId;
  60. $shopAdmin = $this->shopAdmin;
  61. $adminName = $shopAdmin['name'] ?? '';
  62. $post['shopAdminName'] = $adminName;
  63. $respond = CgRefundService::createOrder($post, $cg);
  64. $transaction->commit();
  65. util::success($respond);
  66. } catch (\Exception $exception) {
  67. $transaction->rollBack();
  68. Yii::info("申请出错了,报错信息:" . $exception->getMessage());
  69. util::fail('申请失败');
  70. }
  71. }
  72. //列表
  73. public function actionList()
  74. {
  75. $get = Yii::$app->request->get();
  76. $where = [];
  77. $cgId = $get['cgId'] ?? 0;
  78. if (!empty($cgId)) {
  79. $where['cgId'] = $cgId;
  80. }
  81. $list = CgRefundClass::getRefundList($where);
  82. util::success($list);
  83. }
  84. //根据采购单查退款信息 ssh 20210908
  85. public function actionGetRefundData()
  86. {
  87. $id = Yii::$app->request->get('id', 0);
  88. $refund = CgRefundClass::getById($id, true);
  89. //CgRefundClass::valid($refund, $this->mainId);
  90. $cgId = $refund->cgId ?? 0;
  91. $cg = PurchaseClass::getById($cgId, true);
  92. if (empty($refund)) {
  93. util::fail('没有退款信息');
  94. }
  95. $orderSn = $refund->orderSn ?? '';
  96. $cgItemList = CgRefundItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*');
  97. if (!empty($cgItemList)) {
  98. foreach ($cgItemList as $key => $item) {
  99. $cover = $item['cover'] ?? '';
  100. $shortCover = $cover;
  101. $bigCover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  102. $cover = imgUtil::groupImg($shortCover) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  103. $cgItemList[$key]['cover'] = $cover;
  104. $cgItemList[$key]['bigCover'] = $bigCover;
  105. $cgItemList[$key]['shortCover'] = $shortCover;
  106. $cgItemList[$key]['itemNum'] = isset($item['itemNum']) ? floatval($item['itemNum']) : 0;
  107. }
  108. }
  109. util::success(['info' => $refund, 'itemList' => $cgItemList, 'cgInfo' => $cg]);
  110. }
  111. //根据退款id查退款信息 ssh 20210809
  112. public function actionGetInfo()
  113. {
  114. $id = Yii::$app->request->get('id', 0);
  115. }
  116. }