TalentConditionApi.php 3.4 KB

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