TalentConditionApi.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\TalentCondition;
  4. /**
  5. * Description of TalentConditionApi
  6. *
  7. * @author sgq
  8. */
  9. class TalentConditionApi {
  10. public static function getList($lv, $type, $cat = "", $showAll = false) {
  11. if (is_array($lv)) {
  12. $where[] = ["talentLevel", "in", $lv];
  13. } else {
  14. $where[] = ["talentLevel", "=", $lv];
  15. }
  16. $where[] = ["type", "=", $type];
  17. if (!$showAll) {
  18. $where[] = ["delete", "=", 0];
  19. $where[] = ["active", "=", 1];
  20. }
  21. if ($cat) {
  22. $where[] = ["talentLevelCat", "=", $cat];
  23. }
  24. return TalentCondition::where($where)->select()->toArray();
  25. }
  26. public static function getOne($id) {
  27. return TalentCondition::findOrEmpty($id)->toArray();
  28. }
  29. public static function edit($params) {
  30. $data["type"] = $params["type"];
  31. $data["talentLevel"] = $params["talentLevel"];
  32. $data["talentLevelCat"] = $params["talentLevelCat"];
  33. $data["companyIds"] = $params["companyIds"];
  34. $data["bindFileTypes"] = $params["bindFileTypes"];
  35. $data["name"] = $params["name"];
  36. $data["active"] = $params["active"];
  37. $data["isSalary"] = $params["isSalary"];
  38. $relation = [];
  39. if ($params["relation"]) {
  40. foreach ($params["relation"] as $_companyId => $_relation) {
  41. $relation[] = $_companyId . ":" . $_relation;
  42. }
  43. }
  44. $data["companyWithFileType"] = implode(";", $relation);
  45. if ($params["id"]) {
  46. $data["id"] = $params["id"];
  47. $data["updateUser"] = session("user")["uid"];
  48. $data["updateTime"] = date("Y-m-d H:i:s");
  49. return TalentCondition::update($data);
  50. } else {
  51. $data["createUser"] = session("user")["uid"];
  52. $data["createTime"] = date("Y-m-d H:i:s");
  53. return TalentCondition::insert($data);
  54. }
  55. }
  56. public static function delete($id) {
  57. $data["id"] = $id;
  58. $data["delete"] = 1;
  59. $data["updateUser"] = session("user")["uid"];
  60. $data["updateTime"] = date("Y-m-d H:i:s");
  61. return TalentCondition::update($data);
  62. }
  63. public static function getListByCondition($params) {
  64. $order = $params["order"] ?: "desc";
  65. $offset = $params["offset"] ?: 0;
  66. $limit = $params["limit"] ?: 10;
  67. $talent_arrange_kvs = DictApi::selectByParentCode("talent_arrange");
  68. $companys = \app\common\model\Company::column("name", "id");
  69. $where[] = ["delete", "=", 0];
  70. if ($params["name"]) {
  71. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  72. }
  73. /* if ($params["type"]) {
  74. $where[] = ["type", "=", $params["type"]];
  75. } */
  76. $where[] = ["type", "=", session("user")["type"]];
  77. if ($params["talentLevel"]) {
  78. $where[] = ["talentLevel", "=", $params["talentLevel"]];
  79. }
  80. if ($params["active"]) {
  81. $where[] = ["active", "=", $params["active"]];
  82. }
  83. $count = TalentCondition::where($where)->count();
  84. $list = TalentCondition::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  85. foreach ($list as &$item) {
  86. $item["talentLevel"] = $talent_arrange_kvs[$item["talentLevel"]];
  87. $company_ids = array_filter(explode(",", $item["companyIds"]));
  88. $tmp_companys = [];
  89. for ($i = 0; $i < count($company_ids); $i++) {
  90. $tmp_companys[] = $companys[$company_ids[$i]];
  91. }
  92. $item["companyNames"] = implode(",", $tmp_companys);
  93. }unset($item);
  94. return ["total" => $count, "rows" => $list];
  95. }
  96. public static function getKvList($params) {
  97. return TalentCondition::where($params)->column("name", "id");
  98. }
  99. }