AccountService.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\MemberModel;
  14. use App\Services\BaseService;
  15. use App\Services\ConfigService;
  16. use App\Services\PaymentService;
  17. use App\Services\RedisService;
  18. use Illuminate\Support\Facades\DB;
  19. /**
  20. * 交易管理-服务类
  21. * @author laravel开发员
  22. * @since 2020/11/11
  23. * Class AccountService
  24. */
  25. class AccountService extends BaseService
  26. {
  27. public static $instance = null;
  28. /**
  29. * 构造函数
  30. * @author laravel开发员
  31. * @since 2020/11/11
  32. * AccountService constructor.
  33. */
  34. public function __construct()
  35. {
  36. $this->model = new AccountLogModel();
  37. }
  38. /**
  39. * 静态入口
  40. * @return static|null
  41. */
  42. public static function make()
  43. {
  44. if (!self::$instance) {
  45. self::$instance = (new static());
  46. }
  47. return self::$instance;
  48. }
  49. /**
  50. * @param $params
  51. * @param int $pageSize
  52. * @return array
  53. */
  54. public function getDataList($params, $pageSize = 15)
  55. {
  56. $query = $this->getQuery($params);
  57. $list = $query->select(['a.*'])
  58. ->orderBy('a.create_time','desc')
  59. ->orderBy('a.id','desc')
  60. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  61. $list = $list? $list->toArray() :[];
  62. if($list){
  63. $accountTypes = config('payment.accountTypes');
  64. foreach($list['data'] as &$item){
  65. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H:i:s') : '';
  66. $item['time_text'] = $item['create_time']? dateFormat($item['create_time'],'Y年m月d日') : '';
  67. $type = isset($item['type'])? intval($item['type']) : 0;
  68. $item['type_text'] = isset($item['remark'])? trim($item['remark']) : '';
  69. if(empty($item['type_text'])){
  70. $item['type_text'] = isset($accountTypes[$type])? $accountTypes[$type] : '收支明细';
  71. }
  72. $item['change_type'] = 1;
  73. if(in_array($type,[1,2,4])){
  74. $item['change_type'] = 2;
  75. }
  76. }
  77. }
  78. return [
  79. 'pageSize'=> $pageSize,
  80. 'total'=>isset($list['total'])? $list['total'] : 0,
  81. 'list'=> isset($list['data'])? $list['data'] : []
  82. ];
  83. }
  84. public function getQuery($params)
  85. {
  86. $where = ['a.mark' => 1];
  87. $type = isset($params['type'])? $params['type'] : 0;
  88. if($type>0){
  89. $where['a.type'] = $type;
  90. }
  91. return $this->model->with(['member'])->from("account_logs as a")
  92. ->leftJoin('member as b','b.id','=','a.user_id')
  93. ->where($where)
  94. ->where(function ($query) use($params) {
  95. $keyword = isset($params['keyword']) ? $params['keyword'] : '';
  96. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  97. if($userId){
  98. $query->where('a.user_id',$userId);
  99. }
  100. $status = isset($params['status'])? $params['status'] : 0;
  101. if($status){
  102. $query->where('a.status',$status);
  103. }else{
  104. $query->whereNotIn('a.status',[2]);
  105. }
  106. if ($keyword) {
  107. $query->where(function($query) use($keyword){
  108. $query->where('b.nickname','like',"%{$keyword}%")
  109. ->orWhere('b.mobile','like',"%{$keyword}%")
  110. ->orWhere('b.realname','like',"%{$keyword}%");
  111. });
  112. }
  113. $orderNo = isset($params['order_no'])? trim($params['order_no']) : '';
  114. if($orderNo){
  115. $query->where(function($query) use($orderNo){
  116. $query->where('a.source_order_no','like',"%{$orderNo}%");
  117. });
  118. }
  119. })
  120. ->where(function ($query) use($params){
  121. // 日期
  122. $date = isset($params['date']) ? $params['date'] : [];
  123. $start = isset($date[0])? $date[0] : '';
  124. $end = isset($date[1])? $date[1] : '';
  125. $end = $start>=$end? '' : $end;
  126. if ($start) {
  127. $query->where('a.create_time','>=', strtotime($start));
  128. }
  129. if($end){
  130. $query->where('a.create_time','<=', strtotime($end));
  131. }
  132. });
  133. }
  134. }