WorkGroupMsgSendResultDao.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\WorkGroupMsgSendResult;
  14. use crmeb\basic\BaseAuth;
  15. use crmeb\traits\SearchDaoTrait;
  16. /**
  17. * Class WorkGroupMsgSendResultDao
  18. * @package app\dao\work
  19. */
  20. class WorkGroupMsgSendResultDao extends BaseDao
  21. {
  22. use SearchDaoTrait;
  23. /**
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return WorkGroupMsgSendResult::class;
  29. }
  30. /**
  31. * @param array $where
  32. * @param bool $authWhere
  33. * @return \crmeb\basic\BaseModel
  34. */
  35. public function searchWhere(array $where, bool $authWhere = true)
  36. {
  37. [$with, $whereKey] = app()->make(BaseAuth::class)->________(array_keys($where), $this->setModel());
  38. $whereData = [];
  39. foreach ($whereKey as $key) {
  40. if (isset($where[$key]) && 'timeKey' !== $key) {
  41. $whereData[$key] = $where[$key];
  42. }
  43. }
  44. return $this->getModel()->withSearch($with, $where)->when(!empty($where['client_name']), function ($query) use ($where) {
  45. $query->whereIn('external_userid', function ($query) use ($where) {
  46. $query->name('work_client')->where('name', 'like', '%' . $where['client_name'] . '%')->field(['external_userid']);
  47. });
  48. })->when(!empty($where['notChatId']), function ($query) {
  49. $query->whereNotNull('chat_id');
  50. });
  51. }
  52. /**
  53. * @param array $where
  54. * @return \crmeb\basic\BaseModel
  55. */
  56. public function getGroupChatMsg(array $where)
  57. {
  58. return $this->getModel()->when(!empty($where['msg_id']), function ($query) use ($where) {
  59. $query->whereIn('msg_id', $where['msg_id']);
  60. })->when(!empty($where['status']), function ($query) use ($where) {
  61. $query->where('status', $where['status']);
  62. })->when(!empty($where['owner']), function ($query) use ($where) {
  63. $query->whereIn('userid', $where['owner']);
  64. })->group('userid')->field([
  65. "GROUP_CONCAT(chat_id) as chat_ids",
  66. "GROUP_CONCAT(status) as status_all", 'userid', 'status']);
  67. }
  68. }