| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/1/16/016
- * Time: 16:23
- */
- namespace backend\models\forms;
- use backend\models\OpenApi;
- use yii\base\Model;
- use yii\web\UploadedFile;
- class CompleteMaterialForm extends Model
- {
- public $login;
- public $member_id;
- public $card0;
- public $card1;
- public $name;
- public $address;
- public $mobile;
- public $email;
- public $rid;
- public $forex;
- public $metal;
- public $gold;
- public $silver;
- public $cfd;
- public $wy;
- public $bank_name;
- public $bank_province;
- public $bank_city;
- public $bank_district;
- public $bank_branch;
- public $bank_card_no;
- public $collect_name;
- public $bank_swift_code;
- public $agree1;
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- ['login', 'required', 'message' => '未登录'],
- ['member_id', 'required', 'message' => '当前member_id为空'],
- ['card0', 'required', 'message' => '请选择身份证正面照片'],
- ['card0', 'file'],
- ['card1', 'required', 'message' => '请选择身份证反面照片'],
- ['card1', 'file'],
- ['name', 'required', 'message' => '请填写姓名'],
- ['address', 'required', 'message' => '请填写地址'],
- ['mobile', 'required', 'message' => '请填写手机号码'],
- ['mobile', 'match', 'pattern' => '/^1(3[0-9]|4[57]|5[0-35-9]|7[01678]|8[0-9])\d{8}$/'],
- ['email', 'required', 'message' => '请填写电子邮箱'],
- ['email', 'email'],
- ['rid', 'required', 'message' => '请填写推荐人ID'],
- ['forex', 'required', 'message' => '请填写外汇'],
- ['metal', 'required', 'message' => '请填写金属'],
- ['gold', 'required', 'message' => '请填写黄金'],
- ['silver', 'required', 'message' => '请填写白银'],
- ['cfd', 'required', 'message' => '请填写cfd'],
- ['wy', 'required', 'message' => '请填写外佣'],
- ['bank_name', 'required', 'message' => '请选择银行'],
- ['bank_province', 'required', 'message' => '请选择省'],
- ['bank_city', 'required', 'message' => '请选择市'],
- ['bank_branch', 'required', 'message' => '请填写支行名称'],
- ['bank_card_no', 'required', 'message' => '请填写银行卡号'],
- ['bank_card_no', 'checkBankCardNo'],
- ['collect_name', 'required', 'message' => '请填写收款人姓名'],
- ['bank_swift_code', 'required', 'message' => '请填写银行swift代码'],
- ['rid', 'integer'],
- [['agree1'], 'boolean', 'trueValue' => 'on'],
- ];
- }
- /**
- * 16-19 位卡号校验位采用 Luhm 校验方法计算:
- * 1,将未带校验位的 15 位卡号从右依次编号 1 到 15,位于奇数位号上的数字乘以 2
- * 2,将奇位乘积的个十位全部相加,再加上所有偶数位上的数字
- * 3,将加法和加上校验位能被 10 整除。
- * @param string $attribute
- * @return bool
- */
- public function checkBankCardNo($attribute)
- {
- if (!$this->hasErrors()) {
- $n = 0;
- for ($i = strlen($attribute); $i >= 1; $i--) {
- $index = $i - 1;
- //偶数位
- if ($i % 2 == 0) {
- $n += $attribute{$index};
- } else {//奇数位
- $t = $attribute{$index} * 2;
- if ($t > 9) {
- $t = (int)($t / 10) + $t % 10;
- }
- $n += $t;
- }
- }
- if (($n % 10) != 0) {
- $this->addError($attribute, '银行卡号格式错误');
- }
- }
- }
- /**
- * 代理商(ib)账户资料完善
- * @return bool
- */
- public function complete()
- {
- if ($this->validate()) {
- $api = new OpenApi();
- $data = [];
- $data['name'] = $this->name;
- $data['address'] = $this->address;
- $data['mobile'] = $this->mobile;
- $data['email'] = $this->email;
- $data['rid'] = $this->rid;
- $data['forex'] = $this->forex;
- $data['metal'] = $this->metal;
- $data['gold'] = $this->gold;
- $data['silver'] = $this->silver;
- $data['cfd'] = $this->cfd;
- $data['wy'] = $this->wy;
- $webRoot = \Yii::getAlias('@webroot');
- if ($this->card0 instanceof UploadedFile) {
- $filename = false;
- for ($i = 0; $i < 2; $i++) {
- $temp = '/upload/' . date('YmdHis_') . mt_rand(10000, 99999) . '.' . $this->card0->getExtension();
- if (!is_file($webRoot . $temp)) {
- $filename = $temp;
- break;
- }
- }
- if ($filename != false && $this->card0->saveAs($webRoot . $filename)) {
- $data['id_card_file_path0'] = $filename;
- }
- }
- if ($this->card1 instanceof UploadedFile) {
- $filename = false;
- for ($i = 0; $i < 2; $i++) {
- $temp = '/upload/' . date('YmdHis_') . mt_rand(10000, 99999) . '.' . $this->card1->getExtension();
- if (!is_file($webRoot . $temp)) {
- $filename = $temp;
- break;
- }
- }
- if ($filename != false && $this->card1->saveAs($webRoot . $filename)) {
- $data['id_card_file_path1'] = $filename;
- }
- }
- $data['bank_name'] = $this->bank_name;
- $data['bank_province'] = $this->bank_province;
- $data['bank_city'] = $this->bank_city;
- $data['bank_district'] = $this->bank_district;
- $data['bank_branch'] = $this->bank_branch;
- $data['bank_card_no'] = $this->bank_card_no;
- $data['collect_name'] = $this->collect_name;
- $data['bank_swift_code'] = $this->bank_swift_code;
- $data['login'] = $this->login;
- $data['member_id'] = $this->member_id;
- $result = $api->completeMaterial($data);
- if ($result['code'] == 1) {
- return true;
- } else {
- if (is_array($result['message'])) {
- $this->addErrors($result['message']);
- } else {
- $this->addError('name', $result['message']);
- }
- }
- }
- return !$this->hasErrors();
- }
- }
|