CompleteMaterialForm.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/1/16/016
  6. * Time: 16:23
  7. */
  8. namespace backend\models\forms;
  9. use backend\models\OpenApi;
  10. use yii\base\Model;
  11. use yii\web\UploadedFile;
  12. class CompleteMaterialForm extends Model
  13. {
  14. public $login;
  15. public $member_id;
  16. public $card0;
  17. public $card1;
  18. public $name;
  19. public $address;
  20. public $mobile;
  21. public $email;
  22. public $rid;
  23. public $forex;
  24. public $metal;
  25. public $gold;
  26. public $silver;
  27. public $cfd;
  28. public $wy;
  29. public $bank_name;
  30. public $bank_province;
  31. public $bank_city;
  32. public $bank_district;
  33. public $bank_branch;
  34. public $bank_card_no;
  35. public $collect_name;
  36. public $bank_swift_code;
  37. public $agree1;
  38. /**
  39. * @inheritdoc
  40. */
  41. public function rules()
  42. {
  43. return [
  44. ['login', 'required', 'message' => '未登录'],
  45. ['member_id', 'required', 'message' => '当前member_id为空'],
  46. ['card0', 'required', 'message' => '请选择身份证正面照片'],
  47. ['card0', 'file'],
  48. ['card1', 'required', 'message' => '请选择身份证反面照片'],
  49. ['card1', 'file'],
  50. ['name', 'required', 'message' => '请填写姓名'],
  51. ['address', 'required', 'message' => '请填写地址'],
  52. ['mobile', 'required', 'message' => '请填写手机号码'],
  53. ['mobile', 'match', 'pattern' => '/^1(3[0-9]|4[57]|5[0-35-9]|7[01678]|8[0-9])\d{8}$/'],
  54. ['email', 'required', 'message' => '请填写电子邮箱'],
  55. ['email', 'email'],
  56. ['rid', 'required', 'message' => '请填写推荐人ID'],
  57. ['forex', 'required', 'message' => '请填写外汇'],
  58. ['metal', 'required', 'message' => '请填写金属'],
  59. ['gold', 'required', 'message' => '请填写黄金'],
  60. ['silver', 'required', 'message' => '请填写白银'],
  61. ['cfd', 'required', 'message' => '请填写cfd'],
  62. ['wy', 'required', 'message' => '请填写外佣'],
  63. ['bank_name', 'required', 'message' => '请选择银行'],
  64. ['bank_province', 'required', 'message' => '请选择省'],
  65. ['bank_city', 'required', 'message' => '请选择市'],
  66. ['bank_branch', 'required', 'message' => '请填写支行名称'],
  67. ['bank_card_no', 'required', 'message' => '请填写银行卡号'],
  68. ['bank_card_no', 'checkBankCardNo'],
  69. ['collect_name', 'required', 'message' => '请填写收款人姓名'],
  70. ['bank_swift_code', 'required', 'message' => '请填写银行swift代码'],
  71. ['rid', 'integer'],
  72. [['agree1'], 'boolean', 'trueValue' => 'on'],
  73. ];
  74. }
  75. /**
  76. * 16-19 位卡号校验位采用 Luhm 校验方法计算:
  77. * 1,将未带校验位的 15 位卡号从右依次编号 1 到 15,位于奇数位号上的数字乘以 2
  78. * 2,将奇位乘积的个十位全部相加,再加上所有偶数位上的数字
  79. * 3,将加法和加上校验位能被 10 整除。
  80. * @param string $attribute
  81. * @return bool
  82. */
  83. public function checkBankCardNo($attribute)
  84. {
  85. if (!$this->hasErrors()) {
  86. $n = 0;
  87. for ($i = strlen($attribute); $i >= 1; $i--) {
  88. $index = $i - 1;
  89. //偶数位
  90. if ($i % 2 == 0) {
  91. $n += $attribute{$index};
  92. } else {//奇数位
  93. $t = $attribute{$index} * 2;
  94. if ($t > 9) {
  95. $t = (int)($t / 10) + $t % 10;
  96. }
  97. $n += $t;
  98. }
  99. }
  100. if (($n % 10) != 0) {
  101. $this->addError($attribute, '银行卡号格式错误');
  102. }
  103. }
  104. }
  105. /**
  106. * 代理商(ib)账户资料完善
  107. * @return bool
  108. */
  109. public function complete()
  110. {
  111. if ($this->validate()) {
  112. $api = new OpenApi();
  113. $data = [];
  114. $data['name'] = $this->name;
  115. $data['address'] = $this->address;
  116. $data['mobile'] = $this->mobile;
  117. $data['email'] = $this->email;
  118. $data['rid'] = $this->rid;
  119. $data['forex'] = $this->forex;
  120. $data['metal'] = $this->metal;
  121. $data['gold'] = $this->gold;
  122. $data['silver'] = $this->silver;
  123. $data['cfd'] = $this->cfd;
  124. $data['wy'] = $this->wy;
  125. $webRoot = \Yii::getAlias('@webroot');
  126. if ($this->card0 instanceof UploadedFile) {
  127. $filename = false;
  128. for ($i = 0; $i < 2; $i++) {
  129. $temp = '/upload/' . date('YmdHis_') . mt_rand(10000, 99999) . '.' . $this->card0->getExtension();
  130. if (!is_file($webRoot . $temp)) {
  131. $filename = $temp;
  132. break;
  133. }
  134. }
  135. if ($filename != false && $this->card0->saveAs($webRoot . $filename)) {
  136. $data['id_card_file_path0'] = $filename;
  137. }
  138. }
  139. if ($this->card1 instanceof UploadedFile) {
  140. $filename = false;
  141. for ($i = 0; $i < 2; $i++) {
  142. $temp = '/upload/' . date('YmdHis_') . mt_rand(10000, 99999) . '.' . $this->card1->getExtension();
  143. if (!is_file($webRoot . $temp)) {
  144. $filename = $temp;
  145. break;
  146. }
  147. }
  148. if ($filename != false && $this->card1->saveAs($webRoot . $filename)) {
  149. $data['id_card_file_path1'] = $filename;
  150. }
  151. }
  152. $data['bank_name'] = $this->bank_name;
  153. $data['bank_province'] = $this->bank_province;
  154. $data['bank_city'] = $this->bank_city;
  155. $data['bank_district'] = $this->bank_district;
  156. $data['bank_branch'] = $this->bank_branch;
  157. $data['bank_card_no'] = $this->bank_card_no;
  158. $data['collect_name'] = $this->collect_name;
  159. $data['bank_swift_code'] = $this->bank_swift_code;
  160. $data['login'] = $this->login;
  161. $data['member_id'] = $this->member_id;
  162. $result = $api->completeMaterial($data);
  163. if ($result['code'] == 1) {
  164. return true;
  165. } else {
  166. if (is_array($result['message'])) {
  167. $this->addErrors($result['message']);
  168. } else {
  169. $this->addError('name', $result['message']);
  170. }
  171. }
  172. }
  173. return !$this->hasErrors();
  174. }
  175. }