|
- <?php
- /**
- *
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 娄梦宁
- * PhpStorm OrderlistModel.php
- * Create By 2016/11/11 10:31 $
- */
-
-
- namespace Order\Model;
-
- use Base\Tool\DbTable;
- use Base\Tool\Tool;
- use Util\Util\Util;
-
- class OrderlistModel extends DbTable
- {
- public $db = 'CST';
-
- /**
- * Function Description:获取订单列表
- * Function Name: getordering
- * @param $userId
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getordering($userId)
- {
- //判断哪些是周边游订单,哪些是普通订单
- $sql = "" . "SELECT
- c.line_type,
- a.order_id
- FROM
- order_main a
- LEFT JOIN opera_line c ON c.line_id = a.PARENT_PROD_ID
- WHERE
- a.MEMBER_ID = $userId
- and a.outside_sale_org_id = 164
- AND a.parent_order_id = 0
- AND a.cancel_flag = 0
- GROUP BY
- a.order_id";
- $arr1 = $this->fetchAll($sql);
- $around = '';
- $normol = '';
- foreach ($arr1 as $v) {
- if ($v['line_type'] == 369) {
- $around .= $v['order_id'] . ',';
- } else {
- $normol .= $v['order_id'] . ',';
- }
- }
- $around = rtrim($around, ',');
- $normol = rtrim($normol, ',');
- //进行中
- $sql = "" . "SELECT
- a.order_status,
- a.order_id,
- a.create_time,
- floor(a.order_price) as price,
- a.order_status,
- substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1) AS pnum,
- b.PROD_START_STATION_DATE AS start_date,
- b.PROD_START_STATION_TIME AS start_time,
- b.PROD_end_STATION_TIME AS end_time,
- b.PROD_START_STATION_res_NAME AS start_station,
- b.PROD_end_STATION_res_NAME AS end_station,
- curdate() AS WEEK,
- b.PROD_START_STATION_area_NAME as start_city,
- b.PROD_end_STATION_area_NAME as end_city
- FROM
- order_main a
- INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
- WHERE
- a.order_id in ($normol)
- and a.outside_sale_org_id = 164
- and a.order_status in (145,146)
- and a.cancel_flag=0
- and b.cancel_flag=0
- GROUP BY
- a.ORDER_ID
- ORDER BY start_date desc ,start_time desc
- ";
- $result1 = $this->fetchAll($sql);
- $sql = "" . "SELECT
- a.order_status,
- a.order_id,
- a.create_time,
- floor(a.order_price) as price,
- a.order_status,
- 369 as 'line_type',
- substring_index(a.ORDER_DESCRIPTION, '|' ,- 1) AS pnum,
- b.PROD_START_STATION_DATE AS start_date,
- b.PROD_START_STATION_TIME AS start_time,
- b.PROD_end_STATION_TIME AS end_time,
- b.PROD_START_STATION_res_NAME AS start_station,
- b.PROD_end_STATION_res_NAME AS end_station,
- curdate() AS WEEK,
- b.PROD_START_STATION_area_NAME as start_city,
- b.PROD_end_STATION_area_NAME as end_city,
- c.line_name,
- ifnull(c.line_describe,'') as line_describe
- FROM
- order_main a
- INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
- LEFT JOIN opera_line c ON a.PARENT_PROD_ID = c.line_id
- WHERE
- a.order_id in ($around)
- and a.outside_sale_org_id = 164
- and a.order_status in (145,146)
- and a.cancel_flag=0
- and b.cancel_flag=0
- GROUP BY
- a.ORDER_ID
- ORDER BY start_date desc ,start_time desc
- ";
- $result3 = $this->fetchAll($sql);
- $result1 = array_merge($result1, $result3);
- //已完成
- $sql = "" . "SELECT
- a.order_status,
- a.order_id,
- a.create_time,
- floor(a.order_price) as price,
- a.order_status,
- substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1) AS pnum,
- b.PROD_START_STATION_DATE AS start_date,
- b.PROD_START_STATION_TIME AS start_time,
- b.PROD_end_STATION_TIME AS end_time,
- b.PROD_START_STATION_res_NAME AS start_station,
- b.PROD_end_STATION_res_NAME AS end_station,
- curdate() AS WEEK,
- b.PROD_START_STATION_area_NAME as start_city,
- b.PROD_end_STATION_area_NAME as end_city,
- curdate() AS WEEK
- FROM
- order_main a
- INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
- WHERE
- a.order_id in ($normol)
- and a.outside_sale_org_id = 164
- and a.order_status in (147,148)
- and a.cancel_flag=0
- and b.cancel_flag=0
- GROUP BY
- a.ORDER_ID
- ORDER BY start_date desc ,start_time desc
- ";
- $result2 = $this->fetchAll($sql);
- $sql = "" . "SELECT
- a.order_status,
- a.order_id,
- a.PARENT_ORDER_ID,
- a.create_time,
- 369 as 'line_type',
- floor(a.order_price) as price,
- a.order_status,
- substring_index(a.ORDER_DESCRIPTION, '|' ,- 1) AS pnum,
- b.PROD_START_STATION_DATE AS start_date,
- b.PROD_START_STATION_TIME AS start_time,
- b.PROD_end_STATION_TIME AS end_time,
- b.PROD_START_STATION_res_NAME AS start_station,
- b.PROD_end_STATION_res_NAME AS end_station,
- curdate() AS WEEK,
- b.PROD_START_STATION_area_NAME as start_city,
- b.PROD_end_STATION_area_NAME as end_city,
- c.line_name,
- ifnull(c.line_describe,'') as line_describe
- FROM
- order_main a
- INNER JOIN order_main b ON a.order_id = b.PARENT_ORDER_ID
- LEFT JOIN opera_line c ON a.PARENT_PROD_ID = c.line_id
- WHERE
- a.order_id in ($around)
- and a.outside_sale_org_id = 164
- and a.order_status in (147,148)
- and a.cancel_flag=0
- and b.cancel_flag=0
- GROUP BY
- a.ORDER_ID
- ORDER BY start_date desc ,start_time desc
- ";
- $result4 = $this->fetchAll($sql);
- $result2 = array_merge($result2, $result4);
- if ($result1 === false || $result2 === false) {
- return Util::returnArrEr('获取订单失败!');
- } else {
- $new1 = array();
- $new2 = array();
- foreach ($result1 as $k => $v) {
- if ($v['week'] != $v['start_date']) {
- $wek =Tool::getWeek($v['start_date']);
- $result1[$k]['week'] = $wek;
- } else {
- $result1[$k]['week'] = "今天";
- }
- $result1[$k]['start_date'] = substr($result1[$k]['start_date'], 5, 5);
- $key = $result1[$k]['start_date'].$result1[$k]['start_time'].$result1[$k]['order_id'];
- $new1[$key] = $result1[$k];
- }
- foreach ($result2 as $k => $v) {
- if ($v['week'] != $v['start_date']) {
- $wek =Tool::getWeek($v['start_date']);
- $result2[$k]['week'] = $wek;
- } else {
- $result2[$k]['week'] = "今天";
- }
- $key = $result2[$k]['start_date'].$result2[$k]['start_time'].$result2[$k]['order_id'];
- $result2[$k]['start_date'] = substr($result2[$k]['start_date'], 5, 5);
- $new2[$key] = $result2[$k];
- }
- krsort($new1);
- krsort($new2);
- $new1=array_values($new1);
- $new2=array_values($new2);
- $result = array(
- 'doing' => $new1,
- 'done' => $new2
- );
- return Util::returnArrSu('', $result);
- }
- }
-
- /**
- * Function Description:获取订单详情
- * Function Name: getOrderall
- * @param $order_id
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getOrderall($order_id)
- {
- //判断是否有返程,若有返程,获取返程order_id
- $sql = "select back_orderid,to_orderid from to_from where to_orderid= $order_id or back_orderid=$order_id limit 1";
- $back = $this->fetchAll($sql);
- if (count($back) == 1) {
- //有返程
- $back_orderid = $back[0]['back_orderid'];
- $to_orderid = $back[0]['to_orderid'];
- $id = "$to_orderid,$back_orderid";
- } elseif (count($back) == 0) {
- $id = $order_id;
- } else {
- return Util::returnArrEr('获取返程详情失败!');
- }
- $sql = '' . "select PARENT_PROD_ID from order_main where order_id=$order_id ";
- $around = $this->fetchOne($sql);
- if ($around != 0) {
- $temp = 'a';
- $pnum = "substring_index(a.ORDER_DESCRIPTION, '|' ,- 1)";
- } else {
- $temp = 'c';
- $pnum = "substring_index(substring_index(a.ORDER_DESCRIPTION,',',-1),'|',1)";
- }
- $sql = '' . "SELECT
- c.run_date,
- b.line_id,
- a.order_id,
- a.create_time,
- a.order_status,
- c.PROD_START_STATION_res_NAME AS start_station,
- c.PROD_end_STATION_res_NAME AS end_station,
- $pnum AS pcount,
- substring_index(a.ORDER_DESCRIPTION, ',', 1) AS seat_type,
- a.customer_name,
- a.customer_mobile,
- floor(a.order_price) as order_price,
- c.PROD_START_STATION_DATE AS start_date,
- c.PROD_START_STATION_TIME AS start_time,
- c.PROD_end_STATION_TIME AS end_time,
- b.line_type,
- ifnull(b.line_describe,'') as line_describe,
- b.line_name,
- a.ORDER_PROD_TYPE as testaround
- FROM
- order_main a
- LEFT JOIN order_main c ON c.PARENT_ORDER_ID = a.order_id
- LEFT JOIN opera_line b ON $temp.PARENT_PROD_ID = b.line_id
- WHERE
- a.cancel_flag = 0
- AND b.cancel_flag = 0
- AND a.order_id IN ($id)
- and a.outside_sale_org_id = 164
- GROUP BY
- a.order_id
- ORDER BY
- a.order_id ";
- $result = $this->fetchAll($sql);
- if ($result === false) {
- return Util::returnArrEr('获取订单详情失败!');
- } else {
- $price = 0;
- foreach ($result as $v) {
- $price += (int)$v['order_price'];
- }
- $result['price'] = $price;
- $starttime = $result[0]['start_date'] . " " . $result[0]['start_time'];
- $timer = strtotime($starttime) - time();
- //判断是否可以退票
- if ($timer > 1800) {
- $result['back_ticket'] = 1;
- } else {
- $result['back_ticket'] = 0;
- }
- //判断是否是周边游,是周边游则查出出行人信息
- if ($result[0]['testaround'] == 369) {
- $sql = ""."SELECT DISTINCT
- c.PROD_start_STATION_res_NAME AS start_station,
- c.PROD_START_STATION_DATE AS end_date,
- c.PROD_START_STATION_TIME AS end_time,
- c.PROD_end_STATION_res_NAME as end_station
- FROM
- order_main a
- INNER JOIN order_main c ON a.order_id = c.PARENT_ORDER_ID
- WHERE
- a.PROD_START_STATION_res_id <> c.PROD_START_STATION_res_id
- and a.order_id=$order_id
- ";
- $shou = $this->fetchAll($sql);
- $result[1] = $result[0];
- $result[1]['start_station'] = $shou[0]['start_station'];
- $result[1]['start_date'] = $shou[0]['end_date'];
- $result[1]['start_time'] = $shou[0]['end_time'];
- $result[1]['end_station'] = $shou[0]['end_station'];
- $result[1]['line_type'] = 369;
- $sql = ""."SELECT DISTINCT
- b.customer_name as p_name,
- b.CUSTOMER_ID_NO as p_phone
- FROM
- order_main a
- INNER JOIN order_main b ON a.order_id = b.parent_order_id
- WHERE
- a.order_id IN ($id)
- ";
- $result1 = $this->fetchAll($sql);
- if ($result1 === false) {
- return Util::returnArrEr('获取出行人信息失败!');
- } else {
- $result['customer'] = $result1;
- }
- }
- foreach ($result as $k => $v) {
- if ( strtotime(date('Y-m-d', time())) != strtotime($v['start_date'])) {
- $wek =Tool::getWeek($v['start_date']);
- $result[$k]['week'] = $wek;
- } else {
- $result[$k]['week'] = '今天';
- }
- $result[$k]['start_date'] = date('m月j日', strtotime($result[$k]['start_date']));
- }
-
- if (isset($result[1])) {
- $result['trip_type'] = 2;
- } else {
- $result['trip_type'] = 1;
- }
- if ($result[0]['order_status'] == 145) {
- $timer = time() - strtotime($result[0]['create_time']);
- if ($timer < 900 && $timer > 0) {
- $result['timer'] = 900 - $timer;
- } else {
- $result['timer'] = 0;
- }
- } else {
- $result['timer'] = 0;
- }
- $result['order_id'] = $id;
- $result['order_status'] = $result[0]['order_status'];
- $result['line_type'] = $result[0]['line_type'];
- return Util::returnArrSu('', $result);
- }
- }
-
- /**
- * Function Description:取消订单调用存储过程
- * Function Name: cancel_order
- * @param $order_id
- * @param $user_id
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function cancel_order($order_id, $user_id)
- {
- // $sql = "call SP_CANCEL_ORDER($user_id,$order_id) ";
- // $result = $this->execSql($sql);
- $cancel_url = 'http://'.CS1_DOMAIN.'/api/submit-order/cancel-bus-order';
- $send_post_data = array(
- "order_id" => $order_id,
- "user_id" => $user_id,
- "if_link" => 0,
- "cancel_reason" => "用户取消订单",
- 'opera_platform' => '微信商城'
- );
- $result = Util::httpRequest( $cancel_url, $send_post_data );
- $result_array = json_decode($result, true);
-
- if ($result_array === false || !isset($result_array["code"]) || $result_array["code"] != 0 ) {
- return Util::returnArrEr('取消订单失败!');
- } else {
- return Util::returnArrSu('取消订单成功');
- }
- }
- }
|