Files
huangjingfen/pro_v3.5.1/app/services/work/WorkGroupChatStatisticServices.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

78 lines
2.2 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
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');
}
}