generated from liutk/owl-admin-base
route
parent
3c5569ab09
commit
5b8903bfed
|
|
@ -13,6 +13,7 @@ use Illuminate\Support\Arr;
|
|||
use Slowlyo\OwlAdmin\Admin;
|
||||
use App\Enums\CheckStatus;
|
||||
use Slowlyo\OwlAdmin\Models\AdminUser;
|
||||
use App\Exceptions\RuntimeException;
|
||||
|
||||
class EmployeePromotionService extends BaseService
|
||||
{
|
||||
|
|
@ -53,7 +54,7 @@ class EmployeePromotionService extends BaseService
|
|||
if ($user->can('admin.hr.promotion.update') && $model->canUpdate()) {
|
||||
array_push($actions, 'edit');
|
||||
}
|
||||
if ($user->can('admin.hr.promotion.delete') && $model->canUpdate()) {
|
||||
if ($user->can('admin.hr.promotion.delete') ) {
|
||||
array_push($actions, 'delete');
|
||||
}
|
||||
if (in_array($model->promotion_status, [PromotionStatus::Processing])) {
|
||||
|
|
@ -82,8 +83,8 @@ class EmployeePromotionService extends BaseService
|
|||
*/
|
||||
public function apply($model, $data = [])
|
||||
{
|
||||
if (!$model->canUpdate()) {
|
||||
return $this->setError('审核中, 无法修改');
|
||||
if ($model->promotion_status != PromotionStatus::Employee) {
|
||||
return $this->setError('无法修改');
|
||||
}
|
||||
$validator = Validator::make($data, [
|
||||
'age' => ['required'],
|
||||
|
|
@ -113,8 +114,8 @@ class EmployeePromotionService extends BaseService
|
|||
*/
|
||||
public function invitor($model, $data = [])
|
||||
{
|
||||
if (!$model->canUpdate()) {
|
||||
return $this->setError('审核中, 无法修改');
|
||||
if ($model->promotion_status != PromotionStatus::Invitor) {
|
||||
return $this->setError('无法修改');
|
||||
}
|
||||
$validator = Validator::make($data, [
|
||||
'reason' => ['required'],
|
||||
|
|
@ -174,7 +175,7 @@ class EmployeePromotionService extends BaseService
|
|||
$list = $this->query()->with(['workflow'])->whereIn('id', explode(',', $ids))->get();
|
||||
foreach ($list as $item) {
|
||||
if (!$item->canUpdate()) {
|
||||
return $this->setError($item->promotion_status->text() . ', 无法删除');
|
||||
throw new RuntimeException($item->promotion_status->text() . ', 无法删除');
|
||||
}
|
||||
$item->delete();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class EmployeeService extends BaseService
|
|||
|
||||
// 职位修改
|
||||
if (isset($data['jobs'])) {
|
||||
dd($data['jobs']);
|
||||
$jobs = is_array($data['jobs']) ? $data['jobs'] : explode(',', $data['jobs']);
|
||||
$model->jobs()->sync($jobs);
|
||||
}
|
||||
|
|
@ -71,7 +72,7 @@ class EmployeeService extends BaseService
|
|||
// 职位修改
|
||||
if (isset($data['jobs'])) {
|
||||
if (is_array($data['jobs'])) {
|
||||
if (is_array($data['jobs'][0])) {
|
||||
if (count($data['jobs']) > 0 && is_array($data['jobs'][0])) {
|
||||
$jobs = array_column($data['jobs'], 'key');
|
||||
} else {
|
||||
$jobs = $data['jobs'];
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ enum PromotionStatus: int
|
|||
public static function options()
|
||||
{
|
||||
return [
|
||||
self::Employee->value => '待提交',
|
||||
self::Employee->value => '待补充',
|
||||
self::Invitor->value => '待推荐',
|
||||
self::Processing->value => '审核中',
|
||||
self::Success->value => '审核通过',
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ class PromotionController extends Controller
|
|||
public function show($id)
|
||||
{
|
||||
$info = EmployeePromotion::with(['workflow', 'employee', 'invitor', 'job'])->findOrFail($id);
|
||||
|
||||
return EmployeePromotionResource::make($info);
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +92,40 @@ class PromotionController extends Controller
|
|||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function update($id, Request $request, EmployeePromotionService $service)
|
||||
{
|
||||
$user = $this->guard()->user();
|
||||
$info = EmployeePromotion::findOrFail($id);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
// 申请人完善资料
|
||||
if ($info->promotion_status == PromotionStatus::Employee) {
|
||||
if (!$service->apply($info, $request->only(['age', 'sex', 'education', 'first_work_time', 'work_years', 'work_years_in_company', 'comment_self', 'plans', 'reason']))) {
|
||||
throw new RuntimeException($service->getError());
|
||||
}
|
||||
}
|
||||
// 推荐人填写
|
||||
else if ($info->promotion_status == PromotionStatus::Invitor) {
|
||||
if (!$service->invitor($info, $request->only(['reason']))) {
|
||||
throw new RuntimeException($service->getError());
|
||||
}
|
||||
$workflow = WorkFlowService::make();
|
||||
if (!$workflow->apply($info->workflow, $info->employee)) {
|
||||
throw new RuntimeException($workflow->getError());
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException('资料已填写, 不能修改');
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
return response()->noContent();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
throw new RuntimeException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function destroy($id, EmployeePromotionService $service)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ Route::group([
|
|||
Route::get('hr/promotion/apply', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'applyList']);
|
||||
Route::get('hr/promotion/invite', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'inviteList']);
|
||||
Route::get('hr/promotion/{id}', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'show']);
|
||||
Route::post('hr/promotion/{id}', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'update']);
|
||||
Route::post('hr/promotion/{id}/apply', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'applyUpdate']);
|
||||
Route::post('hr/promotion/{id}/invite', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'inviteUpdate']);
|
||||
Route::delete('hr/promotion/{id}', [\App\Http\Controllers\Api\Hr\PromotionController::class, 'destroy']);
|
||||
|
|
|
|||
Loading…
Reference in New Issue