ArticleCateService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\AccountModel;
  13. use App\Models\ArticleCateModel;
  14. use App\Models\ArticleModel;
  15. use App\Services\BaseService;
  16. /**
  17. * 文章分类管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * Class ArticleCateService
  21. * @package App\Services\Common
  22. */
  23. class ArticleCateService extends BaseService
  24. {
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * ArticleService constructor.
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new ArticleCateModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * 添加或编辑
  48. * @return array
  49. * @since 2020/11/11
  50. * @author laravel开发员
  51. */
  52. public function edit()
  53. {
  54. $data = request()->all();
  55. return parent::edit($data); // TODO: Change the autogenerated stub
  56. }
  57. /**
  58. * 选项
  59. * @return array
  60. */
  61. public function options()
  62. {
  63. // 获取参数
  64. $param = request()->all();
  65. // 用户ID
  66. $keyword = getter($param, "keyword");
  67. $parentId = getter($param, "parent_id");
  68. $id = getter($param, "id");
  69. $datas = $this->model->where(function($query) use($parentId){
  70. if($parentId){
  71. $query->where(['id'=> $parentId,'mark'=>1]);
  72. }else{
  73. $query->where(['status'=> 1,'mark'=>1]);
  74. }
  75. })
  76. ->where(function($query) use($id){
  77. if($id){
  78. $query->whereNotIn('id', [$id]);
  79. }
  80. })
  81. ->where(function($query) use($keyword){
  82. if($keyword){
  83. $query->where('name','like',"%{$keyword}%")->orWhere('code','like',"%{$keyword}%");
  84. }
  85. })
  86. ->select(['id','name','status'])
  87. ->get();
  88. return $datas? $datas->toArray() : [];
  89. }
  90. }