CapitalLogService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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\Common;
  12. use App\Models\CapitalLogModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 资产交易明细-服务类
  16. * Class CapitalLogService
  17. * @package App\Services\Common
  18. */
  19. class CapitalLogService extends BaseService
  20. {
  21. // 静态对象
  22. protected static $instance = null;
  23. /**
  24. * 构造函数
  25. * @since 2020/11/10
  26. * CapitalLogService constructor.
  27. */
  28. public function __construct()
  29. {
  30. $this->model = new CapitalLogModel();
  31. }
  32. /**
  33. * 静态入口
  34. * @return static|null
  35. */
  36. public static function make()
  37. {
  38. if (!self::$instance) {
  39. self::$instance = (new static());
  40. }
  41. return self::$instance;
  42. }
  43. /**
  44. * 获取列表
  45. * @param $params 参数
  46. * @param int $pageSize 分页大小:默认 15
  47. * @return array
  48. */
  49. public function getDataList($params, $pageSize = 15)
  50. {
  51. $where = ['a.mark' => 1];
  52. $type = isset($params['type'])? $params['type'] : 1;
  53. $changeType = isset($params['change_type'])? $params['change_type'] : 1;
  54. $userId = isset($params['user_id'])? $params['user_id'] : 0;
  55. if($type>0){
  56. $where['a.type'] = $type;
  57. }
  58. if($changeType>0){
  59. $where['a.change_type'] = $changeType;
  60. }
  61. if($userId>0){
  62. $where['a.user_id'] = $userId;
  63. }
  64. $list = $this->model->from('capital_logs as a')
  65. ->leftJoin('member as m', 'm.id', '=', 'a.user_id')
  66. ->where($where)
  67. ->where(function ($query) use($params){
  68. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  69. if($keyword){
  70. $query->where('a.order_no','like',"{$keyword}");
  71. }
  72. // 日期
  73. $date = isset($params['date']) ? $params['date'] : [];
  74. $start = isset($date[0])? $date[0] : '';
  75. $end = isset($date[1])? $date[1] : '';
  76. $end = $start>=$end? '' : $end;
  77. if ($start) {
  78. $query->where('a.create_time','>=', strtotime($start));
  79. }
  80. if($end){
  81. $query->where('a.create_time','<', strtotime($end));
  82. }
  83. })
  84. ->select(['a.*', 'm.username'])
  85. ->orderBy('a.create_time','desc')
  86. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  87. $list = $list? $list->toArray() :[];
  88. if($list){
  89. foreach($list['data'] as &$item){
  90. $item['time_text'] = $item['create_time']? datetime(strtotime($item['create_time']), 'm-d H:i'):'';
  91. }
  92. }
  93. return [
  94. 'pageSize'=> $pageSize,
  95. 'total'=>isset($list['total'])? $list['total'] : 0,
  96. 'list'=> isset($list['data'])? $list['data'] : []
  97. ];
  98. }
  99. }