123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- <?php
- namespace app\dao\work;
- use app\dao\BaseDao;
- use app\model\work\WorkGroupChatMember;
- use crmeb\traits\SearchDaoTrait;
- class WorkGroupChatMemberDao extends BaseDao
- {
- use SearchDaoTrait;
-
- protected function setModel(): string
- {
- return WorkGroupChatMember::class;
- }
-
- public function getToDaySum(int $groupId)
- {
- return $this->getModel()->where('status', 1)->where('group_id', $groupId)->whereDay('join_time')->count();
- }
-
- public function getToDayReturn(int $groupId)
- {
- return $this->getModel()->where('status', 0)->where('group_id', $groupId)->whereDay('join_time')->count();
- }
-
- public function getChatMemberStatistics(int $groupId, string $fromUnixtime = 'create_time', array $field = [], int $status = 1, string $time = '', int $page = 0, int $limit = 0)
- {
- $date = '%Y-%m-%d';
- switch ($time) {
- case 'today':
- case 'yesterday':
- $date = '%Y-%m-%d %H';
- break;
- case 'week':
- case 'last week':
- case 'last month':
- case 'month':
- $date = '%Y-%m-%d';
- break;
- case 'year':
- case 'last year':
- $date = '%Y-%m';
- break;
- }
- return $this->search(['time' => $time, 'timeKey' => $fromUnixtime])
- ->where('group_id', $groupId)
- ->where('status', $status)
- ->when($page && $limit, function ($query) use ($page, $limit) {
- $query->page($page, $limit);
- })
- ->field(array_merge($field, ['from_unixtime(' . $fromUnixtime . ',"' . $date . '") as time']))
- ->group('time')
- ->select()->toArray();
- }
-
- public function getChatMemberStatisticsCount(int $groupId, int $status = 1, string $time = '')
- {
- $date = '%Y-%m-%d';
- switch ($time) {
- case 'today':
- case 'yesterday':
- $date = '%Y-%m-%d %H';
- break;
- case 'week':
- case 'last week':
- case 'last month':
- case 'month':
- $date = '%Y-%m-%d';
- break;
- case 'year':
- case 'last year':
- $date = '%Y-%m';
- break;
- }
- return $this->search(['time' => $time, 'timeKey' => 'update_time'])
- ->where('group_id', $groupId)
- ->where('status', $status)
- ->field(['from_unixtime(update_time,"' . $date . '") as time'])
- ->group('time')
- ->count();
- }
-
- public function getChatSum(string $userid)
- {
- return $this->getModel()->where('userid', $userid)->group('group_id')->count();
- }
- }
|