|
- <?php
- require_once __DIR__ . '/../HotelLib.php';
-
- /**
- * Created by PhpStorm.
- * User: gaohan
- * Date: 2016/11/22
- * Time: 17:04
- */
- class OutHotelOrderListModel extends HotelLib
- {
- //供应商订单列表
- function getOrderList($date_type, $start_date, $end_date, $order_status, $supplier_id, $more_search, $current, $page_size)
- {
- $sql = "CALL ht_get_order_list_for_supplier('$date_type', '$start_date', '$end_date', '$order_status','$supplier_id', '$more_search', $current, $page_size)";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $data = array();
- $rowset = $this->DBTool->execProcedure($sql);
- if ($rowset['code'] == "2") {
- $data['code'] = '1';
- $data['info'] = "系统异常";
- return $data;
- }
- if ($rowset['rowset'][0]) {
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- $data['num'] = $rowset['rowset'][2];
- $data['order_list'] = $rowset['rowset'][0];
- $data['current'] = $rowset['rowset'][1][0]['currpage'];
- $data['page_size'] = $rowset['rowset'][1][0]['pagesize'];
- $data['total'] = $rowset['rowset'][1][0]['num'];
- $data['total_page'] = $rowset['rowset'][1][0]['pagecount'];
- } else {
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- $data['num'] = $rowset['rowset'][2];
- $data['order_list'] = '';
- }
-
-
- return $data;
- }
-
- //获取供应商ID
- function getSupplierId($user_id)
- {
- $sql = "select org_id from base_user WHERE id=$user_id";
- $res = $this->DBTool->queryBySql($sql);
- if ($res['code'] == 0) {
- return $res['rowset'][0]['org_id'];
- } else {
- return 0;
- }
- }
-
- /**
- * 酒店拒单
- * @param $cancel_order_id
- * @param $user_id
- * @param $cancel_order_status
- * @return array
- */
- function getCancelOrder($cancel_order_id, $user_id, $cancel_order_status)
- {
- $status_name = '';
- $today = date('Y-m-d H:i:s', time());
- //已取消有2种状态,1、所有正常取消148,2、酒店已安排,我们异常处理并取消了订单383
- $sql = "select type_name from dict_type where id = $cancel_order_status";
- $res = $this->DBTool->queryBySql($sql);
- if ($res['code'] == 0 && !empty($res['rowset']))
- $status_name = $res['rowset'][0]['type_name'];
-
- $sql = "CALL ht_cancel_order(" . $user_id . "," . $cancel_order_id . ", 1)";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $data = array();
- $rowset = $this->DBTool->execProcedure($sql);
- if ($rowset['code'] == "0") {
- $this->resetMemcache($cancel_order_id);
- $supplier_name = $this->getSupplierName($cancel_order_id);
- $this->sendMessageToRTX("酒店拒单", "$supplier_name \n拒绝订单:$cancel_order_id ");
- $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, '酒店拒单');
- }
- $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,148,$cancel_order_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'];
- return $data;
- }
-
- //酒店确认退单 type 1, 酒店拒绝退单 type 2 不依据dict_type表
- //如果是拒绝退单,需要将订单状态变更为已安排,订单状态order_valid_status要还原为
- function htConfirmCancel($order_id, $user_id, $confirm_type=1)
- {
- $today = date('Y-m-d H:i:s', time());
- if($confirm_type == 1)
- $sql = "update order_main set order_disable_type = $confirm_type where order_id = {$order_id} or parent_order_id = {$order_id}";
- else{
- $sql = "update order_main set ORDER_VALID_STATUS = 1 ,order_disable_type = $confirm_type , order_status = 314 where order_id = {$order_id} or parent_order_id = {$order_id}";
- }
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $data = array();
- $rowset = $this->DBTool->execProcedure($sql);
- if ($rowset['code'] == "0") {
- $this->resetMemcache($order_id);
- $supplier_name = $this->getSupplierName($order_id);
- if($confirm_type == 1)
- $msg = "确认";
- else
- $msg = "拒绝";
- $this->sendMessageToRTX("酒店{$msg}退单", "$supplier_name \n订单号:$order_id ");
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => 0,
- "room_type" => 0,
- "log_desc" => "供应商{$msg}退单,订单号为" . $order_id,
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "{$msg}退单");
- }
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- return $data;
- }
-
- //获取订单详情
- function getOrderDetail($order_id)
- {
- $sql = "select order_status,order_confirm_code,parent_prod_name,prod_name,prod_start_station_date,prod_end_station_date,customer_name,customer_mobile,customer_memo
- from order_main WHERE order_id='$order_id' AND cancel_flag=0";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset['rowset'][0];
- }
-
- // 获取订单状态
- function getOrderStatus($order_id)
- {
- $sql = "select order_id,order_status,create_time,(select type_name from dict_type where a.ORDER_STATUS = id ) as order_status_name
- from order_ht_status_log a where order_id = $order_id and cancel_flag = 0";
- $rowset = $this->DBTool->queryBySql($sql);
- writeLog(json_encode($rowset));
- $data['order_status'] = $rowset['rowset'];
- //$data['order_status'] = array("create_time" => "2016-10-19 11:11:10", "order_status_name" => $rowset['rowset'][0]["order_status_name"]);
- return $data;
- }
-
- //获取订单详情的子订单信息
- function getChildOrderDetail($order_id)
- {
- $sql = "select A.run_date,count(A.run_date) as num,A.base_price,A.base_price*count(A.run_date) as total,A.run_time
- from order_main as A LEFT JOIN run_hotel as B on A.run_id=B.id WHERE A.parent_order_id='$order_id' and A.cancel_flag=0 GROUP BY RUN_DATE";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset['rowset'];
- }
-
- function getPrice($order_id)
- {
- // $sql="select count(*) as num ,prod_start_station_date,B.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";
- // writeLog(__FUNCTION__ . " sql= " . $sql);
- // $rowset = $this->DBTool->queryBySql($sql);
- // return $rowset['rowset'];
-
- $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'];
- }
- }
|