EnterpriseApi.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\common\api;
  3. use app\common\api\CompanyApi;
  4. use think\facade\Db;
  5. use app\admin\model\Enterprise;
  6. class EnterpriseApi {
  7. public static function getOne($id){
  8. return Enterprise::findOrEmpty($id);
  9. }
  10. public static function getList($request) {
  11. $companyId = session('user')['companyId'];
  12. $company_info = CompanyApi::getOne($companyId);
  13. $where = [];
  14. if($company_info['code'] != 'super'){
  15. $where[] = ['type','=',session('user')['type']];
  16. if(session('user')['type'] == 1){
  17. $list = Db::table('sys_enterprisetype_properties')->where('companyIds','like',$companyId)->select()->toArray();
  18. $talentType = [];
  19. foreach ($list as $k => $v){
  20. array_push($talentType,$v['talentType']);
  21. }
  22. $where[] = ['enterpriseTag','in',$talentType];
  23. }
  24. }
  25. $offset = trim($request->param("offset")) ?: 0;
  26. $limit = trim($request->param("limit")) ?: 10;
  27. $name = trim($request->param("name"));
  28. $idCard = trim($request->param("idCard"));
  29. $legal = trim($request->param("legal"));
  30. $ephone = trim($request->param("ephone"));
  31. $agentName = trim($request->param("agentName"));
  32. $agentPhone = trim($request->param("agentPhone"));
  33. $checkState = trim($request->param("checkState"));
  34. $active = trim($request->param("active"));
  35. $street = trim($request->param("street"));
  36. $enterpriseTag = trim($request->param("enterpriseTag"));
  37. $industryFieldNew = trim($request->param("industryFieldNew"));
  38. if ($name) {
  39. $where[] = ["name", "like", "%{$name}%"];
  40. }
  41. if ($idCard) {
  42. $where[] = ["idCard", "like", "%{$idCard}%"];
  43. }
  44. if ($legal) {
  45. $where[] = ["legal", "like", "%{$legal}%"];
  46. }
  47. if ($ephone) {
  48. $where[] = ["ephone", "like", "%{$ephone}%"];
  49. }
  50. if ($agentName) {
  51. $where[] = ["agentName", "like", "%{$agentName}%"];
  52. }
  53. if ($agentPhone) {
  54. $where[] = ["agentPhone", "like", "%{$agentPhone}%"];
  55. }
  56. if ($checkState) {
  57. $where[] = ["checkState", "=", "{$checkState}"];
  58. }
  59. if ($active) {
  60. $where[] = ["active", "=", "{$active}"];
  61. }
  62. if ($street) {
  63. $where[] = ["street", "=", "{$street}"];
  64. }
  65. if ($enterpriseTag) {
  66. $where[] = ["enterpriseTag", "=", "{$enterpriseTag}"];
  67. }
  68. if ($industryFieldNew) {
  69. $where[] = ["industryFieldNew", "=", "{$industryFieldNew}"];
  70. }
  71. $count = Enterprise::where($where)->count();
  72. if($count > 0){
  73. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  74. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  75. $industryFieldOldList = DictApi::selectByParentCode("industry_field");
  76. //dd($talentTypeList);
  77. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  78. foreach ($list as $k => &$v){
  79. unset($v['password']);
  80. $v['enterpriseTagName'] = $talentTypeList[$v['enterpriseTag']];//此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  81. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  82. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  83. }
  84. }else{
  85. $list = [];
  86. }
  87. return ["total" => $count, "rows" => $list];
  88. }
  89. public static function updateById($data){
  90. return Enterprise::update($data);
  91. }
  92. }