TalentLogApi.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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, $fst_dept_check_time = null) {
  20. $dept_pass_state = TalentState::DEPT_VERIFY_PASS;
  21. $where[] = ["type", "=", 1];
  22. $where[] = ["mainId", "=", $mainId];
  23. $where[] = ["step", "=", 3];
  24. if ($fst_dept_check_time) {
  25. $where[] = ["createTime", ">=", $fst_dept_check_time];
  26. }
  27. $dept_logs = TalentLog::where($where)->order("createTime desc")->select();
  28. $check_depts = [];
  29. $pass_depts = [];
  30. foreach ($dept_logs as $dept_log) {
  31. if (!in_array($dept_log["companyId"], $check_depts)) {
  32. $check_depts[] = $dept_log["companyId"];
  33. if ($dept_log["new_state"] == $dept_pass_state && $dept_log["active"] == 1) {
  34. $pass_depts[] = $dept_log["companyId"];
  35. }
  36. }
  37. }
  38. return array_unique($pass_depts);
  39. }
  40. public static function getUnCheckDepts($mainId) {
  41. $where[] = ["type", "=", 1];
  42. $where[] = ["mainId", "=", $mainId];
  43. $where[] = ["active", "=", 0];
  44. $where[] = ["step", "=", 3];
  45. //$where[] = ["new_state", "in", [TalentState::DEPT_VERIFY_PASS, TalentState::FST_VERIFY_PASS]];
  46. return TalentLog::where($where)->column("companyId");
  47. }
  48. public static function getFstLog($mainId, $type) {
  49. $where = [];
  50. $where[] = ["mainId", "=", $mainId];
  51. $where[] = ["type", "=", $type];
  52. $where[] = ["active", "=", 1];
  53. $where[] = ["typeFileId", "null"];
  54. $log = TalentLog::where($where)->order("createTime asc")->findOrEmpty()->toArray();
  55. return $log;
  56. }
  57. public static function getLastLog($mainId, $type, $companyId = 0, $extra_where = []) {
  58. $where = [];
  59. $where[] = ["mainId", "=", $mainId];
  60. $where[] = ["type", "=", $type];
  61. $where[] = ["typeFileId", "null"];
  62. if ($companyId) {
  63. $where[] = ["companyId", "=", $companyId];
  64. }
  65. if ($extra_where) {
  66. $where[] = $extra_where;
  67. }
  68. $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();
  69. return $last_log;
  70. }
  71. public static function getLastLogEx($mainId, $type, $companyId = 0, $extra_where = []) {
  72. $where = [];
  73. $where[] = ["mainId", "=", $mainId];
  74. $where[] = ["type", "=", $type];
  75. $where[] = ["typeFileId", "null"];
  76. if ($companyId) {
  77. $where[] = ["companyId", "=", $companyId];
  78. }
  79. if ($extra_where) {
  80. $where = array_merge($where, (array) $extra_where);
  81. }
  82. $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();
  83. return $last_log;
  84. }
  85. public static function getCompanyNewestCheckedLog($mainId, $companyId) {
  86. $where = [];
  87. $where[] = ["mainId", "=", $mainId];
  88. $where[] = ["step", "=", 3];
  89. $where[] = ["companyId", "=", $companyId];
  90. //$where[] = ["active", "=", 1];
  91. $one = TalentLog::where($where)->order("createTime desc")->find();
  92. return $one;
  93. }
  94. public static function getLogByCompanyId($mainId, $companyId, $fst_dept_check_time) {
  95. $where = [];
  96. $where[] = ["mainId", "=", $mainId];
  97. $where[] = ["companyId", "=", $companyId];
  98. $where[] = ["createTime", ">=", $fst_dept_check_time];
  99. $one = TalentLog::where($where)->find();
  100. return $one;
  101. }
  102. public static function getListLogByTime($id, $time, $type = 1) {
  103. $where = [];
  104. $where[] = ["mainId", "=", $id];
  105. $where[] = ["type", "=", $type];
  106. $where[] = ["createTime", ">=", $time];
  107. $where[] = ["typeFileId", "null"];
  108. $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  109. return $list;
  110. }
  111. public static function writeDeptLogs($mainId, $companyIds, $state = []) {
  112. $user = session("user");
  113. $last_log = self::getLastLog($mainId, 1, 0, ["active", "=", 1]);
  114. for ($i = 0; $i < count($companyIds); $i++) {
  115. $log["last_state"] = $last_log["state"] ?: 0;
  116. $log["id"] = getStringId();
  117. if (is_array($state)) {
  118. $log["state"] = $state[0];
  119. $log["new_state"] = $state[1];
  120. } else {
  121. $log["state"] = $log["new_state"] = $state;
  122. }
  123. $log["type"] = 1;
  124. $log["mainId"] = $mainId;
  125. $log["companyId"] = $companyIds[$i];
  126. $log["description"] = "等待部门审核";
  127. $log["step"] = 3; //部门审核阶段
  128. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  129. $log["createTime"] = date("Y-m-d H:i:s");
  130. TalentLog::create($log);
  131. }
  132. }
  133. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null, $companyId = null) {
  134. $user = session("user");
  135. $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);
  136. $log["last_state"] = $last_log["state"] ?: 0;
  137. $log["id"] = getStringId();
  138. if (is_array($state)) {
  139. $log["state"] = $state[0];
  140. $log["new_state"] = $state[1];
  141. if ($state[2]) {
  142. $log["step"] = $state[2];
  143. }
  144. } else {
  145. $log["state"] = $log["new_state"] = $state;
  146. }
  147. $log["type"] = $type;
  148. $log["mainId"] = $mainId;
  149. $log["typeFileId"] = $fileType;
  150. $log["fileId"] = $fileId;
  151. if ($user) {
  152. $log["companyId"] = $user["companyId"];
  153. }
  154. if ($companyId) {
  155. $log["companyId"] = $companyId;
  156. }
  157. $log["active"] = $active;
  158. $log["description"] = $description;
  159. $log["createUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  160. $log["createTime"] = date("Y-m-d H:i:s");
  161. return TalentLog::create($log);
  162. }
  163. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  164. $user = session("user");
  165. if (is_array($state)) {
  166. $log["state"] = $state[0];
  167. $log["new_state"] = $state[1];
  168. } else {
  169. $log["state"] = $log["new_state"] = $state;
  170. }
  171. $log["id"] = $id;
  172. if ($user) {
  173. $log["companyId"] = $user["companyId"];
  174. }
  175. $log["active"] = $active;
  176. $log["description"] = $description;
  177. $log["updateUser"] = $user ? sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]) : "系统";
  178. $log["updateTime"] = date("Y-m-d H:i:s");
  179. return TalentLog::update($log);
  180. }
  181. public static function setActive($id, $value) {
  182. $user = session("user");
  183. $data["id"] = $id;
  184. $data["active"] = $value;
  185. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  186. $data["updateTime"] = date("Y-m-d H:i:s");
  187. return TalentLog::update($data);
  188. }
  189. public static function system($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  190. $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);
  191. $log["last_state"] = $last_log["state"] ?: 0;
  192. $log["id"] = getStringId();
  193. if (is_array($state)) {
  194. $log["state"] = $state[0];
  195. $log["new_state"] = $state[1];
  196. if ($state[2]) {
  197. $log["step"] = $state[2];
  198. }
  199. } else {
  200. $log["state"] = $log["new_state"] = $state;
  201. }
  202. $log["type"] = $type;
  203. $log["mainId"] = $mainId;
  204. $log["typeFileId"] = $fileType;
  205. $log["fileId"] = $fileId;
  206. $log["active"] = $active;
  207. $log["description"] = $description;
  208. $log["createUser"] = '系统';
  209. $log["createTime"] = date("Y-m-d H:i:s");
  210. return TalentLog::create($log);
  211. }
  212. }