rocksaveModel.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. return $this;
  20. }
  21. /**
  22. * 提交保存,简单的保存
  23. */
  24. public function submit($num,$mid=0,$openlx=0)
  25. {
  26. $this->flow = m('flow')->initflow($num);
  27. $this->flow->adminname = $this->now_name;
  28. $this->flow->adminid = $this->now_uid;
  29. $this->flow->openmode = $openlx;
  30. if($openlx == 4 && arrvalue($this->flow->moders,'isluo') != '1')return returnerror('not out open');
  31. $uaarr= array();
  32. $addbo= ($mid===0);
  33. foreach($this->flow->fieldsarra as $k=>$rs){
  34. $fid = $rs['fields'];
  35. $fi1 = substr($fid, 0, 5);
  36. if($fi1=='temp_' || $fi1=='base_' || $rs['islu']=='0')continue;
  37. $val = $this->rock->post($fid);
  38. if($rs['isbt']==1 && isempt($val))return returnerror(''.$rs['name'].'不能为空');
  39. $dev = $rs['dev'];
  40. if(!isempt($dev) && isempt($val) && $dev=='0')$val = $dev; //默认值是0
  41. $uaarr[$fid] = $val;
  42. }
  43. $table = $this->flow->moders['table'];
  44. $allfields = $this->db->getallfields('[Q]'.$table.'');
  45. if(in_array('optdt', $allfields))$uaarr['optdt'] = $this->rock->now;
  46. if(in_array('optid', $allfields))$uaarr['optid'] = $this->now_uid;
  47. if(in_array('optname', $allfields))$uaarr['optname'] = $this->now_name;
  48. if(in_array('uid', $allfields) && $addbo)
  49. $uaarr['uid'] = $this->rock->post('uid', $this->now_uid);
  50. if(in_array('applydt', $allfields) && $addbo)
  51. $uaarr['applydt'] = $this->rock->post('applydt', date('Y-m-d'));
  52. $notsave = array();//不保存的字段
  53. if(method_exists($this->flow, 'flowsavebefore')){
  54. $befa = $this->flow->flowsavebefore($table, $uaarr, $mid, $addbo);
  55. if($befa){
  56. if(is_string($befa))return returnerror($befa);
  57. if(is_array($befa)){
  58. if(isset($befa['msg']))return returnerror($befa['msg']);
  59. if(isset($befa['rows'])){
  60. if(is_array($befa['rows']))foreach($befa['rows'] as $bk=>$bv)$uaarr[$bk]=$bv;
  61. }
  62. if(isset($befa['notsave'])){
  63. $notsave = $befa['notsave'];
  64. if(is_string($notsave))$notsave = explode(',', $notsave);
  65. }
  66. }
  67. }
  68. }
  69. //不保存字段过滤掉
  70. if(is_array($notsave))foreach($notsave as $nofild)if(isset($uaarr[$nofild]))unset($uaarr[$nofild]);
  71. if($addbo){
  72. $mid = $this->flow->insert($uaarr);
  73. if(!$mid)return returnerror($this->db->lasterror());
  74. }
  75. $this->flow->loaddata($mid, false);
  76. $this->flow->submit('提交');
  77. //print_r($uaarr);
  78. return returnsuccess();
  79. }
  80. /**
  81. * 文件上传的
  82. */
  83. public function upload($uptypes='*')
  84. {
  85. if(!$_FILES)return 'sorry!';
  86. $upimg = c('upfile');
  87. $maxsize = (int)$this->rock->get('maxsize', $upimg->getmaxzhao());//上传最大M
  88. $updir = $this->rock->get('updir');
  89. if(isempt($updir)){
  90. $updir=date('Y-m');
  91. }else{
  92. $updir=str_replace(array(' ','.'),'', trim($updir));
  93. $updir=str_replace('{month}',date('Y-m'), $updir);
  94. $updir=str_replace('{Year}',date('Y'), $updir);
  95. $updir=str_replace(array('{','}'),'', $updir);
  96. $updir=str_replace(',','|', $updir);
  97. $bobg = preg_replace("/[a-zA-Z0-9_]/",'', $updir);
  98. $bobg = str_replace(array('-','|'),'', $bobg);
  99. if($bobg)return 'stop:'.$bobg.'';
  100. }
  101. $uptypes = str_replace(',','|', $uptypes);
  102. $upimg->initupfile($uptypes, ''.UPDIR.'|'.$updir.'', $maxsize);
  103. $upses = $upimg->up('file');
  104. if(!is_array($upses))return $upses;
  105. $arr = c('down')->uploadback($upses);
  106. $arr['autoup'] = (getconfig('qcloudCos_autoup') || getconfig('alioss_autoup')) ? 1 : 0; //是否上传其他平台
  107. return $arr;
  108. }
  109. }
粤ICP备19079148号