Project.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. * @param bool $isowner
  15. * @return array
  16. */
  17. public static function inThe($projectid, $username, $isowner = false)
  18. {
  19. $whereArray = [
  20. 'type' => '成员',
  21. 'projectid' => $projectid,
  22. 'username' => $username,
  23. ];
  24. if ($isowner) {
  25. $whereArray['isowner'] = 1;
  26. }
  27. $row = Base::DBC2A(DB::table('project_users')->select(['isowner', 'indate'])->where($whereArray)->first());
  28. if (empty($row)) {
  29. return Base::retError('你不在项目成员内!');
  30. } else {
  31. return Base::retSuccess('你在项目内', $row);
  32. }
  33. }
  34. /**
  35. * 是否在关注列表里
  36. * @param int $taskid
  37. * @param string $username
  38. * @return array
  39. */
  40. public static function inAttention($taskid, $username)
  41. {
  42. $whereArray = [
  43. 'type' => '关注',
  44. 'projectid' => $projectid,
  45. 'username' => $username,
  46. ];
  47. if ($isowner) {
  48. $whereArray['isowner'] = 1;
  49. }
  50. $row = Base::DBC2A(DB::table('project_users')->select(['isowner', 'indate'])->where($whereArray)->first());
  51. if (empty($row)) {
  52. return Base::retError('你不在项目成员内!');
  53. } else {
  54. return Base::retSuccess('你在项目内', $row);
  55. }
  56. }
  57. /**
  58. * 更新项目(complete、unfinished)
  59. * @param int $projectid
  60. */
  61. public static function updateNum($projectid)
  62. {
  63. if ($projectid > 0) {
  64. DB::table('project_lists')->where('id', $projectid)->update([
  65. 'unfinished' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 0)->where('delete', 0)->count(),
  66. 'complete' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 1)->where('delete', 0)->count(),
  67. ]);
  68. }
  69. }
  70. /**
  71. * 任务是否过期
  72. * @param array $task
  73. * @return int
  74. */
  75. public static function taskIsOverdue($task)
  76. {
  77. return $task['complete'] == 0 && $task['enddate'] > 0 && $task['enddate'] <= Base::time() ? 1 : 0;
  78. }
  79. /**
  80. * 过期的排在前
  81. * @param array $taskLists
  82. * @return mixed
  83. */
  84. public static function sortTask($taskLists)
  85. {
  86. $inOrder = [];
  87. foreach ($taskLists as $key => $oitem) {
  88. $inOrder[$key] = $oitem['overdue'] ? -1 : $key;
  89. }
  90. array_multisort($inOrder, SORT_ASC, $taskLists);
  91. return $taskLists;
  92. }
  93. }