AccountService.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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\AccountModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 交易管理-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/11
  18. * Class AccountService
  19. * @package App\Services\Common
  20. */
  21. class AccountService extends BaseService
  22. {
  23. /**
  24. * 构造函数
  25. * @author laravel开发员
  26. * @since 2020/11/11
  27. * AccountService constructor.
  28. */
  29. public function __construct()
  30. {
  31. $this->model = new AccountModel();
  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. $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
  55. if($status>0){
  56. $where['a.status'] = $status;
  57. }
  58. if($type>0){
  59. $where['a.type'] = $type;
  60. }
  61. if($coinType>0){
  62. $where['a.coin_type'] = $coinType;
  63. }
  64. $list = $this->model->from('account_log as a')
  65. ->leftJoin('member as b', 'b.id', '=', 'a.user_id')
  66. ->leftJoin('shop as c', 'c.id', '=', 'a.shop_id')
  67. ->leftJoin('member as d', 'd.id', '=', 'a.source_uid')
  68. ->where($where)
  69. ->where(function ($query) use($params){
  70. $keyword = isset($params['keyword'])? $params['keyword'] : '';
  71. if($keyword){
  72. $query->where('b.nickname','like',"%{$keyword}%")->orWhere('b.mobile','like',"%{$keyword}%");
  73. }
  74. // 日期
  75. $date = isset($params['date']) ? $params['date'] : [];
  76. $start = isset($date[0])? $date[0] : '';
  77. $end = isset($date[1])? $date[1] : '';
  78. $end = $start>=$end? '' : $end;
  79. if ($start) {
  80. $query->where('a.create_time','>=', strtotime($start));
  81. }
  82. if($end){
  83. $query->where('a.create_time','<=', strtotime($end));
  84. }
  85. })
  86. ->select(['a.*','b.username','b.mobile','b.nickname','c.name as shop_name','d.nickname as source_username'])
  87. ->orderBy('a.create_time','desc')
  88. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  89. $list = $list? $list->toArray() :[];
  90. if($list){
  91. foreach($list['data'] as &$item){
  92. $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H.i.s') : '';
  93. }
  94. }
  95. return [
  96. 'pageSize'=> $pageSize,
  97. 'total'=>isset($list['total'])? $list['total'] : 0,
  98. 'list'=> isset($list['data'])? $list['data'] : []
  99. ];
  100. }
  101. /**
  102. * 添加或编辑
  103. * @return array
  104. * @since 2020/11/11
  105. * @author laravel开发员
  106. */
  107. public function edit()
  108. {
  109. $data = request()->all();
  110. return parent::edit($data); // TODO: Change the autogenerated stub
  111. }
  112. /**
  113. * 获取店铺交易统计
  114. * @param $shopId
  115. * @param int $type
  116. * @param int $coinType
  117. * @return mixed
  118. */
  119. public function getShopAccountTotal($shopId, $type = 1, $coinType=1)
  120. {
  121. $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
  122. return $this->model->where($where)
  123. ->where(function($query) use($type, $coinType){
  124. if($type){
  125. $query->whereIn('type', is_array($type)? $type : [$type]);
  126. }
  127. if($coinType){
  128. $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
  129. }
  130. })
  131. ->sum('money');
  132. }
  133. /**
  134. * 获取交易数
  135. * @param $shopId
  136. * @param int $type
  137. * @param int $coinType
  138. * @return mixed
  139. */
  140. public function getShopAccountCount($shopId, $type = 1, $coinType=1)
  141. {
  142. $where = ['shop_id'=>$shopId,'status'=>1,'mark'=>1];
  143. if($coinType){
  144. $where['coin_type'] = $coinType;
  145. }
  146. return $this->model->where($where)
  147. ->where(function($query) use($type, $coinType){
  148. if($type){
  149. $query->whereIn('type', is_array($type)? $type : [$type]);
  150. }
  151. if($coinType){
  152. $query->whereIn('coin_type', is_array($coinType)? $coinType : [$coinType]);
  153. }
  154. })
  155. ->count('id');
  156. }
  157. }