| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- /**
- * 代理分页查询.
- *
- * @author nj
- * @date 2021-01-23 15:35:04
- */
- namespace App\Repositories\Criterias;
- use Illuminate\Database\Eloquent\Builder;
- use KZ2\Laravel\Repositories\Contracts\RepositoryInterface;
- use KZ2\Laravel\Repositories\Criteria\Criteria;
- class AgentPagesCriteria extends Criteria
- {
- private $params = [];
- public function __construct($params = [])
- {
- $this->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;
- }
- }
|