This commit is contained in:
mkm 2023-11-07 17:28:58 +08:00
parent be9ab1acdc
commit cfa0b4451e
2 changed files with 41 additions and 8 deletions

View File

@ -242,6 +242,11 @@ class Merchant extends BaseController
if ($data['mer_state'] && !$merchant['sub_mchid'] && systemConfig('open_wx_combine'))
return app('json')->fail('开启店铺前请先完成微信子商户入驻');
}
if($data['long']!=''&& $data['lat']!=''){
$long=$data['long'];
$lat=$data['lat'];
Db::query("UPDATE eb_merchant SET coordinates = ST_GeomFromText('POINT($long $lat)') WHERE mer_id = $id");
}
Db::name('merchant')->where('mer_id',$id)->update($data);
Queue::push(ChangeMerchantStatusJob::class, $id);

View File

@ -95,15 +95,12 @@ class CloudWarehouse extends BaseController
* 云仓商品列表
* @return mixed
*/
public function index($street_code, $page_num = 1, $category_id = 0)
public function index($street_code, $page_num = 1, $category_id = 0,$location='')
{
if ($category_id == 0) {
return app('json')->fail('分类id不能为0');
}
$cloud_product = Db::name('cloud_product')->where('street_code', $street_code)->where('category_id', $category_id)->where('status', 1)->page($page_num)->column('product_id');
if (!$cloud_product) {
return app('json')->success(['count' => 0, 'list' => []]);
}
// if ($category_id == 0) {
// return app('json')->fail('分类id不能为0');
// }
$cloud_product = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->page($page_num)->column('product_id');
$where = [
'is_show' => 1,
'is_used' => 1,
@ -111,6 +108,37 @@ class CloudWarehouse extends BaseController
'is_del' => 0,
'mer_status' => 1,
];
if (!$cloud_product) {
$list=[];
if($location){
[$lon,$lat]=explode(',',$location);
if($page_num==1){
$limit=0;
}else{
$limit=$page_num*10;
}
$select=Db::query("select mer_id,mer_name ,ST_Distance(coordinates, POINT($lon,$lat)) AS distance from eb_merchant where coordinates !='' ORDER BY distance LIMIT $limit, 10;");
foreach ($select as $k => $v) {
$where['mer_id']=$v['mer_id'];
$product_list = Db::name('store_product')->where($where)
->limit(3)
->withAttr('sku', function ($value, $data) {
$find = Db::name('store_product_attr_value')->where('mer_id', $data['mer_id'])->where('product_id', $data['product_id'])->find();
return ['' => $find];
})
->select();
foreach ($product_list as $k1 => $v1){
$arr=$v1;
$v['distance']=round($v['distance'],2).'km';
$arr['merchant']=$v;
$list[]=$arr;
}
}
}
return app('json')->success(['count' => 0, 'list' => $list]);
}
$count = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->count();
$select = Db::name('store_product')->whereIn('product_id', $cloud_product)->where($where)
->withAttr('merchant', function ($value, $data) {