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_LISTEN = 'http://0.0.0.0:9007'
WEBMAN_COUNT = 8 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); $perPage = $request->input('per_page', 10);
//id //id
$user_id = $request->user['id']; $userId = $request->user['id'];
if(Util::isEmpty($user_id)){ if(Util::isEmpty($userId)){
return Util::fail([],'user_id'.trans('not_null')); return Util::fail([],'user_id'.trans('not_null'));
} }
$where = []; $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) $data = Daily::with('user')->where($where)
+30 -18
View File
@@ -5,12 +5,17 @@ use app\model\RequestTracks;
class DataTracker class DataTracker
{ {
// 不需要埋点的路径
protected $excludePaths = [
'/user/login'
];
public function process($request, \Closure $next) public function process($request, \Closure $next)
{ {
// 前置处理 if ($this->shouldSkipTracking($request)) {
if($request->path() != 'user/login'){ return $next($request);
return $request;
} }
// 前置处理
$this->logRequestData($request); $this->logRequestData($request);
$response = $next($request); $response = $next($request);
@@ -21,11 +26,31 @@ class DataTracker
return $response; 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) protected function logRequestData($request)
{ {
$trackData = [ $trackData = [
'app_id' => 'crm/api', 'app_id' => 'crm/api',
'user_id' => $request->user['id'], 'user_id' => $request->user['id']??0,
'ip' => $request->getRealIp(), 'ip' => $request->getRealIp(),
'method' => $request->method(), 'method' => $request->method(),
'path' => $request->path(), 'path' => $request->path(),
@@ -38,20 +63,7 @@ class DataTracker
$requestTrack = RequestTracks::create($trackData); $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() protected function generateTraceId()
{ {
+68 -32
View File
@@ -5,6 +5,7 @@ namespace app\process;
use app\controller\FeishuController; use app\controller\FeishuController;
use app\model\Customer; use app\model\Customer;
use app\model\CustomerHis; use app\model\CustomerHis;
use app\model\Daily;
use app\model\FeishuUser; use app\model\FeishuUser;
use app\model\RequestTracks; use app\model\RequestTracks;
use app\model\User; use app\model\User;
@@ -18,9 +19,9 @@ class Task
public function onWorkerStart() public function onWorkerStart()
{ {
// 每半小时执行一次 // 每半小时执行一次
new Crontab('0 */30 * * * *', function(){ new Crontab('0 */30 * * * *', function () {
echo date('Y-m-d H:i:s') . "\n"; 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', '跟进提醒', '您有新的跟进提醒', ''); // FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', '');
// $customer = Customer::where(['follow_next', '<=', time() + 3600]) // $customer = Customer::where(['follow_next', '<=', time() + 3600])
// ->where(['follow_next', '>', time()]) // ->where(['follow_next', '>', time()])
@@ -56,29 +57,29 @@ class Task
$feishuUser = FeishuUser::where(['user_id' => $item->user_id])->first(); $feishuUser = FeishuUser::where(['user_id' => $item->user_id])->first();
if ($feishuUser) { if ($feishuUser) {
// 获取凭证 // 获取凭证
$certificate = config('feishu.'.$feishuUser->sign); $certificate = config('feishu.' . $feishuUser->sign);
// 使用parse_url解析URL // 使用parse_url解析URL
$parsedUrl = parse_url($certificate['rUrl']); $parsedUrl = parse_url($certificate['rUrl']);
// 获取域名和端口 // 获取域名和端口
$host = $parsedUrl['host']; $host = $parsedUrl['host'];
$port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : ''; $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->warn = 1;
$item->update(); $item->update();
Log::info('send',['open_id'=>$item['open_id'],'url'=>$url]); Log::info('send', ['open_id' => $item['open_id'], 'url' => $url]);
$content = FeishuController::postMsg( '跟进提醒', '您有新的跟进提醒', $url); $content = FeishuController::postMsg('跟进提醒', '您有新的跟进提醒', $url);
FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post'); 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"; echo date('Y-m-d H:i:s') . "\n";
Log::info('send high seas start',[time()]); Log::info('send high seas start', [time()]);
$where = [ $where = [
['deleted_at', '<=', time() - 3600], ['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 () { 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()]); Log::info('start daily', [time()]);
$where[] = ["user_id", ">", 0];
$where = [ $where = [
['created_at', '<=', time() - (3600 * 24)], ['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) ->where($where)
->whereIn('path', ['customer/claim', 'customer/save', 'follow/save', 'customer/collect']) ->whereIn('path', $eventTracking)
->groupBy('user_id','path') ->groupBy('user_id', 'path')
->orderBy('user_id', 'asc') // ->orderBy('user_id', 'asc')
->get(); ->get();
$statistics = []; $statistics = [];
$users = []; $users = [];
$daily = ''; $content = '';
foreach ($requestTracks as $item) { foreach ($requestTracks as $item) {
$statistics[$item->user_id][$item->path] = $item->count; $statistics[$item->user_id][$item->path] = $item->count;
$users[] = $item->user_id; $users[] = $item->user_id;
} }
foreach ($users as $userId) { foreach ($users as $userId) {
$daily .= date('Y-m-d') . "\n"; $data = [
$daily .= '领取客户'.$statistics[$userId]['customer/claim'].'位\n'; 'user_id' => $userId,
$daily .= '创建或修改客户'.$statistics[$userId]['customer/save'].'位\n'; 'customer_claim' => $statistics[$userId]['customer/claim'] ?? 0,
$daily .= '添加跟进'.$statistics[$userId]['follow/save'].'次\n'; 'customer_save' => $statistics[$userId]['customer/save'] ?? 0,
$daily .= '询盘跟单客户'.$statistics[$userId]['customer/collect'].'位\n'; 'follow_add' => $statistics[$userId]['follow/save'] ?? 0,
$daily .= '请及时查看,30分钟后将向主管发送'; '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(); $feishuUser = FeishuUser::where(['user_id' => $userId])->first();
if ($feishuUser) { if ($feishuUser) {
// 获取凭证 $url = config('const.web_domain') . '/pages/mine/workreportdetil?id=' . $daily->id;
$certificate = config('feishu.'.$feishuUser->sign); $content = FeishuController::postMsg(date('Y-m-d') . '日报', $content, $url);
// 使用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);
FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post'); FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post');
} }
@@ -147,6 +164,25 @@ class Task
Log::info('send high seas end', [time()]); 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 [ return [
'rpc_domain' => getenv('RPC_DOMAIN'), 'rpc_domain' => getenv('RPC_DOMAIN'),
'event_tracking' => [ 'event_tracking' => [
'follow/save', '/follow/save',
'customer/claim', '/customer/claim',
'customer/save', '/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\CrossDomain::class, // 全局跨域中间件
app\middleware\AuthMiddleware::class, // 鉴权中间件 app\middleware\AuthMiddleware::class, // 鉴权中间件
// app\middleware\DataTracker::class, //埋点 app\middleware\DataTracker::class, //埋点
], ],
// 路由中间件 // 路由中间件
'route' => [ 'route' => [
// 'track' => app\middleware\DataTracker::class, 'track' => app\middleware\DataTracker::class,
] ]
]; ];