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.
367 lines
10 KiB
PHP
367 lines
10 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Appointment;
|
|
use App\Models\HospitalAdditional;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Login;
|
|
use Yo;
|
|
|
|
class ComboItemController extends Controller
|
|
{
|
|
public function group_info($hospital, $data)
|
|
{
|
|
$peis = new PEISApiController();
|
|
$info = $peis::Post('团检登记查询', $hospital, $data);
|
|
$items = [];
|
|
$group_info = $info['data'][0];
|
|
if (isset($group_info['项目列表'])) {
|
|
foreach ($group_info['项目列表'] as $datum) {
|
|
$items[] = [
|
|
'id' => $datum['Id'],
|
|
'name' => $datum['名称'],
|
|
];
|
|
}
|
|
}
|
|
return [
|
|
'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['部门名称']),
|
|
'items' => $items,
|
|
'appointment_number' => $group_info['预约Id']
|
|
];
|
|
}
|
|
|
|
public function combo($hospital, $data)
|
|
{
|
|
$peis = new PEISApiController();
|
|
$combo_list = $peis::Post('套餐查询', $hospital, $data)['data'];
|
|
$list = [];
|
|
foreach ($combo_list as $item) {
|
|
$list[] = [
|
|
'id' => $item['Id'],
|
|
'name' => $item['名称'],
|
|
'py' => $item['拼音'],
|
|
'price' => $item['价格'],
|
|
'original_price' => $item['原价'],
|
|
'sex' => $item['性别限制'],
|
|
'desc' => $item['简介'],
|
|
'count' => $item['简介'],
|
|
// 'original_info' => $item
|
|
];
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
public function combo_info($hospital, $data)
|
|
{
|
|
$peis = new PEISApiController();
|
|
$combo_info = $peis::Post('套餐详情查询', $hospital, $data)['data'][0];
|
|
$info = [
|
|
'id' => $combo_info['Id'],
|
|
'name' => $combo_info['名称'],
|
|
'price' => $combo_info['价格'],
|
|
'original_price' => $combo_info['原价'],
|
|
'sex' => $combo_info['性别限制'],
|
|
'items' => [],
|
|
];
|
|
foreach ($combo_info['包含项目'] as $item) {
|
|
$info['items'][] = [
|
|
'id' => $item['Id'],
|
|
'name' => $item['名称'],
|
|
'price' => $item['价格'],
|
|
'discount_type' => $item['优惠方式'],
|
|
'discount_value' => $item['优惠值'],
|
|
];
|
|
}
|
|
$info['count'] = count($info['items']);
|
|
return $info;
|
|
}
|
|
|
|
public function items($hospital, $data)
|
|
{
|
|
$peis = new PEISApiController();
|
|
$items = $peis::Post('自选项目查询', $hospital, $data)['data'];
|
|
$list = [];
|
|
foreach ($items as $item) {
|
|
$list[] = [
|
|
'id' => $item['Id'],
|
|
'name' => $item['名称'],
|
|
'py' => $item['拼音'],
|
|
'price' => $item['价格'],
|
|
'sex' => $item['性别限制'],
|
|
'clinic' => $item['科室Id'],
|
|
'clinic_name' => $item['科室名称'],
|
|
'choose' => $item['可选'],
|
|
];
|
|
}
|
|
return $list;
|
|
}
|
|
|
|
//获取思信所有检查项目
|
|
public function GetSiXinItems(Request $request)
|
|
{
|
|
$hospital = $request->post('hospital');
|
|
$data = [
|
|
'价格下限' => "0",
|
|
'价格上限' => "999999",
|
|
"性别" => null,
|
|
"妇检" => null,
|
|
"套餐Id" => null,
|
|
"项目Id列表" => []
|
|
];
|
|
$peis = new PEISApiController();
|
|
$items = $peis::Post('自选项目查询', $hospital, $data)['data'];
|
|
$list = [];
|
|
foreach ($items as $item) {
|
|
if($item['可选']==true)
|
|
$list[]=$item;
|
|
}
|
|
return Yo::echo([
|
|
'list' => $list
|
|
]);
|
|
}
|
|
//获取思信项目绑定的检查项目
|
|
public function GetSiXinItemsLinks(Request $request)
|
|
{
|
|
$hospital = $request->post('hospital');
|
|
$itemId= $request->post('items');
|
|
$cha=DB::table('item_links')->where('hospital',$hospital)->where('item_id',$itemId)->first();
|
|
return Yo::echo([
|
|
'info'=>$cha
|
|
]);
|
|
}
|
|
//绑定思信项目和检查项目
|
|
public function BindSiXinItemsLinks(Request $request)
|
|
{
|
|
$hospital = $request->post('hospital');
|
|
$itemId= $request->post('items');
|
|
$linkIds= $request->post('linkIds');
|
|
$cha=DB::table('item_links')->where('hospital',$hospital)->where('item_id',$itemId)->first();
|
|
if($cha){
|
|
$cha=DB::table('item_links')->where('id',$cha->id)->update([
|
|
'link_ids'=>$linkIds
|
|
]);
|
|
}else{
|
|
$cha=DB::table('item_links')->insert([
|
|
'hospital'=>$hospital,
|
|
'item_id'=>$itemId,
|
|
'link_ids'=>$linkIds
|
|
]);
|
|
}
|
|
return Yo::echo([
|
|
'info'=>$cha
|
|
]);
|
|
}
|
|
|
|
public function mp_items_list(Request $request)
|
|
{
|
|
Login::user();
|
|
$hospital = $request->post('hospital');
|
|
$combo = $request->post('combo');
|
|
$list = self::items($hospital, [
|
|
'价格下限' => "0",
|
|
'价格上限' => "999999",
|
|
"性别" => null,
|
|
"妇检" => null,
|
|
"套餐Id" => $combo ? (string)$combo : null,
|
|
"项目Id列表" => []
|
|
]);
|
|
$list_map = [];
|
|
foreach ($list as $item) {
|
|
if (!!$item['choose']) {
|
|
if (!isset($list_map['g' . $item['clinic']])) {
|
|
$list_map['g' . $item['clinic']] = [
|
|
'id' => $item['clinic'],
|
|
'name' => $item['clinic_name'],
|
|
'items' => []
|
|
];
|
|
}
|
|
$list_map['g' . $item['clinic']]['items'][] = [
|
|
'id' => $item['id'],
|
|
'name' => $item['name'],
|
|
'py' => $item['py'],
|
|
'price' => $item['price'],
|
|
'sex' => $item['sex'],
|
|
];
|
|
}
|
|
}
|
|
$l = [];
|
|
foreach ($list_map as $item) {
|
|
$l[] = $item;
|
|
}
|
|
return Yo::echo([
|
|
'list' => $l
|
|
]);
|
|
}
|
|
|
|
public function combo_list(Request $request)
|
|
{
|
|
Login::admin([], [17, 24]);
|
|
$hospital = $request->post('hospital');
|
|
$list = self::combo($hospital, [
|
|
'价格下限' => "0",
|
|
'价格上限' => "999999",
|
|
'性别' => null,
|
|
'妇检' => false
|
|
]);
|
|
return Yo::echo([
|
|
'list' => $list
|
|
]);
|
|
}
|
|
|
|
public function mp_buy_info(Request $request)
|
|
{
|
|
Login::user();
|
|
$hospital = $request->post('hospital');
|
|
$combo = $request->post('combo');
|
|
$count = 0;
|
|
$price = 0;
|
|
$original_price = 0;
|
|
$combo_info = false;
|
|
$combo_items_ids = [];//套餐内项目id
|
|
if (!!$combo) {
|
|
$combo_info = self::combo_info($hospital, [
|
|
'套餐Id' => $combo,
|
|
]);
|
|
$count += $combo_info['count'];
|
|
$price += $combo_info['price'];
|
|
if ($combo_info['original_price'] > $combo_info['price']) {
|
|
$original_price += $combo_info['original_price'];
|
|
} else {
|
|
$original_price += $combo_info['price'];
|
|
}
|
|
foreach ($combo_info['items'] as $item) {
|
|
$combo_items_ids[] = $item['id'];
|
|
}
|
|
}
|
|
$items = $request->post('items');
|
|
|
|
|
|
//查询勾选的项目,判断是否有关联项目
|
|
$cha=DB::table('item_links')->where('hospital',$hospital)->whereIn('item_id',$items)->get();
|
|
foreach ($cha as $link) {
|
|
// 将逗号分隔的字符串转换为数组
|
|
$linkIdsArray = explode(',', $link->link_ids);
|
|
// 合并数组到 $items 中
|
|
$items = array_merge($items, $linkIdsArray);
|
|
}
|
|
// 去除重复的元素
|
|
$items = array_values(array_unique($items));
|
|
// 判断自选数组中的某项是否在套餐数组中
|
|
$intersection = array_intersect($items, $combo_items_ids);
|
|
|
|
// 移除自选数组中在套餐数组中存在的项
|
|
$items =array_values(array_diff($items, $intersection));
|
|
|
|
|
|
$items_list = [];
|
|
if (count($items) != 0) {
|
|
$items_list = self::items($hospital, [
|
|
'价格下限' => "0",
|
|
'价格上限' => "999999",
|
|
"性别" => null,
|
|
"妇检" => null,
|
|
"套餐Id" => null,
|
|
"项目Id列表" => $items
|
|
]);
|
|
}
|
|
$item_list_ret = [];
|
|
foreach ($items_list as $item) {
|
|
$count++;
|
|
$price += $item['price'];
|
|
$original_price += $item['price'];
|
|
$item_list_ret[] = [
|
|
'id' => $item['id'],
|
|
'name' => $item['name'],
|
|
'price' => $item['price']
|
|
];
|
|
}
|
|
$time = $request->post('time');
|
|
$time_info = Appointment::where('id', $time['id'])->where('status', 1)->where('del', 2)->first();
|
|
if (!!$time_info) {
|
|
if ($time_info->max_count <= $time_info->used_count) {
|
|
$time_info = false;
|
|
}
|
|
}
|
|
if (!!$time_info) {
|
|
$show = date('Y-m-d H:i', strtotime($time_info->date . ' ' . $time_info->start_time)) . ' - ' . date('H:i', strtotime($time_info->date . ' ' . $time_info->end_time));
|
|
$time_info = [
|
|
'id' => $time_info->id,
|
|
'date' => $time_info->date,
|
|
'show' => $show,
|
|
];
|
|
}
|
|
$group = $request->post('group');
|
|
$group_info = false;
|
|
if (!!$group) {
|
|
$group_info = self::group_info($hospital, [
|
|
"电话号码" => null,
|
|
"证件号码" => null,
|
|
"预约Id" => $group
|
|
]);
|
|
$count += count($group_info['items']);
|
|
}
|
|
return Yo::echo([
|
|
'links'=>$cha,
|
|
'price' => $price,
|
|
'original_price' => $original_price,
|
|
'group' => $group_info,
|
|
'count' => $count,
|
|
'combo' => $combo_info,
|
|
'items' => $item_list_ret,
|
|
'time' => !!$time_info ? $time_info : [
|
|
'id' => 0,
|
|
'date' => date('Y-m-d'),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function mp_combo_list(Request $request)
|
|
{
|
|
Login::user();
|
|
$hospital = $request->post('hospital');
|
|
$list = self::combo($hospital, [
|
|
'价格下限' => "0",
|
|
'价格上限' => "999999",
|
|
'性别' => null,
|
|
'妇检' => false
|
|
]);
|
|
$list_map = [];
|
|
foreach ($list as $item) {
|
|
$item['count'] = 0;
|
|
$list_map['i' . $item['id']] = $item;
|
|
}
|
|
$hospital_additional = HospitalAdditional::where('hospital', $hospital)->first();
|
|
$self_count = [];
|
|
if (!!$hospital_additional) $self_count = json_decode($hospital_additional->combo_count, true);
|
|
$public_additional = HospitalAdditional::where('hospital', 0)->first();
|
|
$public_count = [];
|
|
if (!!$public_additional) $public_count = json_decode($public_additional->combo_count, true);
|
|
foreach ($public_count as $item) {
|
|
if (isset($list_map['i' . $item['id']])) {
|
|
$list_map['i' . $item['id']]['count'] = $item['count'];
|
|
}
|
|
|
|
}
|
|
foreach ($self_count as $item) {
|
|
if (isset($list_map['i' . $item['id']])) {
|
|
$list_map['i' . $item['id']]['count'] = $item['count'];
|
|
}
|
|
}
|
|
$l = [];
|
|
foreach ($list_map as $item) {
|
|
$l[] = $item;
|
|
}
|
|
return Yo::echo([
|
|
'list' => $l
|
|
]);
|
|
}
|
|
}
|