添加活动商品专区
This commit is contained in:
parent
cb6dfe58f9
commit
fc906e0528
@ -14,9 +14,13 @@ namespace app\common\dao\store;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\dao\store\product\CloudProductDao;
|
||||
use app\common\model\BaseModel;
|
||||
use app\common\model\store\GeoStreet;
|
||||
use app\common\model\store\StoreActivity;
|
||||
use app\common\repositories\store\product\SpuRepository;
|
||||
use app\common\repositories\system\RelevanceRepository;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -35,4 +39,69 @@ class StoreActivityDao extends BaseDao
|
||||
$where['is_del'] = 0;
|
||||
return $this->getSearch($where);
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动商品专区
|
||||
* @param $location
|
||||
* @param $streetCode
|
||||
* @param $activityId
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function product($location, $streetCode, $activityId)
|
||||
{
|
||||
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'];
|
||||
}
|
||||
$cloud_product_arr = (new CloudProductDao())->getByDistance($lat, $lng, ['activity_id' => $activityId], 4);
|
||||
$cloud_product = [];
|
||||
foreach ($cloud_product_arr as $key => $value) {
|
||||
$cloud_product[] = $value['product_id'];
|
||||
}
|
||||
$where = [
|
||||
'is_show' => 1,
|
||||
'is_used' => 1,
|
||||
'status' => 1,
|
||||
'is_del' => 0,
|
||||
'mer_status' => 1,
|
||||
'product_id' => $cloud_product
|
||||
];
|
||||
if (!$cloud_product) {
|
||||
return app('json')->success(['count' => 0, 'list' => []]);
|
||||
}
|
||||
$query = Db::name('cloud_product')->where('status', 1);
|
||||
$count = $query->where(function($query){
|
||||
$query->whereOr('mer_labels', '')
|
||||
->whereOr('mer_labels',',5,');
|
||||
})->count();
|
||||
/** @var SpuRepository $spuRep */
|
||||
$spuRep = app()->make(SpuRepository::class);
|
||||
$products = $spuRep->getApiSearch($where, 1, 4, false, true);
|
||||
if ($products['list']) {
|
||||
$list = $products['list'];
|
||||
foreach ($cloud_product_arr as $key => $value) {
|
||||
foreach ($list as $k => $v) {
|
||||
if ($value['product_id'] == $v['product_id']) {
|
||||
if ($value['mer_labels'] == ',5,') {
|
||||
$list[$k]['mer_labels_name'] = '五日达';
|
||||
} else {
|
||||
$list[$k]['mer_labels_name'] = '同城';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ['count' => $count, 'list' => $list ?? []];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,4 +27,27 @@ class CloudProductDao extends BaseDao
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 按距离获取云仓商品列表
|
||||
* @param $lat
|
||||
* @param $lng
|
||||
* @param $limit
|
||||
* @return array
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function getByDistance($lat, $lng, $where = [], $limit = 10)
|
||||
{
|
||||
$query = CloudProduct::where('status', 1)
|
||||
->where($where)
|
||||
->whereIn('store_name', ['耶贝尔柔韧布质竹纸特惠装(10包)', '家家宜除菌洗衣液阳光清香1千克', '家家宜除菌洗衣粉阳光清香1千克-New版', '家家宜柠檬高效除油洗洁精1.12千克'])
|
||||
->whereIn('type_id', [10, 17])
|
||||
->whereNotNull('lat')
|
||||
->whereNotNull('long')
|
||||
->field("product_id,mer_id,store_name,mer_labels,st_distance_sphere(point(`long`,`lat`), point({$lng}, {$lat})) as distance");
|
||||
$query->order('distance')->limit($limit);
|
||||
return $query->select()->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace app\controller\api\store;
|
||||
|
||||
use app\common\dao\store\consumption\StoreConsumptionDao;
|
||||
use app\common\dao\store\StoreActivityDao;
|
||||
use app\common\dao\store\StoreActivityUserDao;
|
||||
use crmeb\basic\BaseController;
|
||||
|
||||
@ -99,4 +100,21 @@ class StoreActivity extends BaseController
|
||||
return app('json')->success($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 活动商品专区
|
||||
* @param StoreActivityDao $dao
|
||||
* @return mixed
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
*/
|
||||
public function product(StoreActivityDao $dao)
|
||||
{
|
||||
$location = $this->request->get('location');
|
||||
$streetCode = $this->request->get('street_code');
|
||||
$activityId = $this->request->get('activity_id', 2);
|
||||
$result = $dao->product($location, $streetCode, $activityId);
|
||||
return app('json')->success($result);
|
||||
}
|
||||
|
||||
}
|
@ -647,6 +647,7 @@ Route::group('api/', function () {
|
||||
Route::resource('store/product/cloudWarehouse', 'api.store.product.CloudWarehouse');
|
||||
Route::get('store/product/town_cloud', 'api.store.product.CloudWarehouse/town');
|
||||
Route::get('storeActivity/consumption', 'api.store.StoreActivity/consumption'); //消费金列表
|
||||
Route::get('storeActivity/product', 'api.store.StoreActivity/product'); //活动商品专区
|
||||
Route::post('open/activityCommission', 'api.open/activityCommission'); //活动佣金回调
|
||||
})->middleware(UserTokenMiddleware::class, false);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user