1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace app\admin\controller\sys_manage;
- use app\admin\validate\sys_manage\AdvValidate;
- use app\admin\validate\sys_manage\ArticleValidate;
- use app\admin\validate\sys_manage\ContentValidate;
- use app\controller\Curd;
- use app\model\Adv;
- use app\model\Article;
- use app\model\Content;
- use support\Request;
- use support\Response;
- class NewsController extends Curd
- {
- public function __construct()
- {
- $this->model = new Content();
- $this->validate = true;
- $this->validateClass = new ContentValidate();
- }
- /** 列表
- * @Desc
- * @Author Gorden
- * @Date 2024/3/5 10:00
- *
- * @param Request $request
- * @return Response
- * @throws \support\exception\BusinessException
- */
- public function select(Request $request): Response
- {
- [$where, $format, $limit, $field, $order] = $this->selectInput($request);
- // $where['content_category'] = ['in',['NEWS','FINANCE','APARTMENT']];
- $where['content_category'] = 'NEWS';
- $order = $request->get('order', 'desc');
- $field = $field ?? 'content_addtimes';
- $query = $this->doSelect($where, $field, $order);
- return $this->doFormat($query, $format, $limit);
- }
- protected function doSelect(array $where, string $field = null, string $order = 'desc')
- {
- $model = $this->model->with('category');
- foreach ($where as $column => $value) {
- if (is_array($value)) {
- if ($value[0] === 'like' || $value[0] === 'not like') {
- $model = $model->where($column, $value[0], "%$value[1]%");
- } elseif (in_array($value[0], ['>', '=', '<', '<>'])) {
- $model = $model->where($column, $value[0], $value[1]);
- } elseif ($value[0] == 'in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereIn($column, $valArr);
- } elseif ($value[0] == 'not in' && !empty($value[1])) {
- $valArr = $value[1];
- if (is_string($value[1])) {
- $valArr = explode(",", trim($value[1]));
- }
- $model = $model->whereNotIn($column, $valArr);
- } elseif ($value[0] == 'null') {
- $model = $model->whereNull($column);
- } elseif ($value[0] == 'not null') {
- $model = $model->whereNotNull($column);
- } elseif ($value[0] !== '' || $value[1] !== '') {
- $model = $model->whereBetween($column, $value);
- }
- } else {
- $model = $model->where($column, $value);
- }
- }
- if ($field) {
- $model = $model->orderBy($field, $order);
- }
- return $model;
- }
- /**
- * @Desc
- * @Author Gorden
- * @Date 2024/3/27 10:24
- *
- * @param Request $request
- * @return array
- * @throws \support\exception\BusinessException
- */
- protected function insertInput(Request $request): array
- {
- $data = $this->inputFilter($request->post());
- $data['content_category'] = 'NEWS';
- return $data;
- }
- }
|