123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- namespace app\admin\controller;
- use think\facade\Db;
- use think\App;
- use think\facade\Validate;
- class Exec extends Base{
- public function __construct(App $app) {
- parent::__construct($app);
- }
- public function list(){
- $param=$this->request->param(["name"=>"","type"=>"","status"=>"","companyNo"=>"",'relaComNo'=>'',"page"=>1,"size"=>15],"post","trim");
- $conditon =[["is_del","=",0],["type","=",0]];
- if($param['name']!='')$conditon[]=["name","like","%{$param['name']}%"];
- if($param['type']!='')$conditon[]=["type","=",$param['type']];
- if($param['companyNo']!='')$conditon[]=["companyNo","=",$param['companyNo']];
- if($param['relaComNo']!='')$conditon[]=["companyNo","=",$param['relaComNo']];
- if($param['status']!=='')$conditon[]=["status","=",$param['status']];
- $count=Db::name("exec")->where($conditon)->count();
- $total = ceil($count/$param['size']);
- $page =$param['page']>=$total ?intval($total) :intval($param['page']);
- $list=Db::name("exec")->where($conditon)->page($page,intval($param['size']))->select()->toArray();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function query(){
- $param=$this->request->param(["name"=>"","status"=>"","companyNo"=>"",'relaComNo'=>'',"type"=>""],"post","trim");
- $conditon =[["is_del","=",0],["type","=",0]];
- if($param['name']!='')$conditon[]=["name","like","%{$param['name']}%"];
- if($param['type']!='')$conditon[]=["type","=",$param['type']];
- if($param['status']!=='')$conditon[]=["status","=",$param['status']];
- if($param['companyNo']!='')$conditon[]=["companyNo","=",$param['companyNo']];
- if($param['relaComNo']!='')$conditon[]=["companyNo","=",$param['relaComNo']];
- $list=Db::name("exec")->where($conditon)->select()->toArray();
- return app_show(0,"获取成功",$list);
- }
- public function add(){
- $param=$this->request->param(["name"=>"","companyNo"=>"",'relaComNo'=>'',"action"=>''],"post","trim");
- $valid=Validate::rule([
- "name|脚本名称"=>'require|max:255',
- "companyNo|业务公司"=>'requireWithout:relaComNo|max:255',
- "relaComNo|业务公司"=>'requireWithout:companyNo|max:255',
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $companyNo = $param['companyNo']??($param['relaComNo']??"");
- $ist =Db::name("exec")->where(["name"=>$param['name'],"companyNo"=>$companyNo,"is_del"=>0])->findOrEmpty();
- if(!empty($ist))return error_show(1004,"同类型脚本名称已存在");
- $data=[
- "name"=>$param['name'],
- "apply_name"=>$this->uname,
- "apply_id"=>$this->uid,
- "companyNo"=>$companyNo,
- "companyName"=>Db::connect('mysql_sys')->name('headquarters')->where(["code"=>$companyNo])->value("name",""),
- "action"=>$param["action"]??"",
- "type"=>0,
- "status"=>0,
- "addtime"=>date("Y-m-d H:i:s"),
- "updatetime"=>date("Y-m-d H:i:s")
- ];
- $insert=Db::name("exec")->insert($data);
- return $insert? app_show("0","新建成功"):app_show("1004","新建失败");
- }
- public function status(){
- $param=$this->request->param(["id"=>"","status"=>""],"post","trim");
- if($param['id']=='')return error_show(1004,"参数id 不能为空");
- $log=Db::name("exec")->where(["id"=>$param['id']])->findOrEmpty();
- if(empty($log))return error_show(1004,"脚本不存在");
- if($log['is_del']==1) return error_show(1004,"脚本已删除");
- if($log['status']==$param['status']) return error_show(1004,"脚本状态已更新");
- if($log['action']==''&&$param['status']==1 ) return error_show(1004,'后端脚本还未上线');
- $del=Db::name("exec")->where(["id"=>$param['id']])->update(["status"=>$param['status'],"updatetime"=>date("Y-m-d H:i:s")]);
- return $del? app_show("0","更新成功"):app_show("1004","更新失败");
- }
- //新建脚本数据
- public function addlog(){
- $param=$this->request->param(["id"=>"","start"=>"","end"=>"","companyNo"=>"",'relaComNo'=>'',"type"=>""],"post","trim");
- $valid=Validate::rule([
- "id|脚本ID"=>'require|number|gt:0',
- "start|起始时间"=>'require|dateFormat:Y-m-d',
- "end|结束时间"=>'require|dateFormat:Y-m-d|gt:start',
- "companyNo|业务公司"=>'requireWithout:relaComNo|max:255',
- "relaComNo|业务公司"=>'requireWithout:companyNo|max:255',
- "type|执行类型"=>'require|number|in:1,2',
- ]);
- if($valid->check($param)==false) return error_show(1004,$valid->getError());
- $exec =Db::name("exec")->where("id",$param['id'])->findOrEmpty();
- if(empty($exec)) return error_show(1004,'未找到脚本数据');
- if($exec['action']=='') return error_show(1004,'后端脚本还未上线');
- $companyNo=$param['companyNo']??($param['relaComNo']??"");
- $data=[
- "name"=>$exec['name'],
- "companyNo"=>$companyNo,
- "companyName"=>Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$companyNo])->value("name",""),
- "start"=>date("Y-m-d 00:00:00",strtotime($param['start'])),
- "end"=>date("Y-m-d 23:59:59",strtotime($param['end'])),
- "apply_id"=>$this->uid,
- "apply_name"=>$this->uname,
- "action"=>$exec['action'],
- "down_url"=>'',
- "status"=>1,
- "remark"=>'',
- "type"=>$param["type"],
- "expiretime"=>$param["type"]==1? date("Y-m-d H:i:s"):date("Y-m-d 22:00:00"),
- "addtime"=> date("Y-m-d H:i:s"),
- "updatetime"=> date("Y-m-d H:i:s")
- ];
- $in=Db::name("exec_log")->insert($data);
- return $in? app_show("0","新建成功"):app_show("1004","新建失败");
- }
- public function loglist(){
- $param=$this->request->param(["name"=>"","apply_name"=>"","status"=>"","action"=>"","type"=>"","companyNo"=>"",'relaComNo'=>'',"page"=>1,"size"=>15],"post","trim");
- $where=[["is_del","=",0],["type","in",[1,2]],["addtime",">=",date("Y-m-d H:i:s",strtotime("-30 day"))]];
- $check = checkRole($this->roleid,147);
- if($check){
- $where[]=["apply_id","=",$this->uid];
- }
- if($param['name']!='')$where[]=["name","like","%{$param['name']}%"];
- if($param['apply_name']!='')$where[]=["apply_name","like","%{$param['apply_name']}%"];
- if($param['type']!='')$where[]=["type","=",$param['type']];
- if($param['status']!='')$where[]=["status","=",$param['status']];
- if($param['action']!='')$where[]=["action","=",$param['action']];
- if($param['companyNo']!='')$where[]=["companyNo","=",$param['companyNo']];
- if($param['relaComNo']!='')$where[]=["companyNo","=",$param['relaComNo']];
- $count=Db::name("exec_log")->where($where)->count();
- $total = ceil($count/$param['size']);
- $page =$param['page']<=$total ? intval($param['page']):intval($total);
- $list=Db::name("exec_log")->where($where)->page($page,intval($param['size']))->order("id desc")->select()
- ->toArray();
- return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
- }
- public function logdel(){
- $param=$this->request->param(["id"=>""],"post","trim");
- if($param['id']=='')return error_show(1004,"参数 id 不能为空");
- $log=Db::name("exec_log")->where(["id"=>$param['id']])->findOrEmpty();
- if(empty($log))return error_show(1004,"脚本记录不存在");
- if($log['is_del']==1) return error_show(1004,"脚本记录已删除");
- if(in_array($log['status'],[2,4])) return error_show(1004,"脚本执行中或已完成");
- $del=Db::name("exec_log")->where(["id"=>$param['id']])->update(["is_del"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
- return $del? app_show("0","删除成功"):app_show("1004","删除失败");
- }
- public function actionList(){
- $ation=[
- ["action"=>"A","name"=>'销售发票申请信息导出'],
- ["action"=>"B","name"=>'进项发票等级导出'],
- ["action"=>"C","name"=>'资金认领导出'],
- ["action"=>"D","name"=>'回款核销明细表'],
- ["action"=>"E","name"=>'回票明细表'],
- ["action"=>"F","name"=>'经营分析报表'],
- ["action"=>"G","name"=>'收入成本明细表'],
- ["action"=>"I","name"=>'应收台账表'],
- ["action"=>"J","name"=>'用友销票表'],
- ["action"=>"K","name"=>'采购单明细表'],
- ["action"=>"M","name"=>'对账单汇总表'],
- ["action"=>"N","name"=>'退货台账'],
- ["action"=>"W","name"=>'对账单采购单对照表'],
- ];
- return app_show(0,"获取成功",$ation);
- }
- }
|