作者 潘浩文
1 个管道 的构建 通过 耗费 1 秒

1

<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;
use app\portal\service\LikeService;
use cmf\controller\HomeBaseController;
use cmf\controller\WeChatBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
class PrizeController extends WeChatBaseController
{
public function _initialize()
{
parent::_initialize();
$this->checkWeChatUserLogin();
}
//活动首页
public function active(){
$this->checkUser();
$banner=Db::name('active')->where('is_top',1)->field('thumbnail')->select();
$this->assign('banner',$banner);
$data=Db::name('active')->where('status',1)->select();
$this->assign('list',$data);
return $this->fetch();
}
//活动首页ajax
public function activeAjax(){
$this->checkUser();
$status=$this->request->param('status');
$data=Db::name('active')->where('status',$status)->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['url']=url('portal/active/activeDetail',array('id'=>$data[$k]['id']));
$data[$k]['image'] = cmf_get_image_preview_url($data[$k]['thumbnail']);
$data[$k]['active_time'] = date('Y-m-d',$data[$k]['active_time']);
$data[$k]['end_time'] = date('Y-m-d',$data[$k]['end_time']);
};
return $data;
}
//活动详情
public function activeDetail()
{
$re=$this->checkUser();
$id=$this->request->param('id');
$data=Db::name('active')
->where('id',$id)
->find();
$data['more']=json_decode($data['more'],true);
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$like=Db::name('like')->where(['cid'=>$id,'users_id'=>$re['id'],'status'=>2])->find();
if ($like){
$like=1;
}else{
$like=0;
}
$comment=Db::name('comment')
->alias('c')
->join('users u','c.users_id=u.id')
->join('brand b','c.cid=b.id')
->where(['b.id'=>$id,'c.status'=>2])
->field('c.*,u.*')
->select();
$this->assign('comment',$comment);
$this->assign('like',$like);
$this->assign('list',$data);
return $this->fetch('active_detail');
}
public function comment(){
$this->checkUser();
$id=$this->request->param('id');
$this->assign('id',$id);
return $this->fetch();
}
public function commentPost(){
$re=$this->checkUser();
$param=$this->request->param();
$param['create_time']=time();
$param['status']=2;
$param['users_id']=$re['id'];
$result=Db::name('comment')->where(['users_id'=>$param['users_id'],'status'=>2,'cid'=>$param['cid']])->find();
if ($result){
return 2;
}
$re1=Db::name('comment')->insert($param);
$re2=Db::name('active')->where('id',$param['cid'])->setInc('comment',1);
if ($re1 && $re2) {
$url = url('portal/active/activeDetail', array('id' => $param['cid']));
return $url;
}else{
return 0;
}
}
//点赞ajax接口
public function like(){
$re=$this->checkUser();
$param=$this->request->param();
$like=new LikeService();
return $like->like($param['id'],2,$re['id']);
}
//兑奖首页
public function prize(){
$re=$this->checkUser();
$user=Db::name('users')->where('id',$re['id'])->find();
$prize=Db::name('prize')->where('status',1)->select();
$category=Db::name('prize_category')->select();
$this->assign('user',$user);
$this->assign('list',$prize);
$this->assign('category',$category);
return $this->fetch();
}
//兑奖首页ajax
public function prizeAjax(){
$category=$this->request->param('category');
$where['status']=1;
if (!empty($category)){
$where['category_id']=$category;
}
$data=Db::name('prize')->where($where)->select();
foreach ($data as $k => $v) {
$data[$k]['url']=url('portal/prize/prizeDetail',array('id'=>$data[$k]['id']));
$data[$k]['image'] = cmf_get_image_preview_url($data[$k]['thumbnail']);
};
return $data;
}
//兑奖详情页
public function prizeDetail(){
$id=$this->request->param('id');
$data=Db::name('prize')
->where('id',$id)
->find();
$data['more']=json_decode($data['more'],true);
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$like=Db::name('like')->where(['cid'=>$id,'users_id'=>session('wechat_user')['users_id'],'status'=>3])->find();
if ($like){
$like=1;
}else{
$like=0;
}
$order=Db::name('prize_order')->where(['prize_id'=>$id,'users_id'=>session('wechat_user')['users_id'],'status'=>1])->find();
if ($order){
$order=1;
}else{
$order=0;
}
$this->assign('order',$order);
$this->assign('like',$like);
$this->assign('list',$data);
return $this->fetch();
}
public function getPrize(){
$id=$this->request->param('id');
$data['prize_id']=$id;
$data['users_id']=session('wechat_user')['users_id'];
$data['create_time']=time();
Db::name('prize_order')->insert($data);
return 1;
}
//上传小票
public function upload(){
$options = [
'app_id' => config('wechat_config.app_id'),
'secret' => config('wechat_config.secret'),
'payment' => config('wechat_config.payment'),
];
$app = new Application($options);
$js = $app->js;
$jss = $js->config(['chooseImage', 'uploadImage', 'previewImage'], $debug = false, $beta = false, $json = true);
$this->assign('js', $jss);
return $this->fetch();
}
//上传小票提交
public function uploadPost(){
$param = $this->request->param();
$options = [
'app_id' => config('wechat_config.app_id'),
'secret' => config('wechat_config.secret'),
'payment' => config('wechat_config.payment'),
];
$app = new Application($options);
// 获取 access token 实例
$access_token = $app->access_token;
return $this->getmedia($access_token, $param['media'], date('Ymd'));
}
private function getmedia($access_token, $media_id, $foldername)
{
$url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" . $access_token . "&media_id=" . $media_id;
if (!file_exists("./upload/" . $foldername)) {
mkdir("./upload/" . $foldername, 0777, true);
}
$file_name = date('YmdHis') . rand(1000, 9999) . '.jpg';
$targetName = './upload/' . $foldername . '/' . $file_name;
$saveName = $foldername . '/' . $file_name;
$ch = curl_init($url); // 初始化
$fp = fopen($targetName, 'wb'); // 打开写入
curl_setopt($ch, CURLOPT_FILE, $fp); // 设置输出文件的位置,值是一个资源类型
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return $saveName;
}
//兑奖记录
public function prizeRecord(){
$status=$this->request->param('status');
$where['p.status']=!empty($status)?$status:0;
$data=Db::name('prize_order')
->alias('po')
->join('prize p'.'po.prize_id=p.id')
->where($where)
->select();
$this->assign('list',$data);
return $this->fetch();
}
//个人首页
public function userIndex(){
$last = Db::name('users_score_log')->where(['users_id' => session('wechat_user')['users_id'], 'action' => '签到'])->max('create_time');
if (date('Ymd', time()) > date('Ymd', $last)) {
$is_qiandao=0;
}else{
$is_qiandao=1;
}
$data=Db::name('users')->where('id',session('wechat_user')['users_id'])->find();
$this->assign('list',$data);
$this->assign('qiandao',$is_qiandao);
return $this->fetch();
}
public function scoreRecord(){
$score=Db::name('users')->where('id',session('wechat_user')['users_id'])->find()['score'];
$data=Db::name('users_score_log')->where('users_id',session('wechat_user')['users_id'])->select();
$this->assign('score',$score);
$this->assign('list',$data);
return $this->fetch();
}
//每日签到功能
public function qiandao(){
$last = Db::name('users_score_log')->where(['users_id' => session('wechat_user')['users_id'], 'action' => '签到'])->max('create_time');
if (date('Ymd', time()) > date('Ymd', $last)) {
$data['score'] = 10;
$data['users_id'] = session('users_id');
$data['create_time'] = time();
$data['action'] = '签到';
Db::name('users_score_log')->insert($data);
Db::name('users')->where('id', session('wechat_user')['users_id'])->setInc('score', 10);
return 1;
} else {
return 0;
}
}
}
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="__TMPL__/public/assets/css/base.css">
<script type="text/javascript" src="__TMPL__/public/assets/js/base.js"></script>
<title>兑礼</title>
<style>
body,html{
background:#fff;
}
.head{
box-sizing: border-box;
display:flex;
padding: 0.31rem 0.3rem;
background: #fff;
}
.head_info{
display:flex;
}
.head_img{
width:1rem;
height:1rem;
}
.head_img img{
width:100%;
height:100%;
}
.head_name{
color:#1A1A1A;
font-size: 0.32rem;
height:1rem;
line-height: 1rem;
margin-left: 0.24rem;
}
.convertibility{
font-size: 0;
margin-left: 0.8rem;
}
.exchange{
display:flex;
margin-top: 0.2rem;
}
.points{
text-align: center;
}
.current_points{
font-size: 0.26rem;
color:#999999;
}
.points_num{
color:#CA287B;
font-size: 0.26rem;
}
.exchangepoints{
width:1.8rem;
height:0.6rem;
border-radius: 0.3rem;
color:#1A1A1A;
font-size: 0.26rem;
border:1px solid rgba(204,204,204,1);
text-align: center;
line-height: 0.6rem;
}
.exchangelist{
width:1.8rem;
height:0.6rem;
border-radius: 0.3rem;
color:#1A1A1A;
font-size: 0.26rem;
border:1px solid rgba(204,204,204,1);
text-align: center;
line-height: 0.6rem;
margin-left: 0.2rem;
}
.active{
background: #CA287B;
color:#fff;
}
.type{
display:flex;
justify-content: space-between;
align-items: center;
height:0.8rem;
padding: 0.27rem 0.49rem;
background: #fff;
/*margin-top: 0.16rem;*/
}
.type li{
list-style: none;
font-size: 0.28rem;
color:#53575C;
}
.type .item{
color:#CA277B;
}
.integral_num{
font-size:0.32rem;
color:#CA277B;
font-weight: bold;
}
.integral_chinese{
font-size:0.32rem;
color:#CA277B;
}
.present_name{
color:#000000;
font-size: 0.32rem;
margin-top: 0.1rem;
margin-left: 0.32rem;
}
.integral{
font-size: 0;
margin-top: 0.08rem;
margin-left: 0.32rem;
}
.present_img{
width:3.71rem;
height:3.71rem;
font-size: 0;
}
.present_img img{
width:100%;
height:100%;
}
.presentlist{
overflow: hidden;
padding-bottom: 0.3rem;
}
.presentlist_item{
float:left;
margin-top: 0.3rem;
}
.presentlist_item:nth-child(2n){
margin-left: 0.08rem;
}
.presentlist_item:nth-child(1){
margin-top: 0;
}
.presentlist_item:nth-child(2){
margin-top: 0;
}
.line{
height:0.16rem;
background:#F5F6FA;
}
</style>
</head>
<body>
<div class="container">
<div class="head">
<div class="head_info">
<p class="head_img"><img src="{:cmf_get_image_preview_url($user.avatar)}" alt=""></p>
<p class="head_name">{$user.name}</p>
</div>
<div class="convertibility">
<div class="points">
<span class="current_points">当前积分余额为</span>
<span class="points_num">{$user.score}</span>
</div>
<div class="exchange">
<a href="{:url('portal/prize/getScore')}" style="text-decoration:none;">
<p class="exchangepoints">兑换积分</p>
</a>
<a href="{:url('user/user/scoreRecord')}" style="text-decoration:none;">
<p class="exchangelist active">兑换记录</p>
</a>
</div>
</div>
</div>
<div class="line"></div>
<div class="body">
<ul class="type">
<li data-id="" class="item">全部</li>
<foreach name="category" item="vo">
<li data-id="{$vo.id}">{$vo.name}</li>
</foreach>
</ul>
<div class="presentlist">
<foreach name="list" item="vo">
<a href="{:url('portal/prize/prizeDetail',array('id'=>$vo.id))}" style="text-decoration:none;">
<div class="presentlist_item">
<p class="present_img">
<img src="{:cmf_get_image_preview_url($vo.thumbnail)}" alt="">
</p>
<p class="present_name">{$vo.name}</p>
<p class="integral">
<span class="integral_num">{$vo.score}</span>
<span class="integral_chinese">积分</span>
</p>
</div>
</a>
</foreach>
</div>
</div>
</div>
<script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
<script>
$(".type li").click(function(){
$(this).addClass("item");
$(this).siblings("li").removeClass("item")
var id=$(this).data('id')
$.ajax({
url: "{:url('portal/prize/prizeAjax')}",
type: "post",
data: {
category:id,
},
success: function (data) {
var html = "";
for (var i = 0; i < data.length; i++) {
html +=' <a href="'+data[i].url+'" style="text-decoration:none;">\n' +
' <div class="presentlist_item">\n' +
' <p class="present_img">\n' +
' <img src="'+data[i].image+'" alt="">\n' +
' </p>\n' +
' <p class="present_name">'+data[i].name+'</p>\n' +
' <p class="integral">\n' +
' <span class="integral_num">'+data[i].score+'</span>\n' +
' <span class="integral_chinese">积分</span>\n' +
' </p>\n' +
' </div>\n' +
' </a>'
}
$(".presentlist").html(html);
}
})
})
</script>
</body>
</html>
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/base.css">
<link rel="stylesheet" href="css/swiper.css">
<script type="text/javascript" src="js/base.js"></script>
<title>兑礼详情</title>
<style>
body,html{
background:#F5F6FA;
}
.head{
height:3.6rem;
}
.swiper-container{
position:relative;
height:3.6rem;
}
.swiper-slide{
height:3.6rem;
}
.swiper-slide img{
width:100%;
height:100%;
}
.content{
display:flex;
justify-content: space-between;
align-items: center;
height:1.14rem;
padding: 0.4rem 0.32rem;
background: #fff;
margin-top: 0.16rem;
}
.discuss{
display:flex;
position:relative;
}
.praise{
width:0.6rem;
height:0.6rem;
background: #CA277B;
border-radius: 50%;
font-size: 0;
text-align: center;
vertical-align: middle;
margin-right: 0.16rem;
}
.praise img{
width:0.28rem;
height:0.28rem;
margin-top: 0.15rem;
}
.comment{
width:1.4rem;
height:0.6rem;
background:#CA277B;
color:#fff;
font-size: 0.26rem;
text-align: center;
line-height: 0.6rem;
border-radius:0.3rem;
}
.content_name{
color: #000000;
font-size: 0.32rem;
}
.text{
background: #fff;
padding: 0.32rem 0.33rem;
margin-top: 0.16rem;
}
.text_name{
color:#252729;
font-size: 0.26rem;
}
.text_content{
color:#252729;
font-size: 0.26rem;
margin-top: 0.24rem;
line-height: 1.7;
}
.activedetail{
margin-top: 0.16rem;
background: #fff;
}
.shop_tab{
display:flex;
justify-content: space-between;
padding: 0.31rem 1.36rem;
align-items: center;
width:7.5rem;
height:0.88rem;
background: #fff;
border-bottom: 1px solid #f5f5f5;
}
.tab{
color:#97A0A8;
font-size: 0.26rem;
position: relative;
}
.active{
color:#CA277B;
}
.active em{
width:0.8rem;
height:0.06rem;
position: absolute;
left:0;
right:0;
top: 0.45rem;
margin: 0 auto;
background:#CA277B;
border-radius: 0.03rem;
}
.goodtail_name{
display:flex;
justify-content: space-between;
align-items: center;
margin-top: 0.36rem;
}
.good_line{
width:2.5rem;
height:1px;
background: #f5f5f5;
}
.good_name{
color:#999999;
font-size: 0.26rem;
}
.goodtail{
background: #fff;
padding: 0 0.24rem 0.5rem 0.24rem;
margin-bottom: 0.8rem;
}
.commenttail{
background: #fff;
padding: 0 0.24rem 0.5rem 0.24rem;
margin-bottom: 0.8rem;
}
.goodtail_img{
width:7.02rem;
margin-top: 0.16rem;
}
.goodtail_img img{
width:100%;
height:100%;
}
.comment_list{
display:flex;
border-bottom: 1px solid #f5f5f5;
padding: 0.3rem 0;
}
.comment_img{
width:0.8rem;
height:0.8rem;
border-radius: 50%;
font-size: 0;
}
.comment_img img{
width:100%;
height:100%;
}
.comment_name{
color:#000000;
font-size: 0.3rem;
}
.comment_date{
color:#999999;
font-size: 0.24rem;
}
.comment_text{
color:#000000;
font-size: 0.28rem;
width:5.86rem;
margin-top: 0.53rem;
}
.comment_content{
margin-left: 0.19rem;
}
.container{
position:relative;
}
.title{
width:7.5rem;
height:0.2rem;
font-size: 0;
position:absolute;
top:0;
z-index: 9;
}
.title img{
width:100%;
height:100%;
}
.foot{
height:1rem;
position: fixed;
bottom:0;
display:flex;
justify-content: space-between;
align-items: center;
border-top:1px solid #f5f5f5;
}
.total{
box-sizing: border-box;
height:1rem;
width:5rem;
background: #fff;
display:flex;
padding-left: 0.41rem;
}
.total_zi{
color:#666666;
font-size: 0.24rem;
height:1rem;
line-height: 1rem;
}
.total_num{
font-size: 0.32rem;
color:#C9277A;
font-weight: bold;
}
.total_integral{
font-size: 0.32rem;
color:#C9277A;
}
.total_points{
display:flex;
margin-left: 0.2rem;
height:1rem;
line-height: 1rem;
}
.changenow{
width:2.5rem;
height:1rem;
background: #C9277A;
color:#fff;
font-size:0.32rem ;
text-align: center;
line-height: 1rem;
}
.alchange{
width:2.5rem;
height:1rem;
background: #C2ADB8;
color:#fff;
font-size:0.32rem ;
text-align: center;
line-height: 1rem;
}
.commentnum{
width:0.3rem;
text-align: center;
height:0.3rem;
line-height: 0.3rem;
background:#CA277B;
border-radius: 50%;
color:#fff;
position:absolute;
left:0.4rem;
font-size: 0.2rem;
}
</style>
</head>
<body>
<div class="container">
<div class="head">
<div class="title">
<img src="img/line.png" alt="">
</div>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide">
<img src="img/ritualbanner.png" alt="" >
</div>
<div class="swiper-slide">
<img src="img/ritualbanner.png" alt="" >
</div>
<div class="swiper-slide">
<img src="img/ritualbanner.png" alt="" >
</div>
</div>
<div class="swiper-pagination"></div>
</div>
</div>
<div class="content">
<div class="content_name">淘气包免费体验30分钟</div>
<div class="discuss">
<p class="praise">
<img src="img/zan.png" alt="">
<p class="commentnum">11</p>
</p>
<p class="comment">
评论留言
</p>
</div>
</div>
<div class="text">
<p class="text_name">兑换要求</p>
<p class="text_content">
兑换,不同货币的交换。
谓两种货币按一定比值交换。《文献通考·钱币二》:“尚书省言,东南诸路盗铸当十钱者多,乃诏广南福建路更不行使当十钱,
</p>
</div>
<div class="activedetail">
<div class="shop_tab">
<p class="tab active" id="1">
<em></em>
活动详情
</p>
<P class="tab" id="2">
<em></em>
评论留言
</P>
</div>
<div class="goodtail" >
<div class="goodtail_name">
<p class="good_line"></p>
<p class="good_name">活动详情</p>
<p class="good_line"></p>
</div>
<div class="goodtail_img">
<img src="img/activetail.png" alt="">
</div>
</div>
<div class="commenttail" style="display:none">
<div class="comment_list">
<div class="comment_img">
<img src="img/commentlist.png" alt="">
</div>
<div class="comment_content">
<p class="comment_name">向昱筱</p>
<p class="comment_date">2018-03-09</p>
<div class="comment_text">
颜值高口感好,很新鲜,奶油一点都不腻,超清
爽的口感,奶香味很浓,非常喜欢。
</div>
</div>
</div>
<div class="comment_list">
<div class="comment_img">
<img src="img/commentlist.png" alt="">
</div>
<div class="comment_content">
<p class="comment_name">向昱筱</p>
<p class="comment_date">2018-03-09</p>
<div class="comment_text">
颜值高口感好,很新鲜,奶油一点都不腻,超清
爽的口感,奶香味很浓,非常喜欢。
</div>
</div>
</div>
<div class="comment_list">
<div class="comment_img">
<img src="img/commentlist.png" alt="">
</div>
<div class="comment_content">
<p class="comment_name">向昱筱</p>
<p class="comment_date">2018-03-09</p>
<div class="comment_text">
颜值高口感好,很新鲜,奶油一点都不腻,超清
爽的口感,奶香味很浓,非常喜欢。
</div>
</div>
</div>
<div class="comment_list">
<div class="comment_img">
<img src="img/commentlist.png" alt="">
</div>
<div class="comment_content">
<p class="comment_name">向昱筱</p>
<p class="comment_date">2018-03-09</p>
<div class="comment_text">
颜值高口感好,很新鲜,奶油一点都不腻,超清
爽的口感,奶香味很浓,非常喜欢。
</div>
</div>
</div>
</div>
</div>
<div class="foot">
<div class="total" >
<div class="total_zi">合计:</div>
<div class="total_points">
<span class="total_num">800</span>
<span class="total_integral">积分</span>
</div>
</div>
<div class="right_now changenow">立即兑换</div>
</div>
<div class="foot" style="display:none">
<div class="total">
<div class="total_zi">合计:</div>
<div class="total_points">
<span class="total_num">800</span>
<span class="total_integral">积分</span>
</div>
</div>
<div class="right_now alchange">已兑换</div>
</div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/swiper.min.js"></script>
<script>
var mySwiper = new Swiper('.swiper-container', {
pagination: {
el: '.swiper-pagination',
},
autoplay: true,//可选选项,自动滑动
})
$(".tab").click(function(){
if($(this).attr("id")==1){
$(this).addClass("active");
$(this).siblings(".tab").removeClass("active")
$(".goodtail").css("display","block");
$(".commenttail").css("display","none")
}else if($(this).attr("id")==2){
$(this).addClass("active");
$(this).siblings(".tab").removeClass("active")
$(".goodtail").css("display","none");
$(".commenttail").css("display","block")
}
})
//评论留言
$(".comment").click(function(){
window.location.href='writeevalute.html'
})
//立即兑换
$(".right_now").click(function(){
window.location.href='uploadticket.html'
})
//点赞
$(".discuss").click(function(){
window.event.stopPropagation();
var num=$(".commentnum").html();
num++;
$(".commentnum").html(num)
})
</script>
</body>
</html>
... ...