WorkGroupChat.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. /**
  15. * 企业微信群
  16. * Class WorkGroupChat
  17. * @package app\model\work
  18. */
  19. class WorkGroupChat extends BaseModel
  20. {
  21. use ModelTrait;
  22. /**
  23. * @var string
  24. */
  25. protected $name = 'work_group_chat';
  26. /**
  27. * @var string
  28. */
  29. protected $key = 'id';
  30. /**
  31. * @var string
  32. */
  33. protected $autoWriteTimestamp = 'int';
  34. /**
  35. * @return \think\model\relation\HasOne
  36. */
  37. public function ownerInfo()
  38. {
  39. return $this->hasOne(WorkMember::class, 'userid', 'owner');
  40. }
  41. /**
  42. * @return \think\model\relation\HasOne
  43. */
  44. public function sendResult()
  45. {
  46. return $this->hasOne(WorkGroupMsgSendResult::class, 'chat_id', 'chat_id');
  47. }
  48. /**
  49. * @return \think\model\relation\HasOne
  50. */
  51. public function chatMember()
  52. {
  53. return $this->hasOne(WorkGroupChatMember::class, 'group_id', 'id');
  54. }
  55. /**
  56. * @param $value
  57. * @return mixed
  58. */
  59. public function getAdminListAttr($value)
  60. {
  61. return json_decode($value, true);
  62. }
  63. /**
  64. * @param $value
  65. * @return false|string
  66. */
  67. public function getGroupCreateTimeAttr($value)
  68. {
  69. return date('Y-m-d H:i:s', $value);
  70. }
  71. /**
  72. * @param $value
  73. * @return false|string
  74. */
  75. public function getJoinTimeAttr($value)
  76. {
  77. return date('Y-m-d H:i:s', $value);
  78. }
  79. /**
  80. * @param $query
  81. * @param $value
  82. */
  83. public function searchUserIdsAttr($query, $value)
  84. {
  85. if ($value) {
  86. if (is_array($value)) {
  87. $query->whereIn('owner', $value);
  88. } else {
  89. $query->where('owner', $value);
  90. }
  91. }
  92. }
  93. public function searchNameAttr($query, $value)
  94. {
  95. if ('' !== $value) {
  96. $query->whereLike('name', '%' . $value . '%');
  97. }
  98. }
  99. /**
  100. * @param $query
  101. * @param $value
  102. * @author 等风来
  103. * @email 136327134@qq.com
  104. * @date 2022/10/10
  105. */
  106. public function searchStatusAttr($query, $value)
  107. {
  108. if ('' !== $value) {
  109. if (is_array($value)) {
  110. $query->whereIn('status', $value);
  111. } else {
  112. $query->where('status', $value);
  113. }
  114. }
  115. }
  116. }