Commit f241f0de by lujunyi

命令 自动任务

parent e201d581
...@@ -17,36 +17,36 @@ class PrescriptionCommand extends Command ...@@ -17,36 +17,36 @@ class PrescriptionCommand extends Command
* *
* @var string * @var string
*/ */
protected $signature = 'app:prescription-command'; protected $signature = 'mohe:prescription';
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string
*/ */
protected $description = 'Command description'; protected $description = '自动审开方';
/** /**
* Execute the console command. * Execute the console command.
*/ */
public function handle() public function handle()
{ {
$this->info('start command'); $this->info('开始自动审开方...');
// 常驻脚本
while (true) {
sleep(5);
// 如果处方单是审方状态,同时对应的药店开启自动审方 // 如果处方单是审方状态,同时对应的药店开启自动审方
$prescriptions = PrescriptionModel::where('status', 1) $prescriptions = PrescriptionModel::where('status', 1)
->where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING) ->where('status', PrescriptionModel::PRESCRIPTION_STATUS_REVIEWING)
->get(); ->get();
if ($prescriptions->count() > 0) { if ($prescriptions->count() > 0) {
$this->info('没有需要审方的处方单');
return;
}
foreach ($prescriptions as $prescription) { foreach ($prescriptions as $prescription) {
// 查询对应的医师是手动并且药师为自动 // 查询对应的医师是手动并且药师为自动
$pharmacist = PharmacyModel::where('id', $prescription->pharmacy_id)->first(); $pharmacist = PharmacyModel::where('id', $prescription->pharmacy_id)->first();
$doctor = DoctorModel::where('id', $prescription->doctor_id)->first(); $doctor = DoctorModel::where('id', $prescription->doctor_id)->first();
if ($doctor->is_auto == 0 && $pharmacist->is_auto == 1) { if ($doctor->is_auto == 0 && $pharmacist->is_auto == 1) {
// var_dump($prescription);
// 更新处方单状态 // 更新处方单状态
$prescriptionInfo = PrescriptionModel::find($prescription->id); $prescriptionInfo = PrescriptionModel::find($prescription->id);
if ($prescriptionInfo) { if ($prescriptionInfo) {
...@@ -65,11 +65,6 @@ public function handle() ...@@ -65,11 +65,6 @@ public function handle()
$pharmacistLog->save(); $pharmacistLog->save();
$this->info($prescription->id.'审方成功'); $this->info($prescription->id.'审方成功');
} }
}
}
} else {
$this->info('没有需要审方的处方单');
} }
} }
......
...@@ -7,16 +7,13 @@ ...@@ -7,16 +7,13 @@
class Kernel extends ConsoleKernel class Kernel extends ConsoleKernel
{ {
protected $commands = [
\App\Console\Commands\PrescriptionCommand::class,
];
/** /**
* Define the application's command schedule. * Define the application's command schedule.
*/ */
protected function schedule(Schedule $schedule): void protected function schedule(Schedule $schedule): void
{ {
// $schedule->command('inspire')->hourly(); // $schedule->command('inspire')->hourly();
$schedule->command('mohe:prescription')->everyFiveMinutes();
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment