Expect.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\model;
  3. use think\Model;
  4. /**
  5. * 期望对象模型
  6. */
  7. class Expect Extends Model
  8. {
  9. // 表名
  10. protected $name = 'expect';
  11. // 开启自动写入时间戳字段
  12. protected $autoWriteTimestamp = 'int';
  13. /**
  14. * 获取用户期望对象对应标签列表
  15. * $expect 格式 1,2,3
  16. * return $user_ids;用户ID集合
  17. */
  18. public static function getTagsByExpect($expect) {
  19. if(!$expect) return false;
  20. $user_ids = [];
  21. $where = [];
  22. $where['id'] = ["in",$expect];
  23. $list = self::where($where)->select();
  24. $tag_ids = [];
  25. if($list) foreach($list as $k => $v) {
  26. $ids = explode(',',$v['tag_ids']);
  27. if($ids) foreach($ids as $m => $n) {
  28. $tag_ids[] = $n;
  29. }
  30. }
  31. $tag_ids = array_unique($tag_ids);
  32. if($tag_ids) {
  33. $tag_ids_str = implode(",",$tag_ids);
  34. $tagCanbeSearch = config('site.tagCanbeSearch');
  35. // 获取对应用户ID
  36. $where = [];
  37. $where['tag_id'] = ['in',$tag_ids_str];
  38. $where['number'] = ['gt',$tagCanbeSearch];
  39. $user_ids = \app\common\model\TagUser::where($where)->column("user_id");
  40. $user_ids = array_unique($user_ids);
  41. }
  42. return $user_ids;
  43. }
  44. public static function getExpectNames($expect_ids) {
  45. if($expect_ids) {
  46. $expect_ids = explode(',',$expect_ids);
  47. $expect_names = self::where(['id'=>['in',$expect_ids]])->column('name');
  48. } else {
  49. $expect_names = [];
  50. }
  51. return $expect_names;
  52. }
  53. }