Ejemplo n.º 1
0
 public function action_show()
 {
     $id = $this->params['id'];
     //详细信息
     $row = ORM::factory('car')->where("id={$id}")->find()->as_array();
     if (empty($row['litpic'])) {
         $row['litpic'] = Common::getDefaultImage();
     }
     //车辆类型
     if (!empty($row['carkindid'])) {
         $cartype = ORM::factory('car_kind')->where("id=" . $row['carkindid'])->find()->as_array();
         $row['counkindname'] = $cartype['kindname'];
     }
     //车辆品牌
     //$carbrand=ORM::factory('car_brand')->where("id=".$row['carbrandid'])->find()->as_array();
     //$row['carbrand'] = $carbrand['kindname'];
     $row['attrname'] = Model_Car_Attr::getAttrnameList($row['attrid']);
     $row['lineseries'] = Common::getSeries($row['id'], '03');
     //线路编号
     //产品图片
     if (!empty($row['piclist'])) {
         $temarr = explode(",", $row['piclist']);
         foreach ($temarr as $key => $value) {
             $row['pic_arr'][$key] = explode("||", $value);
         }
     }
     $sql = "SELECT min(b.adultprice) as carprice FROM sline_car a LEFT JOIN sline_car_suit_price b ON (b.carid = {$id} and b.adultprice!=0) WHERE a.ishidden=0 GROUP BY a.id ORDER BY a.displayorder ASC LIMIT 1";
     $query = DB::query(Database::SELECT, $sql);
     $list = $query->execute()->as_array();
     $this->assign('list', $list);
     $this->assign('row', $row);
     $this->display('cars/show');
 }
Ejemplo n.º 2
0
 public function action_car()
 {
     $action = $this->params['action'];
     if (empty($action)) {
         $this->assign('kindmenu', Common::getConfig('menu_sub.carkind'));
         //分类设置项
         $this->display('stourtravel/car/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');
             $carkindid = Arr::get($_GET, 'carkindid');
             $webid = Arr::get($_GET, 'webid');
             $sort = json_decode(Arr::get($_GET, 'sort'), true);
             $order = 'order by a.modtime desc';
             $webid = empty($webid) ? -1 : $webid;
             $keyword = Common::getKeyword($keyword);
             $specOrders = array('attrid', 'kindlist', 'iconlist', 'themelist');
             if ($sort[0]['property']) {
                 $prefix = '';
                 if ($sort[0]['property'] == 'displayorder') {
                     $prefix = '';
                 } else {
                     if ($sort[0]['property'] == 'ishidden') {
                         $prefix = 'a.';
                     } else {
                         if ($sort[0]['property'] == 'suitday') {
                             $prefix = 'e.';
                         } else {
                             if ($sort[0]['property'] == 'seatnum') {
                                 $prefix = 'a.';
                             } else {
                                 if (in_array($sort[0]['property'], $specOrders)) {
                                     $prefix = 'order_';
                                 }
                             }
                         }
                     }
                 }
                 $order = 'order by ' . $prefix . $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($brandid) ? '' : " and a.carbrandid='{$brandid}'";
             $w .= empty($carkindid) ? '' : " and a.carkindid='{$carkindid}'";
             $w .= $webid == '-1' ? '' : " and a.webid={$webid}";
             if (empty($kindid)) {
                 $sql = "select  a.id,a.webid,a.aid,a.title,a.supplierlist,a.seatnum,a.carkindid,a.kindlist,a.attrid,a.iconlist,a.themelist,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.ishidden,d.kindname as carkindname,IFNULL(b.displayorder,9999) as displayorder,ifnull(e.suitday,0) as suitday from sline_car as a left join sline_allorderlist b on (a.id=b.aid and b.typeid=3)  left join sline_car_kind d on (a.carkindid=d.id) left join (select c.carid,c.id,min(c.suitday) as suitday from(select a.carid,a.id,max(b.day) as suitday\n from sline_car_suit a left join sline_car_suit_price b on a.id=b.suitid  group by a.id) c group by c.carid) e on a.id=e.carid where {$w} {$order} limit {$start},{$limit}";
             } else {
                 $sql = "select  a.id,a.webid,a.aid,a.title,a.supplierlist,a.seatnum,a.carkindid,a.kindlist,a.attrid,a.iconlist,a.themelist,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.ishidden,b.isjian,b.isding,b.istejia,ifnull(b.displayorder,9999) as displayorder ,d.kindname as carkindname,ifnull(e.suitday,0) as suitday from sline_car as a left join sline_kindorderlist as b on (a.id=b.id and b.classid={$kindid} and b.typeid=3) left join sline_car_kind d on (a.carkindid=d.id) left join (select c.carid,c.id,min(c.suitday) as suitday from(select a.carid,a.id,max(b.day) as suitday\n from sline_car_suit a left join sline_car_suit_price b on a.id=b.suitid  group by a.id) c group by c.carid) e on a.id=e.carid where FIND_IN_SET({$kindid},a.kindlist)   order by a.modtime desc";
             }
             $totalcount_arr = DB::query(Database::SELECT, "select count(*) as num from sline_car 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_Car_Attr::getAttrnameList($v['attrid']);
                 $v['series'] = Common::getSeries($v['id'], '03');
                 //编号
                 $v['url'] = Common::getBaseUrl($v['webid']) . '/cars/show_' . $v['aid'] . '.html';
                 //供应商信息
                 $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'];
                 $suits = ORM::factory('car_suit')->where("carid={$v['id']}")->get_all();
                 $suittypes = ORM::factory('car_suit_type')->where("carid={$v['id']}")->get_all();
                 $suitOrder = $sort[0]['property'] == 'suitday' ? 'order by suitday ' . $sort[0]['direction'] : '';
                 $suitSql = "select a.*,ifnull(max(b.day),0) as suitday from sline_car_suit a left join sline_car_suit_price b on a.id=b.suitid where a.carid={$v['id']}  group by a.id {$suitOrder}";
                 $suits = DB::query(Database::SELECT, $suitSql)->execute()->as_array();
                 if (!empty($suits)) {
                     $v['tr_class'] = 'parent-product-tr';
                 }
                 $new_list[] = $v;
                 foreach ($suits as $key => $val) {
                     $val['title'] = $val['suitname'];
                     $val['id'] = 'suit_' . $val['id'];
                     $val['suittypes'] = $suittypes;
                     if ($key != count($suits) - 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('car', $id);
                         $model->deleteClear();
                     } else {
                         if (strpos($id, 'suit') !== FALSE) {
                             $suitid = substr($id, strpos($id, '_') + 1);
                             $suit = ORM::factory('car_suit', $suitid);
                             $carid = $suit->carid;
                             $suit->deleteClear();
                             Model_Car::updateMinPrice($carid);
                         }
                     }
                 } 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=3 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 = 3;
                                     }
                                     $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=3 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 = 3;
                                     }
                                     $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('car_suit', $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('car', $id);
                             } else {
                                 if (strpos($id, 'suit') !== FALSE) {
                                     $suitid = substr($id, strpos($id, '_') + 1);
                                     $model = ORM::factory('car_suit', $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, 3));
                                     }
                                 }
                                 $model->save();
                                 if ($model->saved()) {
                                     echo 'ok';
                                 } else {
                                     echo 'no';
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }