Category.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\model\other;
  12. use app\model\user\UserLabel;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. use think\Model;
  16. /**
  17. * 分类表
  18. * Class Category
  19. * @package app\model\other
  20. */
  21. class Category extends BaseModel
  22. {
  23. use ModelTrait;
  24. /**
  25. * 表名
  26. * @var string
  27. */
  28. protected $name = 'category';
  29. /**
  30. * 主键
  31. * @var string
  32. */
  33. protected $pk = 'id';
  34. /**
  35. * 搜索分类名称
  36. * @param Model $query
  37. * @param $value
  38. */
  39. public function searchNameAttr($query, $value)
  40. {
  41. $query->whereLike('name', '%' . $value . '%');
  42. }
  43. /**
  44. * 归属人
  45. * @param Model $query
  46. * @param $value
  47. */
  48. public function searchOwnerIdAttr($query, $value)
  49. {
  50. $query->where('owner_id', $value);
  51. }
  52. /**
  53. * 类型
  54. * @param Model $query
  55. * @param $value
  56. */
  57. public function searchTypeAttr($query, $value)
  58. {
  59. $query->where('type', $value);
  60. }
  61. /**
  62. * 一对多关联
  63. * @return \think\model\relation\HasMany
  64. */
  65. public function label()
  66. {
  67. return $this->hasMany(UserLabel::class, 'label_cate', 'id');
  68. }
  69. }