From 16a62e5a71c34422da47fee64d55715cc7fae0f2 Mon Sep 17 00:00:00 2001 From: lccsw <1127794702@qq.com> Date: Sat, 18 Sep 2021 11:54:39 +0800 Subject: [PATCH] add-licheb-city-filter --- api/controllers/wxapp/app/City.php | 63 +++++++++++++++++++++ api/controllers/wxapp/licheb/Statistics.php | 23 ++++++-- api/controllers/wxapp/licheb/User.php | 11 +++- common/models/biz/Biz_model.php | 7 +-- 4 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 api/controllers/wxapp/app/City.php diff --git a/api/controllers/wxapp/app/City.php b/api/controllers/wxapp/app/City.php new file mode 100644 index 00000000..537b9026 --- /dev/null +++ b/api/controllers/wxapp/app/City.php @@ -0,0 +1,63 @@ +login_white = array('get');//登录白名单 + $this->check_status = array();//用户状态校验 + $this->check_mobile = array();//需要手机号 + $this->check_headimg =array();//授权微信信息 + $this->load->model("sys/sys_city_model"); + $this->load->model("biz/biz_model"); + } + + protected function get(){ + $page = $this->input_param('page'); + $size = $this->input_param('size'); + !$page && $page = 1; + !$size && $size = 20; + $default_city = 350200; + + $where = [ + 'status' => 1 + ]; + if($this->app_id==2 && $this->session['group_id']==4){ + $biz_id_arr = explode(',',$this->session['biz_id']); + + $biz_where = ['city_id>'=>0,'status'=>1]; + if($this->session['biz_id'] && $biz_id_arr){ + $biz_ids = implode(',',$biz_id_arr); + $biz_where["id in ({$biz_ids})"] = null; + } + $biz_rows = $this->biz_model->select_groupby('city_id',$biz_where,'','','','id,city_id'); + $city_ids = implode(',',array_column($biz_rows,'city_id')); + $city_ids && $where["city_id in ($city_ids)"] = null; + } + $count = $this->sys_city_model->count($where); + $lists = []; + if($count){ + $rows = $this->sys_city_model->select($where,'id desc',$page,$size,'id,city_id,name'); + $city_id_arr = array_column($rows,'city_id'); + $default_city = in_array($city_id_arr,$default_city) ? $default_city : $city_id_arr[0]; + foreach($rows as $key=>$val){ + $lists = $val; + } + $lists = $rows; + } + $data = [ + 'list' => $lists, + 'total' => $count, + 'default' => $default_city + ]; + return $data; + } +} diff --git a/api/controllers/wxapp/licheb/Statistics.php b/api/controllers/wxapp/licheb/Statistics.php index 14266437..cc972f6b 100644 --- a/api/controllers/wxapp/licheb/Statistics.php +++ b/api/controllers/wxapp/licheb/Statistics.php @@ -24,6 +24,7 @@ class Statistics extends Wxapp{ //统计客户 protected function get_cust(){ $season = $this->input_param('season'); + $city_id = $this->input_param('city_id'); //!strlen($season) && $season = ceil((date('n'))/3)-1;//当月是第几季度 //$season_data = $this->season_data($season+1); //$days = getMonth($season+1); @@ -45,9 +46,15 @@ class Statistics extends Wxapp{ 's_time' => date("Y-{$month}-01 00:00:00"), 'e_time' => date("Y-{$month}-t 23:59:59"), ]; + $fileds = 'id,biz_name'; $biz_id_arr = explode(',',$this->session['biz_id']); - if($biz_id_arr){ - $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,'id,biz_name',true); + if($this->session['biz_id'] && $biz_id_arr){ + $city_id && $o_where = ['city_id'=>$city_id]; + $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,$o_where,$fileds); + }else{ + $bizs_lists = $this->biz_model->select(['status'=>0,'city_id'=>$city_id],'id desc','','',$fileds); + } + if($bizs_lists){ $bizs = array_column($bizs_lists,'biz_name'); foreach($bizs_lists as $key=>$val){ $count_data = []; @@ -104,6 +111,7 @@ class Statistics extends Wxapp{ //统计订单 protected function get_orders(){ $season = $this->input_param('season'); + $city_id = $this->input_param('city_id'); !strlen($season) && $season = ceil((date('n'))/3)-1;//当月是第几季度 $season_data = $this->season_data($season+1); $days = getMonth($season+1); @@ -117,9 +125,15 @@ class Statistics extends Wxapp{ 'e_time' => date('Y-m-t 23:59:59',strtotime($val)), ]; } + $fileds = 'id,biz_name'; $biz_id_arr = explode(',',$this->session['biz_id']); - if($biz_id_arr){ - $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,'id,biz_name',true); + if($this->session['biz_id'] && $biz_id_arr){ + $city_id && $o_where = ['city_id'=>$city_id]; + $bizs_lists = $this->biz_model->get_by_id_arr($biz_id_arr,$o_where,$fileds); + }else{ + $bizs_lists = $this->biz_model->select(['status'=>0,'city_id'=>$city_id],'id desc','','',$fileds); + } + if($bizs_lists){ $bizs = array_column($bizs_lists,'biz_name'); foreach($bizs_lists as $key=>$val){ $count_data = []; @@ -140,6 +154,7 @@ class Statistics extends Wxapp{ 'smooth' => true ]; } + } $stat_data = [ 'tooltip' => ['trigger' => 'axis'], diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index afe8d7d0..45f4c345 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -234,11 +234,18 @@ class User extends Wxapp{ * @return array */ protected function get_bizs(){ + $city_id = $this->input_param('city_id'); $lists = []; $biz_id_arr = explode(',',$this->session['biz_id']); - if($biz_id_arr){ - $bizs = $this->biz_model->get_by_id_arr($biz_id_arr,'id,biz_name,jsondata'); + $fileds = 'id,biz_name,jsondata'; + if($this->session['biz_id'] && $biz_id_arr){ + $city_id && $o_where = ['city_id'=>$city_id]; + $bizs = $this->biz_model->get_by_id_arr($biz_id_arr,$o_where,$fileds); + }else{ + $bizs = $this->biz_model->select(['status'=>0,'city_id'=>$city_id],'id desc','','',$fileds); + } + if($bizs){ foreach($bizs as $key => $val){ $auto_brands = []; $jsondata = json_decode($val['jsondata'],true); diff --git a/common/models/biz/Biz_model.php b/common/models/biz/Biz_model.php index 03eab8a8..4864d66c 100755 --- a/common/models/biz/Biz_model.php +++ b/common/models/biz/Biz_model.php @@ -38,10 +38,9 @@ class Biz_model extends HD_Model * id数组获取门店 * @param array() $ids * @param string $fileds - * @param boolean $del_test //是否删除测试门店 * @return array() */ - public function get_by_id_arr($ids_arr,$fileds='id,biz_name',$del_test=false){ + public function get_by_id_arr($ids_arr,$o_where,$fileds='id,biz_name'){ $bizs = []; $ids = implode(',',$ids_arr); if($ids){ @@ -49,9 +48,7 @@ class Biz_model extends HD_Model "id in ($ids)" => null, "status" => 1 ]; - if($del_test){ - $where["id!="] = 1; - } + is_array($o_where) && $where = array_merge($where,$o_where); $bizs = $this->biz_model->select($where,'',0,0,$fileds); } return $bizs;