调整商品列表查询
This commit is contained in:
parent
fb2b83f60f
commit
aa368d2520
@ -315,4 +315,29 @@ class MerchantDao extends BaseDao
|
|||||||
return $this->getModel()::getInstance()->where($where);
|
return $this->getModel()::getInstance()->where($where);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按距离获取有效的商户
|
||||||
|
* @param $lat
|
||||||
|
* @param $lng
|
||||||
|
* @param $distance 距离,单位米
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getValidMerchantByDistance($lat, $lng, $distance = 2000)
|
||||||
|
{
|
||||||
|
$merchant = Merchant::where('type_id', 'IN', ["10", "17"])
|
||||||
|
->where(['is_del' => 0, 'mer_state' => 1])
|
||||||
|
->whereNotNull('lat')
|
||||||
|
->whereNotNull('long')
|
||||||
|
->field("mer_id,st_distance_sphere(point(`long`,`lat`), point({$lng}, {$lat})) as distance")
|
||||||
|
->having("distance <= {$distance}")
|
||||||
|
->limit(50)->select();
|
||||||
|
if (empty($merchant)) {
|
||||||
|
$merchant = $this->getValidMerchantByDistance($lat, $lng, 5000);
|
||||||
|
}
|
||||||
|
if (!empty($merchant)) {
|
||||||
|
return array_column($merchant->toArray(), 'mer_id');
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace app\controller\api\store\product;
|
namespace app\controller\api\store\product;
|
||||||
|
|
||||||
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;
|
||||||
@ -45,18 +46,23 @@ 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 = '')
|
||||||
{
|
{
|
||||||
|
$query = Db::name('cloud_product')->where('status', 1);
|
||||||
$cloud_where['street_code']=$street_code;
|
if (!empty($street_code)) {
|
||||||
$cloud_where['status']=1;
|
$location = GeoStreet::where('street_code', $street_code)->field('lng,lat')->find();
|
||||||
|
if (!empty($location)) {
|
||||||
|
$merIds = (new MerchantDao())->getValidMerchantByDistance($location['lat'], $location['lng']);
|
||||||
|
if (!empty($merIds)) {
|
||||||
|
$query->whereIn('mer_id', $merIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if($cate_pid!=0){
|
if($cate_pid!=0){
|
||||||
$cate_id=Db::name('store_category')->where('pid',$cate_pid)->where('is_show',1)->column('store_category_id');
|
$cate_id=Db::name('store_category')->where('pid',$cate_pid)->where('is_show',1)->column('store_category_id');
|
||||||
}
|
}
|
||||||
if($cate_id>0){
|
if($cate_id>0){
|
||||||
$cloud_where['cate_id']=$cate_id;
|
$query->where('cate_id', $cate_id);
|
||||||
}
|
}
|
||||||
$cloud_product_arr = Db::name('cloud_product')
|
$cloud_product_arr = $query->where(function($query){
|
||||||
->where($cloud_where)
|
|
||||||
->where(function($query){
|
|
||||||
$query->whereOr('mer_labels', '')
|
$query->whereOr('mer_labels', '')
|
||||||
->whereOr('mer_labels',',5,');
|
->whereOr('mer_labels',',5,');
|
||||||
})->page($page)->field('product_id,mer_labels')->select();
|
})->page($page)->field('product_id,mer_labels')->select();
|
||||||
@ -75,9 +81,7 @@ class CloudWarehouse extends BaseController
|
|||||||
if (!$cloud_product) {
|
if (!$cloud_product) {
|
||||||
return app('json')->success(['count' => 0, 'list' => []]);
|
return app('json')->success(['count' => 0, 'list' => []]);
|
||||||
}
|
}
|
||||||
$count = Db::name('cloud_product')
|
$count = $query->where(function($query){
|
||||||
->where($cloud_where)
|
|
||||||
->where(function($query){
|
|
||||||
$query->whereOr('mer_labels', '')
|
$query->whereOr('mer_labels', '')
|
||||||
->whereOr('mer_labels',',5,');
|
->whereOr('mer_labels',',5,');
|
||||||
})->count();
|
})->count();
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
namespace app\controller\api\store\product;
|
namespace app\controller\api\store\product;
|
||||||
|
|
||||||
|
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\product\ProductRepository;
|
||||||
use app\common\repositories\store\StoreCategoryRepository;
|
use app\common\repositories\store\StoreCategoryRepository;
|
||||||
@ -62,23 +64,38 @@ class StoreSpu extends BaseController
|
|||||||
'street_id',
|
'street_id',
|
||||||
'category_id',
|
'category_id',
|
||||||
'type_code',
|
'type_code',
|
||||||
'village_id'
|
'village_id',
|
||||||
|
'location'
|
||||||
]);
|
]);
|
||||||
if ($where['type_id']||$where['type_code']) {
|
if ($where['type_id']||$where['type_code']) {
|
||||||
$arr = ['status' => 1, 'mer_state' => 1, 'is_del' => 0];
|
$arr = ['status' => 1, 'mer_state' => 1, 'is_del' => 0];
|
||||||
if ($where['street_id']) {
|
$query = Merchant::where($arr);
|
||||||
$arr['street_id'] = $where['street_id'];
|
if ($where['location']) {
|
||||||
|
[$lat, $lng] = explode(',', $where['location']);
|
||||||
|
$merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng);
|
||||||
|
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']) {
|
||||||
$arr['village_id'] = $where['village_id'];
|
$query->where('village_id', $where['village_id']);
|
||||||
}
|
}
|
||||||
if($where['type_code']){
|
if($where['type_code']){
|
||||||
$mer_type_id=Db::name('merchant_type')->where('type_code',$where['type_code'])->value('mer_type_id');
|
$mer_type_id=Db::name('merchant_type')->where('type_code',$where['type_code'])->value('mer_type_id');
|
||||||
if($mer_type_id){
|
if($mer_type_id){
|
||||||
$where['type_id'] = $mer_type_id;
|
$query->where('type_id', $mer_type_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$where['mer_ids'] = Merchant::getInstance()->whereIn('type_id', explode(',', $where['type_id']))->where($arr)->column('mer_id');
|
$where['mer_ids'] = $query->whereIn('type_id', explode(',', $where['type_id']))->column('mer_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($where['type_id'], $where['street_id'],$where['type_code'],$where['village_id']);
|
unset($where['type_id'], $where['street_id'],$where['type_code'],$where['village_id']);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user