rocksaveModel.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 20260318公共保存
  4. */
  5. class rocksaveClassModel extends Model
  6. {
  7. public $now_uid = 0;
  8. public $now_name = '';
  9. public $flow;
  10. /**
  11. * 设置当前用户
  12. */
  13. public function setNowuser($id, $name)
  14. {
  15. $this->now_uid = $id;
  16. $this->now_name = $name;
  17. $this->rock->adminid = $this->now_uid;
  18. $this->rock->adminname = $this->now_name;
  19. $this->adminname = $this->now_name;
  20. $this->adminid = $this->now_uid;
  21. return $this;
  22. }
  23. /**
  24. * 提交保存,简单的保存
  25. */
  26. public function submit($num,$mid=0, $openlx=0)
  27. {
  28. $this->flow = m('flow')->initflow($num);
  29. $this->flow->adminname = $this->now_name;
  30. $this->flow->adminid = $this->now_uid;
  31. $this->flow->openmode = $openlx;
  32. if($openlx == 4 && arrvalue($this->flow->moders,'isluo') != '1')return returnerror('not out open');
  33. $uaarr= array();
  34. $addbo= ($mid===0);
  35. foreach($this->flow->fieldsarra as $k=>$rs){
  36. $fid = $rs['fields'];
  37. $fi1 = substr($fid, 0, 5);
  38. if($fi1=='temp_' || $fi1=='base_' || $rs['islu']=='0')continue;
  39. $val = $this->rock->post($fid);
  40. if($rs['isbt']==1 && isempt($val))return returnerror(''.$rs['name'].'不能为空');
  41. $dev = $rs['dev'];
  42. if(!isempt($dev) && isempt($val) && $dev=='0')$val = $dev; //默认值是0
  43. $uaarr[$fid] = $val;
  44. }
  45. $table = $this->flow->moders['table'];
  46. $allfields = $this->db->getallfields('[Q]'.$table.'');
  47. if(in_array('optdt', $allfields))$uaarr['optdt'] = $this->rock->now;
  48. if(in_array('optid', $allfields))$uaarr['optid'] = $this->now_uid;
  49. if(in_array('optname', $allfields))$uaarr['optname'] = $this->now_name;
  50. if(in_array('uid', $allfields) && $addbo)
  51. $uaarr['uid'] = $this->rock->post('uid', $this->now_uid);
  52. if(in_array('applydt', $allfields) && $addbo)
  53. $uaarr['applydt'] = $this->rock->post('applydt', date('Y-m-d'));
  54. $notsave = array();//不保存的字段
  55. if(method_exists($this->flow, 'flowsavebefore')){
  56. $befa = $this->flow->flowsavebefore($table, $uaarr, $mid, $addbo);
  57. if($befa){
  58. if(is_string($befa))return returnerror($befa);
  59. if(is_array($befa)){
  60. if(isset($befa['msg']))return returnerror($befa['msg']);
  61. if(isset($befa['rows'])){
  62. if(is_array($befa['rows']))foreach($befa['rows'] as $bk=>$bv)$uaarr[$bk]=$bv;
  63. }
  64. if(isset($befa['notsave'])){
  65. $notsave = $befa['notsave'];
  66. if(is_string($notsave))$notsave = explode(',', $notsave);
  67. }
  68. }
  69. }
  70. }
  71. //不保存字段过滤掉
  72. if(is_array($notsave))foreach($notsave as $nofild)if(isset($uaarr[$nofild]))unset($uaarr[$nofild]);
  73. if($addbo){
  74. $mid = $this->flow->insert($uaarr);
  75. if(!$mid)return returnerror($this->db->lasterror());
  76. }
  77. $this->flow->loaddata($mid, false);
  78. $this->flow->submit('提交');
  79. //print_r($uaarr);
  80. return returnsuccess(array(
  81. 'mid' => $mid,
  82. 'table' => $table
  83. ));
  84. }
  85. public function saveUdept($table, $mid, $name, $dept)
  86. {
  87. m('flowbill')->update(array(
  88. 'uname' => $name,
  89. 'udeptname' => $dept,
  90. ), "`table`='$table' and `mid`=".$mid."");
  91. }
  92. /**
  93. * 文件上传的
  94. */
  95. public function upload($uptypes='*')
  96. {
  97. if(!$_FILES)return 'sorry!';
  98. $upimg = c('upfile');
  99. $maxsize = (int)$this->rock->get('maxsize', $upimg->getmaxzhao());//上传最大M
  100. $updir = $this->rock->get('updir');
  101. if(isempt($updir)){
  102. $updir=date('Y-m');
  103. }else{
  104. $updir=str_replace(array(' ','.'),'', trim($updir));
  105. $updir=str_replace('{month}',date('Y-m'), $updir);
  106. $updir=str_replace('{Year}',date('Y'), $updir);
  107. $updir=str_replace(array('{','}'),'', $updir);
  108. $updir=str_replace(',','|', $updir);
  109. $bobg = preg_replace("/[a-zA-Z0-9_]/",'', $updir);
  110. $bobg = str_replace(array('-','|'),'', $bobg);
  111. if($bobg)return 'stop:'.$bobg.'';
  112. }
  113. $uptypes = str_replace(',','|', $uptypes);
  114. $upimg->initupfile($uptypes, ''.UPDIR.'|'.$updir.'', $maxsize);
  115. $upses = $upimg->up('file');
  116. if(!is_array($upses))return $upses;
  117. $arr = c('down')->uploadback($upses);
  118. $arr['autoup'] = (getconfig('qcloudCos_autoup') || getconfig('alioss_autoup')) ? 1 : 0; //是否上传其他平台
  119. return $arr;
  120. }
  121. /**
  122. * 文件预览下载用
  123. */
  124. public function fileinfo($fileid, $type, $ismobile=0, $omode=0)
  125. {
  126. $fobj = m('file');
  127. $frs = $fobj->getone($fileid);
  128. if(!$frs)return returnerror('文件不存在了');
  129. $fileext = $frs['fileext'];
  130. $filename = $frs['filename'];
  131. $filepath = $frs['filepath'];
  132. $filepathout = arrvalue($frs, 'filepathout');
  133. $url = '';
  134. $data['fileext'] = $fileext;
  135. $data['filename'] = $filename;
  136. //预览
  137. if($type==0){
  138. if(!$fobj->isview($fileext))
  139. return returnerror('此'.$fileext.'类型文件不支持在线预览');
  140. }
  141. if(substr($filepath,0,4)!='http' && isempt($filepathout) && !file_exists($filepath))return returnerror('文件不存在了1');
  142. if(c('upfile')->isimg($fileext)){
  143. $url = m('admin')->getface($filepath);
  144. if(!isempt($filepathout))$url = $filepathout;
  145. }
  146. if($url==''){
  147. $url = 'index.php?m=public&a=fileviewer&id='.$fileid.'&omode='.$omode.'';
  148. }
  149. $data['url'] = $url;
  150. $data['type'] = $type;
  151. $data['id'] = $fileid;
  152. $data['isview'] = $fobj->isview($fileext); //是否可直接预览
  153. return returnsuccess($data);
  154. }
  155. }
粤ICP备19079148号