TalentConditionApi.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 ($type == 1 && $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. foreach ($params["relation"] as $_companyId => $_relation) {
  38. $relation[] = $_companyId . ":" . $_relation;
  39. }
  40. $data["companyWithFileType"] = implode(";", $relation);
  41. if ($params["id"]) {
  42. $data["id"] = $params["id"];
  43. $data["updateUser"] = session("user")["uid"];
  44. $data["updateTime"] = date("Y-m-d H:i:s");
  45. return TalentCondition::update($data);
  46. } else {
  47. $data["createUser"] = session("user")["uid"];
  48. $data["createTime"] = date("Y-m-d H:i:s");
  49. return TalentCondition::insert($data);
  50. }
  51. }
  52. public static function delete($id) {
  53. $data["id"] = $id;
  54. $data["delete"] = 1;
  55. $data["updateUser"] = session("user")["uid"];
  56. $data["updateTime"] = date("Y-m-d H:i:s");
  57. return TalentCondition::update($data);
  58. }
  59. public static function getListByCondition($params) {
  60. $order = $params["order"] ?: "desc";
  61. $offset = $params["offset"] ?: 0;
  62. $limit = $params["limit"] ?: 10;
  63. $talent_arrange_kvs = DictApi::selectByParentCode("talent_arrange");
  64. $companys = \app\common\model\Company::column("name", "id");
  65. $where[] = ["delete", "=", 0];
  66. if ($params["name"]) {
  67. $where[] = ["name", "like", "%" . $params["name"] . "%"];
  68. }
  69. /* if ($params["type"]) {
  70. $where[] = ["type", "=", $params["type"]];
  71. } */
  72. $where[] = ["type", "=", session("user")["type"]];
  73. if ($params["talentLevel"]) {
  74. $where[] = ["talentLevel", "=", $params["talentLevel"]];
  75. }
  76. if ($params["active"]) {
  77. $where[] = ["active", "=", $params["active"]];
  78. }
  79. $count = TalentCondition::where($where)->count();
  80. $list = TalentCondition::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  81. foreach ($list as &$item) {
  82. $item["talentLevel"] = $talent_arrange_kvs[$item["talentLevel"]];
  83. $company_ids = array_filter(explode(",", $item["companyIds"]));
  84. $tmp_companys = [];
  85. for ($i = 0; $i < count($company_ids); $i++) {
  86. $tmp_companys[] = $companys[$company_ids[$i]];
  87. }
  88. $item["companyNames"] = implode(",", $tmp_companys);
  89. }unset($item);
  90. return ["total" => $count, "rows" => $list];
  91. }
  92. }