TalentConditionApi.php 2.7 KB

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