CommunityCategory.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\common\model\community;
  12. use app\common\model\BaseModel;
  13. class CommunityCategory extends BaseModel
  14. {
  15. /**
  16. * TODO
  17. * @return string
  18. * @author Qinii
  19. * @day 10/26/21
  20. */
  21. public static function tablePk(): string
  22. {
  23. return 'category_id';
  24. }
  25. /**
  26. * TODO
  27. * @return string
  28. * @author Qinii
  29. * @day 10/26/21
  30. */
  31. public static function tableName(): string
  32. {
  33. return 'community_category';
  34. }
  35. public function children()
  36. {
  37. return $this->hasMany(CommunityTopic::class,'category_id','category_id')
  38. ->where('status',1)
  39. ->where('is_del',0)
  40. ->field('category_id,topic_id,topic_name,pic,sort,count_use')
  41. ->order('sort DESC,create_time DESC');
  42. }
  43. public function searchCateNameAttr($query, $value)
  44. {
  45. $query->whereLike('cate_name', "%{$value}%");
  46. }
  47. public function searchCategoryIdAttr($query, $value)
  48. {
  49. $query->where('category_id', $value);
  50. }
  51. public function searchIsShowAttr($query, $value)
  52. {
  53. $query->where('is_show', $value);
  54. }
  55. }