RefundController.php 23 KB

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