Files
advertising/application/models/admin/Order_model.php

221 lines
5.8 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 Order_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
/*
reserve
*/
public function reserveMsg()
{
date_default_timezone_set("Asia/Shanghai");
$signidrese= isset($_POST['signids'])?$_POST['signids']:"";
$vacancyidrese= isset($_POST['vacancyidv'])?$_POST['vacancyidv']:"";
$usernamerese= isset($_POST['username'])?$_POST['username']:"";
$daysrese= isset($_POST['days'])?$_POST['days']:"";
$designrese= isset($_POST['design'])?$_POST['design']:"";
$isreplacerese= isset($_POST['isreplace'])?$_POST['isreplace']:"";
$ordertimerese= isset($_POST['ordertime'])?$_POST['ordertime']:"";
$starttimerese= isset($_POST['starttime'])?$_POST['starttime']:"";
$endtimerese= isset($_POST['endtime'])?$_POST['endtime']:"";
$totalcostrese= isset($_POST['totalcost'])?$_POST['totalcost']:"";
$adminstate= isset($_POST['adminstate'])?$_POST['adminstate']:"";
$state= isset($_POST['state'])?$_POST['state']:"";
$data = array(
'signid' => $signidrese,
'vacancyid' => $vacancyidrese,
'username' => $usernamerese,
'days' => $daysrese,
'design' => $designrese,
'isreplace' => $isreplacerese,
'ordertime' => $ordertimerese,
'starttime' => $starttimerese,
'endtime' => $endtimerese,
'totalcost' => $totalcostrese,
'adminstate' => $adminstate,
'state' =>$state
);
return $data;
}
/*
解析订单信息
*/
public function setOrderMsg($row)
{
$where = array('id' => $row->signid);
$adinfor = $this->Db_model->getSpecificData("advertisement",$where);
$adnumber = "";
if (count($adinfor) > 0)
$adnumber = $adinfor[0]->number;
$where = array('id' => $row->vacancyid);
$vacancyinfor = $this->Db_model->getSpecificData("vacancy",$where);
$number = "";
$cityid = "";
$areaid = "";
$communityid = "";
if (count($vacancyinfor) > 0)
{
$number = $vacancyinfor[0]->number;
$cityid = $vacancyinfor[0]->cityid;
$areaid = $vacancyinfor[0]->areaid;
$communityid = $vacancyinfor[0]->communityid;
}
$where = array('id' => $cityid);
$cinfor = $this->Db_model->getSpecificData("city",$where);
$city = "";
if (count($cinfor) > 0)
$city = $cinfor[0]->name;
$where = array('id' => $areaid);
$ainfor = $this->Db_model->getSpecificData("area",$where);
$area = "";
if (count($ainfor) > 0)
$area = $ainfor[0]->name;
$where = array('id' => $communityid);
$cinfor = $this->Db_model->getSpecificData("community",$where);
$community = "";
if (count($cinfor) > 0)
$community = $cinfor[0]->name;
$where = array('id' => $row->userid);
$areainfor = $this->Db_model->getSpecificData("user",$where);
$user = "";
/*if (count($areainfor) > 0)
{
$user = $areainfor[0]->name;
if ($areainfor[0]->name == "")
$user = $areainfor[0]->wxname;
}*/
$surplus = $this->getDay($row->id);
$data=array(
'id' => $row->id,
'surplus' => $surplus,
'adnumber' => $adnumber,
'signid' => $row->signid,
'vacancyid' => $row->vacancyid,
'number' => $number,
'username' => $row->username,
'cost' => $row->cost,
'design' => $row->design,
'userid' => $row->userid,
'days' => $row->days,
'isreplace' => $this->Config_model->isreplace[$row->isreplace],
'ordertime' => $row->ordertime,
'starttime' => $row->starttime,
'endtime' => $row->endtime,
'totalcost' => $row->totalcost,
'adminstate' => $row->adminstate,
'city' => $city,
'area' => $area,
'community' => $community,
'state' => $row->state//$this->Config_model->orderState[$row->state]
);
return $data;
}
/*
更新当前订单状态
*/
public function checkOrder($infor)
{
date_default_timezone_set("Asia/Shanghai");
foreach ($infor as $row)
{
$_id = $row->id;
$_vid = $row->vacancyid;
$_signid = $row->signid;
$_day = $row->days;
$_starttime = $row->starttime;
$_endtime = $row->endtime;
$_state = $row->state;
if ($_day != 0 && $_starttime != 0 && $_endtime != 0 && $_state == 1)
{
$time1 = strtotime($_starttime);
$time2 = strtotime($_endtime);
$_time = (($time2-$time1)/3600/24);
if ($_time <= 0)
{
$this->setState($_id, 3);
$len = $this->Vacancy_model->updateOrder($_vid, $_id, "remove");
if ($len <= 0)
{
$this->Vacancy_model->setState($_vid, 0);
$this->Ad_model->setFree($_signid, 1);
}
}
}
}
}
/*
设置订单状态
*/
public function setState($id,$state)
{
$where = array('id' => $id);
$data = array('state' => $state);
$this->Db_model->updateData("reserve",$data,$where);
}
/*
订单开始 / 结束时间
*/
public function resetTime($id, $data)
{
$where = array('id' => $id);
//$data = array('starttime' => 0, 'endtime' => 0);
$this->Db_model->updateData("reserve",$data,$where);
}
/*
取广告定单剩余时间
$oid:定单 id
*/
public function getDay($oid)
{
$_starttime = 0;
$_endtime = 0;
$_time = 0;
$where = array('id' => $oid);
$infor = $this->Db_model->getSpecificData("reserve",$where);
if (count($infor) > 0)
{
$_starttime = $infor[0]->starttime;
$_endtime = $infor[0]->endtime;
$time1 = strtotime($_starttime);
$time2 = strtotime($_endtime);
$_time = (($time2-$time1)/3600/24);
$newstr = substr($_starttime,6,strlen($_starttime));
$newstr1 = substr($_endtime,6,strlen($_starttime));
$newstr12=$newstr1-$newstr;
if($newstr12==1){
$_time=$_time-365;
}
}
if ($_time <= 0)
$_time = 0;
return $_time;
}
}