| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace hd\controllers;
- use bizHd\order\classes\ScanPayClass;
- use bizHd\order\classes\ScanPayRefundClass;
- use common\components\util;
- use Yii;
- class ScanPayController extends BaseController
- {
- public $guestAccess = [];
- public function actionList()
- {
- $get = Yii::$app->request->get();
- $status = $get['status'] ?? 0;
- $where = [];
- $where['mainId'] = $this->mainId;
- if (!empty($status)) {
- $where['status'] = $status;
- }
- $list = ScanPayClass::getPayList($where);
- util::success($list);
- }
- public function actionDetail()
- {
- $get = Yii::$app->request->get();
- $id = $get['id'] ?? 0;
- $detail = ScanPayClass::getDetail($id, $this->mainId);
- util::success($detail);
- }
- public function actionRefund()
- {
- $shopAdmin = $this->shopAdmin;
- if (!isset($shopAdmin['super']) || $shopAdmin['super'] != 1) {
- util::fail('超管才能操作退款');
- }
- $post = Yii::$app->request->post();
- $id = $post['id'] ?? 0;
- if (empty($id)) {
- util::fail('参数错误');
- }
- $cacheKey = 'hd_scan_pay_refund_' . $id;
- $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (!empty($has)) {
- util::fail('请5秒之后再提交');
- }
- Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
- $post['mainId'] = $this->mainId;
- $post['shopAdminId'] = $this->shopAdminId;
- $post['shopAdminName'] = $shopAdmin['name'] ?? '';
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $respond = ScanPayRefundClass::createRefund($id, $post);
- $transaction->commit();
- util::success($respond);
- } catch (\Exception $exception) {
- $transaction->rollBack();
- Yii::info('收款码退款失败:' . $exception->getMessage());
- util::fail($exception->getMessage() ?: '操作失败');
- }
- }
- }
|