TalentConditionApi.php 3.7 KB

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