diff --git a/Laravel/app/Services/Admin/YeWu/CheckItemService.php b/Laravel/app/Services/Admin/YeWu/CheckItemService.php
index 9fc78d7..08a472b 100644
--- a/Laravel/app/Services/Admin/YeWu/CheckItemService.php
+++ b/Laravel/app/Services/Admin/YeWu/CheckItemService.php
@@ -18,9 +18,8 @@ public function GetClassList($searchInfo){
}
//获取检查项目列表
public function GetItemList($searchInfo,$page,$pageSize){
- $where=['s_check_item.is_del'=>0];
$small_id=[];
- $list=DB::table('s_check_item');
+ $list=DB::table('s_check_item')->where('s_check_item.is_del', 0)->whereNotNull('sheetType')->where('sheetType', '!=', '');
if(empty($searchInfo['bigClass'])!==true and empty($searchInfo['smallClass'])===true){
$small_id= DB::table('s_check_item_class')->where(['pid'=>$searchInfo['bigClass'],'is_del'=>0])->pluck('id')->toArray();
$list= $list->whereIn('item_class_id',$small_id);
@@ -30,14 +29,31 @@ public function GetItemList($searchInfo,$page,$pageSize){
$list= $list->whereIn('item_class_id',$small_id);
}
if(!empty($searchInfo['name'])){
- $where[]=['item_name','like','%'.$searchInfo['name'].'%'];
+ $list->where(function($query) use ($searchInfo) {
+ $query->where('item_name', 'like', '%'.$searchInfo['name'].'%')
+ ->orWhere('item_code', 'like', '%'.$searchInfo['name'].'%');
+ });
}
- $count= $list->where($where)->count();
+ if (isset($searchInfo['deviceBind']) && $searchInfo['deviceBind'] !== '') {
+ if ($searchInfo['deviceBind'] == 1) {
+ $list->whereIn('s_check_item.id', function($q) {
+ $q->select('item_id')->from('s_check_item_device');
+ });
+ } elseif ($searchInfo['deviceBind'] == 0) {
+ $list->whereNotIn('s_check_item.id', function($q) {
+ $q->select('item_id')->from('s_check_item_device');
+ });
+ }
+ }
+ $count = $list->count();
$list= $list
->leftJoin('s_appointment_type', 's_check_item.reservation_method', '=', 's_appointment_type.id')
- ->select('s_check_item.*','s_appointment_type.name as reservation_method_name')
- ->where($where)->skip(($page-1)*$pageSize) // 跳过前9999条记录
- ->take($pageSize)->get();
+ ->select('s_check_item.*','s_appointment_type.name as reservation_method_name');
+ if (!empty($searchInfo['orderField']) && !empty($searchInfo['orderDirection'])) {
+ $direction = $searchInfo['orderDirection'] == 'ascending' ? 'asc' : 'desc';
+ $list->orderBy($searchInfo['orderField'], $direction);
+ }
+ $list = $list->skip(($page-1)*$pageSize)->take($pageSize)->get();
//查询出所有的预约渠道
$qudaoList=DB::table('s_appointment_type')->get();
foreach ($list as $k=>$v){
diff --git a/Laravel/app/Services/Admin/YeWu/DepartmentResourceService.php b/Laravel/app/Services/Admin/YeWu/DepartmentResourceService.php
index 1e2c5f4..6b00510 100644
--- a/Laravel/app/Services/Admin/YeWu/DepartmentResourceService.php
+++ b/Laravel/app/Services/Admin/YeWu/DepartmentResourceService.php
@@ -5,7 +5,7 @@ class DepartmentResourceService
{
public function Save($info,$userid)
{
- $id = $info['id'];
+ $id = $info['id'] ?? null;
$department_id = $info['department_id'];
//查询科室状态是否正常
$department = DB::table('s_department')
@@ -16,21 +16,70 @@ public function Save($info,$userid)
if(!$department) {
return \Yz::Return(false, '科室状态异常', []);
}
- if(isset($id)) {
- $c = DB::table('s_department_resources')
- ->where('id', $id)
- ->update($info);
- }else {
- $info['is_del']=0;
- $info['adduser']=$userid;
- $info['time_range'] = json_encode($info['time_range']);
- $c = DB::table('s_department_resources')
- ->insert($info);
- }
- if(!$c) {
- return \Yz::Return(false, '保存失败', []);
- }else{
+
+ DB::beginTransaction();
+ try {
+ if(isset($id)) {
+ // 修改诊室
+ $c = DB::table('s_department_resources')
+ ->where('id', $id)
+ ->update($info);
+
+ // 检查是否已关联服务组
+ $bind = DB::table('s_department_resources_device')
+ ->where('rsourece_id', $id)
+ ->first();
+
+ if($bind) {
+ // 已关联 → 同步更新设备名称
+ DB::table('s_devices')
+ ->where('id', $bind->device_id)
+ ->update(['device_name' => $info['department_resources_name']]);
+ } else {
+ // 未关联 → 新建设备并建立关联
+ $deviceId = DB::table('s_devices')->insertGetId([
+ 'device_name' => $info['department_resources_name'],
+ 'status' => 1,
+ 'adduser' => $userid,
+ 'is_del' => 0,
+ ]);
+ DB::table('s_department_resources_device')->insert([
+ 'department_id' => $department_id,
+ 'rsourece_id' => $id,
+ 'device_id' => $deviceId,
+ ]);
+ }
+ } else {
+ // 新增诊室
+ $info['is_del'] = 0;
+ $info['adduser'] = $userid;
+ $info['time_range'] = json_encode($info['time_range']);
+ $resourceId = DB::table('s_department_resources')->insertGetId($info);
+
+ if(!$resourceId) {
+ DB::rollBack();
+ return \Yz::Return(false, '保存失败', []);
+ }
+
+ // 新建设备并建立关联
+ $deviceId = DB::table('s_devices')->insertGetId([
+ 'device_name' => $info['department_resources_name'],
+ 'status' => 1,
+ 'adduser' => $userid,
+ 'is_del' => 0,
+ ]);
+ DB::table('s_department_resources_device')->insert([
+ 'department_id' => $department_id,
+ 'rsourece_id' => $resourceId,
+ 'device_id' => $deviceId,
+ ]);
+ }
+
+ DB::commit();
return \Yz::Return(true, '保存成功', []);
+ } catch (\Exception $e) {
+ DB::rollBack();
+ return \Yz::Return(false, '保存失败:' . $e->getMessage());
}
}
public function GetList($searchInfo,$page,$pageSize){
@@ -50,10 +99,6 @@ public function GetList($searchInfo,$page,$pageSize){
->take($pageSize)->get() ;
foreach ($list as $k=>$v){
$list[$k]->time_range=json_decode($v->time_range,true);
- $list[$k]->devicesInfo=DB::table('s_department_resources_device')
- ->join('s_devices', 's_department_resources_device.device_id', '=', 's_devices.id')
- ->select('s_devices.*')
- ->where('rsourece_id',$v->id)->get();
}
return \Yz::Return(true, '查询成功', ['list'=>$list,'count'=>$c]);
}
diff --git a/YiJi-admin/src/views/Index.vue b/YiJi-admin/src/views/Index.vue
index 6c7fa09..0d0372b 100644
--- a/YiJi-admin/src/views/Index.vue
+++ b/YiJi-admin/src/views/Index.vue
@@ -33,7 +33,7 @@