['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; } /** * @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('property_head c', 'a.property_head_id = c.id') ->leftJoin('sale d', 'a.sale_id = d.id') ->field([ 'a.property_head_id','c.property_name','c.village_name','c.address','c.head_name','c.head_mobile','c.ratio','c.remark','d.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('b.service_status', 3) ->group('a.property_head_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.property_head_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) ->group('a.property_head_id') ->count(); } public function setExcelComplexFields(): array { $zh_cn_fields = [ '所属代理','所属小区', '所属销售','单数','总金额','分成比例','分成金额' ]; $data_fields = ['property_name','village_name','sale_name','work_count','total_sales_amount','ratio',function($row){ return bcmul($row['total_sales_amount'], bcdiv($row['ratio'], 100, 4),2); }]; return [ 'zh_cn_fields' => $zh_cn_fields, 'data_fields' => $data_fields ]; } }