westdc-zf1/application/models/order/Order.php

293 lines
6.5 KiB
PHP
Raw Normal View History

<?php
namespace order;
include_once("helper/view.php");
class Order
{
private $db;
private $config;
protected $events = NULL;
public $projectType = array(
"国家973计划项目课题" => "国家973计划项目课题",
"国家863计划课题"=>"国家863计划课题",
"国家级科技支撑课题" => "国家级科技支撑课题",
"国家级科技重大专项" => "国家级科技重大专项",
"国家级国家重大工程" => "国家级国家重大工程",
"国家级国家自然科学基金" => "国家级国家自然科学基金",
"国际合作项目"=>"国际合作项目",
"省部级项目" => "省部级项目",
"其他项目工程" => "其他项目工程",
); //申请中的项目类型
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
public function events(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
/*************
status:
1 开始进入离线申请申请程序中
2 填写并提交离线申请表
3 邮寄离线申请表
4 收到离线申请表
5 处理离线申请表
10:离线申请完成?
-1: 取消了在线下载进程
**************/
//添加到数据篮
public function addOrder($uuid,$uid = 0){
if(empty($uid))
{
$uid = \view::User('id');
}
if(!is_numeric($uid))
{
$uid = \view::User('id');
}
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
{
return "参数错误";
}
$results = $this->events()->trigger('submit', $this, compact('uuid','uid'));
$data = $results->bottom();
if($data !== true)
{
return $data;
}
$results = $this->events()->trigger('checksource', $this, compact('uuid'));
$data = $results->bottom();
if($data !== true)
{
return array("datetype"=>$data,"uuid"=>$uuid);
}
if($this->pushToDataorder($uuid,$uid) === true)
{
return true;
}else{
return "操作中出现错误,请重试";
}
}//addOrder
//放到数据篮中
public function pushToDataorder($uuid,$uid = 0)
{
if(empty($uid))
{
$uid = \view::User('id');
}
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
$rs = $this->db->query($sql,array($uuid,$uid,1));
if($rs)
{
return true;
}else{
return false;
}
}//pushToDataorder
//提交
public function apply($id,$uid = 0)
{
if(!is_numeric($id) || !is_numeric($uid))
{
return "参数错误";
}
if(empty($uid))
{
$uid = \view::User('id');
}
if($id == -1)
{
$sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$uid);
if($this->db->exec($sql))
{
return true;
}else{
return "处理中遇到问题,请重试";
}
}
if($id > 0)
{
$sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=$uid and id=?",$id);
if($this->db->exec($sql))
{
return true;
}else{
return "处理中遇到问题,请重试";
}
}
return "参数错误";
}//apply()
//删除
public function del($id,$uid = 0)
{
if(!is_numeric($id) || !is_numeric($uid))
{
return "参数错误";
}
if(empty($uid))
{
$uid = \view::User('id');
}
if($id > 0)
{
$sql = $this->db->quoteInto("delete from dataorder where userid=$uid and status in (1,2) and id=?",$id);
if($this->db->exec($sql))
{
return true;
}else{
return "处理中遇到错误,请重试";
}
}
return "参数错误";
}
2013-07-22 09:16:18 +00:00
//发送邮件
public function SendEmail(){
}
//生成pdf
public function pdf($uid = 0)
{
}
//获得要生成pdf的信息
public function getOrderItemForPdf($uid = 0)
{
if(empty($uid))
{
$uid = \view::User('id');
}
$sql = "select m.title||'('||m.filesize::text||'MB)' as title,m.ts_published,date_part('year',doi.ts_published) as publish_year,m.citation,m.suppinfo,
array_to_string(ARRAY(
select r.reference from mdref mr left join reference r on mr.refid=r.id
where mr.reftype=3 and mr.uuid=d.uuid order by mr.place),'\n'::text) as reference,
array_to_string(array(
select fund.fund_type||':'||fund.title||'(编号:'||fund.fund_id||')'
2013-07-22 05:23:41 +00:00
from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid order by mdfund.place),'\n'::text) as fund,
doi.doi as datadoi,doi.authors,doi.publisher,doi.title as doititle,doi.author_en,doi.publisher_en,doi.title_en
from dataorder d left join metadata m on d.uuid=m.uuid left join datadoi doi on doi.uuid=d.uuid
where d.status=2 and d.userid=? order by d.ts_created desc
";
$rows = $this->db->fetchAll($sql,array($uid));
return $rows;
}
2013-07-22 09:16:18 +00:00
public function makePdf($formData,$userid = 0)
{
}
public function PdfOrderSave($formData,$uid = 0)
{
}
//checkPdfOrderField 检查PDF申请表的信息
public function checkPdfOrderField($formData)
{
if(empty($formData['realname']))
{
return "请输入真实姓名";
}
if(empty($formData['email']))
{
return "请输入Email";
}
if (!preg_match('/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$formData['email']))
{
return "请输入正确的电子邮件地址";
}
if(empty($formData['phone']))
{
return "请输入联系电话";
}
if(empty($formData['unit']))
{
return "请输入单位";
}
if(empty($formData['address']))
{
return "请输入地址";
}
if(empty($formData['postcode']) || !is_numeric($formData['postcode']))
{
return "请输入邮政编码";
}
if(empty($formData['project_id']))
{
return "请输入项目编号";
}
if(empty($formData['project_type']))
{
return "请选择项目类型";
}
if(empty($formData['project_title']))
{
return "请填写项目标题";
}
if(empty($formData['project']))
{
return "请填写用途";
}
return true;
}//checkPdfOrderField
}