add 数据之眼-实时浏览量
This commit is contained in:
parent
69a69bef42
commit
5278ad622a
@ -3,9 +3,14 @@
|
||||
namespace app\controller\api\dataview;
|
||||
|
||||
use app\common\repositories\BaseRepository;
|
||||
use app\common\repositories\store\order\StoreOrderRepository;
|
||||
use app\common\repositories\system\merchant\MerchantRepository;
|
||||
use app\common\repositories\user\UserRepository;
|
||||
use app\common\repositories\user\UserVisitRepository;
|
||||
use crmeb\basic\BaseController;
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
class Product extends BaseController
|
||||
{
|
||||
@ -167,4 +172,44 @@ class Product extends BaseController
|
||||
return compact('todayMerchantCount', 'yestertodayMerchantCount', 'weeklyMerchantGrowthRate');
|
||||
}
|
||||
|
||||
public function viewCount()
|
||||
{
|
||||
$res = Cache::store('file')->remember(self::class . '@viewCount', function () {
|
||||
$today = $this->mainGroup('today');
|
||||
$yesterday = $this->mainGroup('yesterday');
|
||||
$lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')));
|
||||
$lastWeekRate = $this->getRate($lastWeek, $today, 4);
|
||||
|
||||
return compact('today', 'yesterday', 'lastWeekRate');
|
||||
}, 2000 + random_int(600, 1200));
|
||||
return app('json')->success($res);
|
||||
}
|
||||
|
||||
protected function mainGroup($date)
|
||||
{
|
||||
$userVisitRepository = app()->make(UserVisitRepository::class);
|
||||
$visitNum = (float)$userVisitRepository->dateVisitNum($date);
|
||||
return $visitNum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $last
|
||||
* @param $today
|
||||
* @param int $scale
|
||||
* @return int|string|null
|
||||
* @author xaboy
|
||||
* @day 2020/6/25
|
||||
*/
|
||||
protected function getRate($last, $today, $scale = 2)
|
||||
{
|
||||
if ($last == $today)
|
||||
return 0;
|
||||
else if ($last == 0)
|
||||
return $today;
|
||||
else if ($today == 0)
|
||||
return -$last;
|
||||
else
|
||||
return (float)bcdiv(bcsub($today, $last, $scale), $last, $scale);
|
||||
}
|
||||
|
||||
}
|
@ -736,6 +736,7 @@ Route::group('api/', function () {
|
||||
Route::get('sales_ranking', 'Order/salesRanking');
|
||||
Route::get('curr_day_order_amount', 'Order/currDayOrderAmount');
|
||||
Route::get('product_count', 'Product/productCount');
|
||||
Route::get('view_count', 'Product/viewCount');
|
||||
|
||||
|
||||
/**---------------------数据之眼可视化大屏api-------------------- end */
|
||||
|
Loading…
x
Reference in New Issue
Block a user