Project.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. DB::table('project_lists')->where('id', $projectid)->update([
  41. 'unfinished' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 0)->where('delete', 0)->count(),
  42. 'complete' => DB::table('project_task')->where('projectid', $projectid)->where('complete', 1)->where('delete', 0)->count(),
  43. ]);
  44. }
  45. /**
  46. * 任务是否过期
  47. * @param array $task
  48. * @return int
  49. */
  50. public static function taskIsOverdue($task)
  51. {
  52. return $task['complete'] == 0 && $task['enddate'] > 0 && $task['enddate'] <= Base::time() ? 1 : 0;
  53. }
  54. /**
  55. * 过期的排在前
  56. * @param array $taskLists
  57. * @return mixed
  58. */
  59. public static function sortTask($taskLists)
  60. {
  61. $inOrder = [];
  62. foreach ($taskLists as $key => $oitem) {
  63. $inOrder[$key] = $oitem['overdue'] ? -1 : $key;
  64. }
  65. array_multisort($inOrder, SORT_ASC, $taskLists);
  66. return $taskLists;
  67. }
  68. }