123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- class Base extends Controller
- {
- public function _initialize(){
- $data = db('column')->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;//失败
- }
- }
- }
- public function alls(){//所有工具
- $cid=db('good')
- ->alias('a')
- ->field('a.*,b.catename')
- ->join('column b','a.column_id=b.id')
- ->order('sort desc')
- ->select();
- $this->assign([
- 'cid'=>$cid,
-
- ]);
- return view('indexs/index');
- }
- }
|