控制器:
public function _initialize(){
parent::_initialize();
//用户积分
$integral = M("Member")->where(array('id'=>$_SESSION['qtuid']))->getField("score");
$this->assign("integral",$integral);
}
//积分
public function jifen(){
//产品列表
$pro_data = $this->getPro2("积分商品",$this->lang,0,1,1,12);
$this->assign("pro_data",$pro_data);
$this->display();
}
//签到——积分
public function signin(){
$uid = I("uid");
$where['id']=$uid;
$where['signindata'] = date('Y-m-d', time());
$m = M("Member");
$exist = $m->where($where)->find();
if ($exist) {
// $this->error('今日已经签到');
// return false;
$data = 2;
}else{
$where2['id'] = $uid;
$score = $m->where($where2)->getField("score");
$data['score'] = $score+1;
$data['signindata'] = date('Y-m-d', time());
if($m->where($where2)->limit(1)->save($data)){
// $this->success("签到成功",U("Member/jifen"));
$data = 1;
}else{
// $this->error("签到失败");
$data = 3;
}
}
$this -> ajaxReturn($data);
}
//积分兑换商品
public function redeem(){
// $uid = I("uid");
$uid = $_SESSION['qtuid'];
$gid = I("gid");
$where['id'] = $uid;
$m = M("Member");
$score = $m->where($where)->getField("score");
$prodata = M("Product")->where(array('id'=>$gid))->find();
$price = $prodata['price'];
if($score>=$price){
$n=M("redeem");
$n->user_id = $uid;
$n->pro_id = $prodata['id'];
$n->ProductName = $prodata['proname'];
$n->addtime = time();
if($n->add()){
$where2['id'] = $uid;
$score = $m->where($where2)->getField("score");
$data[score]=$score-$price;
M("Member")->where($where2)->limit(1)->save($data);
// $this->success("兑换成功",U("Member/jifen"));
$data = 1;
}else{
// $this->error("兑换失败");
$data = 2;
}
}else{
// $this->error("您的积分不足以兑换该商品");
$data = 3;
}
$this -> ajaxReturn($data);
}
//已兑换的商品
public function jifgoods(){
$where['user_id']=$_SESSION['qtuid'];
//收藏列表
$m=M('Redeem');
$data=$m->join('RIGHT JOIN tp_product ON tp_redeem.pro_id = tp_product.id' )->where($where)->select();
import("ORG.Util.Pager");
$count = count($data);
$page = new Page($count,6);
$show = $page->show();
//已兑换的商品列表
$redeemlist=$m->join('RIGHT JOIN tp_product ON tp_redeem.pro_id = tp_product.id' )->field('tp_redeem.*,tp_product.proname,tp_product.prophoto,tp_product.prointo')->where($where)->limit($page->firstRow.','.$page->listRows)->select();
$this->assign("redeemlist",$redeemlist);
$this->assign("page",$show);
$this->display();
}
jifen.php-每日签到送积分:
积分中心(积分:<{$integral}>)
每日签到送积分
积分是由用户购买商品时产生的,一般按一元一分,100元的购物可送100的积分。
);">签 到
----------------------------------------
jifen.php-积分商品:
-
<{$vo.proname}>
<{$vo.price}>积分可兑换);">兑换
<{$page}>
-------------------------------------------------------------------------------------------
jifgoods.php-已兑换商品:
数据表:
积分兑换商品表
CREATE TABLE IF NOT EXISTS `tp_redeem` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(4) DEFAULT NULL COMMENT '会员id',
`pro_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '商品id',
`ProductName` varchar(120) NOT NULL DEFAULT '' COMMENT '商品名称',
`addtime` varchar(30) DEFAULT NULL COMMENT '添加时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='积分兑换商品表' AUTO_INCREMENT=2 ;
产品表
CREATE TABLE IF NOT EXISTS `tp_product` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`cid` int(4) DEFAULT NULL COMMENT '分类id',
`bid` int(11) DEFAULT '0' COMMENT '品牌id',
`lang` tinyint(1) DEFAULT '0' COMMENT '语言',
`proname` varchar(255) NOT NULL DEFAULT '' COMMENT '产品名称',
`price` varchar(30) DEFAULT NULL COMMENT '产品价格',
`isphoto` tinyint(1) DEFAULT '0' COMMENT '是否有图片',
`prophoto` varchar(30) NOT NULL DEFAULT '' COMMENT '产品图片',
`prothumb1` varchar(30) DEFAULT NULL COMMENT '产品缩略图1',
`prothumb2` varchar(30) DEFAULT NULL COMMENT '产品缩略图2',
`prointo` text COMMENT '产品简介',
`procontent` longtext COMMENT '产品详细说明',
`isshow` tinyint(2) DEFAULT NULL COMMENT '是否显示',
`isrecom` tinyint(2) DEFAULT NULL COMMENT '是否推荐',
`orderby` int(11) DEFAULT NULL COMMENT '排序',
`issj` tinyint(1) DEFAULT '0',
`sjisshow` tinyint(1) DEFAULT '1',
`sjprocon` longtext,
`opti` tinyint(1) DEFAULT '0',
`yetitle` varchar(50) DEFAULT NULL,
`keywords` text COMMENT '关键词',
`descri` text,
`hits` int(4) DEFAULT '0' COMMENT '点击量',
`otherpro` varchar(100) DEFAULT NULL COMMENT '其他产品',
`othernews` varchar(100) DEFAULT NULL COMMENT '其他新闻',
`otherdown` varchar(100) DEFAULT NULL COMMENT '其他下载',
`otheranswer` varchar(100) DEFAULT NULL COMMENT '其他回答',
`is_other_img` tinyint(1) DEFAULT '0' COMMENT '是否有关联图',
`tag_id` varchar(255) DEFAULT NULL,
`addtime` varchar(30) DEFAULT NULL COMMENT '添加时间',
`updatetime` varchar(30) DEFAULT NULL COMMENT '修改时间',
`pro_spec` text,
`sketch` text,
`islink` tinyint(1) DEFAULT '0' COMMENT '是否外链',
`title_href` varchar(100) DEFAULT NULL COMMENT '链接地址',
`bewrite` longtext COMMENT '产品描述',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=51 ;
会员表
CREATE TABLE IF NOT EXISTS `tp_member` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`roleid` int(4) DEFAULT '0',
`username` varchar(30) CHARACTER SET gbk NOT NULL,
`nicname` varchar(30) DEFAULT NULL,
`password` char(32) CHARACTER SET gbk NOT NULL,
`email` varchar(32) DEFAULT NULL,
`tel` varchar(16) DEFAULT NULL,
`addtime` int(11) DEFAULT NULL,
`addip` varchar(20) DEFAULT NULL,
`disable` tinyint(1) unsigned zerofill DEFAULT NULL,
`updatetime` int(11) DEFAULT NULL,
`loginnum` int(11) DEFAULT '0',
`lastlogip` varchar(20) DEFAULT NULL,
`lastlogtime` varchar(30) DEFAULT NULL,
`nowlogip` varchar(20) DEFAULT NULL,
`nowlogtime` varchar(30) DEFAULT NULL,
`score` varchar(255) NOT NULL COMMENT '积分',
`signindata` varchar(30) NOT NULL COMMENT '签到时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC AUTO_INCREMENT=5 ;