request->get(); $ghsId = $get['ghsId'] ?? 0; $ghs = GhsClass::getById($ghsId, true); GhsClass::valid($ghs, $this->shopId); $where = []; $where['ghsId'] = $ghsId; $list = GhsRechargeClass::getRechargeList($where); util::success($list); } /** * 花店端:对已付款充值退款(财务权限),经 customRechargeId 走统一退款逻辑。 */ public function actionRefund() { $staff = $this->shopAdmin; if (!isset($staff->finance) || intval($staff->finance) === 0) { util::fail('请有财务权限的人操作'); } $post = Yii::$app->request->post(); $id = intval($post['id'] ?? 0); if ($id <= 0) { util::fail('参数错误'); } $ghsRecharge = GhsRechargeClass::getById($id, true); if (empty($ghsRecharge)) { util::fail('没有找到充值记录'); } $ghsId = intval($ghsRecharge->ghsId ?? 0); $ghs = GhsClass::getById($ghsId, true); if (empty($ghs)) { util::fail('没有找到供货商'); } GhsClass::valid($ghs, $this->shopId); $customRechargeId = intval($ghsRecharge->customRechargeId ?? 0); if ($customRechargeId <= 0) { util::fail('充值记录不完整,无法退款'); } $customRecharge = CustomRechargeClass::getById($customRechargeId, true); if (empty($customRecharge)) { util::fail('没有找到对应充值单'); } $ghsShopId = intval($customRecharge->shopId ?? ($ghs->shopId ?? 0)); $ghsShop = ShopClass::getById($ghsShopId, true); if (empty($ghsShop)) { util::fail('没有找到供货商门店'); } $cacheKey = 'hd_ghs_recharge_refund_' . $id; $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (!empty($has)) { util::fail('请5秒之后再提交'); } Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']); $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { CustomRechargeClass::refundPaidRecharge($customRechargeId, $ghsShop, $staff); $transaction->commit(); util::complete('退款成功'); } catch (\Exception $e) { $transaction->rollBack(); Yii::info('花店充值退款失败:' . $e->getMessage()); util::fail($e->getMessage() ?: '退款失败'); } } }