|
- <?php
- require_once __DIR__.'/../HotelLib.php';
-
- class HTOrderOperation extends HotelLib
- {
- //渠道接单
- function getGetOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__ . " sql= " . $sql0);
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $this->DBTool->my_pdo->beginTransaction();
- $sql = "update order_main set channel_order_status = '551',
- update_time=now(),
- update_user_id='$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag ='0' ";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $res = $this->DBTool->execSql($sql);
- if ($res['code'] != '0') return array('code'=>'2','info'=>'渠道接单失败');
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '3',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this->set($param_s);
- if($setFlag['code'] != '0') {
- $this->DBTool->my_pdo->rollBack();
- return array('code'=>'1','info'=>'渠道接单失败');
- }
- $this->DBTool->my_pdo->commit();
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "接受渠道订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "接受渠道订单");
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "渠道发送确认单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "渠道发送确认单");
- return array('code'=>'0','info'=>'渠道接单成功');
- }
-
- //渠道拒单
- function getRefuseOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $this->DBTool->my_pdo->beginTransaction();
- if ($merge_status == '2'){//渠道 待处理 订单 待发单
- $sql = "update order_main set channel_order_status = '552',order_status = '148',order_level='2',order_valid_status='0',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- $res = $this->DBTool->execSql($sql);
- if($res['code']!="0")return array("code"=>"1","info"=>"渠道据单失败");
-
- $cancel_flag = 1;
- $sql1 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql1);
-
- } else if($merge_status == '3'){//渠道 待处理 订单 待安排
- $sql = "update order_main set channel_order_status = '552',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- $res = $this->DBTool->execSql($sql);
- } else {
-
- }
- writeLog(__FUNCTION__ . " sql= " . $sql);
- // $res = $this->DBTool->execSql($sql);
- if ($res['code'] == '0'){
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '4',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this->set($param_s);
- if($setFlag['code'] != '0') {
- $this->DBTool->my_pdo->rollBack();
- return array('code'=>'1','info'=>'渠道拒单失败');
- }
- $this->DBTool->my_pdo->commit();
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "拒绝渠道订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "拒绝渠道订单");
- return array('code'=>'0','info'=>'渠道拒单成功');
- }else {
- return array('code'=>'1','info'=>'渠道拒单失败');
- }
-
- }
-
-
- //渠道同意申请取消 包含取消
- function getAgreeApply($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $this->DBTool->my_pdo->beginTransaction();
- $sql = "update order_main set channel_order_status = '563',order_status = '148',order_level='2',order_valid_status='0',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
-
- writeLog(__FUNCTION__."$sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
- if($res['code'] != '0') return array("code"=>"1","info"=>"渠道同意申请取消失败");
-
- $cancel_flag = 1;
- $sql2 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql2);
- if($res['code'] != '0') return array("code"=>"1","info"=>"接口错误");
-
- // if($res['code'] == '0'){
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '3',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this ->set($param_s);
- if($setFlag['code'] != '0'){
- $this -> DBTool -> my_pdo -> rollBack();
- return array('code'=>'1','info'=>'渠道同意申请取消失败');
- }
- $this -> DBTool -> my_pdo -> commit();
-
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "同意渠道取消",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "同意渠道取消");
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "取消订单");
- return array('code'=>'0','info'=>'渠道同意申请取消成功');
- // } else {
- // return ['code'=>'1','info'=>'渠道同意申请取消失败'];
- // }
- }
-
- //渠道拒绝申请取消
- function getRefuseApply($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $this->DBTool->my_pdo->beginTransaction();
- if($merge_status == '30'){
- $sql = "update order_main set channel_order_status = '554',order_status = '314',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- } else {
- $sql = "update order_main set channel_order_status = '554',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- }
- writeLog(__FUNCTION__."$sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
-
- if($res['code'] == '0'){
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '4',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this ->set($param);
- if($setFlag['code'] != '0'){
- $this -> DBTool -> my_pdo -> rollBack();
- return array('code'=>'1','info'=>'渠道申请取消失败');
- }
- $this -> DBTool -> my_pdo -> commit();
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "拒绝渠道取消",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "拒绝渠道取消");
- return array('code'=>'0','info'=>'渠道申请取消成功');
- } else {
- return array('code'=>'1','info'=>'渠道申请取消失败');
- }
- }
-
- //发单
- function getSendOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $sql = "update order_main set order_status = '198',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."$sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "发送确认单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "发单");
-
- return $res;
- }
-
- //确认单
- function getRightOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $order_right_id = $param['order_right_id'];
- $docking = $param['docking'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- if($docking == '556'){//直连
- // $tt = '';
- // if($merge_status == '3'){
- $this->DBTool->my_pdo->beginTransaction();
- $tt = 'channel_order_status="551",';
- // }
- $sql = "update order_main set order_status = '314',order_confirm_code = '$order_right_id',$tt
- order_level = '0',update_time = now(),update_user_id = '$user_id' where (order_id = '$order_id' or parent_order_id = '$order_id')
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."$sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
-
- //渠道推送
- if ($res['code'] == '0'){
- $cancel_status = '';
- if($merge_status == '27' || $merge_status =='35'){
- $cancel_status = 4;
- }else{
- $cancel_status = 3;
- }
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => $cancel_status,
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this->set($param_s);
- if($setFlag['code'] != '0') {
- $this->DBTool->my_pdo->rollBack();
- return array('code'=>'1','info'=>'确认失败');
- }
- $this->DBTool->my_pdo->commit();
-
- //记录日志
- if($merge_status == '3'){
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "接受取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "接受取消订单");
- }else{
-
- }
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "确认订单,确认号{$order_right_id}",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "确认单");
-
- return array('code'=>'0','info'=>'确认成功');
- } else {
- return array('code'=>'1','info'=>'确认失败');
- }
- }else{//录单
- $sql2 = "update order_main set order_status = '314',order_confirm_code = '$order_right_id',
- order_level = '0',update_time = now(),update_user_id = '$user_id' where (order_id = '$order_id' or parent_order_id = '$order_id')
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql2);
- $res = $this -> DBTool -> execSql($sql2);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "确认订单,确认号{$order_right_id}",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "确认单");
- return $res;
-
- }
-
-
- }
-
-
- //取消单
- function getCancelOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $docking = $param['docking'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- writeLog(__FUNCTION__."sql=".$sql);
- // $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- $count = $rowset['rowset'][0]['count'];
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- if($docking =='556' && $merge_status == '27'){//直连 申请取消状态下的取消单
- $this->DBTool->my_pdo->beginTransaction();
- // $temp = '';
- // if ($merge_status == '27'){ //渠道 申请取消 订单 待安排
- $temp = 'channel_order_status = 563,';
- // }
- $sql1 = "update order_main set order_status= '148',order_level='2',order_valid_status='0',$temp
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- $res = $this->DBTool->execSql($sql1);
- if($res['code']!="0")return array("code"=>"1","info"=>"取消单失败");
-
- $cancel_flag = 1;
- $sql2 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql2);
- if($res['code'] != '0') return array("code"=>"1","info"=>"取消单失败");
-
- $cancel_status = '';
- if($merge_status == '27'){
- $cancel_status = 3;
- }else{
- $cancel_status = 4;
- }
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => $cancel_status,
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this->set($param_s);
-
- if($setFlag['code'] != '0'){
- $this -> DBTool -> my_pdo -> rollBack();
- return array('code'=>'1','info'=>'取消单失败');
- }
- $this -> DBTool -> my_pdo -> commit();
-
-
- if($merge_status == '27'){
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "拒绝取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "拒绝取消订单");
- }
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "取消单");
-
-
- return array('code'=>'0','info'=>'取消单成功');
-
- }else{//录单
- $sql_1 = "update order_main set order_status= '148',order_level='2',order_valid_status='0',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql_1);
- $res = $this->DBTool->execSql($sql_1);
- if($res['code']!="0")return array("code"=>"1","info"=>"取消单失败");
-
- $cancel_flag = 1;
- $sql_2 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql_2);
-
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "取消单");
- return $res;
- }
-
-
-
- }
-
-
- //退改
- function getRefundOrder($param){
- $order_id = $param['order_id'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $channel_order_status = $param['channel_order_status'];
- $order_status = $param['order_status'];
- $cancel_reason = $param['cancel_reason'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $sql1 = "update order_main set order_status = '382',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql1);
- $res = $this -> DBTool -> execSql($sql1);
- if($res['code'] != '0') return array('code'=>'1','info'=>'退改失败');
-
- // $sql2 = "insert into order_comment(order_id,comment_type,comment_txt,create_user_id,create_time,update_user_id,update_time)
- // values('$order_id',2,'$cancel_reason','$user_id',now(),'$user_id',now())";
- $sql2 = "insert into order_ht_apply_bounce(order_id,reason,create_user_id,create_time,update_user_id,update_time) values ('$order_id','$cancel_reason','$user_id',now(),'$user_id',now())";
- $res = $this->DBTool->execSql($sql2);
-
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "发起退改,退改原因:{$cancel_reason}",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "退改");
- return $res;
-
- }
-
- //取消退改
- function getCancelRefundOrder($param){
- $order_id = $param['order_id'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $channel_order_status = $param['channel_order_status'];
- $order_status = $param['order_status'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $sql1 = "update order_main set order_status = '314',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql1);
- $res = $this -> DBTool -> execSql($sql1);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "取消退改申请",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "取消退改");
- return $res;
- }
-
- //退单
- function getRefundBill($param){
- $order_id = $param['order_id'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $channel_order_status = $param['channel_order_status'];
- $order_status = $param['order_status'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $sql1 = "update order_main set order_status = '564',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql1);
- $res = $this -> DBTool -> execSql($sql1);
-
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "向供应商申请退单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "退单");
- return $res;
- }
-
- //同意退单
- function getAgreeRefundBill($param){
- $order_id = $param['order_id'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $channel_order_status = $param['channel_order_status'];
- $order_status = $param['order_status'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
- $docking = $param['docking'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- if($docking == '556'){//直连
- $this->DBTool->my_pdo->beginTransaction();
- $sql1 = "update order_main set order_status='148',order_level='2',order_valid_status='0',channel_order_status = '563',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql1);
- $res = $this -> DBTool -> execSql($sql1);
- if($res['code'] != '0') return array('code'=>'1','info'=>'同意退单失败');
-
- $cancel_flag = 4;
- $sql2 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql2);
- if($res['code'] != '0') return array("code"=>"1","info"=>"同意退单失败");
-
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '3',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this ->set($param_s);
- if($setFlag['code'] != '0'){
- $this -> DBTool -> my_pdo -> rollBack();
- return array('code'=>'1','info'=>'同意退单失败');
- }
- $this -> DBTool -> my_pdo -> commit();
-
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "同意退单,订单已取消",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "同意退单,订单已取消");
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "渠道同意退单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "渠道同意退单");
-
- return array('code'=>'0','info'=>'同意退单成功');
-
- }else{//录单
- $sql_1 = "update order_main set order_status = '148',order_level = '2',order_valid_status = '0',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql_1);
- $res = $this -> DBTool -> execSql($sql_1);
- if($res['code'] != '0') return array('code'=>'1','info'=>'同意退单失败');
-
- $cancel_flag = 1;
- $sql_2 = "CALL ht_cancel_order('" . $user_id . "','" . $order_id . "',$cancel_flag)";
- $res = $this->DBTool->execProcedure($sql_2);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "同意退单,订单已取消",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "同意退单,订单已取消");
- return $res;
-
- }
-
-
- }
- //to do
- //拒绝退单
- function getRefuseRefundBill($param){
- $order_id = $param['order_id'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $channel_order_status = $param['channel_order_status'];
- $order_status = $param['order_status'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
- $docking = $param['docking'];
-
- $sql = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'1','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- if ($docking == '556'){//直连
-
- $this->DBTool->my_pdo->beginTransaction();
- $sql1 = "update order_main set order_status='314',channel_order_status = '554',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql1);
- $res = $this -> DBTool -> execSql($sql1);
- if($res['code'] != '0') return array('code'=>'1','info'=>'拒绝退单失败');
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => '4',
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this ->set($param_s);
- if($setFlag['code'] != '0'){
- $this -> DBTool -> my_pdo -> rollBack();
- return array('code'=>'1','info'=>'拒绝退单失败');
- }
- $this -> DBTool -> my_pdo -> commit();
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "渠道拒绝退单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "渠道拒绝退单");
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "拒绝退单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "拒绝退单");
- return array('code'=>'0','info'=>'拒绝退单成功');
-
- }else{ //录单
- $sql_1 = "update order_main set order_status = '314',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."$sql=".$sql_1);
- $res = $this -> DBTool -> execSql($sql_1);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "拒绝退单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "拒绝退单");
- return $res;
-
- }
-
- }
-
-
- //批量发单
- function getBatchSendOrder($list_ary,$user_id){
- $res_ary = array();
- $res_ary['success']=array();
- $res_ary['error']=array();
- $res_ary['refresh']=array();
- $res_ary['cannot']=array();
- foreach ($list_ary as $key => $value) {
- writeLog(json_encode($value));
- $value['user_id'] = $user_id;
- $res = $this->sendOneOrder($value);
- if($res['code']=="0"){
- $res_ary['success'][]=$value['order_id'];
- }else if($res['code']=="1"){
- $res_ary['error'][]=$value['order_id'];
- }else if($res['code']=="2"){
- $res_ary['refresh'][]=$value['order_id'];
- }else if($res['code']=='3'){
- $res_ary['cannot'][]=$value['order_id'];
- }else{
-
- }
-
- }
- $count = count($res_ary['error']) + count($res_ary['refresh']) + count($res_ary['cannot']);
-
- $error_count = count($res_ary['error']);
- $refresh_count = count($res_ary['refresh']);
- $cannot_count = count($res_ary['cannot']);
- $res_ary['success'] = implode(',', $res_ary['success']);
- $res_ary['error'] = implode(',', $res_ary['error']);
- $res_ary['refresh'] = implode(',', $res_ary['refresh']);
- $res_ary['cannot'] = implode(',', $res_ary['cannot']);
-
- $t_str = '';
- if($error_count > 0){
- $t_str = $t_str.'有以下订单发单失败:'.$res_ary['error'].'\n';
- }
- if($refresh_count > 0){
- $t_str = $t_str.'有以下订单需要重新刷新订单状态:'.$res_ary['refresh'].'\n';
- }
- if($cannot_count > 0){
- $t_str = $t_str.'有以下订单无法进行发单操作:'.$res_ary['cannot'].'\n';
- }
-
- $data = array();
- if($count==0){
- $data['code']="0";
- $data['info']="批量操作成功";
- }else{
- $data['code']="1";
- $data['info']="失败";
- $data['success']=$res_ary['success'];
- $data['error']=$res_ary['error'];
- $data['refresh']=$res_ary['refresh'];
- $data['cannot']=$res_ary['cannot'];
- }
- return $data;
- }
-
- //单个发单
- function sendOneOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
-
-
- $merge_status_arr = array("2","10","26","34","30");
- if(!in_array($merge_status, $merge_status_arr)){
- return array('code'=>'3','info'=>'不能发单');
- }
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog('---'.$sql0);
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'2','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- $sql = "update order_main set order_status = '198',
- update_time = now(),
- update_user_id = '$user_id'
- where (order_id = '$order_id' or parent_order_id = '$order_id') and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "发送确认单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "发单");
- return $res;
- }
-
-
-
- //批量确认
- function getBatchRightOrder($list_ary,$user_id){
- $res_ary = array();
- $res_ary['success']=array();
- $res_ary['error']=array();
- $res_ary['refresh']=array();
- $res_ary['cannot']=array();
-
- foreach ($list_ary as $key => $value) {
- $value['user_id'] = $user_id;
- $res = $this-> rightOneOrder($value);
-
- if($res['code']=="0"){
- $res_ary['success'][]=$value['order_id'];
- }else if($res['code']=="1"){
- $res_ary['error'][]=$value['order_id'];
- }else if($res['code']=="2"){
- $res_ary['refresh'][]=$value['order_id'];
- }else if($res['code']=='3'){
- $res_ary['cannot'][]=$value['order_id'];
- }else{
-
- }
-
- }
- $count = count($res_ary['error']) + count($res_ary['refresh']) + count($res_ary['cannot']);
- $error_count = count($res_ary['error']);
- $refresh_count = count($res_ary['refresh']);
- $cannot_count = count($res_ary['cannot']);
- $res_ary['success'] = implode(',', $res_ary['success']);
- $res_ary['error'] = implode(',', $res_ary['error']);
- $res_ary['refresh'] = implode(',', $res_ary['refresh']);
- $res_ary['cannot'] = implode(',', $res_ary['cannot']);
-
- $t_str = '';
- if($error_count > 0){
- $t_str = $t_str.'有以下订单确认失败:'.$res_ary['error'].'\n';
- }
- if($refresh_count > 0){
- $t_str = $t_str.'有以下订单需要重新刷新订单状态:'.$res_ary['refresh'].'\n';
- }
- if($cannot_count > 0){
- $t_str = $t_str.'有以下订单无法进行确认操作:'.$res_ary['cannot'].'\n';
- }
-
- $data = array();
- if($count==0){
- $data['code']="0";
- $data['info']="批量操作成功";
- }else{
- $data['code']="1";
- $data['info']=$t_str;
- $data['success']=$res_ary['success'];
- $data['error']=$res_ary['error'];
- $data['refresh']=$res_ary['refresh'];
- $data['cannot']=$res_ary['cannot'];
- }
- return $data;
- }
-
- //确认单个订单
- function rightOneOrder($param){
- $order_id = $param['order_id'];
- $order_status = $param['order_status'];
- $channel_order_status = $param['channel_order_status'];
- $merge_status = $param['merge_status'];
- $user_id = $param['user_id'];
- $order_right_id = $param['order_right_id'];
- $docking = $param['docking'];
- $outside_order_no = $param['outside_order_no'];
- $interface_order_id = $param['interface_order_id'];
-
-
- $merge_status_arr = array("3","11","27","35");
- if(!in_array($merge_status, $merge_status_arr)){
- return array('code'=>'3','info'=>'不能确认');
- }
-
- $sql0 = "select count(*) as count from order_main
- where order_id = '$order_id' and order_status='$order_status' and channel_order_status='$channel_order_status'
- and order_valid_status = '1' and cancel_flag = '0'";
- $rowset = $this->DBTool->queryBySql($sql0);
- if($rowset['code'] != '0') return array('code'=> '1','info'=>'接口错误');
- $count = isset($rowset['rowset'][0]['count']) ? $rowset['rowset'][0]['count'] : 0;
- if($count == 0){
- return array('code'=>'2','info'=>'订单状态已改变,请重新刷新页面');
- }
-
- if($docking == '556'){//直连
- $this->DBTool->my_pdo->beginTransaction();
- $tt = 'channel_order_status="551",';
- $sql = "update order_main set order_status = '314',order_confirm_code = '$order_right_id',$tt
- order_level = '0',update_time = now(),update_user_id = '$user_id' where (order_id = '$order_id' or parent_order_id = '$order_id')
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."$sql=".$sql);
- $res = $this -> DBTool -> execSql($sql);
-
- //渠道推送
- if ($res['code'] == '0'){
- $cancel_status = '';
- if($merge_status == '27' || $merge_status =='35'){
- $cancel_status = 4;
- }else{
- $cancel_status = 3;
- }
-
- $param_s = array(
- 'OrderID' => $outside_order_no,
- 'InterfaceConfirmNo' => '',
- 'OrderStatus' => $cancel_status,
- 'InterFaceSendID' => $interface_order_id,
- 'channelId' => '1'
- );
- $setFlag = $this->set($param_s);
- if($setFlag['code'] != '0') {
- $this->DBTool->my_pdo->rollBack();
- return array('code'=>'1','info'=>'确认失败');
- }
- $this->DBTool->my_pdo->commit();
-
-
- if($merge_status == '3'){
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "接受取消订单",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "接受取消订单");
- }else{
-
- }
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "确认订单,确认号{$order_right_id}",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "确认单");
- return array('code'=>'0','info'=>'确认成功');
- } else {
- return array('code'=>'1','info'=>'确认失败');
- }
- }else{//录单
- $sql2 = "update order_main set order_status = '314',order_confirm_code = '$order_right_id',
- order_level = '0',update_time = now(),update_user_id = '$user_id' where (order_id = '$order_id' or parent_order_id = '$order_id')
- and order_valid_status = '1' and cancel_flag = '0'";
- writeLog(__FUNCTION__."sql=".$sql2);
- $res = $this -> DBTool -> execSql($sql2);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "确认订单,确认号{$order_right_id}",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "确认单");
- return $res;
-
- }
- }
-
- function getCommentTxt($order_ids){
-
- $ids = implode(",", $order_ids);
-
- $sql = "select comment_txt,order_id from order_comment where order_id in ({$ids}) and cancel_flag = 0";
-
- $data = $this->DBTool->queryBySql($sql);
- if($data['code']!="0")return $data;
-
- $arr = array();
- foreach($data['rowset'] as $k => $v){
- $arr[$v['order_id']][] = $v['comment_txt'];
- }
- return $arr;
-
- }
-
- public function set($param)
- {
- $url = 'http://demo.zhizhuchuxing.cn/hotel/set/set-order-status';
- $return = $this -> httpsPostParam($url,$param);
- return $return;
- }
-
-
-
- function httpsPostParam($url, $param = array())
- {
- $ch = curl_init(); // 初始化一个 cURL 对象
- curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
- curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
- // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
- ));
- $rtn = curl_exec($ch); // 运行cURL,请求网页
- if ($errno = curl_errno($ch)) {
- return array('code'=>'1','info'=>'接口调用失败!');
- }
- curl_close($ch); // 关闭URL请求
- // return json_decode($rtn, true); // 返回获取的数据
- return array('code'=> '0','info'=> '对接成功');
- }
- }
-
-
-
- ?>
|