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')) {
|
if ($user->can('admin.hr.promotion.view')) {
|
||||||
array_push($actions, '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');
|
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');
|
array_push($actions, 'delete');
|
||||||
}
|
}
|
||||||
if (in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
if (in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
||||||
|
|
|
||||||
|
|
@ -92,15 +92,24 @@ class EmployeeSignRepairService extends BaseService
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return $validator->errors()->first();
|
return $validator->errors()->first();
|
||||||
}
|
}
|
||||||
if (EmployeeSignLog::filter([
|
if (!$model) {
|
||||||
'date' => $data['date'],
|
// 已经打卡, 不能申请
|
||||||
'employee_id' => $data['employee_id'],
|
if (EmployeeSignLog::filter([
|
||||||
'sign_time' => $data['sign_time']
|
'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()) {
|
])->exists()) {
|
||||||
return '已经补过卡了';
|
return '已经申请过了';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// todo 已经打卡不能申请
|
|
||||||
// todo 验证申请时间是否重复
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ class WorkflowController extends Controller
|
||||||
->whereHas('check', fn($q) => $q->where('subject_type', $subjectType))
|
->whereHas('check', fn($q) => $q->where('subject_type', $subjectType))
|
||||||
->own($user)
|
->own($user)
|
||||||
->where('check_status', '>', CheckStatus::None->value)
|
->where('check_status', '>', CheckStatus::None->value)
|
||||||
->orderBy('check_status')
|
// ->orderBy('check_status')
|
||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->paginate($request->input('per_page'));
|
->paginate($request->input('per_page'));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ class AgreementResource extends JsonResource
|
||||||
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
|
'workflow_check' => WorkflowCheckResource::make($this->whenLoaded('workflow')),
|
||||||
|
|
||||||
'created_at' => $this->created_at->timestamp,
|
'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,
|
'reason' => $this->reason,
|
||||||
'sign_time' => $this->sign_time,
|
'sign_time' => $this->sign_time,
|
||||||
|
'sign_time_text' => $this->sign_time->text(),
|
||||||
'sign_type' => $this->sign_type,
|
'sign_type' => $this->sign_type,
|
||||||
'outside_remarks' => $this->outside_remarks,
|
'outside_remarks' => $this->outside_remarks,
|
||||||
'created_at' => $this->created_at->timestamp,
|
'created_at' => $this->created_at->timestamp,
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ class OvertimeApplyResource extends JsonResource
|
||||||
|
|
||||||
'reason' => $this->reason,
|
'reason' => $this->reason,
|
||||||
'created_at' => $this->created_at->timestamp,
|
'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,
|
'reason' => $this->reason,
|
||||||
'photos' => $this->photos,
|
'photos' => $this->photos,
|
||||||
'created_at' => $this->created_at?->getTimestamp(),
|
'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(),
|
'updated_at' => $this->updated_at?->getTimestamp(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use App\Models\TaskHygiene;
|
||||||
use App\Models\TaskLedger;
|
use App\Models\TaskLedger;
|
||||||
use App\Models\TaskPerformance;
|
use App\Models\TaskPerformance;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
|
use App\Exceptions\RuntimeException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
|
@ -18,30 +19,33 @@ class TaskResource extends JsonResource
|
||||||
*/
|
*/
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
|
$resource = $this->mapResource($this->taskable_type);
|
||||||
return [
|
return [
|
||||||
'id' => $this->resource->id,
|
'id' => $this->id,
|
||||||
'name' => $this->resource->name,
|
'name' => $this->name,
|
||||||
'taskable_type' => $this->resource->taskable_type,
|
'taskable_type' => $this->taskable_type,
|
||||||
'taskable_id' => $this->resource->taskable_id,
|
'taskable_id' => $this->taskable_id,
|
||||||
'taskable' => $this->when($this->resource->relationLoaded('taskable'), function () {
|
'taskable' => $resource::make($this->whenLoaded('taskable')),
|
||||||
$taskable = $this->resource->taskable;
|
'start_at' => (int) $this->start_at?->timestamp,
|
||||||
|
'start_format' => $this->start_at?->format('Y年m月d日'),
|
||||||
switch (Relation::getMorphedModel($this->resource->taskable_type)) {
|
'end_at' => (int) $this->end_at?->timestamp,
|
||||||
case TaskLedger::class:
|
'end_format' => $this->end_at?->format('Y年m月d日'),
|
||||||
return TaskLedgerResource::make($taskable);
|
'created_at' => $this->created_at->timestamp,
|
||||||
|
'created_format' => $this->created_at->format('Y-m-d H:i:s'),
|
||||||
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,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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