SiteAccountLogService.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\site;
  12. use app\model\site\SiteAccountLog;
  13. use core\base\BaseAdminService;
  14. use think\db\exception\DbException;
  15. /**
  16. * 站点账单服务层
  17. * Class SiteAccountLogService
  18. * @package app\service\admin\site
  19. */
  20. class SiteAccountLogService extends BaseAdminService
  21. {
  22. public function __construct()
  23. {
  24. parent::__construct();
  25. $this->model = new SiteAccountLog();
  26. }
  27. /**
  28. * 获取账单列表
  29. * @param array $where
  30. * @return array
  31. * @throws DbException
  32. */
  33. public function getPage(array $where = [])
  34. {
  35. $field = 'id, site_id, type, money, trade_no, create_time';
  36. $search_model = $this->model->where([ [ 'site_id', '=', $this->site_id ] ])->withSearch([ 'create_time', 'type', 'trade_no' ], $where)->field($field)->append([ 'type_name', 'pay_info', 'money' ])->order('create_time desc');
  37. return $this->pageQuery($search_model);
  38. }
  39. /**
  40. * 获取账单详情
  41. * @param int $id
  42. * @return array
  43. */
  44. public function getInfo(int $id)
  45. {
  46. $field = 'id, site_id, type, money, trade_no, create_time';
  47. return $this->model->where([ [ 'site_id', '=', $this->site_id ], ['id', '=', $id]])->field($field)->append([ 'type_name', 'pay_info' ])->findOrEmpty()->toArray();
  48. }
  49. /**
  50. * 统计数据
  51. * @return array
  52. */
  53. public function stat()
  54. {
  55. return [
  56. 'pay' => $this->model->where([[ 'site_id', '=', $this->site_id ], ['type', '=', 'pay']])->sum('money'),
  57. 'refund' => $this->model->where([[ 'site_id', '=', $this->site_id ], ['type', '=', 'refund']])->sum('money'),
  58. 'transfer' => $this->model->where([[ 'site_id', '=', $this->site_id ], ['type', '=', 'transfer']])->sum('money'),
  59. ];
  60. }
  61. }