123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- // +----------------------------------------------------------------------
- // | Niucloud-admin 企业快速开发的saas管理平台
- // +----------------------------------------------------------------------
- // | 官方网址:https://www.niucloud.com
- // +----------------------------------------------------------------------
- // | niucloud团队 版权所有 开源版本可自由商用
- // +----------------------------------------------------------------------
- // | Author: Niucloud Team
- // +----------------------------------------------------------------------
- namespace app\service\admin\stat;
- use app\dict\pay\TransferDict;
- use app\dict\shop\ShopCashOutDict;
- use app\dict\shop\ShopTransferDict;
- use app\dict\site\SiteDict;
- use app\model\order\RechargeOrder;
- use app\model\shop\ShopCashOut;
- use app\model\site\Site;
- use app\service\admin\site\SiteService;
- use core\base\BaseAdminService;
- use think\db\exception\DbException;
- /**
- * 站点统计服务层
- * Class StatService
- * @package app\service\admin\stat
- */
- class SiteStatService extends BaseAdminService
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取站点统计数据
- * @return int[]
- */
- public function getIndexData(){
- $data = [
- 'site_info' => '',
- ];
- $data['site_info'] = (new SiteService())->getInfo($this->site_id);
- $site_create_time = strtotime($data['site_info']['create_time']);
- $site_expire_time = strtotime($data['site_info']['expire_time']);
- $data['site_info']['mix'] = (number_format((time() - $site_create_time) / ($site_expire_time - $site_create_time), 2) * 100).'%';
- $data['site_info']['over_date'] = $site_expire_time - time() > 0 ? number_format(($site_expire_time - time())/ 86400, 2) : 0;
- return $data;
- }
- /**
- * 订单金额
- * @param $start_time
- * @param $end_time
- * @return float
- */
- public function orderMoney($start_time, $end_time)
- {
- $where[] = [
- ['site_id', '=', $this->site_id],
- ['order_status', '>', 0],
- ['create_time', 'between', [$start_time, $end_time]]
- ];
- return (new RechargeOrder())->where($where)->sum('order_money');
- }
- /**
- * 订单数量
- * @param $start_time
- * @param $end_time
- * @return int
- * @throws DbException
- */
- public function orderCount($start_time, $end_time)
- {
- $where[] = [
- ['site_id', '=', $this->site_id],
- ['order_status', '>', 0],
- ['create_time', 'between', [$start_time, $end_time]]
- ];
- return (new RechargeOrder())->where($where)->count('order_id');
- }
- /**
- * 待转账数量(微信零钱)
- * @return array
- * @throws DbException
- */
- public function getTransferCount()
- {
- $data['wait_transfer'] = (new ShopCashOut())->where([['site_id', '=', $this->site_id], ['status', '=', ShopCashOutDict::WAIT_TRANSFER]])->count();
- return $data;
- }
- /**
- * 站点已安装应用数量
- * @return array
- */
- public function getAddonCount()
- {
- $data['addon_num'] = 0;
- $site_info = (new Site())->field('group_id')->where([['site_id', '=', $this->site_id]])->with(['siteGroup'])->findOrEmpty()->toArray();
- if (!empty($site_info) && !empty($site_info['siteGroup']) && is_array($site_info['siteGroup']['addon'])) {
- $data['addon_num'] = count($site_info['siteGroup']['addon']);
- }
- return $data;
- }
- }
|