TalentConditionApi.php 3.0 KB

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