UserLabel.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\model\user;
  12. use app\model\other\Category;
  13. use crmeb\basic\BaseModel;
  14. use crmeb\traits\ModelTrait;
  15. /**
  16. * Class UserLabel
  17. * @package app\model\user
  18. */
  19. class UserLabel extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * 数据表主键
  24. * @var string
  25. */
  26. protected $pk = 'id';
  27. /**
  28. * 模型名称
  29. * @var string
  30. */
  31. protected $name = 'user_label';
  32. /**
  33. * 标签分类
  34. * @param \think\Model $query
  35. * @param $value
  36. */
  37. public function searchLabelCateAttr($query, $value)
  38. {
  39. if ($value !== '') {
  40. $query->where('label_cate', $value);
  41. }
  42. }
  43. /**
  44. * 关联标签分类
  45. * @return \think\model\relation\HasOne
  46. */
  47. public function cateName()
  48. {
  49. return $this->hasOne(Category::class, 'id', 'label_cate')->where('type', 0)->field(['id', 'name'])->bind(['cate_name' => 'name']);
  50. }
  51. }