params = $params; } /** * @param Builder $model * @param RepositoryInterface $repository * @return mixed|void */ public function apply( $model, RepositoryInterface $repository ) { if (!empty($this->params['uid'])) { $model = $model->where('uid', $this->params['uid']); } if (!empty($this->params['agent_uid'])) { $model = $model->where('uid', $this->params['agent_uid']); } if (!empty($this->params['nick'])) { $model = $model->where('nick', 'LIKE', '%' . $this->params['nick'] . '%'); } if (!empty($this->params['username'])) { $model = $model->where('username', 'LIKE', '%' . $this->params['username'] . '%'); } if (!empty($this->params['manage'])) { if ($this->params['deduction_switch'] == 2) { $model = $model->whereIn('deduction_switch', [$this->params['deduction_switch'], 3]); } elseif ($this->params['deduction_switch'] == 10) { // 前端自定义查询CPA $model = $model->where('deduction_switch', 2); } else { $model = $model->where('deduction_switch', $this->params['deduction_switch']); } } if (!empty($this->params['parent_uid'])) { $model = $model->where('parent_uid', $this->params['parent_uid']); } if (!empty($this->params['status'])) { $status = intval($this->params['status']); $model = $model->where('status', $status); } if (!empty($this->params['today_date'])) { $todayDate = $this->params['today_date']; $model = $model->with([ 'attrsDay' => function ($query) use ($todayDate) { $query->where('td_date', $todayDate); } ]); } if (!empty($this->params['end_date']) && !empty($this->params['start_date'])) { $endDate = $this->params['end_date']; $startDate = $this->params['start_date']; $model = $model->with([ 'everyDay' => function ($query) use ($endDate, $startDate) { $query->select( 'agent_uid', \DB::raw('sum(td_order_success_money) as all_success_money'), \DB::raw('sum(td_deduction_success_money) as add_deduction_success_money'), \DB::raw('sum(td_users_total) as all_users_total'), \DB::raw('sum(td_users_deduction) as add_users_deduction'), ) ->whereBetween( 'td_date', [ $startDate, $endDate, ] ) ->groupBy('agent_uid'); } ]); } // $model = $model->with(['channels'=>function($query){ // $query->select('name','agent_uid','uid'); // }]); return $model; } }