Browse Source

退货台账-业务口径

wufeng 2 years ago
parent
commit
fa6ab1bccf
3 changed files with 44 additions and 124 deletions
  1. 2 8
      app/admin/controller/Exec.php
  2. 26 102
      app/command/NowReportHandle.php
  3. 16 14
      app/common.php

+ 2 - 8
app/admin/controller/Exec.php

@@ -59,10 +59,6 @@ class Exec extends Base
         if ($token == "") {
             return error_show(101, 'token不能为空');
         }
-//        $effetc = VerifyTokens($token);
-//        if(!empty($effetc) && $effetc['code']!=0){
-//            return error_show($effetc['code'],$effetc['message']);
-//        }
         $userinfo = GetUserInfo($token);
         if (!isset($userinfo['code']) || $userinfo['code'] != 0) {
             return error_show(101, '未能获取用户信息');
@@ -98,8 +94,7 @@ class Exec extends Base
         $info['addtime'] = date("Y-m-d H:i:s");
         $info['expiretime'] = date("Y-m-d H:i:s", time() + 7 * 24 * 3600);
         $up = Db::name("exec")->save($info);
-        $redis = Cache::store("redis");
-        $isPushed = $redis->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
+        $redis = Cache::store("redis")->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
         return $up ? app_show(0, "编辑成功") : error_show(1004, "编辑失败");
     }
 
@@ -135,8 +130,7 @@ class Exec extends Base
         $info['updatetime'] = date("Y-m-d H:i:s");
         $info['addtime'] = date("Y-m-d H:i:s");
         $up = Db::name("exec")->save($info);
-        $redis = Cache::store("redis");
-        $isPushed = $redis->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
+        $redis = Cache::store("redis")->handler()->lPush($info['type'] == 1 ? "nowreport" : "execreport", json_encode($info));
         return $up ? app_show(0, "编辑成功") : error_show(1004, "编辑失败");
     }
 }

+ 26 - 102
app/command/NowReportHandle.php

@@ -3,10 +3,10 @@ declare (strict_types=1);
 
 namespace app\command;
 
-use app\admin\model\Test1;
 use think\console\Command;
 use think\console\Input;
 use think\console\Output;
+use think\Exception;
 use think\facade\Cache;
 use think\facade\Db;
 
@@ -14,20 +14,13 @@ use think\facade\Db;
 class NowReportHandle extends Command
 {
     //redis队列的key,在ReportReserve控制器中也有定义,要同步修改(轻易不要修改)
-    private $key = 'wanyuhengtong_report_reserve';
-
-    //各个报表的导出字段(这里的字段要和下面的方法中查询字段个数对应)
-    private $field = [
-        'A' => ['退货单号', '流程进度', '退货发起日期', '公司名称', '退货人', '退货数量', '退货销售货款', '退货备注', '客户名称', '客户编码', '一级组织', '二级组织', '三级组织', '平台名称', 'PO编号', '确认单编号', '确认单类型', '确认单下单时间', '业务人员', '确认单产品编号', '产品名称', '产品编码', '一级分类'],
-        'B' => [],
-        'C' => [],
-    ];
+    private $key = 'nowreport';
 
     protected function configure()
     {
         // 指令配置
-        $this->setName('handleData')
-            ->setDescription('处理报表预约记录,生成报表文件');
+        $this->setName('now_report')
+            ->setDescription('定时处理报表预约,生成报表文件');
     }
 
     //处理报表预约记录,生成报表文件
@@ -36,57 +29,43 @@ class NowReportHandle extends Command
 
         try {
 
+            $info = Cache::store('redis')->handler()->rpop($this->key);
+            if ($info) {
 
-            $pk_id = Cache::store('redis')->handler()->rpop($this->key);
-            if ($pk_id) {
-                //有数据,开始处理
-
-                //查询预约记录
-                $rs = Db::name('report_form_reserve')
-                    ->field('id,name,code,start_time,end_time')
-                    ->where(['id' => $pk_id, 'status' => 1])
-                    ->find();
-
-                if ($rs) {
-                    //状态改为处理中
-                    Db::name('report_form_reserve')
-                        ->where(['id' => $pk_id, 'status' => 1])//status==1 待处理
-                        ->update(['status' => 2, 'updatetime' => date('Y-m-d H:i:s')]);//status==2 处理中
-
-                    //处理数据的方法
-                    switch ($rs['code']) {
-                        case 'A':
-                            $res = $this->A($rs['start_time'], $rs['end_time']);
-                            break;
-                    }
+                $info = json_decode($info, true);
 
-                    $file = excelSaveFile($res, $this->field[$rs['code']], $rs['name'] . date('YmdHis'));
+                //不同的方法处理不同的脚本
+                switch ($info['code']) {
+                    case 'A':
+                        $res = $this->A($info['start'], $info['end']);
+                        break;
 
-                    Db::name('report_form_reserve')
-                        ->where(['id' => $pk_id, 'status' => 2])//status==2 处理中
-                        ->update([
-                            'status' => 3, //status==3 处理完成
-                            'down_url' => $file,
-                            'updatetime' => date('Y-m-d H:i:s'),
-                            'expiretime' => date('Y-m-d H:i:s', strtotime('+1 month'))
-                        ]);
+                    default:
+                        throw new Exception('赞不支持这个报表');
+                }
 
-                    $output->writeln('【' . $pk_id . '】该预约记录处理成功');
+                $file = excelSaveFile($res, $info['name'] . date('YmdHis'));
 
+                Db::name('exec')
+                    ->where(['id' => $info['id'], 'status' => 1])//status==1 待处理
+                    ->update([
+                        'status' => 2, //status==2 处理完成
+                        'down_url' => $file,
+                        'updatetime' => date('Y-m-d H:i:s'),
+                        'expiretime' => date('Y-m-d H:i:s', strtotime('+7 day'))
+                    ]);
 
-                } else $output->writeln('没有查询到该预约记录');
+                $output->writeln('【' . $info['id'] . '】该预约记录处理成功');
 
             } else  $output->writeln('没有可供处理的报表预约记录');
 
-        } catch (\Exception $exception) {
+        } catch (Exception $exception) {
             $output->writeln($exception->getMessage() . '|' . $exception->getFile() . '|' . $exception->getLine());
         }
 
     }
 
 
-    //数据处理脚本,每个报表一个方法
-
     //退货台账-业务口径
     private function A(string $start_date = '', string $end_date = '')
     {
@@ -142,60 +121,5 @@ class NowReportHandle extends Command
 
     }
 
-    //库存预警汇总表
-    private function B(string $start_date = '', string $end_date = '')
-    {
-
-        $data = Db::name('sale_return')
-            ->alias('sr')
-            ->field('sr.returnCode 退货单号,sr.status 流程进度,sr.addtime 退货发起日期,sup.name 公司名称,sr.apply_name 退货人,sr.num 退货数量,sr.total_fee 退货销售货款,sr.remark 退货备注,c.companyName 客户名称,or.customer_code 客户编码,"" 一级组织,"" 二级组织,"" 三级组织,p.platform_name 平台名称,s.poNo PO编号,sr.orderCode 确认单编号,s.order_type 确认单类型,s.addtime 确认单下单时间,s.apply_name 业务人员,sr.orderCode 确认单产品编号,sr.good_name 产品名称,sr.good_code 产品编码,"" 一级分类,s.cat_id,c.itemid')
-            ->leftJoin('platform p', 'p.id = sr.platform_id')
-            ->leftJoin('order_return or', 'or.orderCode = sr.orderCode')
-            ->leftJoin('customer_info c', 'c.companyNo = or.customer_code')
-            ->leftJoin('sale s', 's.orderCode = sr.orderCode')
-            ->leftJoin('supplier sup', 'sup.code = s.supplierNo')
-            ->where('sr.is_del', 0)
-            ->whereBetween('sr.addtime', [$start_date . ' 00:00:00', $end_date . ' 23:59:59'])
-            ->cursor();
-
-        $all_sale_return_status = [1 => '待业务审批', 2 => '待专员审批', 3 => '待主管审批', 4 => '退货完成', 5 => '业务驳回', 6 => '采购驳回', 7 => '专员审批不通过'];
-        $all_sale_order_type = [1 => '备库', 2 => '非库存', 3 => '咨询采反', 4 => '项目采反', 5 => '平台部订单销售',];
-        $list = [];
-        foreach ($data as $value) {
-
-            $value['流程进度'] = isset($all_sale_return_status[$value['流程进度']]) ? $all_sale_return_status[$value['流程进度']] : '';
-            $value['确认单类型'] = isset($all_sale_order_type[$value['确认单类型']]) ? $all_sale_order_type[$value['确认单类型']] : '';
-
-            $top = made($value['cat_id']);
-            $value['一级分类'] = isset($top[0]['name']) ? $top[0]['name'] : '';
-
-            if (!empty($value['itemid'])) {
-                $customer_org1 = get_top_customer_org($value['itemid']);
-
-                foreach ($customer_org1 as $vv) {
-                    switch ($vv['level']) {
-                        case 1:
-                            $value['一级组织'] = $vv['name'];
-                            break;
-                        case 2:
-                            $value['二级组织'] = $vv['name'];
-                            break;
-                        case 3:
-                            $value['三级组织'] = $vv['name'];
-                            break;
-                    }
-                }
-            }
-
-            unset($value['cat_id']);
-            unset($value['itemid']);
-
-            yield $list[] = $value;
-        }
-
-        return $list;
-
-    }
-
 
 }

+ 16 - 14
app/common.php

@@ -907,7 +907,7 @@ if (!function_exists('excelSaveBatch')) {
  * filename string 文件名
  */
 if (!function_exists('excelSaveFile')) {
-    function excelSaveFile($datas, array $header = [], string $filename = '')
+    function excelSaveFile($datas, string $filename = '')
     {
 
 //        $urls = [];
@@ -917,22 +917,28 @@ if (!function_exists('excelSaveFile')) {
 //        foreach ($datas as $item) {
 
         $objPHPExcel = new PHPExcel();
-        $objPHPExcel->getProperties();
+
         $keyA = 0; // 设置表头
-        foreach ($header as $v) {
-            $colum = PHPExcel_Cell::stringFromColumnIndex($keyA);
-            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($colum . '1', $v);
-            $keyA += 1;
-        }
 
         $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) { // 列写入
+            foreach ($rows as $keyName => $value) {
                 //判断数据是否有数组,如果有数组,转换成字符串
-
                 if (is_array($value)) $value = implode("、", $value);
 
                 $objActSheet->setCellValue(PHPExcel_Cell::stringFromColumnIndex($span) . $column, $value);
@@ -947,15 +953,11 @@ if (!function_exists('excelSaveFile')) {
         $objWriter->save($dir . $file); // 文件通过浏览器下载
         $url = $dir . $file;
         if (!file_exists($url)) throw new Exception('文件生成失败');
-//            else $urls[] = $url;
 
-//        }
-
-        $saveDir = root_path() . "public/storage/zip/";
+        $saveDir = root_path() . "public/storage/zip/" . date('Ymd') . '/';
         if (!is_dir($saveDir)) mkdir($saveDir, 0777, true);
 
 
-//        $datetime = date("YmdHis");
         $file_dir = $saveDir . $filename . ".zip";
         # 5.1 文件打包,提示:使用本类,linux需开启zlib,windows需取消php_zip.dll前的注释
         $zip = new \ZipArchive ();