WorkGroupMsgSendResultGroupChatDao.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\wechat\WechatUser;
  14. use app\model\work\WorkGroupChat;
  15. use app\model\work\WorkGroupMsgSendResult;
  16. class WorkGroupMsgSendResultGroupChatDao extends BaseDao
  17. {
  18. protected function setModel(): string
  19. {
  20. return WorkGroupMsgSendResult::class;
  21. }
  22. protected function setJoinModel(): string
  23. {
  24. return WorkGroupChat::class;
  25. }
  26. /**
  27. * @param string $alias
  28. * @param string $joinAlias
  29. * @param string $join
  30. * @return \crmeb\basic\BaseModel
  31. */
  32. protected function getModel(string $alias = 'm', string $joinAlias = 'g', string $join = 'left')
  33. {
  34. /** @var WechatUser $wechcatUser */
  35. $wechcatUser = app()->make($this->setJoinModel());
  36. $table = $wechcatUser->getName();
  37. return parent::getModel()->alias($alias)->join($table . ' ' . $joinAlias, $alias . '.chat_id = ' . $joinAlias . '.chat_id', $join);
  38. }
  39. /**
  40. * @param array $where
  41. * @return \crmeb\basic\BaseModel
  42. */
  43. public function groupChat(array $where)
  44. {
  45. return $this->getModel()->when(!empty($where['chat_id']), function ($query) use ($where) {
  46. $query->whereIn('m.chat_id', $where['chat_id']);
  47. })->when(isset($where['status']) && $where['status'] !== '', function ($query) use ($where) {
  48. $query->where('m.status', $where['status']);
  49. })->field(['m.*', 'g.name', 'g.member_num']);
  50. }
  51. }