123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- class Base extends Controller
- {
- public function _initialize(){
- $data = db('column')->order('sort desc')->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')->where('tags_id','<>','')->order('sort desc')->select();//查询出tags_id不为空的所有数据
- 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---------------------------------------------------------
- $getip = getIp();//获取ip
- // $getip = "218.70.26.255"; //重庆IP地址
- if($getip == ''||$getip=='127.0.0.1'||$getip=='::1'){//nginx环境为本地ip为127.0.0.1,apache本地环境为::1
- $getip="210.51.167.169";//默认为北京ip地址
- }
- $content = json_decode(file_get_contents("https://api.seniverse.com/v3/weather/now.json?key=S3OSd1xyPevThEbnB&location=$getip"),true);
- $city=array();
- $city['name'] = $content['results'][0]['location']['name'];//获取城市
- $tq = tianqi($city['name']);//获取当前城市天气
- $this->assign([
- 'data'=>$data,
- 'tags'=>$tags,
- 'good'=>$good,
- 'getip'=>$getip,//ip
- 'city'=>$city,//城市
- 'tq'=>$tq,//天气
- ]);
-
- return view();
- }
-
- public function praise(){//点赞
- $id = input('id');//获取当前点赞id
- $res = db('good')->where('id',$id)->setInc('likes');//setInc:对指定字段进行加操作,setDec:对指定字段进行减操作
- if($res){
- 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');
- }
- }
|