先看代码一一讲解:
<?php require_once '../global.php'; function king_secondbuy(){ global $king; $king->Load('user'); $user=$king->user->access(); //验证 //用户资料是否完整 $res=$king->db->getRows_one("select gid,realname,usertel,useraddress from %s_user where userid='".$user['userid']."' and isdelete=0"); if(!empty($res['realname']) && !empty($res['usertel']) && !empty($res['useraddress'])){ //是否为合理的秒产产品:现在的时间>开始时间<结束时间 $category=((int)kc_get('CID',2,0)!=1)?1:(int)kc_get('CID',2,0); $productID=(int)kc_get('PID',2,1); $serial=($res['gid']==2)?'':kc_random(16); $group=((int)$res['gid']===2)?"vip会员":"普通会员"; $res=$king->db->getRows_one("select unix_timestamp(k_nfinish)as finidate,ktitle,nprice from %s__shop where kid=".$productID." and localtimestamp() BETWEEN k_nstart AND k_nfinish"); if(empty($res)) kc_error($king->lang->get('portal/groupbuy/buyrang')); //活动结束了 $currdate=time(); //当前 $finidate=$res['finidate']; //结束时间 $title=$res['ktitle']; $price=$res['nprice']; $array=array( 'usergroup'=>$group, 'nprice'=>$price, 'userid'=>$user['userid'], 'username'=>$user['username'], 'ktitle'=>$title, 'productID'=>$productID, 'nip'=>kc_getip(), 'ndate'=>$currdate, 'serial'=>$serial, ); //临时表是否存在 $tmptab="temp".$productID; $sql="select ndate from %s__".$tmptab." order by sbid desc limit 1"; $res=$king->db->getRows_one($sql); if(!$res || empty($res)){ //创建临时表 $sql="usergroup char(10) NOT NULL, nprice real not null default 0, userid int(11) NOT NULL DEFAULT 0, username char(15) NOT NULL DEFAULT '', ktitle varchar(100) DEFAULT NULL, productID int(11) NOT NULL DEFAULT 0, nip int(10) NOT NULL DEFAULT 0, ndate int(10) NOT NULL DEFAULT 0, serial varchar(20) DEFAULT NULL"; $king->db->createTable("%s__{$tmptab}",$sql,'sbid'); //第一位参与者 } //写到临时表 $king->db->insert('%s__'.$tmptab,$array); //作临界点判断 if($finidate-$currdate<=1){ //取当前的.0,1 //提到表中 $array=array( 'usergroup'=>$group, 'nprice'=>$price, 'userid'=>$user['userid'], 'username'=>$user['username'], 'ktitle'=>$title, 'productID'=>$productID, 'nip'=>kc_getip(), 'ndate'=>time(), 'serial'=>$serial, 'category'=>$category, 'nstatus'=>0, ); //先入为主 $res=$king->db>getRows_one("select count(gb.userid)as number from %s_groupbuy gb join %s__shop s on gb.productID=s.kid where gb.category=".$category." and s.kid=".$productID." and unix_timestamp(s.k_nfinish)-gb.ndate<=1"); if($res['number']==0) $king->db->insert('%s_groupbuy',$array); //删除临时表 } $goto=$king->config('inst').'index.php'; //pktsandy code $stitle=$king->lang->get('portal/groupbuy/newbuy'); $s.=kc_htm_ol($king->lang->get('portal/groupbuy/sbaccess'),'',$goto); }else{ $stitle=$king->lang->get('portal/groupbuy/gbalert'); $s=$king->lang->get('portal/groupbuy/reqmore'); } $tmp=new KC_Template_class($king->config('templateuser','user'),$king->config('templatepath').'/inside/user/login.htm'); $tmp->assign('title',$stitle); $tmp->assign('main',$s); echo $tmp->output(); } ?>
函数名:king_secondbuy()
这个有点像struts中的action.你只要写上文件名.php?action=下划线后面的名字kingCMS就可以找到它
global $king;
拿到核心类的实例
$king->Load('user');
如由当前是在portal模块所以要加载user模块.这一个他设计的不错.按需加载么
$user=$king->user->access(); //验证
作身份验证.判断是否登陆成功.没有登陆跳到登陆页面
$res=$king->db->getRows_one("select gid,realname,usertel,useraddress from %s_user where userid='".$user['userid']."' and isdelete=0");
if(!empty($res['realname']) && !empty($res['usertel']) && !empty($res['useraddress'])){
如果用户资料中的真实姓名和联系电话还有地址空让他去填写
.....这部分应该都能看懂
}else{
$stitle=$king->lang->get('portal/groupbuy/gbalert');
$s=$king->lang->get('portal/groupbuy/reqmore');
}
$tmp=new KC_Template_class($king->config('templateuser','user'),$king->config('templatepath').'/inside/user/login.htm');
创建一个模板实例.
$tmp->assign('title',$stitle);
$tmp->assign('main',$s);
简单理解成作string的replace就可以
echo $tmp->output();
输出内容
}