RefundController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. //退款退货
  3. namespace ghs\controllers;
  4. use bizGhs\notify\classes\NotifyClass;
  5. use bizGhs\order\classes\RefundOrderItemClass;
  6. use bizGhs\order\services\RefundOrderService;
  7. use bizGhs\shop\classes\ShopClass;
  8. use bizHd\cg\classes\CgRefundClass;
  9. use bizHd\cg\classes\CgRefundItemClass;
  10. use bizHd\notice\classes\NoticeClass;
  11. use bizHd\purchase\classes\PurchaseClass;
  12. use bizHd\purchase\classes\PurchaseClearClass;
  13. use common\components\dateUtil;
  14. use common\components\imgUtil;
  15. use common\components\stringUtil;
  16. use Yii;
  17. use bizGhs\order\classes\RefundOrderClass;
  18. use common\components\util;
  19. use bizGhs\product\classes\ProductClass;
  20. use bizGhs\order\classes\OrderClass;
  21. use bizGhs\order\services\OrderService;
  22. use bizGhs\order\classes\StockWastageOrderClass;
  23. class RefundController extends BaseController
  24. {
  25. //取消的订单退钱,特殊情况的操作:商家取消订单时,客户同时付款成功了,造成的流程冲突,需要退钱 ssh 20250429
  26. public function actionRefundMoney()
  27. {
  28. $get = Yii::$app->request->get();
  29. $id = $get['id'] ?? '';
  30. $order = OrderClass::getById($id, true);
  31. if (empty($order)) {
  32. util::fail('没有找到订单');
  33. }
  34. if ($order->mainId != $this->mainId) {
  35. util::fail('不是你的订单');
  36. }
  37. $shop = $this->shop;
  38. $purchaseId = $order->purchaseId ?? 0;
  39. $cg = PurchaseClass::getById($purchaseId, true);
  40. if (empty($cg)) {
  41. util::fail('没有找到订单');
  42. }
  43. $respond = CgRefundClass::onlyRefundMoney($shop, $cg);
  44. $status = $respond['status'];
  45. $msg = $respond['msg'];
  46. util::success(['status' => $status], $msg);
  47. }
  48. //修改金额 ssh 20240412
  49. public function actionModifyAmount()
  50. {
  51. $get = Yii::$app->request->get();
  52. $id = $get['id'] ?? 0;
  53. $amount = $get['amount'] ?? 0;
  54. $refund = RefundOrderClass::getById($id, true);
  55. RefundOrderClass::valid($refund, $this->mainId);
  56. if (is_numeric($amount) == false) {
  57. util::fail('请填写金额');
  58. }
  59. if ($refund->status != 0) {
  60. util::fail('待审核订单才能修改');
  61. }
  62. $connection = Yii::$app->db;
  63. $transaction = $connection->beginTransaction();
  64. try {
  65. $refund->refundPrice = $amount;
  66. $refund->save();
  67. $cgRefundId = $refund->cgRefundId ?? 0;
  68. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  69. if (empty($cgRefund)) {
  70. util::fail('没有找到退款信息');
  71. }
  72. $cgRefund->refundPrice = $amount;
  73. $cgRefund->save();
  74. $transaction->commit();
  75. util::complete();
  76. } catch (\Exception $e) {
  77. $transaction->rollBack();
  78. Yii::info("操作失败原因:" . $e->getMessage());
  79. util::fail('操作失败');
  80. }
  81. }
  82. //修改申请原因 ssh 20240302
  83. public function actionModifyCause()
  84. {
  85. $staff = $this->shopAdmin;
  86. if (isset($staff->finance) == false || $staff->finance == 0) {
  87. util::fail('请有财务权限的人修改');
  88. }
  89. $get = Yii::$app->request->get();
  90. $id = $get['id'] ?? 0;
  91. $cause = $get['cause'] ?? 0;
  92. $refund = RefundOrderClass::getById($id, true);
  93. RefundOrderClass::valid($refund, $this->mainId);
  94. $refund->cause = $cause;
  95. $refund->save();
  96. $orderSn = $refund->orderSn ?? '';
  97. RefundOrderItemClass::updateByCondition(['orderSn' => $orderSn], ['cause' => $cause]);
  98. $cgRefundId = $refund->cgRefundId ?? 0;
  99. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  100. if (empty($cgRefund)) {
  101. util::fail('没有找到退款信息');
  102. }
  103. $cgRefund->cause = $cause;
  104. $cgRefund->save();
  105. $cgOrderSn = $cgRefund->orderSn ?? '';
  106. CgRefundItemClass::updateByCondition(['orderSn' => $cgOrderSn], ['cause' => $cause]);
  107. util::complete('修改成功');
  108. }
  109. //审核通过 ssh 20230811
  110. public function actionPass()
  111. {
  112. $shopAdmin = $this->shopAdmin;
  113. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  114. util::fail('无法操作');
  115. }
  116. //多处要同步修改ghs_refund ssh 20250331
  117. if (getenv('YII_ENV') == 'production') {
  118. //小向花卉开单售后控制
  119. if ($this->mainId == 23390) {
  120. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960])) {
  121. util::fail('你不能售后哦');
  122. }
  123. //小向花卉售后必须备注
  124. $remark = $post['remark'] ?? '';
  125. if (empty($remark)) {
  126. util::fail('请填写备注007');
  127. }
  128. }
  129. //国恋只有指定人有退款权限
  130. if ($this->mainId == 7704) {
  131. if (in_array($this->shopAdminId, [133727, 133545]) == false) {
  132. util::fail('无法操作。。');
  133. }
  134. }
  135. //小齐出车指定人可以售后
  136. if ($this->mainId == 42680) {
  137. if (!in_array($this->adminId, [40144])) {
  138. util::fail('你不能售后哦。。');
  139. }
  140. }
  141. }
  142. $get = Yii::$app->request->get();
  143. $id = $get['id'] ?? 0;
  144. $version = $get['version'] ?? 0;
  145. $confirm = $get['confirm'] ?? 0;
  146. $refund = RefundOrderClass::getById($id, true);
  147. RefundOrderClass::valid($refund, $this->mainId);
  148. $relateOrderSn = $refund->relateOrderSn ?? '';
  149. if (empty($relateOrderSn)) {
  150. util::fail('没有订单信息');
  151. }
  152. $refundList = RefundOrderClass::getAllByCondition(['relateOrderSn' => $relateOrderSn], null, '*', null, true);
  153. $has = false;
  154. if (!empty($refundList)) {
  155. foreach ($refundList as $single) {
  156. if ($single->status == 1) {
  157. $has = true;
  158. }
  159. }
  160. }
  161. if ($has == true) {
  162. if ($version == 0) {
  163. util::fail('请先升级系统');
  164. }
  165. if ($confirm == 0) {
  166. util::success(['error' => 'notFirstApply']);
  167. }
  168. }
  169. $connection = Yii::$app->db;
  170. $transaction = $connection->beginTransaction();
  171. try {
  172. RefundOrderService::passRefund($refund);
  173. $transaction->commit();
  174. $staff = $this->shopAdmin;
  175. $staffId = $staff->id;
  176. $staffName = $staff->name ?? '';
  177. $refund->shopAdminId = $staffId;
  178. $refund->shopAdminName = $staffName;
  179. $refund->save();
  180. //审核结果通知
  181. $cgRefundId = $refund->cgRefundId ?? 0;
  182. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  183. $cgShopId = $cgRefund->shopId ?? 0;
  184. $cgShop = ShopClass::getById($cgShopId, true);
  185. if (!empty($cgRefund) && !empty($cgShop)) {
  186. NoticeClass::afterSaleNotice($cgShop, $cgRefund);
  187. }
  188. util::complete('操作成功');
  189. } catch (\Exception $e) {
  190. $transaction->rollBack();
  191. Yii::info("操作失败原因:" . $e->getMessage());
  192. util::fail('操作失败');
  193. }
  194. }
  195. //驳回 ssh 20230813
  196. public function actionReject()
  197. {
  198. $shopAdmin = $this->shopAdmin;
  199. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  200. util::fail('无法操作');
  201. }
  202. //多处要同步修改ghs_refund ssh 20250331
  203. if (getenv('YII_ENV') == 'production') {
  204. //小向花卉开单售后控制
  205. if ($this->mainId == 23390) {
  206. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960])) {
  207. util::fail('你不能售后哦。。');
  208. }
  209. //小向花卉售后必须备注
  210. $remark = $post['remark'] ?? '';
  211. if (empty($remark)) {
  212. util::fail('请填写备注007');
  213. }
  214. }
  215. //国恋只有指定人有退款权限
  216. if ($this->mainId == 7704) {
  217. if (in_array($this->shopAdminId, [133727, 133545]) == false) {
  218. util::fail('无法操作。。');
  219. }
  220. }
  221. //小齐出车指定人可以售后
  222. if ($this->mainId == 42680) {
  223. if (!in_array($this->adminId, [40144])) {
  224. util::fail('你不能售后哦。。。');
  225. }
  226. }
  227. }
  228. $post = Yii::$app->request->post();
  229. $id = $post['id'] ?? 0;
  230. $rejectReason = $post['rejectReason'] ?? '';
  231. $refund = RefundOrderClass::getById($id, true);
  232. RefundOrderClass::valid($refund, $this->mainId);
  233. $connection = Yii::$app->db;
  234. $transaction = $connection->beginTransaction();
  235. try {
  236. RefundOrderClass::rejectRefund($refund, $rejectReason);
  237. $transaction->commit();
  238. $staff = $this->shopAdmin;
  239. $staffId = $staff->id;
  240. $staffName = $staff->name ?? '';
  241. $refund->shopAdminId = $staffId;
  242. $refund->shopAdminName = $staffName;
  243. $refund->save();
  244. //审核结果通知
  245. $cgRefundId = $refund->cgRefundId ?? 0;
  246. $cgRefund = CgRefundClass::getById($cgRefundId, true);
  247. $cgShopId = $cgRefund->shopId ?? 0;
  248. $cgShop = ShopClass::getById($cgShopId, true);
  249. if (!empty($cgRefund) && !empty($cgShop)) {
  250. NoticeClass::afterSaleNotice($cgShop, $cgRefund);
  251. }
  252. util::complete('操作成功');
  253. } catch (\Exception $e) {
  254. $transaction->rollBack();
  255. Yii::info("操作失败原因:" . $e->getMessage());
  256. util::fail('操作失败');
  257. }
  258. }
  259. //退款之后报损 ssh 20230409
  260. public function actionRefundWaste()
  261. {
  262. $shopAdmin = $this->shopAdmin;
  263. if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
  264. util::fail('超管才能报损');
  265. }
  266. $post = Yii::$app->request->post();
  267. $refundItemId = $post['refundItemId'] ?? 0;
  268. $wasteProductId = $post['wasteProductId'] ?? 0;
  269. $wasteNum = $post['wasteNum'] ?? 0;
  270. unset($post['refundId']);
  271. unset($post['wasteNum']);
  272. unset($post['wasteProductId']);
  273. $productInfo = ProductClass::getById($wasteProductId, true);
  274. if (empty($productInfo)) {
  275. util::fail('没有找到花材');
  276. }
  277. $ptItemId = $productInfo->itemId ?? 0;
  278. $ratio = $productInfo->ratio ?? 20;
  279. $refundItem = RefundOrderItemClass::getById($refundItemId, true);
  280. if (empty($refundItem)) {
  281. util::fail('没有找到退货信息');
  282. }
  283. if ($refundItem->mainId != $this->mainId) {
  284. util::fail('不是您的退款信息');
  285. }
  286. $unitType = $refundItem->xhUnitType ?? 0;
  287. if ($unitType == 1) {
  288. util::fail('无法报损');
  289. }
  290. $refundNum = $refundItem->xhNum ?? 0;
  291. $hasWasteNum = $refundItem->xhWasteNum ?? 0;
  292. $remainNum = bcsub($refundNum, $hasWasteNum);
  293. if ($wasteNum > $remainNum) {
  294. util::fail('剩余可报损数量 ' . $remainNum);
  295. }
  296. $productList = [['productId' => $wasteProductId, 'bigNum' => $wasteNum, 'smallNum' => 0, 'classId' => 0, 'itemId' => $ptItemId, 'ratio' => $ratio]];
  297. $post['shopId'] = $this->shopId;
  298. $post['sjId'] = $this->sjId;
  299. $post['mainId'] = $this->mainId;
  300. $post['shopAdminId'] = $this->shopAdminId;
  301. $shopAdmin = $this->shopAdmin;
  302. $adminName = $shopAdmin['name'] ?? '';
  303. $post['shopAdminName'] = $adminName;
  304. //属于售后报损
  305. $post['saleType'] = 1;
  306. $connection = Yii::$app->db;
  307. $transaction = $connection->beginTransaction();
  308. try {
  309. $refundItem->xhWasteNum = bcadd($refundItem->xhWasteNum, $wasteNum);
  310. $refundItem->save();
  311. $post['product'] = $productList;
  312. $return = StockWastageOrderClass::addOrder($post);
  313. $transaction->commit();
  314. util::success($return);
  315. } catch (\Exception $e) {
  316. $transaction->rollBack();
  317. Yii::info("报损失败原因:" . $e->getMessage());
  318. util::fail('报损失败');
  319. }
  320. }
  321. //列表
  322. public function actionList()
  323. {
  324. $get = Yii::$app->request->get();
  325. $where = [];
  326. $where['mainId'] = $this->mainId;
  327. $orderSn = $get['orderSn'] ?? '';
  328. if (!empty($orderSn)) {
  329. $where['relateOrderSn'] = $orderSn;
  330. }
  331. $searchTime = $get['searchTime'] ?? '';
  332. if (!empty($searchTime)) {
  333. $startTime = $get['startTime'] ?? '';
  334. $endTime = $get['endTime'] ?? '';
  335. $period = dateUtil::formatTime($searchTime, $startTime, $endTime);
  336. $where['orderTime'] = ['between', [$period['startTime'], $period['endTime']]];
  337. }
  338. $refundSearchTime = $get['refundSearchTime'] ?? '';
  339. if (!empty($refundSearchTime)) {
  340. $startTime = $get['refundStartTime'] ?? '';
  341. $endTime = $get['refundEndTime'] ?? '';
  342. $period = dateUtil::formatTime($refundSearchTime, $startTime, $endTime);
  343. $where['addTime'] = ['between', [$period['startTime'], $period['endTime']]];
  344. }
  345. $customId = $get['customId'] ?? '';
  346. if (!empty($customId)) {
  347. $where['customId'] = $customId;
  348. }
  349. $shopAdminId = $get['shopAdminId'] ?? 0;
  350. if (!empty($shopAdminId)) {
  351. $where['shopAdminId'] = $shopAdminId;
  352. }
  353. $status = $get['status'] ?? -1;
  354. if ($status > -1) {
  355. $where['status'] = $status;
  356. }
  357. $export = $get['export'] ?? 0;
  358. if ($export == 1) {
  359. if (isset($where['orderTime']) == false && isset($where['addTime']) == false) {
  360. util::fail('请选时间');
  361. }
  362. ini_set('memory_limit', '2045M');
  363. set_time_limit(0);
  364. if (isset($where['orderTime'])) {
  365. $start = $where['orderTime'][1][0];
  366. $end = $where['orderTime'][1][1];
  367. $monthTime = bcmul(31, 86400);
  368. $startArea = strtotime($start);
  369. $endArea = strtotime($end);
  370. $diff = bcsub($endArea, $startArea);
  371. if ($diff > $monthTime) {
  372. util::fail('最长可导出一个月');
  373. }
  374. }
  375. if (isset($where['addTime'])) {
  376. $start = $where['addTime'][1][0];
  377. $end = $where['addTime'][1][1];
  378. $monthTime = bcmul(31, 86400);
  379. $startArea = strtotime($start);
  380. $endArea = strtotime($end);
  381. $diff = bcsub($endArea, $startArea);
  382. if ($diff > $monthTime) {
  383. util::fail('最长可导出一个月');
  384. }
  385. }
  386. }
  387. $respond = RefundOrderClass::getOrderList($where);
  388. if ($export == 1) {
  389. RefundOrderClass::exportRefundData($respond, $this->mainId);
  390. }
  391. util::success($respond);
  392. }
  393. //主要根据花材找退款记录 ssh 20240229
  394. public function actionGetListByItem()
  395. {
  396. $get = Yii::$app->request->get();
  397. $where = [];
  398. $where['mainId'] = $this->mainId;
  399. $status = $get['status'] ?? -1;
  400. $cause = $get['cause'] ?? -1;
  401. if ($status > -1) {
  402. $where['status'] = $status;
  403. }
  404. $string = $get['ids'];
  405. $ids = json_decode($string, true);
  406. if (!empty($ids)) {
  407. $productIds = [];
  408. $itemList = ProductClass::getAllByCondition(['mainId' => $this->mainId, 'classId' => ['in', $ids]], null, 'id', 'id');
  409. if (!empty($itemList)) {
  410. $productIds = array_keys($itemList);
  411. }
  412. if (empty($productIds)) {
  413. util::success(['list' => [], 'moreData' => 0, 'totalAmount' => 0, 'totalNum' => 0, 'totalPage' => 1]);
  414. }
  415. $where['productId'] = ['in', $productIds];
  416. }
  417. if ($cause > -1) {
  418. $where['cause'] = $cause;
  419. }
  420. $searchTime = isset($get['searchTime']) && !empty($get['searchTime']) ? $get['searchTime'] : 'today';
  421. $startTime = $get['startTime'] ?? '';
  422. $endTime = $get['endTime'] ?? '';
  423. $period = dateUtil::formatTime($searchTime, $startTime, $endTime, true);
  424. $start = $period['startTime'];
  425. $end = $period['endTime'];
  426. $currentStartDate = date('Y-m-d', strtotime($start));
  427. $currentEndDate = date('Y-m-d', strtotime($end));
  428. $currentStartTime = $currentStartDate . ' 00:00:00';
  429. $currentEndTime = $currentEndDate . ' 23:59:59';
  430. $where['addTime'] = ['between', [$currentStartTime, $currentEndTime]];
  431. $list = RefundOrderItemClass::getRefundItemList($where);
  432. util::success($list);
  433. }
  434. public function actionDetail()
  435. {
  436. $id = Yii::$app->request->get('id', 0);
  437. $refund = RefundOrderClass::getById($id);
  438. if (empty($refund)) {
  439. util::fail('没有找到退款信息');
  440. }
  441. if (isset($refund['mainId']) == false || $refund['mainId'] != $this->mainId) {
  442. util::fail('没有权限');
  443. }
  444. $imgString = $refund['imgList'] ?? '';
  445. $relateOrderSn = $refund['relateOrderSn'] ?? '';
  446. $order = OrderClass::getByCondition(['orderSn' => $relateOrderSn], true);
  447. if (empty($order)) {
  448. util::fail('数据出错了');
  449. }
  450. $refund['relateOrderId'] = $order->id;
  451. if (!empty($imgString)) {
  452. $imgArr = json_decode($imgString, true);
  453. $smallImgList = [];
  454. $bigImgList = [];
  455. if (!empty($imgArr)) {
  456. foreach ($imgArr as $image) {
  457. $smallImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_130,w_130";
  458. $bigImg = imgUtil::groupImg($image) . "?x-oss-process=image/resize,m_fill,h_700,w_700";
  459. $smallImgList[] = $smallImg;
  460. $bigImgList[] = $bigImg;
  461. }
  462. }
  463. $refund['imgList'] = $imgArr;
  464. $refund['smallImgList'] = $smallImgList;
  465. $refund['bigImgList'] = $bigImgList;
  466. }
  467. $orderSn = $refund['orderSn'] ?? '';
  468. $itemList = RefundOrderItemClass::getOrderItemDetail($orderSn);
  469. $staff = $this->shopAdmin;
  470. $staffId = $this->shopAdminId;
  471. $notify = NotifyClass::getByCondition(['staffId' => $staffId, 'type' => 0, 'targetId' => $id], true);
  472. if (!empty($notify)) {
  473. if ($notify->read == 0) {
  474. $notify->read = 1;
  475. $notify->save();
  476. $notifyNum = $staff->notifyNum;
  477. if ($notifyNum > 0) {
  478. $notifyNum--;
  479. $staff->notifyNum = $notifyNum;
  480. $staff->save();
  481. }
  482. }
  483. }
  484. util::success(['info' => $refund, 'itemList' => $itemList]);
  485. }
  486. //退款 lqh 2021.6.25
  487. public function actionCreateOrder()
  488. {
  489. $post = Yii::$app->request->post();
  490. $shopAdmin = $this->shopAdmin;
  491. if (isset($shopAdmin['super']) == false || $shopAdmin['super'] != 1) {
  492. util::fail('超管才能操作退款');
  493. }
  494. //多处要同步修改ghs_refund ssh 20250331
  495. if (getenv('YII_ENV') == 'production') {
  496. //小向花卉开单售后控制
  497. if ($this->mainId == 23390) {
  498. if (!in_array($this->adminId, [24043, 24585, 24586, 24654, 24115, 23960])) {
  499. util::fail('你不能售后哈。。');
  500. }
  501. //小向花卉售后必须备注
  502. $remark = $post['remark'] ?? '';
  503. if (empty($remark)) {
  504. util::fail('请填写备注007');
  505. }
  506. }
  507. //国恋只有指定人有退款权限
  508. if ($this->mainId == 7704) {
  509. if (in_array($this->shopAdminId, [133727, 133545]) == false) {
  510. util::fail('无法操作。。');
  511. }
  512. }
  513. //小齐出车指定人可以售后
  514. if ($this->mainId == 42680) {
  515. if (!in_array($this->adminId, [40144])) {
  516. util::fail('你不能售后哦。。');
  517. }
  518. }
  519. }
  520. $id = isset($post['id']) ? $post['id'] : 0;
  521. $refundType = $post['refundType'] ?? 1;
  522. //避免网络延迟,暂时重复申请
  523. $cacheKey = 'ghs_order_refund_' . $id;
  524. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  525. if (!empty($has)) {
  526. util::fail('请5秒之后再提交');
  527. }
  528. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  529. $connection = Yii::$app->db;
  530. $transaction = $connection->beginTransaction();
  531. try {
  532. if ($refundType == RefundOrderClass::REFUND_TYPE_MONEY_GOOD) {
  533. //花材列表结构
  534. // [{productId:0,num:1,unitType:0,unitPrice:12,unitName:'扎'}]
  535. $productJson = $post['product'] ?? '';
  536. if (empty($productJson)) {
  537. util::fail('请选择花材');
  538. }
  539. $productList = json_decode($productJson, true);
  540. if (!is_array($productList)) {
  541. util::fail('请选择花材哦');
  542. }
  543. $post['product'] = $productList;
  544. } else {
  545. //仅退款花材直接设置为空
  546. $post['product'] = [];
  547. }
  548. $post['price'] = $post['price'] ?? 0;
  549. if ($post['price'] <= 0) {
  550. util::fail("退款金额不能小于0");
  551. }
  552. $post['shopId'] = $this->shopId;
  553. $post['sjId'] = $this->sjId;
  554. $post['shopAdminId'] = $this->shopAdminId;
  555. $post['mainId'] = $this->mainId;
  556. $shopAdmin = $this->shopAdmin;
  557. $adminName = $shopAdmin['name'] ?? '';
  558. $post['shopAdminName'] = $adminName;
  559. $respond = OrderService::refund($id, $post);
  560. $refundId = $respond->id;
  561. $refundInfo = RefundOrderClass::getById($refundId, true);
  562. RefundOrderService::passRefund($refundInfo);
  563. $transaction->commit();
  564. util::success($respond);
  565. } catch (\Exception $exception) {
  566. $transaction->rollBack();
  567. Yii::info("退款出错了,报错信息:" . $exception->getMessage());
  568. util::fail('操作失败');
  569. }
  570. }
  571. }