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
+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');
}
}
});
}
}