TalentConditionApi.php 3.4 KB

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