listQuery(); if (request()->input('_all')) { $list = (clone $query)->get(); $items = $list->all(); $total = $list->count(); } else { $list = (clone $query)->paginate(request()->input('perPage', 20)); $items = $list->items(); $total = $list->total(); } $user = Admin::user(); foreach($items as &$item) { $item->row_actions = $this->rowActions($user, $item); } return compact('items', 'total'); } public function rowActions(AdminUser $user, $model) { // view, edit, delete // apply, cancel $actions = []; if ($user->can('admin.hr.repairs.view')) { array_push($actions, 'view'); } if ($user->can('admin.hr.repairs.delete') && !in_array($model->workflow->check_status, [CheckStatus::Processing])) { array_push($actions, 'delete'); } if (in_array($model->workflow->check_status, [CheckStatus::None, CheckStatus::Cancel, CheckStatus::Fail])) { array_push($actions, 'apply'); } if (in_array($model->workflow->check_status, [CheckStatus::Processing])) { array_push($actions, 'cancel'); } return $actions; } public function resloveData($data, $model = null) { // 获取员工所在的门店 if (! isset($data['store_id']) && isset($data['employee_id'])) { $data['store_id'] = Employee::where('id', $data['employee_id'])->value('store_id'); } return $data; } public function validate($data, $model = null) { $createRules = [ 'employee_id' => ['required'], 'sign_time' => ['required'], 'date' => ['required'], 'store_id' => ['required'], 'reason' => ['required'], ]; $updateRules = [ ]; $message = [ 'date.required' => __('employee_sign_repair.date').'必填', 'store_id.required' => __('employee_sign_repair.store_id').'必填', 'employee_id.required' => __('employee_sign_repair.employee_id').'必填', 'reason.required' => __('employee_sign_repair.reason').'必填', 'sign_time.required' => __('employee_sign_repair.sign_time').'必填', ]; $validator = Validator::make($data, $model ? $updateRules : $createRules, $message); if ($validator->fails()) { return $validator->errors()->first(); } if (EmployeeSignLog::filter([ 'date' => $data['date'], 'employee_id' => $data['employee_id'], 'sign_time' => $data['sign_time'] ])->exists()) { return '已经打过卡了'; } // todo 已经打卡不能申请 // todo 验证申请时间是否重复 return true; } }