zilong 4 роки тому
батько
коміт
3b90221445

+ 32 - 3
app/Community/Actions/Vaccine/Finished.php

xqd xqd
@@ -3,6 +3,9 @@
 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;
 
@@ -12,13 +15,39 @@ class Finished extends RowAction
 
     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()->success('操作成功!')->refresh();
+        if (!$res) {
+            return $this->response()->error('操作失败!');
         }
 
-        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('选填');
+    }
 }

+ 26 - 2
app/Http/Controllers/Api/V1/VaccineController.php

xqd xqd xqd
@@ -8,7 +8,9 @@
 
 namespace App\Http\Controllers\Api\V1;
 
+use App\Models\UserNextVaccine;
 use App\Models\Vaccine;
+use DB;
 
 class VaccineController extends AuthController
 {
@@ -20,15 +22,33 @@ class VaccineController extends AuthController
             'name' => 'max:50',
             'type' => 'in:0,1,2',
             'sort_type' => 'in:0,1,2',
+            'patient_id' => 'integer',
         ]);
 
-        $builder = Vaccine::select(['id', 'type', 'price', 'name', 'remark', 'supplier', 'stock'])->where('org_id', $req['organization_id']);
+        $builder = Vaccine::select(['id', 'type', 'price', 'name', 'remark', 'supplier', 'stock', DB::raw('0 is_recommend')])->where('org_id', $req['organization_id']);
         if (!empty($req['type'])) {
             $builder->where('type', $req['type']);
         }
         if (!empty($req['name'])) {
             $builder->where('name', 'like', '%'.$req['name'].'%');
         }
+        //查询患者推荐接种的置顶
+        if (!empty($req['patient_id'])) {
+            $vaccine_ids = UserNextVaccine::where('patient_id', $req['patient_id'])->where('is_vaccinate', 0)->orderBy('next_vaccinate_time', 'asc')->pluck('vaccine_id')->toArray();
+            if (!empty($vaccine_ids)) {
+                $vaccine_ids = array_values(array_unique($vaccine_ids));
+                $builder->whereNotIn('id', $vaccine_ids);
+
+                $builder2 = Vaccine::select(['id', 'type', 'price', 'name', 'remark', 'supplier', 'stock', DB::raw('1 is_recommend')])->where('org_id', $req['organization_id'])->whereIn('id', $vaccine_ids);
+                if (!empty($req['type'])) {
+                    $builder2->where('type', $req['type']);
+                }
+                if (!empty($req['name'])) {
+                    $builder2->where('name', 'like', '%'.$req['name'].'%');
+                }
+                $topVaccines = $builder2->get()->toArray();
+            }
+        }
         if (!empty($req['sort_type'])) {
             if ($req['sort_type'] == 1) {
                 $builder->orderBy('price', 'asc');
@@ -41,7 +61,11 @@ class VaccineController extends AuthController
             $builder->orderBy('stock', 'desc');
         }
 
-        $data = $builder->paginate();
+        $data = $builder->paginate()->toArray();
+        //组合置顶
+        if ((empty($req['page']) || $req['page'] == 1) && !empty($topVaccines)) {
+            $data['data'] = array_merge($topVaccines, $data['data']);
+        }
 
         return out($data);
     }

+ 14 - 0
app/Models/UserNextVaccine.php

xqd
@@ -0,0 +1,14 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: zilongs
+ * Date: 2021/3/10
+ * Time: 4:06 下午
+ */
+
+namespace App\Models;
+
+class UserNextVaccine extends BaseModel
+{
+
+}

+ 14 - 0
upgrade.md

xqd
@@ -23,5 +23,19 @@
       PRIMARY KEY (`id`),
       KEY `vaccine_id` (`vaccine_id`)
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+    
+    CREATE TABLE `bm_user_next_vaccines` (
+      `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
+      `user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
+      `patient_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '患者ID',
+      `vaccine_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '疫苗ID',
+      `next_vaccinate_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '下次接种时间',
+      `is_vaccinate` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '是否已经接种(0.否 1.是)',
+      `vaccinate_time` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '接种时间',
+      `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
+      `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
+      PRIMARY KEY (`id`),
+      KEY `user_id` (`user_id`)
+    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
 
 - 线上在社区端后台改消息通知的菜单链接为:/cdms/community/noticeManage/noticelist