TalentLogApi.php 5.1 KB

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