TalentLogApi.php 9.1 KB

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