| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Common;
- use App\Models\VideoCategoryModel;
- use App\Models\ActionLogModel;
- use App\Services\BaseService;
- use Illuminate\Support\Facades\DB;
- /**
- * 服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class VideoCategoryService
- * @package App\Services\Common
- */
- class VideoCategoryService extends BaseService
- {
- public static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * VideoCategoryService constructor.
- */
- public function __construct()
- {
- $this->model = new VideoCategoryModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 列表
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['mark' => 1];
- // 状态筛选
- if (isset($params['status']) && $params['status'] !== '') {
- $where['status'] = intval($params['status']);
- }
- $query = $this->model
- ->where($where)
- ->where(function ($query) use ($params) {
- $keyword = isset($params['keyword']) ? trim($params['keyword']) : '';
- if ($keyword) {
- $query->where('name', 'like', "%{$keyword}%");
- }
- })
- ->select([
- 'id',
- 'pid',
- 'name',
- 'status',
- 'sort',
- 'create_time'
- ])
- ->orderBy('sort', 'asc')
- ->orderBy('id', 'desc');
- $list = $query->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- if ($list) {
- foreach ($list['data'] as &$item) {
- $item['create_time'] = $item['create_time']
- ? datetime($item['create_time'], 'Y-m-d H:i:s')
- : '';
- // 状态转义
- $item['status_text'] = $item['status'] == 1 ? '启用' : '禁用';
- }
- }
- return [
- 'pageSize' => $pageSize,
- 'total' => $list['total'] ?? 0,
- 'list' => $list['data'] ?? []
- ];
- }
- /**
- * 分类下拉选项
- * @return array
- */
- public function options()
- {
- $param = request()->all();
- // 关键词(分类名)
- $keyword = getter($param, "keyword");
- $parentId = getter($param, "parent_id");
- $datas = $this->model->where(function ($query) use ($parentId) {
- if ($parentId) {
- // 只取某个父分类下的
- $query->where(['pid' => $parentId, 'mark' => 1]);
- } else {
- // 默认取所有启用的
- $query->where(['status' => 1, 'mark' => 1]);
- }
- })
- ->when($keyword, function ($query) use ($keyword) {
- $query->where('name', 'like', "%{$keyword}%");
- })
- ->select(['id', 'pid', 'name', 'status'])
- ->orderBy('sort', 'asc')
- ->get();
- return $datas ? $datas->toArray() : [];
- }
- /**
- * 删除七天之前标记软删除的数据
- */
- public function delete()
- {
- // 设置日志标题
- ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除视频分类信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
- ActionLogModel::record();
- $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
- return parent::delete();
- }
- }
|