?? order.cgi
字號:
#!/usr/bin/perl
#
#
##########################################################
# 網絡小廚房 商店系統
# Net Kitchen SHOP
##########################################################
#首頁代碼
##########################################################
####################################################################################
#前端預處理
####################################################################################
use FindBin qw($Bin);
use lib "$Bin/library";
use iLcatlib;
use strict;
use vars qw(%FORM %CON %COOKIE $LIB $sth $row @userdata);
#獲得系統參數
tie %CON, 'IniFiles', ( -file => "$Bin/nkshop.ini" );
#構造新對象
$LIB=iLcatlib->new(ttmlpath=>"$CON{path}{ttmlpath}");
#獲得COOKIE
%COOKIE=$LIB->ReadCookie();
#獲得提交內容
%FORM=$LIB->ReadParse();
#連接數據庫
$LIB->MySQL_Connect(
database=>"$CON{database}{database}",
dbhost=>"$CON{database}{dbhost}",
dbuser=>"$CON{database}{dbuser}",
dbpwd=>"$CON{database}{dbpwd}"
);
#用戶檢測
@userdata=$LIB->key_proc("$COOKIE{'key'}","$CON{parameter}{timeout}");
#if ($COOKIE{'test_var'} ne '1') {$LIB->Error("無法正確處理購物車系統,請修改降低您瀏覽器的安全級別");}
if ($FORM{'act'} eq "buy") {&buy;}
elsif ($FORM{'act'} eq "adjust") {&adjust;}
elsif ($FORM{'act'} eq "do_adjust") {&do_adjust;}
elsif ($FORM{'act'} eq "send_order") {&send_order;}
elsif ($FORM{'act'} eq "check_send_order") {&check_send_order;}
elsif ($FORM{'act'} eq "do_send_order") {&do_send_order;}
else {$LIB->Error("Null Request");}
############################################################################################
#將商品存在用戶COOKIE當中
############################################################################################
sub buy
{
my ($user_order,$user_count,$user_spec,$save_cookie);
#########
#先讀出商品的資料
#取得商品
$sth=$LIB->MySQL_Query("select num,statmsg from store where num = '$FORM{'num'}'");
$row = $sth->fetchrow_arrayref();
if ($row->[0] eq "") {$LIB->Error("沒有這個商品存在");}
if ($row->[1] eq 1) {$LIB->Error("無貨不能訂購,如果您有需要請與本站聯系");}
#########
#再讀出COOKIE里已經有的商品
#if ($COOKIE{'test_var'} eq '1') {
$user_order=$COOKIE{'order'};
$user_count=$COOKIE{'count'};
$user_spec=$COOKIE{'spec'};
#$save_cookie = &iLcatlib::cookie(-name=>'order',
# -value=>"$user_order");
print ("Set-Cookie: order=$user_order$row->[0]║; path=/\n");
print ("Set-Cookie: count=$user_count","1║; path=/\n");
print ("Set-Cookie: spec=$user_spec","NULL║; path=/\n");
$LIB->Location("$CON{path}{cgiurl}/nkshop.cgi");
#}
#else {
# $user_order="$FORM{'order'}$row->[0]║";
# $user_count="$FORM{'count'}1║";
# $user_spec="$FORM{'spec'}NULL║";
# $LIB->Location("$CON{path}{cgiurl}/nkshop.cgi?order=$user_order&count=$user_count&user_spec=$user_spec");
#}
#MySQL Disconnect And The END
$LIB->MySQL_Disconnect();$LIB->exit();
}
############################################################################################
# 訂購的商品調整
############################################################################################
sub adjust
{
my ($text,$ordered,@user_order,@user_count,@user_spec,%dbs);
#if ($COOKIE{'order'} eq "") {$LIB->Error("您未做任何訂購");}
###讀出訂購商品
@user_order=$LIB->Shopping("$COOKIE{'order'}");
@user_count=$LIB->Shopping("$COOKIE{'count'}");
@user_spec=$LIB->Shopping("$COOKIE{'spec'}");
###########調整
my $dm_pro_list=0;
my $i=0;
my $all_price=0;
for ($i=0;$i<=$#user_order ;$i++) {
my (@spec_desc,@spec,$fspec,$spec_price);
if ($user_order[$i] =~ /[0-9]/) {
if ($user_spec[$i] eq 'NULL') {$user_spec[$i]="";}
$sth=$LIB->MySQL_Query("select num,name,price,spec_desc,spec from store where num = '$user_order[$i]'");
$row = $sth->fetchrow_arrayref();
if ($row->[3] ne "") {#在當產品有類型的情況下
@spec_desc=$LIB->Str_spec($row->[3]);
@spec=$LIB->Str_spec($row->[4]);
for(my $fsc=0;$fsc<=$#spec;$fsc++) {
#計算當前類型是否加價
$spec_price=$spec[$fsc] if ($spec_desc[$fsc] eq $user_spec[$i]);
#記錄類型選擇數據
$fspec .=qq~<option value="$spec_desc[$fsc]">$spec_desc[$fsc]</option>~;
}
}
#總加價
$spec_price=$spec_price*$user_count[$i];
#計算總價
$all_price=$spec_price+$all_price+$user_count[$i]*$row->[2];
if ($row->[0] ne "") {
$dbs{'pro_list'}{"$dm_pro_list"}={
num => $row->[0],
name => $row->[1],
price => $row->[2],
spec_current => $user_spec[$i],
spec_price => $spec_price,
spec => $fspec,
count => $i,
order_count => $user_count[$i],
};
$dm_pro_list++;
}
}
}
$text = {
cgiurl => $CON{path}{cgiurl},
imgurl => $CON{path}{webimg},
loop_pro_list => $dm_pro_list-1,
all_price => $all_price,
};
print $LIB->Parse("shop_adjust.htm",$text,%dbs);
#MySQL Disconnect And The END
$LIB->MySQL_Disconnect();$LIB->exit();
}
sub do_adjust
{
my ($text,@user_order,@user_count,@user_spec,%dbs);
if ($COOKIE{'order'} eq "") { $LIB->Location("$CON{path}{cgiurl}/nkshop.cgi");}
###讀出訂購商品
@user_order=$LIB->Shopping("$COOKIE{'order'}");
@user_count=$LIB->Shopping("$COOKIE{'count'}");
@user_spec=$LIB->Shopping("$COOKIE{'spec'}");
#########
#重新編碼
my ($i,$new_order,$new_count,$new_spec);
for ($i=0;$i<=$#user_order ;$i++) {
if ($FORM{"rm$i"} eq "0") {#刪除一條
}
elsif ($user_count[$i] eq "0") {
}
else {#重新編碼
$new_order.=qq~$user_order[$i]║~;
if ($FORM{"order_count$i"} ne $user_count[$i]) {
$new_count.=qq~$FORM{"order_count$i"}║~;
}
else {
$new_count.=qq~$user_count[$i]║~;
}
if ($FORM{"new_spec$i"} ne 'NULL') {
$new_spec.=qq~$FORM{"new_spec$i"}║~;
}
else {
$new_spec.=qq~$user_spec[$i]║~;
}
}
}
print ("Set-Cookie: order=$new_order; path=/\n");
print ("Set-Cookie: count=$new_count; path=/\n");
print ("Set-Cookie: spec=$new_spec; path=/\n");
if ($FORM{'type'} eq "0") {
$LIB->Location("$CON{path}{cgiurl}/nkshop.cgi");
}
elsif ($FORM{'type'} eq "2") {
$LIB->Location("$CON{path}{cgiurl}/order.cgi?act=send_order");
}
else {
$LIB->Location("$CON{path}{cgiurl}/order.cgi?act=adjust");
}
#MySQL Disconnect And The END
$LIB->MySQL_Disconnect();$LIB->exit();
}
sub send_order
{
my (%dbs,$text,$all_order_count);
my (@user_order,@user_count,@user_spec);
if ($COOKIE{'order'} eq "") { $LIB->Error("在沒有訂購商品的情況下是無法發送定單");}
###讀出訂購商品
@user_order=$LIB->Shopping("$COOKIE{'order'}");
@user_count=$LIB->Shopping("$COOKIE{'count'}");
@user_spec=$LIB->Shopping("$COOKIE{'spec'}");
###########調整
my $dm_pro_list=0;
my $i=0;
my $all_price=0;
for ($i=0;$i<=$#user_order ;$i++) {
my (@spec_desc,@spec,$spec_price,$pro_value);
if ($user_order[$i] =~ /[0-9]/) {
if ($user_spec[$i] eq 'NULL') {$user_spec[$i]="";}
$sth=$LIB->MySQL_Query("select num,name,price,spec_desc,spec,pid from store where num = '$user_order[$i]'");
$row = $sth->fetchrow_arrayref();
if ($row->[3] ne "") {#在當產品有類型的情況下
@spec_desc=$LIB->Str_spec($row->[3]);
@spec=$LIB->Str_spec($row->[4]);
for(my $fsc=0;$fsc<=$#spec;$fsc++) {
#計算當前類型是否加價
$spec_price=$spec[$fsc] if ($spec_desc[$fsc] eq $user_spec[$i]);
}
}
#總加價(型號加價*附加費)
$spec_price=$spec_price*$user_count[$i];
#單總價(單種訂購量*單價格)
$pro_value=$user_count[$i]*$row->[2]+$spec_price;
#計算總價(當前單種價+總價)
$all_price=$all_price+$pro_value;
#總數量(當前數量+單種數量)
$all_order_count=$all_order_count+$user_count[$i];
if ($row->[0] ne "") {
$dbs{'pro_list'}{"$dm_pro_list"}={
num => $row->[0],
name => $row->[1],
price => $row->[2],
pro_value => $pro_value,
spec_current => $user_spec[$i],
spec_price => $spec_price,
order_count => $user_count[$i],
pid => $row->[5],
};
$dm_pro_list++;
}
}
}
#計算郵費
my (%ems,%pack);
%ems=&_count_postage('0',$all_order_count);
%pack=&_count_postage('1',$all_order_count);
$text = {
loop_pro_list => $dm_pro_list-1,
all_price => $all_price,
ems => $ems{'value'},
pack => $pack{'value'},
sendpack_num => $CON{parameter}{rec_num_type1},
sendpack_value => $CON{parameter}{rec_value_type1},
sendpack_addup => $CON{parameter}{rec_addup_type1},
sendems_num => $CON{parameter}{rec_num_type0},
sendems_value => $CON{parameter}{rec_value_type0},
sendems_addup => $CON{parameter}{rec_addup_type0},
imgurl => $CON{path}{webimg},
cgiurl => $CON{path}{cgiurl},
};
print $LIB->Parse("shop_order_form.htm",$text,%dbs);
#MySQL Disconnect And The END
$LIB->MySQL_Disconnect();$LIB->exit();
}
sub check_send_order
{
my (@view,%dbs);
my ($text,$user_row);
if ($FORM{'uid'} eq "") {$LIB->Error("請填寫用戶名");}
elsif ($FORM{'rec_type'} ne '1' and $FORM{'rec_type'} ne '0') {$LIB->Error('收貨方式錯誤');}
elsif ($FORM{'change_info'} eq 'yes') {
if ($FORM{'rec_name'} eq "") {$LIB->Error('沒有收貨人');}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -