Ad.php
5.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* tpshop
* ============================================================================
* 版权所有 2015-2027 深圳搜豹网络科技有限公司,并保留所有权利。
* 网站地址: http://www.tp-shop.cn
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
* 不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* Author: 当燃
* Date: 2015-09-21
*/
namespace app\manager\controller;
use think\Page;
class Ad extends Base{
public function ad(){
$act = I('get.act','add');
$ad_id = I('get.ad_id/d');
$ad_info = array();
if($ad_id){
$ad_info = D('ad')->where('ad_id',$ad_id)->find();
$ad_info['start_time'] = date('Y-m-d',$ad_info['start_time']);
$ad_info['end_time'] = date('Y-m-d',$ad_info['end_time']);
}
if($act == 'add')
$ad_info['pid'] = $this->request->param('pid');
$position = D('ad_position')->where('1=1')->select();
$this->assign('info',$ad_info);
$this->assign('act',$act);
$this->assign('position',$position);
return $this->fetch();
}
public function adList(){
delFile(RUNTIME_PATH.'Html'); // 先清除缓存, 否则不好预览
$Ad = M('ad');
$pid = I('pid',0);
if($pid){
$where['pid'] = $pid;
$this->assign('pid',I('pid'));
}
$keywords = I('keywords/s',false,'trim');
if($keywords){
$where['ad_name'] = array('like','%'.$keywords.'%');
}
$count = $Ad->where($where)->count();// 查询满足要求的总记录数
$Page = $pager = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
$res = $Ad->where($where)->order('pid desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$list = array();
if($res){
$media = array('图片','文字','flash');
foreach ($res as $val){
$val['media_type'] = $media[$val['media_type']];
$list[] = $val;
}
}
$ad_position_list = M('AdPosition')->getField("position_id,position_name,is_open");
$this->assign('ad_position_list',$ad_position_list);//广告位
$show = $Page->show();// 分页显示输出
$this->assign('list',$list);// 赋值数据集
$this->assign('page',$show);// 赋值分页输出
$this->assign('pager',$pager);
return $this->fetch();
}
public function position(){
$act = I('get.act','add');
$position_id = I('get.position_id/d');
$info = array();
if($position_id){
$info = D('ad_position')->where('position_id',$position_id)->find();
}
$this->assign('info',$info);
$this->assign('act',$act);
return $this->fetch();
}
public function positionList(){
$Position = M('ad_position');
$count = $Position->where('1=1')->count();// 查询满足要求的总记录数
$Page = $pager = new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
$list = $Position->order('position_id DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('list',$list);// 赋值数据集
$show = $Page->show();// 分页显示输出
$this->assign('page',$show);// 赋值分页输出
$this->assign('pager',$pager);
return $this->fetch();
}
public function adHandle(){
$data = I('post.');
$data['start_time'] = strtotime($data['begin']);
$data['end_time'] = strtotime($data['end']);
if($data['act'] == 'add'){
$r = D('ad')->add($data);
}
if($data['act'] == 'edit'){
$r = D('ad')->where('ad_id', $data['ad_id'])->save($data);
}
if($data['act'] == 'del'){
$r = D('ad')->where('ad_id', $data['del_id'])->delete();
if($r) exit(json_encode(1));
}
$referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U('manager/Ad/adList');
// 不管是添加还是修改广告 都清除一下缓存
delFile(RUNTIME_PATH.'Html'); // 先清除缓存, 否则不好预览
if($r){
$this->success("操作成功",U('manager/Ad/adList'));
}else{
$this->error("操作失败",$referurl);
}
}
public function positionHandle(){
$data = I('post.');
if($data['act'] == 'add'){
$r = M('ad_position')->add($data);
}
if($data['act'] == 'edit'){
$r = M('ad_position')->where('position_id',$data['position_id'])->save($data);
}
if($data['act'] == 'del'){
if(M('ad')->where('pid',$data['position_id'])->count()>0){
$this->error("此广告位下还有广告,请先清除",U('manager/Ad/positionList'));
}else{
$r = M('ad_position')->where('position_id', $data['position_id'])->delete();
if($r) exit(json_encode(1));
}
}
$referurl = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : U('manager/Ad/positionList');
if($r){
$this->success("操作成功",$referurl);
}else{
$this->error("操作失败",$referurl);
}
}
public function changeAdField(){
$field = $this->request->request('field');
$data[$field] = I('get.value');
$data['ad_id'] = I('get.ad_id');
M('ad')->save($data); // 根据条件保存修改的数据
}
}