TalentConditionApi.php 2.7 KB

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