BankwithdrawController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace backend\modules\user\controllers;
  3. use backend\models\forms\WithdrawForm;
  4. use backend\models\RateApi;
  5. use backend\models\searches\SsacWithdrawSearch;
  6. use backend\models\searches\WithdrawSearch;
  7. use backend\models\SsacWithdrawApi;
  8. use backend\models\WithdrawApi;
  9. use Yii;
  10. use yii\bootstrap\Html;
  11. class BankwithdrawController extends BaseController
  12. {
  13. /**
  14. * @return string
  15. */
  16. public function actionIndex()
  17. {
  18. return $this->render('index', [
  19. 'rate' => $this->getRate(),
  20. // 'fee' => $this->getFee(),
  21. ]);
  22. }
  23. /**
  24. * @return \yii\web\Response
  25. */
  26. public function actionAjax()
  27. {
  28. $searchModel = new WithdrawSearch();
  29. $dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams());
  30. return $this->asJson($searchModel->outResult($dataProvider));
  31. }
  32. /**
  33. * @return \yii\web\Response
  34. */
  35. public function actionSave()
  36. {
  37. $model = new WithdrawForm();
  38. if (Yii::$app->getRequest()->getIsPost()) {
  39. $model->setAttributes(Yii::$app->getRequest()->post());
  40. if ($model->addWithdraw()) {
  41. return $this->asJson([
  42. 'isSuccess' => true,
  43. 'msg' => '提交成功,请等待审核',
  44. ]);
  45. } else {
  46. return $this->asJson([
  47. 'isSuccess' => false,
  48. 'msg' => Html::errorSummary($model, ['header' => '']),
  49. ]);
  50. }
  51. }
  52. return $this->asJson([
  53. 'isSuccess' => false,
  54. 'msg' => 'Bad Request',
  55. ]);
  56. }
  57. public function actionGetSsacUserInfo()
  58. {
  59. $api = new SsacWithdrawApi();
  60. $result = $api->getUserInfo(Yii::$app->getUser()->getId(), Yii::$app->getRequest()->get('addrToken'));
  61. if ($result['code'] == 1) {
  62. return $this->asJson(['isSuccess' => true, 'data' => $result['data']]);
  63. } else {
  64. return $this->asJson(['isSuccess' => false, 'msg' => $result['message']]);
  65. }
  66. }
  67. public function actionOutGold()
  68. {
  69. $api = new SsacWithdrawApi();
  70. $result = $api->addWithdraw(Yii::$app->getUser()->getId(), Yii::$app->getRequest()->post());
  71. if ($result['code'] == 1) {
  72. return $this->asJson([
  73. 'isSuccess' => true,
  74. 'msg' => '提交成功,请等待审核',
  75. ]);
  76. } else {
  77. return $this->asJson([
  78. 'isSuccess' => false,
  79. 'msg' => $result['message'],
  80. ]);
  81. }
  82. }
  83. /**
  84. * @return \yii\web\Response
  85. */
  86. public function actionSsacAjax()
  87. {
  88. $searchModel = new SsacWithdrawSearch();
  89. $dataProvider = $searchModel->search(Yii::$app->getRequest()->getQueryParams());
  90. return $this->asJson($searchModel->outResult($dataProvider));
  91. }
  92. /**
  93. * @return array
  94. */
  95. protected function getRate()
  96. {
  97. $api = new RateApi();
  98. $result = $api->getRate();
  99. if ($result['code'] == 1) {
  100. return $result['data'];
  101. } else {
  102. return [];
  103. }
  104. }
  105. /**
  106. * @return bool
  107. * @deprecated
  108. */
  109. protected function getFee()
  110. {
  111. $api = new WithdrawApi();
  112. $result = $api->getMonthWithdraw(Yii::$app->getUser()->getId());
  113. return !empty($result['data']) ? true : false;
  114. }
  115. }