<?php

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

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

    public $mpid;
    public $iszero;
    public $uid;
    public $pid;
    public $pmid;
    public $stid;
    public $numpname;
    public $times;
    public $currcontractval;
    public $currchangeval;
    public $stopnowtotal;
    public $currdone;
    public $curralltotal;
    public $currstatus;
    public $audittime;
    public $_table = 'jl_measure_numofper';
    public $_primarykey = 'mpid';
    public $_fields = array('pmid', 'iszero', 'uid', 'pid', 'pmid', 'stid', 'numpname', 'times', 'currcontractval', 'currchangeval', 'stopnowtotal', 'currcontractval', 'currdone', 'curralltotal', 'currstatus', 'audittime');

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

    //标段下最新一期
    public function getLastNew2($pmid) {
        return $this->getOne(array('where' => 'pmid = ?', 'groupby' => 'pmid, numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
//	return $this->__numofperact->getOne(array('select' => 'stopnowtotal, currdone', 'where' => 'pmid = ? and currstatus!=\'checkno\'', 'orderby' => 'numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
    }

    public function getMaxStatusTimes($pmid, $numpname) {
        return $this->getOne(array('select' => 'currstatus', 'where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname), 'desc' => 'times', 'asArray' => TRUE));
    }

    //获取标段的所有期数
    public function getGroupByLastOne2($pmid) {
        return $this->find(array('where' => 'pmid=?', 'groupby' => 'numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
    }

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

    //更新数据
    public function updateAuditStatus($mpid, $statuno = 'checking') {
        $this->currstatus = $statuno;
        $this->audittime = $statuno != 'checking' ? time() : 0;
        return $this->update(array('where' => 'mpid=?', 'param' => array($mpid)));
    }

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

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

}

?>