['sale_group_id', 'property_head_id','sale_type', '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('sale c', 'a.sale_id = c.id') ->field([ 'a.sale_id','c.sale_name','c.mobile', Db::raw("COUNT(a.work_id) AS work_count, SUM(CASE WHEN a.sale_type = 1 THEN b.work_amount ELSE 0 END) AS amount_sales_agent, SUM(CASE WHEN a.sale_type = 2 THEN b.work_amount ELSE 0 END) AS amount_sales_individual") ]) ->where($this->queryWhere()) ->where('a.sale_type', 'in', [1, 2]) ->where('a.order_status', 3) ->group('a.sale_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_id','c.sale_name','c.mobile', Db::raw("COUNT(a.work_id) AS work_count, SUM(CASE WHEN a.sale_type = 1 THEN b.work_amount ELSE 0 END) AS amount_sales_agent, SUM(CASE WHEN a.sale_type = 2 THEN b.work_amount ELSE 0 END) AS amount_sales_individual") ]) ->where($this->queryWhere()) ->where('a.sale_type', 'in', [1, 2]) ->where('a.order_status', 3) ->group('a.sale_id') ->count(); } }