add 数据之眼-平台商品/店铺排行,地方商品数量统计接口
This commit is contained in:
parent
256e93b4ab
commit
f3962dbc4f
@ -46,7 +46,7 @@ class Order extends BaseController
|
||||
->leftJoin('product_order_log og', 'o.order_id = og.order_id')
|
||||
->leftJoin('merchant m', 'o.mer_id = m.mer_id')
|
||||
->leftJoin('store_order_product op', 'o.order_id = op.order_id')
|
||||
->leftJoin('product_library p', 'op.product_id = p.id')
|
||||
->leftJoin('store_product p', 'op.product_id = p.product_id')
|
||||
->whereDay('og.create_time', $day)
|
||||
->where('o.paid', 1)
|
||||
->whereNotNull('o.pay_time');
|
||||
@ -288,7 +288,7 @@ class Order extends BaseController
|
||||
->leftJoin('product_order_log og', 'o.order_id = og.order_id')
|
||||
->leftJoin('merchant m', 'o.mer_id = m.mer_id')
|
||||
->leftJoin('store_order_product op', 'o.order_id = op.order_id')
|
||||
->leftJoin('product_library p', 'op.product_id = p.id')
|
||||
->leftJoin('store_product p', 'op.product_id = p.product_id')
|
||||
->whereTime('og.create_time', 'between', $timeRange) // whereTime('create_time', 'between', [$a[0],$a[1]]);
|
||||
->where('o.paid', 1)
|
||||
->whereNotNull('o.pay_time');
|
||||
@ -376,4 +376,51 @@ class Order extends BaseController
|
||||
unset($street);
|
||||
return \app('json')->success(compact('list'));
|
||||
}
|
||||
|
||||
// 平台商品/店铺销量排行
|
||||
public function salesRanking()
|
||||
{
|
||||
$list = [];
|
||||
|
||||
// 商品销量排行榜
|
||||
$productRankingList = Db::name('store_product')->alias('p')
|
||||
->field('p.product_id, p.store_name, p.image, COUNT(o.`order_id`) AS total_sales')
|
||||
->join('store_order_product op', 'p.product_id = op.product_id')
|
||||
->join('store_order o', 'op.order_id = o.order_id')
|
||||
->group('p.product_id')
|
||||
->order('total_sales DESC')
|
||||
->limit(10)
|
||||
->select()->toArray();
|
||||
|
||||
$productRankingTotal = 0;
|
||||
foreach ($productRankingList as $k => $v) {
|
||||
$productRankingTotal += $v['total_sales'];
|
||||
}
|
||||
|
||||
// 店铺销量排行榜
|
||||
$merchantRankingList = Db::name('store_order')->alias('o')
|
||||
->field('m.`mer_id`, m.`mer_name`, m.mini_banner, COUNT(o.`order_id`) AS total_sales')
|
||||
->join('merchant m', 'o.`mer_id` = m.`mer_id`')
|
||||
->group('m.mer_id')
|
||||
->order('total_sales DESC')
|
||||
->limit(10)
|
||||
->select()->toArray();
|
||||
|
||||
$merchantRankingTotal = 0;
|
||||
foreach ($merchantRankingList as $k => $v) {
|
||||
$merchantRankingTotal += $v['total_sales'];
|
||||
}
|
||||
|
||||
// 统计每个镇的商品数
|
||||
$townProductCountList = [];
|
||||
$geoStreetList = Db::name('geo_street')->field('street_name, street_code')->where('area_code',$this->areaCode)->select()->toArray();
|
||||
foreach ($geoStreetList as $k => $street) {
|
||||
$street['product_count'] = Db::name('merchant')->alias('m')->field('p.`product_id`')
|
||||
->join('store_product p', 'm.mer_id = p.mer_id')
|
||||
->where('m.street_id', $street['street_code'])
|
||||
->count();
|
||||
$townProductCountList[] = $street;
|
||||
}
|
||||
return \app('json')->success(compact('productRankingTotal','productRankingList', 'merchantRankingTotal','merchantRankingList', 'townProductCountList'));
|
||||
}
|
||||
}
|
@ -733,6 +733,7 @@ Route::group('api/', function () {
|
||||
/**---------------------数据之眼可视化大屏api------------------- start */
|
||||
Route::get('user_merchat_count', 'User/userMerchantCount');
|
||||
Route::get('order_statistics', 'Order/orderStatistics');
|
||||
Route::get('sales_ranking', 'Order/salesRanking');
|
||||
|
||||
|
||||
/**---------------------数据之眼可视化大屏api-------------------- end */
|
||||
|
Loading…
x
Reference in New Issue
Block a user