<?php

Doo::loadCore('db/DooModel');

/**
 * 用户表
 */
class AmeasureAudit extends DooModel
{

    public $maid;
    public $pid;
    public $creatoruid;
    public $auditoruid;
    public $mpid;
    public $pmid;
    public $stid;
    public $numpname;
    public $times;
    public $mastatus;
    public $last;
    public $audittime;
    public $auditcontent;
    public $intime;
    public $onlineaudit;
    public $_table = 'jl_measure_audit';
    public $_primarykey = 'maid';
    public $_fields = array('maid', 'pid', 'creatoruid', 'auditoruid', 'mpid', 'pmid', 'stid', 'numpname', 'times', 'mastatus', 'last', 'audittime', 'auditcontent', 'intime', 'onlineaudit');

    public function __construct()
    {
        parent::setupModel(__CLASS__);
    }

    function getPmidWithStatus($uid, $status)
    {
        return $this->getOne(array('where' => 'mastatus=?', 'param' => array($status), 'asArray' => TRUE));
    }

    function getRowData($maid)
    {
        return $this->getOne(array('where' => 'maid=?', 'param' => array($maid), 'asArray' => true));
    }

    function updateStatus($maid, $status, $auditcontent = 1, $online = 1)
    {
        $this->mastatus = $status;
        $this->audittime = time();
        if($auditcontent != 1){
            $this->auditcontent = '';
        }
        $this->onlineaudit = $online;
        return $this->update(array('where' => 'maid=?', 'param' => array($maid)));
    }

    function getAuditsByMpid($mpid){
        return $this->find(array('select' => 'maid, auditoruid, mastatus, auditcontent', 'where' => 'mpid=?', 'asc' => 'last', 'desc' => 'maid', 'param' => array($mpid), 'asArray' => TRUE));
    }

    function getNumAuditsByMpid($mpid){
        return $this->count(array('where' => 'mpid=?', 'param' => array($mpid), 'asArray' => TRUE));
    }

    function getAuditByMpidStatus($mpid,$status)
    {
        return $this->getOne(array('where' => 'mpid=? and mastatus=?', 'param' => array($mpid, $status), 'desc' => 'last', 'asc' => 'maid', 'asArray' => TRUE));
    }

    public function del($maid)
    {
        return $this->delete(array('where' => 'maid=?', 'param' => array($maid)));
    }

    public function getLastAuditMsgByPmid($pmid){
        return $this->getOne(array('where' => 'pmid=?', 'param' => array($pmid), 'desc' => 'maid', 'asArray' => TRUE));
    }

    public function getAuditsByPmidNumTimes($pmid,$numpname,$times){
        return $this->find(array('select' => 'maid, auditoruid, mastatus, auditcontent', 'where' => 'pmid=? and numpname=? and times=?', 'asc' => 'last', 'desc' => 'maid', 'param' => array($pmid,$numpname,$times), 'asArray' => TRUE));
    }

    public function getNumAuditsByPmidNumTimes($pmid,$numpname,$times){
        return $this->count(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($pmid,$numpname,$times), 'asArray' => TRUE));
    }
}

?>