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.
134 lines
4.6 KiB
PHP
134 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API\Admin\YeWu;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\TimeService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class PlanModelController extends Controller
|
|
{
|
|
public function timeList()
|
|
{
|
|
$TimeRange = request('TimeRange');
|
|
if(count($TimeRange)<>2) return \Yz::echoError1('起止时间格式错误');
|
|
$interval_time = request('interval_time');
|
|
$s=new TimeService();
|
|
$list=$s->TimePointsArr($TimeRange[0],$TimeRange[1],$interval_time);
|
|
return \Yz::Return(true,"查询完成",['list' =>$list]);
|
|
}
|
|
public function GetList()
|
|
{
|
|
$page =request('page');
|
|
$pageSize =request('pageSize');
|
|
$searchInfo=request('searchInfo');
|
|
$list=DB::table('plan_model as a')
|
|
->leftJoin('plan_type as b','a.plan_type','=','b.id')
|
|
->select('a.*','b.name as plan_type_name')
|
|
->where(['a.is_del'=>0]);
|
|
if(isset($searchInfo['name'])){
|
|
$list = $list->where('a.name', 'like','%'.$searchInfo['name'].'%');
|
|
}
|
|
if(isset($searchInfo['status'])){
|
|
$list = $list->where('a.status',$searchInfo['status']);
|
|
}
|
|
$count=$list->count();
|
|
if(isset($page) and isset($pageSize)){
|
|
$list=$list->orderBy('a.id', 'desc')->limit($pageSize)->skip(($page - 1) * $pageSize)->take($pageSize);
|
|
}
|
|
$list=$list ->get();
|
|
foreach ($list as $l){
|
|
$l->y_number=json_decode($l->y_number,true);
|
|
}
|
|
return \Yz::Return(true,'查询完成',['list'=>$list,'count'=>$count]);
|
|
}
|
|
public function Save()
|
|
{
|
|
$Info =request('Info');
|
|
$Timelist =request('Timelist');
|
|
|
|
$params = [
|
|
'hospital_id' => isset($Info['hospital_id']) ? $Info['hospital_id'] :null,
|
|
'name' => isset($Info['name']) ? $Info['name'] : null,
|
|
'interval_time' => isset($Info['interval_time']) ? $Info['interval_time'] : null,
|
|
'plan_type' => isset($Info['plan_type']) ? $Info['plan_type'] : null,
|
|
'y_number' => isset($Info['y_number']) ? json_encode($Info['y_number']) : [],
|
|
'count' => isset($Info['count']) ? $Info['count'] : 0,
|
|
'status'=>isset($Info['status']) ? $Info['status'] : 0,
|
|
];
|
|
$requiredFields = ['hospital_id'=>'医院','name'=>'名称','interval_time'=>'时间间隔'];
|
|
// 判断是否为空
|
|
foreach ($requiredFields as $key=> $field) {
|
|
if (!isset($params[$key]) || $params[$key] === null) {
|
|
return \Yz::echoError1('参数 ' . $field . ' 不能为空');
|
|
}
|
|
}
|
|
if(!isset($Info['TimeRange']) or count($Info['TimeRange'])<>2){
|
|
return \Yz::echoError1('起止时间格式错误');
|
|
}
|
|
$params['start_time']=$Info['TimeRange'][0];
|
|
$params['end_time']=$Info['TimeRange'][1];
|
|
$do=false;
|
|
$table=DB::table('plan_model');
|
|
$table_model_time=DB::table('plan_model_time');
|
|
DB::beginTransaction();
|
|
if($Info['id']==0){
|
|
$model_id=$table->insertGetId($params);
|
|
}
|
|
if($Info['id']>0){
|
|
$model_id=$Info['id'];
|
|
$table->where(['id'=>$Info['id']])->update($params);
|
|
}
|
|
$model_time_data=[];
|
|
foreach ($Timelist as $key=>$value){
|
|
$model_time_data[]=[
|
|
'type'=>isset($value['plan_type_id']) ? 1 : 0,
|
|
'model_id'=>$model_id,
|
|
'time'=>$value['time'],
|
|
'type_color'=>isset($value['type_color']) ? $value['type_color'] : null,
|
|
'plan_type_id'=>isset($value['plan_type_id']) ? $value['plan_type_id'] : null,
|
|
];
|
|
}
|
|
if(count($model_time_data)>0){
|
|
DB::table('plan_model_time')->where(['model_id'=>$model_id])->delete();
|
|
$do=$table_model_time->insert($model_time_data);
|
|
}
|
|
if($do){
|
|
DB::commit();
|
|
return \Yz::Return(true,'操作成功',[]);
|
|
}else{
|
|
DB::rollBack();
|
|
return \Yz::echoError1('操作失败');
|
|
}
|
|
|
|
}
|
|
public function GetDetail()
|
|
{
|
|
$id =request('id');
|
|
$info=DB::table('plan_model')->where(['id'=>$id,'is_del'=>0])->first();
|
|
if(!!$info){
|
|
$info->TimeRange=[$info->start_time,$info->end_time];
|
|
$info->y_number=json_decode($info->y_number,true);
|
|
$list=DB::table('plan_model_time as a')->where(['model_id'=>$id])->get();
|
|
$info->list=$list;
|
|
return \Yz::Return(true,'查询完成',$info);
|
|
}else{
|
|
return \Yz::echoError1('查询失败');
|
|
}
|
|
}
|
|
public function Del()
|
|
{
|
|
$id =request('id');
|
|
$d=DB::table('plan_model')->where(['id'=>$id])->update([
|
|
'is_del'=>1
|
|
]);
|
|
if($d){
|
|
return \Yz::Return(true,'操作完成',[]);
|
|
}else{
|
|
return \Yz::echoError1('操作失败');
|
|
}
|
|
}
|
|
|
|
}
|