Merge pull request 'dev' (#131) from dev into master

Reviewed-on: #131
This commit is contained in:
mkm 2024-01-23 16:47:49 +08:00
commit 9f0ba35ca7
5 changed files with 47 additions and 45 deletions

View File

@ -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];
}
} }

View File

@ -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) {

View File

@ -347,7 +347,7 @@ class MerchantDao extends BaseDao
} }
/** /**
* 按距离获取有效的商户 * 按距离获取有效的云仓商品
* @param $lat * @param $lat
* @param $lng * @param $lng
* @param $sort 是否按距离排序 * @param $sort 是否按距离排序

View File

@ -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,8 @@ 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 != ',') { $order = $this->request->get('order');
[$lat, $lng] = explode(',', $location); [$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $street_code);
} 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)) {
@ -73,6 +64,15 @@ class CloudWarehouse extends BaseController
if (!empty($keyword)) { if (!empty($keyword)) {
$query->where('store_name', 'like', '%'. $keyword . '%'); $query->where('store_name', 'like', '%'. $keyword . '%');
} }
if (!empty($order)) {
if ($order == 'sales') {
$query->order($order, 'desc');
} elseif ($order == 'price_desc') {
$query->order('price', 'desc');
} else {
$query->order('price', 'asc');
}
}
$cloud_product_arr = $query->where(function($query){ $cloud_product_arr = $query->where(function($query){
$query->where('mer_labels', '') $query->where('mer_labels', '')
->whereOr('mer_labels',',5,'); ->whereOr('mer_labels',',5,');
@ -87,7 +87,8 @@ class CloudWarehouse extends BaseController
'status' => 1, 'status' => 1,
'is_del' => 0, 'is_del' => 0,
'mer_status' => 1, 'mer_status' => 1,
'product_id' => $cloud_product 'product_id' => $cloud_product,
'order' => $order
]; ];
if (!$cloud_product) { if (!$cloud_product) {
return app('json')->success(['count' => 0, 'list' => []]); return app('json')->success(['count' => 0, 'list' => []]);

View File

@ -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']);