ClientController.php 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. <?php
  2. Doo::loadCore('auth/DooAuth');
  3. Doo::loadClass('PasswordHash');
  4. Doo::loadClass('client');
  5. Doo::loadClass('auth');
  6. Doo::loadClass('attachment');
  7. Doo::loadClass('attfile');
  8. Doo::loadClass('actmeasure');
  9. Doo::loadClass('contractact');
  10. Doo::loadClass('project');
  11. Doo::loadClass('profile');
  12. Doo::loadClass('numofperact');
  13. Doo::loadClass('measureauditact');
  14. Doo::loadClass('itemfile');
  15. Doo::loadModel('users');
  16. Doo::loadClass('itemmeasurenum');
  17. Doo::loadModelAt('aconfig', 'admin');
  18. Doo::loadClass('sms');
  19. Doo::loadClass('sign');
  20. /**
  21. * MainController
  22. * Feel free to delete the methods and replace them with your own code.
  23. *
  24. * @author NoNZero
  25. */
  26. class ClientController extends DooController
  27. {
  28. private $data, $sign, $client, $auth, $att, $file, $zip, $actmeasure, $contractact, $project, $profile, $numofperact, $measureauditact, $attfile, $users, $itemfile, $modelconfig, $aconfig, $sms, $itemMeasureNum;
  29. private $statusArray = array('uncheck' => '1', 'checking' => '2', 'checked' => '3', 'checkno' => '4');
  30. private $fileTypeArray = array('台帐附件');
  31. public function __construct()
  32. {
  33. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  34. $this->client = new client();
  35. $this->auth = new Auth();
  36. $this->att = new attachment();
  37. $this->attfile = new attFile();
  38. $this->zip = new ZipArchive();
  39. $this->actmeasure = new actMeasure();
  40. $this->contractact = new Contractact();
  41. $this->project = new Project();
  42. $this->profile = new Profile();
  43. $this->numofperact = new NumofperAct();
  44. $this->measureauditact = new MeasureauditAct();
  45. $this->users = new Users();
  46. $this->itemfile = new ItemFile();
  47. $this->modelconfig = new AConfig();
  48. $this->itemMeasureNum = new ItemMeasureNumpofper();
  49. $this->aconfig = new AConfig();
  50. $this->sign = new signn();
  51. $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_AUTHKEY);
  52. }
  53. public function ClientSignin()
  54. {
  55. if (isset($_POST['zhname']) && isset($_POST['zhpass'])) {
  56. echo json_encode(array('status' => FALSE, 'msg' => '登录失败,请更新软件。'), JSON_UNESCAPED_UNICODE);
  57. die;
  58. }
  59. if (isset($_POST['uname']) && isset($_POST['upass'])) {
  60. echo json_encode(array('status' => FALSE, 'msg' => '登录失败,请更新软件。'), JSON_UNESCAPED_UNICODE);
  61. die;
  62. }
  63. if (isset($_POST['v3name']) && isset($_POST['v3name'])) {
  64. echo json_encode(array('status' => FALSE, 'msg' => '登录失败,请更新软件。'), JSON_UNESCAPED_UNICODE);
  65. die;
  66. }
  67. if (isset($_POST['v4name']) && isset($_POST['v4pass']) && !empty($_POST['version'])) {
  68. try {
  69. if ($this->modelconfig->getOne(array('select' => 'onoff', 'asArray' => TRUE))['onoff'] != 1) {
  70. $versionTotal = array_sum(explode('.', $_POST['version']));
  71. $StrJson = ($this->modelconfig->getOne(array('select' => 'upgradeinfo', 'asArray' => TRUE))['upgradeinfo']);
  72. $jsonObj = json_decode($StrJson, true);
  73. if ($jsonObj) {
  74. $versionTotalUp = array_sum(explode('.', $jsonObj['version']));
  75. $strJson = json_encode(array('status' => 'upgrade', 'msg' => '您的客户端需要升级,请点击确定按钮,下载新版本,并且覆盖安装。', 'url' => $jsonObj['download']), JSON_UNESCAPED_UNICODE);
  76. if ($jsonObj['condition'] == 1) {
  77. if ($versionTotalUp != $versionTotal) {
  78. echo $strJson;
  79. die;
  80. }
  81. }
  82. if ($jsonObj['condition'] == 2) {
  83. if ($versionTotalUp > $versionTotal) {
  84. echo $strJson;
  85. die;
  86. }
  87. }
  88. }
  89. if ($this->auth->login($_POST['v4name'], $_POST['v4pass'])) {
  90. $uinfo = $this->auth->getUinfo();
  91. if (isset($uinfo['isstop']) && $uinfo['isstop'] > 0) {
  92. echo json_encode(array('status' => 'false', 'msg' => '帐号不存在或者密码错误'), JSON_UNESCAPED_UNICODE);
  93. die;
  94. }
  95. if (isset($uinfo['uid'])) {
  96. $userArray = $this->profile->getProWithUid($uinfo['uid']);
  97. $avatarStr = $userArray['avatar'];
  98. if (isset($userArray['userid'])) {
  99. $msgArray = array('uid' => $uinfo['uid'], 'name' => $userArray['name'], 'email' => $uinfo['uemail'], 'ucompany' => $userArray['company'], 'jobtitle' => $userArray['jobs'], 'avatar' => Doo::conf()->APP_URL . $avatarStr);
  100. echo json_encode(array('status' => 'true', 'msg' => '', 'userinfo' => $msgArray), JSON_UNESCAPED_UNICODE);
  101. die;
  102. }
  103. }
  104. } else {
  105. echo json_encode(array('status' => 'false', 'msg' => '帐号不存在或者密码错误'), JSON_UNESCAPED_UNICODE);
  106. die;
  107. }
  108. } else {
  109. echo json_encode(array('status' => 'false', 'msg' => '该计量支付已关闭,请联系相关管理人员。'), JSON_UNESCAPED_UNICODE);
  110. die;
  111. }
  112. } catch (Exception $exc) {
  113. }
  114. } else {
  115. echo json_encode(array('status' => 'false', 'msg' => '参数错误'), JSON_UNESCAPED_UNICODE);
  116. die;
  117. }
  118. }
  119. // 创建标段
  120. // 参数:用户ID,创建名称,KEY
  121. function ClientCreatmeasure()
  122. {
  123. if (isset($this->params['uid']) && $this->params['uid'] && isset($this->params['bname']) && $this->params['bname'] && $this->params['ckey'] && isset($this->params['ckey'])) {
  124. $retval = $this->contractact->getPidWithKey($this->params['ckey']);
  125. if (isset($retval['pid'])) {
  126. $pArray = $this->project->getRowByPid($retval['pid']);
  127. if (isset($this->params['uid']) && ($this->params['uid'] == $pArray['uid'])) {
  128. $status = array('status' => FALSE, 'msg' => '业主不能作为编制人新建标段!');
  129. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  130. die();
  131. }
  132. $id = $this->actmeasure->insertMeasure(intval($this->params['uid']), $retval['pid'], $retval['stid'], iconv('GBK', 'UTF-8', $this->params['bname']));
  133. $this->measureauditact->insertMeasureAudit($pArray['pid'], 0, $pArray['uid'], 0, $id, $retval['stid'], 1, 'uncheck', 1); //加入业主
  134. $uArray = $this->profile->getProWithUid($retval['uid']);
  135. $strAvatar = $this->auth->getAvatar($uArray['userid']);
  136. $createArray = array('catid' => $id, 'name' => $uArray['name'], 'avatar' => $strAvatar, 'jobs' => $uArray['jobs'], 'company' => $uArray['company'], 'coninfo' => array('phone' => $uArray['phone'], 'mobile' => $uArray['mobile'], 'qq' => $uArray['qq']), 'pname' => $pArray['pname'], 'ptype' => $retval['stname'], 'ownuid' => $pArray['uid'], 'pnameid' => $pArray['pid'], 'ptypeid' => $retval['stid']);
  137. $status = array('status' => TRUE, 'msg' => '', 'createinfo' => $createArray);
  138. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  139. die();
  140. } else {
  141. $status = array('status' => FALSE, 'msg' => 'The key is error');
  142. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  143. die();
  144. }
  145. } else {
  146. $status = array('status' => FALSE, 'msg' => 'error_create');
  147. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  148. die();
  149. }
  150. }
  151. // 编制人审批第一期时 开始审批第一期时候调用ll
  152. public function ClientPeriod()
  153. {
  154. // TODO:上报数据
  155. // TODO:每期更新数据时候和上传时候要查询当前进行期数的第几次一并写入数据库
  156. if (isset($this->params['userid']) && isset($this->params['tenderid']) && isset($this->params['phaseno']) && isset($_POST['MD5_JL']) && isset($_POST['MD5_Zip'])) {
  157. $fp = $this->upfile('upfile');
  158. if (isset($fp[0]['filepath'])) {
  159. /**
  160. * 增加上传压缩包md5检测机制
  161. */
  162. $localmd5HashString = hash_file("md5", Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  163. if ($localmd5HashString != trim($_POST['MD5_Zip'])) {
  164. $status = array('status' => 'FALSE', 'msg' => '期数数据上传失败,请重新上传');
  165. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  166. die();
  167. }
  168. $res = $this->zip->open(Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  169. $extPath = pathinfo($fp[0]['filepath']);
  170. $extPathdir = Doo::conf()->SITE_PATH . $extPath['dirname'] . '/' . $extPath['filename'];
  171. if ($res === TRUE) {
  172. if (!$this->dir_create($extPathdir)) {
  173. $status = array('status' => 'FALSE', 'msg' => '期数数据上传失败');
  174. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  175. die();
  176. }
  177. $this->zip->extractTo($extPathdir);
  178. $this->zip->close();
  179. }
  180. $countArray = json_decode(file_get_contents($extPathdir . '/' . 'JsonFile_Common.json'), TRUE, JSON_UNESCAPED_UNICODE);
  181. if (!isset($countArray)) {
  182. $status = array('status' => 'FALSE', 'msg' => '期数汇总数据上传失败');
  183. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  184. die();
  185. }
  186. $this->actmeasure->updateCon($this->params['tenderid'], $countArray['TotalPrice']);
  187. $pmArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  188. if (isset($pmArray['pmid'])) {
  189. // 由于不通过功能数据表记录重复写入时要考虑当前是第几次审批
  190. $intMaxTimes = $this->numofperact->getMaxTimes($this->params['tenderid'], $this->params['phaseno']);
  191. if (isset($intMaxTimes['times']) && ($intMaxTimes['times'] >= 0)) {
  192. $iniTimes = $intMaxTimes['times'] + 1;
  193. } else {
  194. $iniTimes = 0;
  195. }
  196. // 写入第一期
  197. $mpid = $this->numofperact->insert($pmArray['pid'], $this->params['userid'], $this->params['tenderid'], $pmArray['stid'], $this->params['phaseno'], $countArray['BQHTJL'], $countArray['BQSLBGJL'], $countArray['JZSQLJWC'], $countArray['BQWCJL'], $countArray['LJWCJL'], $iniTimes);
  198. // 更新审批人MPID
  199. $this->measureauditact->updateAuditorMPID($mpid, $this->params['tenderid'], $this->params['phaseno'], $iniTimes);
  200. // 设置审批人状态
  201. $firstAuditor = $this->measureauditact->getFirstAuditor($this->params['tenderid'], $this->params['phaseno'], $iniTimes);
  202. if (isset($firstAuditor)) {
  203. if ($firstAuditor['mastatus'] == 'uncheck') {
  204. $retVal = $this->measureauditact->updateMastatus($firstAuditor['maid']);
  205. if ($retVal > 0) {
  206. // SMS Start
  207. $verifyUserArray = $this->profile->getVerifiedMobile($firstAuditor['auditoruid']);
  208. $pmnameArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  209. if (isset($verifyUserArray) && ($verifyUserArray['mobile'])) {// // XXXX(标段名),陈特,已审批通过。请您继续审批。
  210. $this->__auditNotice($verifyUserArray['mobile'], Doo::conf()->SMS_TIPS_PRE . '您好,' . $pmnameArray["pmname"] . Doo::conf()->SMS_TIPS["AUDIT_NOTICE_AUDITOR2"]);
  211. }
  212. // SMS End
  213. }
  214. }
  215. }
  216. }
  217. if ($mpid > 0) {
  218. if ($this->attfile->insertFile($pmArray['pid'], $pmArray['stid'], $mpid, $this->params['tenderid'], $this->params['phaseno'], $this->params['userid'], $fp[0]['filepath'], 0, $_POST['MD5_JL'], $iniTimes, 2)) {
  219. $infostatus = 0;
  220. $pmArray = $this->numofperact->getRowTender($this->params['tenderid']);
  221. if ($pmArray) {
  222. $countTotal = count($pmArray);
  223. $ownerStatusArray = $this->measureauditact->getStatusTender($pmArray[0]['pmid'], $pmArray[0]['numpname']);
  224. if ($ownerStatusArray) {
  225. $infostatus = $this->statusArray[$ownerStatusArray['mastatus']];
  226. }
  227. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('curr' => $pmArray[0]['numpname'], 'infostatus' => $infostatus, 'total' => $countTotal)), JSON_UNESCAPED_UNICODE);
  228. die();
  229. } else {
  230. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('curr' => 1, 'infostatus' => 1, 'total' => 1)), JSON_UNESCAPED_UNICODE);
  231. die();
  232. }
  233. } else {
  234. $status = array('status' => 'FALSE', 'msg' => '期数上传失败');
  235. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  236. die();
  237. }
  238. } else {
  239. $status = array('status' => 'FALSE', 'msg' => '期数上传失败');
  240. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  241. die();
  242. }
  243. } else {
  244. $status = array('status' => 'FALSE', 'msg' => '文件上传失败,请重试');
  245. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  246. die();
  247. }
  248. } else {
  249. $status = array('status' => 'FALSE', 'msg' => '上传参数错误');
  250. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  251. die();
  252. }
  253. }
  254. /**
  255. * 获取标段状态信息(由于加入了)
  256. * 每个标段只有一期在进行中 group by?
  257. *
  258. * 查询标段的审批状态可以根据业主的审批依据来查询
  259. * 如果除业主意外的人审批状态为未通过怎么处理
  260. */
  261. public function getMAStatus()
  262. {
  263. // curr:当前期数,status:当前状态,total:总期数
  264. // 参数catid
  265. if (isset($this->params['tenderid'])) {
  266. $pmArray = $this->numofperact->getRowTenderCurr($this->params['tenderid']);
  267. $countTotal = count($pmArray);
  268. $ownerStatus = NULL;
  269. $isUnCheck = TRUE;
  270. $ownerStatusArray = $this->measureauditact->getStatusTen($pmArray[0]['pmid'], $pmArray[0]['numpname']);
  271. // if (isset($ownerStatusArray))
  272. // if (($ownerStatusArray[0]['last'] == 1) && ($ownerStatusArray[0]['mastatus'] == 'checked')) {
  273. // $ownerStatus = 'checked';
  274. // } else {
  275. // $ownerStatus = 'checking';
  276. // }
  277. $statusArray = $this->numofperact->getMaxRowStatus($pmArray[0]['pmid'], $pmArray[0]['numpname']);
  278. $ownerStatus = $statusArray['currstatus'];
  279. // foreach ($ownerStatusArray as $kk => $vv) {
  280. // if (($vv['last'] == 1) && ($vv['mastatus'] == 'checked')) {
  281. // $ownerStatus = 'checked';
  282. // } else {
  283. // $ownerStatus = 'checking';
  284. // }
  285. // }
  286. $projectArray = $this->project->getRowByPid($ownerStatusArray[0]['pid']);
  287. $stArray = $this->contractact->getRowByStid($ownerStatusArray[0]['stid']);
  288. $profileArray = $this->profile->getProWithUid($projectArray['uid']);
  289. $auditArray = $this->measureauditact->getAuditUserRedo($pmArray[0]['pmid'], $pmArray[0]['numpname']);
  290. if (isset($auditArray[0]['auditoruid'])) {
  291. foreach ($auditArray as $key => $value) {
  292. $userArray = $this->profile->getProWithUid($value['auditoruid']);
  293. $auditcontent = !empty($value['auditcontent']) ? $value['auditcontent'] : '';
  294. // $finalStatus = $value['mastatus'];
  295. if ($value['mastatus'] != 'uncheck') {
  296. $isUnCheck = FALSE;
  297. }
  298. if ($value['audittime'] > 0) {
  299. $value['audittime'] = date('Y-m-d', $value['audittime']);
  300. }
  301. $auditInfo[] = array('uid' => $userArray['userid'], 'name' => $userArray['name'], 'company' => $userArray['company'], 'jobs' => $userArray['jobs'], 'avatar' => $this->auth->getAvatar($value['auditoruid']), 'mastatus' => $this->statusArray[$value['mastatus']], 'CheckerMemo' => $auditcontent, 'onlineaudit' => $value['onlineaudit'], 'audittime' => $value['audittime']);
  302. }
  303. }
  304. if ($ownerStatusArray) {
  305. if ($isUnCheck) {
  306. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('curr' => $pmArray[0]['numpname'], 'infostatus' => $this->statusArray['uncheck'], 'total' => "$countTotal", 'proName' => $projectArray['pname'], 'stName' => $stArray['stname'], 'name' => $profileArray['name'], 'company' => $profileArray['company'], 'jobs' => $profileArray['jobs']), 'auditinfo' => $auditInfo), JSON_UNESCAPED_UNICODE);
  307. } else {
  308. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('curr' => $pmArray[0]['numpname'], 'infostatus' => $this->statusArray[$ownerStatus], 'total' => "$countTotal", 'proName' => $projectArray['pname'], 'stName' => $stArray['stname'], 'name' => $profileArray['name'], 'company' => $profileArray['company'], 'jobs' => $profileArray['jobs']), 'auditinfo' => $auditInfo), JSON_UNESCAPED_UNICODE);
  309. }
  310. die();
  311. } else {
  312. echo json_encode(array('status' => 'FALSE', 'msg' => '标段状态查询不存在'), JSON_UNESCAPED_UNICODE);
  313. die();
  314. }
  315. } else {
  316. echo json_encode(array('status' => 'FALSE', 'msg' => '标段状态查询参数错误'), JSON_UNESCAPED_UNICODE);
  317. die();
  318. }
  319. }
  320. public function getUserSearch()
  321. {
  322. if (isset($_POST['uemail'])) {
  323. $retval = $this->users->getOne(array('where' => 'uemail=?', 'param' => array($_POST['uemail']), 'asArray' => TRUE));
  324. if (isset($retval['uid'])) {
  325. $proArray = $this->profile->getProWithUid($retval['uid']);
  326. if (isset($proArray['userid'])) {
  327. $strAvatar = $this->auth->getAvatar($proArray['userid']);
  328. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('uid' => $proArray['userid'], 'avatar' => $strAvatar, 'name' => $proArray['name'], 'jobs' => $proArray['jobs'], 'company' => $proArray['company'])), JSON_UNESCAPED_UNICODE);
  329. die();
  330. } else {
  331. echo json_encode(array('status' => 'FALSE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  332. die();
  333. }
  334. } else {
  335. echo json_encode(array('status' => 'FALSE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  336. die();
  337. }
  338. } else {
  339. echo json_encode(array('status' => 'FALSE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  340. die();
  341. }
  342. }
  343. /**
  344. * 获取指定标段指定期数{默认提取重做后最新一期的}
  345. * 单击获取项目相关审批人员和状态
  346. * sectionid:标段ID periodid:期数
  347. * TODO:如果审批人的期数或者次数与标段期数或者次数存在不对应情况的处理
  348. */
  349. public function getAlluserMeasure()
  350. {
  351. if (isset($this->params['tenderid']) && isset($this->params['phaseno'])) {
  352. // error_log(var_export($this->params, TRUE), 3, '/opt/html/jlzftest/data/' . time());
  353. // 先判断是否存在期数问题
  354. // 然后再判断是否存在次数不匹配
  355. // $intNum = $this->numofperact->getCountNumpname($this->params['tenderid'], $this->params['phaseno']);
  356. // // 如果期数是第一期期数必须大于一,否则减一为无效数据 ,为0表示这期为做上报没有产生记录
  357. // if (( $this->params['phaseno'] > 1) && ($intNum == 0)) {// 提取上一期的数据
  358. // // 提取期数减一
  359. // $intLastTimes = $this->numofperact->getMaxTimes($this->params['tenderid'], $this->params['phaseno'] - 1)['times'];
  360. // $uinfoTmpArray = $this->measureauditact->getAllAudit($this->params['tenderid'], $this->params['phaseno'] - 1, $intLastTimes);
  361. // } else {
  362. // $IntMaxRedoTimes = $this->measureauditact->getMaxTimes($this->params['tenderid'], $this->params['phaseno'])['maxtimes'];
  363. // $intTimes = $this->numofperact->getCountTimes($this->params['tenderid'], $this->params['phaseno'], $IntMaxRedoTimes);
  364. // if (($intTimes == 0) && ($IntMaxRedoTimes > 0)) {
  365. // $lastTimes = $IntMaxRedoTimes - 1;
  366. // $uinfoTmpArray = $this->measureauditact->getAllAudit($this->params['tenderid'], $this->params['phaseno'], $lastTimes);
  367. // } else {
  368. // $uinfoTmpArray = $this->measureauditact->getAllAudit($this->params['tenderid'], $this->params['phaseno'], $IntMaxRedoTimes);
  369. // }
  370. // }
  371. $uinfoTmpArray = $this->measureauditact->getAlluserMeasureAudit($this->params['tenderid'], $this->params['phaseno']);
  372. if ($uinfoTmpArray) {
  373. foreach ($uinfoTmpArray as $key => $value) {
  374. $uArray = $this->profile->getProWithUid($value['auditoruid']);
  375. $uinfoArray[$key]['name'] = $uArray['name'];
  376. $uinfoArray[$key]['company'] = $uArray['company'];
  377. $uinfoArray[$key]['jobs'] = $uArray['jobs'];
  378. $uinfoArray[$key]['mastatus'] = $this->statusArray[$value['mastatus']];
  379. $uinfoArray[$key]['uid'] = $value['auditoruid'];
  380. $uinfoArray[$key]['avatar'] = $this->auth->getAvatar($value['auditoruid']);
  381. $uinfoArray[$key]['CheckerMemo'] = !empty($value['auditcontent']) ? $value['auditcontent'] : '';
  382. $uinfoArray[$key]['onlineaudit'] = $value['onlineaudit'];
  383. if ($value['audittime'] > 0) {
  384. $uinfoArray[$key]['audittime'] = date('Y-m-d', $value['audittime']);
  385. } else {
  386. $uinfoArray[$key]['audittime'] = '0';
  387. }
  388. }
  389. } else {
  390. echo json_encode(array('status' => FALSE, 'msg' => '用户列表不存在'), JSON_UNESCAPED_UNICODE);
  391. die();
  392. }
  393. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $uinfoArray), JSON_UNESCAPED_UNICODE);
  394. die();
  395. } else {
  396. echo json_encode(array('status' => FALSE, 'msg' => '错误'), JSON_UNESCAPED_UNICODE);
  397. die();
  398. }
  399. }
  400. //
  401. //
  402. // 配置审批人时候还没有创建标段所以没有MPID存在
  403. function addAuditMeasure()
  404. {
  405. // 必须检查期数是否存在
  406. // 标段ID 当前登录 审批人ID
  407. // 检测是否重复写入 && ($_POST['creatoruid'] > 0)
  408. // TODO: 增加多次审批人变更需求,调整审批人增加、删除接口
  409. // 当前操作的是否为最新一期还是最新一期加一(项目进行中时,不能编辑审批人,所以直接加一)
  410. // 大于一次重做的时候,自动复制编制人和所有审批人次数加一
  411. if (isset($_POST['pmid']) && isset($_POST['creatoruid']) && isset($_POST['auditoruid']) && isset($_POST['numpname'])) {
  412. $IntMaxTimes = $this->measureauditact->getMaxTimesInt($_POST['pmid'], $_POST['numpname']); // 根据标段PMID,期数numpname,获取目前重做次数
  413. if ($IntMaxTimes > 0) {
  414. $inTimes = $IntMaxTimes;
  415. } else {
  416. $inTimes = 0;
  417. }
  418. $pmArray = $this->actmeasure->getRowByPmid($_POST['pmid']);
  419. try {
  420. if ($this->measureauditact->insertMeasureAudit($pmArray['pid'], $_POST['creatoruid'], $_POST['auditoruid'], 0, $_POST['pmid'], $pmArray['stid'], $_POST['numpname'], 'uncheck', 2, $inTimes) > 0) {
  421. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => ''), JSON_UNESCAPED_UNICODE);
  422. die();
  423. }
  424. } catch (PDOException $e) {// 判断异常类型,提示不同错误信息
  425. echo json_encode(array('status' => FALSE, 'msg' => '配置审批人错误'), JSON_UNESCAPED_UNICODE);
  426. }
  427. } else {
  428. echo json_encode(array('status' => FALSE, 'msg' => '配置审批人参数错误'), JSON_UNESCAPED_UNICODE);
  429. die();
  430. }
  431. }
  432. /**
  433. * 删除审批用户
  434. */
  435. function delAuditMeasure()
  436. {
  437. if (isset($this->params['userid']) && isset($this->params['tenderid']) && isset($this->params['phaseno'])) {
  438. // 判断当前标段期数审批状态,决定是否继续执行
  439. $IntMaxTimes = $this->measureauditact->getMaxTimesInt($this->params['tenderid'], $this->params['phaseno']); // 根据标段PMID,期数numpname,获取目前重做次数
  440. if ($IntMaxTimes > 0) {
  441. $inTimes = $IntMaxTimes;
  442. $intHasCount = $this->numofperact->hasTheTimesRow($this->params['tenderid'], $this->params['phaseno'], $inTimes);
  443. if (isset($intHasCount) && ($intHasCount > 0)) {
  444. echo json_encode(array('status' => FALSE, 'msg' => '此标段状态,禁止删除审批人员'), JSON_UNESCAPED_UNICODE);
  445. die();
  446. }
  447. } else {
  448. $inTimes = 0;
  449. }
  450. try {
  451. $this->measureauditact->delAuditUserTimes($this->params['tenderid'], $this->params['phaseno'], $this->params['userid'], $inTimes);
  452. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  453. die();
  454. } catch (PDOException $e) {// 判断异常类型,提示不同错误信息
  455. echo json_encode(array('status' => FALSE, 'msg' => '删除审批人错误'), JSON_UNESCAPED_UNICODE);
  456. }
  457. } else {
  458. echo json_encode(array('status' => FALSE, 'msg' => '删除审批人员参数错误'), JSON_UNESCAPED_UNICODE);
  459. die();
  460. }
  461. }
  462. // 查询状态变更为审批中,已审批中为查询依据
  463. function checkMeasureStatus()
  464. {
  465. if (isset($_POST['sectionid']) && isset($_POST['periodid'])) {
  466. $mpArray = $this->numofperact->getRow($_POST['sectionid'], $_POST['periodid']);
  467. $maArray = $this->measureauditact->getAlluserMeasureAudit($_POST['sectionid'], $_POST['periodid']);
  468. foreach ($maArray as $key => $value) {
  469. if ($value['mastatus'] == 'uncheck') {
  470. $mastatus = $this->statusArray[$value['mastatus']];
  471. }
  472. }
  473. if (isset($mpArray['mpid'])) {
  474. echo json_encode(array('status' => TRUE, 'msg' => '', 'isexist' => TRUE, 'checkstatus' => $mastatus), JSON_UNESCAPED_UNICODE);
  475. die();
  476. } else {
  477. echo json_encode(array('status' => TRUE, 'msg' => '', 'isexist' => FALSE), JSON_UNESCAPED_UNICODE);
  478. die();
  479. }
  480. } else {
  481. echo json_encode(array('status' => FALSE, 'msg' => '标段信息不正确'), JSON_UNESCAPED_UNICODE);
  482. die();
  483. }
  484. }
  485. // 根据用户查询参与的标段信息
  486. // 参数为1时,当提交的附件中有重做记录时,提取记录未经过排重处理,出现重复结果。
  487. // api/client/user/get/15/allproject 此接口也有同样问题
  488. function getAuditProject()
  489. {
  490. // TODO:可以通过SQL直接查询出来
  491. if (isset($_POST['audituid']) && isset($_POST['RequestType'])) {
  492. $downfileurl = NULL;
  493. /**
  494. * 只查询审批中状态的记录
  495. * 然后根据每天记录所在的标段、期数、创建人查询所有此次所有审批人记录、为了判断
  496. * 判断此用户是第几个审批的人
  497. * 直接提取状态为未审批、审批中的
  498. * 未审批(没有到该审批人)
  499. * 审批中(出现在第一个)
  500. * 上传审批时候先遍历所有审批提交文件的状态并设置为旧文件状态
  501. * 然后写入新审批的文件路径等信息
  502. * 审批同时上传审批文件并设置审批表的状态做更改
  503. *
  504. */
  505. if ($_POST['RequestType'] == 1) {
  506. /**
  507. * 功能描述:
  508. * 参数1功能为,取得与当前用户相关的待审批状态的所有进行中的标段期数、最新一次的记录
  509. * 根据用户ID查询编制人和审批人参与的正在进行中的项目,进行中的项目状态为uncheck,checking
  510. * 由于·uncheck状态不能准确反映出其他用户操作对所属标段操作产生的的状态{比如:其他用户操作标段状态为(未通过【打回重做】)}、要排除这种情况
  511. * 还有一种情况为编制人编制项目时,审批人列表已经添加审批人,但是项目没有提交,没有项目文件,此时应根据有没有项目文件进行过滤。
  512. *
  513. * ??此ID为编制人或者为审批人时
  514. */
  515. // 第一步:根据用户ID,查询此用户参与的所有标段{根据最大期数【由于期数是递进关系只获取最大值】、最大次数【由于次数是递进关系只获取最大值】作为条件参数进行查询记录}
  516. $mpArray = $this->measureauditact->getCheckedRowbyUID2($_POST['audituid']); // 通过pmid,numpname分组获取参与的记录
  517. if (isset($mpArray)) {
  518. $statusArray = array('uncheck', 'checking');
  519. foreach ($mpArray as $key => $value) {
  520. /**
  521. * 根据审批ID查询所在标段期数
  522. * 然后去附件表根据标段ID 期数 是否新标志字段去查询最新的文件
  523. * 项目名称 项目类型
  524. *
  525. *
  526. * 此处现在是以创建者ID和审批人ID做关联来做判断
  527. * 判断上一个人的审批状态来提取记录
  528. *
  529. * 变更为一个用户添加所有人
  530. *
  531. */
  532. // $maxtimes = $this->attfile->getMaxTimes2($value['pmid'], $value['numpname']);
  533. $numStatusArray = $this->numofperact->getRow($value['pmid'], $value['numpname'], $value['times']);
  534. if (in_array($numStatusArray['currstatus'], $statusArray)) {
  535. $newfileArray = $this->attfile->getNewLast($value['pmid'], $value['numpname'], $value['times']);
  536. if (isset($newfileArray['filepath'])) {
  537. $projectArray = $this->project->getRowByPid($newfileArray['pid']);
  538. $pmidArray = $this->actmeasure->getRowByPmid($value['pmid']);
  539. $stArray = $this->contractact->getRowByStid($newfileArray['stid']);
  540. // $auditArray = $this->measureauditact->getLastNewRowInfo($value['pmid'], $value['numpname'], $_POST['audituid']);
  541. $pathinfo = pathinfo($newfileArray['filepath']);
  542. $downfileurl[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $projectArray['pname'], 'stName' => $stArray['stname'], 'MD5_Jl' => $newfileArray['filehashcode'], 'tenderstatus' => $this->statusArray[$value['mastatus']], 'tenderid' => $value['pmid'], 'pnameid' => $projectArray['pid'], 'ptypeid' => $stArray['stid'], 'audituidstatus' => $this->statusArray[$value['mastatus']], 'bianzhirenuid' => $pmidArray['uid'], 'tenderName' => $pmidArray['pmname']);
  543. }
  544. }
  545. }
  546. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $downfileurl), JSON_UNESCAPED_UNICODE);
  547. die();
  548. } else {
  549. echo json_encode(array('status' => FALSE, 'msg' => '暂时无审批信息'), JSON_UNESCAPED_UNICODE);
  550. die();
  551. }
  552. }
  553. if ($_POST['RequestType'] == 2) {
  554. /**
  555. * {
  556. * "downurl": "http://d.jl.smartcost.com.cn/data/2015/0608/20150608043245691/ProjectFile.rmf", 最新一期最新一次的文件
  557. * "proName": "巫溪县前进桥", 项目名称
  558. * "stName": "巫溪县 前进桥(终)", 合同段名称
  559. * "MD5_Jl": "7cf05dccc6ad45b2d78f476a3388c3b2", 最新一期最新一次的文件hash code
  560. * "tenderstatus": "2", 标段状态
  561. * "tenderid": "234", 标段ID
  562. * "pnameid": "79", 项目ID
  563. * "ptypeid": "96", 合同段ID
  564. * "audituidstatus": "2", 当前用户审批状态
  565. * "bianzhirenuid": "59", 编制人UID
  566. * "tenderName": "巫溪县 前进桥 终" 标段名称
  567. * }
  568. */
  569. // TODO::不同角色提取条件不同是否使用audituid 作为当前用户提取条件,容易产生冲突
  570. if (!isset($_POST['audituid']) || !($_POST['audituid'] > 0)) {
  571. echo json_encode(array('status' => FALSE, 'msg' => '返回指定用户参与的所有项目参数错误'), JSON_UNESCAPED_UNICODE);
  572. die();
  573. }
  574. // 三个角色数据合并返回
  575. // 返回最新一期的项目文件
  576. // 业主
  577. // 业主查询参与的项目时
  578. // TODO::业主是否参与审批?如果参与提取哪个参与者的审批状态?
  579. $userproArray = $this->project->getRowUid($_POST['audituid']);
  580. $newattArray = $retArray = $hashArray = NULL;
  581. foreach ($userproArray as $upk => $upv) {
  582. $attArray = $this->attfile->getPmidGroup($upv['pid']);
  583. $attaArray = NULL;
  584. foreach ($attArray as $akey => $avalue) {
  585. $attaArray[] = $this->attfile->getLastNumTimes($avalue['pmid']);
  586. }
  587. foreach ($attaArray as $attk => $attv) {
  588. $attfileArray = $this->contractact->getRowByStid($attv['stid']);
  589. $pmidArray = $this->actmeasure->getRowByPmid($attv['pmid']);
  590. $numArray = $this->numofperact->getRow($attv['pmid'], $attv['numpname'], $attv['times']);
  591. $auditArray = $this->measureauditact->getLastNewRowInfo($attv['pmid'], $attv['numpname'], $_POST['audituid']);
  592. $pathinfo = pathinfo($attv['filepath']);
  593. if (isset($pathinfo['dirname'])) {
  594. $retArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $upv['pname'], 'stName' => $attfileArray['stname'], 'MD5_Jl' => $attv['filehashcode'], 'tenderstatus' => $this->statusArray[$numArray['currstatus']], 'tenderid' => $attv['pmid'], 'pnameid' => $upv['pid'], 'ptypeid' => $attfileArray['stid'], 'audituidstatus' => $this->statusArray[$auditArray['mastatus']], 'bianzhirenuid' => $pmidArray['uid'], 'tenderName' => $pmidArray['pmname']);
  595. $hashArray[] = md5(Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf' . $upv['pname'] . $attfileArray['stname'] . $attv['filehashcode'] . $this->statusArray[$numArray['currstatus']] . $attv['pmid'] . $upv['pid'] . $attfileArray['stid'] . $this->statusArray[$auditArray['mastatus']] . $pmidArray['uid'] . $pmidArray['pmname']);
  596. }
  597. }
  598. }
  599. // 施工
  600. $measureArray = $this->actmeasure->getPmidRow($_POST['audituid']);
  601. if (isset($measureArray) && $measureArray) {
  602. $attfileArray = $stidArray = NULL;
  603. foreach ($measureArray as $key => $value) {
  604. $proArray = $this->project->getRowByPid($value['pid']);
  605. $conArray = $this->contractact->getRowByStid($value['stid']);
  606. $attfileArray = $this->attfile->getLastNewProfile2($value['pmid']);
  607. $pmidArray = $this->actmeasure->getRowByPmid($value['pmid']);
  608. $statusArray = $this->numofperact->getMaxRowStatus($attfileArray['pmid'], $attfileArray['numpname']);
  609. $auditArray = $this->measureauditact->getLastNewRowInfo($attfileArray['pmid'], $attfileArray['numpname'], $_POST['audituid']);
  610. $pathinfo = pathinfo($attfileArray['filepath']);
  611. if (!$auditArray['mastatus'])
  612. $auditStr = 'uncheck';
  613. if (isset($pathinfo['dirname'])) {
  614. $hashstr = md5(Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf' . $proArray['pname'] . $conArray['stname'] . $attfileArray['filehashcode'] . $this->statusArray[$statusArray['currstatus']] . $value['pmid'] . $proArray['pid'] . $conArray['stid'] . $this->statusArray[$auditStr] . $pmidArray['uid'] . $pmidArray['pmname']);
  615. if (!in_array($hashstr, $hashArray)) {
  616. $retArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $proArray['pname'], 'stName' => $conArray['stname'], 'MD5_Jl' => $attfileArray['filehashcode'], 'tenderstatus' => $this->statusArray[$statusArray['currstatus']], 'tenderid' => $value['pmid'], 'pnameid' => $proArray['pid'], 'ptypeid' => $conArray['stid'], 'audituidstatus' => $this->statusArray[$auditStr], 'bianzhirenuid' => $pmidArray['uid'], 'tenderName' => $pmidArray['pmname']);
  617. $hashArray[] = $hashstr;
  618. }
  619. }
  620. }
  621. }
  622. // 审批 是否只提取最新一期?
  623. $pmidGroupArray = $this->measureauditact->getPmidGroup($_POST['audituid']);
  624. /**
  625. * 从审批人列表中提取记录时,如果项目进行到新开一次或者一期数据,但是上报人并未上报数据,(犹豫逻辑上机制导致,先创建审批人再通过上报人上报数据才能产生新一期)
  626. * 这时,上报人查询到的数据就为空。
  627. * 如果没有最新一次上报数据(可否提取2期上报数据?即便是能下载也不能打开,因为上一期数据的审批人数或者状态,可能与最新一期的审批人状态不同,然后软件报错)
  628. */
  629. $retval = null;
  630. foreach ($pmidGroupArray as $gkey => $gvalue) {
  631. $retval[] = $this->measureauditact->getLastNumTimes($gvalue['pmid'], $_POST['audituid']);
  632. }
  633. foreach ($retval as $spkey => $spvalue) {
  634. $pathinfo = null;
  635. $proArray = $this->project->getRowByPid($spvalue['pid']);
  636. $conArray = $this->contractact->getRowByStid($spvalue['stid']);
  637. $pmidArray = $this->actmeasure->getRowByPmid($spvalue['pmid']);
  638. /**
  639. * 两种情况 一种情况是 新建一期 还有一种是审批未通过重做 这两种未提交
  640. */
  641. $intNum = $this->numofperact->getCountNumpname($spvalue['pmid'], $spvalue['numpname']);
  642. // 如果期数是第一期期数必须大于一,否则减一为无效数据 ,为0表示这期为做上报没有产生记录
  643. if (($spvalue['numpname'] > 1) && ($intNum == 0)) {// 提取上一期的数据
  644. // 提取期数减一
  645. $intLastTimes = $this->numofperact->getMaxTimes($spvalue['pmid'], $spvalue['numpname'] - 1)['times'];
  646. $numstatusArray = $this->numofperact->getRow($spvalue['pmid'], $spvalue['numpname'] - 1, $intLastTimes); //获取上一期最新一次的状态
  647. } else {
  648. $intTimes = $this->numofperact->getCountTimes($spvalue['pmid'], $spvalue['numpname'], $spvalue['times']);
  649. if (($intTimes == '0') && $spvalue['times'] > 0) {
  650. $numstatusArray = $this->numofperact->getRow($spvalue['pmid'], $spvalue['numpname'], $spvalue['times'] - 1);
  651. } else {// 当创建第一次的时候也会为空,所以下方加了判断
  652. $numstatusArray = $this->numofperact->getRow($spvalue['pmid'], $spvalue['numpname'], $spvalue['times']);
  653. }
  654. }
  655. $afArray = $this->attfile->getLastNewProfile2($spvalue['pmid']); // 由于始终提取最新一期所以不用放入判断情况中
  656. $auditArray = $this->measureauditact->getLastNewRowInfo($spvalue['pmid'], $spvalue['numpname'], $_POST['audituid']);
  657. $pathinfo = pathinfo($afArray['filepath']);
  658. if ($numstatusArray && $auditArray) { // 如果重做审批人有变更,根据审批状态判断是否存在该审批人,不存在则不显示此条记录
  659. $hashstr = md5(Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf' . $proArray['pname'] . $conArray['stname'] . $afArray['filehashcode'] . $this->statusArray[$numstatusArray['currstatus']] . $spvalue['pmid'] . $proArray['pid'] . $conArray['stid'] . $this->statusArray[$auditArray['mastatus']] . $pmidArray['uid'] . $pmidArray['pmname']);
  660. if (!in_array($hashstr, $hashArray)) {
  661. $retArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $proArray['pname'], 'stName' => $conArray['stname'], 'MD5_Jl' => $afArray['filehashcode'], 'tenderstatus' => $this->statusArray[$numstatusArray['currstatus']], 'tenderid' => $spvalue['pmid'], 'pnameid' => $proArray['pid'], 'ptypeid' => $conArray['stid'], 'audituidstatus' => $this->statusArray[$auditArray['mastatus']], 'bianzhirenuid' => $pmidArray['uid'], 'tenderName' => $pmidArray['pmname']);
  662. $hashArray[] = $hashstr;
  663. }
  664. }
  665. }
  666. // $dd = NULL;
  667. // if (isset($retArray))
  668. // $dd = $this->array_unique_fb($retArray);
  669. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $retArray), JSON_UNESCAPED_UNICODE);
  670. }
  671. }
  672. }
  673. //二维数组去掉重复值 并保留键值
  674. function array_unique_fb($array2D)
  675. {
  676. $key = array();
  677. foreach ($array2D as $k => $v) {
  678. if (empty($key))
  679. $key = array_keys($v); //记录数组的KEY
  680. $v = join(",", $v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  681. $temp[$k] = $v;
  682. }
  683. $temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
  684. foreach ($temp as $k => $v) {
  685. $array = explode(",", $v); //再将拆开的数组重新组装
  686. foreach ($array as $i => $t) {
  687. $temp2[$k] = !empty($temp2[$k]) ? array_merge($temp2[$k], array("{
  688. $key[$i]}" => $t)) : array("{
  689. $key[$i]}" => $t); //依次添加到新的数组中去
  690. }
  691. }
  692. return $temp2;
  693. }
  694. function unique_arr($array2D, $stkeep = false, $ndformat = true)
  695. {
  696. // 判断是否保留一级数组键 (一级数组键可以为非数字)
  697. if ($stkeep)
  698. $stArr = array_keys($array2D);
  699. // 判断是否保留二级数组键 (所有二级数组键必须相同)
  700. if ($ndformat)
  701. $ndArr = array_keys(end($array2D));
  702. //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
  703. foreach ($array2D as $v) {
  704. $v = join(",", $v);
  705. $temp[] = $v;
  706. }
  707. //去掉重复的字符串,也就是重复的一维数组
  708. $temp = array_unique($temp);
  709. //再将拆开的数组重新组装
  710. foreach ($temp as $k => $v) {
  711. if ($stkeep)
  712. $k = $stArr[$k];
  713. if ($ndformat) {
  714. $tempArr = explode(",", $v);
  715. foreach ($tempArr as $ndkey => $ndval) {
  716. $output[$k][$ndArr[$ndkey]] = $ndval;
  717. }
  718. } else {
  719. $output[$k] = explode(",", $v);
  720. }
  721. }
  722. return $output;
  723. }
  724. // 标段期审批接口
  725. function auditMeasure()
  726. {
  727. if (isset($_POST['userid']) && isset($_POST['tenderid']) && isset($_POST['phaseno']) && isset($_POST['MD5_JL']) && isset($_POST['MD5_Zip'])) {
  728. $auditcontent = iconv('GBK', 'UTF-8', $_POST['CheckerMemo']);
  729. $auditArray = $this->measureauditact->getLastNewRowInfo($_POST['tenderid'], $_POST['phaseno'], $_POST['userid']);
  730. if (isset($auditArray ['mastatus']) && (($auditArray ['mastatus'] == 'checked') || ($auditArray ['mastatus'] == 'checkno'))) {
  731. echo json_encode(array('status' => FALSE, 'msg' => '该标段已审批完毕。'), JSON_UNESCAPED_UNICODE);
  732. die();
  733. }
  734. $auditUserArray = $this->measureauditact->getUserAuditLast($_POST['tenderid'], $_POST['phaseno']);
  735. $fp = $this->upfile('upfile');
  736. if (isset($fp[0]['filepath'])) {
  737. $localmd5HashString = hash_file("md5", Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  738. if ($localmd5HashString != trim($_POST['MD5_Zip'])) {
  739. $status = array('status' => 'FALSE', 'msg' => '审批期数数据上传失败,请重新上传');
  740. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  741. die();
  742. }
  743. $res = $this->zip->open(Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  744. $extPath = pathinfo($fp[0]['filepath']);
  745. $extPathdir = Doo::conf()->SITE_PATH . $extPath ['dirname'] . '/' . $extPath['filename'];
  746. if ($res === TRUE) {
  747. if (!$this->dir_create($extPathdir)) {
  748. return FALSE;
  749. }
  750. $this->zip->extractTo($extPathdir);
  751. $this->zip->close();
  752. }
  753. // 更新五项最新数据
  754. $countArray = json_decode(file_get_contents($extPathdir . '/' . 'JsonFile_Common.json'), TRUE, JSON_UNESCAPED_UNICODE);
  755. if (!isset($countArray)) {
  756. $status = array('status' => FALSE, 'msg' => '期数汇总数据上传失败');
  757. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  758. die();
  759. }
  760. $iniTimes = 0;
  761. $intMaxTimes = $this->numofperact->getMaxTimes($_POST['tenderid'], $_POST['phaseno']);
  762. if (isset($intMaxTimes['times']) && ($intMaxTimes['times'] > 0)) {
  763. $iniTimes = $intMaxTimes['times'];
  764. }
  765. $this->actmeasure->updateCon($_POST['tenderid'], $countArray['TotalPrice']);
  766. $this->numofperact->updateNumofper($_POST['tenderid'], $_POST['phaseno'], $countArray, $iniTimes);
  767. $numArray = $this->numofperact->getRow($_POST['tenderid'], $_POST['phaseno'], $iniTimes);
  768. if (isset($auditArray['pid'])) {
  769. // 插入附件表之前要更新所有次标段期数的提交的数据状态为旧标志
  770. $this->attfile->setOldfileFlag($_POST['tenderid'], $_POST['phaseno'], $iniTimes);
  771. // 插入此次提交的文件路径数据并设置为新状态
  772. // 写入此时是第几次重做
  773. $this->attfile->insertFile($auditArray['pid'], $auditArray['stid'], $numArray['mpid'], $_POST['tenderid'], $_POST['phaseno'], $_POST['userid'], $fp[0]['filepath'], 0, $_POST['MD5_JL'], $iniTimes);
  774. // 更新审批表审批人的标段期数审批状态
  775. if ($this->measureauditact->setStatusTo($auditArray['maid'], 3, $auditcontent)) {
  776. // 更新下一个人的状态
  777. $countAudit = count($auditUserArray);
  778. if ($auditArray['last'] == '1') {// 根据标志位判断是否为最后一个审核人{ 判断当前审核人是什么角色 } 利用post发送的UID 与 当前期数参与的所有人比较
  779. $this->measureauditact->setStatusTo($auditUserArray[0]['maid'], 3);
  780. $this->numofperact->updateAuditStatus($_POST['tenderid'], $_POST['phaseno'], 'checked', $iniTimes);
  781. // SMS Start
  782. $TenderArray = $this->actmeasure->getRowByPmid($_POST['tenderid']);
  783. $userProArray = $this->profile->getProWithUid($TenderArray['uid']);
  784. if (isset($userProArray) && ($userProArray['mobile'])) {
  785. $retval = $this->__auditNotice($userProArray['mobile'], Doo::conf()->SMS_TIPS_PRE . '您好,' . $TenderArray["pmname"] . Doo::conf()->SMS_TIPS["AUDIT_NOTICE_AUDITOR3"]);
  786. }
  787. // SMS End
  788. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  789. die();
  790. } else {// 不是最后一个审核人根据不同审核人数量变更状态 {当前用户不是最后一个审核人}
  791. if (($countAudit == 2) && ($auditUserArray[0]['last'] == 1) && ($auditUserArray[1]['maid'] == $auditArray['maid'])) {// 如果审核人为两个,第一个是最后审核人角色,第二个为当前审核人,设置审核中状态 {就是当前用户POST UID}
  792. $this->measureauditact->updateMastatus($auditUserArray[0]['maid']);
  793. $this->numofperact->updateAuditStatus($_POST['tenderid'], $_POST['phaseno'], 'checking', $iniTimes);
  794. // SMS Start
  795. $verifyUserArray = $this->profile->getVerifiedMobile($auditUserArray[0]['auditoruid']);
  796. $pmnameArray = $this->actmeasure->getRowByPmid($_POST['tenderid']);
  797. if (isset($verifyUserArray) && ($verifyUserArray['mobile'])) {// XXXX(标段名),陈特,已审批通过。请您继续审批。
  798. $this->__auditNotice($verifyUserArray['mobile'], Doo::conf()->SMS_TIPS_PRE . '您好,' . $pmnameArray["pmname"] . Doo::conf()->SMS_TIPS["AUDIT_NOTICE_AUDITOR2"]);
  799. }
  800. // SMS End
  801. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  802. die();
  803. }
  804. if (($countAudit > 2)) {// 审核人总数大于2时,
  805. foreach ($auditUserArray as $k => $v) {
  806. if ($v['maid'] == $auditArray['maid']) {// 找到当前用户
  807. if ($k == ($countAudit - 1)) {//如果是最后一个
  808. $this->measureauditact->updateMastatus($auditUserArray[0]['maid']);
  809. $verifyUserArray = $this->profile->getVerifiedMobile($auditUserArray[0]['auditoruid']);
  810. $pmnameArray = $this->actmeasure->getRowByPmid($auditUserArray[0]['pmid']);
  811. } else {
  812. $this->measureauditact->updateMastatus($auditUserArray[$k + 1]['maid']);//变更下一个状态
  813. $verifyUserArray = $this->profile->getVerifiedMobile($auditUserArray[$k + 1]['auditoruid']);
  814. $pmnameArray = $this->actmeasure->getRowByPmid($auditUserArray[$k]['pmid']);
  815. }
  816. // SMS Start
  817. if (isset($verifyUserArray) && ($verifyUserArray['mobile'])) {// // XXXX(标段名),陈特,已审批通过。请您继续审批。
  818. $this->__auditNotice($verifyUserArray['mobile'], Doo::conf()->SMS_TIPS_PRE . '您好,' . $pmnameArray["pmname"] . Doo::conf()->SMS_TIPS["AUDIT_NOTICE_AUDITOR2"]);
  819. }
  820. // SMS End
  821. $this->numofperact->updateAuditStatus($_POST['tenderid'], $_POST['phaseno'], 'checking', $iniTimes);
  822. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  823. die();
  824. }
  825. }
  826. // 我是第几个审批的
  827. // 如果是最后一个就把业主审批状态更改为审批中
  828. // 如果是第一个就把后一个设置为审批中
  829. }
  830. }
  831. } else {
  832. echo json_encode(array('status' => FALSE, 'msg' => '审批文件提交失败1'), JSON_UNESCAPED_UNICODE);
  833. die();
  834. }
  835. }
  836. } else {
  837. echo json_encode(array('status' => FALSE, 'msg' => '审批文件提交失败'), JSON_UNESCAPED_UNICODE);
  838. die();
  839. }
  840. } else {
  841. echo json_encode(array('status' => FALSE, 'msg' => '审批参数错误'), JSON_UNESCAPED_UNICODE);
  842. die();
  843. }
  844. }
  845. /**
  846. * 根据标段ID查询是否需要更新
  847. */
  848. function checkTenderUpdate()
  849. {
  850. if (isset($this->params ['tenderid']) && $this->params['tenderid']) {
  851. $updateArray = $this->attfile->getFileUpdate($this->params['tenderid']);
  852. $projectArray = $this->project->getRowByPid($updateArray['pid']);
  853. $stArray = $this->contractact->getRowByStid($updateArray['stid']);
  854. $MeasureArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  855. if (isset($updateArray['filepath'])) {
  856. $pathinfo = pathinfo($updateArray['filepath']);
  857. $downfileurl[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'MD5_Jl' => $updateArray['filehashcode'], 'proName' => $projectArray['pname'], 'stName' => $stArray['stname'], 'pnameid' => $projectArray['pid'], 'ptypeid' => $stArray['stid'], 'BidName' => $MeasureArray['pmname']);
  858. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $downfileurl), JSON_UNESCAPED_UNICODE);
  859. die();
  860. } else {
  861. echo json_encode(array('status' => TRUE, 'msg' => '暂无更新数据'), JSON_UNESCAPED_UNICODE);
  862. die();
  863. }
  864. } else {
  865. echo json_encode(array('status' => FALSE, 'msg' => '更新查询参数错误'), JSON_UNESCAPED_UNICODE);
  866. die();
  867. }
  868. }
  869. /**
  870. * 手动创建第二期的审批人
  871. */
  872. function creatTenderNumPnameUser()
  873. {
  874. if (isset($_POST['tenderid']) && isset($_POST['phaseno']) && ($_POST['phaseno'] > 1)) {
  875. $allMeasureUser = $this->measureauditact->getUserAudit($_POST['tenderid'], $_POST['phaseno'] - 1);
  876. if (isset($allMeasureUser)) {
  877. foreach ($allMeasureUser as $key => $value) {
  878. // if ($key == 1) {
  879. // $status = 'checking';
  880. // } else {
  881. $status = 'uncheck';
  882. // }
  883. try {
  884. $this->measureauditact->insertMeasureAudit($value['pid'], $value['creatoruid'], $value['auditoruid'], $value['mpid'], $value['pmid'], $value['stid'], $_POST['phaseno'], $status, $value['last']);
  885. } catch (Exception $exc) {
  886. }
  887. }
  888. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  889. die();
  890. } else {
  891. echo json_encode(array('status' => FALSE, 'msg' => '审批人员列表不存在'), JSON_UNESCAPED_UNICODE);
  892. die();
  893. }
  894. } else {
  895. echo json_encode(array('status' => FALSE, 'msg' => '创建审批人员列表参数错误'), JSON_UNESCAPED_UNICODE);
  896. die();
  897. }
  898. }
  899. /**
  900. * 返回指定用户参与的所有项目
  901. */
  902. function getUserALLProject()
  903. {
  904. if (!isset($this->params['userid']) || !($this->params['userid'] > 0)) {
  905. echo json_encode(array('status' => FALSE, 'msg' => '返回指定用户参与的所有项目参数错误'), JSON_UNESCAPED_UNICODE);
  906. die();
  907. }
  908. $conArray = $this->contractact->getUserRow($this->params['userid']);
  909. if (isset($conArray) && $conArray) {
  910. foreach ($conArray as $key => $value) {
  911. $proArray = $this->project->getRowByPid($value['pid']);
  912. $attfileArray = $this->attfile->getLastData($value['stid']);
  913. foreach ($attfileArray as $k => $v) {
  914. $pathinfo = pathinfo($v['filepath']);
  915. $retArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $proArray['pname'], 'stName' => $value['stname'], 'MD5_Jl' => $v['filehashcode']);
  916. }
  917. }
  918. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $retArray), JSON_UNESCAPED_UNICODE);
  919. die();
  920. } else {
  921. $userproArray = $this->measureauditact->getProject($this->params['userid']);
  922. if (isset($userproArray) && $userproArray) {
  923. foreach ($userproArray as $upk => $upv) {
  924. $attArray = $this->attfile->getMeasureLastNew($upv['pmid'], $upv['numpname']);
  925. $proArray = $this->project->getRowByPid($attArray['pid']);
  926. $attfileArray = $this->contractact->getRowByStid($attArray['stid']);
  927. $pathinfo = pathinfo($attArray['filepath']);
  928. if (isset($pathinfo['dirname']))
  929. $newattArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo ['dirname'] . '/' . $pathinfo ['filename'] . '/ProjectFile.rmf', 'proName' => $proArray['pname'], 'stName' => $attfileArray['stname'], 'MD5_Jl' => $attArray['filehashcode']);
  930. }
  931. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $newattArray), JSON_UNESCAPED_UNICODE);
  932. die();
  933. }
  934. }
  935. }
  936. /**
  937. * 设置审批未通过操作
  938. * 第一步设置未通过操作,操作相关期数。 同步状态。
  939. * 第二步设置项目查询接口未通过审批的查询返回未锁定的
  940. * 第三步前台相关状态更新
  941. *
  942. * TODO: 更新附件标志位未加入次数标志做更新 ok
  943. * TODO: 不通过两次未通过时候操作期数状态为错误位同步状态位 ok
  944. * TODO: MPID未通过操作不争取 ok
  945. */
  946. function setCheckno()
  947. {
  948. if (isset($this->params['userid']) && isset($this->params['tenderid']) && isset($this->params['phaseno']) && isset($_POST['MD5_JL']) && isset($_POST['MD5_Zip'])) {
  949. $auditcontent = iconv('GBK', 'UTF - 8', $_POST['CheckerMemo']);
  950. $auditArrayStatus = $this->measureauditact->getLastNewRowInfo($this->params['tenderid'], $this->params['phaseno'], $this->params['userid']);
  951. if (isset($auditArrayStatus ['mastatus']) && (($auditArrayStatus ['mastatus'] == 'checked') || ($auditArrayStatus ['mastatus'] == 'checkno'))) {
  952. echo json_encode(array('status' => FALSE, 'msg' => '该标段已审批完毕。'), JSON_UNESCAPED_UNICODE);
  953. die();
  954. }
  955. $auditArray = $this->measureauditact->getRowInfo($this->params['tenderid'], $this->params['phaseno'], $this->params['userid']);
  956. if (isset($auditArray['maid'])) {
  957. $intMaxTimes = $this->numofperact->getMaxTimes($this->params['tenderid'], $this->params['phaseno']);
  958. if (isset($intMaxTimes['times'])) {
  959. $iniTimes = $intMaxTimes['times'];
  960. }
  961. $this->measureauditact->setCheckno($auditArray['maid'], $auditcontent);
  962. $this->numofperact->updateAuditStatus($this->params['tenderid'], $this->params['phaseno'], 'checkno', $iniTimes);
  963. $fp = $this->upfile('upfile');
  964. if (isset($fp[0]['filepath'])) {
  965. // 解压缩文件等待以后直接使用
  966. // TODO:根据校验码校验包的完整性
  967. $localmd5HashString = hash_file("md5", Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  968. if ($localmd5HashString != trim($_POST['MD5_Zip'])) {
  969. $status = array('status' => 'FALSE', 'msg' => '未通过期数数据上传失败,请重新上传');
  970. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  971. die();
  972. }
  973. $res = $this->zip->open(Doo::conf()->SITE_PATH . $fp[0]['filepath']);
  974. $extPath = pathinfo($fp[0]['filepath']);
  975. $extPathdir = Doo::conf()->SITE_PATH . $extPath ['dirname'] . '/' . $extPath['filename'];
  976. if ($res === TRUE) {
  977. if (!$this->dir_create($extPathdir)) {
  978. return FALSE;
  979. }
  980. $this->zip->extractTo($extPathdir);
  981. $this->zip->close();
  982. }
  983. $numArray = $this->numofperact->getRow($this->params['tenderid'], $this->params['phaseno'], $iniTimes);
  984. // 插入附件表之前要更新所有次标段期数的提交的数据状态为旧标志
  985. $this->attfile->setOldfileFlag($this->params['tenderid'], $this->params['phaseno'], $iniTimes);
  986. // 插入此次提交的文件路径数据并设置为新状态
  987. $this->attfile->insertFile($auditArray['pid'], $auditArray['stid'], $auditArray['mpid'], $this->params['tenderid'], $this->params['phaseno'], $this->params['userid'], $fp[0]['filepath'], 0, $_POST['MD5_JL'], $iniTimes);
  988. // SMS Start
  989. $TenderArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  990. $userProArray = $this->profile->getProWithUid($TenderArray['uid']);
  991. if (isset($userProArray) && ($userProArray['mobile'])) {
  992. $retval = $this->__auditNotice($userProArray['mobile'], Doo::conf()->SMS_TIPS_PRE . '您好,' . $TenderArray["pmname"] . Doo::conf()->SMS_TIPS["AUDIT_NOTICE_AUDITOR4"]);
  993. }
  994. // SMS End
  995. echo json_encode(array('status' => TRUE, 'msg' => ''), JSON_UNESCAPED_UNICODE);
  996. die();
  997. } else {
  998. echo json_encode(array('status' => FALSE, 'msg' => '文件上传故障'), JSON_UNESCAPED_UNICODE);
  999. die();
  1000. }
  1001. } else {
  1002. echo json_encode(array('status' => FALSE, 'msg' => '审批期数不存在'), JSON_UNESCAPED_UNICODE);
  1003. die();
  1004. }
  1005. } else {
  1006. echo json_encode(array('status' => FALSE, 'msg' => '审批未通过参数错误'), JSON_UNESCAPED_UNICODE);
  1007. die();
  1008. }
  1009. }
  1010. /**
  1011. * 创建未通过的新一期
  1012. *
  1013. */
  1014. function createNewAudit()
  1015. {
  1016. // 插入上次期数相关审批人员
  1017. // TODO:
  1018. // error_log(var_export($this->params, TRUE), 3, ' / opt / html / jiliang_customedProduct / data / ' . time());
  1019. // die;
  1020. if (isset($this->params['tenderid']) && isset($this->params['phaseno'])) {
  1021. $auditArray = $this->numofperact->getChecknoRow($this->params['tenderid'], $this->params['phaseno']);
  1022. if (isset($auditArray['currstatus']) && ($auditArray['currstatus'] == 'checkno')) {
  1023. $isCreate = false;
  1024. $auditUserArray = $this->measureauditact->getUserAuditLast($this->params['tenderid'], $this->params['phaseno']);
  1025. foreach ($auditUserArray as $key => $value) {
  1026. if ($value['mastatus'] != 'uncheck') {
  1027. $isCreate = true;
  1028. }
  1029. }
  1030. if ($auditUserArray && $isCreate) {
  1031. foreach ($auditUserArray as $key => $value) {
  1032. $this->measureauditact->insertMeasureAudit($value['pid'], $value['creatoruid'], $value['auditoruid'], $value['mpid'], $value['pmid'], $value['stid'], $value['numpname'], $status = 'uncheck', $value['last'], $auditArray['times'] + 1);
  1033. }
  1034. } else {
  1035. echo json_encode(array('status' => FALSE, 'msg' => '无效操作重复创建审批人'), JSON_UNESCAPED_UNICODE);
  1036. die();
  1037. }
  1038. //// $timesArray = $this->numofperact->getMaxTimes($this->params['tenderid'], $this->params['phaseno']);
  1039. // $urlinfoArray = $this->attfile->getLastNewProfileUnlock2($this->params['tenderid'], $this->params['phaseno']);
  1040. // $proArray = $this->project->getRowByPid($urlinfoArray['pid']);
  1041. // $stArray = $this->contractact->getRowByStid($urlinfoArray['stid']);
  1042. // $MeasureArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  1043. // $downArray = NULL;
  1044. // $pathinfo = pathinfo($urlinfoArray['filepath']);
  1045. // if (isset($pathinfo['dirname']))
  1046. // $downArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo['dirname'] . ' / ' . $pathinfo['filename'] . ' / ProjectFile . rmf', 'MD5_Jl' => $urlinfoArray['filehashcode'], 'proName' => $proArray['pname'], 'stName' => $stArray['stname'], 'pnameid' => $proArray['pid'], 'ptypeid' => $stArray['stid'], 'BidName' => $MeasureArray['pmname']);
  1047. // echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $downArray), JSON_UNESCAPED_UNICODE);
  1048. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  1049. die();
  1050. } else {
  1051. echo json_encode(array('status' => FALSE, 'msg' => '审批状态无效'), JSON_UNESCAPED_UNICODE);
  1052. die();
  1053. }
  1054. } else {
  1055. echo json_encode(array('status' => FALSE, 'msg' => '创建未通过的新一期参数错误'), JSON_UNESCAPED_UNICODE);
  1056. die();
  1057. }
  1058. }
  1059. /**
  1060. * 重做新一期获取原报上报文件
  1061. *
  1062. */
  1063. function getReportFile()
  1064. {
  1065. if (isset($this->params['tenderid']) && isset($this->params['phaseno'])) {
  1066. $auditArray = $this->numofperact->getChecknoRow($this->params['tenderid'], $this->params['phaseno']);
  1067. if (isset($auditArray['currstatus']) && ($auditArray['currstatus'] == 'checkno')) {
  1068. $timesArray = $this->numofperact->getMaxTimes($this->params['tenderid'], $this->params['phaseno']);
  1069. $urlinfoArray = $this->attfile->getReportFile($this->params['tenderid'], $this->params['phaseno'], $timesArray['times']);
  1070. $proArray = $this->project->getRowByPid($urlinfoArray['pid']);
  1071. $stArray = $this->contractact->getRowByStid($urlinfoArray['stid']);
  1072. $MeasureArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  1073. $downArray = NULL;
  1074. $pathinfo = pathinfo($urlinfoArray['filepath']);
  1075. if (isset($pathinfo['dirname'])) {
  1076. $downArray[] = array('downurl' => Doo::conf()->APP_URL . $pathinfo['dirname'] . '/' . $pathinfo['filename'] . '/ProjectFile.rmf', 'MD5_Jl' => $urlinfoArray['filehashcode'], 'proName' => $proArray['pname'], 'stName' => $stArray['stname'], 'pnameid' => $proArray['pid'], 'ptypeid' => $stArray['stid'], 'BidName' => $MeasureArray['pmname']);
  1077. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $downArray), JSON_UNESCAPED_UNICODE);
  1078. die();
  1079. } else {
  1080. echo json_encode(array('status' => FALSE, 'msg' => '上报文件不存在'), JSON_UNESCAPED_UNICODE);
  1081. die();
  1082. }
  1083. } else {
  1084. echo json_encode(array('status' => FALSE, 'msg' => '审批状态无效'), JSON_UNESCAPED_UNICODE);
  1085. die();
  1086. }
  1087. } else {
  1088. echo json_encode(array('status' => FALSE, 'msg' => '创建未通过的新一期参数错误'), JSON_UNESCAPED_UNICODE);
  1089. die();
  1090. }
  1091. }
  1092. public function getUserInfo()
  1093. {
  1094. if (isset($this->params['userid']) && ($this->params['userid'] > 0)) {
  1095. $proArray = $this->profile->getProWithUid($this->params['userid']);
  1096. if (isset($proArray['userid'])) {
  1097. $strAvatar = $this->auth->getAvatar($proArray['userid']);
  1098. echo json_encode(array('status' => 'TRUE', 'msg' => '', 'info' => array('avatar' => $strAvatar, 'name' => $proArray['name'], 'jobs' => $proArray['jobs'], 'company' => $proArray['company'])), JSON_UNESCAPED_UNICODE);
  1099. die();
  1100. } else {
  1101. echo json_encode(array('status' => 'FALSE', 'msg' => '此用户不存在'), JSON_UNESCAPED_UNICODE);
  1102. die();
  1103. }
  1104. } else {
  1105. echo json_encode(array('status' => 'FALSE', 'msg' => '用户查询参数无效'), JSON_UNESCAPED_UNICODE);
  1106. die();
  1107. }
  1108. }
  1109. public function updateTenderName()
  1110. {
  1111. if (isset($this->params['BidID']) && isset($this->params['BidNewName'])) {
  1112. if ($this->actmeasure->updateName($this->params['BidID'], iconv('GBK', 'UTF - 8', $this->params['BidNewName']))) {
  1113. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  1114. die();
  1115. } else {
  1116. echo json_encode(array('status' => 'FALSE', 'msg' => '标段名称更新错误'), JSON_UNESCAPED_UNICODE);
  1117. die();
  1118. }
  1119. } else {
  1120. echo json_encode(array('status' => 'FALSE', 'msg' => '标段名称更新参数无效'), JSON_UNESCAPED_UNICODE);
  1121. die();
  1122. }
  1123. }
  1124. /**
  1125. * 清单附件上传,单文件上传
  1126. * @param int $tenderid 标段ID
  1127. * @param int $uid 上传人ID
  1128. * @param int $itemid 本地清单ID
  1129. */
  1130. public function uploadItemFile()
  1131. {
  1132. if (isset($this->params['tenderid']) && isset($this->params['uid'])) {
  1133. if (!isset($_FILES['upitem']) && !isset($_POST['itemid']) && !isset($_POST['category']) && !isset($_POST['phase'])) {
  1134. $this->msg(0, '上传参数错误');
  1135. }
  1136. $fileArray = $this->upItemFile('upitem')[0];
  1137. if (isset($fileArray['filepath'])) {
  1138. $pidArray = $this->actmeasure->getRowByPmid($this->params['tenderid']);
  1139. $memoStr = iconv('GBK', 'UTF-8', $_POST['Memo']);
  1140. $pathinfo_dirname = pathinfo($fileArray['filepath'], PATHINFO_DIRNAME);
  1141. $filenameStr2 = iconv('GBK', 'UTF-8', $fileArray['filename']);
  1142. $url = $pathinfo_dirname . '/' . $filenameStr2;
  1143. setlocale(LC_ALL, 'zh_CN.UTF-8');
  1144. $fname = pathinfo($url);
  1145. $filenameStr = $fname['filename'];
  1146. $postArray = array('ownerid' => $this->params['uid'], 'pid' => $pidArray['pid'], 'pmid' => $this->params['tenderid'], 'filename' => $filenameStr, 'filesize' => $fileArray['filesize'], 'fileext' => $fileArray['fileext'], 'filepath' => $fileArray['filepath']);
  1147. $iaid = $this->itemfile->insertItemFileRecord($postArray);
  1148. if ($iaid > 1) {
  1149. $itemMeasureNumArray = array('iaid' => $iaid, 'pid' => $pidArray['pid'], 'pmid' => $this->params['tenderid'], 'numpname' => $_POST['phase'], 'ownerid' => $this->params['uid'], 'itemid' => $_POST['itemid'], 'categoryid' => array_search($_POST['category'], $this->fileTypeArray), 'tips' => $memoStr);
  1150. if (($imnid = $this->itemMeasureNum->insert($itemMeasureNumArray)) > 0) {
  1151. $extPath = pathinfo($fileArray['filepath']);
  1152. $itemArray = array('onlineFileName' => $extPath['filename'] . '.' . $extPath['extension'], 'imnid' => $imnid, 'fileurl' => Doo::conf()->APP_URL . $fileArray['filepath']);
  1153. $status = array('status' => TRUE, 'msg' => '', 'iteminfo' => $itemArray);
  1154. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1155. die();
  1156. } else {
  1157. $this->msg(0, '附件上传失败,请重新上传.');
  1158. }
  1159. }
  1160. } else {
  1161. $this->msg(0, '附件上传失败,请重新上传');
  1162. }
  1163. } else {
  1164. $this->msg(0, '上传参数错误');
  1165. }
  1166. }
  1167. /**
  1168. * 获得清单附件列表
  1169. */
  1170. public function getItemFileList()
  1171. {
  1172. if (isset($this->params['tenderid'])) {
  1173. $itemfileArray = $this->itemMeasureNum->getItemMeasureNum($this->params['tenderid']);
  1174. foreach ($itemfileArray as $value) {
  1175. $profileArray = $this->profile->getProWithUid($value['ownerid']);
  1176. $attFileArray = $this->itemfile->getItemFile($value['iaid']);
  1177. if (isset($attFileArray) && $attFileArray && isset($profileArray) && $profileArray)
  1178. $downArray[] = array('downurl' => Doo::conf()->APP_URL . $attFileArray['filepath'], 'filename' => $attFileArray['filename'] . '.' . $attFileArray['fileext'], 'fileext' => $attFileArray['fileext'], 'ownerName' => $profileArray['name'], 'itemid' => $value['softwareitemid'], 'Category' => $value['categoryid'], 'Memo' => $value['tips'], 'ownerid' => $value['ownerid'], 'uptime' => date('Y-m-d H:i', $value['intime']), 'fileid' => $value['imnid'], 'phase' => $value['numpname']);
  1179. }
  1180. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $downArray), JSON_UNESCAPED_UNICODE);
  1181. die();
  1182. } else {
  1183. $this->msg(0, '获取附件列表参数错误');
  1184. }
  1185. }
  1186. /**
  1187. * 编辑清单附件描述 文件名?
  1188. */
  1189. public function updateItemFileDesc()
  1190. {
  1191. if (isset($this->params['fileid']) && isset($_POST['FileName']) && isset($_POST['Memo'])) {
  1192. // $memoStr = iconv('GB18030', 'UTF-8', $_POST['Memo']);
  1193. $memoStr = $_POST['Memo'];
  1194. // $filenameStr = iconv('GB18030', 'UTF-8', $_POST['FileName']);
  1195. $filenameStr = $_POST['FileName'];
  1196. $imnidArray = $this->itemMeasureNum->getRowData($this->params['fileid']);
  1197. // if ($this->itemMeasureNum->updateItemFields($this->params['fileid'], $memoStr) > 0) {
  1198. $this->itemMeasureNum->updateItemFields($this->params['fileid'], $memoStr);
  1199. $this->itemfile->updateItemFields($imnidArray['iaid'], $filenameStr);
  1200. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  1201. die();
  1202. // } else {
  1203. // echo json_encode(array('status' => 'FALSE', 'msg' => '附件更新接口参数错误'), JSON_UNESCAPED_UNICODE);
  1204. // die();
  1205. // }
  1206. } else {
  1207. $this->msg(0, '附件更新接口参数错误');
  1208. }
  1209. }
  1210. /**
  1211. * 删除清单附件
  1212. */
  1213. public function delItemFile()
  1214. {
  1215. if (isset($this->params['fileid'])) {
  1216. $this->itemMeasureNum->delItemFields($this->params['fileid']);
  1217. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  1218. die();
  1219. } else {
  1220. $this->msg(0, '关联删除接口参数错误');
  1221. }
  1222. }
  1223. /**
  1224. * @return attachment
  1225. */
  1226. public function getAttaFilesAll()
  1227. {
  1228. if (isset($this->params['tenderid'])) {
  1229. $itemfileArray = $this->itemfile->getFilesAll($this->params['tenderid']);
  1230. foreach ($itemfileArray as $value) {
  1231. // $profileArray = $this->profile->getProWithUid($value['ownerid']);
  1232. // $attFileArray = $this->itemfile->getItemFile($value['iaid']);
  1233. // if (isset($attFileArray) && $attFileArray && isset($profileArray) && $profileArray)
  1234. $filesArray[] = array('downurl' => Doo::conf()->APP_URL . $value['filepath'], 'filename' => $value['filename'] . '.' . $value['fileext'], 'fileext' => $value['fileext'], 'fileid' => $value['iaid']);
  1235. }
  1236. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $filesArray), JSON_UNESCAPED_UNICODE);
  1237. die();
  1238. } else {
  1239. $this->msg(0, '获取附件列表参数错误');
  1240. }
  1241. }
  1242. /**
  1243. * @return attachment
  1244. */
  1245. public function createAttWithTender()
  1246. {
  1247. if (isset($this->params['tenderid'])) {
  1248. $itemfileArray = $this->itemfile->getFilesAll($this->params['tenderid']);
  1249. foreach ($itemfileArray as $value) {
  1250. // $profileArray = $this->profile->getProWithUid($value['ownerid']);
  1251. // $attFileArray = $this->itemfile->getItemFile($value['iaid']);
  1252. // if (isset($attFileArray) && $attFileArray && isset($profileArray) && $profileArray)
  1253. $filesArray[] = array('downurl' => Doo::conf()->APP_URL . $value['filepath'], 'filename' => $value['filename'] . '.' . $value['fileext'], 'fileext' => $value['fileext'], 'fileid' => $value['iaid']);
  1254. }
  1255. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $filesArray), JSON_UNESCAPED_UNICODE);
  1256. die();
  1257. } else {
  1258. $this->msg(0, '获取附件列表参数错误');
  1259. }
  1260. }
  1261. /**
  1262. * 查询指定项目的指定期的全部审批意见。
  1263. * 标段ID,期号
  1264. */
  1265. public function getAuditOpinion()
  1266. {
  1267. if (isset($this->params['tenderid']) && isset($this->params['phaseno'])) {
  1268. $retval = $this->measureauditact->getAuditOpinion($this->params['tenderid'], $this->params['phaseno']);
  1269. $iterator = new ArrayIterator($retval);
  1270. if (iterator_count($iterator) > 0) {
  1271. foreach ($retval as $value) {
  1272. $proArray = $this->profile->getProWithUid($value['auditoruid']);
  1273. $auditcontent = !empty($value['auditcontent']) ? $value['auditcontent'] : '';
  1274. $uArray[] = array('realname' => $proArray['name'], 'jobs' => $proArray['jobs'], 'acontent' => $auditcontent);
  1275. }
  1276. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $uArray), JSON_UNESCAPED_UNICODE);
  1277. die();
  1278. } else {
  1279. echo json_encode(array('status' => 'FALSE', 'msg' => '查询指定项目的指定期的全部审批意见参数错误'), JSON_UNESCAPED_UNICODE);
  1280. die();
  1281. }
  1282. } else {
  1283. $this->msg(0, '查询指定项目的指定期的全部审批意见接口参数错误');
  1284. }
  1285. }
  1286. /**
  1287. * 。
  1288. * 标段ID,期号
  1289. */
  1290. private function __auditNotice($mobile, $text)
  1291. {
  1292. $smsSwitch = $this->aconfig->getOne(array('select' => 'smsSwitch', 'asArray' => TRUE))['smsSwitch'];
  1293. if ($smsSwitch > 0)
  1294. return $this->sms->sendSms($mobile, $text);
  1295. }
  1296. function upfile($fildname, $param = 'doc, docx, xls, xlsx, png, zip')
  1297. {
  1298. return $this->att->uploadMut($fildname, $param);
  1299. }
  1300. function upItemFile($fildname, $param = 'doc, docx, xls, xlsx, png, zip')
  1301. {
  1302. $this->att->setUploadDir();
  1303. return $this->att->uploadMut($fildname, $param);
  1304. }
  1305. /**
  1306. * 根据标段ID获取标段是否已经被删除的提示
  1307. * 标段ID
  1308. */
  1309. public function getCountPmid()
  1310. {
  1311. if (isset($this->params['tenderid'])) {
  1312. $isexist = $this->actmeasure->getCountPmid($this->params['tenderid']);
  1313. if ($isexist > 0) {
  1314. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => null), JSON_UNESCAPED_UNICODE);
  1315. die();
  1316. } else {
  1317. echo json_encode(array('status' => 'FALSE', 'msg' => '该项目[XXX]在云端已被删除,点击“确定”后,可手动删除该项目'), JSON_UNESCAPED_UNICODE);
  1318. die();
  1319. }
  1320. } else {
  1321. $this->msg(0, '获取标段是否存在参数错误');
  1322. }
  1323. }
  1324. function getFileupErrorNo()
  1325. {
  1326. return $this->att->error();
  1327. }
  1328. function Signout()
  1329. {
  1330. session_destroy();
  1331. }
  1332. function isLoggedIn()
  1333. {
  1334. return isset($_SESSION['user_id']);
  1335. }
  1336. function generateFormHash($salt)
  1337. {
  1338. $hash = md5(mt_rand(1, 1000000) . $salt);
  1339. $_SESSION['csrf_hash'] = $hash;
  1340. return $hash;
  1341. }
  1342. function isValidFormHash($hash)
  1343. {
  1344. return $_SESSION['csrf_hash'] === $hash;
  1345. }
  1346. /**
  1347. * 随机字符串函数
  1348. * @param $password 密码
  1349. * @param $random 随机数
  1350. */
  1351. function random($length, $chars = '0123456789')
  1352. {
  1353. $hash = '';
  1354. $max = strlen($chars) - 1;
  1355. for ($i = 0; $i < $length; $i++) {
  1356. $hash .= $chars[mt_rand(0, $max)];
  1357. }
  1358. return $hash;
  1359. }
  1360. /**
  1361. * 生成随机字符串
  1362. * @param string $lenth 长度
  1363. * @return string 字符串
  1364. */
  1365. function create_randomstr($lenth = 6)
  1366. {
  1367. return $this->random($lenth, '123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ');
  1368. }
  1369. function dir_create($path, $mode = 0777)
  1370. {
  1371. if (is_dir($path))
  1372. return TRUE;
  1373. $path = $this->dir_path($path);
  1374. $parent = dirname($path);
  1375. if (!is_dir($parent))
  1376. @mkdir($parent, 0777, true);
  1377. @mkdir($path, 0777, true);
  1378. return is_dir($path);
  1379. }
  1380. function dir_create2($path, $mode = 0777)
  1381. {
  1382. if (is_dir($path))
  1383. return TRUE;
  1384. $path = $this->dir_path($path);
  1385. $parent = dirname($path);
  1386. if (!is_dir($parent)){
  1387. @mkdir($parent, 0777);
  1388. @chmod($parent, 0777);
  1389. }
  1390. @mkdir($path, 0777);
  1391. @chmod($path, 0777);
  1392. return is_dir($path);
  1393. }
  1394. function dir_path($path)
  1395. {
  1396. $path = str_replace('\\', '/', $path);
  1397. if (substr($path, -1) != '/')
  1398. $path = $path . '/';
  1399. return $path;
  1400. }
  1401. function msg($isTrue = 0, $msg = null, $retmsg = null)
  1402. {
  1403. if ($isTrue > 0) {
  1404. echo json_encode(array('status' => 'TRUE', 'msg' => ''), JSON_UNESCAPED_UNICODE);
  1405. die();
  1406. } else {
  1407. echo json_encode(array('status' => 'FALSE', 'msg' => $msg), JSON_UNESCAPED_UNICODE);
  1408. die();
  1409. }
  1410. }
  1411. // function checkVersion($version)
  1412. // {
  1413. // preg_match();
  1414. // }
  1415. //在线签署的接口
  1416. public function getSignCreate(){
  1417. // TODO:上报数据
  1418. if (!empty($_FILES['upspdf']['name']) && !empty($_FILES['upfile']['name']) && isset($_POST['project']) && isset($_POST['tender']) && isset($_POST['phaseno']) && isset($_POST['name']) && isset($_POST['ownuid']) && isset($_POST['widhei'])) {
  1419. //解压压缩包并把图片存到文件夹中
  1420. @$_POST['name'] = iconv('GBK', 'UTF-8', $_POST['name']);
  1421. $upfilename = pathinfo($_FILES['upfile']['name']);
  1422. if($upfilename['extension'] != 'zip'){
  1423. $status = array('status' => 'FALSE', 'msg' => '上传的文件格式有误');
  1424. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1425. die();
  1426. }
  1427. $res = $this->zip->open($_FILES['upfile']['tmp_name']);
  1428. if ($res === TRUE) {
  1429. $samesignname = $this->sign->getSignbyName($_POST['name']);
  1430. if(!empty($samesignname)){
  1431. $status = array('status' => 'FALSE', 'msg' => '存在同名报表');
  1432. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1433. die();
  1434. }
  1435. //添加到签署报表中
  1436. $intime = time();
  1437. $signid = $this->sign->insertSign($_POST['project'], $_POST['tender'], $_POST['phaseno'], $_POST['name'], $_POST['ownuid'],$intime,$_POST['widhei']);
  1438. $extPathdir = Doo::conf()->SITE_PATH . 'signs/' . $signid;
  1439. if ($res === TRUE) {
  1440. if (!$this->dir_create2($extPathdir)) {
  1441. $status = array('status' => 'FALSE', 'msg' => '期数数据上传失败');
  1442. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1443. die();
  1444. }
  1445. $this->zip->extractTo($extPathdir);
  1446. $this->zip->close();
  1447. $fileanddir = $this->deepScanDir($extPathdir);
  1448. sort($fileanddir['file2']);
  1449. $sum = 0;
  1450. foreach($fileanddir['file2'] as $k =>$v){
  1451. $sum++;
  1452. $signatt = new signn();
  1453. $path = 'signs/'.$signid.'/' . $v . '.jpg';
  1454. @chmod(Doo::conf()->SITE_PATH.$path,0777);
  1455. $signatt->insertSignAtt($signid,$v,$path);
  1456. $this->compressed_image(Doo::conf()->SITE_PATH.$path,Doo::conf()->SITE_PATH.$path);
  1457. }
  1458. $sign2 = new signn();
  1459. $sign2->updateSignPageNum($signid,$sum);
  1460. $upspdfname = pathinfo($_FILES['upspdf']['name']);
  1461. if($upspdfname['extension'] != 'pdf'){
  1462. $status = array('status' => 'FALSE', 'msg' => '上传的文件格式有误');
  1463. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1464. die();
  1465. }
  1466. //上传pdf文件
  1467. if(!empty($_FILES["upspdf"]['name'])){
  1468. $pdf_name = $intime.'.pdf';
  1469. $upload_pdf = $extPathdir.'/'.$pdf_name;
  1470. $k = move_uploaded_file($_FILES["upspdf"]["tmp_name"], $upload_pdf);
  1471. if($k){
  1472. $status = array('status' => 'TRUE');
  1473. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1474. die();
  1475. }
  1476. }
  1477. }
  1478. }
  1479. $status = array('status' => 'FALSE', 'msg' => '文件上传失败,请重试');
  1480. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1481. die();
  1482. } else {
  1483. $status = array('status' => 'FALSE', 'msg' => '上传参数错误');
  1484. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1485. die();
  1486. }
  1487. }
  1488. public function getSignList(){
  1489. $wheresql = ' 1';
  1490. if(isset($_POST['project']) && is_numeric($_POST['project'])){
  1491. $wheresql .= ' and project='.$_POST['project'];
  1492. }
  1493. if(isset($_POST['tender']) && is_numeric($_POST['tender'])) {
  1494. $wheresql .= ' and tender='.$_POST['tender'];
  1495. }
  1496. if(isset($_POST['phaseno']) && is_numeric($_POST['phaseno'])){
  1497. $wheresql .= ' and phaseno='.$_POST['phaseno'];
  1498. }
  1499. $signlist = $this->sign->getSignListbyClient($wheresql);
  1500. if(!empty($signlist)){
  1501. // foreach($signlist as $k => $v){
  1502. // $signlist[$k]['pdfpath'] = 'signs/'.$v['sid'].'/'.$v['intime'].'.pdf';
  1503. // }
  1504. echo json_encode(array('status' => TRUE, 'msg' => '', 'info' => $signlist), JSON_UNESCAPED_UNICODE);
  1505. die();
  1506. }else{
  1507. $status = array('status' => TRUE, 'msg' => '当前没有签署报表','info' => '');
  1508. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1509. die();
  1510. }
  1511. }
  1512. // public function testzip(){
  1513. // $this->render('testzip', $this->data);
  1514. // }
  1515. function deepScanDir($dir) {
  1516. $fileArr = array ();
  1517. $fileArr2 = array ();
  1518. $dirArr = array ();
  1519. $dir = rtrim($dir, '//');
  1520. if (is_dir($dir)) {
  1521. $dirHandle = opendir($dir);
  1522. while (false !== ($fileName = readdir($dirHandle))) {
  1523. $subFile = $dir . DIRECTORY_SEPARATOR . $fileName;
  1524. if (is_file($subFile)) {
  1525. $fileArr[] = $subFile;
  1526. $fileArr2[] = basename($subFile,'.jpg');
  1527. }
  1528. elseif (is_dir($subFile) && str_replace('.', '', $fileName) != '') {
  1529. $dirArr[] = $subFile;
  1530. $arr = $this->deepScanDir($subFile);
  1531. $dirArr = array_merge($dirArr, $arr['dir']);
  1532. $fileArr = array_merge($fileArr, $arr['file']);
  1533. $fileArr2 = array_merge($fileArr2, $arr['file2']);
  1534. }
  1535. }
  1536. closedir($dirHandle);
  1537. }
  1538. return array (
  1539. 'dir' => $dirArr,
  1540. 'file' => $fileArr,
  1541. 'file2' => $fileArr2
  1542. );
  1543. }
  1544. /**
  1545. * desription 判断是否gif动画
  1546. * @param sting $image_file图片路径
  1547. * @return boolean t 是 f 否
  1548. */
  1549. function check_gifcartoon($image_file){
  1550. $fp = fopen($image_file,'rb');
  1551. $image_head = fread($fp,1024);
  1552. fclose($fp);
  1553. return preg_match("/".chr(0x21).chr(0xff).chr(0x0b).'NETSCAPE2.0'."/",$image_head)?false:true;
  1554. }
  1555. /**
  1556. * desription 压缩图片
  1557. * @param sting $imgsrc 图片路径
  1558. * @param string $imgdst 压缩后保存路径
  1559. */
  1560. function compressed_image($imgsrc,$imgdst){
  1561. list($width,$height,$type)=getimagesize($imgsrc);
  1562. $new_width = $width;
  1563. $new_height = $height;
  1564. switch($type){
  1565. case 1:
  1566. $giftype=$this->check_gifcartoon($imgsrc);
  1567. if($giftype){
  1568. // header('Content-Type:image/gif');
  1569. $image_wp=imagecreatetruecolor($new_width, $new_height);
  1570. $image = imagecreatefromgif($imgsrc);
  1571. imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  1572. //75代表的是质量、压缩图片容量大小
  1573. imagejpeg($image_wp, $imgdst,100);
  1574. imagedestroy($image_wp);
  1575. }
  1576. break;
  1577. case 2:
  1578. // header('Content-Type:image/jpeg');
  1579. $image_wp=imagecreatetruecolor($new_width, $new_height);
  1580. $image = imagecreatefromjpeg($imgsrc);
  1581. imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  1582. //75代表的是质量、压缩图片容量大小
  1583. imagejpeg($image_wp, $imgdst,100);
  1584. imagedestroy($image_wp);
  1585. break;
  1586. case 3:
  1587. // header('Content-Type:image/png');
  1588. $image_wp=imagecreatetruecolor($new_width, $new_height);
  1589. $image = imagecreatefrompng($imgsrc);
  1590. imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  1591. //75代表的是质量、压缩图片容量大小
  1592. imagejpeg($image_wp, $imgdst,100);
  1593. imagedestroy($image_wp);
  1594. break;
  1595. case 6:
  1596. // header('Content-Type:image/x-ms-bmp');
  1597. $image_wp=imagecreatetruecolor($new_width, $new_height);
  1598. $image = $this->imagecreatefrombmp($imgsrc);
  1599. imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  1600. //75代表的是质量、压缩图片容量大小
  1601. imagejpeg($image_wp, $imgdst,100);
  1602. imagedestroy($image_wp);
  1603. break;
  1604. }
  1605. }
  1606. //bmp 转jpg
  1607. function imagecreatefrombmp( $filename ){
  1608. if ( !$f1 = fopen( $filename, "rb" ) )
  1609. return FALSE;
  1610. $FILE = unpack( "vfile_type/Vfile_size/Vreserved/Vbitmap_offset", fread( $f1, 14 ) );
  1611. if ( $FILE['file_type'] != 19778 )
  1612. return FALSE;
  1613. $BMP = unpack( 'Vheader_size/Vwidth/Vheight/vplanes/vbits_per_pixel' . '/Vcompression/Vsize_bitmap/Vhoriz_resolution' . '/Vvert_resolution/Vcolors_used/Vcolors_important', fread( $f1, 40 ) );
  1614. $BMP['colors'] = pow( 2, $BMP['bits_per_pixel'] );
  1615. if ( $BMP['size_bitmap'] == 0 )
  1616. $BMP['size_bitmap'] = $FILE['file_size'] - $FILE['bitmap_offset'];
  1617. $BMP['bytes_per_pixel'] = $BMP['bits_per_pixel'] / 8;
  1618. $BMP['bytes_per_pixel2'] = ceil( $BMP['bytes_per_pixel'] );
  1619. $BMP['decal'] = ($BMP['width'] * $BMP['bytes_per_pixel'] / 4);
  1620. $BMP['decal'] -= floor( $BMP['width'] * $BMP['bytes_per_pixel'] / 4 );
  1621. $BMP['decal'] = 4 - (4 * $BMP['decal']);
  1622. if ( $BMP['decal'] == 4 )
  1623. $BMP['decal'] = 0;
  1624. $PALETTE = array();
  1625. if ( $BMP['colors'] < 16777216 ){
  1626. $PALETTE = unpack( 'V' . $BMP['colors'], fread( $f1, $BMP['colors'] * 4 ) );
  1627. }
  1628. $IMG = fread( $f1, $BMP['size_bitmap'] );
  1629. $VIDE = chr( 0 );
  1630. $res = imagecreatetruecolor( $BMP['width'], $BMP['height'] );
  1631. $P = 0;
  1632. $Y = $BMP['height'] - 1;
  1633. while( $Y >= 0 ){
  1634. $X = 0;
  1635. while( $X < $BMP['width'] ){
  1636. if ( $BMP['bits_per_pixel'] == 32 ){
  1637. $COLOR = unpack( "V", substr( $IMG, $P, 4 ) );
  1638. $B = ord(substr($IMG, $P,1));
  1639. $G = ord(substr($IMG, $P+1,1));
  1640. $R = ord(substr($IMG, $P+2,1));
  1641. $color = imagecolorexact( $res, $R, $G, $B );
  1642. if ( $color == -1 )
  1643. $color = imagecolorallocate( $res, $R, $G, $B );
  1644. $COLOR[0] = $R*256*256+$G*256+$B;
  1645. $COLOR[1] = $color;
  1646. }elseif ( $BMP['bits_per_pixel'] == 24 )
  1647. $COLOR = unpack( "V", substr( $IMG, $P, 3 ) . $VIDE );
  1648. elseif ( $BMP['bits_per_pixel'] == 16 ){
  1649. $COLOR = unpack( "n", substr( $IMG, $P, 2 ) );
  1650. $COLOR[1] = $PALETTE[$COLOR[1] + 1];
  1651. }elseif ( $BMP['bits_per_pixel'] == 8 ){
  1652. $COLOR = unpack( "n", $VIDE . substr( $IMG, $P, 1 ) );
  1653. $COLOR[1] = $PALETTE[$COLOR[1] + 1];
  1654. }elseif ( $BMP['bits_per_pixel'] == 4 ){
  1655. $COLOR = unpack( "n", $VIDE . substr( $IMG, floor( $P ), 1 ) );
  1656. if ( ($P * 2) % 2 == 0 )
  1657. $COLOR[1] = ($COLOR[1] >> 4);
  1658. else
  1659. $COLOR[1] = ($COLOR[1] & 0x0F);
  1660. $COLOR[1] = $PALETTE[$COLOR[1] + 1];
  1661. }elseif ( $BMP['bits_per_pixel'] == 1 ){
  1662. $COLOR = unpack( "n", $VIDE . substr( $IMG, floor( $P ), 1 ) );
  1663. if ( ($P * 8) % 8 == 0 )
  1664. $COLOR[1] = $COLOR[1] >> 7;
  1665. elseif ( ($P * 8) % 8 == 1 )
  1666. $COLOR[1] = ($COLOR[1] & 0x40) >> 6;
  1667. elseif ( ($P * 8) % 8 == 2 )
  1668. $COLOR[1] = ($COLOR[1] & 0x20) >> 5;
  1669. elseif ( ($P * 8) % 8 == 3 )
  1670. $COLOR[1] = ($COLOR[1] & 0x10) >> 4;
  1671. elseif ( ($P * 8) % 8 == 4 )
  1672. $COLOR[1] = ($COLOR[1] & 0x8) >> 3;
  1673. elseif ( ($P * 8) % 8 == 5 )
  1674. $COLOR[1] = ($COLOR[1] & 0x4) >> 2;
  1675. elseif ( ($P * 8) % 8 == 6 )
  1676. $COLOR[1] = ($COLOR[1] & 0x2) >> 1;
  1677. elseif ( ($P * 8) % 8 == 7 )
  1678. $COLOR[1] = ($COLOR[1] & 0x1);
  1679. $COLOR[1] = $PALETTE[$COLOR[1] + 1];
  1680. }else
  1681. return FALSE;
  1682. imagesetpixel( $res, $X, $Y, $COLOR[1] );
  1683. $X++;
  1684. $P += $BMP['bytes_per_pixel'];
  1685. }
  1686. $Y--;
  1687. $P += $BMP['decal'];
  1688. }
  1689. fclose( $f1 );
  1690. return $res;
  1691. }
  1692. }
  1693. ?>