// +---------------------------------------------------------------------- namespace App\Services\Common; use App\Models\AccountModel; use App\Models\ArticleCateModel; use App\Models\ArticleModel; use App\Services\BaseService; /** * 文章分类管理-服务类 * @author laravel开发员 * @since 2020/11/11 * Class ArticleCateService * @package App\Services\Common */ class ArticleCateService extends BaseService { /** * 构造函数 * @author laravel开发员 * @since 2020/11/11 * ArticleService constructor. */ public function __construct() { $this->model = new ArticleCateModel(); } /** * 静态入口 * @return static|null */ public static function make() { if (!self::$instance) { self::$instance = (new static()); } return self::$instance; } /** * 添加或编辑 * @return array * @since 2020/11/11 * @author laravel开发员 */ public function edit() { $data = request()->all(); return parent::edit($data); // TODO: Change the autogenerated stub } /** * 选项 * @return array */ public function options() { // 获取参数 $param = request()->all(); // 用户ID $keyword = getter($param, "keyword"); $parentId = getter($param, "parent_id"); $id = getter($param, "id"); $datas = $this->model->where(function($query) use($parentId){ if($parentId){ $query->where(['id'=> $parentId,'mark'=>1]); }else{ $query->where(['status'=> 1,'mark'=>1]); } }) ->where(function($query) use($id){ if($id){ $query->whereNotIn('id', [$id]); } }) ->where(function($query) use($keyword){ if($keyword){ $query->where('name','like',"%{$keyword}%")->orWhere('code','like',"%{$keyword}%"); } }) ->select(['id','name','status']) ->get(); return $datas? $datas->toArray() : []; } }