Project.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * 更新项目(complete、unfinished)
  36. * @param int $projectid
  37. */
  38. public static function updateNum($projectid)
  39. {
  40. if ($projectid > 0) {
  41. DB::table('project_lists')->where('id', $projectid)->update([
  42. 'unfinished' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 0)->where('delete', 0)->count(),
  43. 'complete' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 1)->where('delete', 0)->count(),
  44. ]);
  45. }
  46. }
  47. /**
  48. * 任务是否过期
  49. * @param array $task
  50. * @return int
  51. */
  52. public static function taskIsOverdue($task)
  53. {
  54. return $task['complete'] == 0 && $task['enddate'] > 0 && $task['enddate'] <= Base::time() ? 1 : 0;
  55. }
  56. /**
  57. * 过期的排在前
  58. * @param array $taskLists
  59. * @return mixed
  60. */
  61. public static function sortTask($taskLists)
  62. {
  63. $inOrder = [];
  64. foreach ($taskLists as $key => $oitem) {
  65. $inOrder[$key] = $oitem['overdue'] ? -1 : $key;
  66. }
  67. array_multisort($inOrder, SORT_ASC, $taskLists);
  68. return $taskLists;
  69. }
  70. /**
  71. * 获取跟任务有关系的用户(关注的、在项目里的、负责人、创建者)
  72. * @param $taskId
  73. * @return array
  74. */
  75. public static function taskSomeUsers($taskId)
  76. {
  77. $taskDeatil = Base::DBC2A(DB::table('project_task')->select(['follower', 'createuser', 'username', 'projectid'])->where('id', $taskId)->first());
  78. if (empty($taskDeatil)) {
  79. return [];
  80. }
  81. //关注的用户
  82. $userArray = Base::string2array($taskDeatil['follower']);
  83. //创建者
  84. $userArray[] = $taskDeatil['createuser'];
  85. //负责人
  86. $userArray[] = $taskDeatil['username'];
  87. //在项目里的用户
  88. if ($taskDeatil['projectid'] > 0) {
  89. $tempLists = Base::DBC2A(DB::table('project_users')->select(['username'])->where(['projectid' => $taskDeatil['projectid'], 'type' => '成员' ])->get());
  90. foreach ($tempLists AS $item) {
  91. $userArray[] = $item['username'];
  92. }
  93. }
  94. //
  95. return $userArray;
  96. }
  97. }