BankwithdrawController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace backend\modules\ib\controllers;
  3. use backend\models\forms\WithdrawForm;
  4. use backend\models\RateApi;
  5. use backend\models\searches\WithdrawSearch;
  6. use backend\models\WithdrawApi;
  7. use Yii;
  8. use yii\bootstrap\Html;
  9. use backend\models\MemberBankInfoApi;
  10. class BankwithdrawController extends BaseController
  11. {
  12. /**
  13. * @return string
  14. */
  15. public function actionIndex()
  16. {
  17. return $this->render('index', [
  18. 'rate' => $this->getRate(),
  19. // 'fee' => $this->getFee(),
  20. 'bank_info' => $this->getBankInfo(),
  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. /**
  58. * @return array
  59. */
  60. protected function getRate()
  61. {
  62. $api = new RateApi();
  63. $result = $api->getRate();
  64. if ($result['code'] == 1) {
  65. return $result['data'];
  66. } else {
  67. return [];
  68. }
  69. }
  70. /**
  71. * @return bool
  72. * @deprecated
  73. */
  74. protected function getFee()
  75. {
  76. $api = new WithdrawApi();
  77. $result = $api->getMonthWithdraw(Yii::$app->getUser()->getId());
  78. return !empty($result['data']) ? true : false;
  79. }
  80. protected function getBankInfo()
  81. {
  82. $api = new MemberBankInfoApi();
  83. $result = $api->getBankInfo(['member_id' => Yii::$app->getUser()->getId()]);
  84. return !empty($result['data']) ? $result['data'] : [];
  85. }
  86. }