RefundController.php 24 KB

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