|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\API\H5;
|
|
|
|
|
|
use App\Http\Controllers\API\AspNetZhuanController;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Http\Controllers\API\PEISApiController;
|
|
|
use App\Lib\Tools;
|
|
|
use App\Services\ConfigService;
|
|
|
use App\Services\OrderService;
|
|
|
use DateTime;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
{
|
|
|
public function list(Request $request)
|
|
|
{
|
|
|
// status 1-待支付 2-已预约 3-交易关闭 4-已完成 5-已退款
|
|
|
$openid = $request->post('openid');
|
|
|
$user = DB::table('web_users')->where(['openid' => $openid, 'is_del' => 0])->first();
|
|
|
if (!$user) return \Yz::echoError1("openid对应用户不存在");
|
|
|
$persons_sfz = DB::table('web_user_person')->where(['user_id' => $user->id, 'is_del' => 0])->pluck('id_number')->toArray();
|
|
|
|
|
|
$OrderList = DB::table('orders')
|
|
|
->select('id', 'title', 'status', 'name','appointment_date as date', 'appointment_time as time', 'order_number as order','appointment_number',
|
|
|
DB::raw("CASE WHEN type = 1 THEN '个检' WHEN type = 2 THEN '团检' ELSE 'unknown' END as type"),
|
|
|
'price', 'true_price', 'pay_time', 'refund_time', 'created_at')
|
|
|
->where(['web_user_id' => $user->id])
|
|
|
->orWhere(function ($query) use ($persons_sfz) {
|
|
|
$query->WhereIn('id_number', $persons_sfz)
|
|
|
->where('person_id', 0);
|
|
|
})->orderBy('id', 'desc')->get();
|
|
|
$WaitingPaymentTime = config('app.globals.WaitingPaymentTime');//支付等待時間
|
|
|
foreach ($OrderList as $key => $list) {
|
|
|
if ($list->status == 1) {
|
|
|
$datetime = new DateTime($list->created_at);
|
|
|
$timestamp = $datetime->getTimestamp();
|
|
|
$list->end_time = $timestamp + (60 * $WaitingPaymentTime);
|
|
|
if (time() > $list->end_time) {
|
|
|
$list->status = 3;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return \Yz::Return(true, '获取成功', [
|
|
|
'list' => $OrderList
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
public function GetDetail()
|
|
|
{
|
|
|
$id = request('id');
|
|
|
$order_info = DB::table('orders')->where(['id' => $id])->first();
|
|
|
if (!!$order_info) {
|
|
|
$order_info->buy_info = json_decode($order_info->buy_info, true);
|
|
|
$order_info->erxian_appointment_info = json_decode($order_info->erxian_appointment_info, true);
|
|
|
} else {
|
|
|
return \Yz::echoError1('未找到有效订单');
|
|
|
}
|
|
|
return \Yz::Return(true, '获取成功', [
|
|
|
'info' => $order_info
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
//创建订单
|
|
|
public function Create()
|
|
|
{
|
|
|
$hospital_id = request('hospital');
|
|
|
$openid = request('openid');
|
|
|
$person_id = request('person_id');
|
|
|
$combo_id = request('combo_id');
|
|
|
$type = request('type');//1个检2团检
|
|
|
$group_id = request('group_id');//团检id
|
|
|
$item_ids = request('item_ids');//自选item的ids
|
|
|
|
|
|
if (count($item_ids) != 0 and $item_ids[0] == "") {
|
|
|
$item_ids = [];
|
|
|
}
|
|
|
|
|
|
$duo_xuan_yi = request('duo_xuan_yi'); //多选1
|
|
|
$plan_id = request('plan_id');//号源id
|
|
|
$plan_nmr_info = request('plan_nmr_info');//核磁号源信息
|
|
|
$doctor = request('doctor');//预约的医生名字
|
|
|
$coupon_id = request('coupon_id');//优惠券
|
|
|
$jifen = request('jifen', 0); //使用的积分数量
|
|
|
$yucunkuan = request('yucunkuan', 0);//使用的预存款数量
|
|
|
$erxian_info= request('erxian_info');//使用的预存款数量
|
|
|
|
|
|
|
|
|
|
|
|
$wj_flag = request('wj'); //问卷标记
|
|
|
if (isset($wj_flag) and $wj_flag == 1) {
|
|
|
$wj_zhekou = config('app.globals.Wj_ZheKou');//问卷过来的折扣率
|
|
|
}
|
|
|
|
|
|
if (!isset($hospital_id)) return \Yz::echoError1('医院id不能为空');
|
|
|
if ($hospital_id == 1) {
|
|
|
$yyid = 6;
|
|
|
}
|
|
|
if ($hospital_id == 4) {
|
|
|
$yyid = 2;
|
|
|
}
|
|
|
if (!isset($openid)) return \Yz::echoError1('openid不能为空');
|
|
|
if (!isset($person_id)) return \Yz::echoError1('person_id不能为空');
|
|
|
if (!isset($type)) return \Yz::echoError1('type体检类型不能为空');
|
|
|
if ($type != 1 && $type != 2) {
|
|
|
return \Yz::echoError1('type参数,体检类型错误');
|
|
|
}
|
|
|
if (!isset($plan_id)) return \Yz::echoError1('号源id不能为空');
|
|
|
if ($type == 2 and !isset($group_id)) return \Yz::echoError1('团检,group_id不能为空');
|
|
|
if ($type == 1 and isset($group_id)) return \Yz::echoError1('体检类型:个检 与group_id冲突');
|
|
|
|
|
|
$user = DB::table('web_users')->where(['openid' => $openid, 'status' => 1, 'is_del' => 0])->first();
|
|
|
if (!$user) return \Yz::echoError1('用户不存在');
|
|
|
$person = DB::table('web_user_person')->where(['id' => $person_id, 'is_del' => 0])->first();
|
|
|
if (!$person) return \Yz::echoError1('体检人不存在');
|
|
|
$title = "自选项目";
|
|
|
$price = 0;
|
|
|
$quanInfo=false;
|
|
|
$true_price = 0;//订单真实支付金额
|
|
|
$buy_info = [
|
|
|
'combo' => [
|
|
|
'id' => 0,
|
|
|
'name' => $title,
|
|
|
'price' => 0,
|
|
|
],
|
|
|
'items' => [],
|
|
|
'group' => [
|
|
|
'id' => '',
|
|
|
],
|
|
|
'nmr_list' => []
|
|
|
];
|
|
|
//如果是套餐
|
|
|
$Nx1_arrInfo = [];
|
|
|
$TJ_Leixing_id = 1;//存储用体检类型
|
|
|
$checkup_type_id = false; //体检类型id
|
|
|
if (isset($combo_id) and $combo_id <> 0) {
|
|
|
$combo_info = DB::table('combos')->where(['combo_id' => $combo_id, 'status' => 1])->first();
|
|
|
if (!$combo_info) return \Yz::echoError1("套餐不存在");
|
|
|
if (!isset($combo_info->checkup_type_id)) return \Yz::echoError1("套餐未关联体检类型");
|
|
|
$checkup_type_id = $combo_info->checkup_type_id;
|
|
|
|
|
|
//构建多选一数据
|
|
|
if (isset($duo_xuan_yi) and !empty($duo_xuan_yi)) {
|
|
|
$combo_Nx1 = json_decode($combo_info->duo_xuan_yi, true);
|
|
|
foreach ($duo_xuan_yi as $r_k => $r_v) {
|
|
|
foreach ($combo_Nx1 as $k => $n1v) {
|
|
|
if ($r_v['zu_name'] == $n1v['组名称']) {
|
|
|
foreach ($n1v['包含项目'] as $k2 => $v2) {
|
|
|
if ($v2['Id'] == $r_v['item_id']) {
|
|
|
if ($v2['科室名称'] == '影像科') {
|
|
|
$buy_info['nmr_list'][] = [
|
|
|
'item_id' => $v2['Id'],
|
|
|
'name' => $v2['名称'],
|
|
|
];
|
|
|
}
|
|
|
$Nx1_arrInfo[] = [
|
|
|
'id' => $v2['Id'],
|
|
|
'name' => $v2['名称'],
|
|
|
'price' => 0
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$TJ_Leixing_id = $checkup_type_id;
|
|
|
$price += $combo_info->price;
|
|
|
$title = $combo_info->name;
|
|
|
$buy_info['combo'] = [
|
|
|
'id' => $combo_info->combo_id,
|
|
|
'name' => $combo_info->name,
|
|
|
'price' => $combo_info->price,
|
|
|
];
|
|
|
//如果有影像科,则存储在nmr_list字段
|
|
|
$comboItem = DB::table('combo_items')->where(['combo_id' => $combo_id, 'status' => 1, 'keshi_name' => '影像科'])->get();
|
|
|
if (count($comboItem) > 0) {
|
|
|
foreach ($comboItem as $item) {
|
|
|
$buy_info['nmr_list'][] = [
|
|
|
'item_id' => $item->item_id,
|
|
|
'name' => $item->name,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//如果有自选项目
|
|
|
$items_list = [];
|
|
|
if (count($item_ids) != 0) {
|
|
|
$items_list = DB::table('items')->whereIn('item_id', $item_ids)->where(['status' => 1])->get();
|
|
|
$existingIds = [];
|
|
|
$item_price = 0;
|
|
|
foreach ($items_list as $item) {
|
|
|
$item_price += $item->price;
|
|
|
$existingIds[] = $item->item_id;
|
|
|
$buy_info['items'][] = [
|
|
|
'id' => $item->item_id,
|
|
|
'name' => $item->name,
|
|
|
'price' => $item->price
|
|
|
];
|
|
|
//如果有影像科,则存储在nmr_list字段
|
|
|
if ($item->keshi_name == '影像科') {
|
|
|
$buy_info['nmr_list'][] = [
|
|
|
'item_id' => $item->item_id,
|
|
|
'name' => $item->name,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
if (isset($wj_flag) and $wj_flag == 1) {
|
|
|
$item_price = $item_price * $wj_zhekou;
|
|
|
}
|
|
|
|
|
|
|
|
|
$price += $item_price;
|
|
|
$missingIds = array_diff($item_ids, $existingIds);
|
|
|
if (count($missingIds) > 0) return \Yz::echoError1("部分自选项目不可用,Id:" . implode(', ', $missingIds));
|
|
|
}
|
|
|
//如果有 多选一项目
|
|
|
if (!empty($Nx1_arrInfo)) {
|
|
|
$buy_info['items'] = array_merge($buy_info['items'], $Nx1_arrInfo);
|
|
|
}
|
|
|
$true_price = $price;
|
|
|
|
|
|
//如果是团检
|
|
|
$group_info = false;
|
|
|
if ($type == 2) {
|
|
|
$P = new PersonController();
|
|
|
$data = [
|
|
|
'电话号码' => null,
|
|
|
'证件号码' => null,
|
|
|
'预约Id' => $group_id
|
|
|
];
|
|
|
$group_info = $P->group_info($hospital_id, $data);
|
|
|
$group_info = $group_info[0];
|
|
|
|
|
|
//如果有多选一项目
|
|
|
//构建多选一数据
|
|
|
$Nx1_arrInfo=[];
|
|
|
if(isset($duo_xuan_yi) and !empty($duo_xuan_yi)){
|
|
|
foreach ($duo_xuan_yi as $r_k=>$r_v){
|
|
|
$Nx1_arrInfo[]=[
|
|
|
'id' => $r_v['item_id'],
|
|
|
'name' => $r_v['item_name'],
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
$group_info['items'] =array_merge($group_info['items'],$Nx1_arrInfo); //合并多选一
|
|
|
|
|
|
$buy_info['group'] = [
|
|
|
'id' => $group_id,
|
|
|
'combo_name' => $group_info['combo_name'],
|
|
|
'combo_id' => $group_info['combo_id'],
|
|
|
'group_name' => $group_info['group_name'],
|
|
|
'items' => $group_info['items'],
|
|
|
'group_id' => $group_info['group_id'],
|
|
|
];
|
|
|
$TJ_Leixing_id = $group_info['checkup_type_id'];
|
|
|
$title = "单位团检" . $group_info['combo_name'];
|
|
|
$price = $price + $group_info['sixi_zong_ji_jin_e'];
|
|
|
$need_pay = ($price - $group_info['tongshou_xiane']) > 0 ? $price - $group_info['tongshou_xiane'] : 0;
|
|
|
//团检订单金额为减去统收后的金的
|
|
|
$price = $need_pay;
|
|
|
$true_price = $need_pay;
|
|
|
|
|
|
|
|
|
//如果有影像科,则存储在nmr_list字段
|
|
|
$all_items = DB::table('items')->where(['status' => 1, 'keshi_name' => '影像科'])->get();
|
|
|
foreach ($group_info['items'] as $item) {
|
|
|
foreach ($all_items as $it) {
|
|
|
if ($it->item_id == $item['id']) {
|
|
|
$buy_info['nmr_list'][] = [
|
|
|
'item_id' => $it->item_id,
|
|
|
'name' => $it->name,
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//调用思信接口判断各个项目是否可用
|
|
|
$check_items = [];
|
|
|
foreach ($item_ids as $item_id) {
|
|
|
$check_items[] = ['Id' => $item_id];
|
|
|
}
|
|
|
if ((isset($combo_id) and $combo_id <> 0) || count($check_items) != 0) {
|
|
|
$item_check = self::item_check($hospital_id, [
|
|
|
'人员信息列表' => [[
|
|
|
"序号" => 0,
|
|
|
"性别" => $person->sex == 1 ? '男' : '女',
|
|
|
"年龄" => floor((time() - strtotime($person->birthday)) / 86400 / 360),
|
|
|
"婚姻状态" => $person->married == 1 ? '已婚' : '未婚',
|
|
|
]],
|
|
|
'套餐Id' => $combo_id == 0 ? null : $combo_id,
|
|
|
'可选项目信息' => $check_items,
|
|
|
]);
|
|
|
if (count($item_check['data']) != 1) {
|
|
|
return \Yz::echoError1("体检系统提示:" . $item_check['message']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//检查号源是否可用
|
|
|
$plan = new PlanController();
|
|
|
$plan_check = $plan->CheckPlan($plan_id, $hospital_id, $type, $person->sex, $price, $checkup_type_id);
|
|
|
if ($plan_check['status'] === false) return \Yz::echoError1($plan_check['msg']);
|
|
|
$plan = $plan_check['plan'];
|
|
|
|
|
|
|
|
|
|
|
|
//如果是团检 判断号源在 团检登记人的有效时间范围内
|
|
|
$plan_datetime = $plan->date . ' ' . $plan->time;
|
|
|
if (!!$group_info) {
|
|
|
if (!($plan_datetime > $group_info['start_time'] . ' 00:00:00' and $plan_datetime < $group_info['end_time'] . ' 23:59:59')) {
|
|
|
return \Yz::echoError1("预约日期不在单位有效时间范围内,请重新选择");
|
|
|
}
|
|
|
}
|
|
|
$plan_nmr_appointment_info=[];
|
|
|
//校验积分和预存款
|
|
|
$env = config('app.globals.Env');
|
|
|
$AspNet = new AspNetZhuanController();
|
|
|
if ($env == 'pro') { //如果是正式环境, 测试环境不抵扣
|
|
|
if ($jifen > 0) {
|
|
|
$all_jifen = $AspNet::GetJiFen_YuCunKuan(1, $person->ghzid);
|
|
|
if ($jifen > $all_jifen) return \Yz::echoError1("用户剩余积分不足");
|
|
|
}
|
|
|
if ($yucunkuan > 0) {
|
|
|
// return \Yz::echoError1("暂不支持预存款");
|
|
|
$all_yucunkuan = $AspNet::GetJiFen_YuCunKuan(2, $person->ghzid);
|
|
|
if ($yucunkuan > $all_yucunkuan) return \Yz::echoError1("用户剩余预存款不足");
|
|
|
}
|
|
|
$true_price = $true_price - ($jifen + $yucunkuan);
|
|
|
if ($true_price < -1) return \Yz::echoError1("预抵扣金额超过订单金额,操作失败");
|
|
|
if ($true_price < 0) $true_price = 0;
|
|
|
//如果有二线号源,根据体检时间查询二线可用号源,区分上下午
|
|
|
$plan_nmr_info=[];
|
|
|
if (isset($erxian_info) and !empty($erxian_info)) {
|
|
|
foreach ($erxian_info as $erxian_item) {
|
|
|
$nmrPlans=$AspNet::ErXian(['yyid'=>6,'data'=>[$plan->date],'action'=>"1"],uniqid());
|
|
|
if($plan->time<="12:00") $end_time="12:00";
|
|
|
if($plan->time>"12:00") $end_time="23:59";
|
|
|
if(!isset($nmrPlans[$plan->date]) or empty($nmrPlans[$plan->date])) return \Yz::echoError1("二线号源不可用,请重新选则日期");
|
|
|
$temp_date=[];
|
|
|
foreach ($nmrPlans[$plan->date] as $nmp_p){
|
|
|
if($nmp_p['Time']>=substr($plan->time,0,5) and $nmp_p['Time']<=$end_time and $nmp_p['keyong']==="0"){
|
|
|
$temp_date=[
|
|
|
"item_id"=>$erxian_item['item_id'],
|
|
|
"name"=>$erxian_item['name'],
|
|
|
"price"=>$erxian_item['price'],
|
|
|
"time"=>$plan->date." ".$nmp_p['Time'],
|
|
|
];
|
|
|
$plan_nmr_info[]=$temp_date;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(empty($temp_date)) return \Yz::echoError1("二线号源不可用,请重新选则日期");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//校验二线号源
|
|
|
if (isset($plan_nmr_info) and !empty($plan_nmr_info)) {
|
|
|
$plan_nmr_temp = [];
|
|
|
foreach ($plan_nmr_info as $key => $plan_nmr) {
|
|
|
if ($plan_nmr['item_id'] <> -1) {
|
|
|
$dt= explode(" ", $plan_nmr['time']);
|
|
|
$p_nmr_data = [
|
|
|
'item_id' => $plan_nmr['item_id'],
|
|
|
'name' => $plan_nmr['name'],
|
|
|
'date' => $dt[0],
|
|
|
'time' => $dt[1],
|
|
|
'price' => $plan_nmr['price'],
|
|
|
];
|
|
|
//调用接口校验号源是否可用
|
|
|
$erxian_status = $AspNet::ErXian(['YYRQ' => $p_nmr_data['date'], 'YYSJ' => $p_nmr_data['time'], 'yyid' => $yyid, 'action' => 4], uniqid());
|
|
|
if ($erxian_status !== true) return \Yz::echoError1($p_nmr_data['name'] . '号源不可用,请重新选择');
|
|
|
$plan_nmr_temp[] = $p_nmr_data;
|
|
|
}
|
|
|
}
|
|
|
$plan_nmr_appointment_info=$plan_nmr_temp;
|
|
|
}
|
|
|
}
|
|
|
//使用优惠券
|
|
|
if (isset($coupon_id) and !empty($coupon_id)) {
|
|
|
if($true_price==0) return \Yz::echoError1("金额为0,无需使用优惠券");
|
|
|
$use_quan=$this->useYouHuiQuan($true_price,$person,$coupon_id);
|
|
|
$quanInfo=$use_quan['quanInfo'];
|
|
|
$true_price=$use_quan['price'];
|
|
|
}
|
|
|
$now_datetime = date('Y-m-d H:i:s');
|
|
|
//构建订单号
|
|
|
$order_num = $this->generateOrderNumber();
|
|
|
|
|
|
$data = [
|
|
|
'title' => $title,
|
|
|
'type' => $type,
|
|
|
'web_user_id' => $user->id,
|
|
|
'checkup_type_id' => $TJ_Leixing_id,
|
|
|
'person_id' => $person->id,
|
|
|
'name' => $person->name,
|
|
|
'id_number' => $person->id_number,
|
|
|
'buy_info' => json_encode($buy_info, JSON_UNESCAPED_UNICODE),
|
|
|
'price' => $price,
|
|
|
'true_price' => number_format($true_price, 2, '.', ''),
|
|
|
'jifen' => $jifen,
|
|
|
'yucunkuan' => $yucunkuan,
|
|
|
'order_number' => $order_num,
|
|
|
'status' => 99, //先标记为异常,方法最底部更新为正常状态
|
|
|
'appointment_date' => $plan->date,
|
|
|
'appointment_time' => $plan->time,
|
|
|
'erxian_appointment_info' => json_encode($plan_nmr_appointment_info, JSON_UNESCAPED_UNICODE),
|
|
|
'plan_id' => $plan->id,
|
|
|
'plan_number' => $plan->plan_number,
|
|
|
'combo_id' => $combo_id,
|
|
|
'hospital_id' => $hospital_id,
|
|
|
'doctor' => $doctor,
|
|
|
'phone' => $person->phone,
|
|
|
'sex' => $person->sex,
|
|
|
'birthday' => $person->birthday,
|
|
|
'married' => $person->married,
|
|
|
'wj_flag' => $wj_flag,
|
|
|
'youhuiquan' => $quanInfo === false ? '' : json_encode(['id' => $quanInfo['DZJID'], 'name' => $quanInfo['DZJLBMC']], JSON_UNESCAPED_UNICODE),
|
|
|
'created_at' => $now_datetime,
|
|
|
];
|
|
|
|
|
|
|
|
|
$insert = DB::table('orders')->insertGetId($data);
|
|
|
$up_plan = DB::table('plans')->where(['id' => $plan->id, 'status' => 1])->update([
|
|
|
'status' => 2
|
|
|
]);
|
|
|
//更新问卷log表
|
|
|
DB::table('questionnaires_logs')->where(['person_id' => $person->id, 'order_id' => 0])->update([
|
|
|
'order_id' => $insert,
|
|
|
]);
|
|
|
|
|
|
//调用接口扣除积分和预存款、优惠券
|
|
|
$jifen_dikou_status = true;
|
|
|
$yucunkuan_dikou_status = true;
|
|
|
$youhuiquan_dikou_status = true;
|
|
|
|
|
|
if ($env == 'pro') { //如果是正式环境
|
|
|
|
|
|
|
|
|
//开始预约二线
|
|
|
$nowDateTime=date('Y-m-d H:i:s');
|
|
|
if (!empty($plan_nmr_appointment_info)) {
|
|
|
foreach ($plan_nmr_appointment_info as $key => $plan_nmr) {
|
|
|
//$plan_nmr=$plan_nmr_appointment_info[0];
|
|
|
|
|
|
$sex="未知";
|
|
|
if($person->sex==1) $sex='男';
|
|
|
if($person->sex==2) $sex='女';
|
|
|
$p_nmr_data = [
|
|
|
'ghzid'=>$person->ghzid,
|
|
|
'YYRQ'=>$plan_nmr['date'],
|
|
|
'YYSJ'=>$plan_nmr['time'],
|
|
|
'U_SFID'=>$plan_nmr['item_id'],
|
|
|
'U_SFMC'=>$plan_nmr['name'],
|
|
|
'HBXMJE'=>$plan_nmr['price'],
|
|
|
'CJSJ'=>$nowDateTime,
|
|
|
'YYDH'=>$person->phone,
|
|
|
'YYXM'=>$person->name,
|
|
|
'YYXB'=>$sex,
|
|
|
'YYSR'=>$person->birthday,
|
|
|
'YYNL'=>Tools::GetAge($person->birthday).'岁' ,
|
|
|
'YYZJ'=>$person->id_number,
|
|
|
'YYSJ_B'=>$plan_nmr['time'].':00',
|
|
|
'YYSJ_E'=>$plan_nmr['time'].':00',
|
|
|
'YYSJ_BE'=>$plan_nmr['time'].'-'.$plan_nmr['time'],
|
|
|
'ZCRQ'=>$nowDateTime,
|
|
|
'yyid'=>$yyid,
|
|
|
'action'=>2,
|
|
|
];
|
|
|
//调用接口预约二线
|
|
|
$erxian_yuyue= $AspNet::ErXian($p_nmr_data, uniqid());
|
|
|
if(!!$erxian_yuyue){
|
|
|
$plan_nmr_appointment_info[$key]['gid']=$erxian_yuyue;
|
|
|
$ex_u= DB::table('orders')->where(['id' => $insert])->update([
|
|
|
'erxian_appointment_info'=>json_encode($plan_nmr_appointment_info, JSON_UNESCAPED_UNICODE),
|
|
|
]);
|
|
|
if(!$ex_u) return ['status' => false, 'msg' => "二线预约失败"];
|
|
|
}else{
|
|
|
return ['status' => false, 'msg' => "二线预约失败"];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($jifen > 0) {
|
|
|
$jifen_dikou_status = false;
|
|
|
$jifen_dikou_status = $AspNet::UseJiFen($person->ghzid, -$jifen, $yyid, $insert, 'tj_h5', '抵扣体检H5订单', $now_datetime);
|
|
|
}
|
|
|
if ($yucunkuan > 0) {
|
|
|
$yucunkuan_dikou_status = false;
|
|
|
$yucunkuan_dikou_status = $AspNet::UseYuCunKuan($person->ghzid, -$yucunkuan, $yyid, 0, $insert, 'tj_h5', '抵扣体检H5订单', $now_datetime);
|
|
|
}
|
|
|
|
|
|
//核销优惠券
|
|
|
if (isset($coupon_id) and !empty($coupon_id)) {
|
|
|
$youhuiquan_dikou_status = false;
|
|
|
$data = [
|
|
|
'action' => 3,
|
|
|
'ghzid' => $person->ghzid,
|
|
|
'dzjid' => $coupon_id,
|
|
|
'hxbz' => "抵扣体检H5订单",
|
|
|
'yyid' => $yyid
|
|
|
];
|
|
|
$youhuiquan_dikou_status = $AspNet::YouHuiQuan($data);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($insert and $up_plan and $jifen_dikou_status and $yucunkuan_dikou_status and $youhuiquan_dikou_status) {
|
|
|
//中途未报错,更新订单为待支付
|
|
|
DB::table('orders')->where('id', $insert)->update([
|
|
|
'status' => 1 //标记为待支付
|
|
|
]);
|
|
|
$action = false;
|
|
|
if ($true_price == 0) {
|
|
|
//如果是免费的,直接去预约
|
|
|
$yuyue = self::Finish($order_num);
|
|
|
if ($yuyue['status'] === true) {
|
|
|
return \Yz::return(true, "操作成功", ['action' => $action, 'orderid' => $insert]);
|
|
|
} else {
|
|
|
return \Yz::echoError1($yuyue['msg']);
|
|
|
}
|
|
|
}
|
|
|
if ($true_price > 0) {
|
|
|
//如果大于0则提示前端去支付
|
|
|
$action = "pay";
|
|
|
}
|
|
|
return \Yz::return(true, "操作成功", ['action' => $action, 'orderid' => $insert]);
|
|
|
} else {
|
|
|
|
|
|
DB::table('plans')->where(['id' => $plan->id])->update([
|
|
|
'status' => 1
|
|
|
]);
|
|
|
DB::table('questionnaires_logs')->where(['person_id' => $person->id, 'order_id' => $insert])->update([
|
|
|
'order_id' => 0,
|
|
|
]);
|
|
|
return \Yz::echoError1('操作失败');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//订单改约
|
|
|
public function ChangeAppointment()
|
|
|
{
|
|
|
$AspNet = new AspNetZhuanController();
|
|
|
$orderid = request('orderid');
|
|
|
$plan_id = request('planid');
|
|
|
$nmr_info = request('nmr_info');
|
|
|
$doctor = request('doctor');
|
|
|
$orderInfo = DB::table('orders')->where(['id' => $orderid, 'status' => 2])->first();
|
|
|
if (!$orderInfo) return \Yz::echoError1("未找到有效订单");
|
|
|
$person = DB::table('web_user_person')->where(['id' => $orderInfo->person_id, 'is_del' => 0])->first();
|
|
|
if (!$person) return \Yz::echoError1('体检人不存在');
|
|
|
if ($orderInfo->hospital_id == 1) {
|
|
|
$yyid = 6;
|
|
|
}
|
|
|
if ($orderInfo->hospital_id == 4) {
|
|
|
$yyid = 2;
|
|
|
}
|
|
|
|
|
|
//如果重新选择了体检号源,则检验号源有效性//判断体检日期是否在核磁前N天范围内
|
|
|
if(isset($plan_id) && $plan_id <> $orderInfo->plan_id){
|
|
|
$planInfo = DB::table('plans')->where(['id' => $plan_id, 'status' => 1])->first();
|
|
|
if (!$planInfo) return \Yz::echoError1("所选体检日期号源无效");
|
|
|
// $check_plan_kuadu=$this->checkDatesWithinDays([['date'=>$check_erxian_kuadu['mindate'],'date'=>$planInfo->date]],$ErXianKuaDu);
|
|
|
// if(!$check_erxian_kuadu['check_status']) return \Yz::echoError1("体检日期与核磁日期跨度不能大于".$ErXianKuaDu."天,请重新选择");
|
|
|
}
|
|
|
//判断核磁号源有效性能,日期范围是否正常,判断核磁新日期时间是否和旧的日期时间一样
|
|
|
//判断各个二线直接的跨度是否在设定范围内---废弃
|
|
|
// $ErXianKuaDu = config('app.globals.erxian_kuadu');
|
|
|
// $check_erxian_kuadu=$this->checkDatesWithinDays($nmr_info,$ErXianKuaDu);
|
|
|
// if(!$check_erxian_kuadu['check_status']) return \Yz::echoError1("所有二线项目预约跨度不应大于".$ErXianKuaDu."天,请重新选择");
|
|
|
if(isset($plan_id) && $plan_id == $orderInfo->plan_id) return \Yz::echoError1("无需进行此操作");
|
|
|
//如果有二线号源,根据体检时间查询二线可用号源,区分上下午
|
|
|
$db_nmr_info=json_decode($orderInfo->erxian_appointment_info,true);
|
|
|
$nmr_info=[];
|
|
|
if (isset($db_nmr_info) and !empty($db_nmr_info)) {
|
|
|
foreach ($db_nmr_info as $erxian_item) {
|
|
|
$nmrPlans=$AspNet::ErXian(['yyid'=>6,'data'=>[$planInfo->date],'action'=>"1"],uniqid());
|
|
|
if($planInfo->time<="12:00") $end_time="12:00";
|
|
|
if($planInfo->time>"12:00") $end_time="23:59";
|
|
|
if(!isset($nmrPlans[$planInfo->date]) or empty($nmrPlans[$planInfo->date])) return \Yz::echoError1("二线号源不可用,请重新选则日期");
|
|
|
$temp_date=[];
|
|
|
foreach ($nmrPlans[$planInfo->date] as $nmp_p){
|
|
|
if($nmp_p['Time']>=substr($planInfo->time,0,5) and $nmp_p['Time']<=$end_time and $nmp_p['keyong']==="0"){
|
|
|
$temp_date=[
|
|
|
"item_id"=>$erxian_item['item_id'],
|
|
|
"name"=>$erxian_item['name'],
|
|
|
"price"=>$erxian_item['price'],
|
|
|
"time"=>$nmp_p['Time'],
|
|
|
"date"=>$planInfo->date,
|
|
|
];
|
|
|
$nmr_info[]=$temp_date;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if(empty($temp_date)) return \Yz::echoError1("二线号源不可用,请重新选则日期");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//判断二线号源日期时间是否改变,如果改变校验号源有效性
|
|
|
foreach ($nmr_info as $key=>$nmr_item){
|
|
|
foreach ($db_nmr_info as $db_nmr_item){
|
|
|
if($nmr_item['item_id']==$db_nmr_item['item_id']){
|
|
|
if(!($nmr_item['date']==$db_nmr_item['date'] and $nmr_item['time']==$db_nmr_item['time'] and $db_nmr_item['gid']<>"")){
|
|
|
$p_nmr_data = [
|
|
|
'item_id' => $nmr_item['item_id'],
|
|
|
'name' => $nmr_item['name'],
|
|
|
'date' => $nmr_item['date'],
|
|
|
'time' => $nmr_item['time'],
|
|
|
'price' => $nmr_item['price'],
|
|
|
];
|
|
|
//调用接口校验号源是否可用
|
|
|
$erxian_status = $AspNet::ErXian(['YYRQ' => $p_nmr_data['date'], 'YYSJ' => $p_nmr_data['time'], 'yyid' => $yyid, 'action' => 4], uniqid());
|
|
|
if ($erxian_status !== true) return \Yz::echoError1($p_nmr_data['name'] . '号源不可用,请重新选择');
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//如果二线号源校验通过,则先取消再预约新的
|
|
|
foreach ($nmr_info as $key=>$nmr_item){
|
|
|
foreach ($db_nmr_info as $key2=> $db_nmr_item){
|
|
|
if($nmr_item['item_id']==$db_nmr_item['item_id']){
|
|
|
if(!($nmr_item['date']==$db_nmr_item['date'] and $nmr_item['time']==$db_nmr_item['time'])){
|
|
|
//先取消
|
|
|
if($db_nmr_item['gid']<>""){
|
|
|
$AspNet::ErXian(['id' =>$db_nmr_item['gid'], 'yyid' => $yyid, 'action' => 3], uniqid());//取消
|
|
|
$db_nmr_info[$key2]['gid']='';
|
|
|
$ex_u= DB::table('orders')->where(['id' => $orderInfo->id])->update([
|
|
|
'erxian_appointment_info'=>json_encode($db_nmr_info, JSON_UNESCAPED_UNICODE),
|
|
|
]);
|
|
|
}
|
|
|
//再预约新的
|
|
|
$nowDateTime=date('Y-m-d H:i:s');
|
|
|
$sex="未知";
|
|
|
if($person->sex==1) $sex='男';
|
|
|
if($person->sex==2) $sex='女';
|
|
|
$p_nmr_data = [
|
|
|
'ghzid'=>$person->ghzid,
|
|
|
'YYRQ'=>$nmr_item['date'],
|
|
|
'YYSJ'=>$nmr_item['time'],
|
|
|
'U_SFID'=>$nmr_item['item_id'],
|
|
|
'U_SFMC'=>$nmr_item['name'],
|
|
|
'HBXMJE'=>$nmr_item['price'],
|
|
|
'CJSJ'=>$nowDateTime,
|
|
|
'YYDH'=>$person->phone,
|
|
|
'YYXM'=>$person->name,
|
|
|
'YYXB'=>$sex,
|
|
|
'YYSR'=>$person->birthday,
|
|
|
'YYNL'=>Tools::GetAge($person->birthday).'岁' ,
|
|
|
'YYZJ'=>$person->id_number,
|
|
|
'YYSJ_B'=>$nmr_item['time'].':00',
|
|
|
'YYSJ_E'=>$nmr_item['time'].':00',
|
|
|
'YYSJ_BE'=>$nmr_item['time'].'-'.$nmr_item['time'],
|
|
|
'ZCRQ'=>$nowDateTime,
|
|
|
'yyid'=>$yyid,
|
|
|
'action'=>2,
|
|
|
];
|
|
|
//调用接口预约二线
|
|
|
$erxian_yuyue= $AspNet::ErXian($p_nmr_data, uniqid());
|
|
|
if(!!$erxian_yuyue){
|
|
|
$db_nmr_info[$key2]['gid']=$erxian_yuyue;
|
|
|
$db_nmr_info[$key2]['date']=$nmr_item['date'];
|
|
|
$db_nmr_info[$key2]['time']=$nmr_item['time'];
|
|
|
$ex_u= DB::table('orders')->where(['id' => $orderInfo->id])->update([
|
|
|
'erxian_appointment_info'=>json_encode($db_nmr_info, JSON_UNESCAPED_UNICODE),
|
|
|
]);
|
|
|
if(!$ex_u) return ['status' => false, 'msg' => "二线预约失败"];
|
|
|
}else{
|
|
|
return ['status' => false, 'msg' => "二线预约失败"];
|
|
|
}
|
|
|
}
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
// var_dump($nmr_info);
|
|
|
// return false;
|
|
|
//判断体检日期时间是否和旧的日期时间一样。一样则跳过,不一样则更新
|
|
|
if (isset($plan_id) && $plan_id <> $orderInfo->plan_id) {
|
|
|
$peis = new PEISApiController();
|
|
|
$data = "appointmentId=" . $orderInfo->appointment_number . "&appGroupId=66&appPlanId=" . $plan_id . "&appPlanNumber=" . $planInfo->plan_number . "&date=" . urlencode($planInfo->date . ' ' . $planInfo->time);
|
|
|
$ch = $peis::Post2('修改用户预约时间', $peis::Api('修改用户预约时间', $data), $orderInfo->hospital_id, []);
|
|
|
if ($ch == '修改预约时刻保存成功') {
|
|
|
//恢复旧的plans
|
|
|
DB::table('plans')->where(['id' => $orderInfo->plan_id])->update(
|
|
|
['status' => 1]
|
|
|
);
|
|
|
//使用新的plans
|
|
|
DB::table('plans')->where(['id' => $plan_id])->update(
|
|
|
['status' => 2]
|
|
|
);
|
|
|
//更新订单
|
|
|
DB::table('orders')->where(['id' => $orderInfo->id])->update([
|
|
|
'plan_id' => $plan_id,
|
|
|
'plan_number' => $planInfo->plan_number,
|
|
|
'appointment_date' => $planInfo->date,
|
|
|
'appointment_time' => $planInfo->time,
|
|
|
'doctor' => isset($doctor) ? $doctor : null,
|
|
|
]);
|
|
|
}
|
|
|
return \Yz::Return(true, "操作完成", []);
|
|
|
}
|
|
|
return \Yz::echoError1("未更改内容,无需进行此操作");
|
|
|
}
|
|
|
//判断时间跨度
|
|
|
function checkDatesWithinDays($data,$kuadu) {
|
|
|
// 提取所有日期
|
|
|
$dates = array_column($data, 'date');
|
|
|
|
|
|
// 将日期转换为时间戳
|
|
|
$timestamps = array_map('strtotime', $dates);
|
|
|
|
|
|
// 找出最早和最晚的时间戳
|
|
|
$earliest = min($timestamps);
|
|
|
$latest = max($timestamps);
|
|
|
|
|
|
// 计算时间差(以天为单位)
|
|
|
$differenceInDays = ($latest - $earliest) / (60 * 60 * 24);
|
|
|
|
|
|
// 判断时间差是否在3天以内
|
|
|
return ['check_status'=>$differenceInDays <= $kuadu,'mindate'=> date('Y-m-d H:i:s', $earliest)];
|
|
|
}
|
|
|
|
|
|
public function generateOrderNumber()
|
|
|
{
|
|
|
// 获取当前时间的时间戳(精确到毫秒)
|
|
|
$timestamp = round(microtime(true) * 1000);
|
|
|
|
|
|
// 生成一个随机数(可以根据需要调整长度)
|
|
|
$randomPart = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 6);
|
|
|
|
|
|
// 拼接时间戳和随机部分
|
|
|
$orderNumber = date("YmdHis", $timestamp / 1000) . substr($timestamp % 1000, -3) . $randomPart;
|
|
|
|
|
|
return $orderNumber;
|
|
|
}
|
|
|
|
|
|
public function item_check($hospital, $data)
|
|
|
{
|
|
|
$peis = new PEISApiController();
|
|
|
$check = $peis::Post('套餐项目检查', $hospital, $data);
|
|
|
return $check;
|
|
|
}
|
|
|
|
|
|
|
|
|
public function Finish_test() //删除!!!
|
|
|
{
|
|
|
$f = self::Finish('20241030111035259T2IBC6');
|
|
|
dd($f);
|
|
|
}
|
|
|
|
|
|
//最后步骤,开始通知思信预约
|
|
|
public function Finish($order_number)
|
|
|
{
|
|
|
$AspNet=new AspNetZhuanController();
|
|
|
$order_info = DB::table('orders')->where(['order_number' => $order_number])->first();
|
|
|
if (!$order_info) return ['status' => false, 'msg' => "未找到有效订单。"];
|
|
|
$person=DB::table('web_user_person')->where(['id' => $order_info->person_id])->first();
|
|
|
if(!$person) return ['status' => false, 'msg' => "体检人信息无效。"];
|
|
|
$yyid=6;
|
|
|
if($order_info->hospital_id == 1){
|
|
|
$yyid=6;
|
|
|
}
|
|
|
if($order_info->hospital_id == 4){
|
|
|
$yyid=2;
|
|
|
}
|
|
|
|
|
|
|
|
|
$buy_info = json_decode($order_info->buy_info, true);
|
|
|
$combo_id = $buy_info['combo']['id'];
|
|
|
$item_arr = [];
|
|
|
foreach ($buy_info['items'] as $item) {
|
|
|
$item_arr[] = ['Id' => $item['id'], '已收费' => true,'分组项目'=>false,'收费方式'=>'自费',];
|
|
|
}
|
|
|
//调用思信 套餐项目检查
|
|
|
if ((isset($combo_id) and $combo_id <> 0) || count($item_arr) != 0) {
|
|
|
$item_check = self::item_check($order_info->hospital_id, [
|
|
|
'人员信息列表' => [[
|
|
|
"序号" => 0,
|
|
|
"性别" => $order_info->sex == 1 ? '男' : '女',
|
|
|
"年龄" => floor((time() - strtotime($order_info->birthday)) / 86400 / 360),
|
|
|
"婚姻状态" => $order_info->married == 1 ? '已婚' : '未婚',
|
|
|
]],
|
|
|
'套餐Id' => $combo_id == 0 ? null : $combo_id,
|
|
|
'可选项目信息' => $item_arr,
|
|
|
]);
|
|
|
if (count($item_check['data']) != 1) {
|
|
|
return ['status' => false, 'msg' => "体检系统提示:" . $item_check['message']];
|
|
|
}
|
|
|
}
|
|
|
//如果是个检
|
|
|
if ($order_info->type == 1) {
|
|
|
$checkup_type=DB::table('checkup_type')->where(['id' => $order_info->checkup_type_id])->first();
|
|
|
$cad = [
|
|
|
'type' => 1,
|
|
|
"姓名" => $order_info->name,
|
|
|
"性别" => $order_info->sex == 1 ? '男' : '女',
|
|
|
"年龄" => floor((time() - strtotime($order_info->birthday)) / 86400 / 360),
|
|
|
"婚姻状态" => $order_info->married == 1 ? '已婚' : '未婚',
|
|
|
"证件号码" => $order_info->id_number,
|
|
|
"电话号码" => $order_info->phone,
|
|
|
"预约时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time,
|
|
|
"介绍人" => $order_info->referral,
|
|
|
'套餐Id' => $order_info->combo_id == 0 ? null : $order_info->combo_id,
|
|
|
'体检类型Id'=>isset($checkup_type->sx_id)?$checkup_type->sx_id:null,
|
|
|
"已收费" => true,
|
|
|
|
|
|
];
|
|
|
$cad2 = [
|
|
|
"可选项目信息" => $item_arr,
|
|
|
"总计金额" => $order_info->price,
|
|
|
];
|
|
|
if ($order_info->wj_flag == 1) {
|
|
|
$temp = [];
|
|
|
foreach ($item_arr as $k => $item) {
|
|
|
$temp[] = [
|
|
|
"Id" => $item['Id'],
|
|
|
"已收费" => $item['已收费'],
|
|
|
"优惠方式" => "打折",
|
|
|
"优惠值" => config('app.globals.Wj_ZheKou')
|
|
|
];
|
|
|
}
|
|
|
$cad2 = [
|
|
|
"可选项目信息" => $temp,
|
|
|
];
|
|
|
}
|
|
|
$cad = array_merge($cad, $cad2);
|
|
|
} else {
|
|
|
if(isset($buy_info['group']['items'])){
|
|
|
$item_temp=[];
|
|
|
foreach ($buy_info['group']['items'] as $gitem) {
|
|
|
$item_temp[]=[
|
|
|
'Id' => $gitem['id'],
|
|
|
'分组项目' => true,
|
|
|
'收费方式'=>'统收',
|
|
|
'已收费' => true
|
|
|
];
|
|
|
}
|
|
|
$item_arr= array_merge($item_arr,$item_temp);
|
|
|
}
|
|
|
$cad = [
|
|
|
'type' => 2,
|
|
|
"预约Id" => $buy_info['group']['group_id'],
|
|
|
"预约时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time,
|
|
|
'套餐Id' => null,
|
|
|
"可选项目信息" => $item_arr
|
|
|
];
|
|
|
}
|
|
|
//如果是 如果订单未支付 在这里更新订单状态为已支付。
|
|
|
DB::table('orders')->where(['order_number' => $order_number, 'status' => 1])->update([
|
|
|
'status' => 2,
|
|
|
'pay_time' => date('Y-m-d H:i:s'),
|
|
|
]);
|
|
|
//查询确认订单已经是支付状态
|
|
|
$cha = DB::table('orders')->where(['order_number' => $order_number, 'status' => 2])->first();
|
|
|
if (!$cha) return ['status' => false, 'msg' => "订单未支付,禁止预约"];
|
|
|
|
|
|
|
|
|
$create_appointment = self::create_appointment($order_info->hospital_id, $cad);
|
|
|
|
|
|
if (!isset($create_appointment['data'][0][0])) return ['status' => false, 'msg' => "体检预约,返回非预期结果"];
|
|
|
|
|
|
//预约完成后查询预约结果
|
|
|
$appointment_info = self::appointment_info($order_info->hospital_id, [
|
|
|
'type' => $order_info->type,
|
|
|
"证件号码" => null,
|
|
|
"电话号码" => null,
|
|
|
"预约Id" => $create_appointment['data'][0][0],
|
|
|
]);
|
|
|
|
|
|
//如果是医生web端预约,则调用预约时段修改接口,传入医生名称
|
|
|
if ($order_info->source == 'web') {
|
|
|
$peis = new PEISApiController();
|
|
|
$dat = [
|
|
|
"预约Id" => $create_appointment['data'][0][0],
|
|
|
"预约开始时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time,
|
|
|
"预约截止时间" => $order_info->appointment_date . ' ' . $order_info->appointment_time,
|
|
|
"AppDoctor" => $order_info->appdoctor
|
|
|
];
|
|
|
$info = $peis::Post('预约时段修改', $order_info->hospital_id, $dat);
|
|
|
}
|
|
|
$u = DB::table('orders')->where(['order_number' => $order_number])->update([
|
|
|
'appointment_number' => $create_appointment['data'][0][0],
|
|
|
'appointment_back_info' => json_encode($appointment_info['data'][0], JSON_UNESCAPED_UNICODE)
|
|
|
]);
|
|
|
$is_sendMsg = DB::table('configs')->where(['label' => '预约完成短信通知'])->first();
|
|
|
if (!!$is_sendMsg and $is_sendMsg->value == 1) {
|
|
|
$asp = new AspNetZhuanController();
|
|
|
$asp::SendMsg($cha->hospital_id, $cha->phone, $cha->name, $cha->appointment_date . ' ' . substr($cha->appointment_time, 0, 5));
|
|
|
}
|
|
|
return ['status' => true, 'msg' => "完成"];
|
|
|
}
|
|
|
|
|
|
|
|
|
//未支付取消订单
|
|
|
public function Cancel()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
//批量取消订单
|
|
|
public function BatchCancel()
|
|
|
{
|
|
|
$WaitingPaymentTime = config('app.globals.WaitingPaymentTime');//支付等待時間
|
|
|
$orderInfos = DB::table('orders')->where(['status' => 1])->get();
|
|
|
foreach ($orderInfos as $k => $orderInfo) {
|
|
|
$person = DB::table('web_user_person')->where(['id' => $orderInfo->person_id])->first();
|
|
|
$datetime = new DateTime($orderInfo->created_at);
|
|
|
$timestamp = $datetime->getTimestamp();
|
|
|
$orderInfo->end_time = $timestamp + (60 * $WaitingPaymentTime);
|
|
|
if (time() > $orderInfo->end_time) {
|
|
|
$do = new OrderService();
|
|
|
$do->Cancel($orderInfo);
|
|
|
}
|
|
|
}
|
|
|
return \Yz::Return(true, "批量处理完成", []);
|
|
|
}
|
|
|
|
|
|
public function create_appointment($hospital, $data)
|
|
|
{
|
|
|
$peis = new PEISApiController();
|
|
|
$url_code = $data['type'] == 1 ? '个检预约' : '团检预约';
|
|
|
unset($data['type']);
|
|
|
$info = $peis::Post($url_code, $hospital, $data);
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
public function appointment_info($hospital, $data)
|
|
|
{
|
|
|
$peis = new PEISApiController();
|
|
|
$url_code = $data['type'] == 1 ? '个检预约查询' : '团检预约查询';
|
|
|
unset($data['type']);
|
|
|
$info = $peis::Post($url_code, $hospital, $data);
|
|
|
return $info;
|
|
|
}
|
|
|
|
|
|
public function cancel_appointment($hospital, $data)
|
|
|
{
|
|
|
$peis = new PEISApiController();
|
|
|
$url_code = $data['type'] == 1 ? '个检预约取消' : '团检预约取消';
|
|
|
if($data['type']==2){
|
|
|
$data['删除套餐']=true;
|
|
|
}
|
|
|
unset($data['type']);
|
|
|
$info = $peis::Post($url_code, $hospital, $data);
|
|
|
return $info;
|
|
|
}
|
|
|
public function useYouHuiQuan($true_price,$person,$coupon_id){
|
|
|
//如果使用了代金券
|
|
|
$quanInfo = false;
|
|
|
if (isset($coupon_id) and !empty($coupon_id)) {
|
|
|
if ($true_price == 0) return \Yz::echoError1("无需使用代金券");
|
|
|
|
|
|
$AspNet = new AspNetZhuanController();
|
|
|
$data = [
|
|
|
'ghzid' => $person->ghzid,
|
|
|
'action' => 1,
|
|
|
];
|
|
|
$YouHuiQuanList = $AspNet::YouHuiQuan($data);
|
|
|
foreach ($YouHuiQuanList as $key => $quan) {
|
|
|
if ($quan['DZJID'] == $coupon_id) {
|
|
|
$quanInfo = $quan;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ($quanInfo['是否在有效内'] === true and $quanInfo['TimeNuZTTextm'] == "有效" and $quanInfo['ZT'] == 1) {
|
|
|
|
|
|
} else {
|
|
|
return \Yz::echoError1("此代金券不可用");
|
|
|
}
|
|
|
|
|
|
$quanType = false;
|
|
|
$YouHuiQuanType = $AspNet::YouHuiQuan(['action' => 2]);
|
|
|
foreach ($YouHuiQuanType as $key => $qtype) {
|
|
|
if ($quanInfo['DZJLBID'] == $qtype['DZJLBID']) {
|
|
|
$quanType = $qtype;
|
|
|
}
|
|
|
// if($qtype['TJXCXHX']==1 and ($qtype['MKJE']===0 || $qtype['MKJE']>=$true_price)){
|
|
|
// $YouHuiQuanType_ids[]=$qtype['DZJLBID'];
|
|
|
// }
|
|
|
}
|
|
|
if ($quanType === false or $quanInfo === false) return \Yz::echoError1("此代金券不可用");
|
|
|
if ($quanType['TJXCXHX'] != 1) return \Yz::echoError1("此代金券不可用");
|
|
|
if ($quanType['MKJE'] == 0 or $quanType['MKJE'] >= $true_price) {
|
|
|
//抵扣代金券金额
|
|
|
if($quanType['YHLX']==1){//抵扣券
|
|
|
$true_price=($true_price-$quanInfo['JE'])>0 ? $true_price-$quanInfo['JE']:0;
|
|
|
}
|
|
|
if($quanType['YHLX']==2){//抵扣券
|
|
|
$true_price=number_format($true_price*$quanType['DZBL'],2, '.', '');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
return ['price'=>$true_price,'quanInfo'=>$quanInfo];
|
|
|
}
|
|
|
}
|