EnterpriseApi.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 getList($request) {
  8. $companyId = session('user')['companyId'];
  9. $company_info = CompanyApi::getOne($companyId);
  10. $where = [];
  11. if($company_info['code'] != 'super'){
  12. $where[] = ['type','=',session('user')['type']];
  13. if(session('user')['type'] == 1){
  14. $list = Db::table('sys_enterprisetype_properties')->where('companyIds','like',$companyId)->select()->toArray();
  15. $talentType = [];
  16. foreach ($list as $k => $v){
  17. array_push($talentType,$v['talentType']);
  18. }
  19. $where[] = ['enterpriseTag','in',$talentType];
  20. }
  21. }
  22. $offset = trim($request->param("offset")) ?: 0;
  23. $limit = trim($request->param("limit")) ?: 10;
  24. $count = Enterprise::where($where)->count();
  25. if($count > 0){
  26. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  27. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  28. $industryFieldOldList = DictApi::selectByParentCode("industry_field");
  29. //dd($talentTypeList);
  30. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  31. foreach ($list as $k => &$v){
  32. unset($v['password']);
  33. $v['enterpriseTagName'] = $talentTypeList[$v['enterpriseTag']];//此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  34. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  35. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  36. }
  37. }else{
  38. $list = [];
  39. }
  40. return ["total" => $count, "rows" => $list];
  41. }
  42. }