TalentLogApi.php 5.0 KB

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