100 lines
4.0 KiB
PHP
100 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace app\process;
|
|
|
|
use app\controller\FeishuController;
|
|
use app\model\Customer;
|
|
use app\model\CustomerHis;
|
|
use app\model\FeishuUser;
|
|
use app\model\User;
|
|
use support\Log;
|
|
use Webman\App;
|
|
use Workerman\Crontab\Crontab;
|
|
|
|
class Task
|
|
{
|
|
|
|
public function onWorkerStart()
|
|
{
|
|
// 每半小时执行一次
|
|
new Crontab('0 */30 * * * *', function(){
|
|
echo date('Y-m-d H:i:s') . "\n";
|
|
Log::info('send follow start',[time()]);
|
|
// FeishuController::send('xinyouhe','ou_e33bb3017ada6c4781398a68e55a4696', '跟进提醒', '您有新的跟进提醒', '');
|
|
// $customer = Customer::where(['follow_next', '<=', time() + 3600])
|
|
// ->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]);
|
|
FeishuController::send($feishuUser->sign, $feishuUser->open_id, '跟进提醒', '您有新的跟进提醒', $url);
|
|
}
|
|
}
|
|
|
|
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()]);
|
|
});
|
|
|
|
}
|
|
|
|
} |