按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

Zen Cart的安装、设置、升级讨论和使用技巧交流

版主: 赞拓拓, shaning, 美拓拓

按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子reason » 2006-10-17 8:26

修改前一定要备份好自己的数据库!!!


1、把orders字段中orders_id 的 Auto_increment 关闭;

2、把以下代码插入到order.php中;
查找:function create($zf_ot_modules, $zf_mode = 2) {
global $db;

插入意下代码:

$t1 = date("YmdGis");
srand ((float) microtime() * 10000000);
$input = array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
$rand_keys = array_rand ($input, 2);
$l1 = $input;
$l2 = $input;
$r1 = rand(0,9);

$ordernum = $t1.$l1.$l2.$r1;

在这里添加orders_id字段,手工插入:
$sql_data_array = array('orders_id' => $ordernum,

查找:zen_db_perform(TABLE_ORDERS, $sql_data_array);

插入:
/*修改原来的调用自动插入函数为$ordernum变量*/
$insert_id = $ordernum;

以上简单的修改后,订单号会输出如:20050613235934985
表示:2005年06月13日23时59分34秒985随机数
原mod出处:www.oscommerce.com;我修改了日期显示及订单号排列顺序。

[size=22]能说说哪个是数据库的哪个是.php文件的吗?把orders字段中orders_id 的 Auto_increment 关闭需要怎样关闭呢?[/size]
reason
高级会员
高级会员
 
帖子: 117
注册: 2006-06-29 22:42

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子radnows » 2006-10-18 6:39

以1.3.5版includes\classes\order.php为例。原内容如下:

function create($zf_ot_modules, $zf_mode = 2) {
global $db;

if ($this->info['total'] == 0) {
if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
$this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
} else {
$this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
}
}

if ($_SESSION['shipping'] == 'free_free') {
$this->info['shipping_module_code'] = $_SESSION['shipping'];
}

$sql_data_array = array('customers_id' => $_SESSION['customer_id'],
'customers_name' => $this->customer['firstname'] . ' ' . $this->customer['lastname'],
'customers_company' => $this->customer['company'],
'customers_street_address' => $this->customer['street_address'],
'customers_suburb' => $this->customer['suburb'],
'customers_city' => $this->customer['city'],
'customers_postcode' => $this->customer['postcode'],
'customers_state' => $this->customer['state'],
'customers_country' => $this->customer['country']['title'],
'customers_telephone' => $this->customer['telephone'],
'customers_email_address' => $this->customer['email_address'],
'customers_address_format_id' => $this->customer['format_id'],
'delivery_name' => $this->delivery['firstname'] . ' ' . $this->delivery['lastname'],
'delivery_company' => $this->delivery['company'],
'delivery_street_address' => $this->delivery['street_address'],
'delivery_suburb' => $this->delivery['suburb'],
'delivery_city' => $this->delivery['city'],
'delivery_postcode' => $this->delivery['postcode'],
'delivery_state' => $this->delivery['state'],
'delivery_country' => $this->delivery['country']['title'],
'delivery_address_format_id' => $this->delivery['format_id'],
'billing_name' => $this->billing['firstname'] . ' ' . $this->billing['lastname'],
'billing_company' => $this->billing['company'],
'billing_street_address' => $this->billing['street_address'],
'billing_suburb' => $this->billing['suburb'],
'billing_city' => $this->billing['city'],
'billing_postcode' => $this->billing['postcode'],
'billing_state' => $this->billing['state'],
'billing_country' => $this->billing['country']['title'],
'billing_address_format_id' => $this->billing['format_id'],
'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV : $this->info['payment_method']),
'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV : $this->info['payment_module_code']),
'shipping_method' => $this->info['shipping_method'],
'shipping_module_code' => (strpos($this->info['shipping_module_code'], '_') > 0 ? substr($this->info['shipping_module_code'], 0, strpos($this->info['shipping_module_code'], '_')) : $this->info['shipping_module_code']),
'coupon_code' => $this->info['coupon_code'],
'cc_type' => $this->info['cc_type'],
'cc_owner' => $this->info['cc_owner'],
'cc_number' => $this->info['cc_number'],
'cc_expires' => $this->info['cc_expires'],
'date_purchased' => 'now()',
'orders_status' => $this->info['order_status'],
'order_total' => $this->info['total'],
'order_tax' => $this->info['tax'],
'currency' => $this->info['currency'],
'currency_value' => $this->info['currency_value'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
);


zen_db_perform(TABLE_ORDERS, $sql_data_array);

$insert_id = $db->Insert_ID();

头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子radnows » 2006-10-18 6:41

以1.3.5版includes\classes\order.php为例。新内容如下:

function create($zf_ot_modules, $zf_mode = 2) {
global $db;

/*------按时间+随机数结合产生订单号-----*/
$t1 = date("Ymd");
srand ((float) microtime() * 10000000);
$input = array ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0");
$rand_keys = array_rand ($input, 2);
//$t1 = $input[$rand_keys[0]];
$t2 = $input[$rand_keys[1]];
$t3 = rand(0,9);

$ordernum = $t1.$t2.$t3;
/*------------END------------------------*/


if ($this->info['total'] == 0) {
if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
$this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
} else {
$this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
}
}

if ($_SESSION['shipping'] == 'free_free') {
$this->info['shipping_module_code'] = $_SESSION['shipping'];
}


/*在这里添加orders_id字段,手工插入:*/
$sql_data_array = array('orders_id' => $ordernum,
'customers_id' => $_SESSION['customer_id'],
'customers_name' => $this->customer['firstname'] . ' ' . $this->customer['lastname'],
'customers_company' => $this->customer['company'],
'customers_street_address' => $this->customer['street_address'],
'customers_suburb' => $this->customer['suburb'],
'customers_city' => $this->customer['city'],
'customers_postcode' => $this->customer['postcode'],
'customers_state' => $this->customer['state'],
'customers_country' => $this->customer['country']['title'],
'customers_telephone' => $this->customer['telephone'],
'customers_email_address' => $this->customer['email_address'],
'customers_address_format_id' => $this->customer['format_id'],
'delivery_name' => $this->delivery['firstname'] . ' ' . $this->delivery['lastname'],
'delivery_company' => $this->delivery['company'],
'delivery_street_address' => $this->delivery['street_address'],
'delivery_suburb' => $this->delivery['suburb'],
'delivery_city' => $this->delivery['city'],
'delivery_postcode' => $this->delivery['postcode'],
'delivery_state' => $this->delivery['state'],
'delivery_country' => $this->delivery['country']['title'],
'delivery_address_format_id' => $this->delivery['format_id'],
'billing_name' => $this->billing['firstname'] . ' ' . $this->billing['lastname'],
'billing_company' => $this->billing['company'],
'billing_street_address' => $this->billing['street_address'],
'billing_suburb' => $this->billing['suburb'],
'billing_city' => $this->billing['city'],
'billing_postcode' => $this->billing['postcode'],
'billing_state' => $this->billing['state'],
'billing_country' => $this->billing['country']['title'],
'billing_address_format_id' => $this->billing['format_id'],
'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV : $this->info['payment_method']),
'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV : $this->info['payment_module_code']),
'shipping_method' => $this->info['shipping_method'],
'shipping_module_code' => (strpos($this->info['shipping_module_code'], '_') > 0 ? substr($this->info['shipping_module_code'], 0, strpos($this->info['shipping_module_code'], '_')) : $this->info['shipping_module_code']),
'coupon_code' => $this->info['coupon_code'],
'cc_type' => $this->info['cc_type'],
'cc_owner' => $this->info['cc_owner'],
'cc_number' => $this->info['cc_number'],
'cc_expires' => $this->info['cc_expires'],
'date_purchased' => 'now()',
'orders_status' => $this->info['order_status'],
'order_total' => $this->info['total'],
'order_tax' => $this->info['tax'],
'currency' => $this->info['currency'],
'currency_value' => $this->info['currency_value'],
'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
);


zen_db_perform(TABLE_ORDERS, $sql_data_array);

/*修改原来的调用自动插入函数为$ordernum变量*/
$insert_id = $ordernum;

// $insert_id = $db->Insert_ID();


头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子reason » 2006-10-18 8:13

请问不需要改数据库吗?
1、把orders字段中orders_id 的 Auto_increment 关闭;
是不是数据库的啊?要怎么改啊?是删掉吗?
谢谢!!!
reason
高级会员
高级会员
 
帖子: 117
注册: 2006-06-29 22:42

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子radnows » 2006-10-19 11:01

不需要
头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子reason » 2006-10-20 10:58

不行啊!我改完后无法打开结帐的页面啊?点击结账后页面是空白的啊,什么都不显示啊!
1、把orders字段中orders_id 的 Auto_increment 关闭;是什么意思啊?

谢谢啊!!!
reason
高级会员
高级会员
 
帖子: 117
注册: 2006-06-29 22:42

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子radnows » 2006-10-20 15:22

天啊 只是把1.3.5版的zencart的includes\classes\order.php的原内容(确保是没修改过的)替换为新内容都会错 算了
头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子reason » 2006-10-22 13:45

order.php已经用网银在线的order.php替换了,请问需要怎么改啊?谢谢您!

我改完了,但是订单号只是显示年月日和两位随机号,如:2006102387 !
请问可以改成:订单号输出如:20050613235934985
表示:2005年06月13日23时59分34秒985随机数吗?需要怎么改?谢谢!!!
reason
高级会员
高级会员
 
帖子: 117
注册: 2006-06-29 22:42

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子qings » 2006-11-28 11:29

版本1.3.6中文,经过多次测试,虽然orders_id定义为int(11),但是这样随机生成的订单号在10位数没有问题,11位数就会错误,后台察看订单号都是2147483647,再加新订单会说订单号已经存在,无法更新数据库。即使将int(11)加大也仍然是2147483647,这就是楼上10位随机号没有错误的原因,不知道是不是一个bug。

同时收回11月17日发文修改orders_id为varchar的发文,对该文的误导表示歉意。
qings
普通会员
普通会员
 
帖子: 34
注册: 2006-03-21 21:20

Re: 按时间+随机数结合产生订单号 (订单方便管理与确认) 的问题?

帖子radnows » 2006-11-28 20:04

mysql数据库的int值只有10位,再多也是无效。
头像
radnows
论坛版主
论坛版主
 
帖子: 3128
注册: 2005-08-09 23:57
地址: radnows.com

下一页

回到 安装设置

 


  • 相关话题
    回复总数
    阅读次数
    最新文章

在线用户

正在浏览此版面的用户:没有注册用户 和 5 位游客