DBTool->queryBySql($sql); $now_status = $tmp['rowset'][0]['order_status']; $data = array(); //修改订单与异常状态修改订单状态不区分 if ($order_status==$now_status){ $data['code'] = 0; $data['info'] = ''; }else{ $data['code'] = 10; $data['info'] = '请刷新页面后重试'; } return $data; } //查询订单渠道 function getOrgList() { $sql = "select a.id as org_id ,a.supplier_name as org_name from base_supplier a inner join base_supplier_sale b on a.id = b.supplier_id where a.cancel_flag = 0 and a.supplier_type = 301 and a.is_disabled = 0 and b.parent_type = 25"; writeLog('sql= ' . $sql); $org_list = $this->DBTool->queryBySql($sql); $data['code'] = $org_list['code']; $data['info'] = $org_list['info']; $data['org_list'] = $org_list['rowset']; return $data; } //酒店订单列表,调用存储过程 function getOrderList($para_date_type, $para_start_date, $para_end_date, $para_province, $para_city, $para_hotel_name, $para_order_status, $para_org_id, $para_more_search, $current, $page_size, $confirm_number ,$para_channel_order_status) { $sql = "CALL ht_test_order2 ('" . $para_date_type . "','" . $para_start_date . "','" . $para_end_date . "'," . $para_province . "," . $para_city . ",'" . $para_hotel_name . "','" . $para_order_status . "','" . $para_org_id . "','" . $para_more_search . "'," . $current . "," . $page_size . ",'" . $confirm_number . "','" . $para_channel_order_status . "')"; //$sql = "CALL `ht_get_order_list`(0, '2016-09-19', '2016-09-20',0,0,' ',0,0,0,1,10)"; writeLog(__FUNCTION__ . " sql= " . $sql); $data = array(); $rowset = $this->DBTool->execProcedure($sql); if ($rowset['code'] != '0') return array('code'=>'1','info'=>'查询订单列表失败'); $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; $data['order_list'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array(); $data['current'] = isset($rowset['rowset'][1][0]['currpage']) ? $rowset['rowset'][1][0]['currpage'] : '1'; $data['page_size'] = isset($rowset['rowset'][1][0]['pagesize']) ? $rowset['rowset'][1][0]['pagesize'] : '1'; $data['total'] = isset($rowset['rowset'][1][0]['num']) ? $rowset['rowset'][1][0]['num'] : '0'; $data['total_page'] = isset($rowset['rowset'][1][0]['pagecount']) ? $rowset['rowset'][1][0]['pagecount'] : '1'; $data['wait_count'] = isset($rowset['rowset'][1][0]['wait_count']) ? $rowset['rowset'][1][0]['wait_count'] : "0"; $data['cancel_count'] = isset($rowset['rowset'][1][0]['cancel_count']) ? $rowset['rowset'][1][0]['cancel_count'] : "0"; $data['out_count'] = isset($rowset['rowset'][1][0]['out_count']) ? $rowset['rowset'][1][0]['out_count'] : "0"; // $order_ary = []; // foreach ($data['order_list'] as $key => $value) { // $order_ary[] = $value['order_id']; // } // // // // foreach($order_ary as $k => $v){ // // $sql = "select " // // // // } return $data; } /** * 获取user_id对应的真实姓名 * @param $user_id * @return mixed * */ function getUserTrueName($user_id) { // $sql = "select true_name from base_user where id={$user_id} AND CANCEL_FLAG=0 LIMIT 1"; $sql = "select true_name from base_user where id={$user_id} LIMIT 1"; $true_name = $this->DBTool->queryBySql($sql); writeLog(__FUNCTION__ . " sql= " . $sql); return $true_name['rowset'][0]; } //导出订单信息 function outOrderList($para_date_type, $para_start_date, $para_end_date, $para_province, $para_city, $para_hotel_name, $para_order_status, $para_org_id, $para_more_search, $current, $page_size) { $sql = "CALL ht_out_order_list ('" . $para_date_type . "','" . $para_start_date . "','" . $para_end_date . "'," . $para_province . "," . $para_city . ",'" . $para_hotel_name . "'," . $para_order_status . "," . $para_org_id . ",'" . $para_more_search . "'," . $current . "," . $page_size . ")"; // $sql = "CALL `ht_get_order_list`(0, '2016-09-19', '2016-09-20',0,0,' ',0,0,0,1,10)"; writeLog(__FUNCTION__ . " sql= " . $sql); $data = array(); $rowset = $this->DBTool->execProcedure($sql); $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; $data['order_list'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array(); $data['current'] = isset($rowset['rowset'][1][0]['currpage']) ? $rowset['rowset'][1][0]['currpage'] : '1'; $data['page_size'] = isset($rowset['rowset'][1][0]['pagesize']) ? $rowset['rowset'][1][0]['pagesize'] : '1'; $data['total'] = isset($rowset['rowset'][1][0]['num']) ? $rowset['rowset'][1][0]['num'] : '1'; $data['total_page'] = isset($rowset['rowset'][1][0]['pagecount']) ? $rowset['rowset'][1][0]['pagecount'] : '1'; return $data; } //酒店确认,内部确认不需要发rtx function getMakeSure($make_sure_order_id, $make_sure_num, $user_id, $outside = 0) { $today = date('Y-m-d H:i:s', time()); $sql = "update order_main set order_status = 314,order_confirm_code = '$make_sure_num' where order_id = " . $make_sure_order_id . " or parent_order_id =" . $make_sure_order_id; writeLog('sql= ' . $sql); $rowset = $this->DBTool->execSql($sql); $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($make_sure_order_id,314,198,0,1,'$today',1,'$today')"; writeLog('sql= ' . $sql); $rowset = $this->DBTool->execSql($sql); $data['make_sure_order_id'] = $make_sure_order_id; if ($rowset['code'] == "0") { $this->setMemcache($make_sure_order_id, 314); $supplier_name = $this->getSupplierName($make_sure_order_id); $outside ? $this->sendMessageToRTX("酒店确认通知", "$supplier_name \n已完成订单确认:$make_sure_order_id") : true; $model = array( "user_id" => $user_id, "log_type" => 3, "hotel_id" => 0, "room_type" => 0, "log_desc" => "订单号为" . $make_sure_order_id . "的状态由待确认变为已安排,确认号为" . $make_sure_num, "order_id" => $make_sure_order_id ); $this->DBLog->insertLog($model, '变为已安排'); } return $data; } //取消订单 function getCancelOrder($cancel_order_id, $user_id, $cancel_order_status) { $today = date('Y-m-d H:i:s', time()); $cancel_flag = 1; if ($cancel_order_status == 382) { //这里需要判断是修改的取消,还是直接取消 //如果是修改的取消,修改后订单的状态值应该变为382,而如果是直接取消,应该直接变为383 $cancel_flag = 4; } $sql = "select order_status from order_main where ORDER_ID = $cancel_order_id and cancel_flag = 0 and order_valid_status = 1"; $res = $this->DBTool->queryBySql($sql); $before_status = 313; //待发单 if ($res['code'] == 0 && !empty($res['rowset'])) $before_status = $res['rowset'][0]['order_status']; //取消订单前判断该订单是否为已取消148 383 if ($before_status == 148 ||$before_status==383){ $data['code'] = '5'; $data['info'] = '请刷新当前页面再尝试'; return $data; } //end $sql = "CALL ht_cancel_order(" . $user_id . "," . $cancel_order_id . ",$cancel_flag)"; writeLog(__FUNCTION__ . " sql= " . $sql); $data = array(); $rowset = $this->DBTool->execProcedure($sql); $status_name = ''; //已取消有2种状态,1、所有正常取消148,2、酒店已安排,我们异常处理并取消了订单383 $sql = "select type_name from dict_type WHERE id = $before_status"; $res = $this->DBTool->queryBySql($sql); if ($res['code'] == 0 && !empty($res['rowset'])) $status_name = $res['rowset'][0]['type_name']; $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($cancel_order_id,$cancel_order_status,$before_status,0,$user_id,'{$today}',$user_id,'{$today}')"; writeLog(__FUNCTION__ . " sql= " . $sql); $rowset = $this->DBTool->execSql($sql); $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; //正常取消,清空memcache缓存;已安排 异常处理 取消订单 这种情况不清空 if ($cancel_order_status == 382) { $this->setMemcache($cancel_order_id, 383); } else $this->resetMemcache($cancel_order_id); if ($rowset['code'] == "0") { $model = array( "user_id" => $user_id, "log_type" => 3, "hotel_id" => 0, "room_type" => 0, "log_desc" => "订单号为" . $cancel_order_id . "的状态由" . $status_name . "变为已取消", "order_id" => $cancel_order_id ); $this->DBLog->insertLog($model, '变为已取消'); } return $data; } //取消原因 function getCancelReason($cancel_order_id, $cancel_reason, $user_id, $comment_type = 0) { $today = date('Y-m-d H:i:s', time()); $sql = "insert into order_comment(order_id,comment_type,comment_txt,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($cancel_order_id,$comment_type,'{$cancel_reason}',0,$user_id,'{$today}',$user_id,'{$today}')"; $rowset = $this->DBTool->execSql($sql); $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; return $data; } /** * 发送确认单 * User: Steven * @param $order_id 订单号 * @param $user_id 操作人 * @return mixed */ public function getBilling($order_id, $user_id) { $today = date('Y-m-d H:i:s', time()); $sql = "update order_main set order_status = 198,update_time ='$today', order_disable_type = 0 where order_id = " . $order_id . " or parent_order_id =" . $order_id; $rowset = $this->DBTool->execSql($sql); if ($rowset['code'] == "0") { $this->setMemcache($order_id, 198); $model = array( "user_id" => $user_id, "log_type" => 3, "hotel_id" => 0, "room_type" => 0, "log_desc" => "订单号为" . $order_id . "的状态由待发单变为待确认", "order_id" => $order_id ); $this->DBLog->insertLog($model, '变为待确认'); } $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,198,313,0,$user_id,'{$today}',$user_id,'{$today}')"; writeLog(__FUNCTION__ . " sql= " . $sql); $rowset = $this->DBTool->execSql($sql); return $data; } function getHandleOrder($order_id, $user_id, $text_reason, $order_status, $order_status_name) { //382:酒店异常处理待发单 383已取消(区别于148) 待酒店确认退单 $today = date('Y-m-d H:i:s', time()); $new_status = 313; if ($order_status == 314) { //在酒店已经安排的情况下异常订单处理,应该把订单状态变更成异常处理代发单状态(区别于常规的代发单) $new_status = 382; } $sql = "update order_main set order_status = $new_status, is_up=0 , update_time ='$today' where order_id = " . $order_id . " or parent_order_id =" . $order_id; writeLog("update_order_main =" . $sql); $rowset = $this->DBTool->execSql($sql); $sql = "insert into order_comment(order_id,comment_type,comment_txt,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,2,'$text_reason',0,$user_id,'{$today}',$user_id,'{$today}')"; writeLog("handleOrder =" . $sql); $rowset = $this->DBTool->execSql($sql); if ($rowset['code'] == "0") { $this->setMemcache($order_id, 313); $model = array( "user_id" => $user_id, "log_type" => 3, "hotel_id" => 0, "room_type" => 0, "log_desc" => "订单号为" . $order_id . "的状态由" . $order_status_name . "变为待发单", "order_id" => $order_id ); $this->DBLog->insertLog($model, '异常订单处理'); } $data['code'] = $rowset['code']; $data['info'] = $rowset['info']; $sql = "update order_ht_status_log set cancel_flag = 1 where order_id =" . $order_id; $rowset = $this->DBTool->execSql($sql); $sql = "insert into order_ht_status_log(order_id,order_status,before_status,cancel_flag,create_user_id,create_time,update_user_id,update_time) values ($order_id,313,$order_status,0,$user_id,'{$today}',$user_id,'{$today}')"; $rowset = $this->DBTool->execSql($sql); return $data; } //下订单后 存入短信信息 function makeMessage($order_id, $mobile, $message, $now, $user_id) { $sql = "insert into order_send_message (id,order_id,send_mobile,send_message,send_time,create_user_id,create_time,update_user_id,update_time) VALUES ((select max(b.id)+1 from order_send_message as b),'$order_id','$mobile','$message','$now','$user_id','$now','$user_id','$now')"; writeLog(__FUNCTION__ . " sql= " . $sql); $rowset = $this->DBTool->execSql($sql); return $rowset; } //重发短信 查询所需的电话号码 // function getMoble($order_id) // { // $sql = "select send_mobile from order_send_message WHERE order_id='$order_id'"; // writeLog(__FUNCTION__ . " sql= " . $sql); // $rowset = $this->DBTool->queryBySql($sql); // return $rowset['rowset']; // } //查询已发短信条数和内容 function getMessageInfo($order_id) { $sql = "select send_message from order_send_message WHERE order_id='$order_id'"; $sqlt = "select count(order_id) from order_send_message WHERE order_id='$order_id'"; $message = $this->DBTool->queryBySql($sql); $count = $this->DBTool->queryBySql($sqlt); $data['code'] = $message['code']; $data['message'] = $message['rowset']; $data['count'] = $count['rowset'][0]; return $data; } //查询短信所需信息 function getmessage($order_id) { $sql = "select customer_name, parent_prod_name, order_description, hotel_address, customer_mobile from order_main AS A LEFT JOIN opera_hotel AS B on A.parent_prod_name=B.hotel_name WHERE order_id='$order_id' AND A.cancel_flag=0"; $rowset = $this->DBTool->queryBySql($sql); return $rowset['rowset'][0]; } /** * 获取供应商的采购负责人 * @param $supplier_id * @return mixed */ public function getPurchaser($supplier_id) { $sql = "select id as purchaser_id,purchaser_name from base_supplier_purchase where supplier_id=$supplier_id and product_type=25 and cancel_flag=0"; $rowset = $this->DBTool->queryBySql($sql); return $rowset['rowset'][0]; } /** * 获取运营人员 * @param $hotel_id * @return mixed */ public function getPrincipal($hotel_name) { $hotel_name = trim($hotel_name); $sql = "select true_name from base_user where id in (select principal from opera_hotel where hotel_name = '$hotel_name')"; $rowset = $this->DBTool->queryBySql($sql); $tmp = array(); foreach ($rowset['rowset'] as $k => $v) { $tmp[] = $v['true_name']; } $data = implode(',',$tmp); return $data; } function getPrice($order_id) { $sql = "select count(*) as num ,prod_start_station_date,A.base_price*count(*) as base_price from order_main as A LEFT JOIN run_hotel as B on A.run_id=B.id WHERE A.cancel_flag = 0 and A.parent_order_id='$order_id' GROUP BY PROD_START_STATION_DATE"; $rowset = $this->DBTool->queryBySql($sql); return $rowset['rowset']; } } // //$HTOrderList = new HTOrderList(); //$data = $HTOrderList->getMessageInfo(474455); // ////////$data =$HTOrderList ->getOrgList(); ////////$data =$HTOrderList ->getHandleOrder(4565465, 1, 'hehehehe',148); //echo json_encode($data);