php 按公司名 地区 id 排序时的上一个下一个翻页算法

正文开始

~~~ $where = []; if($prevNext=='next') { $whereSamePrev = $where; $whereSamePrev['Company'] = $company; if($city) $whereSamePrev['BusinessCity'] = $city; $whereSamePrev['customerId'] = ['>' , $customerId]; $whereSameOrder = ['customerId' => 'asc']; $samePrev = Customer::field('customerId,Company')->where($whereSamePrev)->order($whereSameOrder)->limit(1)->find(); // print_r($samePrev);exit; if(!$samePrev) { //同公司名字 不同城市的情况 $whereCityBigger = $where; $whereCityBigger['Company'] = $company; if($city) { $whereCityBigger['BusinessCity'] = ['>', $city]; $whereCityBigger['customerId'] = ['>' , $customerId]; $whereCityOrder = ['Company' => 'asc','BusinessCity' => 'asc']; } else { //没有城市对比的情况 上一个必须id偏大 $whereCityBigger['customerId'] = ['>' , $customerId]; $whereCityOrder = ['Company' => 'asc']; } $sameBiggerInfo = Customer::field('customerId,Company')->where($whereCityBigger)->order($whereCityOrder)->limit(1)->find(); if(!$sameBiggerInfo) { //公司大于即可 因为可能城市又偏小 $whereCompanySmaller = $where; $whereCompanySmaller['Company'] = ['>', $company]; $whereCompanySmaller['customerId'] = ['<>' , $customerId]; if($city) { $whereCityOrder = ['Company' => 'asc','BusinessCity' => 'asc', 'customerId' => 'asc']; } else { $whereCityOrder = ['Company' => 'asc', 'customerId' => 'asc']; } $findInfo = Customer::field('customerId,Company')->where($whereCompanySmaller)->order($whereCityOrder)->limit(1)->find(); // print_r($findInfo);exit; } else { // print_r('$sameSmallerInfo');exit; $findInfo = $sameBiggerInfo; } } else { $findInfo = $samePrev; } } else { $whereSamePrev = $where; $whereSamePrev['Company'] = $company; if($city) $whereSamePrev['BusinessCity'] = $city; $whereSamePrev['customerId'] = ['<' , $customerId]; $whereCityOrder = ['customerId' => 'desc']; $samePrev = Customer::field('customerId,Company')->where($whereSamePrev)->order($whereCityOrder)->limit(1)->find(); if(!$samePrev) { //同公司名字 不同城市的情况 $whereCitySmaller = $where; $whereCitySmaller['Company'] = $company; if($city) { $whereCitySmaller['BusinessCity'] = ['<', $city]; $whereCitySmaller['customerId'] = ['<>' , $customerId]; $whereCityOrder = ['Company' => 'desc','BusinessCity' => 'desc']; } else { //没有城市对比的情况 上一个必须id偏小 $whereCitySmaller['customerId'] = ['<' , $customerId]; $whereCityOrder = ['Company' => 'desc']; } $sameSmallerInfo = Customer::field('customerId,Company')->where($whereCitySmaller)->order($whereCityOrder)->limit(1)->find(); if(!$sameSmallerInfo) { //公司小于即可 因为可能城市又偏大 $whereCompanySmaller = $where; $whereCompanySmaller['Company'] = ['<', $company]; $whereCompanySmaller['customerId'] = ['<>' , $customerId]; if($city) { $whereCityOrder = ['Company' => 'desc','BusinessCity' => 'desc', 'customerId' => 'desc']; } else { $whereCityOrder = ['Company' => 'desc', 'customerId' => 'desc']; } $findInfo = Customer::field('customerId,Company')->where($whereCompanySmaller)->order($whereCityOrder)->limit(1)->find(); // print_r($findInfo);exit; } else { // print_r('$sameSmallerInfo');exit; $findInfo = $sameSmallerInfo; } } else { $findInfo = $samePrev; } } ~~~

正文结束

PHP接口(interface)和抽象类(abstract) php模糊匹配数字电话格式