beifenAction.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <?php
  2. @set_time_limit(3600);
  3. class beifenClassAction extends Action
  4. {
  5. public function chushuaAjax()
  6. {
  7. $myext = $this->getsession('adminallmenuid');
  8. if(getconfig('systype')=='demo')return '演示请勿操作';
  9. if($myext!='-1')return '只有管理员才可以用';
  10. $tabstr = 'daily,file,files,flow_log,flow_todos,flow_checks,im_history,im_mess,im_messzt,infor,infors,log,logintoken,meet,reads,sjoin,work,todo,flow_chao,flow_bill,flow_remind,goodm,goodn,goodss,goods,kqanay,kqdkjl,kqerr,kqout,kqinfo,location,official,officialfa,officialhong,schedule,scheduld,project,userinfo,userinfos,userract,hrpositive,word,hrredund,hrsalary,customer,custsale,custract,custfina,custappy,assetm,book,bookborrow,carm,carms,carmang,carmrese,email_cont,emailm,emails,sealapl,vcard,tovoid,editrecord,wouser,dailyfx,knowtraim,knowtrais,fininfom,fininfos,hrtrsalary,hrtransfer,hrdemint,reward,offyuebd,repair,knowtiku,kqdisv,knowledge,kqjcmd,kqjuser,kqjsn,hrcheck,receipt,hrcheckn,hrchecks,hrkaohem,hrkaohes,hrkaohen,demo,finpiao,wordxie,wordeil,subscribe,subscribeinfo,news,finzhang,finkemu,finount,finjibook,custplan,wenjuan,wenjuat,wenjuau,dangan,danganjy,wotpl,seal,godepot,im_tonghua,bianjian';
  11. $mrows = m('mode')->getall("`id`>=108 and `type`<>'系统'");
  12. foreach($mrows as $k1=>$rs1){
  13. if(!isempt($rs1['table']))$tabstr.=','.$rs1['table'].'';
  14. if(!isempt($rs1['tables']))$tabstr.=','.$rs1['tables'].'';
  15. }
  16. $tables = explode(',', $tabstr);
  17. $alltabls = $this->db->getalltable();
  18. foreach($tables as $tabs){
  19. $_tabs = ''.PREFIX.''.$tabs.'';
  20. $yunbo = false;
  21. if(in_array($_tabs, $alltabls) || !$alltabls)$yunbo = true;
  22. if($yunbo){
  23. $sql1 = "delete from `$_tabs`";
  24. $sql2 = "alter table `$_tabs` AUTO_INCREMENT=1";
  25. $this->db->query($sql1, false);
  26. $this->db->query($sql2, false);
  27. }
  28. }
  29. $this->option->delpid('-2,-102'); //收信的清空
  30. if(!getconfig('platdwnum')){
  31. m('company')->delete('id>1');
  32. $sql2 = "alter table `[Q]company` AUTO_INCREMENT=1";
  33. $this->db->query($sql2, false);
  34. }
  35. echo 'ok';
  36. }
  37. public function beifenAjax()
  38. {
  39. m('beifen')->start();
  40. echo 'ok';
  41. }
  42. public function getdataAjax()
  43. {
  44. if(getconfig('systype')=='demo')exit('演示请勿操作');
  45. $carr = c('file')->getfolderrows(''.UPDIR.'/data');
  46. $rows = array();
  47. $len = count($carr);
  48. $oux = 0;
  49. for($k=$len-1;$k>=0;$k--){
  50. if($oux>100)break;
  51. $fils = $carr[$k];
  52. $fils['xu'] = $k;
  53. $rows[] = $fils;
  54. $oux++;
  55. }
  56. if($rows)$rows = c('array')->order($rows, 'filename');
  57. $arr['rows'] = $rows;
  58. $this->returnjson($arr);
  59. }
  60. public function getdatssssAjax()
  61. {
  62. if(getconfig('systype')=='demo')exit('演示请勿操作');
  63. $rows = array();
  64. $folder = $this->post('folder');
  65. $folder = str_replace(array('..','/'),'', $folder);
  66. $path = ''.UPDIR.'/data/'.$folder.'';
  67. $carr = c('file')->getfilerows($path);
  68. foreach($carr as $k=>$rs){
  69. $id = $rs['filename'];
  70. $ids = substr($id,0,-5);
  71. $ida = explode('_', $ids);
  72. $len = count($ida);
  73. $fieldshu = $ida[$len-2];
  74. $total = $ida[$len-1];
  75. $fields = str_replace('_'.$fieldshu.'_'.$total.'.json','', $id);
  76. $filepath = $path.'/'.$id.'';
  77. if(file_exists($filepath)){
  78. $filesize = filesize($filepath);
  79. $rows[] = array(
  80. 'fields' => $fields,
  81. 'fieldshu' => $fieldshu,
  82. 'total' => $total,
  83. 'id' => $id,
  84. 'filesizecn'=> $this->rock->formatsize($filesize)
  85. );
  86. }
  87. }
  88. $arr['rows'] = $rows;
  89. $this->returnjson($arr);
  90. }
  91. public function huifdatanewAjax()
  92. {
  93. if(getconfig('systype')=='demo')exit();
  94. if($this->adminid!=1)return '只有ID=1的管理员才可以用';
  95. $folder = $this->post('folder');
  96. $sida = explode(',', $this->post('sid'));
  97. $alltabls = $this->db->getalltable();
  98. $shul = 0;
  99. $tablss = '';
  100. foreach($sida as $id){
  101. $ids = substr($id,0,-5);
  102. $ida = explode('_', $ids);
  103. $len = count($ida);
  104. $fieldshu = $ida[$len-2];
  105. $total = $ida[$len-1];
  106. $tab = str_replace('_'.$fieldshu.'_'.$total.'.json','', $id); //表
  107. $filepath = ''.UPDIR.'/data/'.$folder.'/'.$id.'';
  108. if(!file_exists($filepath))continue;
  109. $data = m('beifen')->getbfdata('',$filepath);
  110. if(!$data)continue;
  111. $dataarr = $data[$tab];
  112. //表不存在
  113. if(!in_array($tab, $alltabls)){
  114. $createsql = arrvalue($dataarr, 'createsql');
  115. if($createsql){
  116. $this->db->query($createsql, false);
  117. }else{
  118. continue;
  119. }
  120. }
  121. $dataall = $dataarr['data'];
  122. if(count($dataall)<=0)continue; //没有数据
  123. $allfields = $this->db->getallfields($tab);
  124. $fistdata = $dataall[0];
  125. $xufarr = array();
  126. foreach($fistdata as $f=>$v){
  127. if(in_array($f, $allfields)){
  128. $xufarr[] = $f;
  129. }
  130. }
  131. $uparr = array();
  132. foreach($dataall as $k=>$rs){
  133. $str1 = '';
  134. $upa = array();
  135. foreach($xufarr as $f){
  136. $upa[$f] = $rs[$f];
  137. }
  138. $uparr[] = $upa;
  139. }
  140. $sql1 = "delete from `$tab`";
  141. //$sql2 = "alter table `$tab` AUTO_INCREMENT=1";
  142. $bo = $this->db->query($sql1, false);
  143. //$bo = $this->db->query($sql2, false);
  144. foreach($uparr as $k=>$upas){
  145. $bo = $this->db->record($tab, $upas);
  146. }
  147. $shul++;
  148. $tablss.=','.$tab.'';
  149. }
  150. return ''.$tablss.'表已恢复';
  151. }
  152. /**
  153. * 还原数据操作(2017-08-27弃用)
  154. */
  155. public function huifdataAjax()
  156. {
  157. if(getconfig('systype')=='demo')exit('演示请勿操作');
  158. $xu = (int)$this->post('xu');
  159. $carr = c('file')->getfilerows(''.UPDIR.'/data');
  160. $sida = explode(',', $this->post('sid'));
  161. $rows = array();
  162. if(isset($carr[$xu])){
  163. $file = $carr[$xu]['filename'];
  164. $data = m('beifen')->getbfdata($file);
  165. if($data){
  166. $alltabls = $this->db->getalltable();
  167. foreach($sida as $tab){
  168. if(!isset($data[$tab]))continue;
  169. if(!in_array($tab, $alltabls))continue; //表不存在
  170. $dataall = $data[$tab]['data'];
  171. if(count($dataall)<=0)continue;
  172. $allfields = $this->db->getallfields($tab);
  173. $fistdata = $dataall[0];
  174. $xufarr = array();
  175. foreach($fistdata as $f=>$v){
  176. if(in_array($f, $allfields)){
  177. $xufarr[] = $f;
  178. }
  179. }
  180. $uparr = array();
  181. foreach($dataall as $k=>$rs){
  182. $str1 = '';
  183. $upa = array();
  184. foreach($xufarr as $f){
  185. $upa[$f] = $rs[$f];
  186. }
  187. $uparr[] = $upa;
  188. }
  189. $sql1 = "delete from `$tab`";
  190. $sql2 = "alter table `$tab` AUTO_INCREMENT=1";
  191. $bo = $this->db->query($sql1, false);
  192. $bo = $this->db->query($sql2, false);
  193. foreach($uparr as $k=>$upas){
  194. $bo = $this->db->record($tab, $upas);
  195. }
  196. }
  197. }
  198. }
  199. echo 'ok';
  200. }
  201. public function chushuserAjax()
  202. {
  203. if(getconfig('systype')=='demo')return '演示请勿操作';
  204. if($this->adminid!=1)return '只有ID=1的管理员才可以用';
  205. $users = "'diaochan','zhangfei','daqiao','xiaoqiao','zhaozl','rock','xinhu'";
  206. $dbs = m('admin');
  207. $dba = m('dept');
  208. //默认可以多次初始化
  209. if($this->option->getval('sysuserinit', '是') != '是')
  210. if($dbs->rows("`user` in($users)")==0)return '可能你已初始化过用户和部门了,要开启可到【流程模块→数据选项】系统选项下开启';
  211. $dbs->delete('id>1');
  212. $this->db->query('alter table `[Q]admin` AUTO_INCREMENT=2', false);
  213. $dba->delete('id>1');
  214. $this->db->query('alter table `[Q]dept` AUTO_INCREMENT=2', false);
  215. $this->db->query('delete from `[Q]userinfo`', false);
  216. $this->db->query('delete from `[Q]userinfos`', false);
  217. $this->db->query('alter table `[Q]userinfos` AUTO_INCREMENT=1', false);
  218. return 'ok';
  219. }
  220. public function fenbiaoAjax()
  221. {
  222. $allfields = $this->db->getallfields('[Q]flow_set');
  223. if(!in_array('logstr', $allfields)){
  224. $bool = $this->db->query("alter table `[Q]flow_set` add `logstr` varchar(500) DEFAULT NULL COMMENT '操作记录分表';", false);
  225. if(!$bool)return '无法操作:'.$this->db->error().'';
  226. }
  227. $obj = m('mode');
  228. $rows = $obj->getall('1=1');
  229. $atable = array();
  230. $count = m('flow_log')->rows('1=1');
  231. if($count < 10000)return '操作记录少于1W条,不需要分表';
  232. $alltabls = $this->db->getalltable();
  233. $barr = $this->createbiao(1, $alltabls);
  234. if(!$barr['success'])return $barr['msg'];
  235. $biao = $barr['data'];
  236. if(1==1)foreach($rows as $k=>$rs){
  237. $tab = $rs['table'];
  238. if(!isset($atable[$tab])){
  239. $max = m($tab)->getmou('max(id) as ids', 'id>0');
  240. if(!$max)$max = 0;
  241. $max++;
  242. $atable[$tab] = $max;
  243. }
  244. $max = $atable[$tab];
  245. $logstr = $rs['logstr'];
  246. if(isempt($logstr)){
  247. $logarr = array();
  248. }else{
  249. $logarr = json_decode($logstr, true);
  250. }
  251. if(!isset($logarr[$max]))$logarr[$max] = $biao;
  252. $logstr = json_encode($logarr);
  253. $obj->update(array(
  254. 'logstr' => $logstr
  255. ), $rs['id']);
  256. }
  257. //更新
  258. $sql = "update `[Q]file` set `mtype`='flow_log".$biao."' where `mtype`='flow_log'";
  259. $bool = $this->db->query($sql, false);
  260. return 'ok';
  261. }
  262. public function createbiao($xu, $alltabls)
  263. {
  264. $biao = 'a'.$xu.'';
  265. $lognab = 'flow_log'.$biao.'';
  266. if(in_array(''.PREFIX.''.$lognab.'',$alltabls))return $this->createbiao($xu+1, $alltabls);
  267. $sql = 'ALTER TABLE `[Q]flow_log` RENAME TO `[Q]'.$lognab.'`;';
  268. $bool = $this->db->query($sql, false);
  269. if(!$bool)return returnerror('无法操作:'.$this->db->error().'');
  270. $sql = "CREATE TABLE `[Q]flow_log` (
  271. `id` int(11) NOT NULL AUTO_INCREMENT,
  272. `table` varchar(50) DEFAULT NULL,
  273. `mid` int(11) DEFAULT NULL,
  274. `status` tinyint(4) DEFAULT '0' COMMENT '1通过',
  275. `statusname` varchar(20) DEFAULT NULL COMMENT '状态名称',
  276. `name` varchar(50) DEFAULT NULL COMMENT '进程名称',
  277. `courseid` int(11) DEFAULT NULL,
  278. `optdt` datetime DEFAULT NULL COMMENT '操作时间',
  279. `explain` varchar(500) DEFAULT NULL COMMENT '说明',
  280. `ip` varchar(100) DEFAULT NULL,
  281. `web` varchar(100) DEFAULT NULL COMMENT '浏览器',
  282. `checkname` varchar(50) DEFAULT NULL COMMENT '审核人',
  283. `checkid` int(11) DEFAULT '0' COMMENT '审核人id',
  284. `modeid` smallint(6) DEFAULT NULL COMMENT '@模块Id',
  285. `color` varchar(10) DEFAULT NULL,
  286. `valid` tinyint(1) DEFAULT '1',
  287. `step` smallint(6) DEFAULT '0' COMMENT '步骤号',
  288. `qmimg` text COMMENT '签名的图片base64',
  289. `iszb` tinyint(1) DEFAULT '0' COMMENT '是否转办记录',
  290. PRIMARY KEY (`id`),
  291. KEY `table` (`table`,`mid`)
  292. ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='单据操作记录';
  293. ";
  294. $bool = $this->db->query($sql, false);
  295. if(!$bool)return returnerror('无法创建表:'.$this->db->error().'');
  296. return returnsuccess($biao);
  297. }
  298. }
粤ICP备19079148号