📄 nkshop.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 ($FORM{'act'} eq "newbie") {
print ("Set-Cookie: order=; path=/\n");
print ("Set-Cookie: count=; path=/\n");
print ("Set-Cookie: spec=; path=/\n");
$LIB->Location("$CON{path}{cgiurl}/nkshop.cgi");
}
else {&main;}
sub main
{
#===============================
my (%dbs,@view,$text);
#print ("Set-Cookie: test_var=0; path=/\n");
#获得商品分类信息
my $dm_product_cate=0;
$sth=$LIB->MySQL_Query("select cate_num,cate_name,cate_image from pro_cate where cate_level = '1' and cate_type = '0' order by cate_cretime");
while (($row = $sth->fetchrow_arrayref)){
$dbs{'product_cate'}{"$dm_product_cate"}={
cate_num => $row->[0],
cate_name => $row->[1],
cgiurl => $CON{path}{cgiurl},
};
$dm_product_cate++;
}
#获得生存关系信息
my $dm_lifefoot=0;
$sth=$LIB->MySQL_Query("select cate_num,cate_name,cate_image from pro_cate where cate_type = '1'");
while (($row = $sth->fetchrow_arrayref)){
$dbs{'lifefoot'}{"$dm_lifefoot"}={
num => $row->[0],
name => $row->[1],
cgiurl=>$CON{path}{cgiurl},
};
$dm_lifefoot++;
}
###########随机演示产品(由于MySQL版本过低采用这个算法)
my $dm_product=0;
my (@all_num,@all_number,$des);
$sth=$LIB->MySQL_Query("select num from store");
while (($row = $sth->fetchrow_arrayref)){
push(@all_num,$row->[0]);
}
@all_number = $LIB->RandNumber($#all_num,$CON{parameter}{main_demo_limit});
foreach (@all_number) {
$sth=$LIB->MySQL_Query("select num,name,image,des,price from store where num = $all_num[$_]");
$row=$sth->fetchrow_arrayref();
$des=$LIB->Str_dual($row->[3],$CON{parameter}{main_demo_word});
$dbs{'product'}{"$dm_product"}={
num => $row->[0],
name => $row->[1],
image => $row->[2],
des => $des."...",
price => $row->[4],
cgiurl => $CON{path}{cgiurl},
imgurl => $CON{path}{webimg},
};
$dm_product++;
}
#my $dm_product=0;
#my $des;
#$sth=$LIB->MySQL_Query("select num,name,image,des,price from store order by cretime desc limit $CON{parameter}{main_demo_limit}");
#while (($row = $sth->fetchrow_arrayref)){
# $des=$LIB->Str_dual($row->[3],$CON{parameter}{main_demo_word});
# $dbs{'product'}{"$dm_product"}={
# num => $row->[0],
# name => $row->[1],
# image => $row->[2],
# des => $des."...",
# price => $row->[4],
# cgiurl => $CON{path}{cgiurl},
# imgurl => $CON{path}{webimg},
# };
# $dm_product++;
#}
###########最热门的东西
my $dm_hot_product=0;
$sth=$LIB->MySQL_Query("select num,name,image,des,price from store order by choosed desc limit $CON{parameter}{main_hot_product}");
while (($row = $sth->fetchrow_arrayref)){
$des=$LIB->Str_dual($row->[3],$CON{parameter}{main_demo_word});
$dbs{'hot_product'}{"$dm_hot_product"}={
num => $row->[0],
name => $row->[1],
image => $row->[2],
des => $des."...",
price => $row->[4],
cgiurl => $CON{path}{cgiurl},
imgurl => $CON{path}{webimg},
};
$dm_hot_product++;
}
###########最新的东西
my $dm_new_product=0;
$sth=$LIB->MySQL_Query("select num,name,image,des,price from store order by cretime desc limit $CON{parameter}{main_new_product}");
while (($row = $sth->fetchrow_arrayref)){
$des=$LIB->Str_dual($row->[3],$CON{parameter}{main_demo_word});
$dbs{'new_product'}{"$dm_new_product"}={
num => $row->[0],
name => $row->[1],
image => $row->[2],
des => $des."...",
price => $row->[4],
cgiurl => $CON{path}{cgiurl},
imgurl => $CON{path}{webimg},
};
$dm_new_product++;
}
#########
#购物车处理
my (@user_order,@user_count,$all_orders,$i);
#if ($COOKIE{'test_var'} eq '1') {
@user_order=$LIB->Shopping("$COOKIE{'order'}");
@user_count=$LIB->Shopping("$COOKIE{'count'}");
#}
#else {
# @user_order=$LIB->Shopping("$FORM{'order'}");
# @user_count=$LIB->Shopping("$FORM{'count'}");
#}
$all_orders=0;
for ($i=0;$i<=$#user_order ;$i++) {
#########
#取得已订购商品
$sth=$LIB->MySQL_Query("select name from store where num = '$user_order[$all_orders]'");
$row = $sth->fetchrow_arrayref();
if ($row->[0] ne "") {
$dbs{'all_orders'}{"$all_orders"}={
count => $all_orders+1,
order_count => $user_count[$all_orders],
name => $row->[0],
};
$all_orders++;
}
}
$text={
cgiurl => $CON{path}{cgiurl},
imgurl => $CON{path}{webimg},
htmurl => $CON{path}{htmurl},
loop_product_cate => $dm_product_cate-1,
loop_product=> $dm_product-1,
loop_hot_product => $dm_hot_product-1,
loop_new_product => $dm_new_product-1,
loop_lifefoot => $dm_lifefoot-1,
loop_all_orders => $all_orders-1,
};
@view=$LIB->Parse("shop_main.htm",$text,%dbs);
print @view;
#MySQL Disconnect
$LIB->MySQL_Disconnect();
#The END
$LIB->exit();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -