您的位置:首页 > 编程语言

KingCMS接触之:模块开发(代码部分之后台按钮操作)

2010-10-14 13:28 471 查看
在king_def中不是有三个按钮么.他们默认都是ajax操作的.所以函数命名要以king_ajax_函数名. 这种方式.下面是三个秒杀的按钮操作

function king_ajax_delete(){
global $king;
$king->access('portal_secondbuy_delete');
$list=kc_getlist();
$array=explode(',',$list);
$king->db->query("delete from %s_secbuydir where seid in ($list)");
kc_ajax('OK',"<p class=/"k_ok/">".$king->lang->get('system/ok/delete')."</p>",1);
}


这个比较简单.kc_getlist会拿到复选框的数组.跟着用in操作删除记录.你只要改一下表名和复选框所用的列就可以.注意kc_ajax的最后参数1

 

function king_ajax_combing(){
global $king;
$king->access('portal_secondbuy_combing');
//取得所有的临时表
$res=$king->db->getRows("select table_name from information_schema.TABLES where table_name like 'king__temp%'");
if(!$res) $res=array();
foreach($res as $rs){
//临时表的最后一条记录是否写到groupbuy表中
$currTable=$rs['table_name'];
//取到最后一条记录
$inresult=$king->db->getRows_one("select usergroup,nprice,userid,username,ktitle,productID,nip,ndate,serial from ".$currTable." order by sbid desc limit 1");
$currTableLastarr=array(
'usergroup'=>$inresult['usergroup'],
'nprice'=>$inresult['nprice'],
'userid'=>$inresult['userid'],
'username'=>$inresult['username'],
'ktitle'=>$inresult['ktitle'],
'productID'=>$inresult['productID'],
'nip'=>$inresult['nip'],
'ndate'=>$inresult['ndate'],
'serial'=>$inresult['serial'],
'category'=>1,
);
$inprores=$king->db->getRows_one("select k_nstart,k_nfinish,unix_timestamp(k_nfinish)as symbol from %s__shop where kid=".$currTableLastarr['productID']);
$activstart=$inprores['k_nstart'];
$activfinish=$inprores['k_nfinish'];
//如果没有Z加到groupbuy表中
if($inprores['symbol']-$currTableLastarr['ndate']>1) {
$king->db->insert('%s_groupbuy',$currTableLastarr);
}
$countrs=$king->db->getRows_one("select count(distinct(nip))as ipnumber,count(userid)as number from ".$currTable);
$finalarr=array(
"productID"=>$currTableLastarr['productID'],
"ktitle"=>$currTableLastarr['ktitle'],
"nprice"=>$currTableLastarr['nprice'],
"number"=>$countrs['number'],
"ipnumber"=>$countrs['ipnumber'],
"userid"=>$currTableLastarr['userid'],
"username"=>$currTableLastarr['username'],
"nip"=>$currTableLastarr['nip'],
"nstartdate"=>$activstart,
"nendate"=>$activfinish,
"ndate"=>$inresult['ndate'],
);
//统计信息
$king->db->insert('%s_secbuydir',$finalarr);
//删除临时表
$king->db->dropTable($currTable);
}
kc_ajax('OK',"<p class=/"k_ok/">".$king->lang->get('portal/secondbuy/ok')."</p>",1);
}

 

秒杀只能记录结束的前一秒和结束时间的最后一秒.这两个秒位上.反之的记录都在临时表中如果你想整理一下这次活动的信息可以用的上这个操作.

 

$res=$king->db->getRows("select table_name from information_schema.TABLES where table_name like 'king__temp%'");

 if(!$res) $res=array();

 foreach($res as $rs){

      ...etc

 }

从mysql的架构信息表中找到所有以king__temp为开头的表名.开始整理临时表数据

 

//临时表的最后一条记录是否写到groupbuy表中

$currTable=$rs['table_name'];

//取到最后一条记录

$inresult=$king->db->getRows_one("select usergroup,nprice,userid,username,ktitle,productID,nip,ndate,serial from ".$currTable." order by sbid desc limit 1");

这里说一下我的表设计.groupbuy表中记录的用户的操作.后台需要的数据在secbuydir合称是秒杀字典.如果正好在上面说的两个秒位上有人点了连接.在group表中是有记录的.反之没有.我也不知道下一秒会发生什么事情.这里我就需要知道到底在最后的两个秒位有没有人.只要这样作:

   1.取到临时表的最后一条记录的时间

   2.取产品活动的结束时间

两者一减就知道了.

 $inprores=$king->db->getRows_one("select k_nstart,k_nfinish,unix_timestamp(k_nfinish)as symbol from %s__shop where kid=".$currTableLastarr['productID']);

 $activstart=$inprores['k_nstart'];

 $activfinish=$inprores['k_nfinish'];

  //如果没有Z加到groupbuy表中

 if($inprores['symbol']-$currTableLastarr['ndate']>1) {                         

             $king->db->insert('%s_groupbuy',$currTableLastarr);

  }

 

到这里你或许有不同观点!示例么.如果在最后两个秒位没有人点取最后一条入到group表中

 

        $countrs=$king->db->getRows_one("select count(distinct(nip))as ipnumber,count(userid)as number from ".$currTable);

        $finalarr=array(

             "productID"=>$currTableLastarr['productID'],

             "ktitle"=>$currTableLastarr['ktitle'],

             "nprice"=>$currTableLastarr['nprice'],

             "number"=>$countrs['number'],

             "ipnumber"=>$countrs['ipnumber'],

             "userid"=>$currTableLastarr['userid'],

             "username"=>$currTableLastarr['username'],

             "nip"=>$currTableLastarr['nip'],

             "nstartdate"=>$activstart,

             "nendate"=>$activfinish,   

             "ndate"=>$inresult['ndate'],

        );

        //统计信息

        $king->db->insert('%s_secbuydir',$finalarr);

        //删除临时表

        $king->db->dropTable($currTable);

整理活动数据入到secbuydir表中删除临时表
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息