FinanceService.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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\FinanceModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 平台财务管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * Class FinanceService
  19. * @package App\Services\Common
  20. */
  21. class FinanceService extends BaseService
  22. {
  23. /**
  24. * 构造函数
  25. * @author laravel开发员
  26. * @since 2020/11/11
  27. * FinanceService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new FinanceModel();
  32. }
  33. /**
  34. * 静态入口
  35. * @return static|null
  36. */
  37. public static function make()
  38. {
  39. if (!self::$instance) {
  40. self::$instance = (new static());
  41. }
  42. return self::$instance;
  43. }
  44. /**
  45. * @param $params
  46. * @param int $pageSize
  47. * @return array
  48. */
  49. public function getDataList($params, $pageSize = 15)
  50. {
  51. $where = ['a.mark' => 1];
  52. $status = isset($params['status'])? $params['status'] : 0;
  53. $type = isset($params['type'])? $params['type'] : 0;
  54. if($status>0){
  55. $where['a.status'] = $status;
  56. }
  57. if($type>0){
  58. $where['a.type'] = $type;
  59. }
  60. $list = $this->model->from('finance as a')
  61. ->where($where)
  62. ->where(function ($query) use($params){
  63. // 日期
  64. $date = isset($params['date']) ? $params['date'] : [];
  65. $start = isset($date[0])? $date[0] : '';
  66. $end = isset($date[1])? $date[1] : '';
  67. $end = $start>=$end? '' : $end;
  68. if ($start) {
  69. $query->where('a.create_time','>=', strtotime($start));
  70. }
  71. if($end){
  72. $query->where('a.create_time','<', strtotime($end));
  73. }
  74. })
  75. ->select(['a.*'])
  76. ->orderBy('a.create_time','desc')
  77. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  78. $list = $list? $list->toArray() :[];
  79. if($list){
  80. foreach($list['data'] as &$item){
  81. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  82. }
  83. }
  84. return [
  85. 'pageSize'=> $pageSize,
  86. 'total'=>isset($list['total'])? $list['total'] : 0,
  87. 'list'=> isset($list['data'])? $list['data'] : []
  88. ];
  89. }
  90. /**
  91. * 添加或编辑
  92. * @return array
  93. * @since 2020/11/11
  94. * @author laravel开发员
  95. */
  96. public function edit()
  97. {
  98. $data = request()->all();
  99. return parent::edit($data); // TODO: Change the autogenerated stub
  100. }
  101. /**
  102. * 获取店铺交易统计
  103. * @param $shopId
  104. * @param int $type
  105. * @param int $coinType
  106. * @return mixed
  107. */
  108. public function getShopAccountTotal($shopId, $type = 1, $coinType=1)
  109. {
  110. $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
  111. return $this->model->where($where)
  112. ->where(function($query) use($type, $coinType){
  113. if($type){
  114. $query->whereIn('type', is_array($type)? $type : [$type]);
  115. }
  116. if($coinType){
  117. $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
  118. }
  119. })
  120. ->sum('money');
  121. }
  122. /**
  123. * 获取交易数
  124. * @param $shopId
  125. * @param int $type
  126. * @param int $coinType
  127. * @return mixed
  128. */
  129. public function getShopAccountCount($shopId, $type = 1, $coinType=1)
  130. {
  131. $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
  132. if($coinType){
  133. $where['coin_type'] = $coinType;
  134. }
  135. return $this->model->where($where)
  136. ->where(function($query) use($type, $coinType){
  137. if($type){
  138. $query->whereIn('type', is_array($type)? $type : [$type]);
  139. }
  140. if($coinType){
  141. $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
  142. }
  143. })
  144. ->count('id');
  145. }
  146. }