where(['follow_next', '>', time()]) // ->where(['warn', '<', 1]) // ->get(); // foreach ($customer as $item) { // $feishuUser = FeishuUser::where(['user_id' => $item->user_id])->first(); // if ($feishuUser) { // // 获取凭证 // $certificate = config($this->config); // // 使用parse_url解析URL // $parsedUrl = parse_url($certificate['rUrl']); // // 获取域名和端口 // $host = $parsedUrl['host']; // $port = isset($parsedUrl['port']) ? ':' . $parsedUrl['port'] : ''; // $url = $host .$port. '/pages/customer/detile?id='.$customer->id; // $item->warn = 1; // $item->update(); // $user = User::first()->where('id', $item->user_id); // Log::info('send',['open_id'=>$item['open_id'],'url'=>$url]); // // FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', $url); // FeishuController::send($user->sign,$feishuUser->open_id, '跟进提醒', '您有新的跟进提醒', $url); // } // } $where = [ ['follow_next', '<=', time() + 3600], ['follow_next', '>', time()], ['warn', '<', 1] ]; $customer = Customer::where($where)->get(); foreach ($customer as $item) { $feishuUser = FeishuUser::where(['user_id' => $item->user_id])->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='.$item->id; $item->warn = 1; $item->update(); 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()]); }); //回收站客户转向公海 每小时执行一次 new Crontab('0 10 * * * *', function(){ echo date('Y-m-d H:i:s') . "\n"; Log::info('send high seas start',[time()]); $where = [ ['deleted_at', '<=', time() - 3600], ['user_id', '<>', 0], ]; $customer = Customer::where($where)->onlyTrashed()->get(); foreach ($customer as $item) { $item->update(['user_id' => 0, 'deleted_at' => time()]); CustomerHis::create([ 'customer_id' => $item->_id, 'user_his' => $item->user_id, 'user_id' => 0, ]); } Log::info('send high seas end',[time()]); }); //总结日报, 每天执行一次 new Crontab('0 30 17 * * *', function () { echo date('Y-m-d H:i:s') . "\n"; Log::info('start daily', [time()]); $where = [ ['created_at', '<=', time() - (3600 * 24)], ]; $requestTracks = RequestTracks::select('*, COUNT(*) as count') ->where($where) ->whereIn('path', ['customer/claim', 'customer/save', 'follow/save', 'customer/collect']) ->groupBy('user_id','path') ->orderBy('user_id', 'asc') ->get(); $statistics = []; $users = []; $daily = ''; 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分钟后将向主管发送'; $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); FeishuController::send($feishuUser->sign, $feishuUser->open_id, $content, 'post'); } } Log::info('send high seas end', [time()]); }); } }