Просмотр исходного кода

add - 截止某日最后结算余额 导出

liugc 1 год назад
Родитель
Сommit
116b0f2e49

+ 108 - 0
app/adminapi/controller/financial/FinancialPaymentRecordsController.php

@@ -0,0 +1,108 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+
+namespace app\adminapi\controller\financial;
+
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\financial\FinancialPaymentRecordsLists;
+use app\adminapi\logic\financial\FinancialPaymentRecordsLogic;
+use app\adminapi\validate\financial\FinancialPaymentRecordsValidate;
+
+
+/**
+ * FinancialPaymentRecords控制器
+ * Class FinancialPaymentRecordsController
+ * @package app\adminapi\controller
+ */
+class FinancialPaymentRecordsController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取列表
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function lists()
+    {
+        return $this->dataLists(new FinancialPaymentRecordsLists());
+    }
+
+
+    /**
+     * @notes 添加
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function add()
+    {
+        $params = (new FinancialPaymentRecordsValidate())->post()->goCheck('add');
+        $result = FinancialPaymentRecordsLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(FinancialPaymentRecordsLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function edit()
+    {
+        $params = (new FinancialPaymentRecordsValidate())->post()->goCheck('edit');
+        $result = FinancialPaymentRecordsLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(FinancialPaymentRecordsLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function delete()
+    {
+        $params = (new FinancialPaymentRecordsValidate())->post()->goCheck('delete');
+        FinancialPaymentRecordsLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @return \think\response\Json
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function detail()
+    {
+        $params = (new FinancialPaymentRecordsValidate())->goCheck('detail');
+        $result = FinancialPaymentRecordsLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}

+ 3 - 1
app/adminapi/controller/master_worker/EngineerBillController.php

@@ -23,6 +23,7 @@ use app\common\service\ExcelExportService;
 use excel\ExcelWriter;
 use phpseclib3\Common\Functions\Strings;
 use think\facade\Db;
+use think\facade\Log;
 
 /**
  * EngineerSettlement控制器
@@ -57,7 +58,7 @@ class EngineerBillController extends BaseAdminController
             return $this->fail(ExportLogic::getError());
         }*/
 
-        $params = $this->request->post();
+        $params = $this->request->get();
         $deadline_time = strtotime($params['deadline_time'])+86400;
         $settlement_type = $params['settlement_type'];
         $filename = "每".$settlement_type."截止到".$params['deadline_time']."批号".$params['deadline_time']."-最后结算余额";
@@ -70,6 +71,7 @@ class EngineerBillController extends BaseAdminController
         if (false === $result) {
             return $this->fail(ExportLogic::getError());
         }
+        Log::info('导出参数:'.json_encode([$params,$result]));
         // 暂时 - 立即生成导出文件
         (new ExcelExportService)->download($result);
         return $this->success('添加成功-'.$result, [], 1, 1);

+ 78 - 0
app/adminapi/lists/financial/FinancialPaymentRecordsLists.php

@@ -0,0 +1,78 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\financial;
+
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\model\financial\FinancialPaymentRecords;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * FinancialPaymentRecords列表
+ * Class FinancialPaymentRecordsLists
+ * @package app\adminapi\lists
+ */
+class FinancialPaymentRecordsLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['export_conditions', 'batch_number', 'upload_status', 'payment_status'],
+
+        ];
+    }
+
+
+    /**
+     * @notes 获取列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function lists(): array
+    {
+        return FinancialPaymentRecords::where($this->searchWhere)
+            ->field(['id', 'export_conditions', 'batch_number', 'upload_status', 'payment_status'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取数量
+     * @return int
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function count(): int
+    {
+        return FinancialPaymentRecords::where($this->searchWhere)->count();
+    }
+
+}

+ 1 - 0
app/adminapi/lists/master_worker/EngineerBillLists.php

@@ -71,6 +71,7 @@ class EngineerBillLists extends BaseAdminDataLists implements ListsSearchInterfa
             ->where('b.change_time', '<', $deadline_time)
             ->group('a.id')
             ->order('a.id desc')
+            ->having('left_amount > 0')
             ->limit($this->limitOffset, $this->limitLength)
             ->select()->toArray();
 

+ 112 - 0
app/adminapi/logic/financial/FinancialPaymentRecordsLogic.php

@@ -0,0 +1,112 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\financial;
+
+
+use app\common\model\financial\FinancialPaymentRecords;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * FinancialPaymentRecords逻辑
+ * Class FinancialPaymentRecordsLogic
+ * @package app\adminapi\logic
+ */
+class FinancialPaymentRecordsLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            FinancialPaymentRecords::create([
+                'export_conditions' => $params['export_conditions'],
+                'batch_number' => $params['batch_number'],
+                'upload_status' => $params['upload_status'],
+                'payment_status' => $params['payment_status'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            FinancialPaymentRecords::where('id', $params['id'])->update([
+                'export_conditions' => $params['export_conditions'],
+                'batch_number' => $params['batch_number'],
+                'upload_status' => $params['upload_status'],
+                'payment_status' => $params['payment_status'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public static function delete(array $params): bool
+    {
+        return FinancialPaymentRecords::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public static function detail($params): array
+    {
+        return FinancialPaymentRecords::findOrEmpty($params['id'])->toArray();
+    }
+}

+ 206 - 0
app/adminapi/logic/financial/MasterSettlementDetailsLogic.php

@@ -0,0 +1,206 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\financial;
+
+
+use app\common\model\financial\MasterSettlementDetails;
+use app\common\logic\BaseLogic;
+use app\common\model\master_worker\EngineerSettlement;
+use think\facade\Db;
+
+
+/**
+ * MasterSettlementDetails逻辑
+ * Class MasterSettlementDetailsLogic
+ * @package app\adminapi\logic
+ */
+class MasterSettlementDetailsLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 15:57
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            MasterSettlementDetails::create([
+                'account_log_id' => $params['account_log_id'],
+                'payment_time' => $params['payment_time'],
+                'batch_number' => $params['batch_number'],
+                'status' => $params['status'],
+                'master_worker_id' => $params['master_worker_id'],
+                'amount_change' => $params['amount_change'],
+                'change_time' => $params['change_time'],
+                'remark' => $params['remark'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 15:57
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            MasterSettlementDetails::where('id', $params['id'])->update([
+                'account_log_id' => $params['account_log_id'],
+                'payment_time' => $params['payment_time'],
+                'batch_number' => $params['batch_number'],
+                'status' => $params['status'],
+                'master_worker_id' => $params['master_worker_id'],
+                'amount_change' => $params['amount_change'],
+                'change_time' => $params['change_time'],
+                'remark' => $params['remark'],
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除
+     * @param array $params
+     * @return bool
+     * @author likeadmin
+     * @date 2024/12/02 15:57
+     */
+    public static function delete(array $params): bool
+    {
+        return MasterSettlementDetails::destroy($params['id']);
+    }
+
+
+    /**
+     * @notes 获取详情
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/12/02 15:57
+     */
+    public static function detail($params): array
+    {
+        return MasterSettlementDetails::findOrEmpty($params['id'])->toArray();
+    }
+
+
+    /**
+     * @notes 更新批次
+     * @param $params
+     * @return array
+     * @author likeadmin
+     * @date 2024/12/02 15:57
+     */
+    public static function upBatchStatus($params,$batch_number)
+    {
+        $deadline_time = $params['deadline_time'];
+        $settlement_type = $params['settlement_type'];
+        /*$lists =   Db::name('master_worker')->alias('a')->field([
+            'a.id','a.real_name','a.nickname','a.worker_number','e.account_holder','e.bank_name','e.opening_branch','e.account as bank_account','b.id as detail_id'
+        ])
+            ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
+            ->leftJoin('bank_account e', 'a.id = e.worker_id')
+            ->where('a.audit_state', '=', 1)
+            ->where('a.user_money', '>', 0)
+            ->where('b.status', '=', 1)
+            ->where('a.settlement_type', '=', $settlement_type)
+            ->where('b.change_time', '<', $deadline_time)
+            ->select()->toArray();*/
+        $lists = Db::name('master_worker')->alias('a')->field([
+                    'a.id','a.real_name','a.nickname','a.worker_number','a.user_money',
+                    'e.account_holder','e.bank_name','e.opening_branch','e.account as bank_account',
+                    Db::raw("sum(amount_change) as left_amount")
+                ])
+                ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
+                ->leftJoin('bank_account e', 'a.id = e.worker_id')
+                ->where('a.audit_state', '=', 1)
+                ->where('a.user_money', '>', 0)
+                ->where('b.status', '=', 1)
+                ->where('a.settlement_type', '=', $settlement_type)
+                ->where('b.change_time', '<', $deadline_time)
+                ->group('a.id')
+                ->order('a.id desc')
+                ->having('left_amount > 0')
+                ->select()->toArray();
+
+        // 根据条件获取能打款的 工程师 left_amount user_money
+        $can_payment_ids = [];
+        $insertXlsData = [];
+        foreach ($lists as $item) {
+            if(!empty($item['left_amount']) && !empty($item['user_money']) && ((float)$item['left_amount'] <= (float)$item['user_money'])){
+                $can_payment_ids[] = $item['id'];
+                $insertXlsData[] = [
+                    'master_worker_id' => $item['id'],
+                    'worker_number' => $item['worker_number'],
+                    'engineer_name' => $item['account_holder'],
+
+                    'bank_account' => $item['bank_account'],
+                    'bank_name' => $item['bank_name'],
+                    'opening_branch' => $item['opening_branch'],
+
+                    'original_balance' => $item['user_money'],
+                    'total_settlement_amount' => $item['left_amount'],
+                    'payment_status' => 0,
+                    'is_export' => 1,
+
+                    'batch_number'=> $batch_number,
+                    'create_time'=> time(),
+                    'update_time'=> time(),
+                    'admin_id'=> 0,
+                    'is_deduction'=> 0,
+                ];
+            }
+        }
+        //由可发工程师, 修改该工程师 截止$deadline_time 的 状态和批号
+        MasterSettlementDetails::where('id','in', $can_payment_ids)
+            ->where('change_time', '<', $deadline_time)
+            ->where('status', '=', 1)
+            ->update([
+                'status' => 2,
+                'batch_number' => $batch_number,
+            ]);
+        // 生成 可发 数据表格
+        Db::name('engineer_settlement')->insertAll($insertXlsData);
+
+        return $insertXlsData;
+    }
+
+
+
+}

+ 96 - 0
app/adminapi/validate/financial/FinancialPaymentRecordsValidate.php

@@ -0,0 +1,96 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\financial;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * FinancialPaymentRecords验证器
+ * Class FinancialPaymentRecordsValidate
+ * @package app\adminapi\validate
+ */
+class FinancialPaymentRecordsValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'id' => 'require',
+
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'id' => 'id',
+
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return FinancialPaymentRecordsValidate
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function sceneAdd()
+    {
+        return $this->remove('id', true);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return FinancialPaymentRecordsValidate
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return FinancialPaymentRecordsValidate
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return FinancialPaymentRecordsValidate
+     * @author likeadmin
+     * @date 2024/12/02 11:55
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+}

+ 36 - 0
app/common/model/financial/FinancialPaymentRecords.php

@@ -0,0 +1,36 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\financial;
+
+
+use app\common\model\BaseModel;
+
+
+
+/**
+ * FinancialPaymentRecords模型
+ * Class FinancialPaymentRecords
+ * @package app\common\model
+ */
+class FinancialPaymentRecords extends BaseModel
+{
+    
+    protected $name = 'financial_payment_records';
+    protected $type = [
+        'export_conditions' => 'array',
+    ];
+
+    
+}

+ 34 - 0
app/common/model/financial/MasterSettlementDetails.php

@@ -0,0 +1,34 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\financial;
+
+
+use app\common\model\BaseModel;
+
+
+
+/**
+ * MasterSettlementDetails模型
+ * Class MasterSettlementDetails
+ * @package app\common\model
+ */
+class MasterSettlementDetails extends BaseModel
+{
+    
+    protected $name = 'master_settlement_details';
+    
+
+    
+}

+ 31 - 39
app/common/service/ExcelExportService.php

@@ -15,9 +15,11 @@
 namespace app\common\service;
 
 
+use app\adminapi\logic\financial\MasterSettlementDetailsLogic;
 use app\common\enum\FileEnum;
 use app\common\model\export\Export;
 use app\common\model\file\File;
+use app\common\model\financial\FinancialPaymentRecords;
 use app\common\service\storage\Driver as StorageDriver;
 use excel\ExcelWriter;
 use Exception;
@@ -97,59 +99,49 @@ class ExcelExportService
      */
     public function EngineerBillDownload($infoExport)
     {
+        Db::startTrans();
         try{
             $filename = $infoExport['name'];
             $params = $infoExport['params']?:[];
             if($params){ }
-            $deadline_time = $params['deadline_time'];
-            $settlement_type = $params['settlement_type'];
-            $lists =   Db::name('master_worker')->alias('a')->field([
-                    'a.id','a.real_name','a.nickname','a.worker_number','e.account_holder','e.bank_name','e.opening_branch','e.account as bank_account',
-                    Db::raw("sum(amount_change) as left_amount")
-                ])
-                ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
-                ->leftJoin('bank_account e', 'a.id = e.worker_id')
-                ->where('a.audit_state', '=', 1)
-                ->where('a.user_money', '>', 0)
-                ->where('b.status', '=', 1)
-                //->where('a.settlement_type', 'in', $settlement_type)
-                ->where('a.settlement_type', '=', $settlement_type)
-                ->where('b.change_time', '<', $deadline_time)
-                ->group('a.id')
-                ->order('a.id desc')
-                ->select()->toArray();
-
             // 导出逻辑
             /*添加财务打款记录表: 生成批次编号、状态待上传 已取消  打款状态: 未打款、部分打款、全部打款
-            更新表 la_master_settlement_details 批次编号、状态-待算
             生成数据表格:工程师信息、银行卡信息、批次编号信息、应发金额、导出时账号余额、导入时账号余额、扣款金额、扣款说明、实发金额、打款状态(已打、下次打款)、打款时间、备注、是否已导入
-            (账号当前余额 !=0) < (应发金额 !=0)  = 下次打款*/
-            /*工程师ID   工程师编号   工程师姓名
-            工程师银行卡号 工程师开户行及支行信息
-            上月最后结算余额(应发金额)*/
-
-
-
-
-
-
-
-
-
-
-
-
-
+            (账号当前余额 !=0) < (应发金额 !=0)  = 下次打款
+            更新表 la_master_settlement_details 批次编号、状态-待算
+            */
+
+            $batch_number = 'bn' . date('YmdHis') . rand(0, 9);
+
+            // 添加财务打款记录表 -- 批次编号、状态待上传
+            $params['infoExport_id'] = $infoExport->id;
+            FinancialPaymentRecords::create([
+                'export_conditions' => $params,
+                'batch_number' => $batch_number,
+                'upload_status' => 1,
+                'payment_status' => 1,
+            ]);
+            //生成数据表格 & 更新表 -- 批次编号、状态-待算
+            $lists = MasterSettlementDetailsLogic::upBatchStatus($params,$batch_number);
             $filename = ($filename?:'').('-'.date('YmdHis').'-'.$infoExport->id);
             $this->sheet->generateExcelFile([
-                '工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '工程师开户行及支行信息','上月最后结算余额'
-            ], $lists,$filename, ['id','worker_number','real_name','bank_account','bank_name','left_amount']);
+                '工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '所属银行', '工程师开户行及支行信息','导出时账号余额',
+                '批次编号',
+                '应发金额', '扣款金额', '扣款说明', '实发金额', '打款状态','打款时间','备注'
+            ], $lists,$filename, [
+                'master_worker_id','worker_number','engineer_name','bank_account','bank_name','opening_branch','original_balance',
+                'batch_number',
+                'total_settlement_amount','','','','','',''
+            ]);
             $infoExport->file_url = $this->sheet->fileUrl();
             $infoExport->generate_status = 1;
             $infoExport->updatetime = time();
             $infoExport->save();
+
+            Db::commit();
             return $infoExport->file_url;
-        }catch (\Exception $e){
+        } catch (\Exception $e) {
+            Db::rollback();
             throw new Exception($e->getMessage());
         }
     }

+ 1 - 1
extend/excel/ExcelWriter.php

@@ -62,7 +62,7 @@ class ExcelWriter
             }
             $tmp_arr = [];
             foreach ($map as $value){
-                $tmp_arr[] = $row[$value];
+                $tmp_arr[] = $row[$value]??'';
             }
             return $tmp_arr;
         }, $lists);