TalentConditionApi.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. $where[] = ["type", "=", session("user")["type"]];
  69. if ($params["talentLevel"]) {
  70. $where[] = ["talentLevel", "=", $params["talentLevel"]];
  71. }
  72. if ($params["active"]) {
  73. $where[] = ["active", "=", $params["active"]];
  74. }
  75. $count = TalentCondition::where($where)->count();
  76. $list = TalentCondition::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  77. foreach ($list as &$item) {
  78. $item["talentLevel"] = $talent_arrange_kvs[$item["talentLevel"]];
  79. $company_ids = array_filter(explode(",", $item["companyIds"]));
  80. $tmp_companys = [];
  81. for ($i = 0; $i < count($company_ids); $i++) {
  82. $tmp_companys[] = $companys[$company_ids[$i]];
  83. }
  84. $item["companyNames"] = implode(",", $tmp_companys);
  85. }unset($item);
  86. return ["total" => $count, "rows" => $list];
  87. }
  88. }