@ -4,6 +4,7 @@ namespace App\Http\Controllers\API\Internal;
use App\Http\Controllers\API\PEISApiController;
use App\Http\Controllers\API\PEISApiController;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Controller;
use DateTime;
use Illuminate\Http\Request;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\DB;
@ -240,5 +241,161 @@ class OrderController extends Controller
return \Yz::echoErrorJson("未获取到预约信息");
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);
}
}
}