RefundController.php 24 KB

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