调整云仓商品列表查询
This commit is contained in:
parent
7f61f9d6bc
commit
dde3899a58
@ -95,4 +95,30 @@ class CityAreaDao extends BaseDao
|
|||||||
$lst[] = $city;
|
$lst[] = $city;
|
||||||
return $lst;
|
return $lst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取经纬度
|
||||||
|
* @param $location
|
||||||
|
* @param $streetCode
|
||||||
|
* @return array
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
public function getLngAndLat($location, $streetCode)
|
||||||
|
{
|
||||||
|
if (!empty($location) && $location != ',') {
|
||||||
|
[$lat, $lng] = explode(',', $location);
|
||||||
|
} elseif (!empty($streetCode)) {
|
||||||
|
$location = GeoStreet::where('street_code', $streetCode)->field('lng,lat')->find();
|
||||||
|
if (!empty($location)) {
|
||||||
|
[$lat, $lng] = [$location['lat'], $location['lng']];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($lat) || empty($lng)) {
|
||||||
|
[$lat, $lng] = ['28.889137', '105.443352'];
|
||||||
|
}
|
||||||
|
return [$lat, $lng];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,10 @@ namespace app\common\dao\store;
|
|||||||
|
|
||||||
use app\common\dao\BaseDao;
|
use app\common\dao\BaseDao;
|
||||||
use app\common\dao\store\product\CloudProductDao;
|
use app\common\dao\store\product\CloudProductDao;
|
||||||
use app\common\model\BaseModel;
|
|
||||||
use app\common\model\store\GeoStreet;
|
|
||||||
use app\common\model\store\product\CloudProduct;
|
use app\common\model\store\product\CloudProduct;
|
||||||
use app\common\model\store\StoreActivity;
|
use app\common\model\store\StoreActivity;
|
||||||
use app\common\model\store\StoreActivityOrderProduct;
|
use app\common\model\store\StoreActivityOrderProduct;
|
||||||
use app\common\repositories\store\product\SpuRepository;
|
use app\common\repositories\store\product\SpuRepository;
|
||||||
use app\common\repositories\system\RelevanceRepository;
|
|
||||||
use think\exception\ValidateException;
|
use think\exception\ValidateException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -55,17 +52,7 @@ class StoreActivityDao extends BaseDao
|
|||||||
*/
|
*/
|
||||||
public function product($location, $streetCode, $activityId)
|
public function product($location, $streetCode, $activityId)
|
||||||
{
|
{
|
||||||
if (!empty($location) && $location != ',') {
|
[$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $streetCode);
|
||||||
[$lat, $lng] = explode(',', $location);
|
|
||||||
} elseif (!empty($streetCode)) {
|
|
||||||
$location = GeoStreet::where('street_code', $streetCode)->field('lng,lat')->find();
|
|
||||||
if (!empty($location)) {
|
|
||||||
[$lat, $lng] = [$location['lat'], $location['lng']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($lat) || empty($lng)) {
|
|
||||||
[$lat, $lng] = ['28.889137', '105.443352'];
|
|
||||||
}
|
|
||||||
$cloud_product_arr = (new CloudProductDao())->getByDistance($lat, $lng, ['activity_id' => $activityId], 4);
|
$cloud_product_arr = (new CloudProductDao())->getByDistance($lat, $lng, ['activity_id' => $activityId], 4);
|
||||||
$cloud_product = [];
|
$cloud_product = [];
|
||||||
foreach ($cloud_product_arr as $key => $value) {
|
foreach ($cloud_product_arr as $key => $value) {
|
||||||
|
@ -347,7 +347,7 @@ class MerchantDao extends BaseDao
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 按距离获取有效的商户
|
* 按距离获取有效的云仓商品
|
||||||
* @param $lat
|
* @param $lat
|
||||||
* @param $lng
|
* @param $lng
|
||||||
* @param $sort 是否按距离排序
|
* @param $sort 是否按距离排序
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace app\controller\api\store\product;
|
namespace app\controller\api\store\product;
|
||||||
|
|
||||||
|
use app\common\dao\store\CityAreaDao;
|
||||||
use app\common\dao\system\merchant\MerchantDao;
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
use app\common\model\store\GeoStreet;
|
|
||||||
use app\common\model\system\merchant\Merchant;
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\store\product\SpuRepository;
|
use app\common\repositories\store\product\SpuRepository;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -47,17 +47,7 @@ class CloudWarehouse extends BaseController
|
|||||||
public function index($street_code, $page = 1, $category_id = 0, $cate_pid = 0,$cate_id = 0,$location = '')
|
public function index($street_code, $page = 1, $category_id = 0, $cate_pid = 0,$cate_id = 0,$location = '')
|
||||||
{
|
{
|
||||||
$keyword = $this->request->get('keyword');
|
$keyword = $this->request->get('keyword');
|
||||||
if (!empty($location) && $location != ',') {
|
[$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $street_code);
|
||||||
[$lat, $lng] = explode(',', $location);
|
|
||||||
} elseif (!empty($street_code)) {
|
|
||||||
$location = GeoStreet::where('street_code', $street_code)->field('lng,lat')->find();
|
|
||||||
if (!empty($location)) {
|
|
||||||
[$lat, $lng] = [$location['lat'], $location['lng']];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (empty($lat) || empty($lng)) {
|
|
||||||
[$lat, $lng] = ['28.889137', '105.443352'];
|
|
||||||
}
|
|
||||||
$query = Db::name('cloud_product')->where('status', 1);
|
$query = Db::name('cloud_product')->where('status', 1);
|
||||||
$productIds = (new MerchantDao())->getProductByDistance($lat, $lng,false,50000);
|
$productIds = (new MerchantDao())->getProductByDistance($lat, $lng,false,50000);
|
||||||
if (empty($productIds)) {
|
if (empty($productIds)) {
|
||||||
|
@ -10,10 +10,9 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\controller\api\store\product;
|
namespace app\controller\api\store\product;
|
||||||
|
|
||||||
|
use app\common\dao\store\CityAreaDao;
|
||||||
use app\common\dao\system\merchant\MerchantDao;
|
use app\common\dao\system\merchant\MerchantDao;
|
||||||
use app\common\model\store\GeoStreet;
|
|
||||||
use app\common\model\system\merchant\Merchant;
|
use app\common\model\system\merchant\Merchant;
|
||||||
use app\common\repositories\store\product\ProductRepository;
|
|
||||||
use app\common\repositories\store\StoreCategoryRepository;
|
use app\common\repositories\store\StoreCategoryRepository;
|
||||||
use app\common\repositories\system\merchant\MerchantRepository;
|
use app\common\repositories\system\merchant\MerchantRepository;
|
||||||
use app\common\repositories\user\UserHistoryRepository;
|
use app\common\repositories\user\UserHistoryRepository;
|
||||||
@ -68,23 +67,12 @@ class StoreSpu extends BaseController
|
|||||||
'location'
|
'location'
|
||||||
]);
|
]);
|
||||||
if ($where['type_id']||$where['type_code']) {
|
if ($where['type_id']||$where['type_code']) {
|
||||||
|
[$lat, $lng] = (new CityAreaDao())->getLngAndLat($where['location'], $where['street_id']);
|
||||||
$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);
|
||||||
if ($where['location']) {
|
$merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng);
|
||||||
[$lat, $lng] = explode(',', $where['location']);
|
if (!empty($merIds)) {
|
||||||
$merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng);
|
$query->whereIn('mer_id', $merIds);
|
||||||
if (!empty($merIds)) {
|
|
||||||
$query->whereIn('mer_id', $merIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($where['street_id'] && empty($where['location'])) {
|
|
||||||
$location = GeoStreet::where('street_code', $where['street_id'])->field('lng,lat')->find();
|
|
||||||
if (!empty($location)) {
|
|
||||||
$merIds = (new MerchantDao())->getValidMerchantByDistance($location['lat'], $location['lng']);
|
|
||||||
if (!empty($merIds)) {
|
|
||||||
$query->whereIn('mer_id', $merIds);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($where['village_id']) {
|
if ($where['village_id']) {
|
||||||
$query->where('village_id', $where['village_id']);
|
$query->where('village_id', $where['village_id']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user