numofperact.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <?php
  2. Doo::loadModel('numofper');
  3. /**
  4. * Description of numofperact
  5. *
  6. * @author zongheng
  7. */
  8. class NumofperAct {
  9. private $__numofperact;
  10. function __construct() {
  11. $this->__numofperact = new Numofper();
  12. }
  13. public function insert($pid, $uid, $tenderid, $stid, $phaseno, $currcontractval, $currchangeval, $stopnowtotal, $currdone, $curralltotal, $times = 0) {
  14. $this->__numofperact->uid = $uid;
  15. $this->__numofperact->pid = $pid;
  16. $this->__numofperact->pmid = $tenderid;
  17. $this->__numofperact->stid = $stid;
  18. $this->__numofperact->numpname = $phaseno;
  19. $this->__numofperact->times = $times;
  20. $this->__numofperact->currcontractval = $currcontractval;
  21. $this->__numofperact->currchangeval = $currchangeval;
  22. $this->__numofperact->stopnowtotal = $stopnowtotal;
  23. $this->__numofperact->currdone = $currdone;
  24. $this->__numofperact->curralltotal = $curralltotal;
  25. $this->__numofperact->currstatus = 'checking';
  26. $this->__numofperact->audittime = 0;
  27. $this->__numofperact->intime = time();
  28. return $this->__numofperact->insert();
  29. }
  30. public function redoRow($pid, $tenderid, $stid, $phaseno, $times) {
  31. $this->__numofperact->pid = $pid;
  32. $this->__numofperact->pmid = $tenderid;
  33. $this->__numofperact->stid = $stid;
  34. $this->__numofperact->numpname = $phaseno;
  35. if ($times > 0)
  36. $this->__numofperact->times = $times;
  37. $this->__numofperact->currcontractval = 0;
  38. $this->__numofperact->currchangeval = 0;
  39. $this->__numofperact->stopnowtotal = 0;
  40. $this->__numofperact->currdone = 0;
  41. $this->__numofperact->curralltotal = 0;
  42. $this->__numofperact->currstatus = 'checking';
  43. $this->__numofperact->audittime = time();
  44. return $this->__numofperact->insert();
  45. }
  46. public function getRowByMpid($mpid) {
  47. return $this->__numofperact->getOne(array('where' => 'mpid=?', 'param' => array($mpid), 'asArray' => TRUE));
  48. }
  49. public function getCountTotalnum($pmid) {
  50. return $this->__numofperact->count(array('where' => 'pmid=? and currstatus != \'checkno\' ', 'param' => array($pmid), 'asArray' => TRUE));
  51. }
  52. public function getCountTotalnum2($pmid) {
  53. return $this->__numofperact->getOne(array('select' => 'numpname', 'where' => 'pmid=?', 'param' => array($pmid), 'groupby' => 'numpname', 'desc' => 'numpname', 'asArray' => TRUE));
  54. }
  55. public function getMaxStatusTimes($pmid, $numpname) {
  56. return $this->__numofperact->getOne(array('select' => 'currstatus', 'where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname), 'desc' => 'times', 'asArray' => TRUE));
  57. }
  58. // for API
  59. public function getMaxTimes($pmid, $numpname) {
  60. return $this->__numofperact->getOne(array('select' => 'times,currstatus', 'where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname), 'desc' => 'times', 'asArray' => TRUE));
  61. }
  62. public function getCountTotalplus($pmid) {
  63. return $this->__numofperact->getOne(array('select' => 'sum(curralltotal) as totalplus', 'where' => 'pmid=?', 'groupby' => 'numpname', 'desc' => 'times', 'param' => array($pmid), 'asArray' => TRUE));
  64. }
  65. public function getStopNow($pmid) {
  66. return $this->__numofperact->getOne(array('select' => 'sum(stopnowtotal) as sntotal', 'where' => 'pmid=?', 'groupby' => 'numpname', 'desc' => 'times', 'param' => array($pmid), 'asArray' => TRUE));
  67. }
  68. public function getStopNowTotal($pmid) {
  69. return $this->__numofperact->getOne(array('select' => 'stopnowtotal as sntotal', 'where' => 'pmid=?', 'groupby' => 'pmid,numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
  70. }
  71. public function getStopNowSt($stid) {
  72. return $this->__numofperact->getOne(array('select' => 'sum(stopnowtotal) as sntotal', 'where' => 'stid=?', 'param' => array($stid), 'asArray' => TRUE));
  73. }
  74. public function getStopNowT($pmid) {
  75. return $this->__numofperact->getOne(array('select' => 'sum(stopnowtotal) as sntotal', 'where' => 'pmid=?', 'param' => array($pmid), 'DESC' => 'audittime', 'asArray' => TRUE));
  76. }
  77. public function getCurrDoneSt($stid) {
  78. return $this->__numofperact->getOne(array('select' => 'sum(currdone) as currdone', 'where' => 'stid=?', 'param' => array($stid), 'asArray' => TRUE));
  79. }
  80. public function getCurrDonePmid($pmid) {
  81. return $this->__numofperact->getOne(array('select' => 'currdone as currdone', 'where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  82. }
  83. public function getCurrTotal($pmid) {
  84. return $this->__numofperact->getOne(array('select' => 'sum(currcontractval) as currtotal', 'where' => 'pmid=?', 'groupby' => 'numpname', 'desc' => 'times', 'param' => array($pmid), 'asArray' => TRUE));
  85. }
  86. public function getCurrAlltotal($pmid) {
  87. return $this->__numofperact->getOne(array('select' => 'currdone as currtotal', 'where' => 'pmid=?', 'param' => array($pmid), 'groupby' => 'pmid,numpname', 'desc' => 'numpname', 'asArray' => TRUE));
  88. }
  89. public function getCurrdoneNew($pmid) {
  90. return $this->__numofperact->getOne(array('select' => 'currdone as currtotal', 'where' => 'pmid=?', 'param' => array($pmid), 'desc' => 'mpid', 'asArray' => TRUE));
  91. }
  92. public function getCountTotalSTID($stid) {
  93. return $this->__numofperact->getOne(array('select' => 'sum(curralltotal) as totalplus', 'where' => 'stid=? and currstatus != \'checkno\'', 'param' => array($stid), 'asArray' => TRUE));
  94. }
  95. public function getCountTotalSTID2($stid) {
  96. $pdArray = NULL;
  97. $pdArray = $this->getPMID($stid);
  98. $totalPlus = 0;
  99. if ($pdArray)
  100. foreach ($pdArray as $value) {
  101. $t = $this->getMaxNumORTimes($value['pmid']);
  102. $totalPlus = $totalPlus + $t;
  103. }
  104. return array('totalplus' => $totalPlus);
  105. }
  106. // 根据条件STID获取分组后的PMID
  107. public function getPMID($stid) {
  108. return $this->__numofperact->find(array('select' => 'pmid', 'where' => 'stid=? and currstatus != \'checkno\'', 'groupby' => 'pmid', 'param' => array($stid), 'asArray' => TRUE));
  109. }
  110. // 根据条件STID获取分组后的PMID
  111. public function getMaxNumORTimes($pmid) {
  112. $pmidArray = $this->__numofperact->getOne(array('where' => 'pmid=? and currstatus != \'checkno\'', 'param' => array($pmid), 'desc' => 'mpid', 'asArray' => TRUE));
  113. return $pmidArray['curralltotal'];
  114. }
  115. public function getNumByStid($stid) {
  116. return $this->__numofperact->find(array('where' => 'stid=?', 'param' => array($stid), 'desc' => 'mpid', 'asArray' => TRUE));
  117. }
  118. public function getRowByPmid($pmid) {
  119. return $this->__numofperact->find(array('where' => 'pmid=? and currstatus != \'checkno\'', 'param' => array($pmid), 'asArray' => TRUE));
  120. }
  121. public function getGroupByLastOne($pmid) {
  122. return $this->__numofperact->find(array('where' => 'pmid=? and currstatus!=\'checkno\'', 'groupby' => 'numpname', 'desc' => 'numpname,times', 'param' => array($pmid), 'asArray' => TRUE));
  123. }
  124. public function getGroupByLastOne2($pmid) {
  125. return $this->__numofperact->find(array('where' => 'pmid=?', 'groupby' => 'numpname', 'desc' => 'numpname,times', 'param' => array($pmid), 'asArray' => TRUE));
  126. }
  127. public function getRowByPmid2($pmid) {
  128. return $this->__numofperact->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  129. }
  130. public function getRowTender($pmid) {
  131. return $this->__numofperact->find(array('where' => 'pmid=?', 'orderby' => 'numpname', 'param' => array($pmid), 'desc' => 'mpid', 'asArray' => TRUE));
  132. }
  133. public function getRowTender2($pmid) {
  134. return $this->__numofperact->getOne(array('where' => 'pmid=?', 'orderby' => 'numpname', 'param' => array($pmid), 'desc' => 'mpid', 'asArray' => TRUE));
  135. }
  136. public function getRowTenderCurr($pmid) {
  137. return $this->__numofperact->find(array('where' => 'numpname=(SELECT max(numpname) FROM jl_measure_numofper where pmid=?) and pmid=?', 'orderby' => 'numpname', 'param' => array($pmid, $pmid), 'desc' => 'mpid', 'asArray' => TRUE));
  138. }
  139. public function getAlluserMeasureAudit($bid, $num) {
  140. return $this->__numofperact->getOne(array('select' => 'mpid', 'where' => 'pmid=? and numpname=?', 'param' => array($bid, $num), 'asArray' => TRUE));
  141. }
  142. public function getNumOfStatus($bid, $num) {
  143. return $this->__numofperact->getOne(array('where' => 'pmid=? and numpname=?', 'param' => array($bid, $num), 'asArray' => TRUE));
  144. }
  145. public function getCurrStatus($mpid) {
  146. return $this->__numofperact->getOne(array('where' => 'mpid=?', 'param' => array($mpid), 'asArray' => TRUE));
  147. }
  148. public function getRow($pmid, $numpname, $times = 0) {
  149. return $this->__numofperact->getOne(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($pmid, $numpname, $times), 'asArray' => TRUE));
  150. }
  151. public function hasTheTimesRow($pmid, $numpname, $times = 0) {
  152. return $this->__numofperact->count(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($pmid, $numpname, $times), 'asArray' => TRUE));
  153. }
  154. public function getMaxRowStatus($pmid, $numpname) {
  155. return $this->__numofperact->getOne(array('where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname), 'desc' => 'times', 'asArray' => TRUE));
  156. }
  157. public function getChecknoRow($pmid, $numpname) {
  158. return $this->__numofperact->getOne(array('where' => 'pmid=? and numpname=?', 'desc' => 'times', 'param' => array($pmid, $numpname), 'asArray' => TRUE));
  159. }
  160. // public function getMaxCurrStatus($pid, $pmid, $stid) {
  161. // return $this->__numofperact->getOne(array('where' => 'numpname=(SELECT max(numpname) FROM jl_measure_numofper where pid=? and pmid=? and stid=?)', 'param' => array($pid, $pmid, $stid), 'asArray' => TRUE));
  162. // }
  163. public function getLastStatus($pid, $pmid) {
  164. return $this->__numofperact->getOne(array('where' => 'pid=? and pmid=? and currstatus != \'checkno\'', 'desc' => 'numpname', 'param' => array($pid, $pmid), 'asArray' => TRUE));
  165. }
  166. public function getLastStatus2($pid, $pmid) {
  167. return $this->__numofperact->getOne(array('where' => 'pid=? and pmid=?', 'groupby' => 'pmid,numpname,times', 'desc' => 'times', 'param' => array($pid, $pmid), 'asArray' => TRUE));
  168. }
  169. public function getLastStatus3($pid, $pmid) {
  170. return $this->__numofperact->getOne(array('where' => 'pid=? and pmid=?', 'desc' => 'numpname', 'param' => array($pid, $pmid), 'asArray' => TRUE));
  171. }
  172. public function getLastRow($pid, $pmid) {
  173. return $this->__numofperact->getOne(array('where' => 'pid=? and pmid=?', 'groupby' => 'numpname,times', 'desc' => 'mpid', 'param' => array($pid, $pmid), 'asArray' => TRUE));
  174. }
  175. public function getChangTotal($pid) {
  176. return $this->__numofperact->getOne(array('select' => 'sum(currchangeval) as changtotal', 'where' => 'pid=? and currstatus != \'checkno\'', 'param' => array($pid), 'asArray' => TRUE))['changtotal'];
  177. }
  178. public function getCurrDone($pid) {
  179. return $this->__numofperact->getOne(array('select' => 'sum(currdone) as currdone', 'where' => 'pid=?', 'param' => array($pid), 'asArray' => TRUE))['currdone'];
  180. }
  181. public function getCurrDoneNow($pid) {
  182. return $this->__numofperact->getOne(array('select' => 'sum(currdone) as currdone', 'where' => 'pid=? and currstatus!=\'checkno\'', 'param' => array($pid), 'asArray' => TRUE))['currdone'];
  183. }
  184. public function getCheckedCurrdone($stid) {
  185. return $this->__numofperact->getOne(array('select' => 'sum(currdone) as currdone', 'where' => 'stid = ?', 'param' => array($stid), 'asArray' => TRUE))['currdone'];
  186. }
  187. public function getMaxCurrStatus($pid, $pmid, $stid) {
  188. return $this->__numofperact->getOne(array('where' => 'numpname = (SELECT max(numpname) FROM jl_measure_numofper where pid = ? and pmid = ? and stid = ?)', 'param' => array($pid, $pmid, $stid), 'asArray' => TRUE));
  189. }
  190. //标段下最新一期
  191. public function getLastNew($pmid) {
  192. return $this->__numofperact->getOne(array('select' => 'stopnowtotal, currdone', 'where' => 'pmid = ?', 'groupby' => 'pmid, numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
  193. // return $this->__numofperact->getOne(array('select' => 'stopnowtotal, currdone', 'where' => 'pmid = ? and currstatus!=\'checkno\'', 'orderby' => 'numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
  194. }
  195. //标段下最新一期
  196. public function getLastNew2($pmid) {
  197. return $this->__numofperact->getOne(array('where' => 'pmid = ?', 'groupby' => 'pmid, numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
  198. // return $this->__numofperact->getOne(array('select' => 'stopnowtotal, currdone', 'where' => 'pmid = ? and currstatus!=\'checkno\'', 'orderby' => 'numpname', 'desc' => 'numpname', 'param' => array($pmid), 'asArray' => TRUE));
  199. }
  200. //更新数据
  201. public function updateNumofper($tenderid, $phaseno, $itemArray, $times = 0) {
  202. if (!is_array($itemArray)) {
  203. return FALSE;
  204. }
  205. $this->__numofperact->currcontractval = $itemArray['BQHTJL'];
  206. $this->__numofperact->currchangeval = $itemArray['BQSLBGJL'];
  207. $this->__numofperact->stopnowtotal = $itemArray['JZSQLJWC'];
  208. $this->__numofperact->currdone = $itemArray['BQWCJL'];
  209. $this->__numofperact->curralltotal = $itemArray['LJWCJL'];
  210. return $this->__numofperact->update(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($tenderid, $phaseno, $times)));
  211. }
  212. //更新数据
  213. public function updateAuditStatus($tenderid, $phaseno, $statuno = 'checking', $times = 0) {
  214. $this->__numofperact->currstatus = $statuno;
  215. $this->__numofperact->audittime = time();
  216. return $this->__numofperact->update(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($tenderid, $phaseno, $times)));
  217. }
  218. // public function getCurrdoneSTID($stid) {
  219. // return $this->__numofperact->getOne(array('select' => 'sum(currdone) as totalplus', 'where' => 'stid=?', 'param' => array($stid), 'asArray' => TRUE));
  220. // }
  221. public function getCurrdoneSTID($stid) {
  222. return $this->__numofperact->getOne(array('select' => 'sum(currdone) as totalplus', 'where' => 'stid=? and currstatus!=\'checkno\'', 'param' => array($stid), 'asArray' => TRUE));
  223. }
  224. public function getCurrDoneSMontht($stid) {
  225. return $this->__numofperact->find(array('select' => 'sum(currdone) as currdone,FROM_UNIXTIME(audittime,"%Y-%m") as month', 'where' => 'stid=?'
  226. , 'param' => array($stid), 'groupby' => 'FROM_UNIXTIME(audittime,"%Y-%m")', 'asc' => 'audittime', 'asArray' => TRUE));
  227. }
  228. public function getStopNowStMonth($stid) {
  229. return $this->__numofperact->find(array('select' => 'sum(stopnowtotal) as sntotal,FROM_UNIXTIME(audittime,"%Y-%m") as month', 'where' => 'stid=? '
  230. , 'param' => array($stid), 'groupby' => 'FROM_UNIXTIME(audittime,"%Y-%m")', 'asc' => 'audittime', 'asArray' => TRUE));
  231. }
  232. public function getCurrTotalStMonth($stid) {
  233. return $this->__numofperact->find(array('select' => 'sum(curralltotal) as currtotal,FROM_UNIXTIME(audittime,"%Y-%m") as month', 'where' => 'stid=? '
  234. , 'param' => array($stid), 'groupby' => 'FROM_UNIXTIME(audittime,"%Y-%m")', 'asc' => 'audittime', 'asArray' => TRUE));
  235. }
  236. public function getCountTimes($pmid, $numpname, $times) {
  237. return $this->__numofperact->count(array('where' => 'pmid=? and numpname=? and times=?', 'param' => array($pmid, $numpname, $times)));
  238. }
  239. public function getCountNumpname($pmid, $numpname) {
  240. return $this->__numofperact->count(array('where' => 'pmid=? and numpname=?', 'param' => array($pmid, $numpname)));
  241. }
  242. public function getCurrDonePmMonth($pmid) {
  243. return $this->__numofperact->find(array('select' => 'sum(currdone) as currdone,FROM_UNIXTIME(intime,"%Y-%m") as month', 'where' => 'pmid=? and currstatus!=\'checkno\''
  244. , 'param' => array($pmid), 'groupby' => 'FROM_UNIXTIME(intime,"%Y-%m")', 'asc' => 'intime', 'asArray' => TRUE));
  245. }
  246. public function getCurrTotalPmMonth($pmid) {
  247. return $this->__numofperact->find(array('select' => 'sum(curralltotal) as currtotal,FROM_UNIXTIME(intime,"%Y-%m") as month', 'where' => 'pmid=? and currstatus!=\'checkno\''
  248. , 'param' => array($pmid), 'groupby' => 'FROM_UNIXTIME(intime,"%Y-%m")', 'asc' => 'intime', 'asArray' => TRUE));
  249. }
  250. public function getCurrDoneStMonthNoCheckno($stid) {
  251. return $this->__numofperact->find(array('select' => 'sum(currdone) as currdone,FROM_UNIXTIME(intime,"%Y-%m") as month', 'where' => 'stid=? and currstatus!=\'checkno\''
  252. , 'param' => array($stid), 'groupby' => 'FROM_UNIXTIME(intime,"%Y-%m")', 'asc' => 'intime', 'asArray' => TRUE));
  253. }
  254. public function getCurrTotalStMonthNoCheckno($stid) {
  255. $sql = 'SELECT sum(curralltotal) as currtotal,FROM_UNIXTIME(intime,"%Y-%m") as month FROM (SELECT max(mpid) as mpid,max(cast(`curralltotal` as DECIMAL)) as curralltotal,max(intime) as intime FROM `jl_measure_numofper` WHERE stid='.$stid.' AND currstatus!=\'checkno\' GROUP BY pmid) as tmptable GROUP BY FROM_UNIXTIME(intime,"%Y-%m") ORDER BY intime ASC';
  256. $query = Doo::db ()->query ( $sql );
  257. $result = $query->fetchAll ();
  258. return $result;
  259. // return $this->__numofperact->find(array('select' => 'sum(curralltotal) as currtotal,FROM_UNIXTIME(intime,"%Y-%m") as month', 'where' => 'stid=? and currstatus!=\'checkno\''
  260. // , 'param' => array($stid), 'groupby' => 'FROM_UNIXTIME(intime,"%Y-%m")', 'asc' => 'intime', 'asArray' => TRUE));
  261. }
  262. }