TalentLogApi.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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", "=", TalentState::DEPT_VERIFY_PASS];
  25. return TalentLog::where($where)->column("companyId");
  26. }
  27. public static function getFstLog($mainId, $type) {
  28. $where = [];
  29. $where[] = ["mainId", "=", $mainId];
  30. $where[] = ["type", "=", $type];
  31. $where[] = ["active", "=", 1];
  32. $where[] = ["typeFileId", "null"];
  33. $log = TalentLog::where($where)->order("createTime asc")->findOrEmpty()->toArray();
  34. return $log;
  35. }
  36. public static function getLastLog($mainId, $type, $companyId = 0, $extra_where = []) {
  37. $where = [];
  38. $where[] = ["mainId", "=", $mainId];
  39. $where[] = ["type", "=", $type];
  40. $where[] = ["typeFileId", "null"];
  41. if ($companyId) {
  42. $where[] = ["companyId", "=", $companyId];
  43. }
  44. if ($extra_where) {
  45. $where[] = $extra_where;
  46. }
  47. $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();
  48. return $last_log;
  49. }
  50. public static function getCompanyNewestCheckedLog($mainId, $companyId) {
  51. $where = [];
  52. $where[] = ["mainId", "=", $mainId];
  53. $where[] = ["step", "=", 3];
  54. $where[] = ["companyId", "=", $companyId];
  55. $where[] = ["active", "=", 1];
  56. $one = TalentLog::where($where)->order("createTime desc")->findOrEmpty();
  57. return $one;
  58. }
  59. public static function getLogByCompanyId($mainId, $companyId, $fst_dept_check_time) {
  60. $where = [];
  61. $where[] = ["mainId", "=", $mainId];
  62. $where[] = ["companyId", "=", $companyId];
  63. $where[] = ["createTime", ">=", $fst_dept_check_time];
  64. $one = TalentLog::where($where)->findOrEmpty();
  65. return $one;
  66. }
  67. public static function getListLogByTime($id, $time, $type = 1) {
  68. $where = [];
  69. $where[] = ["mainId", "=", $id];
  70. $where[] = ["type", "=", $type];
  71. $where[] = ["createTime", ">=", $time];
  72. $where[] = ["typeFileId", "null"];
  73. $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  74. return $list;
  75. }
  76. public static function writeDeptLogs($mainId, $companyIds, $state = []) {
  77. $user = session("user");
  78. $last_log = self::getLastLog($mainId, 1);
  79. for ($i = 0; $i < count($companyIds); $i++) {
  80. $log["last_state"] = $last_log["state"] ?: 0;
  81. $log["id"] = getStringId();
  82. if (is_array($state)) {
  83. $log["state"] = $state[0];
  84. $log["new_state"] = $state[1];
  85. } else {
  86. $log["state"] = $log["new_state"] = $state;
  87. }
  88. $log["type"] = 1;
  89. $log["mainId"] = $mainId;
  90. $log["companyId"] = $companyIds[$i];
  91. $log["description"] = "等待部门审核";
  92. $log["step"] = 3; //部门审核阶段
  93. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  94. $log["createTime"] = date("Y-m-d H:i:s");
  95. TalentLog::create($log);
  96. }
  97. }
  98. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  99. $user = session("user");
  100. $last_log = self::getLastLog($mainId, $type);
  101. $log["last_state"] = $last_log["state"] ?: 0;
  102. $log["id"] = getStringId();
  103. if (is_array($state)) {
  104. $log["state"] = $state[0];
  105. $log["new_state"] = $state[1];
  106. if ($state[2]) {
  107. $log["step"] = $state[2];
  108. }
  109. } else {
  110. $log["state"] = $log["new_state"] = $state;
  111. }
  112. $log["type"] = $type;
  113. $log["mainId"] = $mainId;
  114. $log["typeFileId"] = $fileType;
  115. $log["fileId"] = $fileId;
  116. $log["companyId"] = $user["companyId"];
  117. $log["active"] = $active;
  118. $log["description"] = $description;
  119. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  120. $log["createTime"] = date("Y-m-d H:i:s");
  121. return TalentLog::create($log);
  122. }
  123. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  124. $user = session("user");
  125. if (is_array($state)) {
  126. $log["state"] = $state[0];
  127. $log["new_state"] = $state[1];
  128. } else {
  129. $log["state"] = $log["new_state"] = $state;
  130. }
  131. $log["id"] = $id;
  132. $log["companyId"] = $user["companyId"];
  133. $log["active"] = $active;
  134. $log["description"] = $description;
  135. $log["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  136. $log["updateTime"] = date("Y-m-d H:i:s");
  137. return TalentLog::update($log);
  138. }
  139. public static function setActive($id, $value) {
  140. $user = session("user");
  141. $data["id"] = $id;
  142. $data["active"] = $value;
  143. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  144. $data["updateTime"] = date("Y-m-d H:i:s");
  145. return TalentLog::update($data);
  146. }
  147. }