WorkGroupChatMember.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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\work;
  12. use crmeb\basic\BaseModel;
  13. use crmeb\traits\ModelTrait;
  14. use think\model\relation\HasOne;
  15. /**
  16. * 企业微信群群成员
  17. * Class WorkGroupChatMember
  18. * @package app\model\work
  19. */
  20. class WorkGroupChatMember extends BaseModel
  21. {
  22. use ModelTrait;
  23. /**
  24. * @var string
  25. */
  26. protected $name = 'work_group_chat_member';
  27. /**
  28. * @var string
  29. */
  30. protected $autoWriteTimestamp = 'int';
  31. /**
  32. * @return HasOne
  33. */
  34. public function member()
  35. {
  36. return $this->hasOne(WorkMember::class, 'userid', 'userid');
  37. }
  38. /**
  39. * @return HasOne
  40. */
  41. public function client()
  42. {
  43. return $this->hasOne(WorkClient::class, 'external_userid', 'userid');
  44. }
  45. /**
  46. * @param $value
  47. * @return false|string
  48. */
  49. public function getJoinTimeAttr($value)
  50. {
  51. return date('Y-m-d H:i:s', $value);
  52. }
  53. /**
  54. * 名称模糊搜索
  55. * @param $query
  56. * @param $value
  57. */
  58. public function searchNameLikeAttr($query, $value)
  59. {
  60. if ('' !== $value) {
  61. $query->where(function ($query) use ($value) {
  62. $query->whereIn('userid', function ($query) use ($value) {
  63. $query->name('work_client')->whereLike('name', '%' . $value . '%')->field(['external_userid']);
  64. })->whereOr('userid', 'in', function ($query) use ($value) {
  65. $query->name('work_member')->whereLike('name', '%' . $value . '%')->field(['userid']);
  66. });
  67. });
  68. }
  69. }
  70. }