This commit is contained in:
2025-04-17 10:14:01 +08:00
parent 88dc849bd5
commit c954218088
6 changed files with 125 additions and 59 deletions
+5 -1
View File
@@ -19,4 +19,8 @@ JWT_EXPIRATION = 2592000
WEBMAN_LISTEN = 'http://0.0.0.0:9007'
WEBMAN_COUNT = 8
RPC_DOMAIN = http://219.157.255.213:25015
# 公共服务
RPC_DOMAIN = http://219.157.255.213:25015
# 前端域名
WEB_DOMAIN = http://219.157.255.213:8085
+10 -3
View File
@@ -26,13 +26,20 @@ class DailyController
$perPage = $request->input('per_page', 10);
//id
$user_id = $request->user['id'];
if(Util::isEmpty($user_id)){
$userId = $request->user['id'];
if(Util::isEmpty($userId)){
return Util::fail([],'user_id'.trans('not_null'));
}
$where = [];
$where['user_id'] = $user_id;
//判断领导
$mast = config('const.daily_group_2');
if ($userId == $mast['master']) {
$where['leader_id'] = $mast['master'];
}else{
$where['user_id'] = $userId;
}
// 执行分页查询
$data = Daily::with('user')->where($where)
+30 -18
View File
@@ -5,12 +5,17 @@ use app\model\RequestTracks;
class DataTracker
{
// 不需要埋点的路径
protected $excludePaths = [
'/user/login'
];
public function process($request, \Closure $next)
{
// 前置处理
if($request->path() != 'user/login'){
return $request;
if ($this->shouldSkipTracking($request)) {
return $next($request);
}
// 前置处理
$this->logRequestData($request);
$response = $next($request);
@@ -21,11 +26,31 @@ class DataTracker
return $response;
}
protected function shouldSkipTracking($request)
{
$currentPath = $request->path();
$eventTracking = config('const.event_tracking');
// 检查是否在排除列表中
// foreach ($this->excludePaths as $path) {
// if (str_starts_with($currentPath, $path)) {
// return true;
// }
// }
if (in_array($currentPath, $eventTracking)) {
return false;
}
return true;
}
protected function logRequestData($request)
{
$trackData = [
'app_id' => 'crm/api',
'user_id' => $request->user['id'],
'user_id' => $request->user['id']??0,
'ip' => $request->getRealIp(),
'method' => $request->method(),
'path' => $request->path(),
@@ -38,20 +63,7 @@ class DataTracker
$requestTrack = RequestTracks::create($trackData);
}
protected function sendToQueue($data)
{
// 使用Redis队列
try {
redis()->lpush('track_queue', json_encode($data));
} catch (\Exception $e) {
// 失败降级处理
file_put_contents(
runtime_path('logs/track_fallback.log'),
json_encode($data) . PHP_EOL,
FILE_APPEND
);
}
}
protected function generateTraceId()
{
+68 -32
View File
@@ -5,6 +5,7 @@ namespace app\process;
use app\controller\FeishuController;
use app\model\Customer;
use app\model\CustomerHis;
use app\model\Daily;
use app\model\FeishuUser;
use app\model\RequestTracks;
use app\model\User;
@@ -18,9 +19,9 @@ class Task
public function onWorkerStart()
{
// 每半小时执行一次
new Crontab('0 */30 * * * *', function(){
new Crontab('0 */30 * * * *', function () {
echo date('Y-m-d H:i:s') . "\n";
Log::info('send follow start',[time()]);
Log::info('send follow start', [time()]);
// FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', '');
// $customer = Customer::where(['follow_next', '<=', time() + 3600])
// ->where(['follow_next', '>', time()])
@@ -56,29 +57,29 @@ class Task
$feishuUser = FeishuUser::where(['user_id' => $item->user_id])->first();
if ($feishuUser) {
// 获取凭证
$certificate = config('feishu.'.$feishuUser->sign);
$certificate = config('feishu.' . $feishuUser->sign);
// 使用parse_url解析URL
$parsedUrl = parse_url($certificate['rUrl']);
// 获取域名和端口
$host = $parsedUrl['host'];
$port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';
$url = 'http://'. $host .$port. '/pages/customer/detile?id='.$item->id;
$url = 'http://' . $host . $port . '/pages/customer/detile?id=' . $item->id;
$item->warn = 1;
$item->update();
Log::info('send',['open_id'=>$item['open_id'],'url'=>$url]);
$content = FeishuController::postMsg( '跟进提醒', '您有新的跟进提醒', $url);
Log::info('send', ['open_id' => $item['open_id'], 'url' => $url]);
$content = FeishuController::postMsg('跟进提醒', '您有新的跟进提醒', $url);
FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post');
}
}
Log::info('send follow start',[time()]);
Log::info('send follow start', [time()]);
});
//回收站客户转向公海 每小时执行一次
new Crontab('0 10 * * * *', function(){
new Crontab('0 10 * * * *', function () {
echo date('Y-m-d H:i:s') . "\n";
Log::info('send high seas start',[time()]);
Log::info('send high seas start', [time()]);
$where = [
['deleted_at', '<=', time() - 3600],
@@ -94,51 +95,67 @@ class Task
]);
}
Log::info('send high seas end',[time()]);
Log::info('send high seas end', [time()]);
});
//总结日报, 每天执行一次
new Crontab('0 30 17 * * *', function () {
echo date('Y-m-d H:i:s') . "\n";
echo date('Y-m-d H:i:s') . " start daily \n";
Log::info('start daily', [time()]);
$where[] = ["user_id", ">", 0];
$where = [
['created_at', '<=', time() - (3600 * 24)],
];
$requestTracks = RequestTracks::select('*, COUNT(*) as count')
$eventTracking = config('const.event_tracking');
$requestTracks = RequestTracks::selectRaw('user_id,path, COUNT(*) as count',)
// select('*',' COUNT(*) as count')
->where($where)
->whereIn('path', ['customer/claim', 'customer/save', 'follow/save', 'customer/collect'])
->groupBy('user_id','path')
->orderBy('user_id', 'asc')
->whereIn('path', $eventTracking)
->groupBy('user_id', 'path')
// ->orderBy('user_id', 'asc')
->get();
$statistics = [];
$users = [];
$daily = '';
$content = '';
foreach ($requestTracks as $item) {
$statistics[$item->user_id][$item->path] = $item->count;
$users[] = $item->user_id;
}
foreach ($users as $userId) {
$daily .= date('Y-m-d') . "\n";
$daily .= '领取客户'.$statistics[$userId]['customer/claim'].'位\n';
$daily .= '创建或修改客户'.$statistics[$userId]['customer/save'].'位\n';
$daily .= '添加跟进'.$statistics[$userId]['follow/save'].'次\n';
$daily .= '询盘跟单客户'.$statistics[$userId]['customer/collect'].'位\n';
$daily .= '请及时查看,30分钟后将向主管发送';
$data = [
'user_id' => $userId,
'customer_claim' => $statistics[$userId]['customer/claim'] ?? 0,
'customer_save' => $statistics[$userId]['customer/save'] ?? 0,
'follow_add' => $statistics[$userId]['follow/save'] ?? 0,
'customer_collect' => $statistics[$userId]['customer/collect'] ?? 0,
'content' => '',
];
//判断领导
$mast = config('const.daily_group_2');
if (in_array($userId, $mast['member'])) {
$data['leader_id'] = $mast['master'];
}else{
$data['leader_id'] = 5;
}
$content .= date('Y-m-d') . "\n";
$data['content'] .= '领取客户' . ($statistics[$userId]['customer/claim'] ?? 0) . '位\n';
$data['content'] .= '创建或修改客户' . ($statistics[$userId]['customer/save'] ?? 0) . '位\n';
$data['content'] .= '添加跟进' . ($statistics[$userId]['follow/save'] ?? 0) . '次\n';
$data['content'] .= '询盘跟单客户' . ($statistics[$userId]['customer/collect'] ?? 0) . '位\n';
$content .= $data['content'];
$daily = Daily::create($data);
$content .= '请及时查看,30分钟后将向主管发送';
$feishuUser = FeishuUser::where(['user_id' => $userId])->first();
if ($feishuUser) {
// 获取凭证
$certificate = config('feishu.'.$feishuUser->sign);
// 使用parse_url解析URL
$parsedUrl = parse_url($certificate['rUrl']);
// 获取域名和端口
$host = $parsedUrl['host'];
$port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : '';
$url = 'http://'. $host .$port. '/pages/customer/detile?id=';
$content = FeishuController::postMsg( '跟进提醒', $daily, $url);
$url = config('const.web_domain') . '/pages/mine/workreportdetil?id=' . $daily->id;
$content = FeishuController::postMsg(date('Y-m-d') . '日报', $content, $url);
FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post');
}
@@ -147,6 +164,25 @@ class Task
Log::info('send high seas end', [time()]);
});
//向领导发送日报 每天执行一次
new Crontab('0 0 18 * * *', function () {
echo date('Y-m-d H:i:s') . "\n";
Log::info('send daily to leader', [time()]);
$where = [];
$where[] = ['send', '=', 0];
$where[] = ['created_at', '>=', strtotime(date('Y-m-d 00:00:00'))];
$daily = Daily::select('leader_id')->where($where)->groupBy('leader_id')->get();
foreach ($daily as $item) {
$feishuUser = FeishuUser::where(['user_id' => $item->leader_id])->first();
if ($feishuUser) {
$url = config('const.web_domain') . '/pages/mine/workreport';
$content = FeishuController::postMsg(date('Y-m-d') . '日报已汇总', '请点击查看', $url);
FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post');
}
}
});
}
}
+10 -3
View File
@@ -3,8 +3,15 @@
return [
'rpc_domain' => getenv('RPC_DOMAIN'),
'event_tracking' => [
'follow/save',
'customer/claim',
'customer/save',
'/follow/save',
'/customer/claim',
'/customer/save',
'/customer/collect',
'/user/login',
],
'web_domain' => getenv('WEB_DOMAIN'),
'daily_group_2' => [
'master' => 28, //组长
'member' => [22, 23, 28, 34, 44, 46, 77, 87] //组员
],
];
+2 -2
View File
@@ -17,12 +17,12 @@ return [
'' => [
app\middleware\CrossDomain::class, // 全局跨域中间件
app\middleware\AuthMiddleware::class, // 鉴权中间件
// app\middleware\DataTracker::class, //埋点
app\middleware\DataTracker::class, //埋点
],
// 路由中间件
'route' => [
// 'track' => app\middleware\DataTracker::class,
'track' => app\middleware\DataTracker::class,
]
];