本地生活商品列表添加经纬度排序
This commit is contained in:
parent
03588028d4
commit
4068620602
@ -134,6 +134,9 @@ class LocalStoreLogic extends Logic
|
||||
$order = ['lsg.price' => $data['money_sort']];
|
||||
}
|
||||
|
||||
// 经纬度排序
|
||||
$distance_sql = "6371 * acos(cos(radians(:user_latitude)) * cos(radians(latitude)) * cos(radians(longitude) - radians(:user_longitude)) + sin(radians(:user_latitude)) * sin(radians(latitude))) AS distance";
|
||||
|
||||
// 数量统计
|
||||
$count = LocalStore::alias('ls')
|
||||
->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id')
|
||||
@ -143,15 +146,33 @@ class LocalStoreLogic extends Logic
|
||||
->count();
|
||||
|
||||
// 列表
|
||||
$lists = LocalStore::alias('ls')
|
||||
->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id')
|
||||
->where(['ls.is_delete' => 0, 'ls.store_state' => 1, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0])
|
||||
->where($where)
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->order($order)
|
||||
->page($data['page_no'], $data['page_size'])
|
||||
->field('ls.shopName, ls.longitude, ls.latitude, lsg.id, lsg.lstore_id, lsg.title, lsg.price')
|
||||
->select();
|
||||
if (isset($data['money_sort'])) {
|
||||
// 经纬度排序
|
||||
$lists = LocalStore::alias('ls')
|
||||
->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id')
|
||||
->where(['ls.is_delete' => 0, 'ls.store_state' => 1, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0])
|
||||
->where($where)
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->order($order)
|
||||
->page($data['page_no'], $data['page_size'])
|
||||
->field('ls.shopName, ls.longitude, ls.latitude, lsg.id, lsg.lstore_id, lsg.title, lsg.price, ' . $distance_sql)
|
||||
->bind([
|
||||
'user_latitude' => $data['latitude'],
|
||||
'user_longitude' => $data['longitude'],
|
||||
])
|
||||
->order('distance', $data['money_sort'])
|
||||
->select();
|
||||
} else {
|
||||
$lists = LocalStore::alias('ls')
|
||||
->join('local_store_goods lsg', 'ls.lstore_id = lsg.lstore_id')
|
||||
->where(['ls.is_delete' => 0, 'ls.store_state' => 1, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0])
|
||||
->where($where)
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->order($order)
|
||||
->page($data['page_no'], $data['page_size'])
|
||||
->field('ls.shopName, ls.longitude, ls.latitude, lsg.id, lsg.lstore_id, lsg.title, lsg.price')
|
||||
->select();
|
||||
}
|
||||
|
||||
foreach ($lists as $key => &$value) {
|
||||
$pic = LocalStoreGoodsPic::where('lsg_id', $value['id'])->field('url')->find();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user