修改店铺街接口
This commit is contained in:
parent
c1e60d12ca
commit
2d64ac1f60
@ -140,7 +140,7 @@ class LocalStoreLogic extends Logic
|
||||
// 数量统计
|
||||
$count = 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(['ls.store_state' => 1, 'ls.is_delete' => 0, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0])
|
||||
->where($where)
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->count();
|
||||
@ -148,7 +148,7 @@ class LocalStoreLogic extends Logic
|
||||
// 列表
|
||||
$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(['ls.store_state' => 1, 'ls.is_delete' => 0, 'lsg.state' => 1, 'lsg.audit_status' => 1, 'lsg.delete_time' => 0])
|
||||
->where($where)
|
||||
->whereNotNull('ls.shopLogo')
|
||||
->order($order)
|
||||
@ -183,35 +183,66 @@ class LocalStoreLogic extends Logic
|
||||
|
||||
public function getStreetlList($data)
|
||||
{
|
||||
$model = new LocalStore;
|
||||
$distance = "";
|
||||
$s = $s1 = "";
|
||||
$where = [];
|
||||
|
||||
$city_where = [];
|
||||
if (isset($data['c_name'])) {
|
||||
if ($data['c_name'] != "") {
|
||||
$s1 = "address like '%" . $data['c_name'] . "%'";
|
||||
$s = "and address like '%" . $data['c_name'] . "%'";
|
||||
}
|
||||
// 城市搜索
|
||||
if (isset($data['c_name']) && $data['c_name'] != "") {
|
||||
$where[] = ['ls.address', 'like', '%' . $data['c_name'] . '%'];
|
||||
}
|
||||
|
||||
$count = $model->where('is_delete', 0)
|
||||
->where($city_where)
|
||||
->where($s1)
|
||||
->where("store_state", 1)
|
||||
->where("shopLogo is not null")
|
||||
->count();
|
||||
|
||||
$size = $data['page_size'];
|
||||
$page = ($data['page_no'] - 1) * $data['page_size'];
|
||||
|
||||
$sql = "SELECT * FROM ls_local_store where is_delete = 0 and store_state = 1 and shopLogo is not null $s ORDER BY lstore_id asc limit " . $page . "," . $size;
|
||||
|
||||
$lists = Db::query($sql);
|
||||
foreach ($lists as $key => $value) {
|
||||
$lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "公里";
|
||||
$lists[$key]['store_nickname'] = $value["shopName"];
|
||||
// 搜索商家名称
|
||||
$keyword = '';
|
||||
if (isset($data['keyword']) && $data['keyword'] != '') {
|
||||
$where[] = ['ls.shopName|lsg.title', 'like', '%' . $data['keyword'] . '%'];
|
||||
$keyword = $data['keyword'];
|
||||
}
|
||||
|
||||
// 价格排序
|
||||
$order = ['lsg.id' => 'desc'];
|
||||
if (isset($data['money_sort'])) {
|
||||
$order = ['lsg.price' => $data['money_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]);
|
||||
}])
|
||||
->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]);
|
||||
}])
|
||||
->where(['is_delete' => 0, 'store_state' => 1])
|
||||
->whereNotNull('shopLogo')
|
||||
->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);
|
||||
// }
|
||||
//
|
||||
// $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"];
|
||||
// }
|
||||
|
||||
$data = [
|
||||
'list' => $lists,
|
||||
'page' => $data['page_no'],
|
||||
@ -219,6 +250,7 @@ class LocalStoreLogic extends Logic
|
||||
'count' => $count,
|
||||
'more' => is_more($count, $data['page_no'], $data['page_size'])
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use app\common\model\localstore\LocalStoreGoods;
|
||||
use app\common\model\user\User;
|
||||
use think\Model;
|
||||
|
||||
@ -13,4 +14,9 @@ class LocalStore extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname');
|
||||
}
|
||||
|
||||
public function goods()
|
||||
{
|
||||
return $this->hasMany(LocalStoreGoods::class, 'lstore_id', 'lstore_id');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user