EnterCategory.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace app\admin\model\enterprise;
  8. use crmeb\traits\ModelTrait;
  9. use crmeb\basic\BaseModel;
  10. use app\admin\model\article\Article as ArticleModel;
  11. /**
  12. * 企业分类model
  13. * Class EnterCategory
  14. * @package app\admin\model\wechat
  15. */
  16. class EnterCategory extends BaseModel
  17. {
  18. use ModelTrait;
  19. protected $pk = 'id';
  20. protected $name = 'enterprise_type';
  21. /**
  22. * 获取系统分页数据 分类
  23. * @param array $where
  24. * @return array
  25. */
  26. public static function systemPage($where = [])
  27. {
  28. $model = new self;
  29. if ($where['title'] !== '') $model = $model->where('title', 'LIKE', "%$where[title]%");
  30. if ($where['status'] !== '') $model = $model->where('status', $where['status']);
  31. $model = $model->where('is_del', 0);
  32. $model = $model->where('hidden', 0);
  33. return self::page($model);
  34. }
  35. /**
  36. * 删除分类
  37. * @param $id
  38. * @return bool
  39. */
  40. public static function delArticleCategory($id)
  41. {
  42. if (count(self::getArticle($id, '*')) > 0)
  43. return self::setErrorInfo('请先删除该类型下的企业!');
  44. return self::edit(['is_del' => 1], $id, 'id');
  45. }
  46. /**
  47. * 获取分类名称和id
  48. * @return array
  49. */
  50. public static function getField()
  51. {
  52. return self::where('is_del', 0)->where('status', 1)->where('hidden', 0)->column('title', 'id');
  53. }
  54. /**
  55. * 分级排序列表
  56. * @param null $model
  57. * @return array
  58. */
  59. public static function getTierList($model = null)
  60. {
  61. if ($model === null) $model = new self();
  62. return sort_list_tier($model->where('is_del', 0)->where('status', 1)->select()->toArray());
  63. }
  64. /**
  65. * 第三方分级排序列表
  66. * @param null $model
  67. * @return array
  68. */
  69. public static function getTierLists($model = null)
  70. {
  71. if ($model === null) $model = new self();
  72. return sort_list_tier($model->where('is_del', 0)->where('status', 1)->where('is_type',1)->select()->toArray());
  73. }
  74. /**
  75. * 获取分类底下的企业
  76. * id 分类表中的分类id
  77. * return array
  78. * */
  79. public static function getArticle($id, $field)
  80. {
  81. $res = ArticleModel::where('status', 1)->where('hide', 0)->column($field, 'id');
  82. $new_res = array();
  83. foreach ($res as $k => $v) {
  84. $cid_arr = explode(',', $v['cid']);
  85. if (in_array($id, $cid_arr)) {
  86. $new_res[$k] = $res[$k];
  87. }
  88. }
  89. return $new_res;
  90. }
  91. /**
  92. * TODO 获取文章分类
  93. * @return array
  94. * @throws \think\db\exception\DataNotFoundException
  95. * @throws \think\db\exception\ModelNotFoundException
  96. * @throws \think\exception\DbException
  97. */
  98. public static function getArticleCategoryList()
  99. {
  100. $list = self::where('is_del', 0)->where('status', 1)->select();
  101. if ($list) return $list->toArray();
  102. return [];
  103. }
  104. /**
  105. * TODO 获取文章分类信息
  106. * @param $id
  107. * @param string $field
  108. * @return mixed
  109. */
  110. public static function getArticleCategoryInfo($id, $field = 'title')
  111. {
  112. $model = new self;
  113. if ($id) $model = $model->where('id', $id);
  114. $model = $model->where('is_del', 0);
  115. $model = $model->where('status', 1);
  116. return $model->column($field, 'id');
  117. }
  118. }