填充模型类 字段列表
mysql> desc 5kcrm_crm_leads;
+----------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------------------+----------------+
| leads_id | int(11) | NO | PRI | NULL | auto_increment |
| customer_id | int(11) | NO | | 0 | |
| is_transform | tinyint(1) | NO | | 0 | |
| name | varchar(255) | YES | | NULL | |
| source | varchar(500) | YES | | 线上搜索 | |
| telephone | varchar(255) | YES | | NULL | |
| mobile | varchar(255) | YES | | NULL | |
| industry | varchar(500) | YES | | 公立学校 | |
| level | varchar(500) | YES | | A(重点线索) | |
| detail_address | varchar(255) | YES | | NULL | |
| remark | text | YES | | NULL | |
| create_user_id | int(10) | NO | | NULL | |
| owner_user_id | int(10) | NO | | NULL | |
| next_time | int(11) | YES | | NULL | |
| follow | varchar(20) | YES | | NULL | |
| create_time | int(11) | NO | | NULL | |
| update_time | int(11) | NO | | NULL | |
| crm_hgsngq | varchar(255) | YES | | NULL | |
| crm_hyjnmp | varchar(255) | YES | | NULL | |
| crm_bufkdm | varchar(255) | YES | | NULL | |
| crm_wwwecw | varchar(500) | YES | | 关系人 | |
| crm_kuqbmc | varchar(255) | YES | | NULL | |
| crm_lxuhjj | varchar(255) | YES | | NULL | |
+----------------+--------------+------+-----+---------------------+----------------+
23 rows in set (0.00 sec)
粘贴中间的绿色部分到文件 columns.txt
* getFields.php
<?php
function fileForEachRow($path, $handler) {
$handle = fopen($path, "r");
if (! $handle ) {
return;
}
while (($buffer = fgets($handle, 1024) ) !== false) {
$buffer = trim($buffer);
call_user_func($handler, $buffer);
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
$fields = [];
fileForEachRow("columns.txt", function($line) use(&$fields) {
$n = strlen($line);
if ($n === 0) {
return;
}
// echo $line.PHP_EOL;
$col = explode("|", $line);
$field = isset($col[1]) ? trim($col[1]) : "";
if ($field) {
array_push($fields, $field);
}
});
printf("[\"%s\"]\n", implode("\",\"", $fields));
* run:
$ php getFields.php
["leads_id","customer_id","is_transform","name","source","telephone","mobile","industry","level","detail_address","remark","create_user_id","owner_user_id","next_time","follow","create_time","update_time","crm_hgsngq","crm_hyjnmp","crm_bufkdm","crm_wwwecw","crm_kuqbmc","crm_lxuhjj"]