Browse Source

细节 优化

wufeng 2 years ago
parent
commit
f427b8637d
3 changed files with 46 additions and 4 deletions
  1. 1 1
      app/admin/controller/Export.php
  2. 3 3
      app/admin/controller/Payment.php
  3. 42 0
      app/common.php

+ 1 - 1
app/admin/controller/Export.php

@@ -19,7 +19,7 @@ class Export extends BaseController
         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', 'like', '%' . $param['invNo'] . '%'];
+        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'] . '%'];

+ 3 - 3
app/admin/controller/Payment.php

@@ -1791,13 +1791,13 @@ class Payment extends BaseController
             ->alias("a")
             ->leftJoin("pay b", "a.payNo=b.payNo and b.is_del=0 and b.status=2")
             ->where(['b.is_del' => 0])
-            ->whereIn('b.hpNo', array_column($post['list'], 'hpNo'))
-            ->column("a.id,a.payNo,a.hpNo,a.invoiceType,a.inv_fee as invoice_fee,a.status,b.inv_status,b.inv_fee,b.companyNo,b.ainv_fee,b.winv_fee,b.hpNo");
+            ->whereIn('a.hpNo', array_column($post['list'], 'hpNo'))
+            ->column("a.id,a.payNo,a.hpNo,a.invoiceType,a.inv_fee as invoice_fee,a.status,b.inv_status,b.inv_fee,b.companyNo,b.ainv_fee,b.winv_fee,a.hpNo");
 
         $val_hpNo = Validate::rule([
             'hpNo|回票申请编号' => 'require',
             'status|审核状态' => 'require|number|in:4,9',
-            'remark|审核备注' => 'requireIf:status:7|max:255'
+            'remark|审核备注' => 'requireIf:status,7|max:255'
         ]);
 
         foreach ($post['list'] as $item) {

+ 42 - 0
app/common.php

@@ -497,4 +497,46 @@ if(!function_exists('menuAction')){
 			menuAction($temp,$list);
 		}
 	}
+}
+
+
+/*
+ * 大文件导出成csv文件
+ * @param file_name string 文件名
+ * @param headArr array 标题
+ * @param $db \think\db\Query 使用Db方法后生成的对象实例
+ */
+if (!function_exists('largerDataExportToCsv')) {
+    function largerDataExportToCsv(string $fileName = '', array $headArr = [], \think\db\Query $db = null, int $num = 10000)
+    {
+        set_time_limit(0);//让程序一直运行
+
+        $fileName .= date('_Y_m_d_H_i_s');//文件名拼接日期
+
+        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头,打开会出现乱码
+
+        fputcsv($fp, $headArr);//添加导出标题
+
+        $count = $db->count();//计算总数
+
+        $total = ceil($count / $num);//计算总页数
+
+        //写入数据
+        for ($i = 1; $i <= $total; $i++) {
+            $result = $db
+                ->page($i, $num)
+                ->cursor();
+            foreach ($result as $k => $value) {
+                fputcsv($fp, $value);
+            }
+            ob_flush();
+            flush();
+        }
+    }
 }