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, CheckStatus::Success])) { 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', 'date'], '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 (!$model) { // 已经打卡, 不能申请 if (EmployeeSignLog::filter([ 'date' => $data['date'], 'employee_id' => $data['employee_id'], 'sign_time' => $data['sign_time'] ])->exists()) { return '已经补过卡了'; } // 同一天不能重复申请 if (EmployeeSignRepair::filter([ 'employee_id' => $data['employee_id'], 'date' => date('Y-m-d', strtotime($data['date'])), 'sign_time' => $data['sign_time'], ])->exists()) { return '已经申请过了'; } } return true; } public function delete(string $ids): mixed { $list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get(); foreach ($list as $item) { $item->delete(); } return true; } }