ArticleCategory.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\article;
  12. use traits\ModelTrait;
  13. use app\admin\model\article\Article as ArticleModel;
  14. use basic\ModelBasic;
  15. use service\UtilService as Util;
  16. /**
  17. * 文章分类model
  18. * Class ArticleCategory
  19. * @package app\admin\model\wechat
  20. */
  21. class ArticleCategory extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**
  25. * 获取系统分页数据 分类
  26. * @param array $where
  27. * @return array
  28. */
  29. public static function systemPage($where = array()){
  30. $model = new self;
  31. if($where['title'] !== '') $model = $model->where('title','LIKE',"%$where[title]%");
  32. if($where['status'] !== '') $model = $model->where('status',$where['status']);
  33. $model = $model->where('is_del',0);
  34. $model = $model->where('hidden',0);
  35. return self::page($model);
  36. }
  37. /**
  38. * 删除分类
  39. * @param $id
  40. * @return bool
  41. */
  42. public static function delArticleCategory($id)
  43. {
  44. if(count(self::getArticle($id,'*'))>0)
  45. return self::setErrorInfo('请先删除改分类下的文章!');
  46. return self::edit(['is_del'=>1],$id,'id');
  47. }
  48. /**
  49. * 获取分类名称和id field
  50. * @param $field
  51. * @return array
  52. */
  53. public static function getField($field){
  54. return self::where('is_del','eq',0)->where('status','eq',1)->where('hidden','eq',0)->column($field);
  55. }
  56. /**
  57. * 分级排序列表
  58. * @param null $model
  59. * @return array
  60. */
  61. public static function getTierList($model = null)
  62. {
  63. if($model === null) $model = new self();
  64. return Util::sortListTier($model->where('is_del',0)->select()->toArray());
  65. }
  66. /**
  67. * 获取分类底下的文章
  68. * id 分类表中的分类id
  69. * return array
  70. * */
  71. public static function getArticle($id,$field){
  72. $res = ArticleModel::where('hide',0)->column($field,'id');
  73. $new_res = array();
  74. foreach ($res as $k=>$v){
  75. $cid_arr = explode(',',$v['cid']);
  76. if(in_array($id,$cid_arr)){
  77. $new_res[$k] = $res[$k];
  78. }
  79. }
  80. return $new_res;
  81. }
  82. }