patient notify
parent
323eadc273
commit
f466a19d6f
|
|
@ -8,7 +8,7 @@ Route::group([
|
||||||
'prefix' => config('admin.route.prefix'),
|
'prefix' => config('admin.route.prefix'),
|
||||||
'middleware' => config('admin.route.middleware'),
|
'middleware' => config('admin.route.middleware'),
|
||||||
], function (Router $router) {
|
], 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('menus', [\App\Admin\Controllers\HomeController::class, 'menus']);
|
||||||
$router->get('current-user', [\App\Admin\Controllers\AuthController::class, 'currentUser']);
|
$router->get('current-user', [\App\Admin\Controllers\AuthController::class, 'currentUser']);
|
||||||
$router->post('login', [\App\Admin\Controllers\AuthController::class, 'login']);
|
$router->post('login', [\App\Admin\Controllers\AuthController::class, 'login']);
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Models\PatientRecord;
|
use App\Models\{PatientRecord, UserSocialite};
|
||||||
use Overtrue\LaravelWeChat\EasyWeChat;
|
use Overtrue\LaravelWeChat\EasyWeChat;
|
||||||
|
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||||||
|
use App\Enums\SocialiteType;
|
||||||
|
|
||||||
class PatientRecordNotify extends Command
|
class PatientRecordNotify extends Command
|
||||||
{
|
{
|
||||||
|
|
@ -20,21 +22,44 @@ class PatientRecordNotify extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = '病历记录: 通知医生';
|
protected $description = '病历记录: 通知';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
public function handle()
|
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 = EasyWeChat::officialAccount();
|
||||||
$app->setAccessToken(new \App\Services\WechatOfficialAccessToken(
|
$app->setAccessToken(new \App\Services\WechatOfficialAccessToken(
|
||||||
appId: $this->getAccount()->getAppId(),
|
appId: $app->getAccount()->getAppId(),
|
||||||
secret: $this->getAccount()->getSecret(),
|
secret: $app->getAccount()->getSecret(),
|
||||||
cache: $this->getCache(),
|
cache: $app->getCache(),
|
||||||
httpClient: $this->getHttpClient(),
|
httpClient: $app->getHttpClient(),
|
||||||
stable: $this->config->get('use_stable_access_token', false),
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ class Kernel extends ConsoleKernel
|
||||||
protected function schedule(Schedule $schedule): void
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
|
$schedule->call(fn () => logger('schdule running'))->everyMinute();
|
||||||
|
$schedule->command('patient-record:notify')->daily();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ return [
|
||||||
'defaults' => [
|
'defaults' => [
|
||||||
'http' => [
|
'http' => [
|
||||||
'timeout' => 5.0,
|
'timeout' => 5.0,
|
||||||
|
'throw' => false,
|
||||||
|
'retry' => false,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue