RefundController.php 23 KB

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