| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- namespace App\Repositories\Criterias;
- use KZ2\Laravel\Repositories\Contracts\RepositoryInterface as Repository;
- use KZ2\Laravel\Repositories\Criteria\Criteria;
- class ChannelPagesCriteria extends Criteria
- {
- private $params = [];
- public function __construct($params = [])
- {
- $this->params = $params;
- }
- public function apply($model, Repository $repository)
- {
- if (!empty($this->params['uid'])) {
- $model = $model->where('uid', 'LIKE', '%' . $this->params['uid'] . '%');
- }
- if (!empty($this->params['agent_uid'])) {
- $model = $model->where('agent_uid', $this->params['agent_uid']);
- }
- if (!empty($this->params['mom_app_uid'])) {
- $model = $model->where('mom_app_uid', $this->params['mom_app_uid']);
- }
- $agentNick = $this->params['agent_username'] ?? null;
- $model = $model->whereHas(
- 'agentName', function ($query) use ($agentNick) {
- if (!empty($agentNick)) {
- $query->where('nick', $agentNick);
- }
- })->with([
- 'agentName' => function ($query) {
- $query->select(
- 'uid',
- 'nick',
- );
- }
- ]);
- $model = $model->with(['channelRow'=>function($q){
- $q->select('channel_code','android_or_ios','mom_app_version','app_download','status');
- }]);
- return $model;
- }
- }
|