作者 景龙
1 个管道 的构建 通过 耗费 1 秒

增加后台城市上传banner图功能

@@ -17,20 +17,19 @@ use think\Db; @@ -17,20 +17,19 @@ use think\Db;
17 class ActiveController extends HomeBaseController 17 class ActiveController extends HomeBaseController
18 { 18 {
19 private $index_limit = 16;//首页分页 19 private $index_limit = 16;//首页分页
20 - private $more_limit = 6;//更多列表分页 20 + private $more_limit = 5;//更多列表分页
21 public function index(){ 21 public function index(){
22 //星际活动 22 //星际活动
23 - $page = $this->request->param('page',1,'intval');  
24 $position['category_id'] = CityCategoryModel::xjhd_c; 23 $position['category_id'] = CityCategoryModel::xjhd_c;
25 $field = 'id,thumbnail,post_title'; 24 $field = 'id,thumbnail,post_title';
26 - $res_xjhd = $this->getChildArticlePage($position,$field,$page);  
27 - $this->assign('res_xjhd',$res_xjhd);  
28 - 25 + $res = $this->getChildArticlePage($position,$field);
  26 + $this->assign('res',$res['data']);
  27 + $this->assign('page',$res['page']);
29 return $this->fetch(); 28 return $this->fetch();
30 } 29 }
31 30
32 //根据子类获取文章分页 31 //根据子类获取文章分页
33 - public function getChildArticlePage($position,$field,$page,$limit=''){ 32 + public function getChildArticlePage($position,$field,$limit=''){
34 $pre = CityCategoryModel::pre; 33 $pre = CityCategoryModel::pre;
35 $limit = empty($limit)?$this->more_limit:$limit; 34 $limit = empty($limit)?$this->more_limit:$limit;
36 $post_id = Db::table($pre.'portal_category_post') 35 $post_id = Db::table($pre.'portal_category_post')
@@ -44,10 +43,10 @@ class ActiveController extends HomeBaseController @@ -44,10 +43,10 @@ class ActiveController extends HomeBaseController
44 ->whereIn('id',$post_id) 43 ->whereIn('id',$post_id)
45 ->where('delete_time', 0) 44 ->where('delete_time', 0)
46 ->field($field) 45 ->field($field)
47 - ->page($page,$limit)  
48 ->order('weigh desc') 46 ->order('weigh desc')
49 - ->select()  
50 - ->toArray(); 47 + ->paginate($limit);
  48 + $arr['data'] = $res->toArray();
  49 + $arr['page'] = $res->render();
51 return $res; 50 return $res;
52 } 51 }
53 52
@@ -29,6 +29,11 @@ class StarController extends HomeBaseController @@ -29,6 +29,11 @@ class StarController extends HomeBaseController
29 $this->assign('city_name',$city_name); 29 $this->assign('city_name',$city_name);
30 $this->assign('city_id',$city_id); 30 $this->assign('city_id',$city_id);
31 $position['city_id'] = $city_id; 31 $position['city_id'] = $city_id;
  32 +
  33 + //城市名称对应banner图
  34 + $city_banner = $this->getCityBanner($city_id);
  35 + $this->assign('city_banner',$city_banner);
  36 +
32 //星球故事 37 //星球故事
33 $position['category_id'] = CityCategoryModel::xqgs; 38 $position['category_id'] = CityCategoryModel::xqgs;
34 $field = 'id,thumbnail,post_excerpt,more'; 39 $field = 'id,thumbnail,post_excerpt,more';
@@ -79,14 +84,24 @@ class StarController extends HomeBaseController @@ -79,14 +84,24 @@ class StarController extends HomeBaseController
79 84
80 //获取城市名称 85 //获取城市名称
81 public function getCityName($city_id){ 86 public function getCityName($city_id){
82 - $city_name = Db::name('city_category') 87 + $res = Db::name('city_category')
83 ->where('id',$city_id) 88 ->where('id',$city_id)
84 ->field('id,name') 89 ->field('id,name')
85 ->find(); 90 ->find();
86 - $city_name = empty($city_name)?'':$city_name['name']; 91 + $city_name = empty($res['name'])?'':$res['name'];
87 return $city_name; 92 return $city_name;
88 } 93 }
89 94
  95 + //获取城市banner图
  96 + public function getCityBanner($city_id){
  97 + $res = Db::name('city_category')
  98 + ->where('id',$city_id)
  99 + ->field('id,image')
  100 + ->find();
  101 + $banner = empty($res['image'])?'':$res['image'];
  102 + return $banner;
  103 + }
  104 +
90 //根据子类获取文章 105 //根据子类获取文章
91 public function getChildArticle($position,$field,$limit=''){ 106 public function getChildArticle($position,$field,$limit=''){
92 $pre = CityCategoryModel::pre; 107 $pre = CityCategoryModel::pre;
@@ -33,6 +33,21 @@ @@ -33,6 +33,21 @@
33 </div> 33 </div>
34 </div> 34 </div>
35 35
  36 + <div class="form-group">
  37 + <label for="thumbnail">banner图</label>
  38 + <div>
  39 + <input type="text" class="form-control" id="thumbnail" name="image">
  40 + <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
  41 + <img src="__TMPL__/public/assets/images/default-thumbnail.png"
  42 + id="thumbnail-preview"
  43 + width="300" height="150" style="cursor: pointer"/>
  44 + </a>
  45 + <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
  46 + <a href="javascript:uploadOneImage('图片上传','#thumbnail');">上传图片</a>
  47 + </div>
  48 + <span class="form-required">图片参考尺寸:1920*666</span>
  49 + </div>
  50 +
36 </div> 51 </div>
37 </div> 52 </div>
38 <div class="form-group"> 53 <div class="form-group">
@@ -45,4 +60,12 @@ @@ -45,4 +60,12 @@
45 </div> 60 </div>
46 <script type="text/javascript" src="__STATIC__/js/admin.js"></script> 61 <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
47 </body> 62 </body>
48 -</html>  
  63 +</html>
  64 +<script type="text/javascript">
  65 + $(function () {
  66 + $('.btn-cancel-thumbnail').click(function () {
  67 + $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
  68 + $('#thumbnail').val('');
  69 + });
  70 + });
  71 +</script>
@@ -32,6 +32,26 @@ @@ -32,6 +32,26 @@
32 <input type="text" class="form-control" id="input-name" name="name" value="{$category_name.name}"> 32 <input type="text" class="form-control" id="input-name" name="name" value="{$category_name.name}">
33 </div> 33 </div>
34 </div> 34 </div>
  35 + <div class="form-group">
  36 + <label for="thumbnail">banner图</label>
  37 + <div>
  38 + <input type="text" class="form-control" id="thumbnail" name="image" value="{$category_name.image}">
  39 + <a href="javascript:uploadOneImage('上传图片','#thumbnail');">
  40 + <if condition="empty($category_name.image)">
  41 + <img src="__TMPL__/public/assets/images/default-thumbnail.png"
  42 + id="thumbnail-preview"
  43 + width="300" height="150" style="cursor: pointer"/>
  44 + <else/>
  45 + <img src="{:cmf_get_image_preview_url($category_name.image)}"
  46 + id="thumbnail-preview"
  47 + width="300" height="150" style="cursor: pointer"/>
  48 + </if>
  49 + </a>
  50 + <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
  51 + <a href="javascript:uploadOneImage('图片上传','#thumbnail');">上传图片</a>
  52 + </div>
  53 + <span class="form-required">图片参考尺寸:1920*666</span>
  54 + </div>
35 55
36 </div> 56 </div>
37 </div> 57 </div>
@@ -46,4 +66,12 @@ @@ -46,4 +66,12 @@
46 </div> 66 </div>
47 <script type="text/javascript" src="__STATIC__/js/admin.js"></script> 67 <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
48 </body> 68 </body>
49 -</html>  
  69 +</html>
  70 +<script type="text/javascript">
  71 + $(function () {
  72 + $('.btn-cancel-thumbnail').click(function () {
  73 + $('#thumbnail-preview').attr('src', '__TMPL__/public/assets/images/default-thumbnail.png');
  74 + $('#thumbnail').val('');
  75 + });
  76 + });
  77 +</script>
@@ -29,7 +29,8 @@ @@ -29,7 +29,8 @@
29 <thead> 29 <thead>
30 <tr> 30 <tr>
31 <th width="200">ID</th> 31 <th width="200">ID</th>
32 - <th>分类名称</th> 32 + <th width="400">分类名称</th>
  33 + <th>banner图</th>
33 <th width="210">操作</th> 34 <th width="210">操作</th>
34 </tr> 35 </tr>
35 </thead> 36 </thead>
@@ -38,6 +39,15 @@ @@ -38,6 +39,15 @@
38 <td>{$vo.id}</td> 39 <td>{$vo.id}</td>
39 <td>{$vo.name}</td> 40 <td>{$vo.name}</td>
40 <td> 41 <td>
  42 + <notempty name="vo.image">
  43 + <a href="javascript:parent.imagePreviewDialog('{:cmf_get_image_preview_url($vo.image)}');">
  44 + <i class="fa fa-photo fa-fw"></i>
  45 + </a>
  46 + <else/>
  47 + <i class="fa fa-close fa-fw"></i>
  48 + </notempty>
  49 + </td>
  50 + <td>
41 <a class="btn btn-xs btn-primary" href="{:url('AdminCityCategory/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a> 51 <a class="btn btn-xs btn-primary" href="{:url('AdminCityCategory/edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
42 <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('AdminCityCategory/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a> 52 <a class="btn btn-xs btn-danger js-ajax-delete" href="{:url('AdminCityCategory/delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
43 </td> 53 </td>
@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 <div class="select"> 38 <div class="select">
39 <input type="text" value="中国" readonly="readonly"> 39 <input type="text" value="中国" readonly="readonly">
40 <img src="__TMPL__/public/assets/starImg/down.png" alt=""> 40 <img src="__TMPL__/public/assets/starImg/down.png" alt="">
41 - <ul> 41 + <ul style="height:300px;overflow-y: scroll;width:240px;">
42 <li>所有</li> 42 <li>所有</li>
43 <volist name="city_name" id="vo"> 43 <volist name="city_name" id="vo">
44 <li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li> 44 <li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li>
@@ -15,10 +15,10 @@ @@ -15,10 +15,10 @@
15 margin-bottom:100px; 15 margin-bottom:100px;
16 } 16 }
17 .excerpt{ 17 .excerpt{
18 - font-size: 14px;  
19 margin: 30px 0 40px 0; 18 margin: 30px 0 40px 0;
20 - color: rgba(153, 153, 153, 1);  
21 - line-height: 22px; 19 + font-size: 16px;
  20 + color: rgba(102, 102, 102, 1);
  21 + line-height: 32px;
22 } 22 }
23 </style> 23 </style>
24 </head> 24 </head>
@@ -30,7 +30,7 @@ @@ -30,7 +30,7 @@
30 <div class="select"> 30 <div class="select">
31 <input type="text" value="中国" readonly="readonly"> 31 <input type="text" value="中国" readonly="readonly">
32 <img src="__TMPL__/public/assets/starImg/down.png" alt=""> 32 <img src="__TMPL__/public/assets/starImg/down.png" alt="">
33 - <ul> 33 + <ul style="height:300px;overflow-y: scroll;width:145px;">
34 <li>所有</li> 34 <li>所有</li>
35 <volist name="city_name" id="vo"> 35 <volist name="city_name" id="vo">
36 <li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li> 36 <li value="{$vo.id}" <eq name="$vo.id" value="$city_id">selected</eq>>{$vo.name}</li>
@@ -15,7 +15,11 @@ @@ -15,7 +15,11 @@
15 <div class="happy_index"> 15 <div class="happy_index">
16 <!-- banner轮播图 --> 16 <!-- banner轮播图 -->
17 <div class="happy_banner"> 17 <div class="happy_banner">
18 - <img src="__TMPL__/public/assets/starImg/star_banner.jpg" alt="" /> 18 + <notempty name="city_banner">
  19 + <img src="{:cmf_get_image_url($city_banner)}" alt="" />
  20 + <else/>
  21 + <img src="__TMPL__/public/assets/starImg/star_banner.jpg" alt="" />
  22 + </notempty>
19 <h3>Planet Discovery</h3> 23 <h3>Planet Discovery</h3>
20 </div> 24 </div>
21 <!-- main 背景 --> 25 <!-- main 背景 -->
@@ -107,8 +107,8 @@ body { @@ -107,8 +107,8 @@ body {
107 line-height: 48px; 107 line-height: 48px;
108 text-shadow: 0px 6px 14px rgba(0, 0, 0, 0.3); 108 text-shadow: 0px 6px 14px rgba(0, 0, 0, 0.3);
109 position: absolute; 109 position: absolute;
110 - top: 499px;  
111 - left: 365px 110 + top: 75%;
  111 + left: 19%;
112 } 112 }
113 113
114 114