更新查询

This commit is contained in:
mkm 2024-01-30 18:28:51 +08:00
parent 5fe3177046
commit d0e87bcb00
3 changed files with 24 additions and 14 deletions

View File

@ -70,7 +70,7 @@ class SpuDao extends BaseDao
->when(isset($where['mer_array_id']),function($query)use($where){ ->when(isset($where['mer_array_id']),function($query)use($where){
$query->whereIn('P.mer_id',$where['mer_array_id']); $query->whereIn('P.mer_id',$where['mer_array_id']);
}) })
->when(isset($where['mer_ids']) && $where['mer_ids'] !== '',function($query)use($where){ ->when(isset($where['mer_ids']) && count($where['mer_ids'])>0,function($query)use($where){
$query->whereIn('P.mer_id',$where['mer_ids']); $query->whereIn('P.mer_id',$where['mer_ids']);
}) })
->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){ ->when(isset($where['keyword']) && $where['keyword'] !== '',function($query)use($where){

View File

@ -164,8 +164,7 @@ class SpuRepository extends BaseRepository
'product.attrValue', 'product.attrValue',
]); ]);
$productMake = app()->make(ProductRepository::class); $productMake = app()->make(ProductRepository::class);
$count = $query->fetchSql(false)->count(); $count = $query->count();
if ($limit == 0) { if ($limit == 0) {
$list = $query->setOption('field', [])->field($this->productFiled)->select() $list = $query->setOption('field', [])->field($this->productFiled)->select()
->each(function ($item) use ($is_sku, $productMake, $userInfo,$where) { ->each(function ($item) use ($is_sku, $productMake, $userInfo,$where) {
@ -179,7 +178,7 @@ class SpuRepository extends BaseRepository
$item['merchant']['village_name']=$village_name.'集体经营合作店铺'; $item['merchant']['village_name']=$village_name.'集体经营合作店铺';
} }
} }
if (isset($item['merchant']['lat'] , $item['merchant']['long']) && isset($where['lat'], $where['long'])) { if (isset($item['merchant']['lat'] , $item['merchant']['long']) && isset($where['lat'], $where['long'])&&$where['lat']!='') {
$distance = getDistance($where['lat'], $where['long'], $item['merchant']['lat'], $item['merchant']['long']); $distance = getDistance($where['lat'], $where['long'], $item['merchant']['lat'], $item['merchant']['long']);
if ($distance < 0.9) { if ($distance < 0.9) {
$distance = max(bcmul($distance, 1000, 0), 1).'m'; $distance = max(bcmul($distance, 1000, 0), 1).'m';
@ -205,7 +204,7 @@ class SpuRepository extends BaseRepository
$item['merchant']['village_name']=$village_name.'集体经营合作店铺'; $item['merchant']['village_name']=$village_name.'集体经营合作店铺';
} }
} }
if (isset($item['merchant']['lat'] , $item['merchant']['long']) && isset($where['lat'], $where['long'])) { if (isset($item['merchant']['lat'] , $item['merchant']['long']) && isset($where['lat'], $where['long'])&&$where['lat']!='') {
$distance = getDistance($where['lat'], $where['long'], $item['merchant']['lat'], $item['merchant']['long']); $distance = getDistance($where['lat'], $where['long'], $item['merchant']['lat'], $item['merchant']['long']);
if ($distance < 0.9) { if ($distance < 0.9) {
$distance = max(bcmul($distance, 1000, 0), 1).'m'; $distance = max(bcmul($distance, 1000, 0), 1).'m';

View File

@ -66,9 +66,14 @@ class StoreSpu extends BaseController
'village_id', 'village_id',
'location' 'location'
]); ]);
if (isset($where['type_code']) && $where['type_code'] == 'PersonalStore') {
$where['long'] = '';
$where['lat'] = '';
} else {
[$lat, $lng] = (new CityAreaDao())->getLngAndLat($where['location'], $where['street_id']); [$lat, $lng] = (new CityAreaDao())->getLngAndLat($where['location'], $where['street_id']);
$where['long'] = $lng; $where['long'] = $lng;
$where['lat'] = $lat; $where['lat'] = $lat;
}
if ($where['type_id'] || $where['type_code']) { if ($where['type_id'] || $where['type_code']) {
$arr = ['status' => 1, 'mer_state' => 1, 'is_del' => 0]; $arr = ['status' => 1, 'mer_state' => 1, 'is_del' => 0];
$query = Merchant::where($arr); $query = Merchant::where($arr);
@ -85,7 +90,13 @@ class StoreSpu extends BaseController
// $query->where('type_id', $mer_type_id); // $query->where('type_id', $mer_type_id);
// } // }
// } // }
$mer_type_id = Db::name('merchant_type')->where('type_code', $where['type_code'])->value('mer_type_id');
if ($mer_type_id && $where['type_code'] == 'PersonalStore') {
$where['mer_ids'] = $query->where('type_id', $mer_type_id)->column('mer_id');
}else{
$where['mer_ids'] = $query->whereIn('type_id', explode(',', $where['type_id']))->column('mer_id'); $where['mer_ids'] = $query->whereIn('type_id', explode(',', $where['type_id']))->column('mer_id');
}
} }
unset($where['type_id'], $where['street_id'], $where['type_code'], $where['village_id']); unset($where['type_id'], $where['street_id'], $where['type_code'], $where['village_id']);