public function getAd($array) { $tbl = new DB_Udo_Ad(); $list = []; /* $result = $tbl->fetchAll(); print_r($result);*/ $AdModel = new AdModel(); //如果用户的地区和年级信息均有效 if ($array['province'] && $array['grade']) { $list = $tbl->fetchAll("id,price,url", "where region_id={$array['province']} and " . $AdModel->getGradeClause($array['grade']) . " and flag = 1", "order by price asc"); } if ($array['province'] && !$array['grade']) { $list = $tbl->fetchAll("id,price,url", "where region_id={$array['province']} and flag = 1", "order by price asc"); } if (!$array['province'] && $array['grade']) { $list = $tbl->fetchAll("id,price,url", "where " . $AdModel->getGradeClause($array['grade']) . " and flag = 1", "order by price asc"); } if (!$array['province'] && !$array['grade']) { $list = $tbl->fetchAll("id,price,url", "where flag = 1", "order by price asc"); } //如果没有筛选出符合用户条件的广告,那么将所有广告作为推送对象 if (!$list) { $list = $tbl->fetchAll("id,price,url", "where flag = 1", "order by price asc"); } return $list; }
function processForm($postImage) { $errors = []; $errors['count'] = 0; $today = date("Y-m-d"); //pass this to be inserted into the database //form was submitted when $_POST is not empty if (!empty($_POST)) { try { $category = Input::getString('category'); } catch (Exception $e) { $errors['category'] = 'Category: ' . $e->getMessage(); $errors['count']++; } try { $postingTitle = Input::getString('title'); } catch (Exception $e) { $errors['title'] = 'Posting Title: ' . $e->getMessage(); $errors['count']++; } try { $price = Input::getNumber('price'); } catch (Exception $e) { $errors['price'] = 'Price: ' . $e->getMessage(); $errors['count']++; } try { $description = Input::getString('description'); } catch (Exception $e) { $errors['description'] = 'Description: ' . $e->getMessage(); $errors['count']++; } try { $date_posted = Input::getDate('date_posted'); } catch (Exception $e) { $errors['date_posted'] = 'Date Posted: ' . $e->getMessage(); $errors['count']++; } if ($errors['count'] == 0) { $adObject = new AdModel(); $adObject->category = $category; $adObject->title = $postingTitle; $adObject->price = $price; $adObject->description = $description; var_dump($postImage); $adObject->image = $postImage; $adObject->date_posted = $today; // hardcoded: $adObject->user_id = $_SESSION['user_id']; $adObject->users_id = 1; $adObject->save(); //unset the $_SESSION['image'] - will be using the one in the database unset($_SESSION['image']); header("Location: /ads.show.php?id=" . $adObject->id); //this will be the $_GET for the ads.show.php die; } } return $errors; }
function pageController() { $ads = AdModel::getMostRecent(3); $ads = array_map(function ($ad) { $truncateAt = 15; if (strlen($ad['description']) > $truncateAt) { $ad['description'] = substr($ad['description'], 0, $truncateAt) . '...'; } return $ad; }, $ads); return ['ads' => $ads]; }
public function index() { //广告位 $admod = new AdModel(); $cid = $this->cid; $adlist = $admod->getad(1, $cid); $this->assign("adlist", $adlist); #var_dump($adlist); #var_dump($_SESSION['cid']); //工长 $formod = new ForemanviewModel(); $forlist = $formod->getforeman($cid); $this->assign("forlist", $forlist); //正在施工 $sgmod = new ShigongdtModel(); $sgdtlist = $sgmod->getsgdt($cid); $this->assign("sgdtlist", $sgdtlist); #var_dump($sgdtlist); //团购活动 $this->display(); }
/** * returns an array of AdModel objects that are all ads associated with the * user */ public function getAds() { $ads = []; $id = $this->id; $query = "SELECT id FROM ads WHERE users_id = {$id}"; $stmt = self::$dbc->prepare($query); $stmt->execute(); $adIds = $stmt->fetchAll(PDO::FETCH_NUM); foreach ($adIds as $adId) { $ads[] = AdModel::find($adId[0]); } return $ads; }
function pageController() { //initializes the session variable if none exists otherwise it resets it //a user id was passed to this page to display if (!empty($_GET['id'])) { $adID = $_GET['id']; $adObject = AdModel::find($adID); } //the form containing only the submit button was submmited - user wants to edit the ad if (!empty($_POST) && !empty($_GET['id'])) { header("Location: /ads.edit.php?id=" . $adID); //this will be the $_GET for the ads.edit.php die; } return array('adObject' => $adObject); }
/** * 工长列表 */ public function foremanlist() { $cid = $_SESSION['cid']; //广告位 $admod = new AdModel(); $cid = $this->cid; $adlist = $admod->getad(2, $cid); $this->assign("adlist", $adlist); #城市 $Amod = new AreaModel(); $arealist = $Amod->getcity($cid); $this->assign("arealist", $arealist); import("ORG.Util.Page"); $M = new ForemanviewModel(); $where = "status=1 "; $areaid = $_GET['areaid']; if (!empty($areaid)) { $where .= " and q_id=" . $areaid; } $this->assign("areaid", $areaid); $where .= " and c_id=" . $cid; $totalRows = $M->getforemannum($where); $p = new Page($totalRows, 48); $list = $M->getforemanbywhere($where, $p->firstRow, $p->listRows); $this->assign("list", $list); $this->assign("page", $p->show()); #------------------------------列表结束 #设计师 $M1 = new ShejiviewModel(); $sjlist = $M1->getsheji($cid); $this->assign("sjlist", $sjlist); #施工动态 $M2 = new ShigongdtModel(); $sgdtlist = $M2->getsgdtbytime(); #var_dump($sgdtlist); $this->assign("sgdtlist", $sgdtlist); #经典案例 $M3 = new CaseModel(); $caselist = $M3->getjdcase($cid); $this->assign("caselist", $caselist); #var_dump($caselist); $this->display(); }
function pageController() { $errors['count'] = 0; if (!empty($_GET['id'])) { $adID = $_GET['id']; $adObject = AdModel::find($adID); } $imageSuccessMessage = ""; //if an image was submitted - validate it even before validating the rest of the form if (!empty($_POST['upload-image']) && $_FILES['fileToUpload']['name'] != '') { try { $postImage = Input::getImage(); //image was successfully uploaded $imageSuccessMessage = "Image: " . basename($_FILES['fileToUpload']['name']) . " has been uploaded!"; //store image in the session $_SESSION['image'] = $postImage; } catch (Exception $e) { $errors['image'] = 'Image: ' . $e->getMessage(); $errors['count']++; } } //clicked on the upload image button without selecting a photo if (!empty($_POST['upload-image']) && $_FILES['fileToUpload']['name'] == '') { $errors['image'] = "Image: Select an image to upload!"; $errors['count']++; } //an image has been submitted; use the image stored in the $_SESSION if (isset($_SESSION['image'])) { $postImage = $_SESSION['image']; } else { //use the image stored in the database $postImage = "Database Image"; } //if there weren't any errors with the image; then, process then rest of the form if ($errors['count'] == 0) { $errors = processForm($adObject, $postImage); // $errors = processForm($adObject->category, $adObject->date_posted, $postImage); } return array('adObject' => $adObject, 'errorMessages' => $errors); }
function pageController() { try { $query = Input::getString('query'); } catch (Exception $e) { $query = ''; } $ads = AdModel::search($query); $ads = array_map(function ($ad) { $truncateAt = 15; if (strlen($ad['description']) > $truncateAt) { $ad['description'] = substr($ad['description'], 0, $truncateAt) . '...'; } return $ad; }, $ads); $ads = array_map(function ($ad) { $date = strtotime($ad['date_posted']); $ad['date_posted'] = date("F d, Y", $date); return $ad; }, $ads); return ['ads' => $ads]; }
$mark = isset($_POST["mark"]) ? $_POST["mark"] : ''; $link = isset($_POST["link"]) ? $_POST["link"] : ''; $pic_url = isset($_POST["pic_url"]) ? $_POST["pic_url"] : ''; $content = isset($_POST["content"]) ? $_POST["content"] : ''; $week = isset($_POST["week"]) ? $_POST["week"] : ''; $ad_start_time = isset($_POST["ad_start_time"]) ? strtotime(trim($_POST["ad_start_time"])) : time(); $ad_end_time = isset($_POST["ad_end_time"]) ? strtotime(trim($_POST["ad_end_time"])) : time(); $out_title = isset($_POST["out_title"]) ? $_POST["out_title"] : ''; $out_link = isset($_POST["out_link"]) ? $_POST["out_link"] : ''; $out_pic_url = isset($_POST["out_pic_url"]) ? $_POST["out_pic_url"] : ''; $status = isset($_POST["status"]) ? $_POST["status"] : ''; if ($title == "" || $alias == "") { $createMessage = "请把信息填写完整!!"; } else { $sql = 'SELECT * FROM `ad` WHERE `alias`="' . $alias . '" AND `id`<>"' . $id . '"'; $rs = $pdo->query($sql); $row = $rs->fetchAll(); //取得所有记录 $count = count($row); if ($count == 0) { $lastetId = AdModel::model()->create($_POST); if ($lastetId != FALSE) { $createMessage = "添加成功"; } else { $createMessage = "添加失败"; } } else { $createMessage = '【名称】或者【标题】或者【系统别名】重复!'; } } }
$link = $_POST['link']; $pic_url = $_POST['pic_url']; $content = $_POST["content"]; $mark = $_POST['mark']; $week = isset($_POST["week"]) ? $_POST["week"] : ''; $ad_start_time = isset($_POST["ad_start_time"]) ? strtotime(trim($_POST["ad_start_time"])) : time(); $ad_end_time = isset($_POST["ad_end_time"]) ? strtotime(trim($_POST["ad_end_time"])) : time(); $out_title = isset($_POST["out_title"]) ? $_POST["out_title"] : ''; $out_link = isset($_POST["out_link"]) ? $_POST["out_link"] : ''; $out_pic_url = isset($_POST["out_pic_url"]) ? $_POST["out_pic_url"] : ''; $status = isset($_POST["status"]) ? $_POST["status"] : ''; if ($title == "" || $alias == "" || $name == "") { $updateMessage = "请把信息填写完整!!"; } else { $sql = 'SELECT * FROM `ad` WHERE (`name`="' . $name . '" OR `alias`="' . $alias . '") AND `id`<>"' . $id . '"'; $rs = $pdo->query($sql); $row = $rs->fetchAll(); $count = count($row); if ($count == 0) { $row = array('title' => $title, 'alias' => $alias, 'name' => $name, 'content' => $content, 'link' => $link, 'pic_url' => $pic_url, 'mark' => $mark, 'week' => $week, 'ad_start_time' => $ad_start_time, 'ad_end_time' => $ad_end_time, 'out_title' => $out_title, 'out_link' => $out_link, 'out_pic_url' => $out_pic_url, 'status' => $status); $result = AdModel::model()->update(array('id' => $id), $row); if ($result > 0) { $updateMessage = "修改成功"; } else { $updateMessage = "修改失败"; } } else { $updateMessage = '标题或者别名重复!'; } } }
$count = count($pdo->query($sql)->fetchAll()); $totalPage = ceil($count / $pageSize); $init = 1; $page_len = 9; //页码个数 $max_p = $totalPage; $pages = $totalPage; //判断当前页码 if (empty($_GET['page']) || $_GET['page'] < 0) { $page = 1; } else { $page = $_GET['page']; } $offset = $pageSize * ($page - 1); $sql = $sql . " LIMIT {$offset},{$pageSize}"; $itemArr = AdModel::model()->findAllBySql($sql); $page_len = $page_len % 2 ? $page_len : $pagelen + 1; //页码个数 $pageoffset = ($page_len - 1) / 2; //页码个数左右偏移量 $key = '<div class="page">'; $key .= "<span>{$page}/{$pages}</span> "; //第几页,共几页 if ($page != 1) { $key .= "<a href=\"ad_manage.php?page=1\">首页</a> "; //第一页 $key .= "<a href=\"ad_manage.php?page=" . ($page - 1) . "\">上一页</a>"; //上一页 } else { $key .= "首页 "; //第一页
/** * 用户是否存在 */ public function getAdAction() { //广告接口首先拿客户端传来的ssotoken 在SSO进行验证获取用户信息 $request = $this->getRequest(); $userModel = new UserModel(); $userModel->logout(); if ('POST' == $request->getMethod()) { $token = trim($this->post()->get("ssotoken")); } else { $token = $this->get("ssotoken"); } //$token = "1"; if (!$token) { $this->displayJsonUdo(Common_Error::ERROR_PARAM); } //获取到用户信息 $url = Common_Config::SSO_SCHOOL_URL; $post_data = array("ssotoken" => $token); //print_r($post_data); $cl = new Common_Curl(); $result = $cl->request($url, $post_data); /* $result = array("id"=>8 , "grade"=>11,"province"=>3,"city"=>4,"area"=>5, "entrances"=>array(0=>array("id"=>1,"name"=>"双十","title"=>"双十网校","grade"=>11,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4), 1=>array("id"=>2,"name"=>"华英","title"=>"华英网校","grade"=>14,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>6), 2=>array("id"=>3,"name"=>"三明","title"=>"三明网校","grade"=>15,"baseUrl"=>"1", "udoUrl"=>"2","city_id"=>4)));*/ //print_r($result); if (array_key_exists('code', $result) && $result['code'] == 0) { $this->displayJsonUdo(Common_Error::ERROR_FAIL, null, "SSO没有返回正确的用户信息哦~"); } //$result = array ("id"=> 2779,"province"=>3,"grade"=>11); //$result = array ("id"=> 2779,"province"=> 0,"grade"=>11); //sso返回成功,开始进行广告过滤 //print_r($result); //过滤出和用户所在地区和年级一致的广告 $ad = new AdModel(); $adlist = $ad->getAd($result); $uid = $userModel->getUserId($token); /*$kaixin = $ad->filterPrimary($uid); if(is_array($kaixin)) $adlist = $kaixin;*/ //计算总竞价值 $price_sum = 0; $temp_arr = array(); foreach ($adlist as $i => $val) { $price_sum += $val['price']; } //生成随机数 $arr = array(); $arr[] = rand(1, 100); $arr = array_unique($arr); $rand = implode(" ", $arr); //获得随机url $url = []; $rate = 0; foreach ($adlist as $i => $val) { $temp_arr[$i] = $val['price'] / $price_sum * 100 + ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0); //print_r($i." ".$temp_arr[$i]); if ($rand <= $temp_arr[$i] && $rand >= ($i - 1 >= 0 ? $temp_arr[$i - 1] : 0)) { $url = $val; $rate = $val['price'] / $price_sum; } } //将推送的广告写入广告推送表 $ad->adLog($url['id'], 0, $rate); $ad->adPushSum($url['id']); $ad->adStatistics($url['id']); $this->displayJsonUdo(Common_Error::ERROR_SUCCESS, $url); }