|
@@ -240,4 +240,59 @@ class TestCar extends PHPUnit_Framework_TestCase
|
|
|
$result_name = $validator->from_name($areas[0],$areas[1],$areas[2]);
|
|
|
}
|
|
|
|
|
|
+ public function testCompareData()
|
|
|
+ {
|
|
|
+ $file = "/Users/a2/work/model.csv";
|
|
|
+ //$file = "/Users/a2/work/brand.csv";
|
|
|
+ $content = file_get_contents($file);
|
|
|
+ $encoding = self::get_encoding($content);
|
|
|
+ unset($content);
|
|
|
+
|
|
|
+ $mod_brand = Model('brand');
|
|
|
+ $mod_car = Model('car');
|
|
|
+ $fs = @fopen($file, 'r');
|
|
|
+ $i = 0;
|
|
|
+ $new_names = [];
|
|
|
+ while( $line = @fgets($fs) )
|
|
|
+ {
|
|
|
+ $line = iconv($encoding, 'UTF-8', trim($line));
|
|
|
+ if($i > 0 )
|
|
|
+ {
|
|
|
+ $arr = explode(";", $line);
|
|
|
+ $car_name = $arr[1];
|
|
|
+ $callback = function($mod,$name) {
|
|
|
+ $result = $mod->table('car_base')->where(['car_name'=>$name])->find();
|
|
|
+ if(!empty($result)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $found = $callback($mod_car, $car_name);
|
|
|
+ if(!$found) {
|
|
|
+ $new_names[] = $car_name;
|
|
|
+ }
|
|
|
+ /*$brand_name = $arr[1];
|
|
|
+ $callback = function ($mod, $name) {
|
|
|
+ $result = $mod->table('brand')->where(['brand_name'=>$name])->find();
|
|
|
+ if(!empty($result)) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ $found = $callback($mod_brand,$brand_name);
|
|
|
+ if(!$found) {
|
|
|
+ $new_names[] = $brand_name;
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ $i++;
|
|
|
+ }
|
|
|
+ var_dump($new_names);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function get_encoding($str)
|
|
|
+ {
|
|
|
+ return mb_detect_encoding($str, ['GB2312','GBK','UTF-16','UCS-2','UTF-8','BIG5','ASCII']);
|
|
|
+ }
|
|
|
}
|