|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\API\Internal;
|
|
|
|
|
|
use App\Http\Controllers\API\PEISApiController;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use DateTime;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class OrderController extends Controller
|
|
|
{
|
|
|
//到检
|
|
|
public function TJCheck()
|
|
|
{
|
|
|
$password = request('password');
|
|
|
$serve_id = request('serve_id');
|
|
|
$exam_id = request('exam_id');
|
|
|
if (!isset($exam_id) or empty($exam_id)) return \Yz::echoError1("体检号不能为空");
|
|
|
if ($password !== 'YRtA1rx1iWgbpYKX') return \Yz::echoError1("校验密码失败");
|
|
|
if (isset($serve_id) and !empty($serve_id) and $serve_id <> '') { //到检通知
|
|
|
$orderInfo = DB::table('orders')->where('appointment_number', $serve_id)->orderBy('id', 'desc')->first();
|
|
|
if (!$orderInfo) {
|
|
|
return $this->CreateOrder($exam_id);
|
|
|
} else {
|
|
|
if (!!$exam_id) {
|
|
|
if ($orderInfo->status == 1 and strpos($orderInfo->source, '线下体检预约') !== false ){
|
|
|
return $this->CreateOrder($exam_id,$orderInfo->id);
|
|
|
}
|
|
|
if ($orderInfo->status == 1) return \Yz::echoError1("订单未付款");
|
|
|
if ($orderInfo->status == 3) return \Yz::echoError1("订单已取消");
|
|
|
if ($orderInfo->status == 4 || $orderInfo->check_status == 2) return \Yz::echoError1("人员已经到检");
|
|
|
if ($orderInfo->status == 5) return \Yz::echoError1("订单已退款");
|
|
|
|
|
|
DB::table('orders')->where('id', $orderInfo->id)->update([
|
|
|
'status' => 4,
|
|
|
// 'tj_number'=>$info['data'][0]['体检号'],
|
|
|
'tj_number' => $exam_id,
|
|
|
'check_status' => 2,
|
|
|
'check_time' => date('Y-m-d H:i:s'),
|
|
|
'check_read_status' => 1
|
|
|
]);
|
|
|
return \Yz::Return(true, "", ['id' => $orderInfo->id]);
|
|
|
} else {
|
|
|
return \Yz::echoError1("体检号不能为空");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else { //体检直接登记用户信息,没经过h5登记。根据体检号查询信息入库
|
|
|
return $this->CreateOrder($exam_id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//根据体检号拉取数据进行存储
|
|
|
public function CreateOrder($exam_id,$order_id=0)
|
|
|
{
|
|
|
if (isset($exam_id)) {
|
|
|
$peis = new PEISApiController();
|
|
|
$data = [
|
|
|
'电话号码' => "",
|
|
|
'证件号码' => "",
|
|
|
'体检号' => $exam_id,
|
|
|
'包含内部信息' => true
|
|
|
];
|
|
|
$reports = $peis::Post('体检报告查询', 1, $data);
|
|
|
if (isset($reports['data'][0]['收费项目列表'])) {
|
|
|
$data = $reports['data'][0];
|
|
|
$items = [];
|
|
|
foreach ($data['收费项目列表'] as $it) {
|
|
|
$items[] = [
|
|
|
'id' => $it['收费项目Id'],
|
|
|
'name' => $it['收费项目名称'],
|
|
|
'price' => '',
|
|
|
];
|
|
|
}
|
|
|
$buyInfo = [
|
|
|
'combo' => [
|
|
|
'id' => 0,
|
|
|
'name' => '',
|
|
|
'price' => ''
|
|
|
],
|
|
|
'items' => $items,
|
|
|
'group' => [
|
|
|
'id' => '',
|
|
|
]
|
|
|
];
|
|
|
$sex = 0;
|
|
|
if ($data['性别'] == '男') $sex = 1;
|
|
|
if ($data['性别'] == '女') $sex = 2;
|
|
|
$dataInfo = [
|
|
|
'hospital_id' => 1,
|
|
|
'title' => $data['套餐名称'],
|
|
|
'type' => $data['单位名称'] == '个人' ? 1 : 2,
|
|
|
'source' => '体检推送',
|
|
|
'name' => $data['姓名'],
|
|
|
'id_number' => $data['证件号码'],
|
|
|
'person_id' => 0,
|
|
|
'buy_info' => json_encode($buyInfo, JSON_UNESCAPED_UNICODE),
|
|
|
'status' => 4,
|
|
|
'plan_number' => $data['分诊信息'],
|
|
|
'appointment_date' => explode('T', $data['登记时间'])[0],
|
|
|
'tj_number' => $exam_id,
|
|
|
'phone' => $data['电话号码'],
|
|
|
'sex' => $sex,
|
|
|
'birthday' => explode('T', $data['出生日期'])[0],
|
|
|
'check_status' => 2,
|
|
|
'check_time' => $data['登记时间'],
|
|
|
];
|
|
|
if($order_id>0){
|
|
|
if(empty($dataInfo['title'])){
|
|
|
$dataInfo['title']='自选项目';
|
|
|
}
|
|
|
unset($dataInfo['source']);
|
|
|
unset($dataInfo['person_id']);
|
|
|
unset($dataInfo['person_id']);
|
|
|
$insert = DB::table('orders')->where('id',$order_id)->update($dataInfo);
|
|
|
}else{
|
|
|
$insert = DB::table('orders')->insert($dataInfo);
|
|
|
}
|
|
|
|
|
|
if ($insert) {
|
|
|
return \Yz::Return(true, "创建成功", ['id' => $insert]);
|
|
|
} else {
|
|
|
return \Yz::echoError1("创建失败");
|
|
|
}
|
|
|
} else {
|
|
|
return \Yz::echoError1("根据体检号查询用户信息出错,结果非预期");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
return \Yz::echoError1("体检号不能为空");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function GetH5Order()
|
|
|
{
|
|
|
$appointment_number = request('appointment_number');//思信预约完成后的id
|
|
|
if (!isset($appointment_number) || empty($appointment_number)) return \Yz::echoError1('预约id 不能为空');
|
|
|
$order_info = DB::table('orders')->where(['appointment_number' => $appointment_number, 'status' => 2, 'check_status' => 1])->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
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
//线下预约完后,未支付,未到检,推送过来订单,由H5进行后续流程,支付改约等
|
|
|
public function OfflineOrderPush()
|
|
|
{
|
|
|
$password = request('password');
|
|
|
if ($password !== 'YRtA1rx1iWgbpYKX') return \Yz::echoErrorJson("校验密码失败");
|
|
|
$hospital_id = request('hospital_id'); //秀英院区1,府城院区4
|
|
|
$appointment_number = request('appointment_number');
|
|
|
$plan_id = request('plan_id');
|
|
|
$combo_id = request('combo_id');
|
|
|
if (!isset($plan_id) or empty($plan_id)) return \Yz::echoErrorJson("占用的号源id不能为空");
|
|
|
$check=DB::table('orders')->where(['appointment_number' => $appointment_number])->first();
|
|
|
if (!!$check) return \Yz::echoErrorJson("预约已存在,无需重复推送");
|
|
|
$plan_info=DB::table('plans')->where('id', $plan_id)->first();
|
|
|
$data = [
|
|
|
"证件号码" => null,
|
|
|
"电话号码" => null,
|
|
|
"预约Id" => $appointment_number,
|
|
|
];
|
|
|
$peis = new PEISApiController();
|
|
|
$info = $peis::Post('个检预约查询', $hospital_id, $data);
|
|
|
if (isset($info['data'][0])) {
|
|
|
$res = $info['data'][0];
|
|
|
$checkup_type_id = null;
|
|
|
$checkup_type = DB::table('checkup_type')->where('name', $res['体检类型'])->first();
|
|
|
if(!!$checkup_type) $checkup_type_id = $checkup_type->id;
|
|
|
// $title=$res['项目列表'];
|
|
|
// if(empty($res['项目列表']) and $res['总计金额']==0){
|
|
|
// $title='空号源';
|
|
|
// }
|
|
|
$items = [];
|
|
|
foreach ($res['项目列表'] as $it) {
|
|
|
if($it['自选项目']){
|
|
|
$items[] = [
|
|
|
'id' => $it['Id'],
|
|
|
'name' => $it['名称'],
|
|
|
'price' => $it['价格'],
|
|
|
'youhui_fangshi' => $it['优惠方式'],
|
|
|
'youhui_zhi' => $it['优惠值'],
|
|
|
];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
$buyInfo = [
|
|
|
'combo' => [
|
|
|
'id' => empty($combo_id)?0:$combo_id,
|
|
|
'name' => '',
|
|
|
'price' => ''
|
|
|
],
|
|
|
'items' => $items,
|
|
|
'group' => [
|
|
|
'id' => '',
|
|
|
]
|
|
|
];
|
|
|
$orderController= new \App\Http\Controllers\API\H5\OrderController();
|
|
|
if((empty($res['套餐名称']) or $res['套餐名称']=='无') and count($items)>0){
|
|
|
$res['套餐名称']='自选项目';
|
|
|
}
|
|
|
$save_data = [
|
|
|
'title' => $res['套餐名称'],
|
|
|
'type' => 1,
|
|
|
'source' => (count($items)==0 and empty($combo_id))?'线下体检预约-空号源':'线下体检预约-项目',
|
|
|
'checkup_type_id' => $checkup_type_id,
|
|
|
'person_id' => 0,
|
|
|
'name' => $res['姓名'],
|
|
|
'id_number' => $res['证件号码'],
|
|
|
'buy_info' => json_encode($buyInfo, JSON_UNESCAPED_UNICODE),
|
|
|
'price' => $res['总计金额'],
|
|
|
'true_price' => $res['总计金额'],
|
|
|
'order_number' =>$orderController->generateOrderNumber(),
|
|
|
'status' =>1,
|
|
|
'appointment_date' =>$plan_info->date,
|
|
|
'appointment_time' =>$plan_info->time,
|
|
|
'appointment_number' =>$res['预约Id'],
|
|
|
'appointment_back_info' => json_encode($res, JSON_UNESCAPED_UNICODE),
|
|
|
'plan_id' =>$plan_info->id,
|
|
|
'plan_number' =>$plan_info->plan_number,
|
|
|
'combo_id' =>empty($combo_id)?0:$combo_id,
|
|
|
'hospital_id' =>$hospital_id,
|
|
|
'phone' =>$res['电话号码'],
|
|
|
'sex' =>null,
|
|
|
'birthday' =>null,
|
|
|
'married' =>4,
|
|
|
];
|
|
|
$insert = DB::table('orders')->insert($save_data);
|
|
|
if ($insert) {
|
|
|
return \Yz::Return(true, "创建成功", ['id' => $insert]);
|
|
|
} else {
|
|
|
return \Yz::echoErrorJson("创建失败");
|
|
|
}
|
|
|
} else {
|
|
|
return \Yz::echoErrorJson("未获取到预约信息");
|
|
|
}
|
|
|
}
|
|
|
//给三方(非思信)提供的查询订单列表接口
|
|
|
public function GetOrderList()
|
|
|
{
|
|
|
// $openid = request('openid');
|
|
|
// $ghzid = request('ghzid');
|
|
|
// $date_range = request('date_range');
|
|
|
// $status = request('status');
|
|
|
|
|
|
$encrypted_data = request('encrypted_data');
|
|
|
$iv = request('iv');
|
|
|
if (!isset($iv)) return \Yz::echoError1('加密时使用的iv不能为空');
|
|
|
|
|
|
$encrypted_data = \App\Lib\Tools::AESDecrypt($encrypted_data, config('app.globals.AES_KEY'), $iv);
|
|
|
if (!$encrypted_data) return \Yz::echoError1('encrypted_data解密失败');
|
|
|
$encrypted_data = json_decode($encrypted_data, true);
|
|
|
if (!isset($encrypted_data['openid'])) return \Yz::echoError1('openid不能为空');
|
|
|
$openid = $encrypted_data['openid'];
|
|
|
if (!isset($encrypted_data['ghzid'])) return \Yz::echoError1('ghzid不能为空');
|
|
|
$ghzid = $encrypted_data['ghzid'];
|
|
|
// if (!isset($encrypted_data['date_range'])) return \Yz::echoError1('date_range不能为空');
|
|
|
$date_range = isset($encrypted_data['date_range'])?$encrypted_data['date_range']:null;
|
|
|
$status =isset($encrypted_data['status'])? $encrypted_data['status']:null;
|
|
|
|
|
|
|
|
|
$encrypt_iv = bin2hex(random_bytes(16 / 2));
|
|
|
|
|
|
if (!isset($ghzid)) return \Yz::echoError1("ghzid不能为空");
|
|
|
|
|
|
$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(['ghzid' => $ghzid, 'is_del' => 0])->first();
|
|
|
// $where=['web_user_id' => $user->id];
|
|
|
|
|
|
|
|
|
|
|
|
$OrderList = DB::table('orders');
|
|
|
$OrderList=$OrderList
|
|
|
->select('id', 'source','title','person_id','checkup_type_id','status','sex', 'name','appointment_number','appointment_date as date', 'appointment_time as time',
|
|
|
DB::raw("CASE WHEN type = 1 THEN '个检' WHEN type = 2 THEN '团检' ELSE 'unknown' END as type"),
|
|
|
'plan_number','price', 'true_price', 'pay_time', 'refund_time', 'hospital_id','doctor','created_at');
|
|
|
|
|
|
if(isset($status)){
|
|
|
if($status==1){
|
|
|
$OrderList=$OrderList->where('status',1);
|
|
|
}
|
|
|
if($status==2){
|
|
|
$OrderList=$OrderList->where('status',2)
|
|
|
->whereNull('appointment_number');
|
|
|
}
|
|
|
if($status==3){
|
|
|
$OrderList=$OrderList->where('status',2)
|
|
|
->whereNotNull('appointment_number');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if(is_array($date_range) and count($date_range)==2){
|
|
|
$OrderList=$OrderList ->whereBetween('created_at', [$date_range[0], $date_range[1].' 23:59:59']);
|
|
|
}
|
|
|
|
|
|
$OrderList=$OrderList ->where(function ($query) use ($persons_sfz,$user) {
|
|
|
$query->where('web_user_id', $user->id)
|
|
|
->orWhere(function ($q) use ($persons_sfz) {
|
|
|
$q->where('id_number', $persons_sfz->id_number)
|
|
|
->where('person_id', 0);
|
|
|
});
|
|
|
})->orderBy('id', 'desc')->get();
|
|
|
|
|
|
|
|
|
$WaitingPaymentTime = config('app.globals.WaitingPaymentTime');//支付等待時間
|
|
|
foreach ($OrderList as $key => $list) {
|
|
|
if($list->hospital_id==1){
|
|
|
$list->yuanqu_id=6;
|
|
|
}
|
|
|
if($list->hospital_id==4){
|
|
|
$list->yuanqu_id=2;
|
|
|
}
|
|
|
$list->keshiname="健康管理中心";
|
|
|
$list->jiuzhendidian="健康管理中心1区";
|
|
|
if($list->sex==1) $list->jiuzhendidian="健康管理中心(1楼男宾区)";
|
|
|
if($list->sex==2) $list->jiuzhendidian="健康管理中心(2楼女宾区)";
|
|
|
$list->zhuyishixiang="";
|
|
|
|
|
|
if ($list->status == 1) {
|
|
|
$datetime = new DateTime($list->created_at);
|
|
|
$timestamp = $datetime->getTimestamp();
|
|
|
$list->end_time = $timestamp + (60 * $WaitingPaymentTime);
|
|
|
if (time() > $list->end_time and strpos($list->source, '线下体检预约') === false) {
|
|
|
$list->status = 3;
|
|
|
}
|
|
|
}
|
|
|
if($list->checkup_type_id==4 and $list->status==2 and $list->hunjian_status==0 and !empty($list->appointment_number)){
|
|
|
//查询配偶是否预约
|
|
|
$buy_info=json_decode($list->buy_info,true);
|
|
|
if(isset($buy_info['peiou_info']['sfz'])){
|
|
|
$peiou_check= DB::select("select * from orders where id_number=?
|
|
|
and checkup_type_id = 4
|
|
|
and status in(2,4)
|
|
|
and appointment_number is not null
|
|
|
", [$buy_info['peiou_info']['sfz']]);
|
|
|
if(count($peiou_check)==0){
|
|
|
$datetime = new DateTime($list->created_at);
|
|
|
$timestamp = $datetime->getTimestamp();
|
|
|
$list->end_time = $timestamp + (60 * config('app.globals.WaitingHunJianPeiOuTime'));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
$info_data = [
|
|
|
'list' => $OrderList
|
|
|
];
|
|
|
$info_data = json_encode($info_data, JSON_UNESCAPED_UNICODE);
|
|
|
return \Yz::Return(true,'查询成功',['info' =>$this->AESEncrypt($info_data, $encrypt_iv) , 'iv' => $encrypt_iv]);
|
|
|
}
|
|
|
|
|
|
//给三方(非思信)提供的查询订单详情
|
|
|
public function GetOrderDetail()
|
|
|
{
|
|
|
$encrypted_data = request('encrypted_data');
|
|
|
$iv = request('iv');
|
|
|
if (!isset($iv)) return \Yz::echoError1('加密时使用的iv不能为空');
|
|
|
|
|
|
$encrypted_data = \App\Lib\Tools::AESDecrypt($encrypted_data, config('app.globals.AES_KEY'), $iv);
|
|
|
if (!$encrypted_data) return \Yz::echoError1('encrypted_data解密失败');
|
|
|
$encrypted_data = json_decode($encrypted_data, true);
|
|
|
if (!isset($encrypted_data['order_id'])) return \Yz::echoError1('order_id不能为空');
|
|
|
$order_id = $encrypted_data['order_id'];
|
|
|
$order = DB::table('orders')
|
|
|
->select('id', 'source','title','person_id','checkup_type_id','status','sex', 'name','appointment_number','appointment_date as date', 'appointment_time as time',
|
|
|
DB::raw("CASE WHEN type = 1 THEN '个检' WHEN type = 2 THEN '团检' ELSE 'unknown' END as type"),
|
|
|
'plan_number','price', 'true_price', 'pay_time', 'refund_time', 'hospital_id','doctor','created_at')
|
|
|
->where(['id' => $order_id])->first();
|
|
|
if (!$order) return \Yz::echoError1('订单不存在');
|
|
|
|
|
|
if($order->hospital_id==1){
|
|
|
$order->yuanqu_id=6;
|
|
|
}
|
|
|
if($order->hospital_id==4){
|
|
|
$order->yuanqu_id=2;
|
|
|
}
|
|
|
$order->keshiname="健康管理中心";
|
|
|
$order->jiuzhendidian="健康管理中心1区";
|
|
|
if($order->sex==1) $order->jiuzhendidian="健康管理中心(1楼男宾区)";
|
|
|
if($order->sex==2) $order->jiuzhendidian="健康管理中心(2楼女宾区)";
|
|
|
$order->zhuyishixiang="";
|
|
|
|
|
|
|
|
|
$encrypt_iv = bin2hex(random_bytes(16 / 2));
|
|
|
|
|
|
$info_data = json_encode($order, JSON_UNESCAPED_UNICODE);
|
|
|
return \Yz::Return(true,'查询成功',['info' =>$this->AESEncrypt($info_data, $encrypt_iv) , 'iv' => $encrypt_iv]);
|
|
|
}
|
|
|
function AESEncrypt($data, $encrypt_iv)
|
|
|
{
|
|
|
// return $data;
|
|
|
return \App\Lib\Tools::AESEncrypt($data, config('app.globals.AES_KEY'), $encrypt_iv);
|
|
|
}
|
|
|
}
|