['a.sale_group_id', 'a.property_head_id','a.sale_type', 'a.sale_id'], ]; } public function queryWhere() { $where = []; if(isset($this->params['time_range']) && $this->params['time_range']){ $startDateTime = strtotime($this->params['time_range'][0]); $endDateTime = strtotime($this->params['time_range'][1])+86400-1; $where[] = ['b.finished_time','BETWEEN',[$startDateTime,$endDateTime]]; } return $where; } /** * 获取数据权限 * $this->adminInfo['data_rules'] * province city admin_id sale_group_id sale_id property_head_id */ public function queryDataWhere(){ $where = []; $data_rules = $this->adminInfo['data_rules']; if (isset($data_rules['province']) && !empty($data_rules['province'])) { $where[] = ['b.province','in' ,$data_rules['province']]; } if (isset($data_rules['city']) && !empty($data_rules['city'])) { $where[] = ['b.city','in' ,$data_rules['city']]; } if (isset($data_rules['sale_group_id']) && !empty($data_rules['sale_group_id'])) { $where[] = ['a.sale_group_id','in' ,$data_rules['sale_group_id']]; } if (isset($data_rules['sale_id']) && !empty($data_rules['sale_id'])) { $where[] = ['a.sale_id','in' ,$data_rules['sale_id']]; } if (isset($data_rules['property_head_id']) && !empty($data_rules['property_head_id'])) { $where[] = ['a.property_head_id','in' ,$data_rules['property_head_id']]; } return $where; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/12/15 10:53 */ public function lists(): array { return Db::name('property_order')->alias('a') ->leftJoin('service_work b', 'a.work_id = b.id') ->leftJoin('sale_group c', 'a.sale_group_id = c.id') ->field([ 'a.sale_group_id','c.sale_name', Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount") ]) ->where('a.sale_type', 'in', [1, 2]) ->where($this->searchWhere) ->where($this->queryWhere()) ->where($this->queryDataWhere()) ->where('b.service_status', 3) ->group('a.sale_group_id') ->limit($this->limitOffset, $this->limitLength) ->select()->toArray(); } /** * @notes 获取数量 * @return int * @author likeadmin * @date 2024/12/15 10:53 */ public function count(): int { return Db::name('property_order')->alias('a') ->leftJoin('service_work b', 'a.work_id = b.id') ->leftJoin('sale c', 'a.sale_id = c.id') ->field([ 'a.sale_group_id','c.sale_name','c.mobile', Db::raw("COUNT(a.work_id) AS work_count,SUM(b.work_amount) AS total_sales_amount") ]) ->where('a.sale_type', 'in', [1, 2]) ->where('a.order_status', 3) ->where($this->queryDataWhere()) ->group('a.sale_group_id') ->count(); } }