|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194 |
- <?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'=> '对接成功');
- }
- }
-
-
-
- ?>
|