BalanceLogService.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\AccountLogModel;
  13. use App\Models\BalanceLogModel;
  14. use App\Services\BaseService;
  15. use Illuminate\Support\Facades\DB;
  16. /**
  17. * 余额日志管理-服务类
  18. * @author laravel开发员
  19. * @since 2020/11/11
  20. * Class BalanceLogService
  21. * @package App\Services\Common
  22. */
  23. class BalanceLogService extends BaseService
  24. {
  25. /**
  26. * 构造函数
  27. * @author laravel开发员
  28. * @since 2020/11/11
  29. * BalanceLogService constructor.
  30. */
  31. public function __construct()
  32. {
  33. $this->model = new BalanceLogModel();
  34. }
  35. /**
  36. * 静态入口
  37. * @return static|null
  38. */
  39. public static function make()
  40. {
  41. if (!self::$instance) {
  42. self::$instance = (new static());
  43. }
  44. return self::$instance;
  45. }
  46. /**
  47. * @param $params
  48. * @param int $pageSize
  49. * @return array
  50. */
  51. public function getDataList($params, $pageSize = 15)
  52. {
  53. $where = ['mark' => 1];
  54. $status = isset($params['status'])? $params['status'] : 0;
  55. $type = isset($params['type'])? $params['type'] : 0;
  56. $userType = isset($params['user_type'])? $params['user_type'] : 0;
  57. $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
  58. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  59. if($status>0){
  60. $where['status'] = $status;
  61. }
  62. if($type>0){
  63. $where['type'] = $type;
  64. }
  65. if($userId>0){
  66. $where['user_id'] = $userId;
  67. }
  68. if($coinType>0){
  69. $where['coin_type'] = $coinType;
  70. }
  71. $year = isset($params['year']) && $params['year']? $params['year'] : '';
  72. $month = isset($params['month']) && $params['month']? $params['month'] : '';
  73. $date = $year&&$month? "{$year}-{$month}" : '';
  74. $date = $date? $date : date('Y');
  75. $model = $this->model->with(['payment'])->where($where)->where(function($query) use($userType,$year,$month){
  76. if($userType>0){
  77. $query->whereIn('user_type', [0, $userType]);
  78. }
  79. $date = $year&&$month? "{$year}-{$month}" : '';
  80. $date = $date? $date : date('Y-m');
  81. if($month){
  82. $query->where('date', 'like', "{$date}%");
  83. }else{
  84. $query->where('date', 'like', "{$year}%");
  85. }
  86. });
  87. // 统计
  88. $countModel = clone $model;
  89. $countModel1 = clone $model;
  90. $counts = [
  91. 'wait'=> moneyFormat($countModel->where(['status'=>1])->sum('money'), 2),
  92. 'checked'=> moneyFormat($countModel1->where(['status'=>2])->sum('money'), 2),
  93. ];
  94. $list = $model->select(['*'])
  95. ->orderBy('create_time','desc')
  96. ->orderBy('id','desc')
  97. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  98. $list = $list? $list->toArray() :[];
  99. if($list){
  100. foreach($list['data'] as &$item){
  101. $item['time_text'] = $item['create_time']? dateFormat($item['create_time'],'m月d日 H:i') : date('Y年m月');
  102. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  103. $item['pay_at'] = $item['pay_at'] && $item['pay_at'] !='0000-00-00 00:00:00'? $item['pay_at'] : $item['create_time'];
  104. $item['payment'] = isset($item['payment'])? $item['payment'] : [];
  105. $item['pay_img'] = $item['pay_img']? get_image_url($item['pay_img']) : '';
  106. if($item['payment'] && isset($item['payment']['qrcode'])){
  107. $item['payment']['qrcode'] = get_image_url($item['payment']['qrcode']);
  108. }
  109. if($item['payment'] && isset($item['payment']['bank_card'])){
  110. $item['payment']['bank_card_text'] = format_bank_card($item['payment']['bank_card']);
  111. }
  112. }
  113. unset($item);
  114. }
  115. return [
  116. 'pageSize'=> $pageSize,
  117. 'counts'=> $counts,
  118. 'date'=> $date,
  119. 'total'=>isset($list['total'])? $list['total'] : 0,
  120. 'list'=> isset($list['data'])? $list['data'] : []
  121. ];
  122. }
  123. }