InfoRepository.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = str_replace(',','|',$search['district']);
  28. $currentQuery = $currentQuery->where(function ($query) use ($district) {
  29. $query->where('district','REGEXP', $district);
  30. });
  31. }
  32. /*企业类型*/
  33. if(isset($search['entType']) && ! empty($search['entType'])) {
  34. $entType = str_replace(',','|',$search['entType']);
  35. $currentQuery = $currentQuery->where(function ($query) use ($entType) {
  36. $query->where('entType','REGEXP',$entType);
  37. });
  38. }
  39. /*经营状态*/
  40. if(isset($search['openStatus']) && ! empty($search['openStatus'])) {
  41. $openStatus = str_replace(',','|',$search['openStatus']);
  42. $currentQuery = $currentQuery->where(function ($query) use ($openStatus) {
  43. $query->where('openStatus','REGEXP',$openStatus);
  44. });
  45. }
  46. /*所属行业*/
  47. if(isset($search['industry']) && ! empty($search['industry'])) {
  48. $industry= str_replace(',','|',$search['industry']);
  49. $currentQuery = $currentQuery->where(function ($query) use ($industry) {
  50. $query->where('industry','REGEXP',$industry);
  51. });
  52. }
  53. /*注册资本*/
  54. if(isset($search['regCapital']) && ! empty($search['regCapital'])) {
  55. $regCapital = explode('-',$search['regCapital']);
  56. $currentQuery = $currentQuery->where(function ($query) use ($regCapital) {
  57. if(!$regCapital[1]){
  58. $query->where('regCapital','>=',(int)$regCapital[0]);
  59. }else{
  60. $query->where('regCapital','>=',(int)$regCapital[0])
  61. ->where('regCapital','<',(int)$regCapital[1]);
  62. }
  63. });
  64. }
  65. if($orderby && is_array($orderby)){
  66. foreach ($orderby AS $field => $value){
  67. $currentQuery = $currentQuery->orderBy($field, $value);
  68. }
  69. }
  70. $currentQuery = $currentQuery->paginate($pagesize);
  71. return $currentQuery;
  72. }
  73. }