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

1

... ... @@ -22,84 +22,6 @@ class ActiveController extends WeChatBaseController
$this->checkWeChatUserLogin();
}
//品牌详情
public function brandDetail()
{
$re=$this->checkUser();
$id=$this->request->param('id');
$data=Db::name('brand')
->alias('b')
->join('brand_category bc1','b.category_id=bc1.id')
->join('brand_category bc2','b.floor_id=bc2.id')
->where('b.id',$id)
->field('b.*,bc1.name as cname,bc2.name as fname')
->find();
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$like=Db::name('like')->where(['cid'=>$id,'users_id'=>$re['id'],'status'=>1])->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'=>1])
->field('c.*,u.*')
->select();
$this->assign('comment',$comment);
$this->assign('like',$like);
$this->assign('list',$data);
return $this->fetch('brand_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']=1;
$param['users_id']=$re['id'];
$result=Db::name('comment')->where(['users_id'=>$param['users_id'],'status'=>1,'cid'=>$param['cid']])->find();
if ($result){
return 2;
}
$re1=Db::name('comment')->insert($param);
$re2=Db::name('brand')->where('id',$param['cid'])->setInc('comment',1);
if ($re1 && $re2) {
$url = url('portal/brand/brandDetail', 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'],1,$re['id']);
}
//活动首页
public function active(){
$this->checkUser();
... ... @@ -151,10 +73,40 @@ class ActiveController extends WeChatBaseController
$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']);
}
... ...
... ... @@ -22,12 +22,13 @@ class BrandController extends WeChatBaseController
$this->checkWeChatUserLogin();
}
//品牌首页接口
public function brand()
{
$this->checkUser();
// $param=$this->request->param();
$where['b.status']=1;
$where['b.status'] = 1;
// if (!empty($param['category'])){
// $where['b.category_id']=$param['category'];
// }
... ... @@ -39,316 +40,125 @@ class BrandController extends WeChatBaseController
// }else{
// $order['create_time']='desc';
// }
$category=Db::name('brand_category')->where('status',1)->select();
$floor=Db::name('brand_category')->where('status',2)->select();
$data=Db::name('brand')
$category = Db::name('brand_category')->where('status', 1)->select();
$floor = Db::name('brand_category')->where('status', 2)->select();
$data = Db::name('brand')
->alias('b')
->join('brand_category bc1','b.category_id=bc1.id')
->join('brand_category bc2','b.floor_id=bc2.id')
->join('brand_category bc1', 'b.category_id=bc1.id')
->join('brand_category bc2', 'b.floor_id=bc2.id')
->where($where)
->order('b.create_time','desc')
->order('b.create_time', 'desc')
->field('b.*,bc1.name as cname,bc2.name as fname')
->select();
$this->assign('category',$category);
$this->assign('floor',$floor);
$this->assign('list',$data);
$this->assign('category', $category);
$this->assign('floor', $floor);
$this->assign('list', $data);
return $this->fetch();
}
//品牌ajax
public function brandAjax()
{
$param=$this->request->param();
$param = $this->request->param();
$where['b.status']=1;
if (!empty($param['category'])){
$where['b.category_id']=$param['category'];
$where['b.status'] = 1;
if (!empty($param['category'])) {
$where['b.category_id'] = $param['category'];
}
if (!empty($param['floor'])){
$where['b.floor_id']=$param['floor'];
if (!empty($param['floor'])) {
$where['b.floor_id'] = $param['floor'];
}
if (!empty($param['search'])){
$where['b.name']=['like','%'.$param['search'].'%'];
if (!empty($param['search'])) {
$where['b.name'] = ['like', '%' . $param['search'] . '%'];
}
if (!empty($param['order'])){
$order['b.dolike']='desc';
}else{
$order['b.create_time']='desc';
if (!empty($param['order'])) {
$order['b.dolike'] = 'desc';
} else {
$order['b.create_time'] = 'desc';
}
$data=Db::name('brand')
$data = Db::name('brand')
->alias('b')
->join('brand_category bc1','b.category_id=bc1.id')
->join('brand_category bc2','b.floor_id=bc2.id')
->join('brand_category bc1', 'b.category_id=bc1.id')
->join('brand_category bc2', 'b.floor_id=bc2.id')
->where($where)
->order($order)
->field('b.*,bc1.name as cname,bc2.name as fname')
->select()->toArray();
foreach ($data as $k => $v) {
$data[$k]['url']=url('portal/brand/brandDetail',array('id'=>$data[$k]['id']));
$data[$k]['image'] = cmf_get_image_preview_url($data[$k]['thumbnail']);
};
foreach ($data as $k => $v) {
$data[$k]['url'] = url('portal/brand/brandDetail', array('id' => $data[$k]['id']));
$data[$k]['image'] = cmf_get_image_preview_url($data[$k]['thumbnail']);
};
return $data;
}
//品牌详情
public function brandDetail()
{
$re=$this->checkUser();
$id=$this->request->param('id');
$data=Db::name('brand')
$re = $this->checkUser();
$id = $this->request->param('id');
$data = Db::name('brand')
->alias('b')
->join('brand_category bc1','b.category_id=bc1.id')
->join('brand_category bc2','b.floor_id=bc2.id')
->where('b.id',$id)
->join('brand_category bc1', 'b.category_id=bc1.id')
->join('brand_category bc2', 'b.floor_id=bc2.id')
->where('b.id', $id)
->field('b.*,bc1.name as cname,bc2.name as fname')
->find();
$data['content']=cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$like=Db::name('like')->where(['cid'=>$id,'users_id'=>$re['id'],'status'=>1])->find();
if ($like){
$like=1;
}else{
$like=0;
$data['content'] = cmf_replace_content_file_url(htmlspecialchars_decode($data['content']));
$like = Db::name('like')->where(['cid' => $id, 'users_id' => $re['id'], 'status' => 1])->find();
if ($like) {
$like = 1;
} else {
$like = 0;
}
$comment=Db::name('comment')
$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'=>1])
->join('users u', 'c.users_id=u.id')
->join('brand b', 'c.cid=b.id')
->where(['b.id' => $id, 'c.status' => 1])
->field('c.*,u.*')
->select();
$this->assign('comment',$comment);
$this->assign('like',$like);
$this->assign('list',$data);
$this->assign('comment', $comment);
$this->assign('like', $like);
$this->assign('list', $data);
return $this->fetch('brand_detail');
}
//品牌评论页面
public function comment(){
public function comment()
{
$this->checkUser();
$id=$this->request->param('id');
$this->assign('id',$id);
$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']=1;
$param['users_id']=$re['id'];
$result=Db::name('comment')->where(['users_id'=>$param['users_id'],'status'=>1,'cid'=>$param['cid']])->find();
if ($result){
public function commentPost()
{
$re = $this->checkUser();
$param = $this->request->param();
$param['create_time'] = time();
$param['status'] = 1;
$param['users_id'] = $re['id'];
$result = Db::name('comment')->where(['users_id' => $param['users_id'], 'status' => 1, 'cid' => $param['cid']])->find();
if ($result) {
return 2;
}
$re1=Db::name('comment')->insert($param);
$re2=Db::name('brand')->where('id',$param['cid'])->setInc('comment',1);
$re1 = Db::name('comment')->insert($param);
$re2 = Db::name('brand')->where('id', $param['cid'])->setInc('comment', 1);
if ($re1 && $re2) {
$url = url('portal/brand/brandDetail', array('id' => $param['cid']));
return $url;
}else{
} else {
return 0;
}
}
//点赞ajax接口
public function like(){
$re=$this->checkUser();
$param=$this->request->param();
$like=new LikeService();
return $like->like($param['id'],1,$re['id']);
}
//活动首页
public function active(){
$where['status']=1;
if (!empty($this->request->param('status'))) {
$where['status'] =$this->request->param('status');
}
$banner=Db::name('active')->where('is_top',1)->field('thumbnail')->select();
$this->assign('banner',$banner);
$data=Db::name('active')->where($where)->select();
$this->assign('list',$data);
return $this->fetch();
}
//活动详情
public function activeDetail()
//点赞ajax接口
public function like()
{
$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'=>session('wechat_user')['users_id'],'status'=>2])->find();
if ($like){
$like=1;
}else{
$like=0;
}
$this->assign('like',$like);
$this->assign('list',$data);
return $this->fetch();
}
//兑奖首页
public function prize(){
$user=Db::name('users')->where('id',session('wechat_user')['users_id'])->find();
$prize=Db::name('prize')->where('status',1)->select();
$category=Db::name('prize_category')->select();
$this->assign('user',$user);
$this->assign('prize',$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;
}
$prize=Db::name('prize')->where($where)->select();
return $prize;
}
//兑奖详情页
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(){
$re = $this->checkUser();
$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'));
$like = new LikeService();
return $like->like($param['id'], 1, $re['id']);
}
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;
}
}
}
}
\ No newline at end of file
... ...
... ... @@ -291,14 +291,31 @@
$(".comment").click(function(){
window.location.href='writeevalute.html'
})
//点赞
$(".discuss").click(function(){
window.event.stopPropagation();
var num=$(".commentnum").html();
num++;
$(".commentnum").html(num)
$(".praise").click(function(){
$.ajax({
url: "{:url('portal/active/like')}",
type: "post",
data: {
id:"{$list.id}",
},
success: function (data) {
if (data==1){
alert('点赞成功')
window.event.stopPropagation();
var num=$(".commentnum").html();
num++;
$(".commentnum").html(num)
}
else if (data==2){
alert('取消点赞成功')
window.event.stopPropagation();
var num=$(".commentnum").html();
num--;
$(".commentnum").html(num)
}
}
})
})
</script>
</html>
... ...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<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;
}
.evalute{
width:6.86rem;
margin: 0 auto;
height:3.6rem;
background:#F7F8FA ;
margin-top: 0.35rem;
border-radius: 0.1rem;
}
.write{
width:6.86rem;
margin: 0 auto;
height:3.6rem;
background:#F7F8FA ;
margin-top: 0.35rem;
border-radius: 0.1rem;
border:none;
outline:none;
padding-left: 0.31rem;
color:#999999;
font-size: 0.33rem;
}
.footer{
width:6.86rem;
text-align: center;
height:0.88rem;
line-height: 0.88rem;
position:fixed;
bottom:0.55rem;
left:0;
right:0;
margin: 0 auto;
background:#CA277B ;
border-radius: 0.44rem;
color:#fff;
font-size:0.32rem ;
}
</style>
</head>
<body>
<div class="container">
<div class="evalute">
<textarea name="" id="comment" cols="30" rows="10" class="write" placeholder="请写下您的评价"></textarea>
</div>
</div>
<div class="footer">发表</div>
<script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
<script>
$(".footer").click(function(){
var comment=$("#comment").val()
$.ajax({
url: "{:url('portal/active/commentPost')}",
type: "post",
data: {
cid:"{$id}",
content:comment,
},
success: function (data) {
if (data==0){
alert('评论失败')
return false;
}
else if (data==2){
alert('您已经评论过了')
return false;
}else {
alert('评论成功')
window.location.href=data;
}
}
})
})
</script>
</body>
</html>
... ...
... ... @@ -302,7 +302,6 @@
})
//点赞
$(".praise").click(function(){
// alert("{$list.id}")
$.ajax({
url: "{:url('portal/brand/like')}",
type: "post",
... ...