Files
advertising/application/controllers/Wap.php

558 lines
14 KiB
PHP
Raw Normal View History

2019-04-11 15:54:34 +08:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Wap extends MY_Controller {
public function __construct()
{
parent::__construct();
$this->Func_model->check_wapSession(true);
$this->load->model('admin/User_model');
$this->load->model('admin/Ad_model');
$this->load->model('admin/City_model');
$this->load->model('admin/Vacancy_model');
$this->load->model('admin/Order_model');
}
/*
获取广告列表
*/
public function adList()
{
$pagecurrent = isset($_POST['pagecurrent'])?stripslashes($_POST['pagecurrent']):"";
$cityid = isset($_POST['cityid'])?$_POST['cityid']:"";
$areaid = isset($_POST['areaid'])?$_POST['areaid']:"";
$communityid = isset($_POST['communityid'])?$_POST['communityid']:"";
$adnum = isset($_POST['adnum'])?$_POST['adnum']:"";
$initcity = isset($_POST['initcity'])?$_POST['initcity']:"";
if ($pagecurrent == "")
{
return false;
}else
{
$data = array();
$num = $this->Config_model->getPageNum();
$like = array();
if ($adnum == "" || $adnum == "请输入信息栏编号,例:QS-005")
{
if ($areaid != "" && $communityid == "")
{
$where = array("areaid" => $areaid);
}else if ($areaid != "" && $communityid != "")
{
$where = array("communityid" => $communityid, "areaid" => $areaid);
}else
{
$where = array();
}
}else{
$like = array("number" => $adnum);
if ($areaid != "" && $communityid == "")
{
$where = array("areaid" => $areaid);
}else if ($areaid != "" && $communityid != "")
{
$where = array("communityid" => $communityid, "areaid" => $areaid);
}else
{
$where = array();
}
}
$data = $this->Db_model->getPage("advertisement",$where,$like,$pagecurrent);
$msg = $this->Db_model->getSearchData("advertisement",$where,$like,"id","DESC",((int)$pagecurrent-1)*$num,$num);
$len = count($data);
foreach ($msg as $row)
{
$data[$len][] = $this->Ad_model->setAdMsg($row);
}
if ($initcity == "true")
$data['arealist'] = $this->City_model->getArea("");
$this->Func_model->toJsFunc("adList",$this->Func_model->decodeUnicode($data));
return;
}
}
/*
wap登陆后 页面
*/
public function index()
{
$data['home_js_url'] = $this->Config_model->getHomeJsUrl();
$data['public_js_url'] = $this->Config_model->getPublicJsUrl();
$data['public_css_url'] = $this->Config_model->getPublicCssUrl();
$data['home_css_url'] = $this->Config_model->getHomeCssUrl();
$data['home_img_url'] = $this->Config_model->getHomeImgUrl();
$data['upload_url'] = $this->Config_model->getAdminUploadUrl();
$data['wid']=$_SESSION['wid'];
//$cityid = isset($_POST['cityid'])?$_POST['cityid']:"";
$data['wname']=isset($_SESSION['wname'])?$_SESSION['wname']:"";
$data['root'] = $this->Config_model->getRoot();
$data['home_page_url'] = $this->Config_model->getHomePageUrl();
$this->load->view($this->Config_model->getHomeViewsRoot().'main', $data);
}
/*
wap 个人信息页面
*/
public function userInfor()
{
$id = $_SESSION['wid'];
if ($id == "")
return ;
$where = array('id' => $id);
$infor = $this->Db_model->getSpecificData("user",$where);
$data = $this->User_model->setUserMsg($infor[0]);
$this->Func_model->toJsFunc("infor",$this->Func_model->decodeUnicode($data));
return ;
}
/*
wap 编辑个人信息页面
*/
public function editInfor()
{
$id = $_SESSION['wid'];
if ($id == "")
return ;
$data = $this->User_model->receiveUserMsg();
$number = isset($_POST['number'])?$_POST['number']:"";
$where = array('code' => $number, 'telephone' => $data['telephone']);
$msg = $this->Db_model->getSpecificData("validate", $where);
if (count($msg) > 0)
{
$_time = $msg[0]->addtime;
$_tmp = strtotime(date("Y-m-d H:i:s")) - strtotime($_time);
if ((int)$_tmp > (int)$this->Config_model->getWait())
{
$this->Db_model->delData("validate",$where);
$this->Func_model->setTip("number_tip",$this->Config_model->msg[19]);
return;
}
}else
{
$this->Func_model->setTip("number_tip",$this->Config_model->msg[19]);
return;
}
$where = array('password' => $data['password']);
$infor = $this->Db_model->getSpecificData("user",$where);
if (count($infor) > 0)
{
if ($id != $infor[0]->id)
{
$this->Func_model->setTip("password_tip",$this->Config_model->msg[7]);
return;
}
}
$where = array('telephone' => $data['telephone']);
$infor = $this->Db_model->getSpecificData("user",$where);
if (count($infor) > 0)
{
if ($id != $infor[0]->id)
{
$this->Func_model->setTip("phone_tip",$this->Config_model->msg[7]);
return;
}
}
$where = array('telephone' => $data['telephone']);
$this->Db_model->delData("validate",$where);
$where = array('id' => $id);
$this->Db_model->updateData("user",$data,$where);
$this->Func_model->toJsFunc("disInfor","");
$this->Func_model->setAlert($this->Config_model->msg[0]);
}
/*
获得城区
*/
public function getArea()
{
$cityid = isset($_POST['cityid'])?$_POST['cityid']:"";
$data = $this->City_model->getArea($cityid);
$this->Func_model->toJsFunc("setArea",$this->Func_model->decodeUnicode($data));
}
/*
获得小区
*/
public function getCommunity()
{
$areaid = isset($_POST['areaid'])?$_POST['areaid']:"";
$data = $this->City_model->getCommunity($areaid);
$this->Func_model->toJsFunc("setCommunity",$this->Func_model->decodeUnicode($data));
}
/*
获得广告页面数据
*/
public function getAd()
{
$id = isset($_POST['adid'])?$_POST['adid']:"";
/* $citydess= isset($_POST['citydess'])?$_POST['citydess']:"";
$data = $this->City_model->getAd($citydess); */
if ($id == "")
return ;
$where = array('signid' => $id);
$infor = $this->Db_model->getSpecificData("vacancy",$where);
if (count($infor) <= 0)
return ;
$this->Order_model->checkOrder($infor);
$where = array('id' => $id);
$infor = $this->Db_model->getSpecificData("advertisement",$where);
$data = $this->Ad_model->setAdMsg($infor[0]);
$data['photo'] = $this->Ad_model->getPhoto($id);
$data['empty'] = $this->Vacancy_model->getVacancy($id,0);
$data['buy'] = $this->Vacancy_model->getVacancy($id,1);
$this->Func_model->toJsFunc("setBuyAd",$this->Func_model->decodeUnicode($data));
}
/*
获取已支付完的广告位订单信息
*/
public function getOrder()
{
$id = $_SESSION['wid'];
if ($id == "")
return ;
$this->Order_model->checkOrder($id, "user");
$where = array('userid' => $id);
$infor = $this->Db_model->getSpecificData("reserve",$where);
$data = array();
foreach ($infor as $row)
{
$data[] = $this->Order_model->setOrderMsg($row);
}
$this->Func_model->toJsFunc("vacancyList",$this->Func_model->decodeUnicode($data));
}
/*
确认选择的广告位
*/
public function selectVacancy()
{
$data = array();
foreach($_POST as $key => $value)
{
$arr = explode("_", $key);
if ($arr[0] == "vacancy")
{
$vid = $arr[1];
$day = $value;
$where = array('id' => $vid);
$infor = $this->Db_model->getSpecificData("vacancy",$where);
if (count($infor) <= 0)
{
break;
}else
{
$msg = $this->Vacancy_model->setVacancyMsg($infor[0]);
if ($msg['state'] != 0)
{
break;
}else
{
$msg['day'] = $day;
$data[] = $msg;
}
}
}
}
$this->Func_model->toJsFunc("selectList",$this->Func_model->decodeUnicode($data));
}
/*
需租广告位确认信息
*/
public function vacancyInfor()
{
date_default_timezone_set("Asia/Shanghai");
$id = isset($_POST['id'])?$_POST['id']:"";
if ($id == "")
return ;
$where = array('id' => $id);
$infor = $this->Db_model->getSpecificData("vacancy",$where);
if (count($infor) <= 0)
return ;
$communityid = $infor[0]->communityid;
$community = $this->City_model->communityInfor($communityid);
$data['community'] = $community['name'];
$data['number'] = $infor[0]->number;
$data['cost'] = $infor[0]->cost;
$data['signid'] = $infor[0]->signid;
$state = $infor[0]->state;
if ($state == 0)
{
$data['state'] = 0;
$data['endtime'] = 0;
$data['surplus'] = 0;
$data['state'] = 0;//空闲
}else
{
$uid = $_SESSION['wid'];
if ($uid == "")
return ;
$where = array('vacancyid' => $id, "userid" => $uid, "state" => 1);
$infor = $this->Db_model->getSpecificData("reserve",$where);
$data['surplus'] = $this->Vacancy_model->getDay($id);
$data['endtime'] = $this->Vacancy_model->getEndTime($id);
if (count($infor) <= 0)
{
$data['state'] = 2;//别人投放
}else
{
$data['state'] = 1;//自己投放
}
}
$this->Func_model->toJsFunc("vacancyInfor",$this->Func_model->decodeUnicode($data));
}
/*
增加订单
*/
public function addOrder()
{
date_default_timezone_set("Asia/Shanghai");
$ordertime = date("m/d/Y H:i:s");
$msg = isset($_POST['msg'])?$_POST['msg']:"";
if ($msg == "" || $msg == 0)
return ;
$userid = $_SESSION['wid'];
$where = array('id' => $userid);
$infor = $this->Db_model->getSpecificData("user",$where);
if (count($infor) <= 0)
{
$username = "";
}else
{
if ($infor[0]->name == "")
$username = $infor[0]->wxname;
else
$username = $infor[0]->name;
}
$data = array();
$arr = explode('|', $msg);
foreach($arr as $key => $value)
{
$_tmp = explode(',', $value);
$_data = array();
$_data['signid'] = $_tmp[0];
$_data['vacancyid'] = $_tmp[1];
$_data['userid'] = $userid;
$_data['username'] = $username;
$_data['days'] = $_tmp[2];
$_data['isreplace'] = $_tmp[5];
$_data['ordertime'] = $ordertime;
$_data['starttime'] = 0;
$_data['endtime'] = 0;
$_data['cost'] = $_tmp[3];
$_data['design'] = $_tmp[4];
$_data['state'] = $_tmp[7];
$_data['totalcost'] = $_tmp[6];
$where = array('id' => $_data['vacancyid']);
$vacancyinfor = $this->Db_model->getSpecificData("vacancy",$where);
if ($_data['state'] == 0)
{
if (count($vacancyinfor) <= 0)
{
return ;
}else
{
if ($vacancyinfor[0]->state != 0)
{
$this->Func_model->setAlert($this->Config_model->msg[20]);
$this->Func_model->toJsFunc("disMyAd","");
return ;
}
}
}else if ($_data['state'] == 1)
{
$where = array('signid' => $_data['signid'], 'vacancyid' => $_data['vacancyid'], 'userid' => $_data['userid'], 'state' => (int)1);
$infor = $this->Db_model->getSpecificData("reserve",$where);
if (count($infor) <= 0)
{
$this->Func_model->setAlert($this->Config_model->msg[20]);
$this->Func_model->toJsFunc("disMyAd","");
return ;
}else
{
$_data['starttime'] = $this->Vacancy_model->getEndTime($_data['vacancyid']);
if ($_data['starttime'] == 0)
$_data['endtime'] = 0;
else
{
$_data['endtime'] = date("m/d/Y",strtotime($_data['starttime']." +".$_data['days']." day"));
}
}
}
$data[] = $_data;
}
$str = $this->Func_model->arrToString($data, ",", "|");
$myfile = fopen("upload/".$userid.".txt", "w");
fwrite($myfile, $str);
fclose($myfile);
$this->Func_model->setPage("http://erp.itxxoo.com/Wxpay/example/jsapi.php?userid=".$userid."&type=ad");
/*date_default_timezone_set("Asia/Shanghai");
$ordertime = date("m/d/Y H:i:s");
$msg = isset($_POST['msg'])?$_POST['msg']:"";
if ($msg == "" || $msg == 0)
return ;
$userid = $_SESSION['wid'];
$where = array('id' => $userid);
$infor = $this->Db_model->getSpecificData("user",$where);
if (count($infor) <= 0)
{
$username = "";
}else
{
$username = $infor[0]->name;
}
$data = array();
$arr = explode('|', $msg);
foreach($arr as $key => $value)
{
$_tmp = explode(',', $value);
$_data = array();
$_data['signid'] = $_tmp[0];
$_data['vacancyid'] = $_tmp[1];
$_data['userid'] = $userid;
$_data['username'] = $username;
$_data['days'] = $_tmp[2];
$_data['isreplace'] = $_tmp[5];
$_data['ordertime'] = $ordertime;
$_data['starttime'] = 0;
$_data['endtime'] = 0;
$_data['cost'] = $_tmp[3];
$_data['design'] = $_tmp[4];
$_data['state'] = $_tmp[7];
$_data['totalcost'] = $_tmp[6];
$where = array('id' => $_data['vacancyid']);
$vacancyinfor = $this->Db_model->getSpecificData("vacancy",$where);
if ($_data['state'] == 0)
{
if (count($vacancyinfor) <= 0)
{
return ;
}else
{
if ($vacancyinfor[0]->state != 0)
{
$this->Func_model->setAlert($this->Config_model->msg[20]);
$this->Func_model->toJsFunc("disMyAd","");
return ;
}
}
$this->Vacancy_model->setState($_data['vacancyid'], 1);
$this->Ad_model->setFree($_data['signid'], -1);
$this->Db_model->insertData("reserve",$_data);
$where = array('vacancyid' => $_data['vacancyid'], 'state' => $_data['state']);
}else if ($_data['state'] == 1)
{
$where = array('signid' => $_data['signid'], 'vacancyid' => $_data['vacancyid'], 'userid' => $_data['userid'], 'state' => (int)1);
$infor = $this->Db_model->getSpecificData("reserve",$where);
if (count($infor) <= 0)
{
$this->Func_model->setAlert($this->Config_model->msg[20]);
$this->Func_model->toJsFunc("disMyAd","");
return ;
}else
{
$_data['starttime'] = $this->Vacancy_model->getEndTime($_data['vacancyid']);
if ($_data['starttime'] == 0)
$_data['endtime'] = 0;
else
{
$_data['endtime'] = date("m/d/Y",strtotime($_data['starttime']." +".$_data['days']." day"));
}
$this->Db_model->insertData("reserve",$_data);
$where = array('ordertime' => $_data['ordertime']);
}
}
$infor = $this->Db_model->getSpecificData("reserve",$where);
$oid = $infor[0]->id;
$this->Vacancy_model->updateOrder($_data['vacancyid'], $oid, "add");
$this->Func_model->setAlert($this->Config_model->msg[0]);
$this->Func_model->toJsFunc("disMyAd","");
}*/
}
}