Files
huangjingfen/pro_v3.5.1/app/services/work/WorkGroupChatStatisticServices.php
panchengyong 7acbf45ff7 new files
2026-03-07 22:29:07 +08:00

84 lines
2.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2026 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\services\work;
use app\dao\work\WorkGroupChatStatisticDao;
use app\services\BaseServices;
use think\annotation\Inject;
/**
* 群聊统计
* Class WorkGroupChatStatisticServices
* @package app\services\work
* @mixin WorkGroupChatStatisticDao
*/
class WorkGroupChatStatisticServices extends BaseServices
{
/**
* @var WorkGroupChatStatisticDao
*/
#[Inject]
protected WorkGroupChatStatisticDao $dao;
/**
* 保存或者修改
* @param int $chatId
* @param bool $todaySum
* @param bool $todayReturnSum
* @param int $chatSum
* @param int $chatReturnSum
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function saveOrUpdate(int $chatId, bool $todaySum, bool $todayReturnSum, int $chatSum, int $chatReturnSum)
{
$info = $this->dao->getToDayInfo($chatId);
if ($info) {
if ($todaySum) {
$info->today_sum++;
}
if ($todayReturnSum) {
$info->today_return_sum++;
}
$info->chat_sum = $chatSum;
$info->chat_return_sum = $chatReturnSum;
$info->save();
} else {
$this->dao->save([
'group_id' => $chatId,
'today_sum' => $todaySum ? 1 : 0,
'today_return_sum' => $todayReturnSum ? 1 : 0,
'chat_sum' => $chatSum,
'chat_return_sum' => $chatReturnSum,
]);
}
}
/**
* 群统计列表
* @param int $id
* @param string $time
* @return array
*/
public function getChatStatisticsList(int $id, string $time)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getDataList(['time' => $time, 'group_id' => $id], ['*'], $page, $limit);
$count = $this->dao->count(['time' => $time, 'group_id' => $id]);
return compact('list', 'count');
}
}