| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- /**
- * 话题标准.
- *
- * @author jim <jim458734573@gmail.com>
- * @date 2020-01-28 20:41:32
- */
- declare(strict_types=1);
- namespace App\Repositories\Criterias;
- use Hyperf\Database\Query\Builder;
- use KZ2\Repositories\Contracts\RepositoryInterface;
- use KZ2\Repositories\Criteria\Criteria;
- class TopicCriteria 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
- ) {
- $model = $model->with(['category', 'user']);
- if (isset($this->params['status'])) {
- $model = $model->where('status', $this->params['status']);
- }
- if (!empty($this->params['category_id'])) {
- $model = $model->where('category_id', $this->params['category_id']);
- }
- if (!empty($this->params['user_id'])) {
- $model = $model->where('user_id', $this->params['user_id']);
- }
- // 置顶条件.
- $topType = isset($this->params['top_type']) ? trim($this->params['top_type']) : '';
- if (!empty($topType)) {
- switch ($topType) {
- case 'only_top':
- $model = $model->where('is_top', 1);
- break;
- case 'not_top':
- $model = $model->where('is_top', 0);
- break;
- default:
- break;
- }
- }
- // 精华条件.
- $digestType = isset($this->params['digest_type']) ? trim($this->params['digest_type']) : '';
- if (!empty($digestType)) {
- switch ($digestType) {
- case 'only_digest':
- $model = $model->where('is_digest', 1);
- break;
- case 'not_digest':
- $model = $model->where('is_digest', 0);
- break;
- default:
- break;
- }
- }
- return $model;
- }
- }
|