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.

77 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers\API\Internal;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PlanController extends Controller
{
//给自助机用接口
//获取可用号源列表,
public function PlanList()
{
$hospital_id =request('hospital');
$date=request('date');
$is_vip=request('is_vip');
$checkup_type_id= request('checkup_type_id');//体检类型表对应id
if(!isset($checkup_type_id)) return \Yz::echoError1("体检类型不能为空");
$currentDateTime = now();
$list=DB::table('plans')
->where('date',$date)->whereIn('status',[1])
->whereRaw('CONCAT(date, " ", time) >?', [$currentDateTime])
->whereNull('bind_work_unit_id')
->where(function($query) use ($checkup_type_id) {
foreach ($checkup_type_id as $id) {
$query->orWhereRaw('JSON_CONTAINS(checkup_type_id, CAST(? AS JSON), "$")', [$id]);
}
})
->where(['hospital_id'=>$hospital_id,'type'=>1,'is_del'=>0])
->where('is_vip','=',$is_vip);
$list=$list->get();
return \Yz::Return(true,"查询完成",['list'=>$list]);
}
//给自助机用接口
//占用号源
public function UsePlan(){
$id =request('id');
$plan=DB::table('plans')->where('id',$id)->first();
if(!$plan) return \Yz::echoError1("该号源不存在");
if($plan->status<>1) return \Yz::echoError1("该号源已被占用,请重新选择");
$u=DB::table('plans')->where(['id'=>$id,'status'=>1,'is_del'=>0])->update(['status'=>2]);
if($u){
return \Yz::Return(true,'占用成功',['id'=>$id]);
}else{
return \Yz::echoError1("操作失败");
}
}
public function CancelUsePlan()
{
$id =request('id');
$plan=DB::table('plans')->where('id',$id)->first();
if(!$plan) return \Yz::echoError1("该号源不存在");
if($plan->status<>2) return \Yz::echoError1("该号源未被占用,无需撤销");
$order=DB::table('orders')->where(['plan_id'=>$id,'status'=>2])->whereNull('source')->first();
if($order){
if($order->type ==1){
return \Yz::echoError1("该预约来自小程序,请顾客在小程序操作,或到号源后台取消订单");
}
if($order->type ==2){
return \Yz::echoError1("该预约来自小程序,请到号源后台取消订单");
}
}
$u=DB::table('plans')->where(['id'=>$id])->update(['status'=>1]);
if($u){
return \Yz::Return(true,'撤销占用成功',['id'=>$id]);
}else{
return \Yz::echoError1("操作失败");
}
}
}