TalentLogApi.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\TalentLog;
  4. /**
  5. * Description of TalentLogApi
  6. *
  7. * @author sgq
  8. */
  9. class TalentLogApi {
  10. public static function getList($type, $mainId, $active = 1) {
  11. $where[] = ["type", "=", $type];
  12. $where[] = ["mainId", "=", $mainId];
  13. $where[] = ["active", "=", $active];
  14. $whr[] = ["step", "=", 3];
  15. $whr[] = ["type", "=", $type];
  16. $whr[] = ["mainId", "=", $mainId];
  17. return $list = TalentLog::whereOr([$where, $whr])->order("createTime desc")->select()->toArray();
  18. }
  19. public static function getPassDepts($mainId) {
  20. $where[] = ["type", "=", 1];
  21. $where[] = ["mainId", "=", $mainId];
  22. $where[] = ["active", "=", 1];
  23. $where[] = ["step", "=", 3];
  24. $where[] = ["new_state", "=", 9];
  25. return TalentLog::where($where)->column("companyId");
  26. }
  27. public static function getLastLog($mainId, $type, $companyId = 0, $extra_where = []) {
  28. $where = [];
  29. $where[] = ["mainId", "=", $mainId];
  30. $where[] = ["type", "=", $type];
  31. $where[] = ["typeFileId", "null"];
  32. if ($companyId) {
  33. $where[] = ["companyId", "=", $companyId];
  34. }
  35. if ($extra_where) {
  36. $where[] = $extra_where;
  37. }
  38. $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();
  39. return $last_log;
  40. }
  41. public static function getCompanyNewestCheckedLog($mainId, $companyId) {
  42. $where = [];
  43. $where[] = ["mainId", "=", $mainId];
  44. $where[] = ["step", "=", 3];
  45. $where[] = ["companyId", "=", $companyId];
  46. $where[] = ["active", "=", 1];
  47. $one = TalentLog::where($where)->order("createTime desc")->findOrEmpty();
  48. return $one;
  49. }
  50. public static function getLogByCompanyId($mainId, $companyId, $fst_dept_check_time) {
  51. $where = [];
  52. $where[] = ["mainId", "=", $mainId];
  53. $where[] = ["companyId", "=", $companyId];
  54. $where[] = ["createTime", ">=", $fst_dept_check_time];
  55. $one = TalentLog::where($where)->findOrEmpty();
  56. return $one;
  57. }
  58. public static function getListLogByTime($id, $time, $type = 1) {
  59. $where = [];
  60. $where[] = ["mainId", "=", $id];
  61. $where[] = ["type", "=", $type];
  62. $where[] = ["createTime", ">=", $time];
  63. $where[] = ["typeFileId", "null"];
  64. $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  65. return $list;
  66. }
  67. public static function writeDeptLogs($mainId, $companyIds, $state = []) {
  68. $user = session("user");
  69. $last_log = self::getLastLog($mainId, 1);
  70. for ($i = 0; $i < count($companyIds); $i++) {
  71. $log["last_state"] = $last_log["state"] ?: 0;
  72. $log["id"] = getStringId();
  73. if (is_array($state)) {
  74. $log["state"] = $state[0];
  75. $log["new_state"] = $state[1];
  76. } else {
  77. $log["state"] = $log["new_state"] = $state;
  78. }
  79. $log["type"] = 1;
  80. $log["mainId"] = $mainId;
  81. $log["companyId"] = $companyIds[$i];
  82. $log["description"] = "等待部门审核";
  83. $log["step"] = 3; //部门审核阶段
  84. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  85. $log["createTime"] = date("Y-m-d H:i:s");
  86. TalentLog::create($log);
  87. }
  88. }
  89. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  90. $user = session("user");
  91. $last_log = self::getLastLog($mainId, $type);
  92. $log["last_state"] = $last_log["state"] ?: 0;
  93. $log["id"] = getStringId();
  94. if (is_array($state)) {
  95. $log["state"] = $state[0];
  96. $log["new_state"] = $state[1];
  97. if ($state[2]) {
  98. $log["step"] = $state[2];
  99. }
  100. } else {
  101. $log["state"] = $log["new_state"] = $state;
  102. }
  103. $log["type"] = $type;
  104. $log["mainId"] = $mainId;
  105. $log["typeFileId"] = $fileType;
  106. $log["fileId"] = $fileId;
  107. $log["companyId"] = $user["companyId"];
  108. $log["active"] = $active;
  109. $log["description"] = $description;
  110. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  111. $log["createTime"] = date("Y-m-d H:i:s");
  112. return TalentLog::create($log);
  113. }
  114. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  115. $user = session("user");
  116. if (is_array($state)) {
  117. $log["state"] = $state[0];
  118. $log["new_state"] = $state[1];
  119. } else {
  120. $log["state"] = $log["new_state"] = $state;
  121. }
  122. $log["id"] = $id;
  123. $log["companyId"] = $user["companyId"];
  124. $log["active"] = $active;
  125. $log["description"] = $description;
  126. $log["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  127. $log["updateTime"] = date("Y-m-d H:i:s");
  128. return TalentLog::update($log);
  129. }
  130. public static function setActive($id, $value) {
  131. $user = session("user");
  132. $data["id"] = $id;
  133. $data["active"] = $value;
  134. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  135. $data["updateTime"] = date("Y-m-d H:i:s");
  136. return TalentLog::update($data);
  137. }
  138. }