TalentLogApi.php 6.2 KB

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