change.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <?php
  2. Doo::loadModel('change');
  3. Doo::loadModel('changeatt');
  4. Doo::loadModel('changeaudit');
  5. Doo::loadModel('changeauditlist');
  6. Doo::loadModel('changelist');
  7. Doo::loadModel('changecompany');
  8. class Changes
  9. {
  10. private $__change,$__changeatt,$__changeaudit,$__changeauditlist,$__changelist,$__changecompany;
  11. function __construct()
  12. {
  13. $this->__change = new Change();
  14. $this->__changeatt = new ChangeAtt();
  15. $this->__changeaudit = new ChangeAudit();
  16. $this->__changeauditlist = new ChangeAuditList();
  17. $this->__changelist = new ChangeList();
  18. $this->__changecompany = new ChangeCompany();
  19. }
  20. //change
  21. public function insertChangeMsg($pmArr,$uid,$cmsg)
  22. {
  23. $this->__change->pid = $pmArr['pid'];
  24. $this->__change->stid = $pmArr['stid'];
  25. $this->__change->pmid = $pmArr['pmid'];
  26. $this->__change->uid = $uid;
  27. $this->__change->pnum = $cmsg['pnum'];
  28. $this->__change->pname = $cmsg['pname'];
  29. $this->__change->mnum = $cmsg['mnum'];
  30. $this->__change->odname = $cmsg['odname'];
  31. $this->__change->onum = $cmsg['onum'];
  32. $this->__change->cdname = $cmsg['cdname'];
  33. $this->__change->cnum = $cmsg['cnum'];
  34. $this->__change->description = $cmsg['description'];
  35. $this->__change->basis = $cmsg['basis'];
  36. $this->__change->remarks = $cmsg['remarks'];
  37. $this->__change->ctype = !empty($cmsg['ctype']) ? implode(',', $cmsg['ctype']) : '';
  38. $this->__change->category = $cmsg['category'];
  39. $this->__change->cnature = $cmsg['cnature'];
  40. $this->__change->companyid = $cmsg['companyid'];
  41. $this->__change->bear = $cmsg['bear'];
  42. $this->__change->decimalnum = $cmsg['changedecimalnum'];
  43. $this->__change->status = isset($cmsg['uncheck']) ? 'uncheck' : 'checking';
  44. $this->__change->intime = time();
  45. $this->__change->cintime = time();
  46. return $this->__change->insert();
  47. }
  48. public function updateChangeMsg($cid,$cmsg,$times,$status = '')
  49. {
  50. $this->__change->cid = $cid;
  51. $this->__change->pnum = $cmsg['pnum'];
  52. $this->__change->pname = $cmsg['pname'];
  53. $this->__change->mnum = $cmsg['mnum'];
  54. $this->__change->odname = $cmsg['odname'];
  55. $this->__change->onum = $cmsg['onum'];
  56. $this->__change->cdname = $cmsg['cdname'];
  57. $this->__change->cnum = $cmsg['cnum'];
  58. $this->__change->description = $cmsg['description'];
  59. $this->__change->basis = $cmsg['basis'];
  60. $this->__change->remarks = $cmsg['remarks'];
  61. $this->__change->ctype = !empty($cmsg['ctype']) ? implode(',', $cmsg['ctype']) : '';
  62. $this->__change->category = $cmsg['category'];
  63. $this->__change->cnature = $cmsg['cnature'];
  64. $this->__change->companyid = $cmsg['companyid'];
  65. $this->__change->bear = $cmsg['bear'];
  66. $this->__change->decimalnum = $cmsg['changedecimalnum'];
  67. $this->__change->times = $times;
  68. if($status != ''){
  69. $this->__change->status = $status;
  70. }
  71. $this->__change->cintime = time();
  72. return $this->__change->update();
  73. }
  74. public function getListbyMydetail($pmid='',$uid,$limit)
  75. {
  76. if(empty($pmid)){
  77. return $this->__change->find(array('where' => '(status="checking" or status="back" or status="uncheck") and cid in(select `jl_change_audit`.cid from `jl_change_audit` where `jl_change_audit`.uid=? and `jl_change_audit`.status="checking") and pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1)', 'param' => array($uid), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  78. }else{
  79. return $this->__change->find(array('where' => 'pmid=? and (status="checking" or status="back" or status="uncheck") and cid in(select `jl_change_audit`.cid from `jl_change_audit` where `jl_change_audit`.uid=? and `jl_change_audit`.status="checking") and pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1)', 'param' => array($pmid,$uid), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  80. }
  81. }
  82. public function getNumbystatus($pmid='',$status,$status2 = '',$sql = '')
  83. {
  84. if(!empty($status2)){
  85. if(empty($pmid)){
  86. return $this->__change->count(array('where' => '(status=? or status=?)'.$sql, 'param' => array($status,$status2), 'asArray' => TRUE));
  87. }else{
  88. return $this->__change->count(array('where' => 'pmid=? and (status=? or status=?)'.$sql, 'param' => array($pmid,$status,$status2), 'asArray' => TRUE));
  89. }
  90. }else{
  91. if(empty($pmid)){
  92. return $this->__change->count(array('where' => 'status=?'.$sql, 'param' => array($status), 'asArray' => TRUE));
  93. }else{
  94. return $this->__change->count(array('where' => 'pmid=? and status=?'.$sql, 'param' => array($pmid,$status), 'asArray' => TRUE));
  95. }
  96. }
  97. }
  98. public function getListbyStatus($pmid='',$status,$limit,$status2 = '',$sql = '')
  99. {
  100. if(!empty($status2)){
  101. if(empty($pmid)){
  102. return $this->__change->find(array('where' => '(status=? or status=?)'.$sql, 'param' => array($status,$status2), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  103. }else{
  104. return $this->__change->find(array('where' => 'pmid=? and (status=? or status=?)'.$sql, 'param' => array($pmid,$status,$status2), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  105. }
  106. }else{
  107. if(empty($pmid)){
  108. return $this->__change->find(array('where' => 'status=?'.$sql, 'param' => array($status), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  109. }else{
  110. return $this->__change->find(array('where' => 'pmid=? and status=?'.$sql, 'param' => array($pmid,$status), 'desc' => 'cid', 'limit' => $limit, 'asArray' => TRUE));
  111. }
  112. }
  113. }
  114. public function updateChangeTotalamount($cid,$total)
  115. {
  116. $this->__change->cid = $cid;
  117. $this->__change->totalamount = $total;
  118. $this->__change->update();
  119. }
  120. public function getChangebyid($cid)
  121. {
  122. return $this->__change->getOne(array('where' => 'cid=?', 'param' => array($cid), 'asArray' => TRUE));
  123. }
  124. public function getNeedChangeAllList($uid)
  125. {
  126. return $this->__change->find(array('select' => 'cid,pid,stid,pmid', 'where' => 'cid in (select `cid` from `jl_change_audit` where uid=? and status="checking")', 'param' => array($uid), 'asArray' => TRUE));
  127. }
  128. public function getPassChangeListID($pmid)
  129. {
  130. return $this->__change->find(array('select' =>'cid','where' => 'pmid=? and status="checked"', 'param' => array($pmid), 'asArray' => TRUE));
  131. }
  132. public function getLastChangePnum($pmid)
  133. {
  134. return $this->__change->getOne(array('select' => 'pnum', 'where' => 'pmid=? and status!="del"', 'param' => array($pmid), 'desc' => 'cid','asArray' => TRUE));
  135. }
  136. //搜索该标段有无相同申请编号的变更令
  137. public function getChangebyPnumPmid($pnum,$pmid,$cid = '')
  138. {
  139. if($cid != ''){
  140. return $this->__change->getOne(array('where' => 'pnum=? and pmid=? and cid!=? and status!="del" and status!="checkno"', 'param' => array($pnum,$pmid,$cid), 'asArray' => TRUE));
  141. }else{
  142. return $this->__change->getOne(array('where' => 'pnum=? and pmid=? and status!="del" and status!="checkno"', 'param' => array($pnum,$pmid), 'asArray' => TRUE));
  143. }
  144. }
  145. public function delChangebyCid($cid)
  146. {
  147. return $this->__change->delete(array('where' => 'cid=?', 'param' => array($cid), 'asArray' => TRUE));
  148. }
  149. public function updateChangeDecimalNum($cid,$dnum)
  150. {
  151. $this->__change->cid = $cid;
  152. $this->__change->decimalnum = $dnum;
  153. return $this->__change->update();
  154. }
  155. public function updateChangeStatus($cid,$status = 'del')
  156. {
  157. $this->__change->cid = $cid;
  158. $this->__change->status = $status;
  159. $this->__change->cintime = time();
  160. return $this->__change->update();
  161. }
  162. //changeatt
  163. public function insertChangeAtt($files)
  164. {
  165. $this->__changeatt->pid = $files['pid'];
  166. $this->__changeatt->stid = $files['stid'];
  167. $this->__changeatt->pmid = $files['pmid'];
  168. $this->__changeatt->cid = $files['cid'];
  169. $this->__changeatt->uid = $files['uid'];
  170. $this->__changeatt->filename = $files['filename'];
  171. $this->__changeatt->fileext = $files['fileext'];
  172. $this->__changeatt->filesize = $files['filesize'];
  173. $this->__changeatt->filepath = $files['filepath'];
  174. $this->__changeatt->intime = $files['intime'];
  175. return $this->__changeatt->insert();
  176. }
  177. public function getChangeAttbyFid($id)
  178. {
  179. return $this->__changeatt->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  180. }
  181. public function getChangeAttListbycid($cid)
  182. {
  183. return $this->__changeatt->find(array('where' => 'cid=?', 'asc' => 'intime', 'param' => array($cid), 'asArray' => TRUE));
  184. }
  185. public function delChangeAttbyFid($fid)
  186. {
  187. return $this->__changeatt->delete(array('where' => 'id=?', 'param' => array($fid), 'asArray' => TRUE));
  188. }
  189. //changeaudit
  190. public function getNeedChangeNumbyUid($uid)
  191. {
  192. return $this->__changeaudit->count(array('where' => 'uid=? and status="checking" and pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1)', 'param' => array($uid), 'asArray' => TRUE));
  193. }
  194. public function getPmidGroup($uid)
  195. {
  196. // return $this->__changeaudit->find(array('where' => 'uid=? and cid in (SELECT `jl_change`.`cid` FROM `jl_change` WHERE `jl_change`.status!="uncheck")', 'param' => array($uid), 'groupby' => 'pmid', 'asArray' => TRUE));
  197. $sql = 'SELECT a.* FROM `jl_change_audit` as a join `jl_project_measure` as b on a.pmid=b.pmid WHERE a.uid='.$uid.' and a.cid in (SELECT `jl_change`.`cid` FROM `jl_change` WHERE `jl_change`.status!="uncheck") and a.pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1) GROUP BY a.pmid order by convert(b.pmname using gbk)';
  198. $query = Doo::db ()->query ( $sql );
  199. $result = $query->fetchAll ();
  200. return $result;
  201. }
  202. public function getNumbyMydetail($pmid='',$uid)
  203. {
  204. if(empty($pmid)){
  205. return $this->__changeaudit->count(array('where' => 'uid=? and status="checking" and pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1)', 'param' => array($uid), 'asArray' => TRUE));
  206. }else{
  207. return $this->__changeaudit->count(array('where' => 'pmid=? and uid=? and status="checking" and pid in (SELECT `jl_project`.`pid` FROM `jl_project` WHERE `jl_project`.`switch_change`=1)', 'param' => array($pmid,$uid), 'asArray' => TRUE));
  208. }
  209. }
  210. public function getOneAuditbystatus($cid,$status)
  211. {
  212. return $this->__changeaudit->getOne(array('where' => 'cid=? and status=? and usite!=0', 'param' => array($cid,$status), 'asArray' => TRUE));
  213. }
  214. public function getChangeAuditsbycid($cid)
  215. {
  216. return $this->__changeaudit->find(array('where' => 'cid=?', 'asc' => 'id', 'param' => array($cid), 'asArray' => TRUE));
  217. }
  218. public function getChangeAuditsbySort($cid,$notime = '')
  219. {
  220. if($notime != ''){
  221. return $this->__changeaudit->find(array('where' => 'cid=? and times!=?', 'asc' => 'usort', 'param' => array($cid,$notime), 'asArray' => TRUE));
  222. }else{
  223. return $this->__changeaudit->find(array('where' => 'cid=?', 'asc' => 'usort', 'param' => array($cid), 'asArray' => TRUE));
  224. }
  225. }
  226. public function getChangeAuditsbycidtime($cid,$times)
  227. {
  228. return $this->__changeaudit->find(array('where' => 'cid=? and times=? and usite!=0', 'groupby' => 'usite', 'asc' => 'usort', 'param' => array($cid,$times), 'asArray' => TRUE));
  229. }
  230. public function getChangeAuditbylastlist($cid,$times)
  231. {
  232. $sql = 'SELECT * FROM (SELECT MAX(usort) as ust FROM `jl_change_audit` WHERE cid='.$cid.' and times='.$times.' and usite!=0 GROUP BY usite ) as b JOIN `jl_change_audit` as a ON a.usort = b.ust WHERE cid='.$cid.' and times='.$times.' and usite!=0 ORDER BY usite';
  233. $query = Doo::db ()->query ( $sql );
  234. $result = $query->fetchAll ();
  235. return $result;
  236. }
  237. public function getOneChangeAudit($uid,$cid,$times)
  238. {
  239. return $this->__changeaudit->getOne(array('where' => 'cid=? and uid=? and times=? and usite!=0', 'desc' => 'usort', 'param' => array($cid,$uid,$times), 'asArray' => TRUE));
  240. }
  241. public function updateChangeAudit($uid,$cid,$times,$status,$desc,$time,$list = '')
  242. {
  243. $oneaudit = $this->getOneChangeAudit($uid,$cid,$times);
  244. $this->__changeaudit->id = $oneaudit['id'];
  245. $this->__changeaudit->status = $status;
  246. $this->__changeaudit->sdesc = $desc;
  247. $this->__changeaudit->sintime = $time;
  248. $this->__changeaudit->list_json = $list;
  249. $this->__changeaudit->update();
  250. }
  251. //默认取最后一个审批人,site取0则取最后一个创建人
  252. public function getChangeAuditLastUser($cid,$site = 1)
  253. {
  254. $sql = $site == 0 ? ' and usite=0' : '';
  255. return $this->__changeaudit->getOne(array('where' => 'cid=?'.$sql, 'desc' => 'usort', 'param' => array($cid), 'asArray' => TRUE));
  256. }
  257. public function delChangeAuditbyCid($cid)
  258. {
  259. return $this->__changeaudit->delete(array('where' => 'cid=?', 'param' => array($cid), 'asArray' => TRUE));
  260. }
  261. public function getChangeAuditsMaxUsite($cid,$times)
  262. {
  263. return $this->__changeaudit->getOne(array('select' => 'MAX(usite) as maxsite', 'where' => 'cid=? and times=?', 'groupby' => 'times', 'param' => array($cid,$times) , 'asArray' => TRUE));
  264. }
  265. //changeauditlist
  266. public function getChangeAuditListbycid($cid)
  267. {
  268. return $this->__changeauditlist->find(array('where' => 'cid=?', 'asc' => 'convert(lnum using gbk)', 'param' => array($cid), 'asArray' => TRUE));
  269. }
  270. public function getOneChangeAuditList($lid)
  271. {
  272. return $this->__changeauditlist->getOne(array('where' => 'id=?', 'param' => array($lid), 'asArray' => TRUE));
  273. }
  274. public function delChangeAuditListbyCid($cid)
  275. {
  276. return $this->__changeauditlist->delete(array('where' => 'cid=?', 'param' => array($cid)));
  277. }
  278. //changelist
  279. public function insertChangelist($pmArray,$listArray)
  280. {
  281. $this->__changelist->pid = $pmArray['pid'];
  282. $this->__changelist->stid = $pmArray['stid'];
  283. $this->__changelist->pmid = $pmArray['pmid'];
  284. $this->__changelist->lnum = trim($listArray['lnum']);
  285. $this->__changelist->lname = trim($listArray['lname']);
  286. $this->__changelist->unit = trim($listArray['unit']);
  287. $this->__changelist->unitprice = $listArray['unitprice'];
  288. $this->__changelist->amount = $listArray['amount'];
  289. $this->__changelist->insert();
  290. }
  291. public function getChangeListbyPmid($pmid = '',$sql = '')
  292. {
  293. if(empty($pmid)){
  294. return $this->__changelist->find(array('where' => $sql, 'asc' => 'convert(lnum using gbk)', 'asArray' => TRUE));
  295. }else{
  296. return $this->__changelist->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asc' => 'convert(lnum using gbk)', 'asArray' => TRUE));
  297. }
  298. }
  299. public function getChangeListbyid($id)
  300. {
  301. return $this->__changelist->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  302. }
  303. public function getChangeListbylname($lname)
  304. {
  305. return $this->__changelist->getOne(array('where' => 'lname=?', 'param' => array(trim($lname)), 'asArray' => TRUE));
  306. }
  307. public function delChangeListbyPmid($pmid)
  308. {
  309. return $this->__changelist->delete(array('where' => 'pmid=?', 'param' => array($pmid)));
  310. }
  311. //changecompany
  312. public function getCompanyList($pmid = '')
  313. {
  314. if($pmid != ''){
  315. return $this->__changecompany->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  316. }else{
  317. return $this->__changecompany->find(array('asArray' => TRUE));
  318. }
  319. }
  320. public function getCompanybyid($id)
  321. {
  322. return $this->__changecompany->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  323. }
  324. public function delAllChangebyPmid($pmid)
  325. {
  326. // TODO: 根据pmid删除所有相关联的变更令内容
  327. // TODO: 项目管理和前台删除标段中使用
  328. $changeattlist = $this->__changeatt->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  329. if(!empty($changeattlist)){
  330. include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
  331. foreach($changeattlist as $k => $v){
  332. $this->IoHandler = new IoHandler();
  333. $path = DOO::conf()->SITE_PATH.$v['filepath'];
  334. $this->IoHandler->DeleteFile($path);
  335. $this->delChangeAttbyFid($v['id']);
  336. }
  337. }
  338. $this->__changelist->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  339. $this->__changeaudit->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  340. $this->__changeauditlist->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  341. $this->__changecompany->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  342. $this->__change->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  343. }
  344. }