WorkGroupChatDao.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\dao\work;
  12. use app\dao\BaseDao;
  13. use app\model\work\WorkGroupChat;
  14. use crmeb\traits\SearchDaoTrait;
  15. /**
  16. * 企业微信群
  17. * Class WorkGroupChatDao
  18. * @package app\dao\work
  19. */
  20. class WorkGroupChatDao extends BaseDao
  21. {
  22. use SearchDaoTrait;
  23. /**
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return WorkGroupChat::class;
  29. }
  30. /**
  31. * @param array $where
  32. * @return \crmeb\basic\BaseModel
  33. */
  34. public function groupChat(array $where)
  35. {
  36. return $this->getModel()->when(!empty($where['chat_id']), function ($query) use ($where) {
  37. $query->whereIn('owner', function ($query) use ($where) {
  38. $query->name('work_group_msg_task')->when(!empty($where['status']), function ($query) use ($where) {
  39. $query->where('status', $where['status']);
  40. })->whereIn('chat_id', $where['chat_id'])->field('userid');
  41. });
  42. })->when(!empty($where['owner']), function ($query) use ($where) {
  43. $query->whereIn('owner', $where['owner']);
  44. })->when(!empty($where['name']), function ($query) use ($where) {
  45. $query->whereLike('name', '%' . $where['name'] . '%');
  46. })->when(!empty($where['chat_id']), function ($query) use ($where) {
  47. if (is_array($where['chat_id'])) {
  48. $query->whereIn('chat_id', $where['chat_id']);
  49. } else {
  50. $query->where('chat_id', $where['chat_id']);
  51. }
  52. });
  53. }
  54. }