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['companyName']) && ! empty($search['companyName'])) {
  20. $keywords = str_replace(',','|',$search['companyName']);
  21. $currentQuery = $currentQuery->where(function ($query) use ($keywords) {
  22. $query->where('companyName' , '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['entType']) && ! empty($search['entType'])) {
  35. $entType = $search['entType'];
  36. if (is_array($entType)) $entType = join('|',$entType) ;
  37. $currentQuery = $currentQuery->where(function ($query) use ($entType) {
  38. $query->where('entType','REGEXP',$entType);
  39. });
  40. }
  41. /*经营状态*/
  42. if(isset($search['openStatus']) && ! empty($search['openStatus'])) {
  43. $openStatus = $search['openStatus'];
  44. if (is_array($openStatus)) $openStatus = join('|',$openStatus) ;
  45. $currentQuery = $currentQuery->where(function ($query) use ($openStatus) {
  46. $query->where('openStatus','REGEXP',$openStatus);
  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['regCapital']) && ! empty($search['regCapital'])) {
  59. $regCapital = explode('-',$search['regCapital']);
  60. $currentQuery = $currentQuery->where(function ($query) use ($regCapital) {
  61. if(!$regCapital[1]){
  62. $query->where('regCapital','>=',(int)$regCapital[0]);
  63. }else{
  64. $query->where('regCapital','>=',(int)$regCapital[0])
  65. ->where('regCapital','<',(int)$regCapital[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. }