<?php

namespace App\Http\Controllers\API\H5;

use App\Http\Controllers\API\PEISApiController;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class PersonController extends Controller
{
  public function group_info($hospital, $data)
  {
    $peis = new PEISApiController();
    $info = $peis::Post('团检登记查询', $hospital, $data);
    $group_list=[];
    foreach ($info['data'] as $it) {
      $items = [];
      $group_info = $it;
      if (isset($group_info['项目列表'])) {
        foreach ($group_info['项目列表'] as $datum) {
          $items[] = [
            'id' => $datum['Id'],
            'name' => $datum['名称'],
          ];
        }
      }
      $data=[
        'name' => $group_info['姓名'],
        'id_number' => $group_info['证件号码'],
        'combo_name' => $group_info['套餐名称'],
        'combo_id' => $group_info['套餐Id'],
        'start_time' => $group_info['预约开始日期'],
        'end_time' => $group_info['预约结束日期'],
        'group_name' => $group_info['单位名称'] . ($group_info['部门名称']),
        'group_id' => $group_info['预约Id'],
        'tongshou_xiane'=>$group_info['统收限额'],
        'sixi_zong_ji_jin_e'=>$group_info['总计金额'],
        'items' => $items,
      ];
      $group_list[]=$data;
    }

    return $group_list;
  }

  //团检登记查询，根据身份证和电话查分组id
  public function GetGroupUnit()
  {
    $phone = request('phone');
    $id_number = request('id_number');
    $hospital_id = request('hospital_id');
    if (!isset($phone)) return \Yz::echoError1('电话不能为空');
    if (!isset($id_number)) return \Yz::echoError1('身份证不能为空');
    if (!isset($hospital_id)) return \Yz::echoError1('医院id不能为空');
    $data = [
      '电话号码' => $phone,
      '证件号码' => $id_number
    ];
    $res = self::group_info($hospital_id, $data);
    return \Yz::Return(true,"查询完成",['unit'=>$res]);
  }
  //获取团检套餐
  public function GetGroupCombo()
  {
    $hospital_id = request('hospital_id');
    $group_id = request('group_id');
    if (!isset($group_id)) return \Yz::echoError1('group_id不能为空');
    $data = [
      '电话号码' => null,
      '证件号码' => null,
      '预约Id'=>$group_id
    ];
    $res = self::group_info($hospital_id, $data);
    return \Yz::Return(true,"查询完成",['unit'=>$res]);
  }
}
