1
0
Fork 0

patient notify

master
panliang 2023-09-23 13:56:34 +08:00
parent 323eadc273
commit f466a19d6f
4 changed files with 38 additions and 9 deletions

View File

@ -8,7 +8,7 @@ Route::group([
'prefix' => config('admin.route.prefix'),
'middleware' => config('admin.route.middleware'),
], function (Router $router) {
$router->resource('dashboard', \App\Admin\Controllers\HomeController::class);
$router->get('dashboard', [\App\Admin\Controllers\HomeController::class, 'index']);
$router->get('menus', [\App\Admin\Controllers\HomeController::class, 'menus']);
$router->get('current-user', [\App\Admin\Controllers\AuthController::class, 'currentUser']);
$router->post('login', [\App\Admin\Controllers\AuthController::class, 'login']);

View File

@ -3,8 +3,10 @@
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\PatientRecord;
use App\Models\{PatientRecord, UserSocialite};
use Overtrue\LaravelWeChat\EasyWeChat;
use Slowlyo\OwlAdmin\Models\AdminUser;
use App\Enums\SocialiteType;
class PatientRecordNotify extends Command
{
@ -20,21 +22,44 @@ class PatientRecordNotify extends Command
*
* @var string
*/
protected $description = '病历记录: 通知医生';
protected $description = '病历记录: 通知';
/**
* Execute the console command.
*/
public function handle()
{
$list = PatientRecord::where('is_notified', 0)->whereNotNul('notify_user_id')->whereNotNul('notify_at')->get();
$now = now();
$list = PatientRecord::where('is_notified', 0)
->whereNotNull('notify_user_id')
->whereBetween('notify_at', [$now->copy()->startOfDay(), $now->copy()->endOfDay()])
->get();
$app = EasyWeChat::officialAccount();
$app->setAccessToken(new \App\Services\WechatOfficialAccessToken(
appId: $this->getAccount()->getAppId(),
secret: $this->getAccount()->getSecret(),
cache: $this->getCache(),
httpClient: $this->getHttpClient(),
stable: $this->config->get('use_stable_access_token', false),
appId: $app->getAccount()->getAppId(),
secret: $app->getAccount()->getSecret(),
cache: $app->getCache(),
httpClient: $app->getHttpClient(),
stable: $app->getConfig()->get('use_stable_access_token', false),
));
$api = $app->getClient();
// 微信公众号关联账户
$users = UserSocialite::where('user_type', (new AdminUser)->getMorphClass())->where('type', SocialiteType::WxOfficial)->whereIn('user_id', $list->pluck('notify_user_id'))->get();
foreach ($list as $item) {
$user = $users->firstWhere('user_id', $item->notify_user_id);
if ($user) {
$response = $api->postJson('/cgi-bin/message/template/send', [
'touser' => $user->openid,
'template_id' => '',
'url' => url('/h5/pages/record/detail?id=' . $item->id),
'data' => []
]);
if ($response->isFailed()) {
logger('病历记录: 通知, 模板消息发送, 失败', $response->toArray(false));
continue;
}
$item->update(['is_notified' => 1]);
}
}
}
}

View File

@ -13,6 +13,8 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->call(fn () => logger('schdule running'))->everyMinute();
$schedule->command('patient-record:notify')->daily();
}
/**

View File

@ -7,6 +7,8 @@ return [
'defaults' => [
'http' => [
'timeout' => 5.0,
'throw' => false,
'retry' => false,
],
],