TalentLogApi.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 getCompanyNewestCheckedLog($mainId, $companyId) {
  72. $where = [];
  73. $where[] = ["mainId", "=", $mainId];
  74. $where[] = ["step", "=", 3];
  75. $where[] = ["companyId", "=", $companyId];
  76. //$where[] = ["active", "=", 1];
  77. $one = TalentLog::where($where)->order("createTime desc")->findOrEmpty();
  78. return $one;
  79. }
  80. public static function getLogByCompanyId($mainId, $companyId, $fst_dept_check_time) {
  81. $where = [];
  82. $where[] = ["mainId", "=", $mainId];
  83. $where[] = ["companyId", "=", $companyId];
  84. $where[] = ["createTime", ">=", $fst_dept_check_time];
  85. $one = TalentLog::where($where)->findOrEmpty();
  86. return $one;
  87. }
  88. public static function getListLogByTime($id, $time, $type = 1) {
  89. $where = [];
  90. $where[] = ["mainId", "=", $id];
  91. $where[] = ["type", "=", $type];
  92. $where[] = ["createTime", ">=", $time];
  93. $where[] = ["typeFileId", "null"];
  94. $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  95. return $list;
  96. }
  97. public static function writeDeptLogs($mainId, $companyIds, $state = []) {
  98. $user = session("user");
  99. $last_log = self::getLastLog($mainId, 1);
  100. for ($i = 0; $i < count($companyIds); $i++) {
  101. $log["last_state"] = $last_log["state"] ?: 0;
  102. $log["id"] = getStringId();
  103. if (is_array($state)) {
  104. $log["state"] = $state[0];
  105. $log["new_state"] = $state[1];
  106. } else {
  107. $log["state"] = $log["new_state"] = $state;
  108. }
  109. $log["type"] = 1;
  110. $log["mainId"] = $mainId;
  111. $log["companyId"] = $companyIds[$i];
  112. $log["description"] = "等待部门审核";
  113. $log["step"] = 3; //部门审核阶段
  114. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  115. $log["createTime"] = date("Y-m-d H:i:s");
  116. TalentLog::create($log);
  117. }
  118. }
  119. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  120. $user = session("user");
  121. $last_log = self::getLastLog($mainId, $type);
  122. $log["last_state"] = $last_log["state"] ?: 0;
  123. $log["id"] = getStringId();
  124. if (is_array($state)) {
  125. $log["state"] = $state[0];
  126. $log["new_state"] = $state[1];
  127. if ($state[2]) {
  128. $log["step"] = $state[2];
  129. }
  130. } else {
  131. $log["state"] = $log["new_state"] = $state;
  132. }
  133. $log["type"] = $type;
  134. $log["mainId"] = $mainId;
  135. $log["typeFileId"] = $fileType;
  136. $log["fileId"] = $fileId;
  137. $log["companyId"] = $user["companyId"];
  138. $log["active"] = $active;
  139. $log["description"] = $description;
  140. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  141. $log["createTime"] = date("Y-m-d H:i:s");
  142. return TalentLog::create($log);
  143. }
  144. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  145. $user = session("user");
  146. if (is_array($state)) {
  147. $log["state"] = $state[0];
  148. $log["new_state"] = $state[1];
  149. } else {
  150. $log["state"] = $log["new_state"] = $state;
  151. }
  152. $log["id"] = $id;
  153. $log["companyId"] = $user["companyId"];
  154. $log["active"] = $active;
  155. $log["description"] = $description;
  156. $log["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  157. $log["updateTime"] = date("Y-m-d H:i:s");
  158. return TalentLog::update($log);
  159. }
  160. public static function setActive($id, $value) {
  161. $user = session("user");
  162. $data["id"] = $id;
  163. $data["active"] = $value;
  164. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  165. $data["updateTime"] = date("Y-m-d H:i:s");
  166. return TalentLog::update($data);
  167. }
  168. public static function system($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null, $fileId = null) {
  169. $last_log = self::getLastLog($mainId, $type);
  170. $log["last_state"] = $last_log["state"] ?: 0;
  171. $log["id"] = getStringId();
  172. if (is_array($state)) {
  173. $log["state"] = $state[0];
  174. $log["new_state"] = $state[1];
  175. if ($state[2]) {
  176. $log["step"] = $state[2];
  177. }
  178. } else {
  179. $log["state"] = $log["new_state"] = $state;
  180. }
  181. $log["type"] = $type;
  182. $log["mainId"] = $mainId;
  183. $log["typeFileId"] = $fileType;
  184. $log["fileId"] = $fileId;
  185. $log["active"] = $active;
  186. $log["description"] = $description;
  187. $log["createUser"] = '系统';
  188. $log["createTime"] = date("Y-m-d H:i:s");
  189. return TalentLog::create($log);
  190. }
  191. }