InfoRepository.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * 挖掘线索
  4. * @author system
  5. * @version 1.0
  6. * @date 2018-11-19 08:23:08
  7. *
  8. */
  9. namespace App\Repositories\Company;
  10. use App\Repositories\Base\Repository;
  11. class InfoRepository extends Repository {
  12. public function model() {
  13. return \App\Models\CompanyInfoModel::class;
  14. }
  15. public function searchCompany(array $search,array $orderby=['id'=>'desc'],$pagesize=10)
  16. {
  17. $currentQuery = $this->model;
  18. /*企业名称*/
  19. if(isset($search['company_name']) && ! empty($search['company_name'])) {
  20. $keywords = str_replace(',','|',$search['company_name']);
  21. $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
  22. $query->where('company_name' , 'REGEXP', $keywords);
  23. });
  24. }
  25. /*所在地区*/
  26. if(isset($search['district']) && ! empty($search['district'])) {
  27. $district = $search['district'];
  28. if (is_array($district)) $district = join('|',$district) ;
  29. $currentQuery = $currentQuery->where(function ($query) use ($district) {
  30. $query->where('district','REGEXP', $district);
  31. });
  32. }
  33. /*企业类型*/
  34. if(isset($search['ent_type']) && ! empty($search['ent_type'])) {
  35. $ent_type = $search['ent_type'];
  36. if (is_array($ent_type)) $ent_type = join('|',$ent_type) ;
  37. $currentQuery = $currentQuery->where(function ($query) use ($ent_type) {
  38. $query->where('ent_type','REGEXP',$ent_type);
  39. });
  40. }
  41. /*经营状态*/
  42. if(isset($search['open_status']) && ! empty($search['open_status'])) {
  43. $open_status = $search['open_status'];
  44. if (is_array($open_status)) $open_status = join('|',$open_status) ;
  45. $currentQuery = $currentQuery->where(function ($query) use ($open_status) {
  46. $query->where('open_status','REGEXP',$open_status);
  47. });
  48. }
  49. /*所属行业*/
  50. if(isset($search['industry']) && ! empty($search['industry'])) {
  51. $industry = $search['industry'];
  52. if (is_array($industry)) $industry = join('|',$industry) ;
  53. $currentQuery = $currentQuery->where(function ($query) use ($industry) {
  54. $query->where('industry','REGEXP',$industry);
  55. });
  56. }
  57. /*注册资本*/
  58. if(isset($search['reg_capital']) && ! empty($search['reg_capital'])) {
  59. $reg_capital = explode('-',$search['reg_capital']);
  60. $currentQuery = $currentQuery->where(function ($query) use ($reg_capital) {
  61. if(!$reg_capital[1]){
  62. $query->where('reg_capital','>=',(int)$reg_capital[0]);
  63. }else{
  64. $query->where('reg_capital','>=',(int)$reg_capital[0])
  65. ->where('reg_capital','<',(int)$reg_capital[1]);
  66. }
  67. });
  68. }
  69. if($orderby && is_array($orderby)){
  70. foreach ($orderby AS $field => $value){
  71. $currentQuery = $currentQuery->orderBy($field, $value);
  72. }
  73. }
  74. $currentQuery = $currentQuery->paginate($pagesize);
  75. return $currentQuery;
  76. }
  77. }