You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
12 KiB
PHP
271 lines
12 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Admin\YeWu;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class PlanModelController extends Controller
|
|
{
|
|
public function GetList(Request $request)
|
|
{
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
$group = $request->get('role');//中间件产生的参数
|
|
$searchInfo = request('searchInfo');
|
|
$page = request('page');
|
|
$pageSize = request('pageSize');
|
|
$department_id = 0;
|
|
$list = DB::table('s_source_roster')
|
|
->leftJoin('s_department_resources', 's_source_roster.resources_id', '=', 's_department_resources.id')
|
|
// ->leftJoin('s_devices', 's_source_roster.device_id', '=', 's_devices.id')
|
|
->leftJoin('s_period', 's_source_roster.period_id', '=', 's_period.id')
|
|
->select('s_source_roster.*', 's_department_resources.department_resources_name', 's_period.period_name')
|
|
->where(['s_source_roster.is_del' => 0]);
|
|
if ($group == 1) {//如果是管理员
|
|
if (!empty($searchInfo['department_id'])) {
|
|
$list = $list->where('s_source_roster.department_id', $searchInfo['department_id']);
|
|
}
|
|
|
|
} else {
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->get();
|
|
$department_id = $userInfo[0]->department_id;
|
|
$list = $list->where(['s_source_roster.department_id' => $department_id]);
|
|
}
|
|
if (!empty($searchInfo['resources_id'])) {
|
|
$list = $list->where('s_source_roster.resources_id', $searchInfo['resources_id'] );
|
|
}
|
|
if (!empty($searchInfo['device_id'])) {
|
|
//$list = $list->where('s_source_roster.device_id', 'like','%,'.$searchInfo['device_id'].',%' );
|
|
$list = $list->whereRaw("FIND_IN_SET({$searchInfo['device_id']}, s_source_roster.device_id)");
|
|
}
|
|
if (!empty($searchInfo['xingqi'])) {
|
|
$list = $list->where('s_source_roster.weekname', $searchInfo['xingqi'] );
|
|
}
|
|
if (isset($searchInfo['status'])) {
|
|
|
|
$list = $list->where('s_source_roster.status', $searchInfo['status']);
|
|
}
|
|
|
|
$count = $list;
|
|
$count = $count->count();
|
|
$list = $list->orderBy('id','desc')->limit($pageSize)->skip(($page - 1) * $pageSize) // 跳过前9999条记录
|
|
->take($pageSize)->get();
|
|
$ids = [];
|
|
foreach ($list as $key => $value) {
|
|
$list[$key]->countsInfo = [];
|
|
$ids[] = $value->id;
|
|
}
|
|
//匹配渠道数量
|
|
$countsInfo = DB::table('s_source_roster_count')
|
|
->leftJoin('s_appointment_type', 's_source_roster_count.appointment_type_id', '=', 's_appointment_type.id')
|
|
->select('s_source_roster_count.*', 's_appointment_type.name')
|
|
->whereIn('roster_id', $ids)->get();
|
|
|
|
if (count($countsInfo) > 0) {
|
|
foreach ($list as $key => $value) {
|
|
foreach ($countsInfo as $k => $v) {
|
|
if ($value->id == $v->roster_id) {
|
|
$list[$key]->countsInfo[] = $v;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//匹配设备(服务组)
|
|
$devices = DB::table('s_devices')->get();
|
|
foreach ($list as $key => $value) {
|
|
$list[$key]->devices = [];
|
|
$array_device_id = explode(",", $value->device_id);
|
|
foreach ($devices as $k => $v) {
|
|
if (in_array($v->id, $array_device_id)) {
|
|
$list[$key]->devices[] = $v;
|
|
}
|
|
}
|
|
}
|
|
|
|
return \Yz::Return(true, '操作成功', ['list' => $list, 'count' => $count]);
|
|
}
|
|
|
|
public function Save(Request $request)
|
|
{
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
$bitian = array('xingqi', 'max_total', 'qudao_total', 'period_id', 'begin_time', 'end_time', 'end_reservation_time', 'resources_id', 'devices', 'patientType');
|
|
$bitian_zh = array('星期', '当日总量', '渠道数量', '时间段', '开始时间', '结束时间', '停止预约时间', '资源', '设备', '患者类型');
|
|
$planInfo = request('planInfo');
|
|
foreach ($bitian as $key => $field) { //必填项不能为空
|
|
if (array_key_exists($field, $planInfo) && $planInfo[$field] !== '' && $planInfo[$field] !== null && $planInfo[$field] !== [] && $planInfo[$field] !== 0) {
|
|
} else {
|
|
return \Yz::echoError1($bitian_zh[$key] . ' 不能为空');
|
|
}
|
|
}
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
if (!isset($userInfo->department_id)) return \Yz::echoError1('该用户未绑定科室');
|
|
$department_id = $userInfo->department_id;
|
|
|
|
DB::beginTransaction();
|
|
foreach ($planInfo['xingqi'] as $key => $value) {
|
|
$data=[
|
|
'department_id' => $department_id,
|
|
'weekname' => $value,
|
|
'resources_id' => $planInfo['resources_id'],
|
|
'device_id' => isset($planInfo['devices'])?implode(',', $planInfo['devices']):'',
|
|
'period_id' => $planInfo['period_id'], //时间段id
|
|
'patient_type' =>isset($planInfo['patientType'])?implode(',', $planInfo['patientType']):'',//病人类型
|
|
'begin_time' => $planInfo['begin_time'],
|
|
'end_time' => $planInfo['end_time'],
|
|
'end_reservation_time' => $planInfo['end_reservation_time'],
|
|
'time_unit' => $planInfo['time_unit'],
|
|
'status' => $planInfo['status'],
|
|
'adduser' => $userid,
|
|
];
|
|
if($planInfo['id']==0){//新增
|
|
//判断记录是否存在
|
|
$is_ex=DB::table('s_source_roster')->where([
|
|
'department_id' => $department_id,
|
|
'weekname' => $value,
|
|
'resources_id' => $planInfo['resources_id'],
|
|
'period_id' => $planInfo['period_id'], //时间段id
|
|
])->get();
|
|
if(count($is_ex)>0){
|
|
DB::rollBack();
|
|
return \Yz::echoError1($value.'已存在相同记录,id为:'.$is_ex[0]->id);
|
|
}
|
|
$roster_id=DB::table('s_source_roster')->insertGetId($data);
|
|
if ($roster_id) {
|
|
foreach ($planInfo['qudao_total'] as $k => $v) {
|
|
$i_c=DB::table('s_source_roster_count')->insert([
|
|
'roster_id' => $roster_id,
|
|
'appointment_type_id' => $v['id'],
|
|
'max_total' => $planInfo['max_total'],
|
|
'count' => $v['count'],
|
|
]);
|
|
if (!$i_c) {
|
|
DB::rollBack();
|
|
return \Yz::echoError1('保存失败');
|
|
}
|
|
}
|
|
} else {
|
|
DB::rollBack();
|
|
return \Yz::echoError1('保存失败');
|
|
}
|
|
}else{//修改
|
|
$data['id']=$planInfo['id'];
|
|
|
|
$i=DB::table('s_source_roster')->where(['id'=>$planInfo['id'],'is_del'=>0])->update($data);
|
|
|
|
foreach ($planInfo['qudao_total'] as $k => $v) {
|
|
$i_c=DB::table('s_source_roster_count')->where(['roster_id'=>$planInfo['id'],'appointment_type_id'=>$v['appointment_type_id']])->update([
|
|
'max_total' => $planInfo['max_total'],
|
|
'count' => $v['count'],
|
|
]);
|
|
|
|
}
|
|
if ($i or $i_c) { } else {
|
|
DB::rollBack();
|
|
return \Yz::echoError1('保存失败');
|
|
}
|
|
}
|
|
|
|
}
|
|
DB::commit();
|
|
return \Yz::Return(true, '保存成功', []);
|
|
}
|
|
//获取模板信息详情
|
|
public function GetDetailInfo()
|
|
{
|
|
$id = request('id');
|
|
$info = DB::table('s_source_roster')->where(['id' => $id])->first();
|
|
if (!!$info) {
|
|
$info->devices =array_map('intval',explode(',', $info->device_id)) ;
|
|
$info->patientType = explode(',', $info->patient_type);
|
|
$info->qudao_total = DB::table('s_source_roster_count')
|
|
->select('s_source_roster_count.*', 's_appointment_type.name')
|
|
->leftJoin('s_appointment_type', 's_source_roster_count.appointment_type_id', '=', 's_appointment_type.id')
|
|
->where(['roster_id' => $id])->get();
|
|
$ratio= DB::table('s_appointment_type_ratio')
|
|
->where(['department_id' => $info->department_id])->get();
|
|
foreach ($info->qudao_total as $key => $value) {
|
|
foreach ($ratio as $k => $v) {
|
|
if ($value->appointment_type_id == $v->appointment_type_id) {
|
|
$info->qudao_total[$key]->ratio = $v->ratio;
|
|
}
|
|
}
|
|
}
|
|
return \Yz::Return(true, '操作成功', $info);
|
|
}else{
|
|
return \Yz::echoError1('数据不存在');
|
|
}
|
|
|
|
}
|
|
//获取自己的预约类型比例
|
|
public function GetAppointmentRatio(Request $request)
|
|
{
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
if (!!$userInfo) {
|
|
$appointment_type = DB::table('s_appointment_type')->where(['status' => 1, 'is_del' => 0])->get();
|
|
$department_id = $userInfo->department_id;
|
|
$ratio = DB::table('s_appointment_type_ratio')
|
|
->where(['department_id' => $department_id])->get();
|
|
|
|
foreach ($appointment_type as $key => $value) {
|
|
$appointment_type[$key]->ratio = 0;
|
|
foreach ($ratio as $k => $v) {
|
|
if ($value->id == $v->appointment_type_id) {
|
|
$appointment_type[$key]->ratio = $v->ratio;
|
|
}
|
|
}
|
|
}
|
|
return \Yz::Return(true, '操作成功', $appointment_type);
|
|
}
|
|
}
|
|
//保存预约类型比例
|
|
public function SaveAppointmentRatio(Request $request)
|
|
{
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
if (!!$userInfo) {
|
|
$department_id = $userInfo->department_id;
|
|
$ratioInfo = request('ratioInfo');
|
|
$u = false;
|
|
DB::table('s_appointment_type_ratio')->where(['department_id' => $department_id])->delete();
|
|
|
|
foreach ($ratioInfo as $key => $value) {
|
|
$u=DB::table('s_appointment_type_ratio')->insert([
|
|
'department_id' => $department_id,
|
|
'appointment_type_id' => $value['id'],
|
|
'ratio' => $value['ratio'],
|
|
]);
|
|
}
|
|
if($u){
|
|
return \Yz::Return(true, '操作成功', []);
|
|
}else{
|
|
return \Yz::echoError1('保存失败,无数据更新');
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//删除计划模板
|
|
public function Del(Request $request)
|
|
{
|
|
$userid = $request->get('userid');//中间件产生的参数
|
|
$ids = request('ids');
|
|
$userInfo = DB::table('users')->where(['id' => $userid])->first();
|
|
if (!!$userInfo) {
|
|
$appointment_type = DB::table('s_appointment_type')->where(['status' => 1, 'is_del' => 0])->get();
|
|
$department_id = $userInfo->department_id;
|
|
$d= DB::table('s_source_roster')
|
|
->where(['department_id' => $department_id])->whereIn('id',$ids)->update([
|
|
'is_del'=>1,
|
|
]);
|
|
if($d){
|
|
return \Yz::Return(true, '操作成功', []);
|
|
}else{
|
|
return \Yz::echoError1('操作失败');
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|