UserLabel.php 1.7 KB

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