Browse Source

Merge branch 'dev' of wugg/cxinv into master

wugg 2 years ago
parent
commit
c576347a62
6 changed files with 1232 additions and 0 deletions
  1. 159 0
      app/admin/controller/Exec.php
  2. 13 0
      app/admin/route/app.php
  3. 39 0
      app/command/ExecPush.php
  4. 838 0
      app/command/Report.php
  5. 180 0
      app/common.php
  6. 3 0
      config/console.php

+ 159 - 0
app/admin/controller/Exec.php

@@ -0,0 +1,159 @@
+<?php
+
+
+namespace app\admin\controller;
+
+use think\facade\Db;
+use think\App;
+use think\facade\Validate;
+class Exec extends \app\admin\BaseController{
+
+	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]];
+		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($param['page']):intval($total);
+		$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]];
+		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::name("supplier_info")->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::name("supplier_info")->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"=>$exec["type"],
+			"expiretime"=>$exec["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]];
+		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(["logid"=>""],"post","trim");
+		 if($param['logid']=='')return error_show(1004,"参数logid 不能为空");
+		 $log=Db::name("exec_log")->where(["id"=>$param['logid']])->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['logid']])->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"=>'对账单汇总表']
+			];
+		return app_show(0,"获取成功",$ation);
+	}
+}

+ 13 - 0
app/admin/route/app.php

@@ -220,6 +220,19 @@ Route::rule('pie','admin/Export/payInvoiceExport');//用友销票表
 Route::rule('pe','admin/Export/payExport');//对账单汇总
 Route::rule('cm','admin/Export/cgdManage');//采购单明细表
 
+Route::rule('execlist','admin/Exec/list');//脚本列表
+Route::rule('execstatus','admin/Exec/status');//脚本使用状态
+Route::rule('execadd','admin/Exec/add');//脚本新建
+Route::rule('execall','admin/Exec/query');//脚本列表全部
+Route::rule('execlogadd','admin/Exec/addlog');//添加脚本执行记录
+Route::rule('execloglist','admin/Exec/loglist');//脚本执行记录列表
+Route::rule('execlogdel','admin/Exec/logdel');//脚本执行记录删除
+Route::rule('execaction','admin/Exec/actionList');//后端已上线脚本
+
+
+
+
+
 route::rule("interadd","admin/InterOrder/create");//网络部录单
 route::rule("interedit","admin/InterOrder/save");//网络部录单
 route::rule("interlist","admin/InterOrder/list");//网络部录单列表

+ 39 - 0
app/command/ExecPush.php

@@ -0,0 +1,39 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Cache;use think\facade\Db;
+
+class ExecPush extends Command
+{
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('execpush')
+            ->setDescription('the execpush command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+    	$key = Cache::store("redis")->handler()->get("reportKey");
+    	if($key==1) return '';
+    	Cache::store("redis")->handler()->set("reportKey",1,180);
+    	$list =Db::name("exec_log")->where([["expiretime","<=",date("Y-m-d H:i:s")],["status","=",1],["is_del","=",
+    	0]])->select()->toArray();
+    	if(!empty($list)){
+    		foreach ($list as $value){
+    			Cache::store("redis")->handler()->lpush("Reportexec",json_encode($value,JSON_UNESCAPED_UNICODE));
+    			Db::name("exec_log")->where($value)->update(["status"=>4,"updatetime"=>date("Y-m-d H:i:s")]);
+    			$date=date("Y-m-d H:i:s");
+    			$output->writeln("[{$date}] 脚本记录{$value['id']}放入待执行中");
+    		}
+    	}
+    	Cache::store("redis")->handler()->set("reportKey",0);
+    }
+}

+ 838 - 0
app/command/Report.php

@@ -0,0 +1,838 @@
+<?php
+
+namespace app\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\input\Argument;
+use think\console\input\Option;
+use think\console\Output;
+use think\facade\Cache;use think\facade\Db;
+
+class Report extends Command
+{
+		//相关字段的文字转换
+	private $key='Reportexec';
+	private $param=[];
+	private $qrdType = [1 => '库存品', 2 => '非库存品', 3 => '采购反馈'];
+	private $qrdSource = [1 => '直接下单', 2 => '竞价转单', 3 => '项目转单', 4 => '平台导入', 5 => '有赞平台', 6 => '售后补换货',7=>'报备转单',8=>'支付渠道拆单'];
+	private $sendType = [1 => '包邮', 2 => '自提'];
+	private $pay_status = [1 => '未回', 2 => '部分回款', 3 => '已回'];
+	private $inv_status = [1 => '未开', 2 => '部分开票', 3 => '已开'];
+	private $cgd_inv_status = [1 => '未回', 2 => '部分回票', 3 => '已回'];
+	private $cgd_pay_status = [1 => '未付', 2 => '部分付款', 3 => '已付'];
+	private $invoice_pool_status = [1 => '财务审核通过', 2 => '待财务上传发票', 3 => '金税开票中/验票中', 4 => '开票成功', 5 => '开票失败', 6 => '发票退票/废弃', 7 => '取消申请', 8 => '财务驳回', 9 => '验票失败'];
+	private $cgdType = [1 => '库存', 2 => '非库存', 3 => '咨询'];
+	private $invoice_return_status = [0 => '待财务审核', 1 => '退票中', 2 => '退票成功', 3 => '审核驳回', 4 => '退票失败'];
+	private $sendStatus = [1=>'未发货',2=>'部分发货',3=>'全部发货'];
+
+    protected function configure()
+    {
+        // 指令配置
+        $this->setName('report')
+            ->setDescription('the report command');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+        // 指令输出
+
+        $Command = Cache::store('redis')->handler()->get('ExecCommand');
+        if($Command>=3) return '';
+		$info = Cache::store('redis')->handler()->rpop($this->key);
+		if($info==false) return '';
+		Cache::store('redis')->handler()->incrby('ExecCommand',1);
+        Db::startTrans();
+        try{
+        $info = json_decode($info,true);
+	    ini_set ('memory_limit', '512M') ;
+        $date=date("Y-m-d H:i:s");
+        $param = Db::name("exec_log")->where("id",$info['id'])->findOrEmpty();
+        if(isset($param) && !empty($param)){
+        if($param['is_del']==1) throw new \Exception("脚本记录已删除");
+        switch ($param['action']){
+			case 'A':
+				$method="A";
+				$file ='销售发票申请信息导出';
+				break;
+			case 'B':
+				$method="B";
+				$file ='进项发票等级导出';
+				break;
+			case 'C':
+				$method="C";
+				$file ='资金认领导出';
+				break;
+			case 'D':
+				$method="D";
+				$file = '回款核销明细表';
+				break;
+			case 'E':
+				$method="E";
+				$file='回票明细表';
+				break;
+			case 'F':
+				$method="F";
+				$file='经营分析报表';
+				break;
+			case 'G':
+				$method="G";
+				$file='收入成本明细表';
+				break;
+			case 'I':
+				$method="I";
+				$file='应收台账表';
+				break;
+			case 'J':
+				$method="J";
+				$file='用友销票表';
+				break;
+			case 'K':
+				$method="K";
+				$file='采购单明细表';
+				break;
+			case 'M':
+				$method="M";
+				$file='对账单汇总表';
+				break;
+			default:
+				$file='暂无数据';
+				$method="";
+				break;
+		}
+
+		if($method=='')  $output->writeln("[$date]【{$param['name']}】[{$param['apply_name']}]预约记录处理失败");
+		$data =$this->$method($param);
+		$url=excelSaveFile($data,$file);
+		 Db::name('exec_log')
+                    ->where(['id' => $param['id'], 'status' => 4])//status==1 待处理
+                    ->update([
+                        'status' => 2, //status==2 处理完成
+                        'down_url' => $url,
+                        'updatetime' => date('Y-m-d H:i:s')
+                    ]);
+		 $end = date("Y-m-d H:i:s");
+		$output->writeln("[$date]【{$param['name']}】[{$param['apply_name']}]预约记录处理完成 end:【{$end}】");
+
+        	}
+
+        }catch (\Exception $e){
+			Db::name('exec_log')
+                    ->where(['id' => $info['id'], 'status' =>4])//status==1 待处理
+                    ->update([
+                        'status' => 3, //status==2 处理失败
+                        'down_url' => '',
+                        "remark"=>$e->getMessage(),
+                        'updatetime' => date('Y-m-d H:i:s')
+                    ]);
+			 $output->writeln("[$date]【{$info['name']}】[{$info['apply_name']}]预约记录处理失败 message:【{$e->getMessage()}】");
+        }
+       Cache::store('redis')->handler()->decrby('ExecCommand',1);
+		Db::commit();
+    }
+
+    //销售发票申请信息导出
+	private function A($param=[])
+	{
+//		$param = $this->request->only(['start' => '', 'end' => '', 'status' => '', 'inv_type' => '', 'inv_out' => '', 'invNo' => '', 'relaComNo' => '', 'inv_number' => '', 'inv_code' => '', 'inv_company' => '', 'buyer_name' => '', 'apply_id' => '', 'apply_name' => '',], 'post', 'trim');
+		$where = [['a.is_del', '=', 0], ['e.status', 'in', [1, 2]]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+		if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["a.inv_out","=",$param['companyNo']];
+
+//		if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
+//		if ($param['inv_type'] != '') $where[] = ['a.inv_type', '=', $param['inv_type']];
+//		if ($param['inv_out'] != '') $where[] = ['a.inv_out', '=', $param['inv_out']];
+//		if ($param['invNo'] != '') $where[] = ['a.invNo', 'in', $param['invNo']];
+//		if ($param['relaComNo'] != '') $where[] = ['a.inv_out', '=', $param['relaComNo']];
+//		if ($param['inv_number'] != '') $where[] = ['c.inv_number', 'like', '%' . $param['inv_number'] . '%'];
+//		if ($param['inv_code'] != '') $where[] = ['c.inv_code', 'like', '%' . $param['inv_code'] . '%'];
+//		if ($param['inv_company'] != '') $where[] = ['a.inv_company', 'like', '%' . $param['inv_company'] . '%'];
+//		if ($param['buyer_name'] != '') $where[] = ['b.buyer_title', 'like', '%' . $param['buyer_name'] . '%'];
+//		if ($param['apply_id'] != '') $where[] = ['a.apply_id', '=', $param['apply_id']];
+//		if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
+
+		$open_type = [1 => '金税开票', 2 => '金税线下', 3 => '纯线下'];//开票方式
+		$inv_type = config('invoiceType.invoiceName');//开票种类(发票类型)
+
+		$list = Db::name('invoice_pool')
+		          ->alias('a')
+		          ->field('a.inv_out 卖方公司编码,a.inv_company 卖方公司名称,a.invNo 申请编号,f.department 申请部门,a.apply_name 申请人,b.buyer_title 发票买方公司名称,concat(b.buyer_code," ") 发票买方企业纳税识别号,b.buyer_addr 发票买方企业地址,b.buyer_mobile 发票买方企业联系方式,b.buyer_bank 发票买方企业收款银行,concat(b.buyer_bankNo," ") 发票买方企业财务账户,d.orderCode 公司订单号,b.buyer_title 订单企业客户,d.goodName 订单商品名,concat(g.inv_cat_code," ") 税收分类编码,g.inv_cat_name 税收分类名称,d.goodName 发票明细商品名称,CONCAT(d.catName,"*",d.goodName) 发票货物或应税劳务、服务名称,d.unitName 单位,d.goodNum 数量,d.goodPrice 单价,round(d.tax/100,2) 税率,d.totalPrice 总价,a.inv_type 开票种类,a.open_type 开票方式,a.remark 申请备注,c.remark 发票备注')
+		          ->leftJoin('invoice_pool_info b', 'a.invNo=b.invNo')
+		          ->leftJoin('invoice_ticket c', 'a.invNo=c.invNo AND c.type=0 AND c.status=1')
+		          ->leftJoin('invoice_good d', 'd.invNo=a.invNo')
+		          ->leftJoin('assoc e', 'e.viceCode=d.invNo AND e.orderCode=d.orderCode AND e.is_del=0')
+		          ->leftJoin('qrd_info f', 'f.sequenceNo=e.orderCode')
+		          ->leftJoin('good g', 'g.spuCode=d.goodNo')
+		          ->withAttr('开票方式', function ($val) use ($open_type) {
+			          return $open_type[$val] ?? '';
+		          })->withAttr('开票种类', function ($val) use ($inv_type) {
+				return $inv_type[$val] ?? '';
+			})
+		          ->where($where)
+		          ->order('a.addtime desc')
+		          ->cursor();
+		foreach ($list as $value){
+			yield $value;
+		}
+	}
+
+	//进项发票等级导出
+	private function B($param=[])
+	{
+//		$param = $this->request->only(['start' => '', 'end' => '', 'invType' => '', 'company' => '', 'relaComNo' => '', 'supplierNo' => '', 'hpNo' => '', 'payNo' => '', 'invoiceType' => '', 'status' => '', 'invoiceNumber' => '', 'checkApi' => '', 'invoiceCode' => '', 'open_start' => '', 'open_end' => '', 'apply_id' => '', 'apply_name' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
+//		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+//		if ($param['invType'] != '') $where[] = ['a.invType', '=', $param['invType']];
+//		if ($param['company'] != '') $where[] = ['b.companyNo', 'like', '%' . $param['company'] . '%'];
+//		if ($param['relaComNo'] != '') $where[] = ['b.companyNo|b.supplierNo', 'like', '%' . $param['relaComNo'] . '%'];
+//		if ($param['supplierNo'] != '') $where[] = ['b.supplierNo', '=', $param['supplierNo']];
+//		if ($param['hpNo'] != '') $where[] = ['a.hpNo', 'like', '%' . $param['hpNo'] . '%'];
+//		if ($param['payNo'] != '') $where[] = ['a.payNo', 'like', '%' . $param['payNo'] . '%'];
+//		if ($param['invoiceType'] != '') $where[] = ['a.invoiceType', '=', $param['invoiceType']];
+//		if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
+//		if ($param['invoiceNumber'] != '') $where[] = ['a.invoiceNumber', '=', $param['invoiceNumber']];
+//		if ($param['checkApi'] != '') $where[] = ['a.checkApi', '=', $param['checkApi']];
+//		if ($param['invoiceCode'] != '') $where[] = ['a.invoiceCode', '=', $param['invoiceCode']];
+//		if (($param['open_start'] != '') && ($param['open_end'] != '')) $where[] = ['a.open_time', 'between', [$param['open_start'], $param['open_end']]];
+//		if ($param['apply_id'] != '') $where[] = ['a.apply_id', '=', $param['apply_id']];
+//		if ($param['apply_name'] != '') $where[] = ['a.apply_name', 'like', '%' . $param['apply_name'] . '%'];
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+		if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["b.companyNo","=",$param['companyNo']];
+		$status = [1 => '待系统验证', 2 => '买方公司审核', 3 => '待买方公司认证', 4 => '认证成功', 5 => '验证失败', 6 => '买方审核驳回', 7 => '认证失败', 8 => '回票流程终止', 9 => '验证超次数', 10 => '回票已退'];//认证状态
+
+		$invoiceType = config('invoiceType.invoiceName');//开票种类(发票类型)
+
+		$list = Db::name('pay_invoice')
+		          ->alias('a')
+		          ->leftJoin('pay b', 'a.payNo=b.payNo')
+		          ->leftJoin('invoice_info c', 'c.hpNo=a.hpNo AND c.status=1')
+		          ->field('"" 序号,a.payNo,a.hpNo,a.addtime,a.invoiceNumber,a.open_time,b.supplierName,a.invoiceType,a.status,a.updatetime,a.remark,c.item_list,c.total')
+		          ->where($where)
+		          ->order('a.addtime desc')
+		          ->cursor();
+
+		$data = [];
+		$i = 1;
+		foreach ($list as $item) {
+
+			if ($item['item_list']) {
+				$item_list = json_decode($item['item_list'], true);
+				foreach ($item_list as $val) {
+					$tp = [
+						'序号' => $i++,
+						'回票申请编号' => $item['hpNo'],
+						'对账编号' => $item['payNo'],
+						'年' => date('Y', strtotime($item['addtime'])),
+						'月' => date('m', strtotime($item['addtime'])),
+						'发票号' => $item['invoiceNumber'],
+						'开票日期' => $item['open_time'],
+						'金额' => $val['amount'],
+						'税额' => $val['tax'],
+						'税率' => $val['tax_rate'],
+						'总额' => $item['total'],
+						'供应商' => $item['supplierName'],
+						'业务类型' => '采购回票',
+						'发票类型' => $invoiceType[$item['invoiceType']] ?? '',
+						'认证状态' => $status[$item['status']] ?? '',
+						'认证时间' => $item['updatetime'],
+						'备注' => $item['remark'],
+					];
+
+					yield  $tp;
+				}
+			} else {
+				$tp = [
+					'序号' => $i++,
+					'回票申请编号' => $item['hpNo'],
+					'对账编号' => $item['payNo'],
+					'年' => date('Y', strtotime($item['addtime'])),
+					'月' => date('m', strtotime($item['addtime'])),
+					'发票号' => $item['invoiceNumber'],
+					'开票日期' => $item['open_time'],
+					'金额' => '',
+					'税额' => '',
+					'税率' => '',
+					'总额' => $item['total'],
+					'供应商' => $item['supplierName'],
+					'业务类型' => '采购回票',
+					'发票类型' => $invoiceType[$item['invoiceType']] ?? '',
+					'认证状态' => $status[$item['status']] ?? '',
+					'认证时间' => $item['updatetime'],
+					'备注' => $item['remark'],
+				];
+				yield  $tp;
+			}
+		}
+	}
+
+	//资金认领导出
+	private function C($param=[])
+	{
+//		$param = $this->request->only(['start' => '', 'end' => '', 'name' => '', 'bank' => '', 'status' => '', 'tradNo' => '', 'company' => '', 'userd_lower' => '', 'used_upper' => ''], 'post', 'trim');
+		$where = [['a.is_del', '=', 0], ['b.is_del', '=', 0]];
+//		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.trade_time', 'between', [$param['start'], $param['end']]];
+//		if ($param['name'] != '') $where[] = ['a.trade_out', 'like', '%' . $param['name'] . '%'];
+//		if ($param['bank'] != '') $where[] = ['a.trade_bank', 'like', '%' . $param['bank'] . '%'];
+//		if ($param['status'] != '') $where[] = ['a.status', '=', $param['status']];
+//		if ($param['tradNo'] != '') $where[] = ['a.tradNo', 'like', '%' . $param['tradNo'] . '%'];
+//		if ($param['company'] != '') $where[] = ['a.companyNo', 'like', '%' . $param['company'] . '%'];
+//		if ($param['userd_lower'] != '') $where[] = ['a.used_fee', '>=', $param['userd_lower']];
+//		if ($param['used_upper'] != '') $where[] = ['a.used_fee', '<=', $param['used_upper']];
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+		if (($param['companyNo'] != '') && ($param['companyNo'] != '')) $where[] = ["a.companyNo","=",$param['companyNo']];
+		$status = [1 => '未认领', 2 => '部分认领', 3 => '全部认领'];//状态
+		$b_status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '退款', 5 => '解除认领'];//认领审批状态
+
+		$list = Db::name('trade')
+		          ->alias('a')
+		          ->field('a.companyNo 收款方公司编码,a.trade_in 收款单位名称,a.trade_account 付款银行单位账号,a.trade_out 付款银行单位名称,a.trade_remark 付款备注,a.trade_time 交易时间,a.tradNo 资金编号,a.status 状态,a.total_fee 收入金额,a.balance 未认领金额,a.used_fee 已认领金额,b.logNo 资金认领编号,a.customerNo 认领企业,c.orderCode 订单编号,d.poCode 平台编号,d.goodName 产品名称,d.ownerName 资金创建人,c.apply_name 认领创建人,b.status 认领审批状态,b.remark 驳回原因')
+		          ->leftJoin('trade_pool b', 'b.tradNo=a.tradNo')
+		          ->leftJoin('assoc c', 'c.viceCode=b.logNo and c.type=2 and c.status<>3')
+		          ->leftJoin('qrd_info d', 'd.sequenceNo=c.orderCode')
+		          ->withAttr('状态', function ($val) use ($status) {
+			          return $status[$val] ?? '';
+		          })->withAttr('认领审批状态', function ($val) use ($b_status) {
+				return $b_status[$val] ?? '';
+			})
+		          ->where($where)
+		          ->order('a.trade_time desc')
+		          ->cursor();
+		foreach ($list as $value){
+			yield $value;
+		}
+	}
+
+	//回款核销明细表
+	private function D($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0],['b.status',">=",2],["b.type","=",2]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['b.addtime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
+
+		$data = Db::name('assoc')
+		          ->alias('b')
+		          ->field('DATE_FORMAT(b.addtime,\'%Y\') 年,DATE_FORMAT(b.addtime,\'%m\') 月,DATE_FORMAT(b.addtime,\'%d\') 日,a.companyName 业务公司名称,a.companyNo 业务公司编号,b.viceCode 资金认领编号,c.tradNo 资金编号,c.total_fee 本次核销金额,c.addtime 本次核销时间,c.status 资金认领状态,a.sequenceNo 确认单编号,a.department 业务员部门,a.ownerName 业务员,a.platName 平台类型,a.qrdSource 确认单类型,a.qrdType 商品类型,a.poCode PO编号,a.customerAttr 客户属性,a.branch 分公司,a.customerName 客户名称,a.firstCat 一级分类,a.goodName 产品名称,round(a.tax/100,2) 税点,(a.goodNum-a.thNum) 下单数量,a.goodPrice 销售单价,(a.totalPrice-a.th_fee) 销售总额')
+		          ->leftJoin('qrd_info a', 'b.orderCode=a.sequenceNo')
+		          ->leftJoin('trade_pool c', 'c.logNo=b.viceCode')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+
+		//资金认领状态
+		$status = [1 => '待审批', 2 => '审批通过', 3 => '审批驳回', 4 => '已解除认领', 5 => '已取消认领'];
+
+		//        $list = [];
+
+		foreach ($data as $value) {
+			$value['资金认领状态'] = $status[$value['资金认领状态']] ?? '';
+			$value['确认单类型'] = $this->qrdSource[$value['确认单类型']] ?? '';
+			$value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
+			yield $value;
+		}
+		//
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('回款核销明细表', array_keys($list[0]), $list);
+
+	}
+
+	//回票明细表
+	private function E($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0], ['b.is_del', '=', 0], ['c.is_del', '=', 0], ['d.is_del', '=', 0]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.check_time', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['b.companyNo', '=', $param['companyNo']];
+
+		$data = Db::name('pay_invoice')
+		          ->alias('a')
+		          ->field('d.cgdTime 采购单下单日期,b.companyName 业务公司名称,b.companyNo 业务公司编号,a.hpNo 对账回票编号,a.payNo 对账单号,c.cgdNo 采购单编号,a.check_time 本次回票时间,a.invoiceNumber 发票号,a.inv_amount 本次回票金额,a.inv_subtotal_amount 不含税采购成本,
+            "" 税额,
+            "" 票面税率,
+            d.companyName 公司回票抬头,d.goodNo 商品编号,d.firstCat 一级分类,d.fundCode 核算码,d.goodName 商品名称,d.goodNum 商品数量,d.goodUnit 单位,d.cgdSource 采购单类型,d.ownerName 采购员,d.supplierName 供应商名称,d.supplierNo 供应商编号,d.goodType 商品类型,round(d.tax/100,2) 税率,d.packPrice 包装费,d.certPrice 证书费,d.markPrice 加标费,d.openPrice 开模费,d.costPrice 成本工艺费,d.deliveryPrice 物流费,d.barePrice 成本单价,d.diff_weight 工差,d.diff_fee 工差金额,d.goodPrice 单价,d.totalPrice 采购总货款,d.qrdCode 确认单编号,d.bkCode 备库编号,d.thNum 退货数量,d.th_fee 退货金额,e.item_list')
+		          ->leftJoin('pay b', 'a.payNo=b.payNo')
+		          ->leftJoin('pay_info c', 'c.payNo=a.payNo')
+		          ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
+		          ->leftJoin('invoice_info e', 'e.payNo=a.payNo')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+
+		//采购单类型
+		$cgdSource = [1 => '直接下单', 2 => '咨询', 3 => '项目', 4 => '平台', 5 => '有赞'];
+		//商品类型
+		$goodType = [1 => '正常商品', 2 => '赠品', 3 => '样品'];
+
+		//        $list = [];
+
+		foreach ($data as $value) {
+			$value['采购单类型'] = $cgdSource[$value['采购单类型']] ?? '';
+			$value['商品类型'] = $goodType[$value['商品类型']] ?? '';
+
+			$item_list = json_decode($value['item_list'], true);
+
+			unset($value['item_list']);
+			foreach ($item_list as $item) {
+				$value['税额']= $item['tax'] ?? '';
+				$value['票面税率']= $item['tax_rate'] ?? '';
+				//                $list = array_merge($value, [
+				//                    '税额' => $item['tax'] ?? '',
+				//                    '票面税率' => $item['tax_rate'] ?? '',
+				//                ]);
+				yield $value;
+			}
+
+		}
+
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('回票明细表', array_keys($list[0]), $list);
+
+	}
+
+	//经营分析报表
+	private function F($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
+
+		$data = Db::name('qrd_info')
+		          ->alias('a')
+		          ->field('
+            DATE_FORMAT(a.createdTime,\'%Y\') 年,
+            DATE_FORMAT(a.createdTime,\'%m\') 月,
+            DATE_FORMAT(a.createdTime,\'%d\') 日,
+            a.companyName 业务公司名称,
+            a.companyNo 业务公司编号,
+            a.department 销售部门,
+            a.ownerName 销售员,
+            a.qrdSource 订单来源,
+            "" 活动类型,
+            a.sequenceNo 确认单编号,
+            a.cxCode 销售订单号,
+            b.bkCode 备库单编号,
+            b.sequenceNo 采购单单号,
+            a.platName 平台类型,
+            a.poCode PO编号,
+            a.customerAttr 客户属性,
+            a.branch 分公司,
+            a.customerName 客户名称,
+            a.goodNo 商品编码,
+            a.firstCat 一级分类,
+            a.secCat 二级分类,
+            a.thirdCat 三级分类,
+            a.goodName 产品名称,
+            a.goodUnit 单位,
+            a.goodNum 下单数量,
+            a.goodPrice 销售单价,
+            a.totalPrice 销售总额,
+            round(a.tax/100,2) 税点,
+            b.ownerName 采购员,
+            b.goodPrice 采购裸价,
+            b.markPrice 加标费,
+            b.packPrice 包装费,
+            b.certPrice 证书费,
+            b.openPrice 开模费,
+            b.costPrice 工艺费,
+            b.deliveryPrice 物流费,
+            b.goodPrice 采购单价合计,
+            ifnull(b.totalPrice,a.total_origin_price) 采购总货款,
+            (a.totalPrice -ifnull(b.totalPrice,a.total_origin_price))  毛利润,
+            round((a.totalPrice -ifnull(b.totalPrice,a.total_origin_price))/a.totalPrice,2) 毛利率,
+            round(b.tax/100,2) 采购税点,
+            round(b.totalPrice/(1+ round(b.tax/100,2)),2) 不含税采购成本,
+            a.qrdType 库存性质,
+            b.supplierName 供应商名称,
+            b.sendType 发货方式,
+            a.thNum 退货数量,
+            a.fundCode 财务核算编码')
+		          ->leftJoin('cgd_info b', 'b.qrdCode=a.sequenceNo and b.is_del=0')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+
+		$list = [];
+
+		foreach ($data as $value) {
+			$value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
+			$value['库存性质'] = $this->qrdType[$value['库存性质']] ?? '';
+			//            $value['开票状态'] = $this->inv_status[$value['开票状态']] ?? '';
+			//            $value['回款状态'] = $this->pay_status[$value['回款状态']] ?? '';
+			$value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
+
+			$value['毛利润'] = round(bcsub($value['销售总额'], $value['采购总货款'], 3), 2);
+			$value['毛利率'] = $value['销售总额'] == 0 ? 0 : round(bcmul(bcsub(1, bcdiv($value['采购总货款'], $value['销售总额'], 5), 5), 100), 2) . '%';
+			$value['不含税采购成本'] = round(bcdiv($value['采购总货款'], bcadd(1,$value['采购税点']), 3), 2);
+
+			yield $value;
+		}
+
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('经营分析报表', array_keys($list[0]), $list);
+
+	}
+
+	//收入成本明细表
+	private function G($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0], ['d.is_del', '=', 0], ['a.status', '>=', 4]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['a.inv_out', '=', $param['companyNo']];
+
+		$data = Db::name('invoice_pool')
+		          ->alias('a')
+		          ->field('
+            a.invNo 发票申请编号,
+            d.orderCode 确认单编号,
+            e.cxCode 销售主单编号,
+            e.qrdSource 销售来源,
+            b.seller_title 销售方抬头,
+            e.department 业务部门,
+            e.ownerName 业务人员,
+           ifnull((SELECT goodNum from cfp_invoice_good w where w.invNo =a.invNo and w.orderCode=e.sequenceNo),"") 本次开票数量,
+            d.cancel_fee 本次开票金额,
+            c.open_date 本次开票时间,
+            c.inv_number 发票号,
+            round(e.tax/100,2) 开票税点,
+            a.status 开票状态,
+            e.customerName 客户名称,
+            e.fundCode 财务核算码,
+            e.firstCat 一级分类,
+            e.secCat 二级分类,
+            e.thirdCat 三级分类,
+            e.goodNo 产品编号,
+            e.goodName 产品名称,
+            f.sequenceNo 采购单编号,
+            f.supplierName 卖出方公司,
+            f.sendType 发货方式,
+            e.qrdType 商品类型,
+            f.ownerName 采购员,
+            ifnull(f.goodNum,e.goodNum) 采购下单数量,
+            f.barePrice 采购裸价,            
+            f.markPrice 加标费,
+            f.packPrice 包装费,
+            f.certPrice 证书费,
+            f.openPrice 开模费,
+            f.costPrice 工艺费,
+            f.deliveryPrice 物流费,
+            f.goodPrice 成本合计,
+            ifnull(f.totalPrice,e.total_origin_price) 采购货款,
+            round(f.tax/100,2) 采购单税点,
+            g.returnCode 退票编号,
+            if(g.returnCode<>"",a.inv_value,"") 退票金额,
+            g.status 退票状态,
+            g.return_type 退票方式,
+            f.thNum 退货数量,
+            f.th_fee 退货金额            
+            ')
+		          ->leftJoin('invoice_pool_info b', 'b.invNo=a.invNo')
+		          ->leftJoin('invoice_ticket c', 'c.invNo=a.invNo and c.type=0 and c.status=1')
+		          ->leftJoin('assoc d', 'd.viceCode=a.invNo and d.type=1')
+		          ->leftJoin('qrd_info e', 'e.sequenceNo=d.orderCode')
+		          ->leftJoin('cgd_info f', 'f.qrdCode=d.orderCode')
+		          ->leftJoin('invoice_return g', 'g.invNo=a.invNo and g.status=2')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+
+		$list = [];
+
+		foreach ($data as $value) {
+			$value['开票状态'] = $this->invoice_pool_status[$value['开票状态']] ?? '';
+			$value['发货方式'] = $this->sendType[$value['发货方式']] ?? '';
+			$value['商品类型'] = $this->qrdType[$value['商品类型']] ?? '';
+			$value['退票状态'] = $this->invoice_return_status[$value['退票状态']] ?? '';
+			$value['销售来源'] = $this->qrdSource[$value['销售来源']] ?? '';
+			yield $value;
+		}
+
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('收入成本明细表', array_keys($list[0]), $list);
+
+	}
+
+	//应收台账表
+	private function I($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.createdTime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['a.companyNo', '=', $param['companyNo']];
+
+		$data = Db::name('qrd_info')
+		          ->alias('a')
+		          ->field('
+            a.createdTime 下单时间,        
+            a.companyName 业务公司名称,
+            a.companyNo 业务公司编号,
+            a.sequenceNo 业务订单编号,
+            a.cxCode 销售订单主编号,
+            a.department 销售部门,
+            a.ownerName 销售员,
+            a.qrdSource 订单来源,
+            a.platName 平台类型,
+            a.poCode PO编号,
+            a.customerName 客户名称,
+            a.customerAttr 客户属性,
+            a.branch 客户分公司,
+            a.firstCat 一级分类,
+            a.goodName 产品名称,
+            round(a.tax/100,2) 税点,
+            (a.goodNum - a.thNum) 下单数量,
+            a.goodPrice 销售单价,
+            a.totalPrice 销售总额,
+            a.th_fee 退货总额,
+            a.pay_status 回款状态,
+            a.apay_fee 总已回款,
+            a.pay_fee 回款中,
+            a.wpay_fee 总未回款,
+            a.pay_tag_fee 回款标签金额,
+            a.inv_status 开票状态,
+            a.ainv_fee 总已开票,
+            a.inv_fee 开票中,
+            a.winv_fee 总未开票,
+            a.inv_tag_fee 开票标签金额,
+            a.invtime 最近开票时间,
+            "" 业务提票时间,
+            a.paytime 最近回款时间,
+            0 账期,
+            0 比率,
+            "" 订单是否超期,
+            "" 开票是否超期,
+            a.sendStatus 发货状态,
+            "" 最近一次发货时间            
+            ')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+		//        echo Db::name('qrd_info')->getLastSql();die;
+		$time = time();
+
+		foreach ($data as $value) {
+			$value['订单来源'] = $this->qrdSource[$value['订单来源']] ?? '';
+			$value['回款状态'] = $this->pay_status[$value['回款状态']] ?? '';
+			$value['开票状态'] = $this->inv_status[$value['开票状态']] ?? '';
+			$value['发货状态'] = $this->sendStatus[$value['发货状态']] ?? '';
+			$value['业务提票时间'] =Db::name("assoc")->where(["type"=>1,"status"=>[1,2],"is_del"=>0,'orderCode'=>$value['业务订单编号']])
+			                    ->order("id desc")->value('addtime','');
+			//计算账期
+			$value['账期'] = round(bcdiv(bcsub($time,strtotime($value['最近回款时间']??$value['下单时间']), 3), 86400, 3),
+				2);
+			$value['比率'] = round(bcdiv($value['账期'], 30, 1));
+			$value['订单是否超期'] = $value['比率'] > 6 ? '是' : '否';
+
+			$value['开票是否超期'] = round(bcdiv(bcsub($time, strtotime($value['最近开票时间']??$value['下单时间']), 1), 86400, 1)) > 15 ? '是' : '否';
+
+			$value['最近一次发货时间'] = Db::table('fh_source')
+			                       ->where(['qrdNo' => $value['业务订单编号']])
+			                       ->order(['id' => 'desc'])
+			                       ->value('send_date', '');
+			yield $value;
+		}
+
+	}
+
+	//用友销票表
+	private function J($param=[])
+	{
+//		$param = $this->request->only(['company' => '', 'start' => '', 'end' => ''], 'post', 'trim');
+
+		$where = [['a.is_del', '=', 0], ['c.is_del', '=', 0], ['d.is_del', '=', 0], ['e.is_del', '=', 0]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.addtime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['e.companyNo', '=', $param['companyNo']];
+
+		$data = Db::name('pay_invoice')
+		          ->alias('a')
+		          ->field('
+            d.companyName 回票业务公司名称,
+            a.hpNo 回票编码,
+            c.cgdNo 采购单编号,
+            d.fundCode 财务核算编码,
+            d.goodName 产品名称,
+            d.supplierName 供应商名称,
+            a.invoiceNumber 发票号,
+            b.item_list,
+            "" 发票货物或应税劳务、服务名称,
+            "" 回票数量,
+            "" 本次回票价款,
+            "" 本次回票税额,
+            "" 回票税率,
+            b.total 本次回票总金额,
+            a.check_time 本次回票时间
+            ')
+		          ->leftJoin('invoice_info b', 'b.payNo=a.payNo')
+		          ->leftJoin('pay_info c', 'c.payNo=a.payNo')
+		          ->leftJoin('cgd_info d', 'd.sequenceNo=c.cgdNo')
+		          ->leftJoin('pay e', 'e.payNo=a.payNo')
+		          ->where($where)
+		          ->order(['a.id' => 'desc'])
+		          ->cursor();
+
+		$list = [];
+
+		foreach ($data as $value) {
+
+			$item_list = json_decode($value['item_list'], true);
+			unset($value['item_list']);
+			foreach ($item_list as $item) {
+				$list = array_merge($value, [
+					'发票货物或应税劳务、服务名称' => $item['name'] ?? '',
+					'回票数量' => $item['quantity'] ?? '',
+					'本次回票价款' => $item['amount'] ?? '',
+					'本次回票税额' => $item['tax'] ?? '',
+					'回票税率' => $item['tax_rate'] ?? '',
+				]);
+				yield $list;
+
+			}
+		}
+//		return $list;
+	}
+
+	/** 采购单管理数据
+	 * @throws \PHPExcel_Exception
+	 * @throws \PHPExcel_Reader_Exception
+	 * @throws \PHPExcel_Writer_Exception
+	 * @throws \think\db\exception\DataNotFoundException
+	 * @throws \think\db\exception\DbException
+	 * @throws \think\db\exception\ModelNotFoundException
+	 */
+	private function K($param=[])
+	{
+//		$param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => '', "supplierNo" => ''], 'post', 'trim');
+
+		$where = [];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['createdTime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
+//		if ($param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
+		$data = Db::name("cgd_info")->where($where)
+		          ->field("
+        sequenceNo '采购单编号',
+        companyName '业务企业',
+        supplierName '供应商名称',
+        ownerName '采购员',
+        department '采购部门',
+        createdTime '采购时间',
+        cgdType '采购单类型',
+        if(qrdCode='',bkCode,qrdCode) '确认单编号/备库单编号',
+        cxCode '销售单主单号',
+        goodNo '商品编号',
+        goodName '商品名称',
+        firstCat '一级分类',
+        secCat '二级分类',
+        thirdCat '三级分类',
+        fundCode '核算码',
+       round(tax/100,2) '税率',
+        barePrice '裸价',
+        markPrice '加标费',
+        certPrice '证书费',
+        openPrice '开模费',
+        packPrice '包装费',
+        costPrice '工艺费',
+        deliveryPrice '物流费',
+        goodPrice '单价',
+        isStock '是否库存',
+        diff_fee '工差金额',
+        goodNum '商品数量',
+        totalPrice '总价',
+        sendStatus '发货状态',
+        '' as '对账编号',
+        '' as '付款状态',
+        '' as '回票状态'
+        ")->cursor();
+		$list = [];
+		foreach ($data as $value) {
+
+			$value['采购单类型'] = $this->cgdType[$value['采购单类型']];
+			$payinfo = Db::name("pay_info")->alias("a")
+			             ->leftJoin("pay b", "a.payNo=b.payNo and b.status=2")
+			             ->where(["a.status" => 1, "a.is_del" => 0,'cgdNo'=>$value['采购单编号']])
+			             ->field("b.payNo,b.inv_status,b.pay_status")->find();
+			$value['对账编号'] = $payinfo['payNo'] ?? "";
+			$value['付款状态'] = $this->cgd_pay_status[$payinfo['pay_status'] ?? "1"];
+			$value['回票状态'] = $this->cgd_inv_status[$payinfo['inv_status'] ?? "1"];
+			$value['是否库存'] = $value['是否库存']==1?'是':'否';
+			$value['发货状态'] = $this->sendStatus[$value['发货状态']];
+			yield $value;
+		}
+
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('采购单明细表', array_keys($list[0]), $list);
+	}
+
+	/**
+	 * 对账单汇总表
+	 */
+	private function M($param=[])
+	{
+//		$param = $this->request->only(['companyNo' => '', 'start' => '', 'end' => '', "supplierNo" => ''], 'post', 'trim');
+
+		$where = [["is_del", "=", 0], ["status", "=", 2]];
+
+		if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['addtime', 'between', [$param['start'], $param['end']]];
+		if ($param['companyNo'] != '') $where[] = ['companyNo', '=', $param['companyNo']];
+//		if ($param['supplierNo'] != '') $where[] = ['supplierNo', '=', $param['supplierNo']];
+		$data = Db::name("pay")->where($where)
+		          ->field("
+        companyName '业务公司',
+        apply_name '申请人',
+        addtime '申请时间',
+        supplierName '供应商名称',
+         '' as '付款时间',
+         payNo '对账编号',
+         total_fee '对账总额',
+         apay_fee '已付款',
+         pay_fee '付款中',
+         wpay_fee '未付款',
+         pay_status '付款状态',
+         pay_tag_fee '付款加签金额',
+         pay_tag as '付款加签时间',
+         '' as '付款标签名称',
+         ainv_fee '已回票',
+         inv_fee '回票中',
+         winv_fee '未回票',
+         inv_status '回票状态',
+         inv_tag_fee '回票加签金额',
+         inv_tag as '回票加签时间',
+         '' as '回票标签名称',
+         remark '备注'
+        ")->cursor();
+		foreach ($data as $value) {
+			$tag = Db::name("tag_log")->alias("a")->leftJoin("order_tag b", "a.tag_id=b.id")->where(["a.code" =>
+				$value['对账编号'], "a.status" => 1])->column("a.addtime,b.tag_name", "b.type");
+			$value['付款加签时间'] = $tag[1]['addtime'] ?? "";
+			$value['回票加签时间'] = $tag[2]['addtime'] ?? "";
+			$value['回票标签名称'] = $tag[2]['tag_name'] ?? "";
+			$value['付款标签名称'] = $tag[1]['tag_name']?? "";
+			$value['付款状态'] = $this->pay_status[$value['付款状态']];
+			$value['回票状态'] = $this->inv_status[$value['回票状态']];
+			$value['付款时间'] = Db::name("pay_payment")->where(['payNo'=>$value['对账编号'],"is_del"=>0])->order("id desc")
+			                   ->value('return_time','');
+			yield $value;
+		}
+		//        if (empty($list)) $list[] = ['导出数据为空' => ''];
+		//
+		//        excelExport('订单对账汇总表', array_keys($list[0]), $list);
+	}
+}

+ 180 - 0
app/common.php

@@ -3,6 +3,7 @@
 use think\facade\Config;
 use think\facade\Db;
 use think\facade\Filesystem;
+use tp5er\thinkCsv\Export;
 // 应用公共文件
 function app_show($code=0,$message="",$data=[]){
     $result = ['code'=>$code,"message"=>$message,"data"=>$data];
@@ -478,6 +479,66 @@ function excelExport($fileName = '', $headArr = [], $data = [])
 
 }
 
+if(!function_exists("Csv_save")){
+	function Csv_save($fileName,$headArr =[],$data=[],$num=10000){
+	  /*
+ * 导出数据生成csv文件
+ * @param file_name string 文件名
+ * @param headArr array 表头
+ * @param $db \think\db\Query 使用Db方法后生成的对象实例
+ * @param callback 回调函数,一般用在对查询结果进行二次处理的时候(例如二次计算,将状态等值由数字转变为文本,额外添加字段等)
+ */
+
+    set_time_limit(0);//让程序一直运行
+    $fileName .= date('_Y_m_d');//文件名拼接日期
+    header('Content-Encoding:UTF-8');
+    header("Content-type:application/vnd.ms-excel;charset=UTF-8");
+    header('Content-Disposition:attachment;filename="' . $fileName . '.csv"');
+    $fp = fopen('php://output', 'a');//打开php标准输出流
+    fwrite($fp, chr(0xEF) . chr(0xBB) . chr(0xBF));//添加bom头,以UTF-8编码导出的csv文件,如果文件头未添加bom头,打开会出现乱码
+
+    try {
+
+        if (!empty($headArr)) fputcsv($fp, $headArr);//添加导出标题
+        $max = PHP_INT_MAX;
+        $count=0;//阈值
+
+        //写入数据
+        for ($i = 1; $i > 0; $i++) {
+
+
+            $has_data = false;//默认没有查询到数据
+            foreach ($data as $k => $value) {
+//                $max = $value[$pk];//维护最大值
+//                $has_data = true;//存在查询数据
+//                if ($function) $value = $function($value);//调用回调函数处理
+
+                if (empty($headArr)) {
+                    $headArr = array_keys($value);
+                    fputcsv($fp, $headArr);//添加导出标题
+                }
+
+                fputcsv($fp, $value);
+                if (($k + 1) % $num == 0) {
+                    ob_flush();//清空缓存,释放内存
+                    flush();
+                }
+                $count++;//阈值自增
+            }
+            if ($has_data === false) break;//结束循环
+            if($count>=1000000) throw new \think\Exception('超出文件的最大显示行数,请根据条件分批次导出数据或使用预约导出功能,更多问题请联系开发人员');
+        }
+    }catch (\think\Exception $exception){
+        fputcsv($fp,[$exception->getMessage()]);
+    }
+    ob_flush();
+    flush();
+    ob_end_clean();
+    fclose($fp);
+    exit();
+	}
+}
+
 if(!function_exists('menuAction')){
 	function menuAction($row,&$list=[]){
 		$temp=[];
@@ -499,3 +560,122 @@ if(!function_exists('menuAction')){
 	}
 }
 
+/**
+ * 批量生成多个文件excel,生成压缩包,保存到本地,返回文件链接
+ * datas 生成器
+ * header array 头部字段
+ * filename string 文件名
+ */
+if (!function_exists('excelSaveFile')) {
+    function excelSaveFile($datas, string $filename = '')
+    {
+
+//        $urls = [];
+        $dir = root_path() . 'public/storage/report/' . date("YmdHis") . "/";
+        if (!is_dir($dir)) mkdir($dir, 0777, true);
+
+//        foreach ($datas as $item) {
+        PHPExcel_Settings::setCacheStorageMethod();
+        PHPExcel_CachedObjectStorageFactory::cache_in_memory_gzip;//单元格缓存为MemoryGZip
+        $objPHPExcel = new PHPExcel();
+
+        $keyA = 0; // 设置表头
+
+        $column = 2;
+        $objActSheet = $objPHPExcel->getActiveSheet();
+
+        foreach ($datas as $key => $rows) { // 行写入
+
+            //第一行取key作表头
+            if($key==0){
+                $objPHPExcel->getProperties();
+                foreach ($rows as $k=>$v) {
+                    $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
+                    $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $k);
+                    $keyA += 1;
+                }
+            }
+
+            //写入列
+            $span = 0;
+            foreach ($rows as $keyName => $value) {
+                //判断数据是否有数组,如果有数组,转换成字符串
+                if (is_array($value)) $value = implode("、", $value);
+
+                $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
+                $span++;
+            }
+            $column++;
+        }
+
+        $file = $filename . ".xls";
+        $objPHPExcel->setActiveSheetIndex(0);
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
+        $objWriter->save($dir . $file); // 文件通过浏览器下载
+        $url = $dir . $file;
+        if (!file_exists($url)) throw new Exception('文件生成失败');
+
+        $saveDir = root_path() . "public/storage/zip/" . date('Ymd') . '/';
+        if (!is_dir($saveDir)) mkdir($saveDir, 0777, true);
+
+
+        $file_dir = $saveDir . $filename . ".zip";
+        # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
+        $zip = new \ZipArchive ();
+        # 5.2 文件不存在则生成一个新的文件 用CREATE打开文件会追加内容至zip
+        if ($zip->open($file_dir, \ZipArchive::OVERWRITE) !== true && $zip->open($file_dir, \ZipArchive::CREATE) !== true) echo '无法打开文件或者文件创建失败';
+
+        # 5.3 批量写入压缩包
+//        $zip->addEmptyDir($fileName);//往zip压缩包写入空目录
+//        foreach ($urls as $fileName) {
+        @$zip->addFile($url, DIRECTORY_SEPARATOR . basename($url));
+//        }
+        // @$zip->addFile($v['file_path'], 'resume'.DIRECTORY_SEPARATOR.basename($headername));
+        # 5.4 关闭压缩包写入
+        $zip->close();
+
+        @deldir($dir);//删除已生成的文件及目录
+        //6. 检查文件是否存在,并输出文件
+        if (!file_exists($file_dir)) throw new Exception('压缩包文件不存在');
+
+        return str_replace(root_path()."public/" , env("host.host"), $file_dir);
+
+    }
+}
+//读取大文件
+if (!function_exists('read_big_file')){
+    function read_big_file(string $file=''){
+        $handle = fopen($file, 'rb');
+        while (feof($handle) === false) {
+            yield fgets($handle);
+        }
+        fclose($handle);
+    }
+}
+
+
+    function deldir($path){
+    //如果是目录则继续
+    if(is_dir($path)){
+        //扫描一个文件夹内的所有文件夹和文件并返回数组
+        $p = scandir($path);
+        //如果 $p 中有两个以上的元素则说明当前 $path 不为空
+        if(count($p)>2){
+            foreach($p as $val){
+                //排除目录中的.和..
+                if($val !="." && $val !=".."){
+                    //如果是目录则递归子目录,继续操作
+                    if(is_dir($path.$val)){
+                        //子目录中操作删除文件夹和文件
+                        deldir($path.$val.'/');
+                    }else{
+                        //如果是文件直接删除
+                        unlink($path.$val);
+                    }
+                }
+            }
+        }
+    }
+    //删除目录
+    return rmdir($path);
+}

+ 3 - 0
config/console.php

@@ -13,5 +13,8 @@ return [
 
         'Good'=>app\command\good::class,//处理中间表的采销数据
         'reporttips'=>app\command\reportTips::class,//处理中间表的采销数据
+
+        'Report'=>app\command\Report::class,//处理中间表的采销数据
+        'ExecPush'=>app\command\ExecPush::class,//处理中间表的采销数据
     ],
 ];