TalentLogApi.php 4.7 KB

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