Exec.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. namespace app\admin\controller;
  3. use think\facade\Db;
  4. use think\App;
  5. use think\facade\Validate;
  6. class Exec extends Base{
  7. public function __construct(App $app) {
  8. parent::__construct($app);
  9. }
  10. public function list(){
  11. $param=$this->request->param(["name"=>"","type"=>"","status"=>"","companyNo"=>"",'relaComNo'=>'',"page"=>1,"size"=>15],"post","trim");
  12. $conditon =[["is_del","=",0],["type","=",0]];
  13. if($param['name']!='')$conditon[]=["name","like","%{$param['name']}%"];
  14. if($param['type']!='')$conditon[]=["type","=",$param['type']];
  15. if($param['companyNo']!='')$conditon[]=["companyNo","=",$param['companyNo']];
  16. if($param['relaComNo']!='')$conditon[]=["companyNo","=",$param['relaComNo']];
  17. if($param['status']!=='')$conditon[]=["status","=",$param['status']];
  18. $count=Db::name("exec")->where($conditon)->count();
  19. $total = ceil($count/$param['size']);
  20. $page =$param['page']>=$total ?intval($total) :intval($param['page']);
  21. $list=Db::name("exec")->where($conditon)->page($page,intval($param['size']))->select()->toArray();
  22. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  23. }
  24. public function query(){
  25. $param=$this->request->param(["name"=>"","status"=>"","companyNo"=>"",'relaComNo'=>'',"type"=>""],"post","trim");
  26. $conditon =[["is_del","=",0],["type","=",0]];
  27. if($param['name']!='')$conditon[]=["name","like","%{$param['name']}%"];
  28. if($param['type']!='')$conditon[]=["type","=",$param['type']];
  29. if($param['status']!=='')$conditon[]=["status","=",$param['status']];
  30. if($param['companyNo']!='')$conditon[]=["companyNo","=",$param['companyNo']];
  31. if($param['relaComNo']!='')$conditon[]=["companyNo","=",$param['relaComNo']];
  32. $list=Db::name("exec")->where($conditon)->select()->toArray();
  33. return app_show(0,"获取成功",$list);
  34. }
  35. public function add(){
  36. $param=$this->request->param(["name"=>"","companyNo"=>"",'relaComNo'=>'',"action"=>''],"post","trim");
  37. $valid=Validate::rule([
  38. "name|脚本名称"=>'require|max:255',
  39. "companyNo|业务公司"=>'requireWithout:relaComNo|max:255',
  40. "relaComNo|业务公司"=>'requireWithout:companyNo|max:255',
  41. ]);
  42. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  43. $companyNo = $param['companyNo']??($param['relaComNo']??"");
  44. $ist =Db::name("exec")->where(["name"=>$param['name'],"companyNo"=>$companyNo,"is_del"=>0])->findOrEmpty();
  45. if(!empty($ist))return error_show(1004,"同类型脚本名称已存在");
  46. $data=[
  47. "name"=>$param['name'],
  48. "apply_name"=>$this->uname,
  49. "apply_id"=>$this->uid,
  50. "companyNo"=>$companyNo,
  51. "companyName"=>Db::connect('mysql_sys')->name('headquarters')->where(["code"=>$companyNo])->value("name",""),
  52. "action"=>$param["action"]??"",
  53. "type"=>0,
  54. "status"=>0,
  55. "addtime"=>date("Y-m-d H:i:s"),
  56. "updatetime"=>date("Y-m-d H:i:s")
  57. ];
  58. $insert=Db::name("exec")->insert($data);
  59. return $insert? app_show("0","新建成功"):app_show("1004","新建失败");
  60. }
  61. public function status(){
  62. $param=$this->request->param(["id"=>"","status"=>""],"post","trim");
  63. if($param['id']=='')return error_show(1004,"参数id 不能为空");
  64. $log=Db::name("exec")->where(["id"=>$param['id']])->findOrEmpty();
  65. if(empty($log))return error_show(1004,"脚本不存在");
  66. if($log['is_del']==1) return error_show(1004,"脚本已删除");
  67. if($log['status']==$param['status']) return error_show(1004,"脚本状态已更新");
  68. if($log['action']==''&&$param['status']==1 ) return error_show(1004,'后端脚本还未上线');
  69. $del=Db::name("exec")->where(["id"=>$param['id']])->update(["status"=>$param['status'],"updatetime"=>date("Y-m-d H:i:s")]);
  70. return $del? app_show("0","更新成功"):app_show("1004","更新失败");
  71. }
  72. //新建脚本数据
  73. public function addlog(){
  74. $param=$this->request->param(["id"=>"","start"=>"","end"=>"","companyNo"=>"",'relaComNo'=>'',"type"=>""],"post","trim");
  75. $valid=Validate::rule([
  76. "id|脚本ID"=>'require|number|gt:0',
  77. "start|起始时间"=>'require|dateFormat:Y-m-d',
  78. "end|结束时间"=>'require|dateFormat:Y-m-d|gt:start',
  79. "companyNo|业务公司"=>'requireWithout:relaComNo|max:255',
  80. "relaComNo|业务公司"=>'requireWithout:companyNo|max:255',
  81. "type|执行类型"=>'require|number|in:1,2',
  82. ]);
  83. if($valid->check($param)==false) return error_show(1004,$valid->getError());
  84. $exec =Db::name("exec")->where("id",$param['id'])->findOrEmpty();
  85. if(empty($exec)) return error_show(1004,'未找到脚本数据');
  86. if($exec['action']=='') return error_show(1004,'后端脚本还未上线');
  87. $companyNo=$param['companyNo']??($param['relaComNo']??"");
  88. $data=[
  89. "name"=>$exec['name'],
  90. "companyNo"=>$companyNo,
  91. "companyName"=>Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$companyNo])->value("name",""),
  92. "start"=>date("Y-m-d 00:00:00",strtotime($param['start'])),
  93. "end"=>date("Y-m-d 23:59:59",strtotime($param['end'])),
  94. "apply_id"=>$this->uid,
  95. "apply_name"=>$this->uname,
  96. "action"=>$exec['action'],
  97. "down_url"=>'',
  98. "status"=>1,
  99. "remark"=>'',
  100. "type"=>$param["type"],
  101. "expiretime"=>$param["type"]==1? date("Y-m-d H:i:s"):date("Y-m-d 22:00:00"),
  102. "addtime"=> date("Y-m-d H:i:s"),
  103. "updatetime"=> date("Y-m-d H:i:s")
  104. ];
  105. $in=Db::name("exec_log")->insert($data);
  106. return $in? app_show("0","新建成功"):app_show("1004","新建失败");
  107. }
  108. public function loglist(){
  109. $param=$this->request->param(["name"=>"","apply_name"=>"","status"=>"","action"=>"","type"=>"","companyNo"=>"",'relaComNo'=>'',"page"=>1,"size"=>15],"post","trim");
  110. $where=[["is_del","=",0],["type","in",[1,2]],["addtime",">=",date("Y-m-d H:i:s",strtotime("-30 day"))]];
  111. $check = checkRole($this->roleid,147);
  112. if($check){
  113. $where[]=["apply_id","=",$this->uid];
  114. }
  115. if($param['name']!='')$where[]=["name","like","%{$param['name']}%"];
  116. if($param['apply_name']!='')$where[]=["apply_name","like","%{$param['apply_name']}%"];
  117. if($param['type']!='')$where[]=["type","=",$param['type']];
  118. if($param['status']!='')$where[]=["status","=",$param['status']];
  119. if($param['action']!='')$where[]=["action","=",$param['action']];
  120. if($param['companyNo']!='')$where[]=["companyNo","=",$param['companyNo']];
  121. if($param['relaComNo']!='')$where[]=["companyNo","=",$param['relaComNo']];
  122. $count=Db::name("exec_log")->where($where)->count();
  123. $total = ceil($count/$param['size']);
  124. $page =$param['page']<=$total ? intval($param['page']):intval($total);
  125. $list=Db::name("exec_log")->where($where)->page($page,intval($param['size']))->order("id desc")->select()
  126. ->toArray();
  127. return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
  128. }
  129. public function logdel(){
  130. $param=$this->request->param(["id"=>""],"post","trim");
  131. if($param['id']=='')return error_show(1004,"参数 id 不能为空");
  132. $log=Db::name("exec_log")->where(["id"=>$param['id']])->findOrEmpty();
  133. if(empty($log))return error_show(1004,"脚本记录不存在");
  134. if($log['is_del']==1) return error_show(1004,"脚本记录已删除");
  135. if(in_array($log['status'],[2,4])) return error_show(1004,"脚本执行中或已完成");
  136. $del=Db::name("exec_log")->where(["id"=>$param['id']])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
  137. return $del? app_show("0","删除成功"):app_show("1004","删除失败");
  138. }
  139. public function actionList(){
  140. $ation=[
  141. ["action"=>"A","name"=>'销售发票申请信息导出'],
  142. ["action"=>"B","name"=>'进项发票等级导出'],
  143. ["action"=>"C","name"=>'资金认领导出'],
  144. ["action"=>"D","name"=>'回款核销明细表'],
  145. ["action"=>"E","name"=>'回票明细表'],
  146. ["action"=>"F","name"=>'经营分析报表'],
  147. ["action"=>"G","name"=>'收入成本明细表'],
  148. ["action"=>"I","name"=>'应收台账表'],
  149. ["action"=>"J","name"=>'用友销票表'],
  150. ["action"=>"K","name"=>'采购单明细表'],
  151. ["action"=>"M","name"=>'对账单汇总表'],
  152. ["action"=>"N","name"=>'退货台账'],
  153. ["action"=>"W","name"=>'对账单采购单对照表'],
  154. ];
  155. return app_show(0,"获取成功",$ation);
  156. }
  157. }