Quellcode durchsuchen

add - 财务打款

liugc vor 1 Jahr
Ursprung
Commit
8715f4d409

+ 6 - 3
app/adminapi/controller/financial/FinancialPaymentRecordsController.php

@@ -78,7 +78,7 @@ class FinancialPaymentRecordsController extends BaseAdminController
 
 
 
 
     /**
     /**
-     * @notes 删除
+     * @notes 取消
      * @return \think\response\Json
      * @return \think\response\Json
      * @author likeadmin
      * @author likeadmin
      * @date 2024/12/02 11:55
      * @date 2024/12/02 11:55
@@ -86,8 +86,11 @@ class FinancialPaymentRecordsController extends BaseAdminController
     public function delete()
     public function delete()
     {
     {
         $params = (new FinancialPaymentRecordsValidate())->post()->goCheck('delete');
         $params = (new FinancialPaymentRecordsValidate())->post()->goCheck('delete');
-        FinancialPaymentRecordsLogic::delete($params);
-        return $this->success('删除成功', [], 1, 1);
+        $result = FinancialPaymentRecordsLogic::delete($params);
+        if (true === $result) {
+            return $this->success('取消成功', [], 1, 1);
+        }
+        return $this->fail(FinancialPaymentRecordsLogic::getError());
     }
     }
 
 
 
 

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

@@ -61,7 +61,16 @@ class EngineerBillController extends BaseAdminController
         $params = $this->request->get();
         $params = $this->request->get();
         $deadline_time = strtotime($params['deadline_time'])+86400;
         $deadline_time = strtotime($params['deadline_time'])+86400;
         $settlement_type = $params['settlement_type'];
         $settlement_type = $params['settlement_type'];
-        $filename = "每".$settlement_type."截止到".$params['deadline_time']."批号".$params['deadline_time']."-最后结算余额";
+
+        $allData = $this->dataLists(new EngineerBillLists())->getData()['data']['lists'];
+        if(empty($allData)) return $this->fail('无数据');
+
+        $type = [
+            1=>'周(7天)',
+            2=>'半月',
+            3=>'整月'
+        ];
+        $filename = "截止到".$params['deadline_time'].$type[$settlement_type].'型结算单';
         $result = ExportLogic::add([
         $result = ExportLogic::add([
             'download_type' => 1,
             'download_type' => 1,
             'params' => ['settlement_type'=>$settlement_type,'deadline_time'=>$deadline_time],
             'params' => ['settlement_type'=>$settlement_type,'deadline_time'=>$deadline_time],

+ 8 - 1
app/adminapi/lists/financial/FinancialPaymentRecordsLists.php

@@ -16,6 +16,7 @@ namespace app\adminapi\lists\financial;
 
 
 
 
 use app\adminapi\lists\BaseAdminDataLists;
 use app\adminapi\lists\BaseAdminDataLists;
+use app\adminapi\logic\export\ExportLogic;
 use app\common\model\financial\FinancialPaymentRecords;
 use app\common\model\financial\FinancialPaymentRecords;
 use app\common\lists\ListsSearchInterface;
 use app\common\lists\ListsSearchInterface;
 
 
@@ -55,12 +56,18 @@ class FinancialPaymentRecordsLists extends BaseAdminDataLists implements ListsSe
      */
      */
     public function lists(): array
     public function lists(): array
     {
     {
-        return FinancialPaymentRecords::where($this->searchWhere)
+        $lists = FinancialPaymentRecords::where($this->searchWhere)
             ->field(['id', 'export_conditions', 'batch_number', 'upload_status', 'payment_status'])
             ->field(['id', 'export_conditions', 'batch_number', 'upload_status', 'payment_status'])
             ->limit($this->limitOffset, $this->limitLength)
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->order(['id' => 'desc'])
             ->select()
             ->select()
             ->toArray();
             ->toArray();
+        foreach ($lists as &$item) {
+            $item['file_url'] = ExportLogic::detail(['id'=>$item['export_conditions']['infoExport_id']])['file_url'];
+            $item['settlement_type'] = $item['export_conditions']['settlement_type'];
+            $item['deadline_time'] = date('Y-m-d', $item['export_conditions']['deadline_time']-1);
+        }
+        return $lists;
     }
     }
 
 
 
 

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

@@ -59,7 +59,7 @@ class EngineerBillLists extends BaseAdminDataLists implements ListsSearchInterfa
         $settlement_type = $this->params['settlement_type'];
         $settlement_type = $this->params['settlement_type'];
         return Db::name('master_worker')->alias('a')->field([
         return 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',
             '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")
+            Db::raw("sum(b.amount_change) as left_amount")
         ])
         ])
             ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
             ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
             ->leftJoin('bank_account e', 'a.id = e.worker_id')
             ->leftJoin('bank_account e', 'a.id = e.worker_id')

+ 3 - 3
app/adminapi/lists/master_worker/EngineerSettlementLists.php

@@ -38,7 +38,7 @@ class EngineerSettlementLists extends BaseAdminDataLists implements ListsSearchI
     public function setSearch(): array
     public function setSearch(): array
     {
     {
         return [
         return [
-            '=' => ['master_worker_id', 'worker_number', 'engineer_name', 'original_balance', 'total_settlement_amount', 'deduction_amount', 'final_settlement_amount', 'settlement_time', 'settlement_details_remarks'],
+            '=' => ['batch_number','master_worker_id', 'worker_number', 'engineer_name', 'original_balance', 'total_settlement_amount', 'deduction_amount', 'final_settlement_amount', 'settlement_time', 'settlement_details_remarks'],
 
 
         ];
         ];
     }
     }
@@ -55,8 +55,8 @@ class EngineerSettlementLists extends BaseAdminDataLists implements ListsSearchI
      */
      */
     public function lists(): array
     public function lists(): array
     {
     {
-        return EngineerSettlement::where($this->searchWhere)
-            ->field(['id', 'master_worker_id', 'worker_number', 'engineer_name', 'original_balance', 'total_settlement_amount', 'deduction_amount', 'final_settlement_amount', 'settlement_time', 'settlement_details_remarks'])
+        return EngineerSettlement::where('is_export',2)->where($this->searchWhere)
+            ->field(['id', 'master_worker_id', 'worker_number', 'engineer_name', 'original_balance', 'total_settlement_amount', 'deduction_amount', 'final_settlement_amount', 'settlement_time', 'settlement_details_remarks','batch_number'])
             ->limit($this->limitOffset, $this->limitLength)
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->order(['id' => 'desc'])
             ->select()
             ->select()

+ 23 - 2
app/adminapi/logic/financial/FinancialPaymentRecordsLogic.php

@@ -17,6 +17,8 @@ namespace app\adminapi\logic\financial;
 
 
 use app\common\model\financial\FinancialPaymentRecords;
 use app\common\model\financial\FinancialPaymentRecords;
 use app\common\logic\BaseLogic;
 use app\common\logic\BaseLogic;
+use app\common\model\financial\MasterSettlementDetails;
+use app\common\model\master_worker\EngineerSettlement;
 use think\facade\Db;
 use think\facade\Db;
 
 
 
 
@@ -86,7 +88,7 @@ class FinancialPaymentRecordsLogic extends BaseLogic
 
 
 
 
     /**
     /**
-     * @notes 删除
+     * @notes 取消
      * @param array $params
      * @param array $params
      * @return bool
      * @return bool
      * @author likeadmin
      * @author likeadmin
@@ -94,7 +96,26 @@ class FinancialPaymentRecordsLogic extends BaseLogic
      */
      */
     public static function delete(array $params): bool
     public static function delete(array $params): bool
     {
     {
-        return FinancialPaymentRecords::destroy($params['id']);
+        Db::startTrans();
+        try {
+            $recordInfo = FinancialPaymentRecords::findOrEmpty($params['id'])->toArray();
+            if($recordInfo){
+                if((int)$recordInfo['upload_status'] !== 1){
+                    throw new \Exception('非待上传,不能取消');
+                }
+                MasterSettlementDetails::where('batch_number',$recordInfo['batch_number'])->where('status','<',3)->update(['status'=>1,'batch_number'=>'']);
+                EngineerSettlement::destroy(['batch_number'=>$recordInfo['batch_number'],'is_deduction'=>['neq',1]]);
+                FinancialPaymentRecords::update(['payment_status'=>2],['id'=>$params['id']]);
+            }else{
+                throw new \Exception('记录不存在');
+            }
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
     }
     }
 
 
 
 

+ 5 - 3
app/adminapi/logic/financial/MasterSettlementDetailsLogic.php

@@ -19,6 +19,7 @@ use app\common\model\financial\MasterSettlementDetails;
 use app\common\logic\BaseLogic;
 use app\common\logic\BaseLogic;
 use app\common\model\master_worker\EngineerSettlement;
 use app\common\model\master_worker\EngineerSettlement;
 use think\facade\Db;
 use think\facade\Db;
+use think\facade\Log;
 
 
 
 
 /**
 /**
@@ -145,7 +146,7 @@ class MasterSettlementDetailsLogic extends BaseLogic
         $lists = Db::name('master_worker')->alias('a')->field([
         $lists = Db::name('master_worker')->alias('a')->field([
                     'a.id','a.real_name','a.nickname','a.worker_number','a.user_money',
                     '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',
                     'e.account_holder','e.bank_name','e.opening_branch','e.account as bank_account',
-                    Db::raw("sum(amount_change) as left_amount")
+                    Db::raw("sum(b.amount_change) as left_amount")
                 ])
                 ])
                 ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
                 ->leftJoin('master_settlement_details b', 'a.id = b.master_worker_id AND b.status = 1')
                 ->leftJoin('bank_account e', 'a.id = e.worker_id')
                 ->leftJoin('bank_account e', 'a.id = e.worker_id')
@@ -163,7 +164,7 @@ class MasterSettlementDetailsLogic extends BaseLogic
         $can_payment_ids = [];
         $can_payment_ids = [];
         $insertXlsData = [];
         $insertXlsData = [];
         foreach ($lists as $item) {
         foreach ($lists as $item) {
-            if(!empty($item['left_amount']) && !empty($item['user_money']) && ((float)$item['left_amount'] <= (float)$item['user_money'])){
+            if(!empty($item['left_amount']) && !empty($item['user_money']) && !((float)$item['left_amount'] > (float)$item['user_money'])){
                 $can_payment_ids[] = $item['id'];
                 $can_payment_ids[] = $item['id'];
                 $insertXlsData[] = [
                 $insertXlsData[] = [
                     'master_worker_id' => $item['id'],
                     'master_worker_id' => $item['id'],
@@ -188,7 +189,7 @@ class MasterSettlementDetailsLogic extends BaseLogic
             }
             }
         }
         }
         //由可发工程师, 修改该工程师 截止$deadline_time 的 状态和批号
         //由可发工程师, 修改该工程师 截止$deadline_time 的 状态和批号
-        MasterSettlementDetails::where('id','in', $can_payment_ids)
+        MasterSettlementDetails::where('master_worker_id','in', $can_payment_ids)
             ->where('change_time', '<', $deadline_time)
             ->where('change_time', '<', $deadline_time)
             ->where('status', '=', 1)
             ->where('status', '=', 1)
             ->update([
             ->update([
@@ -198,6 +199,7 @@ class MasterSettlementDetailsLogic extends BaseLogic
         // 生成 可发 数据表格
         // 生成 可发 数据表格
         Db::name('engineer_settlement')->insertAll($insertXlsData);
         Db::name('engineer_settlement')->insertAll($insertXlsData);
 
 
+        Log::write('insertXlsData', 'info',$insertXlsData);
         return $insertXlsData;
         return $insertXlsData;
     }
     }
 
 

+ 32 - 23
app/adminapi/logic/master_worker/EngineerSettlementLogic.php

@@ -92,7 +92,7 @@ class EngineerSettlementLogic extends BaseLogic
                                     'batch_number' => $param['batch_number'],
                                     'batch_number' => $param['batch_number'],
                                     'status' => 3,
                                     'status' => 3,
                                     'master_worker_id' => $param['master_worker_id'],
                                     'master_worker_id' => $param['master_worker_id'],
-                                    'amount_change' => -(float)$param['final_settlement_amount'],
+                                    'amount_change' => -(float)$param['deduction_amount'],
                                     'change_time' => time(),
                                     'change_time' => time(),
                                     'remark' => '直接扣款'
                                     'remark' => '直接扣款'
                                 ]);
                                 ]);
@@ -128,7 +128,6 @@ class EngineerSettlementLogic extends BaseLogic
                             ->where('batch_number', $param['batch_number'])
                             ->where('batch_number', $param['batch_number'])
                             ->where('status', 2)
                             ->where('status', 2)
                             ->update([
                             ->update([
-                                'payment_status' => 1,
                                 'payment_time' => $param['settlement_time']??date('Y-m-d H:i:s'),
                                 'payment_time' => $param['settlement_time']??date('Y-m-d H:i:s'),
                                 'status'=>3, 'remark'=>''
                                 'status'=>3, 'remark'=>''
                             ]);
                             ]);
@@ -244,53 +243,63 @@ class EngineerSettlementLogic extends BaseLogic
         //$engineerSettlement 中每条都不能为空
         //$engineerSettlement 中每条都不能为空
         // $masterWorker->user_money >= $param['total_settlement_amount']
         // $masterWorker->user_money >= $param['total_settlement_amount']
         //$param['total_settlement_amount'] = $params['final_settlement_amount']+deduction_amount;
         //$param['total_settlement_amount'] = $params['final_settlement_amount']+deduction_amount;
-
+        // 该批次是否为待上传
         try {
         try {
             if(empty($params)) throw new \Exception('表格数据为空');
             if(empty($params)) throw new \Exception('表格数据为空');
-
+            $master_worker_ids = array_column($params, 'master_worker_id');
             //上传表格中所有 master_worker_id 不能存在重复
             //上传表格中所有 master_worker_id 不能存在重复
-
-            if(count(array_unique(array_column($params, 'master_worker_id')))>1){
-                throw new \Exception('上传表格中所有 master_worker_id 必须不能存在重复');
-            }
-
+            array_filter(array_count_values($master_worker_ids), function($count) {
+                if($count>1) throw new \Exception('上传表格中所有工程师不能存在重复');
+            });
             //上传表格中所有批号必须相同
             //上传表格中所有批号必须相同
             if(count(array_unique(array_column($params, 'batch_number')))>1){
             if(count(array_unique(array_column($params, 'batch_number')))>1){
-                throw new \Exception('上传表格中所有批号必须相同');
+                throw new \Exception('上传表格中所有批号必须同批次');
+            }
+            $batch_number = $params[0]['batch_number'];
+            // 该批次是否为待上传
+            $financialRecords = FinancialPaymentRecords::where('batch_number', $batch_number)->where('upload_status', 1)->findOrEmpty();
+            if($financialRecords->isEmpty()){
+                throw new \Exception('该批次不存在或已取消/已上传,禁止上传');
             }
             }
-            // 每条数据在表 EngineerSettlement 中不能为空
-            $engineer_worker_ids = EngineerSettlement::where('batch_number', $params[0]['batch_number'])
+            // 每条数据在表 EngineerSettlement 中不能为空即 下载记录必须存在
+            $engineer_worker_ids = EngineerSettlement::where('batch_number', $batch_number)
                 ->where('is_export', 1)
                 ->where('is_export', 1)
                 ->where('is_deduction', 0)
                 ->where('is_deduction', 0)
                 ->where('payment_status', 0)
                 ->where('payment_status', 0)
                 ->column('master_worker_id');
                 ->column('master_worker_id');
-
-
-
+            $masterWorkers = MasterWorker::where('id', 'in',$master_worker_ids)->column('user_money', 'id');
 
 
             foreach ($params as &$param) {
             foreach ($params as &$param) {
-                if(!in_array($param['master_worker_id'], $engineer_worker_ids)) throw new \Exception('工程师不存在');
-
+                $param['deduction_amount'] = $param['deduction_amount']??0;
+                $param['deduction_describe'] = $param['deduction_describe']??'';
+                $param['settlement_details_remarks'] = $param['settlement_details_remarks']??'';
 
 
+                if(!isset($param['final_settlement_amount']) || empty($param['final_settlement_amount'])){
+                    throw new \Exception('应付金额不能为空');
+                }
+                if($param['deduction_amount'] > 0 && (!isset($param['deduction_describe']) || empty($param['deduction_describe']))){
+                    throw new \Exception('扣款存在,扣款说明不能为空');
+                }
+                if(!in_array($param['master_worker_id'], $engineer_worker_ids)) throw new \Exception('下载记录不存在');
                 //判断日期时间格式是否正确 2024/1/1 00:00:00 或 2024-1-1 00:00:00
                 //判断日期时间格式是否正确 2024/1/1 00:00:00 或 2024-1-1 00:00:00
-                if(!preg_match('/^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])
+                if(isset($param['settlement_time']) && !preg_match('/^[0-9]{4}\/[0-9]{1,2}\/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])
                     && !preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])){
                     && !preg_match('/^[0-9]{4}-[0-9]{1,2}-[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/', $param['settlement_time'])){
                     throw new \Exception('日期时间格式错误');
                     throw new \Exception('日期时间格式错误');
-                }else{
-                    $param['settlement_time'] = date('Y-m-d H:i:s', strtotime($param['settlement_time']));
                 }
                 }
+                $param['settlement_time'] = isset($param['settlement_time'])?date('Y-m-d H:i:s', strtotime($param['settlement_time'])):date('Y-m-d H:i:s');
                 if(!is_numeric($param['original_balance']) || !is_numeric($param['total_settlement_amount']) || !is_numeric($param['deduction_amount']) || !is_numeric($param['final_settlement_amount'])){
                 if(!is_numeric($param['original_balance']) || !is_numeric($param['total_settlement_amount']) || !is_numeric($param['deduction_amount']) || !is_numeric($param['final_settlement_amount'])){
                     throw new \Exception('金额格式错误');
                     throw new \Exception('金额格式错误');
                 }
                 }
+                if($param['total_settlement_amount'] != ($param['final_settlement_amount']+$param['deduction_amount'])){
+                    throw new \Exception('金额计算错误:'.$param['master_worker_id']);
+                }
                 if(!preg_match('/^[0-9]*$/', $param['worker_number'])){
                 if(!preg_match('/^[0-9]*$/', $param['worker_number'])){
                     throw new \Exception('工程师编号格式错误:'.$param['worker_number']);
                     throw new \Exception('工程师编号格式错误:'.$param['worker_number']);
                 }
                 }
                 if(!preg_match('/^[0-9]*$/', $param['master_worker_id'])){
                 if(!preg_match('/^[0-9]*$/', $param['master_worker_id'])){
                     throw new \Exception('工程师ID格式错误:'.$param['master_worker_id']);
                     throw new \Exception('工程师ID格式错误:'.$param['master_worker_id']);
                 }
                 }
-                $masterWorker = MasterWorker::where('id', $param['master_worker_id'])->where('worker_number', $param['worker_number'])->findOrEmpty();
-                if($masterWorker->isEmpty()) throw new \Exception('工程师不存在:'.$param['master_worker_id']);
-                if($masterWorker->user_money < $param['total_settlement_amount']) throw new \Exception('余额不足');
+                if($masterWorkers[$param['master_worker_id']] < $param['total_settlement_amount']) throw new \Exception('余额不足-'.$param['master_worker_id']);
             }
             }
             return $params;
             return $params;
         } catch (\Exception $e) {
         } catch (\Exception $e) {

+ 4 - 3
app/common/service/ExcelExportService.php

@@ -123,16 +123,17 @@ class ExcelExportService
             ]);
             ]);
             //生成数据表格 & 更新表 -- 批次编号、状态-待算
             //生成数据表格 & 更新表 -- 批次编号、状态-待算
             $lists = MasterSettlementDetailsLogic::upBatchStatus($params,$batch_number);
             $lists = MasterSettlementDetailsLogic::upBatchStatus($params,$batch_number);
-            $filename = ($filename?:'').('-'.date('YmdHis').'-'.$infoExport->id);
+            $filename = ($filename?($filename.'-批号'.$batch_number):'').('-'.date('YmdHis').'-'.$infoExport->id);
             $this->sheet->generateExcelFile([
             $this->sheet->generateExcelFile([
                 '工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '所属银行', '工程师开户行及支行信息','导出时账号余额',
                 '工程师ID', '工程师编号', '工程师姓名', '工程师银行卡号', '所属银行', '工程师开户行及支行信息','导出时账号余额',
                 '批次编号',
                 '批次编号',
-                '应发金额', '扣款金额', '扣款说明', '实发金额', '打款状态','打款时间','备注'
+                '应发金额', '扣款金额', '扣款说明', '实发金额', '打款时间','备注'
             ], $lists,$filename, [
             ], $lists,$filename, [
                 'master_worker_id','worker_number','engineer_name','bank_account','bank_name','opening_branch','original_balance',
                 'master_worker_id','worker_number','engineer_name','bank_account','bank_name','opening_branch','original_balance',
                 'batch_number',
                 'batch_number',
-                'total_settlement_amount','','','','','',''
+                'total_settlement_amount','','','','',''
             ]);
             ]);
+            $infoExport->name = $filename;
             $infoExport->file_url = $this->sheet->fileUrl();
             $infoExport->file_url = $this->sheet->fileUrl();
             $infoExport->generate_status = 1;
             $infoExport->generate_status = 1;
             $infoExport->updatetime = time();
             $infoExport->updatetime = time();