Files
douba_shop/app/services/work/WorkGroupMsgSendResultServices.php
Karlcarlo c9a98f342c chore: 添加静态资源文件和版本配置文件
添加大量图片、字体、音频等静态资源文件,包括用户界面图片、模板文件和安装界面素材
添加系统版本配置文件(.version)和常量定义文件(.constant)
更新供应商依赖文件,包括Symfony VarDumper组件和相关许可证文件
添加验证码配置文件(captcha.php)和.gitignore规则
2026-03-06 20:14:23 +08:00

124 lines
4.3 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\WorkGroupMsgSendResultDao;
use app\jobs\work\WorkGroupMsgJob;
use app\services\BaseServices;
use crmeb\services\wechat\Work;
use think\annotation\Inject;
use think\facade\Log;
/**
* 企业微信群发消息客户发送详情
* Class WorkGroupMsgSendResultServices
* @package app\services\work
* @mixin WorkGroupMsgSendResultDao
*/
class WorkGroupMsgSendResultServices extends BaseServices
{
/**
* @var WorkGroupMsgSendResultDao
*/
#[Inject]
protected WorkGroupMsgSendResultDao $dao;
/**
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getClientList(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getDataList($where, ['*'], $page, $limit, 'create_time', ['client']);
$count = $this->dao->count($where);
return compact('list', 'count');
}
/**
* 获取群主发送详情
* @param array $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroupChatMsgList(array $where)
{
[$page, $limit] = $this->getPageValue();
$list = $this->dao->getGroupChatMsg($where)->whereNotNull('chat_id')->page($page, $limit)->select()->toArray();
$count = $this->dao->getGroupChatMsg($where)->whereNotNull('chat_id')->count();
return compact('list', 'count');
}
/**
* 获取企业群发成员执行结果
* @param int $type
* @param string $userid
* @param string $msgid
* @param string|null $cursor
* @return bool
*/
public function getSendResult(int $type, string $userid, string $msgid, string $cursor = null)
{
try {
$response = Work::getGroupmsgSendResult($msgid, $userid, 500, $cursor);
$sendList = $response['send_list'] ?? [];
foreach ($sendList as $item) {
$where = ['msg_id' => $msgid, 'userid' => $userid];
if ($type) {
$where['chat_id'] = $item['chat_id'];
} else {
$where['external_userid'] = $item['external_userid'];
}
$info = $this->dao->get($where);
if (!$info) {
$this->dao->save([
'msg_id' => $msgid,
'userid' => $item['userid'],
'chat_id' => $item['chat_id'] ?? null,
'status' => $item['status'],
'send_time' => $item['send_time'] ?? 0,
'external_userid' => $item['external_userid'] ?? null,
]);
} else {
$info->status = $item['status'];
$info->send_time = $item['send_time'] ?? 0;
$info->save();
}
}
if ($response['next_cursor']) {
WorkGroupMsgJob::dispatchDo('getSendResult', [$type, $userid, $msgid, $response['next_cursor']]);
}
return true;
} catch (\Throwable $e) {
Log::error(
json_encode([
'message' => '获取企业群发成员执行结果失败:' . $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)
);
return false;
}
}
}