|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: fuhc
- * Date: 2017/4/14
- * Time: 11:42
- */
-
- //修改酒店订单
- require_once __DIR__ . '/../HotelLib.php';
- require_once __DIR__ . '/MakeHotelOrder.class.php';
-
- class HTUpdateOrderLevelLib extends HotelLib
- {
-
- // order_level 对酒店订单:订单操作状态(0:确认单 1:修改单 2:取消单)
-
- //1.入住需求
- //1.1修改入住需求 //用的原来的修改订单接口
- function orderUpdateCheckIn($param)
- {
- $MakeOrderLib = new MakeHotelOrder();
- $user_id = $param['user_id'];
- $hotel_id = $param['hotel_id'];
- $room_type = $param['room_type'];
- $org_id = $param['org_id'];
- $org_num = $param['org_num'];
- $room_list = $param['room_list'];
- $room_count = $param['room_count'];
- $cus_list = $param['cus_list'];
- $checkin_time = $param['checkin_time'];
- $start_date = $param['start_date'];
- $end_start = $param['end_date'];
- $if_cancel = $param['if_cancel'];
- $benefit = $param['benefit'];
- $total_commission = $param['total_commission'];
- $order_id = $param['order_id'];
-
- $org_name = $this->orgNameGet($org_id);
- $old_room_count = $this->roomCountGet($order_id);
- $sql = "SELECT A.PARENT_PROD_ID AS hotel_id,
- A.PROD_ID AS room_type,
- A.OUTSIDE_ORDER_NO AS outside_order_no,
- A.PROD_START_STATION_DATE AS start_date,
- A.PROD_END_STATION_DATE AS end_date,
- A.OUTSIDE_SALE_ORG_ID AS outside_sale_org_id,
- B.SUPPLIER_NAME as supplier_name
- FROM ORDER_MAIN AS A
- INNER JOIN BASE_SUPPLIER AS B ON B.ID = A.OUTSIDE_SALE_ORG_ID
- WHERE A.ORDER_ID = '{$order_id}'
- AND A.ORDER_VALID_STATUS=1
- AND A.CANCEL_FLAG = 0 LIMIT 1";
-
- $order = $this->DBTool->queryBySql($sql);
- $log_arr = array();
- if ($order['code'] != "0") return $order;
- // $log="修改入住需求:修改订单渠道【{$old_supplier_name}】为【{$org_name}】;
- // 修改渠道订单号【{$old_outside_order_no}】为【{$org_num}】;
- // 修改入住日期【{$old_start_date}】为【{$start_date}】;修改间夜数【{$old_room_count}】为【{$room_count}】";
- $old_hotel_id = $order['rowset'][0]['hotel_id'];
- $old_room_type = $order['rowset'][0]['room_type'];
- $old_outside_order_no = $order['rowset'][0]['outside_order_no'];
- $old_start_date = $order['rowset'][0]['start_date'];
- $old_end_date = $order['rowset'][0]['end_date'];
- $old_outside_sale_org_id = $order['rowset'][0]['outside_sale_org_id'];
- $old_supplier_name = $order['rowset'][0]['supplier_name'];
- $log_arr[] = $org_name == $old_supplier_name ? "" : "修改订单渠道【{$old_supplier_name}】为【{$org_name}】;";
- $log_arr[] = $org_num == $old_outside_order_no ? "" : "修改渠道订单号【{$old_outside_order_no}】为【{$org_num}】;";
- $log_arr[] = $start_date == $old_start_date ? "" : "修改入住日期【{$old_start_date}】为【{$start_date}】;";
- $log_arr[] = $room_count == $old_room_count ? "" : "修改间夜数【{$old_room_count}】为【{$room_count}】;";
- if (count($log_arr) <= 0) return array("code" => "0", "info" => "没有修改任务内容");
- if (count($log_arr) > 0) array_unshift($log_arr, "修改入住需求:");
-
- $rowset = $MakeOrderLib->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") return $rowset;
- // $sql = "SELECT PROD_ID, PARENT_PROD_ID FROM ORDER_MAIN WHERE ORDER_ID = $order_id AND CANCEL_FLAG=0";
- // $order = $this->DBTool->queryBySql($sql);
- $log = implode('', $log_arr);
- writeLog("log---log---" . $log);
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => $hotel_id,
- "room_type" => $room_type,
- "log_desc" => $log,
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, '修改订单');
- if ($order_id != 0) {
- $this->setMemcache($order_id, 313);
- }
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- return $data;
- }
-
- //1.1.1获取库存
- function stockGetList($param)
- {
- $hotel_id = $param['hotel_id'];
- $parent_room_type = $param['parent_room_type'];
- $room_type = $param['room_type'];
- $org_id = $param['org_id'];
- $start_date = $param['start_date'];
- $end_date = $param['end_date'];
-
- $nullP = ifNullParam(array($hotel_id, $parent_room_type, $room_type, $org_id, $start_date, $end_date));
- if ($nullP['code'] != "0") return $nullP;
- $sql = "CALL ht_get_room_stock({$hotel_id},{$parent_room_type},{$room_type},{$org_id},'{$start_date}','{$end_date}')";
- writeLog(__FUNCTION__ . " sql= " . $sql);
- $rowset = $this->DBTool->execProcedure($sql);
- $data['code'] = $rowset['code'];
- $data['info'] = $rowset['info'];
- $data['price_info_list'] = isset($rowset['rowset'][0]) ? $rowset['rowset'][0] : array();
- $data['stock_list'] = isset($rowset['rowset'][1]) ? $rowset['rowset'][1] : array();
- $data['order_list'] = $rowset['rowset'];
- return $data;
- }
-
- //1.2修改销售价
- function orderUpdateXSJ($param)
- {
- $order_id = $param['order_id'];
- $user_id = $param['user_id'];
- $room_list = $param['room_list'];
- $data = array();
- try {
- $this->DBTool->my_pdo->beginTransaction();
-
- //得到订单 是 录单还是直连
- // 556:直连 557:录单
- $order_property = $this->orderPropertyGet($order_id);
- $docking_type = $order_property['docking_type'];
- if ("556" == $docking_type) throw new PDOException("事务异常-直连订单不允许修改销售价");
-
- foreach ($room_list as $k => $v) {
- $order_price = $v['order_price'];
- $run_date = $v['run_date'];
- // if(''==trim($order_price))return array("code"=>"50orderUpdateXSJ","info"=>"参数错误!");
- // if(''==trim($run_date))return array("code"=>"50orderUpdateXSJ","info"=>"参数错误!");
- //根据修改的值从数据库中查询是否存在 若存在,则说明没有进行修改
- $sql_0 = "select count(*) as count from order_main
- where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_price = '{$order_price}'
- and order_valid_status = 1
- and cancel_flag=0 limit 1";
- $data_0 = $this->DBTool->queryBySql($sql_0);
- if ($data_0['code'] != "0") throw new PDOException("事务异常");
- $count_0 = isset($data_0['rowset'][0]['count']) ? $data_0['rowset'][0]['count'] : "1";
- if ("1" == $count_0) return array("code" => "0", "info" => "您没有进行修改");
-
- //原来的销售价
- $sql_0_1 = "SELECT ORDER_PRICE AS old_order_price FROM order_main where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0 limit 1";
- $data_0_0 = $this->DBTool->queryBySql($sql_0_1);
- $old_order_price = $data_0_0['rowset'][0]['old_order_price'];
-
- $sql_1 = "select ({$order_price}-base_price) as profit_value from order_main where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0 limit 1";
- $data_1 = $this->DBTool->queryBySql($sql_1);
- $profit_value = 0;
- if ("0" == $data_1['code']) $profit_value = isset($data_1['rowset'][0]['profit_value']) ? $data_1['rowset'][0]['profit_value'] : "0";
- if ("0" != $data_1['code']) throw new PDOException("事务异常");
- //更改销售价和利润
- $sql_2 = "update order_main
- set order_price = '{$order_price}',
- profit_value=$profit_value,
- update_time = now(),
- update_user_id = '{$user_id}'
- where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0";
-
- $data = $this->DBTool->execSql($sql_2);
- if ($data['code'] != "0") throw new PDOException("事务异常");
-
- //3.更改主订单的销售总价
- //3.1查到子订单销售单价的总和
- $sql_3_1 = "SELECT
- SUM(ORDER_PRICE) AS sum_order_price,
- SUM(PROFIT_VALUE) AS sum_profit_value
- FROM ORDER_MAIN
- WHERE PARENT_ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0 LIMIT 1";
- $rowset = $this->DBTool->queryBySql($sql_3_1);
- if ($rowset['code'] != "0") throw new PDOException("事务异常");
- $sum_order_price = isset($rowset['rowset'][0]['sum_order_price']) ? $rowset['rowset'][0]['sum_order_price'] : "-1";
- $sum_profit_value = isset($rowset['rowset'][0]['sum_profit_value']) ? $rowset['rowset'][0]['sum_profit_value'] : "-1";
-
-
- //3.2将销售单价总和更改到主订单
- $sql_3_2 = "UPDATE ORDER_MAIN
- SET ORDER_PRICE = '{$sum_order_price}',
- PROFIT_VALUE = '{$sum_profit_value}',
- UPDATE_USER_ID = '{$user_id}',
- UPDATE_TIME = NOW()
- WHERE ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0";
- $rowset = $this->DBTool->execSql($sql_3_2);
- if ($rowset['code'] != "0") throw new PDOException("事务异常");
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "修改销售价:修改【{$run_date}】销售价【{$old_order_price}】为【{$order_price}】",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "修改订单");
- }
- $this->DBTool->my_pdo->commit();
- } catch (PDOException $ex) {
- $data['code'] = "17";
- $data['info'] = "事务异常";
- $this->DBTool->my_pdo->rollBack();
- }
-
- return $data;
-
- }
-
- //1.3修改采购价
- function orderUpdateCGJ($param)
- {
- $order_id = $param['order_id'];
- $user_id = $param['user_id'];
- $cus_list = $param['cus_list'];
- $data = array();
- try {
- $this->DBTool->my_pdo->beginTransaction();
- foreach ($cus_list as $k => $v) {
- $base_price = $v['base_price'];
- $run_date = $v['run_date'];
- //根据修改的值从数据库中查询是否存在 若存在,则说明没有进行修改
- $sql_0 = "select count(*) as count
- from order_main
- where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and base_price = '{$base_price}'
- and order_valid_status = 1
- and cancel_flag = 0 limit 1";
- $data_0 = $this->DBTool->queryBySql($sql_0);
- if ($data_0['code'] != "0") throw new PDOException("事务异常11");
- $count_0 = $data_0['rowset'][0]['count'];
-
- if ("1" == $count_0) return array("code" => "0", "info" => "您没有进行修改");
-
- //原来的成本价
- $sql_0_1 = "SELECT BASE_PRICE AS old_base_price from order_main where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0";
- writeLog($sql_0_1);
- $data_0_1 = $this->DBTool->queryBySql($sql_0_1);
- $old_base_price = $data_0_1['rowset'][0]['old_base_price'];
-
- $sql_1 = "select (order_price - {$base_price}) as profit_value from order_main where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0";
- $data_1 = $this->DBTool->queryBySql($sql_1);
- $profit_value = 0;
- if ("0" == $data_1['code']) $profit_value = isset($data_1['rowset'][0]['profit_value']) ? $data_1['rowset'][0]['profit_value'] : "0";
- if ("0" != $data_1['code']) throw new PDOException("事务异常22");
- $status_arr1 = array("198", "382"); //需要生成修改单
- $cstr = "";
- $order_property = $this->orderPropertyGet($order_id);
- $order_status = $order_property['order_status'];
- $status_agree_update_arr = array("313", "198", "382"); //待发单-待安排-退改中
- if (!in_array($order_status, $status_agree_update_arr)) throw new PDOException("事务异常-目前只有待发单-待安排-退改中状态的订单允许进行修改");
- if (in_array($order_status, $status_arr1)) {
- $cstr = "order_level = '1',";
- $sql = "UPDATE ORDER_MAIN
- SET ORDER_LEVEL='1'
- WHERE (ORDER_ID = '{$order_id}' OR PARENT_ORDER_ID = '{$order_id}')
- and order_valid_status = 1
- and cancel_flag=0";
- writeLog("fuhc-" . $sql);
- $res = $this->DBTool->execSql($sql);
- if ($res['code'] != "0") throw new PDOException("事务异常cc");
- }
- $sql = "update order_main
- set base_price = '{$base_price}',
- profit_value=$profit_value,
- update_time = now(),{$cstr}
- update_user_id = '{$user_id}'
- where parent_order_id = '{$order_id}'
- and run_date = '{$run_date}'
- and order_valid_status = 1
- and cancel_flag=0";
- writeLog(__FUNCTION__ . "修改采购价 sql = 【" . $sql . "】");
- $data = $this->DBTool->execSql($sql);
-
-
- if ($data['code'] != "0") throw new PDOException("事务异常33");
-
-
- //3.更新主订单的成本价和利润
- //3.1查到子订单成本价和利润
- $sql_3_1 = "SELECT
- SUM(BASE_PRICE) AS sum_base_price,
- SUM(PROFIT_VALUE) AS sum_profit_value
- FROM ORDER_MAIN
- WHERE PARENT_ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0 LIMIT 1";
- $rowset = $this->DBTool->queryBySql($sql_3_1);
- if ($rowset['code'] != "0") throw new PDOException("事务异常44");
- $sum_base_price = isset($rowset['rowset'][0]['sum_base_price']) ? $rowset['rowset'][0]['sum_base_price'] : "-1";
- $sum_profit_value = isset($rowset['rowset'][0]['sum_profit_value']) ? $rowset['rowset'][0]['sum_profit_value'] : "-1";
-
-
- //3.2将销售单价总和更改到主订单
- $sql_3_2 = "UPDATE ORDER_MAIN
- SET BASE_PRICE = '{$sum_base_price}',
- PROFIT_VALUE = '{$sum_profit_value}',
- UPDATE_USER_ID = '{$user_id}',
- UPDATE_TIME = NOW()
- WHERE ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0";
- $rowset = $this->DBTool->execSql($sql_3_2);
- if ($rowset['code'] != "0") throw new PDOException("事务异常55");
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "修改采购价:修改【{$run_date}】采购价【{$old_base_price}】为【{$base_price}】",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, "修改订单");
- }
- $this->DBTool->my_pdo->commit();
- } catch (PDOException $ex) {
- $data['code'] = "17";
- $data['info'] = $ex->getMessage();
- $this->DBTool->my_pdo->rollBack();
- }
-
- return $data;
- }
-
-
- //修改客人信息
- function customerUpdate($param)
- {
- $order_id = $param['order_id'];
- $customer_name = $param['customer_name'];
- $customer_mobile = $param['customer_mobile'];
- $user_id = isset($param['user_id']) ? $param['user_id'] : "0";
-
-
- //原来的客人信息
- $sql_0 = "SELECT CUSTOMER_NAME AS customer_name,
- CUSTOMER_MOBILE as customer_mobile,
- ORDER_STATUS AS order_status
- FROM ORDER_MAIN
- WHERE ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0 LIMIT 1";
- $data = $this->DBTool->queryBySql($sql_0);
- $old_customer = $data['rowset'][0];
- $order_status = $data['rowset'][0]['order_status'];
- if ($old_customer['customer_name'] == $customer_name && $old_customer['customer_mobile'] == $customer_mobile) {
- return array("code" => "0", "info" => "客人信息没有修改");
- }
- $status_arr1 = array("198", "382");
- $cstr = "";
- if (in_array($order_status, $status_arr1)) {
- $cstr = "order_level = '1',";
- }
- $sql = "update order_main
- set customer_name = '$customer_name',
- customer_mobile = '$customer_mobile',
- update_user_id = '$user_id',{$cstr}
- update_time = now()
- where (parent_order_id = '$order_id' or order_id = '$order_id')
- and order_valid_status=1
- and cancel_flag = 0";
- writeLog(__FUNCTION__ . "修改客人信息 sql=" . $sql);
- $rowset = $this->DBTool->execSql($sql);
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "修改客人信息:修改客人信息【{$old_customer['customer_name']},{$old_customer['customer_mobile']}】为【{$customer_name},{$customer_mobile}】",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, '修改订单');
- return $rowset;
- }
-
- //新增订单备注
- function commentAdd($param)
- {
- $order_id = $param['order_id'];
- $comment_type = $param['comment_type'];
- if (!in_array($comment_type, array("0", "1"))) return array("code" => "20", "info" => "备注类型应为内部或公共!");
- $comment_txt = trim($param['comment_txt']);
- $user_id = isset($param['user_id']) ? $param['user_id'] : "0";
- $rowset = array();
- try {
- $this->DBTool->my_pdo->beginTransaction();
- $sql1 = "insert into order_comment (order_id,comment_type,comment_txt,create_user_id,create_time,update_user_id,update_time)
- values('$order_id','$comment_type','$comment_txt','$user_id',now(),'$user_id',now())";
-
- //0:内部备注
- $log = '';
- if ("0" == $comment_type) {
- writeLog(__FUNCTION__ . "sql1=[" . $sql1 . "]");
- $rowset = $this->DBTool->execSql($sql1);
- if ($rowset['code'] != "0") throw new PDOException("事务异常22");
- $log = "添加备注:【内部备注】【{$comment_txt}】";
- }
-
- //1:公共备注
- $sql2 = "";
- if ("1" == $comment_type) {
- //大兵哥说公共备注也不生成修改单 2017/4/21
- // $order_property = $this->orderPropertyGet($order_id);
- // $order_status = $order_property['order_status'];
- // $status_agree_update_arr = ["313","198","201"]; //待发单-待安排-退改中
- // if(!in_array($order_status,$status_agree_update_arr))throw new PDOException("事务异常-目前只有待发单-待安排-退改中状态的订单允许进行修改");
- // $status_arr1 = ["198", "201"]; //需要生成修改单
- // if (in_array($order_status, $status_arr1)) {
- // $sql2 = "update order_main
- // set order_level = 1,
- // update_user_id = '$user_id',
- // update_time = now()
- // where (parent_order_id = $order_id or order_id = $order_id)
- // and order_valid_status=1
- // and cancel_flag = 0";
- // $rowset = $this->DBTool->execSql($sql1);
- // if($rowset['code']!="0")throw new PDOException("事务异常55");
- // $rowset = $this->DBTool->execSql($sql2);
- // if($rowset['code']!="0")throw new PDOException("事务异常33");
- // }else{
- $rowset = $this->DBTool->execSql($sql1);
- if ($rowset['code'] != "0") throw new PDOException("事务异常44");
- // }
- writeLog(__FUNCTION__ . "sql1=[" . $sql1 . "]sql2=[" . $sql2 . "]");
-
- $log = "添加备注:【公共备注】【{$comment_txt}】";
- }
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => $log,
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, '修改订单');
- $this->DBTool->my_pdo->commit();
- } catch (PDOException $ex) {
- $data['code'] = "17";
- $data['info'] = $ex->getMessage();
- $this->DBTool->my_pdo->rollBack();
- }
- return $rowset;
- }
-
- //删除订单备注
- function commentDel($param)
- {
- $order_id = $param['order_id'];
- $comment_id = $param['comment_id'];
- $user_id = isset($param['user_id']) ? $param['user_id'] : "0";
-
- $sql_0 = "SELECT COMMENT_TXT as comment_txt,
- COMMENT_TYPE as comment_type,
- CASE COMMENT_TYPE WHEN 0 THEN '内部备注'
- WHEN 1 THEN '公共备注' END AS comment_type_desc
- FROM ORDER_COMMENT WHERE ID ='{$comment_id}' AND CANCEL_FLAG = 0 LIMIT 1";
- $comment = $this->DBTool->queryBySql($sql_0);
- $old_comment_txt = $comment['rowset'][0]['comment_txt'];
- $old_comment_type_desc = $comment['rowset'][0]['comment_type_desc'];
-
- $sql = "UPDATE ORDER_COMMENT
- SET CANCEL_FLAG=1,
- UPDATE_USER_ID='$user_id',
- UPDATE_TIME=NOW()
- WHERE ID = $comment_id AND CANCEL_FLAG=0";
- writeLog(__FUNCTION__ . "sql=[" . $sql . "]");
- $rowset = $this->DBTool->execSql($sql);
-
- $model = array(
- "user_id" => $user_id,
- "log_type" => 3,
- "hotel_id" => "0",
- "room_type" => "0",
- "log_desc" => "删除备注:【{$old_comment_type_desc}】【{$old_comment_txt}】",
- "order_id" => $order_id
- );
- $this->DBLog->insertLog($model, '修改订单');
- return $rowset;
- }
-
- //根据订单号得到订单当前状态,是录单或直连
- private function orderPropertyGet($order_id)
- {
- $sql = "select order_status,docking_type
- from order_main
- where order_id = '{$order_id}'
- and order_valid_status = 1
- and cancel_flag = 0 limit 1";
- $data = $this->DBTool->queryBySql($sql);
-
- return $data[0];
- }
-
- //根据父订单号统计房间数量
- private function roomCountGet($order_id)
- {
- $sql = "SELECT COUNT(*) AS room_count FROM ORDER_MAIN
- WHERE PARENT_ORDER_ID = '{$order_id}'
- AND ORDER_VALID_STATUS = 1
- AND CANCEL_FLAG = 0 LIMIT 1";
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset['rowset'][0]['room_count'];
- }
-
- //根据渠道id得到渠道名称
- private function orgNameGet($id)
- {
- $sql = "SELECT SUPPLIER_NAME AS supplier_name
- FROM base_supplier
- WHERE ID = '{$id}' AND CANCEL_FLAG = 0";
- $rowset = $this->DBTool->queryBySql($sql);
- return $rowset['rowset'][0]['supplier_name'];
- }
- }
|