generated from liutk/owl-admin-base
api resource
parent
5772c4f002
commit
7a29a42bf6
|
|
@ -51,10 +51,10 @@ class EmployeePromotionService extends BaseService
|
|||
if ($user->can('admin.hr.promotion.view')) {
|
||||
array_push($actions, 'view');
|
||||
}
|
||||
if ($user->can('admin.hr.promotion.update') && in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
||||
if ($user->can('admin.hr.promotion.update') && !in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
||||
array_push($actions, 'edit');
|
||||
}
|
||||
if ($user->can('admin.hr.promotion.delete') && in_array($model->promotion_status, [PromotionStatus::Processing, PromotionStatus::Fail])) {
|
||||
if ($user->can('admin.hr.promotion.delete') && !in_array($model->promotion_status, [PromotionStatus::Processing, PromotionStatus::Fail])) {
|
||||
array_push($actions, 'delete');
|
||||
}
|
||||
if (in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
||||
|
|
|
|||
|
|
@ -92,15 +92,24 @@ class EmployeeSignRepairService extends BaseService
|
|||
if ($validator->fails()) {
|
||||
return $validator->errors()->first();
|
||||
}
|
||||
if (EmployeeSignLog::filter([
|
||||
'date' => $data['date'],
|
||||
'employee_id' => $data['employee_id'],
|
||||
'sign_time' => $data['sign_time']
|
||||
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 '已经申请过了';
|
||||
}
|
||||
}
|
||||
// todo 已经打卡不能申请
|
||||
// todo 验证申请时间是否重复
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class WorkflowController extends Controller
|
|||
->whereHas('check', fn($q) => $q->where('subject_type', $subjectType))
|
||||
->own($user)
|
||||
->where('check_status', '>', CheckStatus::None->value)
|
||||
->orderBy('check_status')
|
||||
// ->orderBy('check_status')
|
||||
->orderBy('id', 'desc')
|
||||
->paginate($request->input('per_page'));
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class AgreementResource extends JsonResource
|
|||
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
|
||||
|
||||
'created_at' => $this->created_at->timestamp,
|
||||
'created_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ class EmployeeSignRepairResource extends JsonResource
|
|||
|
||||
'reason' => $this->reason,
|
||||
'sign_time' => $this->sign_time,
|
||||
'sign_time_text' => $this->sign_time->text(),
|
||||
'sign_type' => $this->sign_type,
|
||||
'outside_remarks' => $this->outside_remarks,
|
||||
'created_at' => $this->created_at->timestamp,
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ class OvertimeApplyResource extends JsonResource
|
|||
|
||||
'reason' => $this->reason,
|
||||
'created_at' => $this->created_at->timestamp,
|
||||
'created_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class ReimbursementResource extends JsonResource
|
|||
'reason' => $this->reason,
|
||||
'photos' => $this->photos,
|
||||
'created_at' => $this->created_at?->getTimestamp(),
|
||||
'created_at_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
'created_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $this->updated_at?->getTimestamp(),
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use App\Models\TaskHygiene;
|
|||
use App\Models\TaskLedger;
|
||||
use App\Models\TaskPerformance;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use App\Exceptions\RuntimeException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
|
|
@ -18,30 +19,33 @@ class TaskResource extends JsonResource
|
|||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$resource = $this->mapResource($this->taskable_type);
|
||||
return [
|
||||
'id' => $this->resource->id,
|
||||
'name' => $this->resource->name,
|
||||
'taskable_type' => $this->resource->taskable_type,
|
||||
'taskable_id' => $this->resource->taskable_id,
|
||||
'taskable' => $this->when($this->resource->relationLoaded('taskable'), function () {
|
||||
$taskable = $this->resource->taskable;
|
||||
|
||||
switch (Relation::getMorphedModel($this->resource->taskable_type)) {
|
||||
case TaskLedger::class:
|
||||
return TaskLedgerResource::make($taskable);
|
||||
|
||||
case TaskHygiene::class:
|
||||
return TaskHygieneResource::make($taskable);
|
||||
|
||||
case TaskPerformance::class:
|
||||
return TaskPerformanceResource::make($taskable);
|
||||
}
|
||||
|
||||
return $taskable;
|
||||
}),
|
||||
'start_at' => (int) $this->resource->start_at?->timestamp,
|
||||
'end_at' => (int) $this->resource->end_at?->timestamp,
|
||||
'created_at' => $this->resource->created_at->timestamp,
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'taskable_type' => $this->taskable_type,
|
||||
'taskable_id' => $this->taskable_id,
|
||||
'taskable' => $resource::make($this->whenLoaded('taskable')),
|
||||
'start_at' => (int) $this->start_at?->timestamp,
|
||||
'start_format' => $this->start_at?->format('Y年m月d日'),
|
||||
'end_at' => (int) $this->end_at?->timestamp,
|
||||
'end_format' => $this->end_at?->format('Y年m月d日'),
|
||||
'created_at' => $this->created_at->timestamp,
|
||||
'created_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
protected function mapResource(string $type)
|
||||
{
|
||||
$model = Relation::getMorphedModel($type);
|
||||
$class = match ($model) {
|
||||
default => 'App\\Http\\Resources\\'.class_basename($model).'Resource',
|
||||
};
|
||||
|
||||
if (! class_exists($class)) {
|
||||
throw new RuntimeException('未知的 subject_type');
|
||||
}
|
||||
|
||||
return $class;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue