|
@@ -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) {
|