コード例 #1
0
 public function actionImport()
 {
     //$this->redirect('/buyer/index');
     $model = new Buyer();
     if (Yii::$app->request->isPost) {
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file->extension == 'xls') {
             $model->file->saveAs('uploads/up.xls');
             //require('/vendor/excel_reader2.php');
             require_once '../vendor/excel_reader2.php';
             $data = new Spreadsheet_Excel_Reader();
             //设置文本输出编码
             $data->setOutputEncoding('UTF-8');
             $data->read('uploads/up.xls');
             //读取excel
             $arr1 = array();
             $arr2 = array();
             $arr3 = array();
             $arr4 = array();
             $arr5 = array();
             $arr6 = array();
             $arr7 = array();
             $arr8 = array();
             for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
                 //显示每个单元格内容
                 $arr1[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][1];
                 $arr2[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][2];
                 $arr3[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][3];
                 $arr4[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][4];
                 $arr5[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][5];
                 $arr6[$data->sheets[0]['cells'][$i][1]] = empty($data->sheets[0]['cells'][$i][6]) ? '' : $data->sheets[0]['cells'][$i][6];
                 $arr7[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][7];
                 $arr8[$data->sheets[0]['cells'][$i][1]] = $data->sheets[0]['cells'][$i][8];
                 $buyer = new Buyer();
                 $buyer->platform = $arr1[$data->sheets[0]['cells'][$i][1]];
                 $buyer->account = $arr2[$data->sheets[0]['cells'][$i][1]];
                 $buyer->pass = $arr3[$data->sheets[0]['cells'][$i][1]];
                 $buyer->pay_account = $arr4[$data->sheets[0]['cells'][$i][1]];
                 $buyer->pay_pass = $arr5[$data->sheets[0]['cells'][$i][1]];
                 $buyer->regarea = $arr6[$data->sheets[0]['cells'][$i][1]];
                 $buyer->regphone = $arr7[$data->sheets[0]['cells'][$i][1]];
                 $buyer->remark = $arr8[$data->sheets[0]['cells'][$i][1]];
                 $buyer->create_time = date('Y-m-d H:i:s');
                 $exists = Buyer::find()->where('account = :account', [':account' => $buyer->account])->one();
                 if (is_null($exists)) {
                     $buyer->save();
                 }
             }
             $i = $i - 2;
             echo "\t<meta charset='utf-8'>";
             echo "<script>alert('成功导入" . $i . "个小号')</script>";
             //echo "<script>history.go(-1);</script>";
         } else {
             echo "\t<meta charset='utf-8'>";
             echo "<script>alert('上传失败')</script>";
             echo "<script>history.go(-1);</script>";
         }
         return;
     }
     return $this->renderAjax('import', ['model' => $model]);
 }
コード例 #2
0
 private function registerUser($data, $role)
 {
     if (isset($data['phone_number'])) {
         $data['phone_number'] = str_replace(' ', '', $data['phone_number']);
     }
     if (isset($data['work_phone'])) {
         $data['work_phone'] = str_replace(' ', '', $data['work_phone']);
     }
     $u = new User();
     $data['role_id'] = $role;
     switch (strtolower($role)) {
         case Config::get('constants.ROLE_SELLER'):
             $a = new Seller();
             break;
         case Config::get('constants.ROLE_BROKER'):
             $a = new Broker();
             break;
         default:
             $a = new Buyer();
             $u->status = 2;
             $data['skip_verification'] = true;
             break;
     }
     if (!isset($data['password']) || $data['password'] == "") {
         $pwd = Str::random(10);
         $data['password'] = $data['password_confirmation'] = $pwd;
     }
     if ($u->validate($data)) {
         if ($a->validate($data)) {
             if (isset($pwd)) {
                 Session::set('validate_password', true);
             }
             $data['password'] = Hash::make($data['password']);
             $u->fill($data);
             $code = Str::random(10);
             $u->verification_code = $code;
             $data['verification_code'] = $code;
             $u->save();
             $data['user_id'] = $u->id;
             $a->fill($data);
             $a->save();
             $email = $u->email;
             if (isset($data['skip_verification'])) {
                 $data['url']['link'] = url('/');
                 $data['url']['name'] = 'Go to CompanyExchange';
                 Mail::queue('emails.templates.welcome', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             } else {
                 Mail::queue('emails.templates.progress', $data, function ($message) use($email) {
                     $message->from('*****@*****.**', 'CompanyExchange');
                     $message->to($email);
                     $message->subject('Welcome to CompanyExchange');
                 });
             }
             Auth::loginUsingId($u->id);
             return true;
         }
         Input::flash();
         return $a->getValidator();
     }
     Input::flash();
     return $u->getValidator();
 }