'预订日期', '入住日期', '离店日期']; // public $search_status; /** * @inheritdoc */ public function rules() { return [ [['date_from', 'date_to', 'search_key', 'date_type', 'ORDER_STATUS', 'CHANNEL_ORDER_STATUS', 'sub_refuse_flag', 'hotel_name', 'channel_id', 'diret_flag', 'confirm_num', 'PROD_START_STATION_DATE', 'hotel_id', 'PROD_END_STATION_DATE', 'invoice_status', 'peiru', 'peichu'], 'safe'], ]; } public function getSupplier() { return $this->hasOne(BaseSupplier::className(), ['ID' => 'PROD_TOP_ORG_ID']); } /** * @Author wanglg * @Desc 导出订单列表查询 * @param $params * @return ActiveDataProvider */ public function exportList($params) { $query = self::find()->joinWith('statusLabel a') ->joinWith('allMemo') ->joinWith('salesMan') ->joinWith('channelStatusLabel b'); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => false, 'pagination' => false, ]); $this->load($params); $query->andFilterWhere([ 'order_main.CANCEL_FLAG' => 0, 'ORDER_PROD_TYPE' => 25, //酒店主订单 ]); $query->addSelect(['order_main.*', 'b.type_name as channel_type_name', 'GROUP_CONCAT(order_comment.COMMENT_TXT separator ";") AS CUSTOMER_MEMO', '(select count(*) from order_main m where m.PARENT_ORDER_ID=order_main.order_id AND m.CANCEL_FLAG=0) as room_count']); $query->andFilterWhere(['or', ['like', 'order_main.ORDER_ID', trim($this->search_key)], ['like', 'CUSTOMER_NAME', trim($this->search_key)], ['like', 'CUSTOMER_MOBILE', trim($this->search_key)]]); //预订时间 $date_start = ' 00:00:00'; $date_end = ' 23:59:59'; if ($this->date_type == 2) { $query->andFilterWhere(['or', ['and', ['<=', 'PROD_START_STATION_DATE', $this->date_from], ['>', 'prod_end_station_date', $this->date_from]], ['and', ['<=', 'prod_start_station_date', $this->date_to], ['>', 'prod_end_station_date', $this->date_to]], ['and', ['>=', 'prod_start_station_date', $this->date_from], ['<=', 'prod_end_station_date', $this->date_to]]]); } elseif ($this->date_type == 3) { $date_column = 'PROD_END_STATION_DATE'; $query->andFilterWhere(['between', $date_column, $this->date_from, $this->date_to]); } else { $date_column = 'order_main.CREATE_TIME'; $query->andFilterWhere(['between', $date_column, $this->date_from . $date_start, $this->date_to . $date_end]); if ($this->PROD_START_STATION_DATE != '' || $this->PROD_END_STATION_DATE != '') { //注意,查询时这里的PROD_END_STATION_DATE不是离店日期,是入住的范围终点 $this->PROD_START_STATION_DATE == '' ? $this->PROD_START_STATION_DATE = $this->PROD_END_STATION_DATE : true; $this->PROD_END_STATION_DATE == '' ? $this->PROD_END_STATION_DATE = $this->PROD_START_STATION_DATE : true; $query->andFilterWhere(['between', 'order_main.PROD_START_STATION_DATE', $this->PROD_START_STATION_DATE, $this->PROD_END_STATION_DATE]); } } if ($this->diret_flag) { //直连标志 $query->andFilterWhere(['order_main.DOCKING_TYPE' => $this->diret_flag]); } if ($this->confirm_num) { if ($this->confirm_num == 1) { $query->andFilterWhere(['NOT', ['order_main.ORDER_CONFIRM_CODE' => 'null']]); } else { $query->andWhere(['order_main.ORDER_CONFIRM_CODE' => null]); } } if ($this->channel_id) { $query->andFilterWhere(['order_main.OUTSIDE_SALE_ORG_ID' => $this->channel_id]); } if ($this->hotel_name) { $query->andFilterWhere(['like', 'order_main.PARENT_PROD_NAME', trim($this->hotel_name)]); } $query->groupBy('order_main.ORDER_ID'); $query->orderBy(['CREATE_TIME' => SORT_DESC]); if ($this->ORDER_STATUS) { $query->andFilterWhere(['order_main.ORDER_STATUS' => $this->ORDER_STATUS]); } if ($this->CHANNEL_ORDER_STATUS) { $query->andFilterWhere(['order_main.CHANNEL_ORDER_STATUS' => $this->CHANNEL_ORDER_STATUS]); } $query->groupBy('order_main.ORDER_ID'); $sql = $query->createCommand()->getRawSql(); return $dataProvider; // return $query -> asArray() -> all(); } /** * Author:Steven * Desc:酒店订单列表 * @param $params * @return array */ public function search_list($params) { //statusLabel 订单状态 $query = self::find()->joinWith('statusLabel a') ->joinWith(['user', 'allMemo', 'operaHotelRoom', 'baseChannel', 'channelStatusLabel b', 'orderInvoiceInfo c'])/*->joinWith('user') ->joinWith('allMemo') ->joinWith('operaHotelRoom') ->joinWith('baseChannel') ->joinWith('channelStatusLabel b') ->joinWith('orderInvoiceInfo c')*/ ; // add conditions that should always apply here ->leftJoin('dict_type a','order_main.CHANNEL_ORDER_STATUS=dict_type.ID') $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => false, 'pagination' => [ 'pageSize' => 20, ] ]); $this->load($params); #region 功能描述数据权限 //酒店运营人员只能看到自己运营的酒店订单,酒店采购负责人只能看到自己采购的酒店订单,其他(酒店管理人员、酒店客服人员、酒店客服管理人员)数据均可见 $user_role = Yii::$app->user->identity->USER_ROLE; //获取当前用户的角色 if ($user_role == BaseUserAuth::HOTEL_OPERATOR) { //酒店运营人员 ||$user_role==BaseUserAuth::BUS_OPERA_CUS $query->andFilterWhere([ 'order_main.PRINCIPAL_ID' => Yii::$app->user->id, ]); } else if ($user_role == BaseUserAuth::HOTEL_PURCHASE) { //酒店采购负责人 $query->andFilterWhere([ 'order_main.SALES_MAN' => Yii::$app->user->id, ]); } #endregion if (!empty($params['cookie_order_id'])) { $query->andFilterWhere([ 'order_main.ORDER_ID' => $params['cookie_order_id'], ]); } $query->andFilterWhere([ 'order_main.CANCEL_FLAG' => 0, 'ORDER_PROD_TYPE' => 25, //酒店主订单 // 'order_main.ORDER_STATUS' => $this->ORDER_STATUS //前台需要根据不同状态获取数量,这里不需要 ]); $query->addSelect(['order_main.*']); $query->andFilterWhere(['or', ['like', 'order_main.ORDER_ID', trim($this->search_key)], ['like', 'CUSTOMER_NAME', trim($this->search_key)], ['like', 'CUSTOMER_MOBILE', trim($this->search_key)], ['like', 'ORDER_CONFIRM_CODE', trim($this->search_key)], ['like', 'order_main.OUTSIDE_ORDER_NO', trim($this->search_key)]]); //预订时间 $date_start = ' 00:00:00'; $date_end = ' 23:59:59'; if ($this->date_type == 2) { $query->andFilterWhere(['or', ['and', ['<=', 'PROD_START_STATION_DATE', $this->date_from], ['>', 'prod_end_station_date', $this->date_from]], ['and', ['<=', 'prod_start_station_date', $this->date_to], ['>', 'prod_end_station_date', $this->date_to]], ['and', ['>=', 'prod_start_station_date', $this->date_from], ['<=', 'prod_end_station_date', $this->date_to]]]); //日期相同和不同 /*if ($this->date_from == $this->date_to) { $query->andFilterWhere(['PROD_START_STATION_DATE' => $this->date_from]); } else { // $query->andFilterWhere(['and', // ['>=', 'PROD_START_STATION_DATE', $this->date_from], // ['<=', 'PROD_END_STATION_DATE', date('Y-m-d', strtotime('+1 days', strtotime($this->date_to)))]]); $query -> andFilterWhere(['or', ['and', ['<=', 'PROD_START_STATION_DATE', $this->date_from], ['>', 'prod_end_station_date', $this->date_from]], ['and', ['<=', 'prod_start_station_date', $this->date_to], ['>', 'prod_end_station_date', $this->date_to]], ['and', ['>=', 'prod_start_station_date', $this->date_from], ['<=', 'prod_end_station_date', $this->date_to]]]); }*/ } elseif ($this->date_type == 3) { $date_column = 'PROD_END_STATION_DATE'; $query->andFilterWhere(['between', $date_column, $this->date_from, $this->date_to]); } else { $date_column = 'order_main.CREATE_TIME'; $query->andFilterWhere(['between', $date_column, $this->date_from . $date_start, $this->date_to . $date_end]); if ($this->PROD_START_STATION_DATE != '' || $this->PROD_END_STATION_DATE != '') { //注意,查询时这里的PROD_END_STATION_DATE不是离店日期,是入住的范围终点 $this->PROD_START_STATION_DATE == '' ? $this->PROD_START_STATION_DATE = $this->PROD_END_STATION_DATE : true; $this->PROD_END_STATION_DATE == '' ? $this->PROD_END_STATION_DATE = $this->PROD_START_STATION_DATE : true; $query->andFilterWhere(['between', 'order_main.PROD_START_STATION_DATE', $this->PROD_START_STATION_DATE, $this->PROD_END_STATION_DATE]); } // $query->andFilterWhere(['>=', 'order_main.PROD_START_STATION_DATE', $this->date_from]); } if ($this->invoice_status) { $query->andFilterWhere(['c.Status' => $this->invoice_status]); } if ($this->diret_flag) { //直连标志 $query->andFilterWhere(['order_main.DOCKING_TYPE' => $this->diret_flag]); } if ($this->confirm_num) { if ($this->confirm_num == 1) { $query->andFilterWhere(['NOT', ['order_main.ORDER_CONFIRM_CODE' => 'null']]); } else { $query->andWhere(['order_main.ORDER_CONFIRM_CODE' => null]); } } if ($this->channel_id) { $query->andFilterWhere(['order_main.OUTSIDE_SALE_ORG_ID' => $this->channel_id]); } if ($this->hotel_name) { $query->andFilterWhere(['like', 'order_main.PARENT_PROD_NAME', trim($this->hotel_name)]); } $query->groupBy('order_main.ORDER_ID'); $query->orderBy(['CREATE_TIME' => SORT_DESC, 'RUN_DATE'=> SORT_ASC]); $sql = $query->createCommand()->getRawSql(); if ($this->ORDER_STATUS) { $query->andFilterWhere(['order_main.ORDER_STATUS' => $this->ORDER_STATUS]); } if ($this->CHANNEL_ORDER_STATUS) { $query->andFilterWhere(['order_main.CHANNEL_ORDER_STATUS' => $this->CHANNEL_ORDER_STATUS]); } $statusCount = Yii::$app->db->createCommand('select t.order_status,count(*) as count from(' . $sql . ') as t GROUP BY t.ORDER_STATUS')->queryAll(); $channnelStatusCount = Yii::$app->db->createCommand('select t.channel_order_status,count(*) as count from(' . $sql . ') as t GROUP BY t.CHANNEL_ORDER_STATUS')->queryAll(); $status_arr = []; $channel_status_arr = []; foreach ($statusCount as $item) { $status_arr[0] += $item['count']; $status_arr[$item['order_status']] = $item['count']; } foreach ($channnelStatusCount as $item) { $channel_status_arr[$item['channel_order_status']] = $item['count']; } return ['dataProvider' => $dataProvider, 'status_arr' => $status_arr, 'channel_status_arr' => $channel_status_arr]; } /** * 酒店供应商查询列表 * * @param array $params * * @return ActiveDataProvider */ public function supplierSearch($params) { //INNER JOIN order_ht_status_log g on m.ORDER_ID=g.ORDER_ID and g.ORDER_STATUS=198 $query = self::find()->joinWith('statusLabel')->joinWith('user')->joinWith('publicMemo')->joinWith('operaHotel') ->innerJoin('order_ht_status_log', 'order_main.ORDER_ID = order_ht_status_log.ORDER_ID and order_ht_status_log.ORDER_STATUS=198'); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, 'pagination' => [ 'pageSize' => 10, ], 'sort' => false // [ // 'defaultOrder'=> ['CREATE_TIME'=> SORT_DESC], // 'attributes' => false // ] ]); $this->load($params); $login_user = Yii::$app->user->identity; /* @var $login_user \common\models\User */ $this->search_key = trim($this->search_key); $query->andFilterWhere([ 'order_main.CANCEL_FLAG' => 0, 'ORDER_PROD_TYPE' => 25, //酒店主订单 'opera_hotel.SUPPLIER_ID' => $login_user->ORG_ID, //当前账号供应商酒店下的订单 // 'order_main.ORDER_STATUS' => $this->ORDER_STATUS //前台需要根据不同状态获取数量,这里不需要 ]); $query->addSelect([ 'order_main.*', '(select count(*) from order_main m where m.PARENT_ORDER_ID=order_main.order_id AND m.CANCEL_FLAG=0) as room_count', '(select count(*) from order_main m where m.PARENT_ORDER_ID=order_main.order_id AND m.STOCK_TYPE=229 and m.CANCEL_FLAG=0) as sub_refuse_flag', ]); $query->andFilterWhere(['or', ['like', 'order_main.ORDER_ID', $this->search_key], ['like', 'CUSTOMER_NAME', $this->search_key], ['like', 'CUSTOMER_MOBILE', $this->search_key]]); //预订时间 $date_start = ' 00:00:00'; $date_end = ' 23:59:59'; if ($this->date_type == 2) { //日期相同和不同 if ($this->date_from == $this->date_to) { $query->andFilterWhere(['PROD_START_STATION_DATE' => $this->date_from]); } else { $query->andFilterWhere(['and', ['>=', 'PROD_START_STATION_DATE', $this->date_from], ['<=', 'PROD_END_STATION_DATE', date('Y-m-d', strtotime('+1 days', strtotime($this->date_to)))]]); } } elseif ($this->date_type == 3) { $date_column = 'PROD_END_STATION_DATE'; $query->andFilterWhere(['between', $date_column, $this->date_from, $this->date_to]); } else { $date_column = 'order_main.CREATE_TIME'; $query->andFilterWhere(['between', $date_column, $this->date_from . $date_start, $this->date_to . $date_end]); } $query->groupBy('order_main.ORDER_ID'); $query->orderBy(['CREATE_TIME' => SORT_DESC]); // $sql = $query -> createCommand()->getRawSql(); return $dataProvider; } public function attributeLabels() { return array_merge( parent::attributeLabels(), [ 'ID' => 'ID', 'CREATE_USER_ID' => '跟单客服', 'CREATE_USER_NAME' => '操作人', 'CREATE_TIME' => '预订时间', 'ORDER_ID' => '订单编号', 'OUTSIDE_ORDER_NO' => '渠道商订单号', 'PROD_NAME' => '预订产品', 'BASE_PRICE' => '成本金额', 'CUSTOMER_NAME' => '客人姓名', 'CUSTOMER_MEMO' => '备注', 'ORDER_STATUS' => '订单状态', 'date_type' => '时间范围', 'date_from' => '起始日期', 'date_to' => '结束日期', 'SUPPLIER_NAME' => '订单渠道', 'ORDER_PRICE' => '订单金额', 'PROD_START_STATION_DATE' => '入住时间', 'PROD_END_STATION_DATE' => '离店时间', 'PARENT_PROD_NAME' => '酒店名称', 'PROD_SUPPLY_ORG_NAME' => '供应商', 'TOTAL_COMMISSION' => '渠道佣金', 'SALES_NAME' => '采购负责人', 'PRINCIPAL' => '运营负责人', 'ORDER_TITLE_ID' => '是否是组合订单', 'PAY_WAY' => '支付方式', 'PROFIT_VALUE' => '利润', ]); } }