ScanPayController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace hd\controllers;
  3. use bizHd\order\classes\ScanPayClass;
  4. use bizHd\order\classes\ScanPayRefundClass;
  5. use common\components\util;
  6. use Yii;
  7. class ScanPayController extends BaseController
  8. {
  9. public $guestAccess = [];
  10. public function actionList()
  11. {
  12. $get = Yii::$app->request->get();
  13. $status = $get['status'] ?? 0;
  14. $where = [];
  15. $where['mainId'] = $this->mainId;
  16. if (!empty($status)) {
  17. $where['status'] = $status;
  18. }
  19. $list = ScanPayClass::getPayList($where);
  20. util::success($list);
  21. }
  22. public function actionDetail()
  23. {
  24. $get = Yii::$app->request->get();
  25. $id = $get['id'] ?? 0;
  26. $detail = ScanPayClass::getDetail($id, $this->mainId);
  27. util::success($detail);
  28. }
  29. public function actionRefund()
  30. {
  31. $shopAdmin = $this->shopAdmin;
  32. if (!isset($shopAdmin['super']) || $shopAdmin['super'] != 1) {
  33. util::fail('超管才能操作退款');
  34. }
  35. $post = Yii::$app->request->post();
  36. $id = $post['id'] ?? 0;
  37. if (empty($id)) {
  38. util::fail('参数错误');
  39. }
  40. $cacheKey = 'hd_scan_pay_refund_' . $id;
  41. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  42. if (!empty($has)) {
  43. util::fail('请5秒之后再提交');
  44. }
  45. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  46. $post['mainId'] = $this->mainId;
  47. $post['shopAdminId'] = $this->shopAdminId;
  48. $post['shopAdminName'] = $shopAdmin['name'] ?? '';
  49. $connection = Yii::$app->db;
  50. $transaction = $connection->beginTransaction();
  51. try {
  52. $respond = ScanPayRefundClass::createRefund($id, $post);
  53. $transaction->commit();
  54. util::success($respond);
  55. } catch (\Exception $exception) {
  56. $transaction->rollBack();
  57. Yii::info('收款码退款失败:' . $exception->getMessage());
  58. util::fail($exception->getMessage() ?: '操作失败');
  59. }
  60. }
  61. }