EnterpriseApi.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. $count = Enterprise::where($where)->count();
  28. if($count > 0){
  29. $talentTypeList = DictApi::selectByParentCode("enterprise_tag");
  30. $industryFieldNewList = DictApi::selectByParentCode("industry_field");
  31. $industryFieldOldList = DictApi::selectByParentCode("industry_field");
  32. //dd($talentTypeList);
  33. $list = Enterprise::where($where)->limit($offset, $limit)->order("createTime", 'desc')->select()->toArray();
  34. foreach ($list as $k => &$v){
  35. unset($v['password']);
  36. $v['enterpriseTagName'] = $talentTypeList[$v['enterpriseTag']];//此处旧字段为talentType,新字段为enterpriseTag,为防止数据污染与丢失,因而这样写
  37. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  38. $v['industryFieldNewName'] = $industryFieldNewList[$v['industryFieldNew']];
  39. }
  40. }else{
  41. $list = [];
  42. }
  43. return ["total" => $count, "rows" => $list];
  44. }
  45. public static function updateById($data){
  46. return Enterprise::update($data);
  47. }
  48. }