public function actionUpdateHd201509t3m2($filename = 'xjfdax1012.csv') { $filepathname = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'imported_data' . DIRECTORY_SEPARATOR . $filename; $fh = fopen($filepathname, "r"); while (!feof($fh)) { $line = trim(fgets($fh)); if (empty($line) || strlen($line) == 0) { continue; } $fields = explode(",", $line); $mobile = trim($fields[0]); $mobile_utf8 = iconv('GBK', 'UTF-8//IGNORE', $mobile); $hd201509t3 = MHd201509t3::findOne(['mobile' => $mobile_utf8]); if (empty($hd201509t3)) { echo $mobile_utf8 . "\t\t" . "not found, add!\n"; $hd201509t3 = new MHd201509t3(); $hd201509t3->mobile = $mobile_utf8; $hd201509t3->status = 0; $hd201509t3->score = 0; $hd201509t3->save(false); } else { echo $mobile_utf8 . "\t\t" . "found!\t\t" . "\n"; //$hd201509t6->qdbm = $qdbm_ok_utf8; //$hd201509t6->save(false); } } fclose($fh); echo "done\n"; }
public function actionImporthd201509t3() { $file = Yii::$app->getRuntimePath() . DIRECTORY_SEPARATOR . 'xjfdax-20150828.csv'; $fh = fopen($file, "r"); $i = 0; while (!feof($fh)) { $line = fgets($fh); if (empty($line)) { continue; } $arr = explode(",", $line); $arr[0] = iconv('GBK', 'UTF-8//IGNORE', $arr[0]); $mobile = trim($arr[0]); echo $mobile . "\n"; $hd201509t3 = MHd201509t3::findOne(['mobile' => $mobile]); if (!empty($hd201509t3)) { //U::W("mobile=$mobile already exists"); //U::W($arr); } else { $hd201509t3 = new MHd201509t3(); } $hd201509t3->mobile = $mobile; $hd201509t3->save(false); $i++; if ($i % 1000 == 1) { U::W($i); } } fclose($fh); }