<?php

namespace app\api\controller;

use app\api\BaseController;
use think\facade\Cache;
use think\facade\Db;

/**
 * 数据大屏接口.
 */
class Statistics extends BaseController
{

    //人口构成(80岁以上、61-80岁、36-60岁、18-35岁、0-17岁)
    public function get_people($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] = ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] = ['village_id', '=', $village_id];
        }
        // 80岁以上
        $num1 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('>', 80)->count();
        //61-80岁
        $num2 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<=', 80)->whereAge('>', 60)->count();
        //36-60岁
        $num3 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<=', 60)->whereAge('>=', 36)->count();
        //18-35岁
        $num4 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<', 36)->whereAge('>', 17)->count();
        //0-17岁
        $num5 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<', 18)->count();
        $return = [
                ['value'=>$num1,'name'=>'80岁以上'],
                ['value'=>$num2,'name'=>'61-80岁'],
                ['value'=>$num3,'name'=>'36-60岁'],
                ['value'=>$num4,'name'=>'18-35岁'],
                ['value'=>$num5,'name'=>'0-17岁']
            ];
        $this->apiSuccess('获取成功',$return);
    }

    //人群关爱(特困人员、高龄老人、低保人员、空巢老人、残疾人员、留守儿童)
    public function get_people2($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] = ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] = ['village_id', '=', $village_id];
        }
        // 特困人员
        $num1 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('>', 80)->count();
        //高龄老人
        $num2 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('>', 80)->count();
        //空巢老人
        $num4 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<=', 80)->whereAge('>', 60)->count();
        //留守儿童
        $num6 = Db::table('fa_szxc_information_usermsg')->where($where)->whereAge('<', 18)->count();

        foreach ($where as $key =>$value){
            $where[$key][0] = 'm.'.$value[0];
        }
        //低保人员
        $num3 = Db::table('fa_szxc_information_usermsg')
            ->alias('m')
            ->where($where)
            ->join(['fa_szxc_information_insurance'=> 'i'],'m.user_id=i.user_id and i.insurance_type!=219')->count();
        //残疾人员
        $num5  = Db::table('fa_szxc_information_usermsg')
            ->alias('m')
            ->where($where)
            ->join(['fa_szxc_information_insurance' => 'i'],'m.user_id=i.user_id and i.whether_disabled!=112')->count();
        $return = [
            ['value'=>$num1,'name'=>'特困人员'],
            ['value'=>$num2,'name'=>'高龄老人'],
            ['value'=>$num3,'name'=>'空巢老人'],
            ['value'=>$num4,'name'=>'留守儿童'],
            ['value'=>$num5,'name'=>'低保人员'],
            ['value'=>$num6,'name'=>'残疾人员']
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //事项办理(待办事项、延期待办、总计办理、办理结率)
    public function get_num($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['county', '=', $area_id];
        }
        if ($street_id){
            $where[] = ['township', '=', $street_id];
        }
        if ($village_id){
            $where[] = ['village', '=', $village_id];
        }

//        待办事项
        $shuqiu = Db::table('fa_article')->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','>', date('Y-m-d h:i:s'))->count();
//        延期待办
        $time = Db::table('fa_article')->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','<=', date('Y-m-d h:i:s'))->count();
        //        总计办理
        $is_solve = Db::table('fa_article')->where('is_solve', 1)->where($where)->count();
        if($is_solve){
            //        办理结率
            $num4 = ($is_solve-$shuqiu-$time)/$is_solve;
        }else{
            $num4 = 0;
        }

        $num4 = round($num4*100,2).'%';
        $return = [
            ['value'=>$shuqiu,'name'=>'待办事项'],
            ['value'=>$time,'name'=>'延期待办'],
            ['value'=>$is_solve,'name'=>'总计办理'],
            ['value'=>$num4,'name'=>'办理结率']
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //资产情况(总耕地面积、人均耕地面积、退林还耕面积、种植物种类、养殖物种类)
    public function get_num2($area_id=0,$street_id=0,$village_id=0){
        $where = $map = [];
        if ($area_id){
            $where[] = ['b.area_id', '=', $area_id];
            $map[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['b.street_id', '=', $street_id];
            $map[] = ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['b.village_id', '=', $village_id];
            $map[] = ['village_id', '=', $village_id];
        }
        // 总耕地面积
        $num1 = Db::table('fa_szxc_information_planting')->alias('a')->join(['fa_szxc_information_usermsg' => 'b'],'a.user_id = b.user_id')->where($where)->sum('land_area');
        //人均耕地面积
        $all = Db::table('fa_szxc_information_usermsg')->where($map)->whereStatus('=', 1)->count();
        if($all){
            $num2 = $num1/$all;
        }else{
            $num2 = 0;
        }

        //退林还耕面积
        $num3 = $num1*0.3;
        //种植物种类
        $num4 = Db::table('fa_szxc_information_planting')->alias('a')->join(['fa_szxc_information_usermsg' => 'b'],'a.user_id = b.user_id')->where($where)->column('crops_msg');
        $a = 0;
        foreach ($num4 as $k=>$v){
            $v = json_decode($v,true);
            $v = array_filter(array_column($v,'name'));
            $v = array_filter($v);
            $a = $a + count($v);
        }
        $num4 = $a;

        //养殖物种类
        $num5 = 12;
        $return = [
            ['value'=>$num1,'name'=>'总耕地面积'],
            ['value'=>$num2,'name'=>'人均耕地面积'],
            ['value'=>$num3,'name'=>'退林还耕面积'],
            ['value'=>$num4,'name'=>'种植物种类'],
            ['value'=>$num5,'name'=>'养殖物种类']
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //消费数据(农资消费总计、食品消费总计、衣着消费总计、居住消费总计、生活用品及服务总计、交通通信总计、教育文化娱乐总计、医疗服务总计)
    public function get_num3($area_id=0,$street_id=0,$village_id=0){
        $where  = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] = ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] = ['village_id', '=', $village_id];
        }
//        农资消费总计
        $num1 = 3687;
//        食品消费总计
        $num2 = 42222;
//        衣着消费总计
        $num3 = 25841;
//        居住消费总计
        $num4 = 84511;
//        生活用品及服务总计
        $num5 = 4254;
//        交通通信总计
        $num6 = 12631;
//        教育文化娱乐总计
        $num7 = 8571;
        //医疗服务总计
        $num8 = 63541;
        $return = [
            ['value'=>$num1,'name'=>'农资消费总计'],
            ['value'=>$num2,'name'=>'食品消费总计'],
            ['value'=>$num3,'name'=>'衣着消费总计'],
            ['value'=>$num4,'name'=>'居住消费总计'],
            ['value'=>$num5,'name'=>'生活用品及服务总计'],
            ['value'=>$num6,'name'=>'交通通信总计'],
            ['value'=>$num7,'name'=>'教育文化娱乐总计'],
            ['value'=>$num8,'name'=>'医疗服务总计']
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //收入构成(工资性收入、生产经营性收入、财产性收入、保险性收入)
    public function get_num4($area_id=0,$street_id=0,$village_id=0){
        $where  = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] = ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] = ['village_id', '=', $village_id];
        }
//        工资性收入
        $num1 = 12;
//        生产经营性收入
        $num2 = 123;
//        财产性收入
        $num3 = 124;
//        保险性收入
        $num4 = 125;

        $return = [
            ['value'=>$num1,'name'=>'工资性收入'],
            ['value'=>$num2,'name'=>'生产经营性收入'],
            ['value'=>$num3,'name'=>'财产性收入'],
            ['value'=>$num4,'name'=>'保险性收入']
        ];
        $this->apiSuccess('获取成功',$return);
    }


    //土地性质(园地
    //耕地
    //林地
    //牧草地
    //养殖
    //坑塘
    //农田水利设施用地)
    public function get_num5($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['u.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['u.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['u.village_id', '=', $village_id];
        }
        // 总面积
        $num = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id')->sum('p.land_area');

        //农田水利
        $sum_218 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=218')->sum('p.land_area');
        //坑塘
        $sum_217 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=217')->sum('p.land_area');
        //养殖
        $sum_yz = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=216')->sum('p.land_area');
        //牧草地
        $sum_215 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=215')->sum('p.land_area');
        //林地
        $sum_214 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=214')->sum('p.land_area');
        //耕地
        $sum_70 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=70')->sum('p.land_area');
        //园地
        $sum_69 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id and p.nature_of_land=69')->sum('p.land_area');

        $return = [
            ['value'=>$sum_70,'name'=>'耕地面积','land'=>$num],
            ['value'=>$sum_69,'name'=>'园地','land'=>$num],
            ['value'=>$sum_214,'name'=>'林地','land'=>$num],
            ['value'=>$sum_215,'name'=>'牧草地','land'=>$num],
            ['value'=>$sum_yz,'name'=>'养殖','land'=>$num],
            ['value'=>$sum_217,'name'=>'坑塘','land'=>$num],
            ['value'=>$sum_218,'name'=>'农田水利设施用地','land'=>$num]
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //文化程度(
    //文盲及半文盲
    //小学
    //初中
    //高中/技校/中专
    //大学专科及以上
    //不详)
    public function get_num6($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        // 文盲及半文盲
        $num1 = Db::table('fa_szxc_information_usermsg')->where('education',71)->where($where)->count();
        //小学
        $num2 = Db::table('fa_szxc_information_usermsg')->where('education',72)->where($where)->count();
        //初中
        $num3 = Db::table('fa_szxc_information_usermsg')->where('education',73)->where($where)->count();
        //高中/技校/中专
        $num4 = Db::table('fa_szxc_information_usermsg')->where('education',74)->where($where)->count();
        //大学专科及以上
        $num5 = Db::table('fa_szxc_information_usermsg')->where('education',75)->where($where)->count();
        //不详
//        $num6 = Db::table('fa_szxc_information_usermsg')->where('education',76)->where($where)->count();
        $total = $num2 + $num3 + $num4 + $num5;
        if ($num2!=0){
            $bcdiv1 = bcmul(bcdiv($num2,$total,3),100,1);
        }else{
            $bcdiv1=0;
        }
        if ($num3!=0){
            $bcdiv2 = bcmul(bcdiv($num3,$total,3),100,1);
        }else{
            $bcdiv2=0;
        }
        if ($num4!=0){
            $bcdiv3 = bcmul(bcdiv($num4,$total,3),100,1);
        }else{
            $bcdiv3=0;
        }
        if ($num5!=0){
            $bcdiv4 = bcmul(bcdiv($num5,$total,3),100,1);
        }else{
            $bcdiv4=0;
        }
        $return = [
//            ['value'=>$num1,'name'=>'文盲及半文盲'],
            ['value'=>$num2,'name'=>'小学','bfb'=>$bcdiv1],
            ['value'=>$num3,'name'=>'初中','bfb'=>$bcdiv2],
            ['value'=>$num4,'name'=>'高中/技校/中专','bfb'=>$bcdiv3],
            ['value'=>$num5,'name'=>'大学专科及以上','bfb'=>$bcdiv4],
//            ['value'=>$num6,'name'=>'不详'],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //政治面貌(
    //群众
    //团员
    //党员
    //预备役)
    public function get_num7($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        // 群众
        $num1 = Db::table('fa_szxc_information_usermsg')->where('political_outlook',2)->where($where)->count();
        //团员
        $num2 = Db::table('fa_szxc_information_usermsg')->where('political_outlook',3)->where($where)->count();
        //党员
        $num3 = Db::table('fa_szxc_information_usermsg')->where('political_outlook',4)->where($where)->count();
        //预备役
        $num4 = Db::table('fa_szxc_information_usermsg')->where('political_outlook',177)->where($where)->count();

        $return = [
            ['value'=>$num1,'name'=>'群众'],
            ['value'=>$num2,'name'=>'团员'],
            ['value'=>$num3,'name'=>'党员'],
            ['value'=>$num4,'name'=>'预备役'],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //优秀村民
    public function get_num8($area_id=0,$street_id=0,$village_id=0,$page=1,$limit=10){
//        $where[] = ['user_id','in','1,3,5'];
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        // 群众
        $return = Db::table('fa_szxc_information_usermsg')
            ->field('name,age,address_name as address,gender')
            ->where($where)
            ->page($page,$limit)
            ->withAttr('gender', function ($value, $data) {
                if($value == 1){
                    return '男';
                }elseif($value == 2){
                    return '女';
                }else{
                    return '暂无';
                }
            })
            ->select();
        $this->apiSuccess('获取成功',$return);
    }


    //是否参保
    public function get_num9($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $return = [
            ['yi'=>346],
            ['wei'=>30],
            ['type' => [['value'=>30,'name'=>'未参保'],
                        ['value'=>60,'name'=>'低保'],
                        ['value'=>45,'name'=>'城乡居民基本医保'],
                        ['value'=>77,'name'=>'新农合'],
                        ['value'=>82,'name'=>'城镇居民医保'],
                        ['value'=>62,'name'=>'职工医保'],
                        ['value'=>20,'name'=>'其他']]
            ]
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //农业结构
    public function get_num10($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }

        $return = [
            ['value'=>135,'name'=>'萝卜'],
            ['value'=>24,'name'=>'白菜'],
            ['value'=>87,'name'=>'芋头'],
            ['value'=>51,'name'=>'地瓜'],
            ['value'=>102,'name'=>'土豆'],
            ['value'=>24,'name'=>'山药'],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //村名数量 男 女 已婚 未婚 技能培训次数 农业指导次数 政策指导次数 求职人数 土地总面积 荒地总面积 养殖面积 种植面积
    public function get_num11()
    {
//        $return = "{villagernum:1000,mannum:600,wumannum:400,married:600,unmarried:400,skillnum:20,policynum:20,agriculture:20,Jobnum:105,landsum:800,wasteland:100,breeding:200,planting500}";

        $where  = $map = [];
        $post = get_params();

        if ($post) {
            if (isset($post['area_id']) && !empty($post['area_id'])) {
                 $where['area_id']  = $map['area_id']  = $post['area_id'];
            }
            if (isset($post['street_id']) && !empty($post['street_id'])) {
                $where['street_id'] = $map['street_id'] = $post['street_id'];

            }
            if (isset($post['village_id']) && !empty($post['village_id'])) {
                $where['village_id'] = $map['village_id'] = $post['village_id'];
            }
        }

        //土地总面积
        $land_area_num = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id')->sum('p.land_area');
        //        荒地面积
        $waste_land_area = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id')->sum('p.waste_land_area');
        //养殖面积
        $sum_216 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_planting'=>'p'], 'u.user_id = p.user_id')->sum('p.breed_area');
        //种植面积
        $zz_mianji = $land_area_num - $sum_216 - $waste_land_area;

        if($land_area_num >= 100000){
            $land_area_num = bcdiv($land_area_num,10000).'万';
        }
        //总人数
        $num1 = Db::table('fa_szxc_information_usermsg')->where($map)->where('status',1)->count();
        //男
        $num2 = Db::table('fa_szxc_information_usermsg')->where($map)->where('gender',1)->count();
        //女
        $num3 = Db::table('fa_szxc_information_usermsg')->where($map)->where('gender',2)->count();
        //已婚
        $num4 = Db::table('fa_szxc_information_usermsg')->where($map)->where('marital_status',170)->count();
        //未婚
        $num5 = Db::table('fa_szxc_information_usermsg')->where($map)->where('marital_status',169)->count();
        $return = [
            'villagernum' => $num1,
            'mannum'      => $num2,
            'wumannum'    => $num3,
            'married'     => $num4,
            'unmarried'   => $num5,
            'skillnum'    => 20,
            'policynum'   => 20,
            'agriculture' => 20,
            'Jobnum'      => 105,
            'landsum'     => $land_area_num,
            'wasteland'   => $waste_land_area,
            'breeding'    => $sum_216,
            'planting'    => $zz_mianji < 0 ? 0:$zz_mianji
        ];
        $this->apiSuccess('获取成功', $return);
    }


    //优秀工作人员
    public function get_num12($area_id=0,$street_id=0,$village_id=0,$page=1,$limit=10){
        $where[] = ['user_id','in','77,78,79'];
//        $where = [];
//        if ($area_id){
//            $where[] = ['area_id', '=', $area_id];
//        }
//        if ($street_id){
//            $where[] =  ['street_id', '=', $street_id];
//        }
//        if ($village_id){
//            $where[] =  ['village_id', '=', $village_id];
//        }
        // 群众
        $return = Db::table('fa_szxc_information_usermsg')
            ->field('name,phone as telephone')
            ->where($where)
            ->page($page,$limit)
            ->select()->toArray();
        foreach ($return as $k=>$v){
            $return[$k]['pic'] = "https://lihai001.oss-cn-chengdu.aliyuncs.com/uploads/20230118/a32db5b98f8cf2aa8d1fa07dce0ca9a3.png";
        }
        $this->apiSuccess('获取成功',$return);
    }

    //职业
//    国家机关、党群组织、企业、事业单位负责人
//    专业技术人员
//    办事人员和有关人员
//    社会生产服务和生活服务人员
//    农、林、牧、渔业生产及辅助人员
//    生产、运输设备操作人员及有关人员
//    军人
//    不便分类的其他从业人员
    public function get_num13($area_id=0,$street_id=0,$village_id=0){
        $where  = [];
        if ($area_id){
            $where[] = ['u.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['u.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['u.village_id', '=', $village_id];
        }
//        国家机关、党群组织、企业、事业单位负责人
        $num1 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=77')->count();
//        专业技术人员
        $num2 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=78')->count();
//        办事人员和有关人员
        $num3 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=79')->count();
//        社会生产服务和生活服务人员
        $num4 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=80')->count();
//        农、林、牧、渔业生产及辅助人员
        $num5 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=81')->count();
//        生产、运输设备操作人员及有关人员
        $num6 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=82')->count();
//        军人
        $num7 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=83')->count();
//        不便分类的其他从业人员
        $num8 = Db::table('fa_szxc_information_useraddress')
            ->alias('u')
            ->where($where)
            ->join(['fa_szxc_information_usermsg'=>'p'], 'u.user_id = p.user_id and p.occupation=84')->count();

        $return = [
            ['value'=>$num1,'name'=>'国家机关、党群组织、企业、事业单位负责人'],
            ['value'=>$num2,'name'=>'专业技术人员'],
            ['value'=>$num3,'name'=>'办事人员和有关人员'],
            ['value'=>$num4,'name'=>'社会生产服务和生活服务人员'],
            ['value'=>$num5,'name'=>'农、林、牧、渔业生产及辅助人员'],
            ['value'=>$num6,'name'=>'生产、运输设备操作人员及有关人员'],
            ['value'=>$num7,'name'=>'军人'],
            ['value'=>$num8,'name'=>'不便分类的其他从业人员']
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //农业产量
    public function get_num14($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }

        $return = [
            ['value'=>1351,'name'=>'萝卜'],
            ['value'=>245,'name'=>'白菜'],
            ['value'=>874,'name'=>'芋头'],
            ['value'=>511,'name'=>'地瓜'],
            ['value'=>1024,'name'=>'土豆'],
            ['value'=>249,'name'=>'山药'],
        ];
        $this->apiSuccess('获取成功',$return);
    }


    //农产品品牌
    public function get_num15($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $find=Db::connect('shop')->table('eb_merchant_address')->where($where)->limit(6)->select();
        $count=Db::connect('shop')->table('eb_merchant_address')->where($where)->count();
        $select=[];
        if ($find){
            foreach ($find as $k=>$v){
                $arr[]=$v['mer_id'];
            }
            $select=Db::connect('shop')->table('eb_merchant')->where('mer_id','in',$arr)->field('mer_avatar value,mer_name name')->limit(6)->select();
        }
        $product_price=Db::connect('shop')->table('eb_product_order_log')->where($where)->sum('product_price');
        $where[]=['group_id','=',14];
        $user_product_price=Db::connect('shop')->table('eb_product_order_log')->where($where)->sum('product_price');

        $return['msg'] = $select;
        $return['total'] = $count;
        $return['xl'] = ['0',$product_price];
        $return['cgl'] = ['0',$user_product_price];
        $this->apiSuccess('获取成功',$return);
    }

    //农产品市场行情
    public function get_num16($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }

        $return = [
            ['month'=>'1月','minnum'=>'661','maxnum'=>'879'],
            ['month'=>'2月','minnum'=>'356','maxnum'=>'521'],
            ['month'=>'3月','minnum'=>'415','maxnum'=>'754'],
            ['month'=>'4月','minnum'=>'258','maxnum'=>'369'],
            ['month'=>'5月','minnum'=>'779','maxnum'=>'916'],
            ['month'=>'6月','minnum'=>'1465','maxnum'=>'1874'],
            ['month'=>'7月','minnum'=>'668','maxnum'=>'837'],
            ['month'=>'8月','minnum'=>'571','maxnum'=>'710'],
            ['month'=>'9月','minnum'=>'498','maxnum'=>'638'],
            ['month'=>'10月','minnum'=>'587','maxnum'=>'800'],
            ['month'=>'11月','minnum'=>'881','maxnum'=>'983'],
            ['month'=>'12月','minnum'=>'1008','maxnum'=>'1250'],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //农产品需求量
    public function get_num17($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['a.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['a.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['a.village_id', '=', $village_id];
        }
        $return = Db::connect('shop')->table('eb_product_order_log')->alias('a')
            ->join('eb_store_product b','a.product_id = b.product_id')
            ->where($where)
            ->group('a.product_id')
            ->field("count('a.id') as value ,b.store_name as name")
            ->order('value desc')
            ->limit('6')
            ->select();
//        $return = [
//            ['value'=>835,'name'=>'萝卜'],
//            ['value'=>124,'name'=>'白菜'],
//            ['value'=>187,'name'=>'芋头'],
//            ['value'=>251,'name'=>'地瓜'],
//            ['value'=>902,'name'=>'土豆'],
//            ['value'=>214,'name'=>'山药'],
//        ];
        $this->apiSuccess('获取成功',$return);
    }

    //企业直播
    public function get_num18($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }

        $list = Db::connect('shop')->table('eb_broadcast_room')->field('room_id,name,cover_img,share_img,start_time,end_time,anchor_name,anchor_wechat,phone,live_status')->where($where)->select();
        $this->apiSuccess('获取成功',$list);
    }

    //商户列表
    public function get_num19($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['b.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['b.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['b.village_id', '=', $village_id];
        }

        $list = Db::connect('shop')->table('eb_merchant')
            ->alias('a')
            ->join('eb_merchant_address b','a.mer_id = b.mer_id')
            ->field('mer_name,real_name,mer_phone,mer_address,mer_keyword,mer_avatar,sales,category_id')
            ->withAttr('category',function ($value,$data){
                return Db::connect('shop')->table('eb_merchant_category')->where('merchant_category_id',$data['category_id'])->value('category_name');
            })
            ->where($where)
            ->select();

        $this->apiSuccess('获取成功',$list);
    }

    //农产品销量前十
    public function get_num20($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $map[] = ['a.status','=',1];
        $map[] = ['a.is_del','=',0];
//        录入商户
        $return['shanghu'] = Db::connect('shop')->table('eb_merchant')->alias('a')->join('eb_merchant_address b','a.mer_id = b.mer_id')->where($where)->where($map)->count();
//        总订单
        $return['total_order'] = Db::connect('shop')->table('eb_product_order_log')->where('status',1)->count();
//        镇订单
        $z_order = Db::connect('shop')->table('eb_product_order_log')->where($where)->where('status',1)->count();
//        镇分佣
        $return['fenyong'] = 0;
        //总市场流量
        $return['liuliang'] = bcmul(bcdiv($z_order,$return['total_order'],2),100);
//        $return['liuliang'] = 15;
        $return['month'] = 12;
        // 商品销量前十
        $return['data'] = Db::connect('shop')->table('eb_store_product')
            ->alias('a')
            ->join('eb_product_order_log b','a.product_id = b.product_id')
            ->join('eb_store_order c','b.order_id = c.order_id')
            ->field('a.store_name as name,sum(c.total_num) as value')
            ->withAttr('total', function ($value, $data) {
                $where = [];
                return Db::connect('shop')->table('eb_store_product')
                    ->alias('a')
                    ->join('eb_product_order_log b','a.product_id = b.product_id')
                    ->join('eb_store_order c','b.order_id = c.order_id')
                    ->where($where)
                    ->group('a.product_id')->sum('c.total_num');
            })
            ->where($where)
            ->limit(10)
            ->group('a.product_id')
            ->order('value desc')
            ->select();

        $this->apiSuccess('获取成功',$return);
    }

    //新农产品市场行情
    public function get_num21($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['a.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['a.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['a.village_id', '=', $village_id];
        }

        $return = Db::connect('shop')->table('eb_product_order_log')->alias('a')
            ->join('eb_store_product b','a.product_id = b.product_id')
            ->where ($where)
            ->group('a.product_id')
            ->field("count('a.id') as value ,b.store_name as name,price,ot_price")
            ->order('value desc')
            ->select()
            ->toarray();
        foreach ($return as $k =>$v){
            $return[$k]['demand'] = $v['value'];
            $return[$k]['minnum'] =  [
                    ['month'=>'1月','value'=>0],
                    ['month'=>'2月','value'=>$v['price']],
                    ['month'=>'3月','value'=>0],
                    ['month'=>'4月','value'=>0],
                    ['month'=>'5月','value'=>0],
                    ['month'=>'6月','value'=>0],
                    ['month'=>'7月','value'=>0],
                    ['month'=>'8月','value'=>0],
                    ['month'=>'9月','value'=>0],
                    ['month'=>'10月','value'=>0],
                    ['month'=>'11月','value'=>0],
                    ['month'=>'12月','value'=>0]
                ];
            $return[$k]['maxnum'] =  [
                ['month'=>'1月','value'=>0],
                ['month'=>'2月','value'=>$v['ot_price']],
                ['month'=>'3月','value'=>0],
                ['month'=>'4月','value'=>0],
                ['month'=>'5月','value'=>0],
                ['month'=>'6月','value'=>0],
                ['month'=>'7月','value'=>0],
                ['month'=>'8月','value'=>0],
                ['month'=>'9月','value'=>0],
                ['month'=>'10月','value'=>0],
                ['month'=>'11月','value'=>0],
                ['month'=>'12月','value'=>0]
            ];
        }
        $this->apiSuccess('获取成功',$return);
    }


    //养殖户数
    public function get_num22($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['s.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['s.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['s.village_id', '=', $village_id];
        }
        $m_7=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=7')
            ->count();
        $m_6=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=6')
            ->count();
        $m_5=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=5')
            ->count();
        $m_4=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=4')
            ->count();
        $m_3=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=3')
            ->count();
        $m_2=Db::connect('shop')->table('eb_merchant_address')
            ->alias('s')
            ->where($where)
            ->join(['eb_merchant'=>'m'],'s.mer_id=m.mer_id and type_id=2')
            ->count();

        $return = [
            ['value'=>$m_7,'name'=>'种植企业'],
            ['value'=>$m_6,'name'=>'养殖企业'],
            ['value'=>$m_5,'name'=>'加工企业'],
            ['value'=>$m_2,'name'=>'厂家直销'],
            ['value'=>$m_4,'name'=>'个人小店'],
            ['value'=>$m_3,'name'=>'旗舰店'],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //养殖户销量分析
    public function get_num23($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $where[] =  ['mer_type_id', '=', 6];
        $m_1=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_2=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_3=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_4=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_5=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_6=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_7=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_8=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_9=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_10=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_11=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_12=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $return = [

            [
                'name'=>'产量',
                'data'=> [$m_1,$m_2,$m_3,$m_4,$m_5,$m_6,$m_7,$m_8,$m_9,$m_10,$m_11,$m_12]
            ]
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //养殖户产量分析(饼状图)
    public function get_num24($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $where[] =  ['mer_type_id', '=', 7];
        $m=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->count();
        $return = [
            ['name' => '种植','value'=>$m],
        ];
        $this->apiSuccess('获取成功',$return);
    }


    //产业结构,锥形图
    public function get_num25($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['a.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['a.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['a.village_id', '=', $village_id];
        }
        $return['data'] = Db::connect('shop')->table('eb_product_order_log')->alias('a')
            ->join('eb_store_product b','a.product_id = b.product_id')
            ->where($where)
            ->group('a.product_id')
            ->field("count('a.id') as value ,b.store_name as name,image as img")
            ->order('value desc')
            ->limit('5')
            ->select()
            ->toarray();
        $return['img'] = array_column($return['data'],'img');
//        $return['data'] = [
//            ['name' => '土豆','value'=>90,'img'=>'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z5.png'],
//            ['name' => '番茄','value'=>34,'img'=>'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z1.png'],
//            ['name' => '红薯','value'=>64,'img'=>'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z2.png'],
//            ['name' => '山药','value'=>15,'img'=>'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z4.png'],
//            ['name' => '白菜','value'=>78,'img'=>'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z3.png'],
//        ];
//        $return['img'] = [
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z5.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z1.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z2.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z4.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/z3.png',
//        ];
        $this->apiSuccess('获取成功',$return);
    }


    //市场行情(小程序端)
    public function get_num26($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['a.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['a.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['a.village_id', '=', $village_id];
        }

        $return['data'] = Db::connect('shop')->table('eb_product_order_log')->alias('a')
            ->join('eb_store_product b','a.product_id = b.product_id')
            ->where($where)
            ->group('a.product_id')
            ->field("b.store_name as name,price")
            ->limit('7')
            ->select()
            ->toarray();

//        $return = [
//            ['value'=>3.50,'name'=>'黄瓜'],
//            ['value'=>1.60,'name'=>'白萝卜'],
//            ['value'=>2.30,'name'=>'茄子'],
//            ['value'=>3.50,'name'=>'西红柿'],
//            ['value'=>4.50,'name'=>'长豆角'],
//            ['value'=>2.10,'name'=>'土豆'],
//            ['value'=>2.10,'name'=>'胡萝卜'],
//        ];
        $this->apiSuccess('获取成功',$return);
    }

    //镇公司农产品市场行情
    public function get_num27($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['village_id', '=', $village_id];
        }
        $where[] =  ['mer_type_id', 'in', [6,7]];
        $m_1=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_2=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_3=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_4=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_5=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_6=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_7=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_8=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_9=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_10=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_11=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $m_12=Db::connect('shop')->table('eb_product_order_log')
            ->where($where)
            ->whereMonth('create_time', date('Y').'-01')
            ->count();
        $return = [
            [
                'name'=>'萝卜',
                'demand'=>7852,
                'minnum'=>
                    [['value'=>$m_1],
                        ['value'=>$m_2],
                        ['value'=>$m_3],
                        ['value'=>$m_4],
                        ['value'=>$m_5],
                        ['value'=>$m_6],
                        ['value'=>$m_7],
                        ['value'=>$m_8],
                        ['value'=>$m_9],
                        ['value'=>$m_10],
                        ['value'=>$m_11],
                        ['value'=>$m_12]],
                'maxnum'=>
                    [['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0],
                        ['value'=>0]],
            ],
        ];
        $this->apiSuccess('获取成功',$return);
    }

    //获取图片
    public function get_num28($area_id=0,$street_id=0,$village_id=0){
        $where = [];
        if ($area_id){
            $where[] = ['a.area_id', '=', $area_id];
        }
        if ($street_id){
            $where[] =  ['a.street_id', '=', $street_id];
        }
        if ($village_id){
            $where[] =  ['a.village_id', '=', $village_id];
        }

        $return = Db::connect('shop')->table('eb_product_order_log')->alias('a')
            ->join('eb_store_product b','a.product_id = b.product_id')
            ->where ($where)
            ->group('a.product_id')
            ->field("count('a.id') as value,image")
            ->order('value desc')
            ->limit('10')
            ->select()
            ->toarray();
        $return = array_column($return,'image');
//        $return = [
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_baicai.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_dadou.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_fanqie.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_gaoliang.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_hongshu.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_huluobo.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_qiezi.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_shanyao.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_tudou.png',
//            'https://lihai001.oss-cn-chengdu.aliyuncs.com/public/kk/s_xiaomai.png',
//        ];
        $this->apiSuccess('获取成功',$return);
    }

//获取天气
    public function get_weather($street_id=0){
        //            获取天气
//            101271007 纳溪    510503
//            101271002 江阳区  510502
//            101271008 龙马潭区  510504
//            101271003 泸县   510521
//            101271004 合江   510522
//            101271006 古蔺   510525
//            101271005 叙永  510524
//            判断区域
        $name = '101271002';
        if ($street_id){
            $name = $street_id;
        }

        $url = "https://devapi.qweather.com/v7/weather/now?key=b3e94fa75aae4551b6a5db150b409261&location=".$name;
        $url1 = "https://devapi.qweather.com/v7/indices/1d?key=b3e94fa75aae4551b6a5db150b409261&type=0&location=".$name;
        $is_cun = Cache::store('redis')->get($name);
        $is_cun1 = Cache::store('redis')->get($name.'-1');
        if($is_cun){
            $data = json_decode($is_cun,1);
            $data1 = json_decode($is_cun1,1);
            $news['weather'] = $data;
            $news['weather_indices'] = $data1;
        }else{
            $data = file_get_contents("compress.zlib://".$url);
            $data1 = file_get_contents("compress.zlib://".$url1);
            Cache::store('redis')->set($name,$data,1800);
            Cache::store('redis')->set($name.'-1',$data1,1800);
            $data = json_decode($data,1);
            $data1 = json_decode($data1,1);
            $news['weather'] = $data;
            $news['weather_indices'] = $data1;
        }
        $this->apiSuccess('获取成功', $news);
    }


}