修改店铺街接口
This commit is contained in:
parent
5504331eb2
commit
9aab2cfb51
@ -187,61 +187,66 @@ class LocalStoreLogic extends Logic
|
||||
|
||||
// 城市搜索
|
||||
if (isset($data['c_name']) && $data['c_name'] != "") {
|
||||
$where[] = ['ls.address', 'like', '%' . $data['c_name'] . '%'];
|
||||
$where[] = ['address', 'like', '%' . $data['c_name'] . '%'];
|
||||
}
|
||||
|
||||
// 搜索商家名称
|
||||
$keyword = '';
|
||||
if (isset($data['keyword']) && $data['keyword'] != '') {
|
||||
$where[] = ['ls.shopName|lsg.title', 'like', '%' . $data['keyword'] . '%'];
|
||||
$where[] = ['shopName|title', 'like', '%' . $data['keyword'] . '%'];
|
||||
$keyword = $data['keyword'];
|
||||
}
|
||||
|
||||
// 价格排序
|
||||
$order = ['lstore_id' => 'desc'];
|
||||
if (isset($data['money_sort'])) {
|
||||
$order = ['lsg.price' => $data['money_sort']];
|
||||
}
|
||||
// if (isset($data['money_sort'])) {
|
||||
// $order = ['lsg.price' => $data['money_sort']];
|
||||
// }
|
||||
|
||||
// 经纬度排序
|
||||
if (isset($data['distance_sort'])) {
|
||||
$order = ['distance' => $data['distance_sort']];
|
||||
}
|
||||
// if (isset($data['distance_sort'])) {
|
||||
// $order = ['distance' => $data['distance_sort']];
|
||||
// }
|
||||
|
||||
// 经纬度排序
|
||||
$distance_sql = "6371 * acos(cos(radians(" . $data['latitude'] . ")) * cos(radians(latitude)) * cos(radians(longitude) - radians(" . $data['longitude'] . ")) + sin(radians(" . $data['latitude'] . ")) * sin(radians(latitude))) AS distance";
|
||||
|
||||
// 数量统计
|
||||
$count = LocalStore::with(['goods' => function ($query) use ($keyword) {
|
||||
$query->where('name', 'like', "%{$keyword}%")->where(['state' => 1, 'audit_status' => 1, 'delete_time' => 0]);
|
||||
$count = LocalStore::with(['street_goods' => function ($query) use ($keyword) {
|
||||
$query->where('title', 'like', "%{$keyword}%")
|
||||
->where(['state' => 1, 'audit_status' => 1, 'delete_time' => 0]);
|
||||
}])
|
||||
->where(['is_delete' => 0, 'store_state' => 1])
|
||||
->whereNotNull('shopLogo')
|
||||
->count();
|
||||
|
||||
$lists = LocalStore::with(['goods' => function ($query) use ($keyword) {
|
||||
$query->where('name', 'like', "%{$keyword}%")->where(['state' => 1, 'audit_status' => 1, 'delete_time' => 0]);
|
||||
// 这里的Join只是为了配合with获取指定的字段
|
||||
$lists = LocalStore::alias('ls')
|
||||
->with(['street_goods' => function ($query) use ($keyword) {
|
||||
$query->where('title', 'like', "%{$keyword}%")
|
||||
->where(['state' => 1, 'audit_status' => 1, 'delete_time' => 0]);
|
||||
}])
|
||||
->where(['is_delete' => 0, 'store_state' => 1])
|
||||
->whereNotNull('shopLogo')
|
||||
->join('local_store_goods lsg', 'lsg.lstore_id = ls.lstore_id')
|
||||
->where(['ls.is_delete' => 0, 'ls.store_state' => 1])
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->field('ls.lstore_id as ls_id, ls.shopName, ls.longitude, ls.latitude, ' . $distance_sql . ', lsg.id, lsg.lstore_id, lsg.title, lsg.price')
|
||||
->order($order)
|
||||
->page($data['page_no'], $data['page_size'])
|
||||
->field('shopName, longitude, latitude, ' . $distance_sql)
|
||||
->select();
|
||||
|
||||
// foreach ($lists as $key => &$value) {
|
||||
// // 东龙汇超时价格 *88折
|
||||
// if ($value['lstore_id'] == 138) {
|
||||
// $lists[$key]['original_price'] = $value['price'];
|
||||
// $lists[$key]['price'] = round($value['price'] * LocalStoreGoodsLogic::$sale, 2);
|
||||
// }
|
||||
//
|
||||
foreach ($lists as $key => &$value) {
|
||||
// 东龙汇超时价格 *88折
|
||||
if ($value['lstore_id'] == 138) {
|
||||
$lists[$key]['original_price'] = $value['price'];
|
||||
$lists[$key]['price'] = round($value['price'] * LocalStoreGoodsLogic::$sale, 2);
|
||||
}
|
||||
|
||||
// $pic = LocalStoreGoodsPic::where('lsg_id', $value['id'])->field('url')->find();
|
||||
// $lists[$key]['url'] = UrlServer::getFileUrl($pic['url']);
|
||||
// $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km";
|
||||
//// $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "km";
|
||||
// $lists[$key]['store_nickname'] = $value["shopName"];
|
||||
// }
|
||||
$lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km";
|
||||
// $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "km";
|
||||
$lists[$key]['store_nickname'] = $value["shopName"];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
|
||||
@ -15,8 +15,8 @@ class LocalStore extends Model
|
||||
return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname');
|
||||
}
|
||||
|
||||
public function goods()
|
||||
public function streetGoods()
|
||||
{
|
||||
return $this->hasMany(LocalStoreGoods::class, 'lstore_id', 'lstore_id');
|
||||
return $this->hasMany(LocalStoreGoods::class, 'lstore_id', 'lstore_id')->field('id, lstore_id, title, price')->order('id desc')->limit(10);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user