LaborApplyController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Http\Requests\LaborApply\LaborApplyRequest;
  4. use App\Jobs\LaborApplyRecordJob;
  5. use App\LaborApply;
  6. use App\Services\LaborApplyService;
  7. use App\UserWorkgroup;
  8. use App\Warehouse;
  9. use Illuminate\Contracts\Foundation\Application;
  10. use Illuminate\Http\RedirectResponse;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Routing\Redirector;
  13. use Illuminate\Support\Facades\Auth;
  14. use Illuminate\Support\Facades\Gate;
  15. class LaborApplyController extends Controller
  16. {
  17. public function index(Request $request,\App\Filters\LaborApplyFilters $filters)
  18. {
  19. $builder = LaborApply::query()
  20. ->filter($filters)
  21. ->with(['warehouse', 'userWorkGroup', 'applyUser']);
  22. if (!(\auth()->user()->isSuperAdmin() || Gate::allows('宝时人事部'))) {
  23. $builder->where('apply_user_id', \auth()->id());
  24. }
  25. $labor_applies = $builder
  26. ->orderByDesc('created_at')
  27. ->paginate();
  28. return view('personnel.laborApply.index', compact('labor_applies'));
  29. }
  30. public function create()
  31. {
  32. $warehouses = Warehouse::all();
  33. $userWorkGroups = UserWorkgroup::all();
  34. /** @var LaborApplyService $service */
  35. $service = app('LaborApplyService');
  36. //获取开放状态
  37. $can_create_status = $service->getCanCreateStatus();
  38. return view('personnel.laborApply.create', compact('userWorkGroups', 'warehouses', 'can_create_status'));
  39. }
  40. public function store(LaborApplyRequest $request, LaborApply $laborApply)
  41. {
  42. $laborApply->fill($request->all());
  43. $laborApply->apply_user_id = Auth::id();
  44. $laborApply->status = '创建';
  45. $laborApply->save();
  46. return redirect(route('laborApply.index'))->with('success', '申请成功!');
  47. }
  48. /**
  49. * Display the specified resource.
  50. *
  51. * @param \App\LaborApply $laborApply
  52. * @return \Illuminate\Http\Response
  53. */
  54. public function show(LaborApply $laborApply)
  55. {
  56. //
  57. }
  58. public function edit(LaborApply $laborApply)
  59. {
  60. $warehouses = Warehouse::all();
  61. $userWorkGroups = UserWorkgroup::all();
  62. return view('personnel.laborApply.edit', compact('laborApply', 'warehouses', 'userWorkGroups'));
  63. }
  64. public function update(Request $request, LaborApply $laborApply)
  65. {
  66. $laborApply->actual_num = $request->input('actual_num');
  67. $laborApply->status = '任务完结';
  68. $laborApply->save();
  69. return redirect(route('laborApply.index'))->with('success', '填写实到人数成功!');
  70. }
  71. /**
  72. * Remove the specified resource from storage.
  73. *
  74. * @param \App\LaborApply $laborApply
  75. * @return \Illuminate\Http\Response
  76. */
  77. public function destroy(LaborApply $laborApply)
  78. {
  79. $laborApply->delete();
  80. return redirect(route('laborApply.index'))->with('success', '删除成功');
  81. }
  82. /**
  83. * 临时开放按钮
  84. * @return Application|RedirectResponse|Redirector
  85. */
  86. public function temporaryOpen()
  87. {
  88. /** @var LaborApplyService $service */
  89. $service = app('LaborApplyService');
  90. $service->setCanCreateStatus(LaborApply::CAN_CREATE_STATUS_TEMPORARY_OPEN);
  91. $ttl = LaborApplyService::LABOR_APPLY_STATUS_TTL;
  92. //调用定时任务 开放时间过了自动生成报表
  93. LaborApplyRecordJob::dispatch()->delay(now()->addSeconds($ttl));
  94. return redirect(route('laborApply.create'))->with('success', "临时开放成功,有效时间为:{$ttl}S ");
  95. }
  96. /**
  97. *手动生成劳务分配
  98. */
  99. public function createDispatch()
  100. {
  101. /** @var LaborApplyService $laborApplyService */
  102. $laborApplyService = app('LaborApplyService');
  103. $response = $laborApplyService->allocationLaborToLaborCompany();
  104. if ($response['success']) {
  105. return redirect(route('laborApplyDispatch.index'))->with('success', '重新生成劳务派遣数据成功!');
  106. }else{
  107. return redirect(route('laborApplyDispatch.index'))->with('danger', $response['error_message']);
  108. }
  109. }
  110. }