1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- class Base extends Controller
- {
- public function _initialize(){
- $data = db('column')->select();
- // $tags = db('tags')->select();
- $good =db('good')->select();
- //标签栏一个工具对应多个标签处理-----------------------------------
- $tags_id = input('id');
- // 找到所有标签,对其进行格式化处理
- $tags_data = db('tags')->select();
- $tags = [];
- foreach ($tags_data as $value) {
- $tags[$value['id']] = ['tagname'=>$value['tagname'], 'children'=>[]];
- }
- // 找到所有商品,判断商品是否在标签内
- $ta = db('good')->field('id, title, tags_id')->select();
- foreach ($ta as $val) {
- $tag_ids = explode(',', $val['tags_id']);
-
- if ($tag_ids) {
- foreach($tag_ids as $tid) {
- if($tags[$tid]) {
- $tags[$tid]['children'][] = $val;
- }
- }
- }
- }
- //end---------------------------------------------------------
- $this->assign([
- 'data'=>$data,
- 'tags'=>$tags,
- 'good'=>$good,
- ]);
-
- return view();
- }
-
- public function praise(){//点赞
- $id = input('id');//获取当前点赞id
- $res = db('good')->where(array('id'=>$id))->field('likes')->find();
- if ($res) {
- $res1 = db('good')->where('id',$id)->setInc('likes');//setInc:对指定字段进行加操作,setDec:对指定字段进行减操作
- if($res1){
- return 1;//点赞成功
- }else{
- return 2;//失败
- }
- }
- }
- }
|