EducationApi.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\EducationSchool as EduModel;
  4. use app\common\state\MainState;
  5. use think\facade\Db;
  6. /**
  7. * Description of EducationApi
  8. *
  9. * @author sgq
  10. */
  11. class EducationApi {
  12. public static function getList($params) {
  13. $user = session("user");
  14. $order = trim($params["order"]) ?: "desc";
  15. $offset = trim($params["offset"]) ?: 0;
  16. $limit = trim($params["limit"]) ?: 10;
  17. $where = [];
  18. if ($user["usertype"] == 3) {
  19. $where[] = ["personId", "=", $user["uid"]];
  20. } else if ($user["usertype"] == 1) {
  21. $where[] = ["type", "=", $user["type"]];
  22. } else {
  23. return [];
  24. }
  25. if ($_where = self::getWhereByParams($params)) {
  26. $where = array_merge($where, $_where);
  27. }
  28. $count = EduModel::where($where)->count();
  29. $list = EduModel::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  30. $levelMap = DictApi::selectByParentCode("talent_arrange");
  31. $streetMap = DictApi::selectByParentCode("street");
  32. $relationMap = DictApi::selectByParentCode("education_relation");
  33. $gradeMap = DictApi::selectByParentCode("education_grade");
  34. $educationProjectMap = DictApi::selectByParentCode("education_project");
  35. $schoolMap = DictApi::selectByParentCode("education_school_pool");
  36. foreach ($list as $key => $item) {
  37. $list[$key]["talentArrangeName"] = $levelMap[$item["talentArrange"]];
  38. $list[$key]["houseStreetName"] = $streetMap[$item["houseStreet"]];
  39. $list[$key]["companyStreetName"] = $streetMap[$item["companyStreet"]];
  40. $list[$key]["cRelationName"] = $relationMap[$item["cRelation"]];
  41. $list[$key]["nowGradeName"] = $gradeMap[$item["nowGrade"]];
  42. $list[$key]["projectName"] = $educationProjectMap[$item["project"]];
  43. $list[$key]["applySchoolName"] = $schoolMap[$item["applySchool"]];
  44. }
  45. return ["total" => $count, "rows" => $list];
  46. }
  47. public static function getWhereByParams($params) {
  48. foreach ($params as $key => $param) {
  49. $params[$key] = trim(\StrUtil::getRequestDecodeParam($params, $key));
  50. }unset($param);
  51. $where = [];
  52. if ($params["year"]) {
  53. $where[] = ["year", "=", $params["year"]];
  54. }
  55. if ($params["enterpriseName"]) {
  56. $where[] = ["enterpriseName", "like", "%" . $params["enterpriseName"] . "%"];
  57. }
  58. if ($params["pName"]) {
  59. $where[] = ["pName", "like", "%" . $params["pName"] . "%"];
  60. }
  61. if ($params["pSex"]) {
  62. $where[] = ["pSex", "=", $params["pSex"]];
  63. }
  64. if ($params["pIdcard"]) {
  65. $where[] = ["pIdcard", "like", "%" . $params["pIdcard"] . "%"];
  66. }
  67. if ($params["talentArrange"]) {
  68. $where[] = ["talentArrange", "=", $params["talentArrange"]];
  69. }
  70. if ($params["certificateNo"]) {
  71. $where[] = ["certificateNo", "like", "%" . $params["certificateNo"] . "%"];
  72. }
  73. if ($params["address"]) {
  74. $where[] = ["address", "like", "%" . $params["address"] . "%"];
  75. }
  76. if ($params["phone"]) {
  77. $where[] = ["phone", "like", "%" . $params["phone"] . "%"];
  78. }
  79. if ($params["project"]) {
  80. $where[] = ["project", "=", $params["project"]];
  81. }
  82. if ($params["cName"]) {
  83. $where[] = ["cName", "like", "%" . $params["cName"] . "%"];
  84. }
  85. if ($params["cSex"]) {
  86. $where[] = ["cSex", "=", $params["cSex"]];
  87. }
  88. if ($params["cIdcard"]) {
  89. $where[] = ["cIdcard", "like", "%" . $params["cIdcard"] . "%"];
  90. }
  91. if ($params["cRelation"]) {
  92. $where[] = ["cRelation", "=", $params["cRelation"]];
  93. }
  94. if ($params["nowSchool"]) {
  95. $where[] = ["nowSchool", "like", "%" . $params["nowSchool"] . "%"];
  96. }
  97. if ($params["nowGrade"]) {
  98. $where[] = ["nowGrade", "=", $params["nowGrade"]];
  99. }
  100. if ($params["applySchool"]) {
  101. $where[] = ["applySchool", "=", $params["applySchool"]];
  102. }
  103. if ($params["companyStreet"]) {
  104. $where[] = ["companyStreet", "=", $params["companyStreet"]];
  105. }
  106. if ($params["houseStreet"]) {
  107. $where[] = ["houseStreet", "=", $params["houseStreet"]];
  108. }
  109. if ($params["checkState"]) {
  110. $where[] = ["checkState", "=", $params["checkState"]];
  111. }
  112. return $where;
  113. }
  114. public static function getInfoById($id) {
  115. return EduModel::findOrEmpty($id)->toArray();
  116. }
  117. }