|
|
@@ -26,13 +26,17 @@ class RetentionMoneyLogic extends BaseLogic
|
|
|
$incWhere =$where;
|
|
|
$incWhere[] = ['action', '=',WorkerAccountLogEnum::INC];
|
|
|
$data = [];
|
|
|
- $data['amount_inc_total'] = MasterWorkerRetentionMoneyLog::where($incWhere)
|
|
|
- ->sum('amount');
|
|
|
+ //$data['amount_inc_total'] = MasterWorkerRetentionMoneyLog::where($incWhere)->sum('amount');
|
|
|
+ $data['amount_inc_total'] = $model->earnest_money;
|
|
|
+
|
|
|
$outWhere = $where;
|
|
|
$outWhere[] =['action', '=',WorkerAccountLogEnum::DEC];
|
|
|
- $data['amount_dec_total'] = MasterWorkerRetentionMoneyLog::where($outWhere)
|
|
|
- ->sum('amount');
|
|
|
- $data['amount_available_total'] = $data['amount_inc_total'] - $data['amount_dec_total'];
|
|
|
+ //$data['amount_dec_total'] = MasterWorkerRetentionMoneyLog::where($outWhere)->sum('amount');
|
|
|
+ $data['amount_dec_total'] = $model->earnest_money_freeze;
|
|
|
+ //$data['amount_available_total'] = $data['amount_inc_total'] - $data['amount_dec_total'];
|
|
|
+ $data['amount_available_total'] = $model->earnest_money_usable;
|
|
|
+
|
|
|
+
|
|
|
$data['retention_money_status'] = $model->retention_money_status;
|
|
|
$data['retention_money_status_text'] = $model->retention_money_status_text;
|
|
|
$data['retention_pay_status'] = $model->retention_pay_status;
|
|
|
@@ -65,6 +69,24 @@ class RetentionMoneyLogic extends BaseLogic
|
|
|
'work_id' => $params['work_id'],
|
|
|
'remark' => $params['remark'],
|
|
|
]);
|
|
|
+
|
|
|
+ // $params['worker_id']
|
|
|
+ $masterWorkerInfo = MasterWorker::where('id', $params['worker_id'])->findOrEmpty();
|
|
|
+ if($params['action'] == WorkerAccountLogEnum::INC){
|
|
|
+ $masterWorkerInfo->earnest_money_usable += $params['earnest_money_usable'];
|
|
|
+ if($masterWorkerInfo->earnest_money_usable > $masterWorkerInfo->earnest_money){
|
|
|
+ throw new \Exception('可用质保金超过配置质保金');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if($params['action'] == WorkerAccountLogEnum::DEC){
|
|
|
+ $masterWorkerInfo->earnest_money_usable -= $params['earnest_money_usable'];
|
|
|
+ $masterWorkerInfo->earnest_money_freeze += $params['earnest_money_freeze'];
|
|
|
+ if($masterWorkerInfo->earnest_money_usable < 0){
|
|
|
+ throw new \Exception('可用质保金不足');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $masterWorkerInfo->save();
|
|
|
+
|
|
|
Db::commit();
|
|
|
return true;
|
|
|
} catch (\Exception $e) {
|