TaskService.php 975 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/23
  6. * Time: 17:36
  7. */
  8. namespace App\Services\Content;
  9. use App\Repositories\TaskRepository;
  10. use Illuminate\Support\Facades\Cache;
  11. class TaskService
  12. {
  13. protected $taskRepository;
  14. /**
  15. * TaskService constructor.
  16. * @param $reportRepository
  17. */
  18. public function __construct(TaskRepository $taskRepository)
  19. {
  20. $this->taskRepository = $taskRepository;
  21. }
  22. //获取任务类型
  23. public function getTask($utype, $type = '')
  24. {
  25. $lists = Cache::get('task_list');
  26. if ($lists === null) {
  27. $task_lists = $this->taskRepository->all();
  28. foreach ($task_lists as $k => $v) {
  29. $lists[$v->utype][$v->t_alias] = $v;
  30. }
  31. Cache::put('task_list', $lists, '86400');
  32. }
  33. if ($type) {
  34. return array_get($lists[$utype], $type);
  35. }
  36. return $lists[$utype];
  37. }
  38. }