public function action_show() { $id = $this->params['id']; //详细信息 $row = ORM::factory('hotel')->where("id={$id}")->find()->as_array(); if (empty($row['litpic'])) { $row['litpic'] = Common::getDefaultImage(); } //酒店星级 $hoteltype = ORM::factory('hotel_rank')->where("aid=" . intval($row['hotelrankid']))->find()->as_array(); $row['randname'] = $hoteltype['hotelrank']; //酒店属性 $row['attrname'] = Model_Hotel_Attr::getAttrnameList($row['attrid']); $row['series'] = Common::getSeries($row['id'], '02'); //编号 //产品图片 if (!empty($row['piclist'])) { $temarr = explode(",", $row['piclist']); foreach ($temarr as $key => $value) { $row['pic_arr'][$key] = explode("||", $value); } } $this->assign('row', $row); $this->display('hotels/show'); }
public function action_hotel() { $action = $this->params['action']; if (empty($action)) { $this->assign('kindmenu', Common::getConfig('menu_sub.hotelkind')); //分类设置项 $this->display('stourtravel/hotel/list'); } else { if ($action == 'read') { $start = Arr::get($_GET, 'start'); $limit = Arr::get($_GET, 'limit'); $keyword = Arr::get($_GET, 'keyword'); $kindid = Arr::get($_GET, 'kindid'); $attrid = Arr::get($_GET, 'attrid'); $rankid = Arr::get($_GET, 'rankid'); $webid = Arr::get($_GET, 'webid'); $webid = empty($webid) ? -1 : $webid; $keyword = Common::getKeyword($keyword); $sort = json_decode(Arr::get($_GET, 'sort'), true); $specOrders = array('attrid', 'kindlist', 'iconlist', 'themelist'); $order = 'order by a.modtime desc'; if ($sort[0]['property']) { if ($sort[0]['property'] == 'displayorder') { $order = 'order by displayorder ' . $sort[0]['direction'] . ',a.modtime desc'; } else { if ($sort[0]['property'] == 'ishidden') { $order = 'order by a.ishidden ' . $sort[0]['direction'] . ',a.modtime desc'; } else { if ($sort[0]['property'] == 'suitday') { $order = 'order by d.suitday ' . $sort[0]['direction'] . ',a.modtime desc'; } else { if (in_array($sort[0]['property'], $specOrders)) { $order = 'order by order_' . $sort[0]['property'] . ' ' . $sort[0]['direction'] . ',a.modtime desc'; } } } } } $w = "a.id is not null"; $w .= empty($keyword) ? '' : " and (a.title like '%{$keyword}%' or a.id like '%{$keyword}%')"; $w .= empty($kindid) ? '' : " and find_in_set({$kindid},a.kindlist)"; $w .= empty($attrid) ? '' : " and find_in_set({$attrid},a.attrid)"; $w .= empty($rankid) ? '' : " and a.hotelrankid='{$rankid}'"; $w .= $webid == '-1' ? '' : " and a.webid={$webid}"; if (empty($kindid)) { $sql = "select a.id,a.aid,a.title,a.kindlist,a.attrid,a.hotelrankid,a.hotelrankid ,a.ishidden,a.webid,a.iconlist,a.supplierlist,a.themelist,b.isding,b.isjian,b.istejia,if(length(ifnull(a.attrid,''))=0,0,1) as order_attrid,if(length(ifnull(a.kindlist,''))=0,0,1) as order_kindlist,if(length(ifnull(a.iconlist,''))=0,0,1) as order_iconlist,if(length(ifnull(a.themelist,''))=0,0,1) as order_themelist\n,ifnull(b.displayorder,9999) as displayorder,ifnull(d.suitday,0) as suitday from sline_hotel as a left join sline_allorderlist b on (a.id=b.aid and b.typeid=2) left join (select c.hotelid,c.id,min(c.suitday) as suitday from(select a.hotelid,a.id,max(b.day) as suitday\n from sline_hotel_room a left join sline_hotel_room_price b on a.id=b.suitid group by a.id) c group by c.hotelid) d on a.id=d.hotelid where {$w} {$order} limit {$start},{$limit}"; } else { $sql = "select a.id,a.aid,a.title,a.kindlist,a.attrid,a.hotelrankid,a.hotelrankid ,a.ishidden,a.webid,a.iconlist,if(length(ifnull(a.attrid,''))=0,0,1) as order_attrid,if(length(ifnull(a.kindlist,''))=0,0,1) as order_kindlist,if(length(ifnull(a.iconlist,''))=0,0,1) as order_iconlist,if(length(ifnull(a.themelist,''))=0,0,1) as order_themelist\n,a.themelist,b.isding,b.isjian,b.istejia,ifnull(b.displayorder,9999) as displayorder,ifnull(d.suitday,0) as suitday from sline_hotel as a left join sline_kindorderlist as b on (b.classid={$kindid} and a.id=b.aid and b.typeid=2) left join (select c.hotelid,c.id,min(c.suitday) as suitday from(select a.hotelid,a.id,max(b.day) as suitday\n from sline_hotel_room a left join sline_hotel_room_price b on a.id=b.suitid group by a.id) c group by c.hotelid) d on a.id=d.hotelid where {$w} {$order} limit {$start},{$limit}"; } $totalcount_arr = DB::query(Database::SELECT, "select count(*) as num from sline_hotel a where {$w}")->execute()->as_array(); $list = DB::query(Database::SELECT, $sql)->execute()->as_array(); $new_list = array(); foreach ($list as $k => $v) { $v['kindname'] = Model_Destinations::getKindnameList($v['kindlist']); $v['attrname'] = Model_Hotel_Attr::getAttrnameList($v['attrid']); $v['url'] = Common::getBaseUrl($v['webid']) . '/hotels/show_' . $v['aid'] . '.html'; $iconname = Model_Icon::getIconName($v['iconlist']); $name = ''; foreach ($iconname as $icon) { if (!empty($icon)) { $name .= '<span style="color:red">[' . $icon . ']</span>'; } } $v['iconname'] = $name; $v['series'] = Common::getSeries($v['id'], '02'); //编号 //供应商信息 $supplier = ORM::factory('supplier')->where("id='{$v['supplierlist']}'")->find()->as_array(); $v['suppliername'] = $supplier['suppliername']; $v['linkman'] = $supplier['linkman']; $v['mobile'] = $supplier['mobile']; $v['address'] = $supplier['address']; $v['qq'] = $supplier['qq']; //$homes=ORM::factory('hotel_room')->where("hotelid",'=',$v['id'])->get_all(); //读取套餐 $suitOrder = $sort[0]['property'] == 'suitday' ? 'order by suitday ' . $sort[0]['direction'] : ''; $homeSql = "select a.*,ifnull(max(b.day),0) as suitday from sline_hotel_room a left join sline_hotel_room_price b on a.id=b.suitid where a.hotelid={$v['id']} group by a.id {$suitOrder}"; $homes = DB::query(Database::SELECT, $homeSql)->execute()->as_array(); if (!empty($homes)) { $v['tr_class'] = 'parent-product-tr'; } $new_list[] = $v; foreach ($homes as $key => $val) { $val['title'] = $val['roomname']; $val['roomid'] = $val['id']; $val['id'] = 'suit_' . $val['id']; $val['hotelid'] = $val['hotelid']; if ($key != count($homes) - 1) { $val['tr_class'] = 'suit-tr'; } $new_list[] = $val; } } $result['total'] = $totalcount_arr[0]['num']; $result['lists'] = $new_list; $result['success'] = true; echo json_encode($result); } else { if ($action == 'save') { } else { if ($action == 'delete') { $rawdata = file_get_contents('php://input'); $data = json_decode($rawdata); $id = $data->id; if (is_numeric($id)) { $model = ORM::factory('hotel', $id); $model->deleteClear(); } else { if (strpos($id, 'suit') !== FALSE) { $suitid = substr($id, strpos($id, '_') + 1); $suit = ORM::factory('hotel_room', $suitid); $hotelid = $suit->hotelid; $suit->deleteClear(); Model_Hotel::updateMinPrice($hotelid); } } } else { if ($action == 'update') { $id = Arr::get($_POST, 'id'); $field = Arr::get($_POST, 'field'); $val = Arr::get($_POST, 'val'); $kindid = Arr::get($_POST, 'kindid'); if ($field == 'displayorder') { $displayorder = empty($val) ? 9999 : $val; if (is_numeric($id)) { if (empty($kindid)) { $order = ORM::factory('allorderlist'); $order_mod = $order->where("aid='{$id}' and typeid=2 and webid=0")->find(); if ($order_mod->id) { $order_mod->displayorder = $displayorder; } else { $order_mod->displayorder = $displayorder; $order_mod->aid = $id; $order_mod->webid = 0; $order_mod->typeid = 2; } $order_mod->save(); if ($order_mod->saved()) { echo 'ok'; } else { echo 'no'; } } else { $kindorder = ORM::factory('kindorderlist'); $kindorder_mod = $kindorder->where("aid='{$id}' and typeid=2 and classid={$kindid}")->find(); if ($kindorder_mod->id) { $kindorder_mod->displayorder = $displayorder; } else { $kindorder_mod->displayorder = $displayorder; $kindorder_mod->aid = $id; $kindorder_mod->classid = $kindid; $kindorder_mod->typeid = 2; } $kindorder_mod->save(); if ($kindorder->saved()) { echo 'ok'; } else { echo 'no'; } } } else { if (strpos($id, 'suit') !== FALSE) { $suitid = substr($id, strpos($id, '_') + 1); $suit = ORM::factory('hotel_room', $suitid); $suit->displayorder = $displayorder; if ($suit->id) { $suit->save(); if ($suit->saved()) { echo 'ok'; } else { echo 'no'; } } } } } else { if (is_numeric($id)) { $model = ORM::factory('hotel', $id); } else { if (strpos($id, 'suit') !== FALSE) { $suitid = substr($id, strpos($id, '_') + 1); $model = ORM::factory('hotel_room', $suitid); } } if ($model->id) { $model->{$field} = $val; if ($field == 'kindlist') { $model->{$field} = implode(',', Model_Destinations::getParentsStr($val)); } else { if ($field == 'attrid') { $model->{$field} = implode(',', Model_Attrlist::getParentsStr($val, 2)); } } $model->save(); if ($model->saved()) { echo 'ok'; } else { echo 'no'; } } } } } } } } }