WithdrawForm.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace backend\models\forms;
  3. use backend\models\WithdrawApi;
  4. use Yii;
  5. use yii\base\Model;
  6. class WithdrawForm extends Model
  7. {
  8. public $login;
  9. public $amount;
  10. public $true_name;
  11. public $bank_province;
  12. public $bank_city;
  13. public $bank_name;
  14. public $bank_sub_name;
  15. public $bank_card_no;
  16. public $swift;
  17. public $mobile;
  18. /**
  19. * @inheritdoc
  20. */
  21. public function rules()
  22. {
  23. return [
  24. [['login', 'amount', 'true_name', 'bank_province', 'bank_city', 'bank_name', 'bank_sub_name', 'bank_card_no', 'mobile'], 'required'],
  25. [['login'], 'integer'],
  26. [['amount'], 'match', 'pattern' => '/^([1-9]\d*|[0])(\.\d{1,2})?$/'],
  27. [['bank_card_no'], 'integer'],
  28. // [['mobile'], 'match', 'pattern' => '/^1(3[0-9]|4[57]|5[0-35-9]|7[01678]|8[0-9])\d{8}$/'],
  29. [['mobile'], 'match', 'pattern' => '/^1[3-9]\d{9}$/'],
  30. ];
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function attributeLabels()
  36. {
  37. return [
  38. 'login' => '申请账户',
  39. 'amount' => '出金金额',
  40. 'true_name' => '收款人',
  41. 'bank_province' => '所在省份',
  42. 'bank_city' => '所在城市',
  43. 'bank_name' => '收款银行',
  44. 'bank_sub_name' => '所属支行',
  45. 'bank_card_no' => '收款卡号',
  46. 'swift' => 'swift代码',
  47. 'mobile' => '联系手机',
  48. ];
  49. }
  50. /**
  51. * @return bool
  52. */
  53. public function addWithdraw()
  54. {
  55. if (Yii::$app->getUser()->getIsGuest()) {
  56. $this->addError('login', '用户未登录');
  57. Yii::$app->getUser()->loginRequired();
  58. return false;
  59. }
  60. if ($this->validate()) {
  61. $data = [];
  62. $data['member_id'] = Yii::$app->getUser()->getId();
  63. $data['amount'] = $this->amount;
  64. $data['true_name'] = $this->true_name;
  65. $data['bank_name'] = $this->bank_name;
  66. $data['bank_sub_name'] = $this->bank_sub_name;
  67. $data['bank_card_no'] = $this->bank_card_no;
  68. $data['bank_province'] = $this->bank_province;
  69. $data['bank_city'] = $this->bank_city;
  70. $data['mobile'] = $this->mobile;
  71. $data['login'] = $this->login;
  72. //$data['swift'] = $this->swift;
  73. $api = new WithdrawApi();
  74. $result = $api->addWithdraw($data);
  75. if ($result['code'] == 0) {
  76. if (is_array($result['message'])) {
  77. $this->addErrors($result['message']);
  78. } else {
  79. $this->addError('receivers', $result['message']);
  80. }
  81. }
  82. }
  83. return !$this->hasErrors();
  84. }
  85. }