Zencart客户资料转移合并工具精简版Customers Populate v1.0

很久没给大家分享点有用的东西了,今天抽空写了一个zencart客户资料转移合并工具,感觉还是有点用的,就分享给大家

主要的用途就是就一个zencart网站的客户全部迁移到另一个网站

1<?php
2// +----------------------------------------------------------------------
3// | Project:Zencart客户资料转移合并工具简版 Customers Populate v1.0
4// +----------------------------------------------------------------------
5// | Explanation:2014-12-1
6// +----------------------------------------------------------------------
7// | Version: V1.0
8// +----------------------------------------------------------------------
9// | Authors: ezencart <info@ezencart.com QQ:40309022>
10// +----------------------------------------------------------------------
11
12header('Content-Type:text/html;charset=UTF-8');
13require('includes/application_top.php');
14
15function ez_get_customers_books($customers_id,$customers_default_address_id){
16  global $db;
17  $books_data=array();
18  $books=$db->Execute("SELECT * FROM ".TABLE_ADDRESS_BOOK." WHERE customers_id=".$customers_id);
19  while(!$books->EOF){
20    $books->fields['primary'] = ($books->fields['address_book_id']==$customers_default_address_id) ? 1 : 0;
21    $books_data[]=$books->fields;
22    $books->MoveNext();
23  }
24  return $books_data;
25}
26
27function ez_get_customers_info($customers_id){
28  global $db;
29  $customers_info=$db->Execute("SELECT * FROM ".TABLE_CUSTOMERS_INFO." WHERE customers_info_id=".$customers_id);
30  unset($customers_info->fields['customers_info_id']);
31  return $customers_info->fields;
32}
33
34$customers_data=array();
35
36//导出
37if($_GET['toolaction']=='export'){
38  $customers = $db->Execute("SELECT * FROM ".TABLE_CUSTOMERS);
39
40  while(!$customers->EOF){
41    $customers->fields['books']=ez_get_customers_books($customers->fields['customers_id'],$customers->fields['customers_default_address_id']);
42    $customers->fields['customers_info']=ez_get_customers_info($customers->fields['customers_id']);
43    $customers_data[$customers->fields['customers_email_address']]=$customers->fields;
44    $customers->MoveNext();
45  }
46  file_put_contents(DIR_FS_SQL_CACHE.'/customers_data.log', json_encode($customers_data));
47  echo '导出成功';
48  exit;
49}
50
51//导入
52if($_GET['toolaction']=='import'){
53  if(!file_exists(DIR_FS_SQL_CACHE.'/customers_data.log')) {echo '客户资料文件不存在';die;}
54  $customers_data_json=file_get_contents(DIR_FS_SQL_CACHE.'/customers_data.log');
55  $customers_data=json_decode($customers_data_json,true);
56  foreach($customers_data as $email_address => $email_data){
57
58    $check_email_query = "select count(*) as total
59                            from " . TABLE_CUSTOMERS . "
60                            where customers_email_address = '" . $email_address . "'";
61    $check_email = $db->Execute($check_email_query);
62    if ($check_email->fields['total'] > 0) continue;  //邮箱已存在跳出
63
64    $book_data=$email_data['books'];
65    $customers_info=$email_data['customers_info'];
66
67    unset($email_data['books'],$email_data['customers_id'],$email_data['customers_info']);
68
69    //插入客户表
70    zen_db_perform(TABLE_CUSTOMERS, $email_data);
71    $customers_id = $db->Insert_ID();
72
73    //插入客户信息表
74    $customers_info['customers_info_id']=$customers_id;
75    zen_db_perform(TABLE_CUSTOMERS_INFO, $customers_info);
76
77    //插入地址表
78    foreach($book_data as $book){
79      $book['customers_id']=$customers_id;
80      unset($book['address_book_id']);
81      $primary= ($book['primary']==1) ? 1 : 0;
82      unset($book['primary'],$book['address_book_id']);
83
84      zen_db_perform(TABLE_ADDRESS_BOOK, $book);
85      $books_id = $db->Insert_ID();
86
87      //更新客户表默认地址
88      if($primary==1)  $db->Execute("UPDATE ".TABLE_CUSTOMERS." SET customers_default_address_id=".$books_id." WHERE customers_id=".$customers_id);
89    }
90  }
91  echo '导入成功';
92  exit;
93}
94?>
95<a href="?toolaction=export">导出</a>
96<a href="?toolaction=import">导入</a>

使用方法很简单,只用将文件上传到网站根目录,然后浏览器运行http://xxx.com/customers_populate.php,导出后将cache/customers_data.log转移到另一个站的cache下,然后执行导入。

点此下载:customers_populate_v1.0

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: