change.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. public function getChangeDoingCount($pid)
  163. {
  164. return $this->__change->count(array('where' => 'pid=? and status in ("uncheck", "checking", "checked")', 'param' => array($pid), 'asArray' => TRUE));
  165. }
  166. //changeatt
  167. public function insertChangeAtt($files)
  168. {
  169. $this->__changeatt->pid = $files['pid'];
  170. $this->__changeatt->stid = $files['stid'];
  171. $this->__changeatt->pmid = $files['pmid'];
  172. $this->__changeatt->cid = $files['cid'];
  173. $this->__changeatt->uid = $files['uid'];
  174. $this->__changeatt->filename = $files['filename'];
  175. $this->__changeatt->fileext = $files['fileext'];
  176. $this->__changeatt->filesize = $files['filesize'];
  177. $this->__changeatt->filepath = $files['filepath'];
  178. $this->__changeatt->intime = $files['intime'];
  179. return $this->__changeatt->insert();
  180. }
  181. public function getChangeAttbyFid($id)
  182. {
  183. return $this->__changeatt->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  184. }
  185. public function getChangeAttListbycid($cid)
  186. {
  187. return $this->__changeatt->find(array('where' => 'cid=?', 'asc' => 'intime', 'param' => array($cid), 'asArray' => TRUE));
  188. }
  189. public function delChangeAttbyFid($fid)
  190. {
  191. return $this->__changeatt->delete(array('where' => 'id=?', 'param' => array($fid), 'asArray' => TRUE));
  192. }
  193. //changeaudit
  194. public function getNeedChangeNumbyUid($uid)
  195. {
  196. 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));
  197. }
  198. public function getPmidGroup($uid)
  199. {
  200. // 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));
  201. $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)';
  202. $query = Doo::db ()->query ( $sql );
  203. $result = $query->fetchAll ();
  204. return $result;
  205. }
  206. public function getNumbyMydetail($pmid='',$uid)
  207. {
  208. if(empty($pmid)){
  209. 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));
  210. }else{
  211. 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));
  212. }
  213. }
  214. public function getOneAuditbystatus($cid,$status)
  215. {
  216. return $this->__changeaudit->getOne(array('where' => 'cid=? and status=? and usite!=0', 'param' => array($cid,$status), 'asArray' => TRUE));
  217. }
  218. public function getChangeAuditsbycid($cid)
  219. {
  220. return $this->__changeaudit->find(array('where' => 'cid=?', 'asc' => 'id', 'param' => array($cid), 'asArray' => TRUE));
  221. }
  222. public function getChangeAuditsbySort($cid,$notime = '')
  223. {
  224. if($notime != ''){
  225. return $this->__changeaudit->find(array('where' => 'cid=? and times!=?', 'asc' => 'usort', 'param' => array($cid,$notime), 'asArray' => TRUE));
  226. }else{
  227. return $this->__changeaudit->find(array('where' => 'cid=?', 'asc' => 'usort', 'param' => array($cid), 'asArray' => TRUE));
  228. }
  229. }
  230. public function getChangeAuditsbycidtime($cid,$times)
  231. {
  232. return $this->__changeaudit->find(array('where' => 'cid=? and times=? and usite!=0', 'groupby' => 'usite', 'asc' => 'usort', 'param' => array($cid,$times), 'asArray' => TRUE));
  233. }
  234. public function getChangeAuditbylastlist($cid,$times)
  235. {
  236. $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';
  237. $query = Doo::db ()->query ( $sql );
  238. $result = $query->fetchAll ();
  239. return $result;
  240. }
  241. public function getOneChangeAudit($uid,$cid,$times)
  242. {
  243. return $this->__changeaudit->getOne(array('where' => 'cid=? and uid=? and times=? and usite!=0', 'desc' => 'usort', 'param' => array($cid,$uid,$times), 'asArray' => TRUE));
  244. }
  245. public function updateChangeAudit($uid,$cid,$times,$status,$desc,$time,$list = '')
  246. {
  247. $oneaudit = $this->getOneChangeAudit($uid,$cid,$times);
  248. $this->__changeaudit->id = $oneaudit['id'];
  249. $this->__changeaudit->status = $status;
  250. $this->__changeaudit->sdesc = $desc;
  251. $this->__changeaudit->sintime = $time;
  252. $this->__changeaudit->list_json = $list;
  253. $this->__changeaudit->update();
  254. }
  255. //默认取最后一个审批人,site取0则取最后一个创建人
  256. public function getChangeAuditLastUser($cid,$site = 1)
  257. {
  258. $sql = $site == 0 ? ' and usite=0' : '';
  259. return $this->__changeaudit->getOne(array('where' => 'cid=?'.$sql, 'desc' => 'usort', 'param' => array($cid), 'asArray' => TRUE));
  260. }
  261. public function delChangeAuditbyCid($cid)
  262. {
  263. return $this->__changeaudit->delete(array('where' => 'cid=?', 'param' => array($cid), 'asArray' => TRUE));
  264. }
  265. public function getChangeAuditsMaxUsite($cid,$times)
  266. {
  267. return $this->__changeaudit->getOne(array('select' => 'MAX(usite) as maxsite', 'where' => 'cid=? and times=?', 'groupby' => 'times', 'param' => array($cid,$times) , 'asArray' => TRUE));
  268. }
  269. //changeauditlist
  270. public function getChangeAuditListbycid($cid)
  271. {
  272. return $this->__changeauditlist->find(array('where' => 'cid=?', 'asc' => 'convert(lnum using gbk)', 'param' => array($cid), 'asArray' => TRUE));
  273. }
  274. public function getOneChangeAuditList($lid)
  275. {
  276. return $this->__changeauditlist->getOne(array('where' => 'id=?', 'param' => array($lid), 'asArray' => TRUE));
  277. }
  278. public function delChangeAuditListbyCid($cid)
  279. {
  280. return $this->__changeauditlist->delete(array('where' => 'cid=?', 'param' => array($cid)));
  281. }
  282. //changelist
  283. public function insertChangelist($pmArray,$listArray)
  284. {
  285. $this->__changelist->pid = $pmArray['pid'];
  286. $this->__changelist->stid = $pmArray['stid'];
  287. $this->__changelist->pmid = $pmArray['pmid'];
  288. $this->__changelist->lnum = trim($listArray['lnum']);
  289. $this->__changelist->lname = trim($listArray['lname']);
  290. $this->__changelist->unit = trim($listArray['unit']);
  291. $this->__changelist->unitprice = $listArray['unitprice'];
  292. $this->__changelist->amount = $listArray['amount'];
  293. $this->__changelist->insert();
  294. }
  295. public function getChangeListbyPmid($pmid = '',$sql = '')
  296. {
  297. if(empty($pmid)){
  298. return $this->__changelist->find(array('where' => $sql, 'asc' => 'convert(lnum using gbk)', 'asArray' => TRUE));
  299. }else{
  300. return $this->__changelist->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asc' => 'convert(lnum using gbk)', 'asArray' => TRUE));
  301. }
  302. }
  303. public function getChangeListbyid($id)
  304. {
  305. return $this->__changelist->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  306. }
  307. public function getChangeListbylname($lname)
  308. {
  309. return $this->__changelist->getOne(array('where' => 'lname=?', 'param' => array(trim($lname)), 'asArray' => TRUE));
  310. }
  311. public function delChangeListbyPmid($pmid)
  312. {
  313. return $this->__changelist->delete(array('where' => 'pmid=?', 'param' => array($pmid)));
  314. }
  315. //changecompany
  316. public function getCompanyList($pmid = '')
  317. {
  318. if($pmid != ''){
  319. return $this->__changecompany->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  320. }else{
  321. return $this->__changecompany->find(array('asArray' => TRUE));
  322. }
  323. }
  324. public function getCompanybyid($id)
  325. {
  326. return $this->__changecompany->getOne(array('where' => 'id=?', 'param' => array($id), 'asArray' => TRUE));
  327. }
  328. public function delAllChangebyPmid($pmid)
  329. {
  330. // TODO: 根据pmid删除所有相关联的变更令内容
  331. // TODO: 项目管理和前台删除标段中使用
  332. $changeattlist = $this->__changeatt->find(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  333. if(!empty($changeattlist)){
  334. include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
  335. foreach($changeattlist as $k => $v){
  336. $this->IoHandler = new IoHandler();
  337. $path = DOO::conf()->SITE_PATH.$v['filepath'];
  338. $this->IoHandler->DeleteFile($path);
  339. $this->delChangeAttbyFid($v['id']);
  340. }
  341. }
  342. $this->__changelist->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  343. $this->__changeaudit->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  344. $this->__changeauditlist->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  345. $this->__changecompany->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  346. $this->__change->delete(array('where' => 'pmid=?', 'param' => array($pmid), 'asArray' => TRUE));
  347. }
  348. }