Project.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. }