TalentConditionApi.php 3.2 KB

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