TalentLogApi.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 getLastLogByStep($id, $type, $step, $active = 2) {
  112. $where = [];
  113. $where[] = ["mainId", "=", $id];
  114. $where[] = ["type", "=", $type];
  115. $where[] = ["active", "=", $active];
  116. $where[] = ["step", "=", $step];
  117. $last = TalentLog::where($where)->order("createTime desc")->find();
  118. return $last;
  119. }
  120. public static function writeDeptLogs($mainId, $companyIds, $state = []) {
  121. $user = session("user");
  122. $last_log = self::getLastLog($mainId, 1, 0, ["active", "=", 1]);
  123. for ($i = 0; $i < count($companyIds); $i++) {
  124. $log["last_state"] = $last_log["state"] ?: 0;
  125. $log["id"] = getStringId();
  126. if (is_array($state)) {
  127. $log["state"] = $state[0];
  128. $log["new_state"] = $state[1];
  129. } else {
  130. $log["state"] = $log["new_state"] = $state;
  131. }
  132. $log["type"] = 1;
  133. $log["mainId"] = $mainId;
  134. $log["companyId"] = $companyIds[$i];
  135. $log["description"] = "等待部门审核";
  136. $log["step"] = 3; //部门审核阶段
  137. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  138. $log["createTime"] = date("Y-m-d H:i:s");
  139. TalentLog::create($log);
  140. }
  141. }
  142. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null, $companyId = null) {
  143. $user = session("user");
  144. $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);
  145. $log["last_state"] = $last_log["state"] ?: 0;
  146. $log["id"] = getStringId();
  147. if (is_array($state)) {
  148. $log["state"] = $state[0];
  149. $log["new_state"] = $state[1];
  150. if ($state[2]) {
  151. $log["step"] = $state[2];
  152. }
  153. } else {
  154. $log["state"] = $log["new_state"] = $state;
  155. }
  156. $log["type"] = $type;
  157. $log["mainId"] = $mainId;
  158. $log["typeFileId"] = $fileType;
  159. $log["fileId"] = $fileId;
  160. if ($user) {
  161. $log["companyId"] = $user["companyId"];
  162. }
  163. if ($companyId) {
  164. $log["companyId"] = $companyId;
  165. }
  166. $log["active"] = $active;
  167. $log["description"] = $description;
  168. $log["createUser"] = $user ? ($user["userType"] == 3 ? "申报用户" : sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"])) : "系统";
  169. $log["createTime"] = date("Y-m-d H:i:s");
  170. return TalentLog::create($log);
  171. }
  172. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  173. $user = session("user");
  174. if (is_array($state)) {
  175. $log["state"] = $state[0];
  176. $log["new_state"] = $state[1];
  177. } else {
  178. $log["state"] = $log["new_state"] = $state;
  179. }
  180. $log["id"] = $id;
  181. if ($user) {
  182. $log["companyId"] = $user["companyId"];
  183. }
  184. $log["active"] = $active;
  185. $log["description"] = $description;
  186. $log["updateUser"] = $user ? ($user["userType"] == 3 ? "申报用户" : sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"])) : "系统";
  187. $log["updateTime"] = date("Y-m-d H:i:s");
  188. return TalentLog::update($log);
  189. }
  190. public static function setActive($id, $value) {
  191. $user = session("user");
  192. $data["id"] = $id;
  193. $data["active"] = $value;
  194. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  195. $data["updateTime"] = date("Y-m-d H:i:s");
  196. return TalentLog::update($data);
  197. }
  198. public static function system($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  199. $last_log = self::getLastLog($mainId, $type, 0, ["active", "=", 1]);
  200. $log["last_state"] = $last_log["state"] ?: 0;
  201. $log["id"] = getStringId();
  202. if (is_array($state)) {
  203. $log["state"] = $state[0];
  204. $log["new_state"] = $state[1];
  205. if ($state[2]) {
  206. $log["step"] = $state[2];
  207. }
  208. } else {
  209. $log["state"] = $log["new_state"] = $state;
  210. }
  211. $log["type"] = $type;
  212. $log["mainId"] = $mainId;
  213. $log["typeFileId"] = $fileType;
  214. $log["fileId"] = $fileId;
  215. $log["active"] = $active;
  216. $log["description"] = $description;
  217. $log["createUser"] = '系统';
  218. $log["createTime"] = date("Y-m-d H:i:s");
  219. return TalentLog::create($log);
  220. }
  221. }