/** * Creates a new Custom model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Custom(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->custom_id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionImportcustom() { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'custom.txt'; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); if (empty($line)) { continue; } $arr = explode("\t", $line); $arr[1] = iconv('GBK', 'UTF-8//IGNORE', $arr[1]); $arr[2] = iconv('GBK', 'UTF-8//IGNORE', $arr[2]); $mobile = trim($arr[0]); $name = trim($arr[1]); $office_title = trim($arr[2]); $office = MOffice::findOne(['gh_id' => 'gh_03a74ac96138', 'title' => $office_title]); if (empty($office)) { U::W(['office_title is invalid', $arr]); exit; } $custom = Custom::findOne(['mobile' => $mobile]); if (!empty($custom)) { //U::W("mobile=$mobile already exists"); //U::W($arr); } else { $custom = new Custom(); } $custom->mobile = $mobile; $custom->name = $name; $custom->office_id = $office->office_id; $custom->save(false); $i++; if ($i % 1000 == 1) { U::W($i); } } fclose($fh); }