isEmpty()){ throw new \Exception('用户不存在'); } $where = []; $where[] = ['worker_id','=',$params['worker_id']] ; $incWhere =$where; $incWhere[] = ['action', '=',WorkerAccountLogEnum::INC]; $data = []; $data['amount_inc_total'] = MasterWorkerRetentionMoneyLog::where($incWhere) ->sum('amount'); $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['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; $data['retention_pay_status_text'] = $model->retention_pay_status_text; $data['worker_number'] = $model->worker_number; $data['real_name'] = $model->real_name; $data['worker_id'] = $model->id; return $data; } catch(\Exception $e){ self::setError($e->getMessage()); return false; } } public static function add($params) { Db::startTrans(); try { if(isset($params['work_id']) && !empty($params['work_id'])){ $workModel = ServiceWork::findOrEmpty($params['work_id']); if($workModel->isEmpty()){ throw new \Exception('工单不存在'); } } MasterWorkerRetentionMoneyLog::create([ 'sn' => generate_sn(MasterWorkerRetentionMoneyLog::class,'sn'), 'worker_id' => $params['worker_id'], 'action' => $params['action'], 'amount' => $params['amount'], 'work_id' => $params['work_id'], 'remark' => $params['remark'], ]); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } }