Project.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Module;
  3. use DB;
  4. /**
  5. * Class Project
  6. * @package App\Module
  7. */
  8. class Project
  9. {
  10. /**
  11. * 是否在项目里
  12. * @param int $projectid
  13. * @param string $username
  14. * @return array
  15. */
  16. public static function inThe($projectid, $username)
  17. {
  18. $count = DB::table('project_users')->where([
  19. 'type' => '成员',
  20. 'projectid' => $projectid,
  21. 'username' => $username,
  22. ])->count();
  23. if ($count <= 0) {
  24. return Base::retError('你不在项目成员内!');
  25. } else {
  26. return Base::retSuccess('你在项目内');
  27. }
  28. }
  29. /**
  30. * 更新项目(complete、unfinished)
  31. * @param int $projectid
  32. */
  33. public static function updateNum($projectid)
  34. {
  35. DB::table('project_lists')->where('id', $projectid)->update([
  36. 'unfinished' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 0)->count(),
  37. 'complete' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 1)->count(),
  38. ]);
  39. }
  40. /**
  41. * 任务是否过期
  42. * @param array $task
  43. * @return int
  44. */
  45. public static function taskIsOverdue($task)
  46. {
  47. return $task['complete'] == 0 && $task['enddate'] > 0 && $task['enddate'] <= Base::time() ? 1 : 0;
  48. }
  49. /**
  50. * 过期的排在前
  51. * @param array $taskLists
  52. * @return mixed
  53. */
  54. public static function sortTask($taskLists)
  55. {
  56. $inOrder = [];
  57. foreach ($taskLists as $key => $oitem) {
  58. $inOrder[$key] = $oitem['overdue'] ? -1 : $key;
  59. }
  60. array_multisort($inOrder, SORT_ASC, $taskLists);
  61. return $taskLists;
  62. }
  63. }