|
楼主 |
发表于 2012-8-11 10:31:06
|
显示全部楼层
模型
PHP复制代码
<?php
class Madmin extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->database();
}
function get_customer_record($ic_number,$cur_record)//根据字段ic_number查询一条记录
{
$this->db->select('ic_number,mobile_phone,other_phone');
$this->db->where('ic_number',$ic_number);
if ($cur_record > 100)
{
$query = $this->db->get('customer',5,$cur_record-5);//重复的记录都相近
}else{
$query = $this->db->get('customer');
}
return $query->row();
}
function get_customer_list_page($db_name,$offset,$limit)//自定读取某数据表N条记录
{
$query = $this->db->get($db_name,$limit,$offset);
return $query->result();
}
function insert_db($data)//处理过的数据通过数组插入到指定的表
{
$this->db->insert('customer',$data))
}
function update_db($ic_number,$phone_type,$phone)//根据条件更新mobile_phone,other_phone字段数据
{
if ($phone_type == 'mobile')
{
$this->db->set('mobile_phone',$phone);
}else{
$this->db->set('other_phone',$phone);
}
$this->db->where('ic_number',$ic_number);
$this->db->update('customer');
}
}
?>
复制代码
控制器:
PHP复制代码
<?php
class Admin extends CI_Controller {
var $base_url;
function __construct ()
{
parent ::__construct ();
$this->load->helper('url');
$this->base_url = $this->config->item('base_url');
$this->load->library('pagination');
}
//将客户数据从各零散数据表,通过清除重复记录,判断同信息不同电话号码信息
//重新整理后导入custmoer表内
function customer_import ()//导入整理客户数据
{
$data['baseurl'] = $this->base_url;
$source = 'maybank_0';
$cur_record = $this->uri->segment(3);
if (empty($cur_record)){$cur_record = 0;}
$limit = 10;
$data['cur_record'] = $cur_record + $limit;
$data['limit'] = $limit;
$this->load->model('Madmin');
if ($source <> Null)
{
$temp_data = array();
$data['import_data'] = $this->Madmin->get_customer_list_page($source,$cur_record,$limit);
foreach ($data['import_data'] as $row)
{
++$cur_record;
if (substr($row->phone,0,1) == '1' or substr($row->phone,0,2) == '01' or substr($row->phone,0,3) == '001' or substr($row->phone,0,3) == '601')
//检测电话号为手机的号码
{
$temp_data['mobile_phone'] = $row->phone;
$phone_type = 'mobile';
}else{
$temp_data['other_phone'] = $row->phone;
$phone_type = 'other';
}
$result = $this->Madmin->get_customer_record($row->ic_number,$cur_record);
if (!empty($result))
{
if ($result->ic_number == $row->ic_number)
//根据身份证号(ic_number)判断是否有重复记录和电话号码类型,忽悠重复记录及更新或追加电话号码信息
{
$phone = '';
if ($phone_type == 'mobile' and $result->mobile_phone <> NULL)
{
$phone = $result->mobile_phone.','.$row->phone;
}else if ($phone_type == 'other' and $result->other_phone <> NULL){
$phone = $result->other_phone.','.$row->phone;
}else{
$phone = $row->phone;
}
$this->Madmin->update_db($row->ic_number,$phone_type,$phone);
unset($temp_data);
continue;
}
}
$temp_data['name'] = $row->name;
$temp_data['category_id'] = 1;
$temp_data['ic_number'] = $row->ic_number;
$temp_data['address_1'] = $row->address_1;
$temp_data['address_2'] = $row->address_2;
$temp_data['address_3'] = $row->address_3;
$temp_data['address_4'] = $row->address_4;
$temp_data['postcode'] = $row->postcode;
$temp_data['sex'] = $row->sex;
$temp_data['name'] = $row->name;
$temp_data['race_cd'] = $row->race_cd;
$temp_data['credit_limit'] = 0;
$this->Madmin->insert_db($temp_data);
unset($temp_data);
}
$data['success'] = '共执行处理 '.$data['cur_record'].' 条记录!['.date("H:i:s").']</br>';
}
$this->load->view('customer_import',$data);
}
}
复制代码
视图:
|
|