1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Community\Actions\Vaccine;
- use App\Models\Order;
- use App\Models\OrderVaccine;
- use App\Models\UserNextVaccine;
- use App\Models\Vaccine;
- use Encore\Admin\Actions\RowAction;
- use Illuminate\Database\Eloquent\Model;
- class Finished extends RowAction
- {
- public $name = '完成订单';
- public function handle(Model $model)
- {
- $req = request()->post();
- $id = $this->row->id;
- $res = Order::where('id',$id)->update(['order_status'=>Order::FINISHED,'end_time'=>time()]);
- if (!$res) {
- return $this->response()->error('操作失败!');
- }
- $order = Order::select(['user_id', 'patient_id'])->where('id', $id)->first();
- //更新下次接种的疫苗为已经接种了
- $vaccine_id = OrderVaccine::where('order_id', $id)->value('vaccine_id');
- UserNextVaccine::where('user_id', $order['user_id'])->where('patient_id', $order['patient_id'])->where('vaccine_id', $vaccine_id)->where('is_vaccinate', 0)->update(['is_vaccinate' => 1, 'vaccinate_time' => time()]);
- //添加下次接种疫苗
- if (!empty($req['vaccine_id'])) {
- $order = Order::select(['user_id', 'patient_id'])->where('id', $id)->first();
- UserNextVaccine::create([
- 'user_id' => $order['user_id'],
- 'patient_id' => $order['patient_id'],
- 'vaccine_id' => $req['vaccine_id'],
- 'next_vaccinate_time' => strtotime($req['next_vaccinate_date']),
- ]);
- }
- return $this->response()->success('操作成功!')->refresh();
- }
- public function form()
- {
- $order_id = $this->row->id;
- $order = Order::select(['organization_id'])->where('id', $order_id)->first();
- $vaccines = Vaccine::where('org_id', $order['organization_id'])->pluck('name', 'id')->toArray();
- $vaccines = ['0' => '选填'] + $vaccines;
- $this->select('vaccine_id', __('下次接种疫苗'))->options($vaccines);
- $this->date('next_vaccinate_date', '下次接种时间')->placeholder('选填');
- }
- }
|