load->database(); } /* 解析广告位信息 */ public function setVacancyMsg($row) { $where = array('id' => $row->cityid); $cityinfor = $this->Db_model->getSpecificData("city",$where); $city = ""; if (count($cityinfor) > 0) $city = $cityinfor[0]->name; $where = array('id' => $row->areaid); $areainfor = $this->Db_model->getSpecificData("area",$where); $area = ""; if (count($areainfor) > 0) $area = $areainfor[0]->name; $where = array('id' => $row->communityid); $communityinfor = $this->Db_model->getSpecificData("community",$where); $community = ""; if (count($communityinfor) > 0) $community = $communityinfor[0]->name; $where = array('id' => $row->signid); $adinfor = $this->Db_model->getSpecificData("advertisement",$where); $adnumber = ""; if (count($adinfor) > 0) $adnumber = $adinfor[0]->number; $data=array( 'id' => $row->id, 'number' => $row->number, 'signid' => $row->signid, 'adnumber' => $adnumber, 'cityid' => $row->cityid, 'city' => $city, 'areaid' => $row->areaid, 'area' => $area, 'communityid' => $row->communityid, 'community' => $community, 'cost' => $row->cost, 'design' => $row->design, 'addtime' => $row->addtime, 'state' => $row->state ); return $data; } /* 接收广告位信息 */ public function receiveVacancyMsg() { date_default_timezone_set("Asia/Shanghai"); $number = isset($_POST['vnumber'])?$_POST['vnumber']:""; $cost = isset($_POST['vcost'])?$_POST['vcost']:""; $design = isset($_POST['vdesign'])?$_POST['vdesign']:""; $signid = isset($_POST['adid'])?$_POST['adid']:""; $where = array('id' => $signid); $adinfor = $this->Db_model->getSpecificData("advertisement",$where); $cityid = ""; $areaid = ""; $communityid = ""; if (count($adinfor) > 0) { $cityid = $adinfor[0]->cityid; $areaid = $adinfor[0]->areaid; $communityid = $adinfor[0]->communityid; } $data = array( 'number' => $number, 'signid' => $signid, 'cityid' => $cityid, 'areaid' => $areaid, 'communityid' => $communityid, 'cost' => $cost, 'design' => $design, 'addtime' => date("m/d/Y") ); return $data; } /* 取广告位 $type = 0 空 $type = 1 非空 */ public function getVacancy($id, $type = 0) { $where = array('signid' => $id); $infor = $this->Db_model->getSpecificData("vacancy",$where); $data = array(); if (count($infor) <= 0) { return $data; } foreach ($infor as $row) { $state = $row->state; if ($state == $type) { $vid = $row->id; $tmp = $this->setVacancyMsg($row); $tmp['surplus'] = $this->getDay($vid); array_push($data,$tmp); } } return $data; } /* 设置广告位状态 */ public function setState($vid,$state) { $where = array('id' => $vid); $data = array('state' => $state); $this->Db_model->updateData("vacancy",$data,$where); } /* 更新广告位的当前订单(结束 / 退钱) */ public function updateOrder($vid, $oid, $type="add") { $where = array('id' => $vid); $infor = $this->Db_model->getSpecificData("vacancy",$where); $list = ""; if (count($infor) > 0) { $list = $infor[0]->orderid; } $arr = array(); if ($list != "" && $list != 0) $arr = explode("_", $list); if ($type == "add") { $arr[] = $oid; }else if ($type == "remove") { $tmp = array(); foreach($arr as $k=>$v) { if ($v == $oid) { $_i = ($k-1) >= 0 ? ($k-1) : 0; $tmp = array_splice($arr, $_i); foreach($tmp as $i=>$j) { $_data = array('state' => 3); $_where = array('id' => $j); $this->Db_model->updateData("reserve",$_data,$_where); } break; } } } $data = array('orderid' => implode("_",$arr)); $this->Db_model->updateData("vacancy",$data,$where); return count($arr); } /* 取广告位剩余时间 $vid:广告位id */ public function getDay($vid) { date_default_timezone_set("Asia/Shanghai"); $day = 0; $where = array('id' => $vid); $infor = $this->Db_model->getSpecificData("vacancy",$where); if (count($infor) <= 0) { $day = 0; }else { $_orderid = $infor[0]->orderid; $_arr = explode("_", $_orderid); $_len = count($_arr); $_oid = $_arr[$_len - 1]; $where = array('id' => $_oid); $infor = $this->Db_model->getSpecificData("reserve",$where); if (count($infor) <= 0) return ; $_endtime = $infor[0]->endtime; if ($_endtime != 0 && $_endtime != "") { $_now = date("m/d/Y"); $time1 = strtotime($_now); $time2 = strtotime($_endtime); $_time = (($time2-$time1)/3600/24); if ($_time >= 0) { $day = $_time; } else $day = 0; }else { $day = 0; } } return $day; } /* 取广告位到期时间 $vid:广告位id */ public function getEndTime($vid) { date_default_timezone_set("Asia/Shanghai"); $day = 0; $where = array('id' => $vid); $infor = $this->Db_model->getSpecificData("vacancy",$where); if (count($infor) <= 0) { $day = 0; //过期制动修改 //$data = array('state' => 3); // $this->Db_model->updateData("reserve",$where); }else { $_orderid = $infor[0]->orderid; $_arr = explode("_", $_orderid); $_len = count($_arr); $_oid = $_arr[$_len - 1]; $where = array('id' => $_oid); $infor = $this->Db_model->getSpecificData("reserve",$where); if (count($infor) <= 0) $day = 0; else { $_endtime = $infor[0]->endtime; $day = $_endtime; } } return $day; } }