ChangeController.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  1. <?php
  2. //ini_set('display_errors', on);
  3. Doo::loadClass('auth');
  4. Doo::loadClass('attfile');
  5. Doo::loadClass('profile');
  6. Doo::loadClass('project');
  7. Doo::loadClass('contractact');
  8. Doo::loadClass('actmeasure');
  9. Doo::loadClass('numofperact');
  10. Doo::loadClass('measureauditact');
  11. Doo::loadClass('sign');
  12. Doo::loadClass('sms');
  13. Doo::loadClass('change');
  14. Doo::loadModelAt('aconfig', 'admin');
  15. Doo::loadClass('Hashids/Hashids');
  16. /* * proDetail
  17. * MainController
  18. * Feel free to delete the methods and replace them with your own code.
  19. *
  20. * @author darkredz
  21. */
  22. class ChangeController extends DooController
  23. {
  24. private $aconfig, $data, $sms, $sign, $change, $auth, $attfile, $profile, $project, $contractact, $actmeasure, $measureauditact, $numofperact, $__hashids, $statusArray = array('uncheck' => '<span class = "colGray">未审批</span>', 'checking' => '<span class = "colOrange">审批中</span>', 'checked' => '<span class = "colGreen">审批通过</span>', 'checkno' => '<span class = "colRed">审批不通过</span>');
  25. private $changeType = array('1' => 'A.位置', '2' => 'B.数量', '3' => 'C.结构', '4' => 'D.新增', '5' => 'E.取消', '6' => 'F.纠错');
  26. private $changeCategory = array('1' => 'A类变更(设计变更)', '2' => 'B类变更(施工措施变更)', '3' => 'C类变更(计划变更)', '4' => 'D类变更(条件变更)', '5' => 'E类变更(新增工程)');
  27. private $changeNature = array('1' => '一般设计变更', '2' => '较大设计变更', '3' => '重大设计变更');
  28. private $changeStatus = array('2' => 'uncheck', '3' => 'checking', '4' => 'checked', '5' => 'checkno');
  29. private $changeUnit = array('m','km','m2','m3','kg','t','m3·km','总额','月','项','处','个','根','棵','块','每一试桩','桥长米','公路公里','株','组','座','元','工日','套','台班','艘班','m/处','m/道','m/座','m2/m','m3/m','m3/处','根/米','亩','m3/m2');
  30. public function beforeRun($resource, $action)
  31. {
  32. if ($this->auth->getUid()) {
  33. $uGroups = $this->profile->getProWithUid($this->auth->getUid());
  34. $falg = Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  35. if (!$falg)
  36. return Doo::acl()->defaultFailedRoute;
  37. } else {
  38. return Doo::acl()->defaultFailedRoute;
  39. }
  40. }
  41. public function __construct()
  42. {
  43. $this->aconfig = new AConfig();
  44. $this->auth = new Auth();
  45. $this->attfile = new attFile();
  46. $this->profile = new Profile();
  47. $this->project = new Project();
  48. $this->contractact = new Contractact();
  49. $this->actmeasure = new actMeasure();
  50. $this->numofperact = new NumofperAct();
  51. $this->measureauditact = new MeasureauditAct();
  52. $this->sign = new Signn();
  53. $this->change = new Changes();
  54. $this->sms = new Sms(Doo::conf()->SMS_URL, Doo::conf()->SMS_ACCOUNT, DOO::conf()->SMS_PASSWORD, DOO::conf()->SMS_EXTNO);
  55. $this->__hashids = new Hashids\Hashids('jlzffileid', 8);
  56. $this->data['rootUrl'] = Doo::conf()->APP_URL;
  57. $this->data['currChannle'] = 'change';
  58. $this->data['user'] = $this->profile->getProWithUid($this->auth->getUid());
  59. $mpidArray = $this->measureauditact->getAuditProject2($this->auth->getUid());
  60. $this->data['numofchecking'] = 0;
  61. if (isset($mpidArray[0]['pid'])) {
  62. foreach ($mpidArray as $key => $value) {
  63. // 审批操作按照时间排序多标段
  64. $this->data['numofchecking'] += $this->measureauditact->getCountMyChecking($value['pid'], $this->auth->getUid());
  65. }
  66. }
  67. if (!isset($this->data['numofchecking']) || $this->data['numofchecking'] == 0) {
  68. $this->data['numofchecking'] = null;
  69. }
  70. $this->data['signSwitch'] = $this->aconfig->getOne(array('select' => 'signswitch', 'asArray' => TRUE))['signswitch'];
  71. //获取需要您签署的数目
  72. if($this->data['signSwitch'] > 0)
  73. $this->data['needSignNum'] = $this->sign->getNeedSignNumbyUid($this->auth->getUid()) != 0 ? $this->sign->getNeedSignNumbyUid($this->auth->getUid()) : '';
  74. //获取桌面版本
  75. $this->getsoftware();
  76. //草图入口
  77. $this->data['imediateSwitch'] = $this->aconfig->getOne(array('select' => 'imediateswitch', 'asArray' => TRUE))['imediateswitch'];
  78. //获取需要你审批的变更令数目
  79. $this->data['needChangeNum'] = $this->change->getNeedChangeNumbyUid($this->auth->getUid()) != 0 ? $this->change->getNeedChangeNumbyUid($this->auth->getUid()) : '';
  80. }
  81. function getsoftware(){
  82. $StrJson = ($this->aconfig->getOne(array('select' => 'upgradeinfo', 'asArray' => TRUE))['upgradeinfo']);
  83. $upgradeinfo = json_decode($StrJson, true);
  84. if ($upgradeinfo) {
  85. $this->data['version'] = $upgradeinfo['version'];
  86. $this->data['download'] = $upgradeinfo['download'];
  87. }
  88. }
  89. /**
  90. *
  91. * @return type
  92. */
  93. public function index()
  94. {
  95. //获取 项目-标段类型-标段 的树结构, 包含个人对应的原报,审批和变更令审批人专属树结构
  96. $sectionlist = array();
  97. $hashArray = array();
  98. //先取原报人标段
  99. $mpidArray = $this->actmeasure->getRowUser($this->auth->getUid());
  100. if(!empty($mpidArray)){
  101. foreach($mpidArray as $k => $v){
  102. $sectionlist[] = array('pid' => $v['pid'], 'stid' => $v['stid'], 'pmid' => $v['pmid']);
  103. $hashArray[] = md5($v['pmid']);
  104. }
  105. }
  106. //再取审批表标段
  107. // $mpidArray2 = $this->measureauditact->getPmidGroup($this->auth->getUid());
  108. // if(!empty($mpidArray2)){
  109. // foreach($mpidArray2 as $k2 => $v2){
  110. // $hashstr = md5($v2['pmid']);
  111. // if(!in_array($hashstr,$hashArray)){
  112. // $sectionlist[] = array('pid' => $v2['pid'], 'stid' => $v2['stid'], 'pmid' => $v2['pmid']);
  113. // $hashArray[] = md5($v2['pmid']);
  114. // }
  115. // }
  116. // }
  117. //最后取变更令审批人所属的标段
  118. $mpidArray3 = $this->change->getPmidGroup($this->auth->getUid());
  119. if(!empty($mpidArray3)){
  120. foreach($mpidArray3 as $k3 => $v3){
  121. $hashstr = md5($v3['pmid']);
  122. if(!in_array($hashstr,$hashArray)){
  123. $sectionlist[] = array('pid' => $v3['pid'], 'stid' => $v3['stid'], 'pmid' => $v3['pmid']);
  124. $hashArray[] = md5($v3['pmid']);
  125. }
  126. }
  127. }
  128. //算法 ---> 把一个二维数组按内容转换成一个三维数组
  129. $prolist = array();
  130. if(!empty($sectionlist)){
  131. $newlist = array();
  132. $i = 0;
  133. foreach($sectionlist as $key => $value){
  134. $j = 0;
  135. $newkey = $value['pid'];
  136. $newst = $value['stid'];
  137. $newpm = $value['pmid'];
  138. if(!isset($newlist[$newkey])){
  139. $newlist[$newkey]['i'] = $i;
  140. $prolist[$i]['open'] = 0;
  141. $prolist[$i]['pid'] = $newkey;
  142. $prolist[$i]['pname'] = $this->project->getRowByPid($newkey)['pname'];
  143. $prolist[$i]['stlist'] = array();
  144. $newlist[$newkey]['st'][$newst]['j'] = $j;
  145. $newlist[$newkey]['stnum'] = $j;
  146. $prolist[$i]['stlist'][$j]['open'] = 0;
  147. $prolist[$i]['stlist'][$j]['stid'] = $newst;
  148. $prolist[$i]['stlist'][$j]['stname'] = $this->contractact->getRowByStid($newst)['stname'];
  149. $prolist[$i]['stlist'][$j]['pmlist'] = array();
  150. array_push($prolist[$i]['stlist'][$j]['pmlist'],array('open' => 0, 'pmid' => $newpm, 'pmname' => $this->actmeasure->getRowByPmid($newpm)['pmname']));
  151. $i++;
  152. }else{
  153. $i2 = $newlist[$newkey]['i'];
  154. if(!isset($newlist[$newkey]['st'][$newst])){
  155. $newlist[$newkey]['st'][$newst]['j'] = $newlist[$newkey]['stnum']+1;
  156. $j = $newlist[$newkey]['st'][$newst]['j'];
  157. $newlist[$newkey]['stnum']++;
  158. $prolist[$i2]['stlist'][$j]['stid'] = $newst;
  159. $prolist[$i2]['stlist'][$j]['stname'] = $this->contractact->getRowByStid($newst)['stname'];
  160. $prolist[$i2]['stlist'][$j]['pmlist'] = array();
  161. array_push($prolist[$i2]['stlist'][$j]['pmlist'],array('open' => 0, 'pmid' => $newpm, 'pmname' => $this->actmeasure->getRowByPmid($newpm)['pmname']));
  162. }else{
  163. $j2 = $newlist[$newkey]['st'][$newst]['j'];
  164. array_push($prolist[$i2]['stlist'][$j2]['pmlist'],array('open' => 0, 'pmid' => $newpm, 'pmname' => $this->actmeasure->getRowByPmid($newpm)['pmname']));
  165. }
  166. }
  167. }
  168. }
  169. //获取需要您审批的签署表cid,pid,stid,pmid信息,并open所有需要审批的节点
  170. $cListmsg = $this->change->getNeedChangeNumbyUid($this->auth->getUid()) != 0 ? $this->change->getNeedChangeAllList($this->auth->getUid()) : '';
  171. $pidArray = $stidArray = $pmidArray = array();
  172. if(!empty($cListmsg)){
  173. foreach($cListmsg as $clk => $clv){
  174. array_push($pidArray,$clv['pid']);
  175. array_push($stidArray,$clv['stid']);
  176. array_push($pmidArray,$clv['pmid']);
  177. }
  178. }
  179. $pmid = isset($this->params['pmid']) ? $this->params['pmid'] : $prolist[0]['stlist'][0]['pmlist'][0]['pmid'];
  180. $pmArray = $this->actmeasure->getRowByPmid($pmid);
  181. if(!empty($pmArray)){
  182. foreach($prolist as $pk => $pv){
  183. if($pmArray['pid'] == $pv['pid'] || in_array($pv['pid'], $pidArray)){
  184. $prolist[$pk]['open'] = $pmArray['pid'] == $pv['pid'] ? 1 : 2;
  185. foreach($prolist[$pk]['stlist'] as $sk => $sv){
  186. if($pmArray['stid'] == $sv['stid'] || in_array($sv['stid'], $stidArray)){
  187. $prolist[$pk]['stlist'][$sk]['open'] = $pmArray['stid'] == $sv['stid'] ? 1 : 2;
  188. foreach($prolist[$pk]['stlist'][$sk]['pmlist'] as $mk => $mv){
  189. if($pmArray['pmid'] == $mv['pmid'] || in_array($mv['pmid'], $pmidArray)){
  190. $prolist[$pk]['stlist'][$sk]['pmlist'][$mk]['open'] = $pmArray['pmid'] == $mv['pmid'] ? 1 : 2;
  191. // break;
  192. }
  193. }
  194. // break;
  195. }
  196. }
  197. // break;
  198. }
  199. }
  200. }
  201. //只有原报人才可以创建变更令和上报变更令
  202. $this->data['userchangepower'] = $this->auth->getUid() == $pmArray['uid'] ? 1 : 0;
  203. $changelist = $this->change->getChangeListbyPmid($pmid);
  204. $this->data['firstuse'] = empty($changelist) ? 1 : 0;
  205. $status = (isset($this->params['status']) && is_numeric($this->params['status']) && $this->params['status'] != 2) || ($this->params['status'] == 2 && $this->auth->getUid() == $pmArray['uid']) ? $this->params['status'] : 1;
  206. $this->data['status'] = $status;
  207. $this->data['pmArray'] = $pmArray;
  208. $this->data['prolist'] = $prolist;
  209. $this->data['num1'] = $this->change->getNumbyMydetail($pmid,$this->auth->getUid());
  210. $this->data['num2'] = $this->change->getNumbystatus($pmid,'uncheck','back');
  211. $this->data['num3'] = $this->change->getNumbystatus($pmid,'checking');
  212. $this->data['num4'] = $this->change->getNumbystatus($pmid,'checked');
  213. $this->data['num5'] = $this->change->getNumbystatus($pmid,'checkno');
  214. //获取列表内容
  215. Doo::loadHelper('DooPager');
  216. $pagestr = '/'.$pmid.'/'.$status;
  217. $totalArchive = $status != 1 ? $this->change->getNumbystatus($pmid,$this->changeStatus[$status]) : $this->change->getNumbyMydetail($pmid,$this->auth->getUid());
  218. $pager = new DooPager(Doo::conf()->APP_URL . 'change/index'.$pagestr.'/page', $totalArchive, 10, 100);
  219. $pager->setCss('', 'disabled', 'active');
  220. if (isset($this->params['pindex']))
  221. $pager->paginate(intval($this->params['pindex']));
  222. else
  223. $pager->paginate(1);
  224. if ($pager->limit != ' -10,10')
  225. $list = $status != 1 ? ($status ==2 ? $this->change->getListbyStatus($pmid,$this->changeStatus[$status], $pager->limit,'back') : $this->change->getListbyStatus($pmid,$this->changeStatus[$status], $pager->limit)) : $this->change->getListbyMydetail($pmid,$this->auth->getUid(), $pager->limit);
  226. if(isset($list) && !empty($list)){
  227. foreach($list as $lk => $lv){
  228. if($status == 3){
  229. $checkman = $this->change->getOneAuditbystatus($lv['cid'],'checking');
  230. $list[$lk]['checkman'] = $checkman['name'];
  231. // $list[$lk]['checkstatus'] = $this->statusArray[$checkman['status']];
  232. }
  233. $list[$lk]['username'] = $this->auth->getRowByUid($lv['uid'])['name'];
  234. $list[$lk]['changeCategory'] = $this->changeCategory[$lv['category']];
  235. }
  236. }
  237. //uid
  238. $this->data['uid'] = $this->auth->getUid();
  239. $this->data['list'] = isset($list) ? $list : '';
  240. $this->data['pager'] = $pager->output;
  241. $this->render('biangeng-poj', $this->data, TRUE);
  242. }
  243. //签约清单
  244. public function dealBills(){
  245. if(isset($this->params['pmid']) && is_numeric($this->params['pmid'])){
  246. $pmid = $this->params['pmid'];
  247. $pmArray = $this->actmeasure->getRowByPmid($pmid);
  248. if(empty($pmArray)){
  249. exit('不存在此标段');
  250. }
  251. $this->data['pmArray'] = $pmArray;
  252. $list = $this->change->getChangeListbyPmid($pmid);
  253. if(!empty($list)){
  254. foreach($list as $k => $v){
  255. $totalamount = floatval($v['unitprice'])*floatval($v['amount']);
  256. $list[$k]['totalamount'] = $totalamount;
  257. }
  258. }
  259. $this->data['list'] = $list;
  260. $this->render('biangeng-dealbills', $this->data, TRUE);
  261. }else{
  262. exit('不存在此标段');
  263. }
  264. }
  265. public function changeDetail(){
  266. //获取变更令信息
  267. if(isset($this->params['cid']) && is_numeric($this->params['cid'])) {
  268. $cid = $this->params['cid'];
  269. $changeArray = $this->change->getChangebyid($cid);
  270. if(!empty($changeArray)){
  271. $pmArray = $this->actmeasure->getRowByPmid($changeArray['pmid']);
  272. if(empty($pmArray)){
  273. exit('不存在此标段');
  274. }
  275. $this->data['pmArray'] = $pmArray;
  276. $ctypelist = array();
  277. if(!empty($changeArray['ctype'])){
  278. $ctype = explode(',',$changeArray['ctype']);
  279. foreach($ctype as $tk => $tv){
  280. $ctypelist[$tk]['typename'] = $this->changeType[$tv];
  281. }
  282. }
  283. $changeArray['ctypelist'] = $ctypelist;
  284. $changeArray['categoryname'] = $this->changeCategory[$changeArray['category']];
  285. $changeArray['naturename'] = $this->changeNature[$changeArray['cnature']];
  286. $changeArray['companyname'] = $this->change->getCompanybyid($changeArray['companyid'])['name'];
  287. $this->data['changeArray'] = $changeArray;
  288. //获取清单,按清单编号排序
  289. $clist = $this->change->getChangeAuditListbycid($cid);
  290. $ototalnum = 0;
  291. $ctotalnum = 0;
  292. $stotalnum = 0;
  293. if(!empty($clist)){
  294. foreach($clist as $ck => $cv){
  295. $osum = floatval($cv['unitprice'])*floatval($cv['oamount']);
  296. $clist[$ck]['osum'] = $osum;
  297. $ototalnum += $osum;
  298. $csum = floatval($cv['unitprice'])*floatval($cv['camount']);
  299. $clist[$ck]['csum'] = $csum;
  300. $ctotalnum += $csum;
  301. if($cv['samount'] != ''){
  302. $ssum = floatval($cv['unitprice'])*floatval($cv['samount']);
  303. $clist[$ck]['ssum'] = $ssum;
  304. $stotalnum += $ssum;
  305. }else{
  306. $clist[$ck]['ssum'] = '';
  307. $clist[$ck]['samount'] = '';
  308. }
  309. }
  310. }
  311. include (DOO::conf()->SITE_PATH . 'protected/plugin/TemplateTag.php');
  312. $this->data['ototalnum'] = tofloat($ototalnum);
  313. $this->data['ctotalnum'] = tofloat($ctotalnum);
  314. $this->data['stotalnum'] = $stotalnum != 0 ? tofloat($stotalnum) : '';
  315. $this->data['clist'] = $clist;
  316. //获取附件
  317. $attlist = $this->change->getChangeAttListbycid($cid);
  318. $showattlist = array();
  319. if(!empty($attlist)){
  320. foreach($attlist as $k => $v){
  321. //加密下载的id
  322. $fid = $this->__hashids->encode($v['id']);
  323. $showattlist[$k]['sort'] = $k+1;
  324. $showattlist[$k]['downurl'] = '/change/file/download/'.$fid;
  325. $showattlist[$k]['filename'] = $v['filename'].'.'.$v['fileext'];
  326. $showattlist[$k]['time'] = date('Y-m-d H:i',$v['intime']);
  327. $showattlist[$k]['size'] = $this->changefilesize($v['filesize']);
  328. }
  329. }
  330. $this->data['attlist'] = $showattlist;
  331. //获取审批流程列表
  332. $auditlist = $this->change->getChangeAuditsbySort($cid);
  333. $this->data['auditlist'] = $auditlist;
  334. $this->render('biangeng-detail', $this->data, TRUE);
  335. }
  336. }
  337. exit('参数有误');
  338. }
  339. public function changeNew(){
  340. if(isset($this->params['pmid']) && is_numeric($this->params['pmid'])){
  341. $pmid = $this->params['pmid'];
  342. $pmArray = $this->actmeasure->getRowByPmid($pmid);
  343. if(empty($pmArray)){
  344. exit('不存在此标段');
  345. }
  346. if($this->auth->getUid() != $pmArray['uid']){
  347. exit('不是原报人无法创建变更令');
  348. }
  349. //表单提交
  350. if(isset($_POST['pnum'])){
  351. if(isset($_POST['checking'])){
  352. if(empty($_POST['pnum']) || !isset($_POST['pname']) || empty($_POST['pname']) || !isset($_POST['mnum']) || empty($_POST['mnum']) || !isset($_POST['description']) || empty($_POST['description']) || !isset($_POST['changeaudit']) || empty($_POST['changeaudit']) || !isset($_POST['changelist']) || !isset($_POST['changewhitelist'])){
  353. exit('参数缺失或为空');
  354. }
  355. if(empty($_POST['changelist']) && empty($_POST['changewhitelist'])){
  356. exit('变更清单缺失');
  357. }
  358. }elseif(isset($_POST['uncheck'])){
  359. if(empty($_POST['pnum']) || !isset($_POST['pname']) || empty($_POST['pname'])){
  360. exit('参数缺失或为空');
  361. }
  362. }
  363. //先添加生成变更令
  364. $cid = $this->change->insertChangeMsg($pmArray,$this->auth->getUid(),$_POST);
  365. if($cid){
  366. //附件添加cid
  367. if(!empty($_POST['changeatt'])){
  368. Doo::loadModel('changeatt');
  369. $attlist = explode(',', $_POST['changeatt']);
  370. foreach($attlist as $ak => $av){
  371. $changeAtt = new ChangeAtt();
  372. $changeAtt->id = $av;
  373. $changeAtt->cid = $cid;
  374. $changeAtt->update();
  375. }
  376. }
  377. //审批人添加
  378. //先添加提交人到audit中
  379. $site = 0;
  380. Doo::loadModel('changeaudit');
  381. $changeaudit2 = new ChangeAudit();
  382. $userArray2 = $this->auth->getRowByUid($this->auth->getUid());
  383. $changeaudit2->pid = $pmArray['pid'];
  384. $changeaudit2->stid = $pmArray['stid'];
  385. $changeaudit2->pmid = $pmArray['pmid'];
  386. $changeaudit2->cid = $cid;
  387. $changeaudit2->times = 0;
  388. $changeaudit2->usite = $site;
  389. $changeaudit2->usort = $site;
  390. $changeaudit2->uid = $this->auth->getUid();
  391. $changeaudit2->company = $userArray2['company'];
  392. $changeaudit2->jobs = $userArray2['jobs'];
  393. $changeaudit2->name = $userArray2['name'];
  394. $changeaudit2->status = isset($_POST['checking']) ? 'checked' : 'checking';
  395. $changeaudit2->sintime = isset($_POST['checking']) ? time() : '';
  396. $changeaudit2->insert();
  397. $site++;
  398. $auditArr = array();
  399. if(!empty($_POST['changeaudit'])){
  400. $auditlist = explode(',', $_POST['changeaudit']);
  401. foreach($auditlist as $uk => $uv){
  402. $userArray = $this->auth->getRowByUid($uv);
  403. $changeaudit = new ChangeAudit();
  404. $changeaudit->pid = $pmArray['pid'];
  405. $changeaudit->stid = $pmArray['stid'];
  406. $changeaudit->pmid = $pmArray['pmid'];
  407. $changeaudit->cid = $cid;
  408. $changeaudit->times = 0;
  409. $changeaudit->usite = $site;
  410. $changeaudit->usort = $site;
  411. $changeaudit->uid = $uv;
  412. $changeaudit->company = $userArray['company'];
  413. $changeaudit->jobs = $userArray['jobs'];
  414. $changeaudit->name = $userArray['name'];
  415. $changeaudit->status = (isset($_POST['checking']) && $uk == 0) ? 'checking' : 'uncheck';
  416. $changeaudit->insert();
  417. $site++;
  418. array_push($auditArr,array('uid' => $uv, 'ucamount' => ''));
  419. }
  420. }
  421. //清单添加,不分顺序,最终展示按清单编号排序
  422. Doo::loadModel('changeauditlist');
  423. $total = 0;
  424. if(!empty($_POST['changelist'])){
  425. $clist = explode(',',$_POST['changelist']);
  426. foreach($clist as $ck => $cv){
  427. $clistarr = explode('_',$cv);
  428. if(!empty($clistarr[1]) && is_numeric($clistarr[1])){
  429. $changelistArr = $this->change->getChangeListbyid($clistarr[0]);
  430. $total += floatval($changelistArr['unitprice'])*floatval($clistarr[1]);
  431. $cauditlist = new ChangeAuditList();
  432. $cauditlist->pid = $pmArray['pid'];
  433. $cauditlist->stid = $pmArray['stid'];
  434. $cauditlist->pmid = $pmArray['pmid'];
  435. $cauditlist->cid = $cid;
  436. $cauditlist->lid = $clistarr[0];
  437. $cauditlist->lnum = $changelistArr['lnum'];
  438. $cauditlist->lname = $changelistArr['lname'];
  439. $cauditlist->unit = $changelistArr['unit'];
  440. $cauditlist->unitprice = $changelistArr['unitprice'];
  441. $cauditlist->oamount = $changelistArr['amount'];
  442. $cauditlist->camount = $clistarr[1];
  443. $cauditlist->auditjson = json_encode($auditArr);
  444. $cauditlist->insert();
  445. }
  446. }
  447. }
  448. if(!empty($_POST['changewhitelist'])){
  449. $wlist = explode(',',$_POST['changewhitelist']);
  450. foreach($wlist as $wk => $wv){
  451. $wlistarr = explode(';',explode('->',$wv)[1]);
  452. if(!empty($wlistarr[0]) && !empty($wlistarr[1]) && !empty($wlistarr[3]) && !empty($wlistarr[4]) && !empty($wlistarr[5]) && is_numeric($wlistarr[3]) && is_numeric($wlistarr[4]) && is_numeric($wlistarr[5])){
  453. $total += floatval($wlistarr[3])*floatval($wlistarr[5]);
  454. $cauditlist = new ChangeAuditList();
  455. $cauditlist->pid = $pmArray['pid'];
  456. $cauditlist->stid = $pmArray['stid'];
  457. $cauditlist->pmid = $pmArray['pmid'];
  458. $cauditlist->cid = $cid;
  459. $cauditlist->lid = 0;
  460. $cauditlist->lnum = $wlistarr[0];
  461. $cauditlist->lname = $wlistarr[1];
  462. $cauditlist->unit = $wlistarr[2];
  463. $cauditlist->unitprice = $wlistarr[3];
  464. $cauditlist->oamount = $wlistarr[4];
  465. $cauditlist->camount = $wlistarr[5];
  466. $cauditlist->auditjson = json_encode($auditArr);
  467. $cauditlist->insert();
  468. }
  469. }
  470. }
  471. //变更令添加变更总金额
  472. $this->change->updateChangeTotalamount($cid,$total);
  473. $status = isset($_POST['uncheck']) ? 2 : 3;
  474. return '/change/index/'.$pmArray['pmid'].'/'.$status;
  475. }else{
  476. exit('添加到变更令失败');
  477. }
  478. }
  479. $this->data['companylist'] = $this->change->getCompanyList();
  480. $list = $this->change->getChangeListbyPmid($pmid);
  481. if(!empty($list)){
  482. foreach($list as $k => $v){
  483. $totalamount = floatval($v['unitprice'])*floatval($v['amount']);
  484. $list[$k]['totalamount'] = $totalamount;
  485. }
  486. }
  487. //获取标段审批人列表
  488. $auditactlist = $this->measureauditact->getUserAuditID($this->params['pmid']);
  489. //获取原报人
  490. $measureArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
  491. $inside = 1;
  492. $userlist = array();
  493. $usernamelist = array();
  494. if(!empty($auditactlist)){
  495. foreach($auditactlist as $k => $v){
  496. if($measureArray['uid'] == $v['auditoruid']){
  497. $inside = 0;
  498. }
  499. $usermsg = $this->auth->getRowByUid($v['auditoruid']);
  500. $userlist[$k]['userid'] = $usermsg['userid'];
  501. $userlist[$k]['name'] = $usermsg['name'];
  502. $userlist[$k]['jobs'] = $usermsg['jobs'];
  503. $userlist[$k]['avatar'] = $usermsg['avatar'];
  504. $userlist[$k]['company'] = $usermsg['company'];
  505. array_push($usernamelist, $usermsg['name']);
  506. }
  507. }
  508. if($inside){
  509. $usermsg2 = $this->auth->getRowByUid($measureArray['uid']);
  510. $orginArray['userid'] = $measureArray['uid'];
  511. $orginArray['avatar'] = $usermsg2['avatar'];
  512. $orginArray['name'] = $usermsg2['name'];
  513. $orginArray['jobs'] = $usermsg2['jobs'];
  514. $orginArray['company'] = $usermsg2['company'];
  515. array_push($userlist,$orginArray);
  516. array_push($usernamelist, $usermsg2['name']);
  517. }
  518. $this->data['pmArray'] = $pmArray;
  519. $this->data['userlist'] = $userlist;
  520. $this->data['usernamelist'] = implode(',',$usernamelist);
  521. $this->data['userArray'] = $this->auth->getRowByUid($this->auth->getUid());
  522. $this->data['list'] = $list;
  523. $this->data['year'] = date('Y',time());
  524. //获取此标段的最新一个变更令申请编号,没有则赋值为 变更申请编号001
  525. $lastnum = $this->change->getLastChangePnum($this->params['pmid']);
  526. if(!empty($lastnum)){
  527. //正则获取申请编号
  528. $pattern = '/(?!\d{3,6})(\D|\d)|\d{3,6}/i';
  529. preg_match_all($pattern, $lastnum['pnum'],$str);
  530. $arr = $str[0];
  531. $pnum = '';
  532. for($i = 0; $i < count($arr); $i++){
  533. if(mb_strlen($arr[$i],'UTF8') > 1){
  534. if($arr[$i] == date('Y',time()) || $arr[$i] == date('Y',strtotime("-1 year"))){
  535. $pnum .= $arr[$i];
  536. }else{
  537. $pnum .= $this->makenum($arr[$i]);
  538. }
  539. }else{
  540. $pnum .= $arr[$i];
  541. }
  542. }
  543. $this->data['pnum'] = $pnum;
  544. }else{
  545. $this->data['pnum'] = '变更申请编号001';
  546. }
  547. $this->render('biangeng-new', $this->data, TRUE);
  548. }else{
  549. exit('不存在此标段');
  550. }
  551. }
  552. //生成和num相同位数的并加一 001 -》 002, 0023 -》 0024
  553. function makenum($num){
  554. $len = mb_strlen($num,'UTF8'); //获取原位数
  555. $intnum = intval($num)+1; //获取int
  556. $len2 = mb_strlen($intnum,'UTF8'); //获取int位数
  557. if($len > $len2){
  558. $arr = Array();
  559. for($i = 0; $i < $len-$len2; $i++){
  560. $arr[$i] = '0';
  561. }
  562. $intnum = implode('',$arr).$intnum;
  563. }
  564. return $intnum;
  565. }
  566. public function changeApproval(){
  567. if (isset($this->params['cid']) && is_numeric($this->params['cid'])) {
  568. $cid = $this->params['cid'];
  569. $changeArray = $this->change->getChangebyid($cid);
  570. if (!empty($changeArray)) {
  571. //判断当前变更令是否处于你审批状态,否 则显示详情页
  572. $userchange = $this->change->getOneChangeAudit($this->auth->getUid(), $cid, $changeArray['times']);
  573. if ($changeArray['status'] != 'checking' || empty($userchange) || $userchange['status'] != 'checking') {
  574. return '/change/detail/' . $cid;
  575. die;
  576. }
  577. $pmArray = $this->actmeasure->getRowByPmid($changeArray['pmid']);
  578. if (empty($pmArray)) {
  579. exit('不存在此标段');
  580. }
  581. //审批结果
  582. if(isset($_POST['approval']) && is_numeric($_POST['approval'])){
  583. $status = $_POST['status'];
  584. Doo::loadModel('change');
  585. Doo::loadModel('changeaudit');
  586. Doo::loadModel('changeauditlist');
  587. $sintime = time();
  588. if($status == 'checked'){
  589. //通过
  590. $this->change->updateChangeAudit($this->auth->getUid(),$cid, $changeArray['times'], 'checked',$_POST['desc'],$sintime,$_POST['clist']);
  591. //更新audit_list
  592. $clist = explode(',',$_POST['clist']);
  593. $totalamount = 0;
  594. foreach($clist as $k => $v){
  595. $lid = explode('_',$v)[0];
  596. $ucamount = explode('_',$v)[1] != '' ? explode('_',$v)[1] : 0;
  597. $oneauditlist = $this->change->getOneChangeAuditList($lid);
  598. $totalamount += floatval($oneauditlist['unitprice'])*floatval($ucamount);
  599. $auditjson = json_decode($oneauditlist['auditjson'],true);
  600. foreach($auditjson as $ak => $av){
  601. if($av['uid'] == $this->auth->getUid()){
  602. $auditjson[$ak]['ucamount'] = $ucamount;
  603. }
  604. }
  605. $cauditlist = new ChangeAuditList();
  606. $cauditlist->id = $lid;
  607. $cauditlist->samount = $ucamount;
  608. $cauditlist->auditjson = json_encode($auditjson);
  609. $cauditlist->update();
  610. }
  611. //更新change总金额
  612. $this->change->updateChangeTotalamount($cid,$totalamount);
  613. //更改下一个审批状态或结束审批
  614. $audit = new ChangeAudit();
  615. $auditlist = $audit->getChangeAuditbylastlist($cid,$changeArray['times']);
  616. $flag = true;
  617. foreach($auditlist as $uk => $uv){
  618. if($uv['status'] == 'uncheck'){
  619. $changeaudit = new ChangeAudit();
  620. $changeaudit->id = $uv['id'];
  621. $changeaudit->status = 'checking';
  622. $changeaudit->update();
  623. $flag = false;
  624. break;
  625. }
  626. }
  627. //审批完成,更改change状态
  628. if($flag){
  629. $changes = new Change();
  630. $changes->cid = $cid;
  631. $changes->status = 'checked';
  632. $changes->sintime = $sintime;
  633. $changes->update();
  634. }
  635. }elseif($status == 'back'){
  636. if(isset($_POST['back']) && $_POST['back'] == 1 && !empty($_POST['lastuid'])){
  637. //退回到上一个审批人
  638. $lastuid = $_POST['lastuid'];
  639. //新增本次审批人,设为未审批并排序加2;
  640. $auditArray2 = $this->change->getOneChangeAudit($this->auth->getUid(),$cid,$changeArray['times']);
  641. //改变当前状态
  642. $this->change->updateChangeAudit($this->auth->getUid(),$cid, $changeArray['times'], 'back',$_POST['desc'],$sintime);
  643. $changeaudit2 = new ChangeAudit();
  644. $changeaudit2->insertChangeAudit($auditArray2,'uncheck',$auditArray2['usort']+2);
  645. //新增上一个审批人,设为审批中并排序加1;
  646. $changeaudit = new ChangeAudit();
  647. $auditArray = $changeaudit->getOneChangeAudit($lastuid,$cid,$changeArray['times']);
  648. $changeaudit->insertChangeAudit($auditArray,'checking',$auditArray2['usort']+1);
  649. //把接下未审批的审批人排序都加2
  650. $changeaudit3 = new ChangeAudit();
  651. $auditlist = $changeaudit3->getChangeAuditsbycidtimeWithout($cid,$changeArray['times'],$lastuid,$this->auth->getUid());
  652. if(!empty($auditlist)){
  653. foreach($auditlist as $ak => $av){
  654. $changeaudit4 = new ChangeAudit();
  655. $changeaudit4->id = $av['id'];
  656. $changeaudit4->usort = $av['usort']+2;
  657. $changeaudit4->update();
  658. }
  659. }
  660. //获取上上个审批通过人uid
  661. if($auditArray2['usite'] > 2){
  662. $lastlastuid = $changeaudit3->getChangeAuditbycidsitetime($cid,$changeArray['times'],$auditArray2['usite']-2)['uid'];
  663. }else{
  664. $lastlastuid = '';
  665. }
  666. //更新audit_list
  667. $clist = $this->change->getChangeAuditListbycid($cid);
  668. $totalamount = 0;
  669. foreach($clist as $ck => $cv){
  670. $auditjson = json_decode($cv['auditjson'],true);
  671. $samount = '';
  672. if(empty($lastlastuid)){
  673. $totalamount += floatval($cv['unitprice'])*floatval($cv['camount']);
  674. }
  675. foreach($auditjson as $jk => $jv){
  676. if(!empty($lastlastuid) && $jv['uid'] == $lastlastuid){
  677. $totalamount += floatval($cv['unitprice'])*floatval($jv['ucamount']);
  678. $samount = $jv['ucamount'];
  679. }
  680. if($jv['uid'] == $lastuid){
  681. $auditjson[$jk]['ucamount'] = '';
  682. }
  683. }
  684. $cauditlist = new ChangeAuditList();
  685. $cauditlist->id = $cv['id'];
  686. $cauditlist->samount = $samount;
  687. $cauditlist->auditjson = json_encode($auditjson);
  688. $cauditlist->update();
  689. }
  690. //更新change总金额
  691. $this->change->updateChangeTotalamount($cid,$totalamount);
  692. }elseif(isset($_POST['back']) && $_POST['back'] == 2){
  693. //退回到提交人,重新上报
  694. $this->change->updateChangeAudit($this->auth->getUid(),$cid, $changeArray['times'], 'backnew',$_POST['desc'],$sintime);
  695. $changeaudit = new ChangeAudit();
  696. //获取最后一次上报的上报人信息
  697. $auditArray = $changeaudit->getChangeAuditLastUser($cid,0);
  698. //获取最后一个审批人的usort
  699. $auditArray2 = $changeaudit->getChangeAuditLastUser($cid);
  700. //新建新的提交人,并把time+1
  701. $changeaudit->insertChangeAudit($auditArray,'checking',$auditArray2['usort']+1,$auditArray['times']+1);
  702. //更新audit_list
  703. $clist = $this->change->getChangeAuditListbycid($cid);
  704. $totalamount = 0;
  705. foreach($clist as $ck => $cv){
  706. $totalamount += floatval($cv['unitprice'])*floatval($cv['camount']);
  707. $cauditlist = new ChangeAuditList();
  708. $cauditlist->id = $cv['id'];
  709. $cauditlist->samount = '';
  710. $cauditlist->auditjson = '';
  711. $cauditlist->update();
  712. }
  713. //更新change
  714. $changes = new Change();
  715. $changes->cid = $cid;
  716. $changes->status = 'back';
  717. $changes->totalamount = $totalamount;
  718. $changes->update();
  719. }
  720. }elseif($status == 'checkno'){
  721. //不通过
  722. $this->change->updateChangeAudit($this->auth->getUid(),$cid, $changeArray['times'], 'checkno',$_POST['desc'],$sintime);
  723. $changes = new Change();
  724. $changes->cid = $cid;
  725. $changes->status = 'checkno';
  726. $changes->sintime = time();
  727. $changes->update();
  728. }
  729. return '/change/detail/'. $cid;
  730. }
  731. $this->data['pmArray'] = $pmArray;
  732. $ctypelist = array();
  733. if (!empty($changeArray['ctype'])) {
  734. $ctype = explode(',', $changeArray['ctype']);
  735. foreach ($ctype as $tk => $tv) {
  736. $ctypelist[$tk]['typename'] = $this->changeType[$tv];
  737. }
  738. }
  739. $changeArray['ctypelist'] = $ctypelist;
  740. $changeArray['categoryname'] = $this->changeCategory[$changeArray['category']];
  741. $changeArray['naturename'] = $this->changeNature[$changeArray['cnature']];
  742. $changeArray['companyname'] = $this->change->getCompanybyid($changeArray['companyid'])['name'];
  743. $this->data['changeArray'] = $changeArray;
  744. //获取用户审批变更清单的列表
  745. $auditlist = $this->change->getChangeAuditbylastlist($cid,$changeArray['times']);
  746. //获取清单,按清单编号排序
  747. $clist = $this->change->getChangeAuditListbycid($cid);
  748. $ototalnum = 0;
  749. $ctotalnum = 0;
  750. $stotalnum = 0;
  751. $listtablehtml = '<table class="table table-striped table-bordered nowrap" id="tablelist" cellspacing="0" width="100%">
  752. <thead>
  753. <tr><th rowspan="2" class="text-center" width="100">清单编号</th><th rowspan="2" class="text-center">名称</th><th rowspan="2" class="text-center">单位</th><th rowspan="2" class="text-center">单价</th><th colspan="2" class="text-center">原设计</th><th colspan="2" class="text-center">申报变更</th>';
  754. $thhtml = '<th class="text-center">数量</th>
  755. <th class="text-center">金额</th>
  756. <th class="text-center">数量</th>
  757. <th class="text-center">金额</th>';
  758. $utotalarr = array();
  759. $checkinguid = 0;
  760. $firstcheck = 0;
  761. $lastid = 0;
  762. foreach ($auditlist as $ak => $av) {
  763. $listtablehtml .= '<th colspan="2" class="text-center">'.$av['name'].' 审批</th>';
  764. $thhtml .= '<th class="text-center">数量</th><th class="text-center">金额</th>';
  765. $utotalarr[$ak]['uid'] = $av['uid'];
  766. $utotalarr[$ak]['status'] = $av['status'];
  767. $utotalarr[$ak]['usum'] = 0;
  768. if($av['status'] == 'checking'){
  769. $checkinguid = $av['uid'];
  770. if($ak == 0){
  771. $firstcheck = 1;
  772. }else{
  773. $lastid = $auditlist[$ak-1]['uid'];
  774. }
  775. }
  776. }
  777. $this->data['lastuid'] = $lastid;
  778. //获取上一个审批人名称和提交人名称
  779. if($lastid != ''){
  780. $this->data['lastusername'] = $this->auth->getRowByUid($lastid)['name'];
  781. }
  782. $this->data['createusername'] = $this->auth->getRowByUid($changeArray['uid'])['name'];
  783. $this->data['firstcheck'] = $firstcheck;
  784. $listtablehtml .= '</tr><tr>'. $thhtml .'</tr>
  785. </thead>
  786. <tbody id="list">';
  787. if (!empty($clist)) {
  788. include (DOO::conf()->SITE_PATH . 'protected/plugin/TemplateTag.php');
  789. foreach ($clist as $ck => $cv) {
  790. $osum = floatval($cv['unitprice']) * floatval($cv['oamount']);
  791. $clist[$ck]['osum'] = $osum;
  792. $ototalnum += $osum;
  793. $csum = floatval($cv['unitprice']) * floatval($cv['camount']);
  794. $clist[$ck]['csum'] = $csum;
  795. $ctotalnum += $csum;
  796. if($cv['samount'] != ''){
  797. $ssum = floatval($cv['unitprice'])*floatval($cv['samount']);
  798. $samount = $cv['samount'];
  799. $stotalnum += $ssum;
  800. }else{
  801. $ssum = $csum;
  802. $samount = $cv['camount'];
  803. $stotalnum += $ssum;
  804. }
  805. $listtablehtml .= '<tr class="clist"><td>' . $cv['lnum'] . '</td><td>' . $cv['lname'] . '</td><td>' . $cv['unit'] . '</td><td>' . tofloat($cv['unitprice']) . '</td><td>' . $cv['oamount'] . '</td><td>' . tofloat($osum) . '</td><td>' . $cv['camount'] . '</td><td>' . tofloat($csum) . '</td>';
  806. $userjson = json_decode($cv['auditjson'], true);
  807. $tdhtml = '';
  808. foreach ($userjson as $uk => $uv) {
  809. if ($uv['uid'] == $checkinguid) {
  810. $tdhtml .= '<td><input class="form-control input-sm" type="number" min="0" step="0.001" listid="'.$cv['id'].'" value="'.$samount.'" placeholder="请输入变更数量"></td><td class="cnum">'.tofloat($ssum).'</td>';
  811. }else{
  812. if($uv['ucamount'] != ''){
  813. $usum = floatval($cv['unitprice'])*floatval($uv['ucamount']);
  814. $tdhtml .= '<td>'.$uv['ucamount'].'</td><td>'.tofloat($usum).'</td>';
  815. //update utotalarr value=>usum
  816. foreach($utotalarr as $tk => $tv){
  817. if($tv['uid'] == $uv['uid']){
  818. $utotalarr[$tk]['usum'] = floatval($utotalarr[$tk]['usum'])+$usum;
  819. break;
  820. }
  821. }
  822. }else{
  823. $tdhtml .= '<td></td><td></td>';
  824. }
  825. }
  826. }
  827. $listtablehtml = $listtablehtml.$tdhtml.'</tr>';
  828. }
  829. }
  830. $listtablehtml .= '</tbody><tfoot><tr class="info"><td>合计</td><td></td><td></td><td></td><td></td><td>'.tofloat($ototalnum).'</td><td></td><td>'.tofloat($ctotalnum).'</td>';
  831. foreach($utotalarr as $tk => $tv){
  832. $addtd = $tv['status'] == 'checking' ? tofloat($stotalnum) : ($tv['usum'] != 0 ? tofloat($tv['usum']) : '');
  833. $checkinghtml = $tv['status'] == 'checking' ? ' class="utotalnum"': '';
  834. $listtablehtml .= '<td></td><td'. $checkinghtml .'>'.$addtd.'</td>';
  835. }
  836. $listtablehtml .= '</tr>
  837. </tfoot>
  838. </table>';
  839. $this->data['listtablehtml'] = $listtablehtml;
  840. //uid
  841. $this->data['userid'] = $this->auth->getUid();
  842. //cid
  843. $this->data['cid'] = $cid;
  844. //获取附件
  845. $attlist = $this->change->getChangeAttListbycid($cid);
  846. $showattlist = array();
  847. if (!empty($attlist)) {
  848. foreach ($attlist as $k => $v) {
  849. //加密下载的id
  850. $fid = $this->__hashids->encode($v['id']);
  851. $showattlist[$k]['fid'] = $v['id'];
  852. $showattlist[$k]['uid'] = $v['uid'];
  853. $showattlist[$k]['sort'] = $k + 1;
  854. $showattlist[$k]['downurl'] = '/change/file/download/' . $fid;
  855. $showattlist[$k]['filename'] = $v['filename'] . '.' . $v['fileext'];
  856. $showattlist[$k]['time'] = date('Y-m-d H:i', $v['intime']);
  857. $showattlist[$k]['size'] = $this->changefilesize($v['filesize']);
  858. }
  859. }
  860. $this->data['attlist'] = $showattlist;
  861. $auditlist2 = $this->change->getChangeAuditsbySort($cid);
  862. $this->data['auditlist'] = $auditlist2;
  863. $this->render('biangeng-approval', $this->data, TRUE);exit;
  864. }
  865. }
  866. exit('参数有误');
  867. }
  868. //重新上报、修改变更内容
  869. public function changeReport(){
  870. if(isset($this->params['cid']) && is_numeric($this->params['cid'])){
  871. $cid = $this->params['cid'];
  872. $changeArray = $this->change->getChangebyid($cid);
  873. //判断当前变更令是否处于上报或重新上报状态,否 则显示详情页
  874. if (!empty($changeArray) && ($changeArray['status'] == 'back' || $changeArray['status'] == 'uncheck') && $changeArray['uid'] == $this->auth->getUid() ) {
  875. $pmArray = $this->actmeasure->getRowByPmid($changeArray['pmid']);
  876. if (empty($pmArray)) {
  877. exit('不存在此标段');
  878. }
  879. if($this->auth->getUid() != $pmArray['uid']){
  880. exit('不是原报人无法修改或重新上报变更令');
  881. }
  882. //表单提交
  883. if(isset($_POST['pnum'])){
  884. if(isset($_POST['status']) && $_POST['status'] == 'checking'){
  885. if(empty($_POST['pnum']) || !isset($_POST['pname']) || empty($_POST['pname']) || !isset($_POST['mnum']) || empty($_POST['mnum']) || !isset($_POST['description']) || empty($_POST['description']) || !isset($_POST['changeaudit']) || empty($_POST['changeaudit']) || !isset($_POST['changelist']) || !isset($_POST['changewhitelist'])){
  886. exit('参数缺失或为空');
  887. }
  888. if(empty($_POST['changelist']) && empty($_POST['changewhitelist'])){
  889. exit('变更清单缺失');
  890. }
  891. }elseif(isset($_POST['status']) && $_POST['status'] == 'save'){
  892. if(empty($_POST['pnum']) || !isset($_POST['pname']) || empty($_POST['pname'])){
  893. exit('参数缺失或为空');
  894. }
  895. }
  896. Doo::loadModel('change');
  897. Doo::loadModel('changeaudit');
  898. Doo::loadModel('changeauditlist');
  899. //获取提交人audit表信息
  900. $creatorArray = $this->change->getChangeAuditLastUser($cid,0);
  901. $sort = $creatorArray['usort']+1;
  902. //先修改成变更令
  903. $status = isset($_POST['status']) && $_POST['status'] == 'checking' ? 'checking' : '';
  904. $this->change->updateChangeMsg($cid,$_POST,$creatorArray['times'],$status);
  905. if($status){
  906. //再修改提交人上报信息
  907. $changeaudit2 = new ChangeAudit();
  908. $changeaudit2->id = $creatorArray['id'];
  909. $changeaudit2->status = 'checked';
  910. $changeaudit2->sintime = time();
  911. $changeaudit2->update();
  912. }
  913. //附件添加cid
  914. if(!empty($_POST['changeatt'])){
  915. Doo::loadModel('changeatt');
  916. $attlist = explode(',', $_POST['changeatt']);
  917. foreach($attlist as $ak => $av){
  918. $changeAtt = new ChangeAtt();
  919. $changeAtt->id = $av;
  920. $changeAtt->cid = $cid;
  921. $changeAtt->update();
  922. }
  923. }
  924. //先删除所有审批人列,再重新添加
  925. $caudit = new ChangeAudit();
  926. $caudit->deleteChangeAuditthisTime($cid,$creatorArray['times']);
  927. //审批人添加
  928. $auditArr = array();
  929. if(!empty($_POST['changeaudit'])){
  930. $auditlist = explode(',', $_POST['changeaudit']);
  931. $site = 1;
  932. foreach($auditlist as $uk => $uv){
  933. $userArray = $this->auth->getRowByUid($uv);
  934. $changeaudit = new ChangeAudit();
  935. $changeaudit->pid = $pmArray['pid'];
  936. $changeaudit->stid = $pmArray['stid'];
  937. $changeaudit->pmid = $pmArray['pmid'];
  938. $changeaudit->cid = $cid;
  939. $changeaudit->times = $creatorArray['times'];
  940. $changeaudit->usite = $site;
  941. $changeaudit->usort = $sort;
  942. $changeaudit->uid = $uv;
  943. $changeaudit->company = $userArray['company'];
  944. $changeaudit->jobs = $userArray['jobs'];
  945. $changeaudit->name = $userArray['name'];
  946. $changeaudit->status = (isset($_POST['status']) && $_POST['status'] == 'checking' && $uk == 0) ? 'checking' : 'uncheck';
  947. $changeaudit->insert();
  948. $sort++;
  949. $site++;
  950. array_push($auditArr,array('uid' => $uv, 'ucamount' => ''));
  951. }
  952. }
  953. //先删除变更令所有清单列,再重新添加
  954. $cauditlist2 = new ChangeAuditList();
  955. $this->change->delChangeAuditListbyCid($cid);
  956. //清单添加,不分顺序,最终展示按清单编号排序
  957. $total = 0;
  958. if(!empty($_POST['changelist'])){
  959. $clist = explode(',',$_POST['changelist']);
  960. foreach($clist as $ck => $cv){
  961. $clistarr = explode('_',$cv);
  962. if(!empty($clistarr[1]) && is_numeric($clistarr[1])){
  963. $changelistArr = $this->change->getChangeListbyid($clistarr[0]);
  964. $total += floatval($changelistArr['unitprice'])*floatval($clistarr[1]);
  965. $cauditlist = new ChangeAuditList();
  966. $cauditlist->pid = $pmArray['pid'];
  967. $cauditlist->stid = $pmArray['stid'];
  968. $cauditlist->pmid = $pmArray['pmid'];
  969. $cauditlist->cid = $cid;
  970. $cauditlist->lid = $clistarr[0];
  971. $cauditlist->lnum = $changelistArr['lnum'];
  972. $cauditlist->lname = $changelistArr['lname'];
  973. $cauditlist->unit = $changelistArr['unit'];
  974. $cauditlist->unitprice = $changelistArr['unitprice'];
  975. $cauditlist->oamount = $changelistArr['amount'];
  976. $cauditlist->camount = $clistarr[1];
  977. $cauditlist->auditjson = json_encode($auditArr);
  978. $cauditlist->insert();
  979. }
  980. }
  981. }
  982. if(!empty($_POST['changewhitelist'])){
  983. $wlist = explode(',',$_POST['changewhitelist']);
  984. foreach($wlist as $wk => $wv){
  985. $wlistarr = explode(';',explode('->',$wv)[1]);
  986. if(!empty($wlistarr[0]) && !empty($wlistarr[1]) && !empty($wlistarr[3]) && !empty($wlistarr[4]) && !empty($wlistarr[5]) && is_numeric($wlistarr[3]) && is_numeric($wlistarr[4]) && is_numeric($wlistarr[5])){
  987. $total += floatval($wlistarr[3])*floatval($wlistarr[5]);
  988. $cauditlist = new ChangeAuditList();
  989. $cauditlist->pid = $pmArray['pid'];
  990. $cauditlist->stid = $pmArray['stid'];
  991. $cauditlist->pmid = $pmArray['pmid'];
  992. $cauditlist->cid = $cid;
  993. $cauditlist->lid = 0;
  994. $cauditlist->lnum = $wlistarr[0];
  995. $cauditlist->lname = $wlistarr[1];
  996. $cauditlist->unit = $wlistarr[2];
  997. $cauditlist->unitprice = $wlistarr[3];
  998. $cauditlist->oamount = $wlistarr[4];
  999. $cauditlist->camount = $wlistarr[5];
  1000. $cauditlist->auditjson = json_encode($auditArr);
  1001. $cauditlist->insert();
  1002. }
  1003. }
  1004. }
  1005. //变更令添加变更总金额
  1006. $this->change->updateChangeTotalamount($cid,$total);
  1007. $status = isset($_POST['status']) && $_POST['status'] == 'checking' ? 3 : 2;
  1008. return '/change/index/'.$pmArray['pmid'].'/'.$status;
  1009. }
  1010. $this->data['companylist'] = $this->change->getCompanyList();
  1011. $list = $this->change->getChangeListbyPmid($pmArray['pmid']);
  1012. if(!empty($list)){
  1013. foreach($list as $k => $v){
  1014. $totalamount = floatval($v['unitprice'])*floatval($v['amount']);
  1015. $list[$k]['totalamount'] = $totalamount;
  1016. }
  1017. }
  1018. //获取标段审批人列表
  1019. $auditactlist = $this->measureauditact->getUserAuditID($pmArray['pmid']);
  1020. //获取原报人
  1021. $measureArray = $this->actmeasure->getRowByPmid($pmArray['pmid']);
  1022. $inside = 1;
  1023. $userlist = array();
  1024. $usernamelist = array();
  1025. if(!empty($auditactlist)){
  1026. foreach($auditactlist as $k => $v){
  1027. if($measureArray['uid'] == $v['auditoruid']){
  1028. $inside = 0;
  1029. }
  1030. $usermsg = $this->auth->getRowByUid($v['auditoruid']);
  1031. $userlist[$k]['userid'] = $usermsg['userid'];
  1032. $userlist[$k]['name'] = $usermsg['name'];
  1033. $userlist[$k]['jobs'] = $usermsg['jobs'];
  1034. $userlist[$k]['avatar'] = $usermsg['avatar'];
  1035. $userlist[$k]['company'] = $usermsg['company'];
  1036. array_push($usernamelist, $usermsg['name']);
  1037. }
  1038. }
  1039. if($inside){
  1040. $usermsg2 = $this->auth->getRowByUid($measureArray['uid']);
  1041. $orginArray['userid'] = $measureArray['uid'];
  1042. $orginArray['avatar'] = $usermsg2['avatar'];
  1043. $orginArray['name'] = $usermsg2['name'];
  1044. $orginArray['jobs'] = $usermsg2['jobs'];
  1045. $orginArray['company'] = $usermsg2['company'];
  1046. array_push($userlist,$orginArray);
  1047. array_push($usernamelist, $usermsg2['name']);
  1048. }
  1049. //获取已选审批人列表,生成changeaudit和selectauditlist,并把未在常用审批人的uid找出来
  1050. $auditlist = $this->change->getChangeAuditsbycidtime($cid,$changeArray['times']);
  1051. $changeauditList = array();
  1052. $selectauditlist = array();
  1053. $searchauditlist = array();
  1054. foreach($auditlist as $adk => $adv){
  1055. array_push($changeauditList,$adv['uid']);
  1056. $addauditlist = $adv['uid'].'_'.$adv['name'].'_'.$adv['company'].'_'.$adv['jobs'];
  1057. array_push($selectauditlist,$addauditlist);
  1058. if(!in_array($adv['name'],$usernamelist)){
  1059. array_push($searchauditlist,$auditlist[$adk]);
  1060. array_push($usernamelist,$adv['name']);
  1061. }
  1062. }
  1063. $this->data['changeaudit'] = implode(',',$changeauditList);
  1064. $this->data['selectauditlist'] = implode('->',$selectauditlist);
  1065. $this->data['sauditlist'] = $searchauditlist;
  1066. $this->data['auditlist'] = $auditlist;
  1067. //获取已选清单列表,已选清单id列表,属于签约清单的changelist,和changewhitelist
  1068. $clist = $this->change->getChangeAuditListbycid($cid);
  1069. $ototalnum = 0;
  1070. $ctotalnum = 0;
  1071. $changeidlist = array();
  1072. $changelist = array();
  1073. $changewhitelist = array();
  1074. if(!empty($clist)){
  1075. $addnum = 1;
  1076. foreach($clist as $ck => $cv){
  1077. $osum = floatval($cv['unitprice'])*floatval($cv['oamount']);
  1078. $clist[$ck]['osum'] = $osum;
  1079. $ototalnum += $osum;
  1080. $csum = floatval($cv['unitprice'])*floatval($cv['camount']);
  1081. $clist[$ck]['csum'] = $csum;
  1082. $ctotalnum += $csum;
  1083. if($cv['lid'] != 0){
  1084. array_push($changeidlist,$cv['lid']);
  1085. array_push($changelist,$cv['lid'].'_'.$cv['camount']);
  1086. }else{
  1087. $clist[$ck]['add'] = $addnum;
  1088. array_push($changewhitelist,$addnum.'->'.$cv['lnum'].';'.$cv['lname'].';'.$cv['unit'].';'.$cv['unitprice'].';'.$cv['oamount'].';'.$cv['camount']);
  1089. $addnum++;
  1090. $clist[$ck]['changeunit'] = $this->changeUnit;
  1091. }
  1092. }
  1093. }
  1094. include (DOO::conf()->SITE_PATH . 'protected/plugin/TemplateTag.php');
  1095. $this->data['changelist'] = implode(',',$changelist);
  1096. $this->data['changewhitelist'] = implode(',',$changewhitelist);
  1097. $this->data['changeidlist'] = implode(',',$changeidlist);
  1098. $this->data['ototalnum'] = tofloat($ototalnum);
  1099. $this->data['ctotalnum'] = tofloat($ctotalnum);
  1100. $this->data['clist'] = $clist;
  1101. //获取已添加的附件列表
  1102. $attlist = $this->change->getChangeAttListbycid($cid);
  1103. $showattlist = array();
  1104. if (!empty($attlist)) {
  1105. foreach ($attlist as $k => $v) {
  1106. //加密下载的id
  1107. $fid = $this->__hashids->encode($v['id']);
  1108. $showattlist[$k]['uid'] = $v['uid'];
  1109. $showattlist[$k]['sort'] = $k + 1;
  1110. $showattlist[$k]['downurl'] = '/change/file/download/' . $fid;
  1111. $showattlist[$k]['filename'] = $v['filename'] . '.' . $v['fileext'];
  1112. $showattlist[$k]['time'] = date('Y-m-d H:i', $v['intime']);
  1113. $showattlist[$k]['size'] = $this->changefilesize($v['filesize']);
  1114. }
  1115. }
  1116. $this->data['attlist'] = $showattlist;
  1117. $this->data['changeArray'] = $changeArray;
  1118. $this->data['pmArray'] = $pmArray;
  1119. $this->data['userlist'] = $userlist;
  1120. $this->data['usernamelist'] = implode(',',$usernamelist);
  1121. $this->data['userArray'] = $this->auth->getRowByUid($this->auth->getUid());
  1122. $this->data['list'] = $list;
  1123. $this->data['year'] = date('Y',time());
  1124. $this->render('biangeng-update', $this->data, TRUE);
  1125. }else{
  1126. return '/change/detail/' . $cid;
  1127. die;
  1128. }
  1129. }else{
  1130. exit('不存在此变更令');
  1131. }
  1132. }
  1133. public function editCompany(){
  1134. if(isset($_POST['uci']) && isset($_POST['uc']) && isset($_POST['ac'])){
  1135. $addhtml = '';
  1136. $selecthtml = '';
  1137. Doo::loadModel('changecompany');
  1138. if(!empty($_POST['uci'])){
  1139. $idarr = $_POST['uci'];
  1140. $namearr = $_POST['uc'];
  1141. foreach($idarr as $k => $v){
  1142. $company = new ChangeCompany();
  1143. $company->id = $v;
  1144. $company->name = $namearr[$k];
  1145. $company->update();
  1146. $selecthtml .= '<option value="'.$v.'">'.$namearr[$k].'</option>';
  1147. }
  1148. }
  1149. if(!empty($_POST['ac'])){
  1150. $addarr = $_POST['ac'];
  1151. foreach($addarr as $ak => $av){
  1152. if(!empty(trim($av))){
  1153. $company2 = new ChangeCompany();
  1154. $company2->name = $av;
  1155. $id = $company2->insert();
  1156. $selecthtml .= '<option value="'.$id.'">'.$av.'</option>';
  1157. $addhtml .= '<div class="form-group"><input type="text" id="'.$id.'" class="form-control" value="'.$av.'"></div>';
  1158. }
  1159. }
  1160. }
  1161. echo json_encode(array('code' => 200, 'addhtml' => $addhtml, 'selecthtml' => $selecthtml));
  1162. die;
  1163. }else{
  1164. echo json_encode(array('code' => 500));
  1165. die;
  1166. }
  1167. }
  1168. public function searchUser(){
  1169. if(!isset($_GET['name']) || empty($_GET['name'])){
  1170. echo json_encode(array('code' => 400, 'msg' => '请输入审批人名称'));
  1171. exit;
  1172. }
  1173. $usermsg = $this->profile->checkUserName($_GET['name']);
  1174. if(!empty($usermsg)){
  1175. $namelist = $_POST['namelist'];
  1176. if(in_array($usermsg['name'], $namelist)){
  1177. echo json_encode(array('code' => 400, 'msg' => '列表或常用中已存在当前审批人'));
  1178. exit;
  1179. }else{
  1180. echo json_encode(array('code' => 200, 'user' => $usermsg));
  1181. exit;
  1182. }
  1183. }else{
  1184. echo json_encode(array('code' => 400, 'msg' => '不存在此审批人名称'));
  1185. exit;
  1186. }
  1187. }
  1188. public function fileUpload(){
  1189. if(!isset($this->params['pmid']) && !is_numeric($this->params['pmid'])){
  1190. exit(json_encode(array('success' => false, 'msg' => '参数有误')));
  1191. }
  1192. $pmArray = $this->actmeasure->getRowByPmid($this->params['pmid']);
  1193. if(empty($pmArray)){
  1194. exit(json_encode(array('success' => false, 'msg' => '不存在此标段,无法上传')));
  1195. }
  1196. Doo::loadClass('extras/Uploader');
  1197. $files = array();
  1198. $upload_dir = Doo::conf()->SITE_PATH . 'cfiles/';
  1199. $uploader = new FileUpload('uploadfile');
  1200. $intime = time();
  1201. $extPathdir = $upload_dir.date('Y/md/',$intime);
  1202. if (!$this->dir_create2($extPathdir)) {
  1203. $status = array('success' => FALSE, 'msg' => '文件夹创建失败');
  1204. echo json_encode($status, JSON_UNESCAPED_UNICODE);
  1205. die();
  1206. }
  1207. $files['filename'] = $uploader->getFileNameWithoutExt();
  1208. $files['fileext'] = $uploader->getExtension();
  1209. $files['filesize'] = $uploader->getFileSize();
  1210. $filepath = date('Ymdhis',$intime) . rand(100, 999) . '.' . $files['fileext'];
  1211. $uploader->newFileName = $filepath;
  1212. $files['filepath'] = 'cfiles/'.date('Y/md/',$intime).$filepath;
  1213. $result = $uploader->handleUpload($extPathdir);
  1214. if (!$result) {
  1215. exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
  1216. }
  1217. $files['pid'] = $pmArray['pid'];
  1218. $files['stid'] = $pmArray['stid'];
  1219. $files['pmid'] = $pmArray['pmid'];
  1220. $files['cid'] = isset($this->params['cid']) && is_numeric($this->params['cid']) ? $this->params['cid'] : 0;
  1221. $files['uid'] = $this->auth->getUid();
  1222. $files['intime'] = $intime;
  1223. $result2 = $this->change->insertChangeAtt($files);
  1224. if(empty($result2)){
  1225. exit(json_encode(array('success' => false, 'msg' => '添加到数据库发生错误')));
  1226. }
  1227. $files2 = array();
  1228. $files2['id'] = $result2;
  1229. //加密下载的id
  1230. $fid = $this->__hashids->encode($result2);
  1231. $files2['downurl'] = '/change/file/download/'.$fid;
  1232. $files2['filename'] = $files['filename'].'.'.$files['fileext'];
  1233. $files2['time'] = date('Y-m-d H:i',$intime);
  1234. $files2['size'] = $this->changefilesize($files['filesize']);
  1235. echo json_encode(array('success' => true, 'files' => $files2));
  1236. }
  1237. public function fileDownload(){
  1238. $fid = isset($this->params['fid'])?$this->params['fid']:null;
  1239. if($fid) {
  1240. //解密下载的id
  1241. $fid = $this->__hashids->decode($fid)[0];
  1242. $fileArray = $this->change->getChangeAttbyFid($fid);
  1243. if (!empty($fileArray)) {
  1244. $pathf = DOO::conf()->SITE_PATH;
  1245. $this->file_down($pathf.$fileArray['filepath'],$fileArray['filename'].'.'.$fileArray['fileext']);
  1246. }
  1247. }
  1248. }
  1249. public function fileDelete(){
  1250. $fid = isset($_POST['fid']) && is_numeric($_POST['fid']) ? $_POST['fid'] : null;
  1251. if($fid){
  1252. $fileArray = $this->change->getChangeAttbyFid($fid);
  1253. if (!empty($fileArray) && $fileArray['uid'] == $this->auth->getUid()) {
  1254. include (DOO::conf()->SITE_PATH . 'protected/plugin/io.han.php');
  1255. $pathf = DOO::conf()->SITE_PATH;
  1256. $this->IoHandler = new IoHandler();
  1257. $this->IoHandler->DeleteFile($pathf.$fileArray['filepath']);
  1258. $this->change->delChangeAttbyFid($fid);
  1259. exit(json_encode(array('code' => 200)));
  1260. }
  1261. }
  1262. exit(json_encode(array('code' => 400)));
  1263. }
  1264. public function pnumCheck(){
  1265. if(isset($_POST['pnum']) && !empty($_POST['pnum']) && isset($_POST['status']) && !empty($_POST['status']) && isset($_POST['pmid']) && is_numeric($_POST['pmid'])){
  1266. if($_POST['status'] == 'new'){
  1267. $changeArray = $this->change->getChangebyPnumPmid($_POST['pnum'],$_POST['pmid']);
  1268. if(!empty($changeArray)){
  1269. exit(json_encode(array('code' => 400,'msg' => '当前标段变更令已存在此申请编号,请重新输入或改变自增编号值')));
  1270. }else{
  1271. exit(json_encode(array('code' => 200,'msg' => '')));
  1272. }
  1273. }elseif($_POST['status'] == 'update'){
  1274. if(isset($_POST['cid']) && is_numeric($_POST['cid'])){
  1275. $changeArray = $this->change->getChangebyPnumPmid($_POST['pnum'],$_POST['pmid'],$_POST['cid']);
  1276. if(!empty($changeArray)){
  1277. exit(json_encode(array('code' => 400,'msg' => '当前标段变更令已存在此申请编号,请重新输入或改变自增编号值')));
  1278. }else{
  1279. exit(json_encode(array('code' => 200,'msg' => '')));
  1280. }
  1281. }
  1282. }
  1283. }
  1284. exit(json_encode(array('code' => 400,'msg' => '判断参数有误')));
  1285. }
  1286. public function substr_replace_cn($string, $repalce = '*', $start = 0, $len = 0)
  1287. {
  1288. $count = mb_strlen($string, 'UTF-8'); //此处传入编码,建议使用utf-8。此处编码要与下面mb_substr()所使用的一致
  1289. if (!$count) {
  1290. return $string;
  1291. }
  1292. if ($len == 0) {
  1293. $end = $count; //传入0则替换到最后
  1294. } else {
  1295. $end = $start + $len; //传入指定长度则为开始长度+指定长度
  1296. }
  1297. $i = 0;
  1298. $returnString = '';
  1299. while ($i < $count) { //循环该字符串
  1300. $tmpString = mb_substr($string, $i, 1, 'UTF-8'); // 与mb_strlen编码一致
  1301. if ($start <= $i && $i < $end) {
  1302. $returnString .= $repalce;
  1303. } else {
  1304. $returnString .= $tmpString;
  1305. }
  1306. $i++;
  1307. }
  1308. return $returnString;
  1309. }
  1310. function unicode_encode($name)
  1311. {//to Unicode
  1312. $name = iconv('UTF-8', 'UCS-2', $name);
  1313. $len = strlen($name);
  1314. $str = '';
  1315. for ($i = 0; $i < $len - 1; $i = $i + 2) {
  1316. $c = $name[$i];
  1317. $c2 = $name[$i + 1];
  1318. if (ord($c) > 0) {// 两个字节的字
  1319. $str .= '\\' . base_convert(ord($c), 10, 16) . base_convert(ord($c2), 10, 16);
  1320. } else {
  1321. $str .= $c2;
  1322. }
  1323. }
  1324. $str = strtoupper($str);
  1325. return $str;
  1326. }
  1327. function unicode_decode($name)
  1328. {//Unicode to
  1329. $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
  1330. preg_match_all($pattern, $name, $matches);
  1331. if (!empty($matches)) {
  1332. $name = '';
  1333. for ($j = 0; $j < count($matches[0]); $j++) {
  1334. $str = $matches[0][$j];
  1335. if (strpos($str, '\\u') === 0) {
  1336. $code = base_convert(substr($str, 2, 2), 16, 10);
  1337. $code2 = base_convert(substr($str, 4), 16, 10);
  1338. $c = chr($code) . chr($code2);
  1339. $c = iconv('UCS-2', 'UTF-8', $c);
  1340. $name .= $c;
  1341. } else {
  1342. $name .= $str;
  1343. }
  1344. }
  1345. }
  1346. return $name;
  1347. }
  1348. function dir_create2($path, $mode = 0777)
  1349. {
  1350. if (is_dir($path))
  1351. return TRUE;
  1352. $path = $this->dir_path($path);
  1353. $parent = dirname($path);
  1354. if (!is_dir($parent)){
  1355. @mkdir($parent, 0777);
  1356. @chmod($parent, 0777);
  1357. }
  1358. @mkdir($path, 0777);
  1359. @chmod($path, 0777);
  1360. return is_dir($path);
  1361. }
  1362. function dir_path($path)
  1363. {
  1364. $path = str_replace('\\', '/', $path);
  1365. if (substr($path, -1) != '/')
  1366. $path = $path . '/';
  1367. return $path;
  1368. }
  1369. //字节转换
  1370. function changefilesize($value){
  1371. $units = array(' B', ' KB', ' MB', ' GB', ' TB');
  1372. for ($i = 0; $value >= 1024 && $i < 4; $i++) $value /= 1024;
  1373. return round($value, 2).$units[$i];
  1374. }
  1375. /**
  1376. * 文件下载
  1377. * @param $filepath 文件路径
  1378. * @param $filename 文件名称
  1379. */
  1380. public function file_down($filepath,$filename) {
  1381. if (ob_get_length() !== false)
  1382. @ob_end_clean();
  1383. header('Content-Description: File Download');
  1384. header('Content-Type: application/octet-stream');
  1385. header('Content-Disposition: attachment; filename='.basename($filename));
  1386. header('Content-Transfer-Encoding: binary');
  1387. header('Expires: 0');
  1388. header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  1389. header('Pragma: public');
  1390. header('Content-Length: ' . filesize($filepath));
  1391. @readfile($filepath);
  1392. }
  1393. }
  1394. ?>