ScanPayController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace ghs\controllers;
  3. use bizGhs\order\classes\ScanPayClass;
  4. use bizGhs\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. if (getenv('YII_ENV') == 'production') {
  36. if ($this->mainId == 23390) {
  37. if (!in_array($this->adminId, [23960, 77951, 4])) {
  38. util::fail('你不能售后哈。。');
  39. }
  40. }
  41. if ($this->mainId == 7704) {
  42. if (in_array($this->shopAdminId, [133727, 133545]) == false) {
  43. util::fail('无法操作。。');
  44. }
  45. }
  46. if ($this->mainId == 42680) {
  47. if (!in_array($this->adminId, [40144])) {
  48. util::fail('你不能售后哦。。');
  49. }
  50. }
  51. }
  52. $post = Yii::$app->request->post();
  53. $id = $post['id'] ?? 0;
  54. if (empty($id)) {
  55. util::fail('参数错误');
  56. }
  57. $cacheKey = 'ghs_scan_pay_refund_' . $id;
  58. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  59. if (!empty($has)) {
  60. util::fail('请5秒之后再提交');
  61. }
  62. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
  63. $post['mainId'] = $this->mainId;
  64. $post['shopAdminId'] = $this->shopAdminId;
  65. $post['shopAdminName'] = $shopAdmin['name'] ?? '';
  66. $connection = Yii::$app->db;
  67. $transaction = $connection->beginTransaction();
  68. try {
  69. $respond = ScanPayRefundClass::createRefund($id, $post);
  70. $transaction->commit();
  71. util::success($respond);
  72. } catch (\Exception $exception) {
  73. $transaction->rollBack();
  74. Yii::info('收款码退款失败:' . $exception->getMessage());
  75. util::fail($exception->getMessage() ?: '操作失败');
  76. }
  77. }
  78. }