TalentLogApi.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. return $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  15. }
  16. public static function getLastLog($mainId, $type, $companyId = 0) {
  17. $where = [];
  18. $where[] = ["mainId", "=", $mainId];
  19. $where[] = ["type", "=", $type];
  20. $where[] = ["typeFileId", "null"];
  21. if ($companyId) {
  22. $where[] = ["companyId", "=", $companyId];
  23. }
  24. $last_log = TalentLog::where($where)->order("createTime desc")->findOrEmpty()->toArray();
  25. return $last_log;
  26. }
  27. public static function getListLogByTime($id, $time) {
  28. $where = [];
  29. $where[] = ["mainId", "=", $id];
  30. $where[] = ["createTime", ">=", $time];
  31. $list = TalentLog::where($where)->order("createTime desc")->select()->toArray();
  32. return $list;
  33. }
  34. public static function write($type, $mainId, $state = [], $description = "", $active = 0, $fileType = null) {
  35. $user = session("user");
  36. $last_log = self::getLastLog($mainId, $type);
  37. $log["last_state"] = $last_log["state"] ?: 0;
  38. $log["id"] = getStringId();
  39. if (is_array($state)) {
  40. $log["state"] = $state[0];
  41. $log["new_state"] = $state[1];
  42. } else {
  43. $log["state"] = $log["new_state"] = $state;
  44. }
  45. $log["type"] = $type;
  46. $log["mainId"] = $mainId;
  47. $log["typeFileId"] = $fileType;
  48. $log["companyId"] = $user["companyId"];
  49. $log["active"] = $active;
  50. $log["description"] = $description;
  51. $log["createUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  52. $log["createTime"] = date("Y-m-d H:i:s");
  53. return TalentLog::create($log);
  54. }
  55. public static function rewrite($id, $state = [], $description = "", $active = 0) {
  56. $user = session("user");
  57. if (is_array($state)) {
  58. $log["state"] = $state[0];
  59. $log["new_state"] = $state[1];
  60. } else {
  61. $log["state"] = $log["new_state"] = $state;
  62. }
  63. $log["id"] = $id;
  64. $log["companyId"] = $user["companyId"];
  65. $log["active"] = $active;
  66. $log["description"] = $description;
  67. $log["updateUser"] = sprintf("%s(%s)", $user["account"], $user["companyName"] ?: $user["rolename"]);
  68. $log["updateTime"] = date("Y-m-d H:i:s");
  69. return TalentLog::update($log);
  70. }
  71. public static function setActive($id, $value) {
  72. $user = session("user");
  73. $data["id"] = $id;
  74. $data["active"] = $value;
  75. $data["updateUser"] = sprintf("%s(%s)", $user["account"], $user["rolename"]);
  76. $data["updateTime"] = date("Y-m-d H:i:s");
  77. return TalentLog::update($data);
  78. }
  79. }