|
- <?php
- require_once __DIR__ . '/../HotelLib.php';
-
- /**
- * Created by PhpStorm.
- * User: luocj
- * Date: 2016/10/18
- * Time: 10:00
- */
- class ModifyHotelOrder extends HotelLib
- {
- function getOrderInfo($order_id)
- {
-
- $sql = "select count(*) as total,stock_type,order_id,order_description,run_date,parent_order_id,prod_id,count(*)*order_price as all_price,prod_name,order_price,base_price,(order_price - base_price)*count(*) as benefit,run_time as checkin_time,order_confirm_code,outside_sale_org_id
- from order_main where parent_order_id=$order_id and cancel_flag = 0 and order_prod_type in (25,26) group by run_date ";
- $rowset = $this->DBTool->queryBySql($sql);
- $data['hotel_child_order_detail'] = $rowset['rowset'];
- $sql = "select order_status,order_description,outside_order_no,parent_prod_name as hotel_name,order_confirm_code,refuse_flag,
- prod_name as product_name,prod_start_station_date as start_date,prod_end_station_date as end_date,
- run_date,run_time as checkin_time,customer_memo,customer_name,customer_mobile,order_price,create_time,order_pay_time
- from order_main where order_prod_type in (25,26) and order_id = $order_id and cancel_flag = 0 and parent_order_id = 0 or outside_order_no = $order_id ";
- $rowset = $this->DBTool->queryBySql($sql);
- $data['hotel_order_detail'][0] = array_change_key_case($rowset['rowset'][0], CASE_LOWER);
-
- // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
- // from run_hotel_distrib as a
- // inner join run_hotel as b on b.id=a.run_id
- // inner join opera_hotel c on c.hotel_id = b.hotel_id
- // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
- // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
- // writeLog('sql= ' . $sql);
- // $order_list = $this->DBTool->queryBySql($sql);
- // $data['yongjinRule'] = $order_list['rowset'];
- return $data;
- }
-
- // function getOrderList($start_date, $end_date, $hotel_id, $room_type, $org_id, $order_id)
- // {
- // //获取库存
- // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
- // from run_hotel_distrib as a
- // inner join run_hotel as b on b.id=a.run_id
- // inner join opera_hotel c on c.hotel_id = b.hotel_id
- // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
- // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and a.saled_count < a.total_count and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
- // writeLog('sql= ' . $sql);
- // $order_list = $this->DBTool->queryBySql($sql);
- // $data['order_stock'] = $order_list['rowset'];
- // $sql = "select order_status,order_description,outside_order_no,parent_prod_name as hotel_name,order_confirm_code,refuse_flag,
- // prod_name as product_name,prod_start_station_date as start_date,prod_end_station_date as end_date,
- // run_date,run_time as checkin_time,customer_memo,customer_name,customer_mobile,order_price,create_time,order_pay_time
- // from order_main where order_id = $order_id and cancel_flag = 0 or outside_order_no = $order_id and parent_order_id = 0 ";
- // $rowset = $this->DBTool->queryBySql($sql);
- // $data['hotel_order_detail'] = $rowset['rowset'];
- // $sql = "select count(*) as total,order_id,order_description,run_date,parent_order_id,prod_id,count(*)*order_price as all_price,prod_name,order_price,base_price,(order_price - base_price)*count(*) as benefit,run_time as checkin_time,order_confirm_code,outside_sale_org_id
- // from order_main where parent_order_id=$order_id and cancel_flag = 0 group by run_date";
- // $rowset = $this->DBTool->queryBySql($sql);
- // $data['hotel_child_order_detail'] = $rowset['rowset'];
- //
- // //当库存为0时,专门获取佣金等
- // $sql = "select b.run_date as run_date,b.stock_type,a.total_count as total_count,a.saled_count as saled_count,b.base_price as base_price,d.back_commision_type as back_commision_type,d.back_commision_method as back_commision_method,d.back_percent as back_percent,d.back_value as back_value,a.cus_price as lingshouprice,a.prod_price as fenxiaoprice,d.commision_flag as commision_flag
- // from run_hotel_distrib as a
- // inner join run_hotel as b on b.id=a.run_id
- // inner join opera_hotel c on c.hotel_id = b.hotel_id
- // inner join base_supplier_sale d on d.supplier_id =a.distrib_id
- // where a.distrib_id=$org_id and b.run_date >= '$start_date' and b.run_date <'$end_date' and b.HOTEL_ID =$hotel_id and b.room_type = $room_type and d.parent_type = 25 and d.cancel_flag = 0 and b.is_onsale = 1 and b.run_status = 1 and a.authority_status = 1 and c.hotel_status = 1 and a.stock_type <> 329";
- // writeLog('sql= ' . $sql);
- // $order_list = $this->DBTool->queryBySql($sql);
- // $data['yongjinRule'] = $order_list['rowset'];
- // return $data;
- // }
-
- // 获取订单状态
- 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 getModifyOrderList($user_id, $hotel_id, $room_type, $org_id, $org_num, $room_list, $cus_list, $checkin_time, $if_cancel, $benefit, $total_commission, $order_id, $logList)
- {
- $MakeOrder = new MakeHotelOrder();
- $rowset = $MakeOrder->makeOrderList($user_id, $hotel_id, $room_type, $org_id, $org_num, $room_list, $cus_list, $checkin_time, $if_cancel, $benefit, $total_commission, $order_id);
-
- if ($rowset['code'] == "0") {
- $sql = "select PROD_ID, PARENT_PROD_ID from order_main where order_id = $order_id and cancel_flag=0";
- $order = $this->DBTool->queryBySql($sql);
- if ($order['code'] == 0) {
- $hotel_id = $order['rowset'][0]['PARENT_PROD_ID'];
- $room_type = $order['rowset'][0]['PROD_ID'];
- } else {
- $hotel_id = 0;
- $room_type = 0;
- }
- $log = '';
- if (is_array($logList) && (count($logList) > 0)) {
- foreach ($logList as $item) {
- $ext_old = '';
- $ext_new = '';
- if ($item['name'] == 'memo') { //备注特殊处理,添加和删除
- $old = explode('||', $item['old_val']);
- $new = explode('||', $item['new_val']);
- $old_arr = array();
- $new_arr = array();
- foreach ($old as $temp) {
- $tmp = explode('|', $temp);
- array_push($old_arr, $tmp[3]);
- }
- foreach ($new as $key => $temp) {
- $tmp = explode('|', $temp);
- $pos = array_search($tmp[3], $old_arr);
- if ($pos || $pos === 0) {
- unset($old_arr[$pos]);
- unset($new_arr[$key]);
- } else
- array_push($new_arr, $tmp[3]);
- }
- $ext_old .= implode(';', $old_arr);
- $ext_new .= implode(';', $new_arr);
- $item['old_val'] = $ext_old;
- $item['new_val'] = $ext_new;
- if ($ext_old != '')
- $ext_old = '删除备注“' . $item['old_val'] . '”';
- if ($ext_new != '')
- $ext_new = '添加备注“' . $item['new_val'] . '”';
-
- $log .= $ext_old . $ext_new;
- } else{
- $log .= "修改" . getLabel($item['name']) . '“' . $item['old_val'] . '”为“' . $item['new_val'] . '”;';
-
- }
- }
- }
- if($order_id != 0){
- $this->setMemcache($order_id, 313);
- }
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => $hotel_id,
- "room_type" => $room_type,
- "log_desc" => "修改订单号为" . $order_id . "的订单: $log",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, '修改订单');
- }
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- return $data;
- }
-
- /**
- * 获取真实姓名
- * @param $user_id
- * @return mixed
- */
- function getTrueName($user_id)
- {
- $sql = "select true_name from base_user where ID=$user_id AND CANCEL_FLAG=0 LIMIT 1";
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset['rowset'][0];
- }
-
- function getBookInfo($order_id)
- {
- $sql = "select A.order_status,F.true_name,A.order_description,A.outside_order_no,A.parent_prod_name as hotel_name,A.order_confirm_code,
- A.prod_name as product_name,A.prod_start_station_date as start_date,A.prod_end_station_date as end_date,
- A.run_date,A.run_time as checkin_time,A.customer_memo,A.customer_name,A.customer_mobile,A.order_price,A.create_time,A.order_pay_time,B.CONFIRM_FROM as org_id,C.org_name,
- (SELECT type_name from dict_type WHERE ID=D.SETT_TYPE) as type_name,
- (SELECT type_name from dict_type WHERE ID=D.SETT_FREQUENCY) as type_time
- from order_main A LEFT JOIN opera_hotel B ON A.PARENT_PROD_ID=B.hotel_id LEFT JOIN base_confirm_organization C
- on B.CONFIRM_FROM=C.ID LEFT JOIN base_supplier D ON B.SUPPLIER_ID=D.ID
- LEFT JOIN base_user F ON A.CREATE_USER_ID=F.ID
- where (A.order_id = '{$order_id}' or A.outside_order_no = '{$order_id}') and A.cancel_flag = 0
- and A.parent_order_id = 0 and C.CANCEL_FLAG=0 AND D.CANCEL_FLAG=0 and A.order_prod_type in (25,26)";
- $rowset = $this->DBTool->queryBySql($sql);
- $data['hotel_order_detail'] = $rowset['rowset'];
- return $data;
- }
-
- //判断是否经过修改
- function isUpdate($order_id)
- {
- $sql = "select id from order_main WHERE parent_order_id=$order_id AND cancel_flag=1";
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset;
- }
-
- function getPrice($order_id)
- {
- // $sql = "select count(*) as num ,prod_start_station_date,
- // (select case stock_type when 228 then b.base_price_buyout when 229 then b.base_price_inquiry when 230 then base_price_reserve end from run_hotel_sub_room b where a.run_date = b.run_date and a.parent_prod_id =b.hotel_id and a.prod_id = b.room_type )*count(*) as base_price
- // from order_main as a
- // 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'];
- }
- // function getO(){
- // $sql="select * from opera_hotel";
- // $rowset = $this->DBTool->queryBySql($sql);
- // $data=$rowset['rowset'];
- // return $data;
- //
- // }
- }
-
- //$ModifyHotelOrder = new ModifyHotelOrder();
- //$data = $ModifyHotelOrder ->getOrderList('2016-09-09','2016-09-11',3,1,41,455390);
- //echo json_encode($data);
-
- //获取备注的字段名称
- function getLabel($key)
- {
- if ($key == '')
- return '';
- $label = '';
- switch ($key) {
- case 'org_id':
- $label = '渠道商';
- break;
- case 'org_num':
- $label = '渠道订单号';
- break;
- case 'start_date':
- $label = '入住时间';
- break;
- case 'end_date':
- $label = '离店时间';
- break;
- case 'total':
- $label = '间夜数';
- break;
- case 'contact':
- $label = '联系人';
- break;
- case 'mobile':
- $label = '联系电话';
- break;
- case 'memo':
- $label = '备注';
- break;
- case 'amount':
- $label = '结算价';
- break;
- }
-
- return $label;
- }
|