SiteStatService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\stat;
  12. use app\dict\pay\TransferDict;
  13. use app\dict\shop\ShopCashOutDict;
  14. use app\dict\shop\ShopTransferDict;
  15. use app\dict\site\SiteDict;
  16. use app\model\order\RechargeOrder;
  17. use app\model\shop\ShopCashOut;
  18. use app\model\site\Site;
  19. use app\service\admin\site\SiteService;
  20. use core\base\BaseAdminService;
  21. use think\db\exception\DbException;
  22. /**
  23. * 站点统计服务层
  24. * Class StatService
  25. * @package app\service\admin\stat
  26. */
  27. class SiteStatService extends BaseAdminService
  28. {
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * 获取站点统计数据
  35. * @return int[]
  36. */
  37. public function getIndexData(){
  38. $data = [
  39. 'site_info' => '',
  40. ];
  41. $data['site_info'] = (new SiteService())->getInfo($this->site_id);
  42. $site_create_time = strtotime($data['site_info']['create_time']);
  43. $site_expire_time = strtotime($data['site_info']['expire_time']);
  44. $data['site_info']['mix'] = (number_format((time() - $site_create_time) / ($site_expire_time - $site_create_time), 2) * 100).'%';
  45. $data['site_info']['over_date'] = $site_expire_time - time() > 0 ? number_format(($site_expire_time - time())/ 86400, 2) : 0;
  46. return $data;
  47. }
  48. /**
  49. * 订单金额
  50. * @param $start_time
  51. * @param $end_time
  52. * @return float
  53. */
  54. public function orderMoney($start_time, $end_time)
  55. {
  56. $where[] = [
  57. ['site_id', '=', $this->site_id],
  58. ['order_status', '>', 0],
  59. ['create_time', 'between', [$start_time, $end_time]]
  60. ];
  61. return (new RechargeOrder())->where($where)->sum('order_money');
  62. }
  63. /**
  64. * 订单数量
  65. * @param $start_time
  66. * @param $end_time
  67. * @return int
  68. * @throws DbException
  69. */
  70. public function orderCount($start_time, $end_time)
  71. {
  72. $where[] = [
  73. ['site_id', '=', $this->site_id],
  74. ['order_status', '>', 0],
  75. ['create_time', 'between', [$start_time, $end_time]]
  76. ];
  77. return (new RechargeOrder())->where($where)->count('order_id');
  78. }
  79. /**
  80. * 待转账数量(微信零钱)
  81. * @return array
  82. * @throws DbException
  83. */
  84. public function getTransferCount()
  85. {
  86. $data['wait_transfer'] = (new ShopCashOut())->where([['site_id', '=', $this->site_id], ['status', '=', ShopCashOutDict::WAIT_TRANSFER]])->count();
  87. return $data;
  88. }
  89. /**
  90. * 站点已安装应用数量
  91. * @return array
  92. */
  93. public function getAddonCount()
  94. {
  95. $data['addon_num'] = 0;
  96. $site_info = (new Site())->field('group_id')->where([['site_id', '=', $this->site_id]])->with(['siteGroup'])->findOrEmpty()->toArray();
  97. if (!empty($site_info) && !empty($site_info['siteGroup']) && is_array($site_info['siteGroup']['addon'])) {
  98. $data['addon_num'] = count($site_info['siteGroup']['addon']);
  99. }
  100. return $data;
  101. }
  102. }