OpenDemoForm.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace backend\models\forms;
  3. use backend\helpers\RandomHelper;
  4. use common\helpers\MtKit;
  5. use common\helpers\Utils;
  6. use yii\base\Model;
  7. class OpenDemoForm extends Model
  8. {
  9. public $username;
  10. public $email;
  11. public $phone;
  12. private $_login;
  13. private $_password;
  14. /**
  15. * @inheritdoc
  16. */
  17. public function rules()
  18. {
  19. return [
  20. ['username', 'required'],
  21. ['email', 'required'],
  22. ['email', 'email'],
  23. ['phone', 'required'],
  24. ['phone', 'checkPhone'],
  25. ];
  26. }
  27. public function checkPhone($attribute, $params = [])
  28. {
  29. if (!$this->hasErrors()) {
  30. if (Utils::checkPhoneNumber($this->phone) == false) {
  31. $this->addError($attribute, '手机号码格式错误');
  32. }
  33. }
  34. }
  35. /**
  36. * @return bool
  37. */
  38. public function openDemo()
  39. {
  40. if ($this->validate()) {
  41. $this->_password = RandomHelper::getRandomStringForMt4();
  42. $passwordInvestor = RandomHelper::getRandomStringForMt4();
  43. $passwordPhone = RandomHelper::getRandomStringForMt4();
  44. $login = MtKit::openUserDemo(null, $this->_password, $passwordInvestor, $passwordPhone, $this->username, null, $this->email, $this->phone);
  45. if ($login) {
  46. $this->_login = $login;
  47. } else {
  48. $this->addError('username', '模拟账户申请失败');
  49. }
  50. }
  51. return !$this->hasErrors();
  52. }
  53. /**
  54. * @return int
  55. */
  56. public function getLogin()
  57. {
  58. return $this->_login;
  59. }
  60. /**
  61. * @return string
  62. */
  63. public function getPassword()
  64. {
  65. return $this->_password;
  66. }
  67. }