| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\AccountLogModel;
- use App\Models\BalanceLogModel;
- use App\Services\BaseService;
- use Illuminate\Support\Facades\DB;
- /**
- * 余额日志管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * Class BalanceLogService
- * @package App\Services\Common
- */
- class BalanceLogService extends BaseService
- {
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * BalanceLogService constructor.
- */
- public function __construct()
- {
- $this->model = new BalanceLogModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * @param $params
- * @param int $pageSize
- * @return array
- */
- public function getDataList($params, $pageSize = 15)
- {
- $where = ['mark' => 1];
- $status = isset($params['status'])? $params['status'] : 0;
- $type = isset($params['type'])? $params['type'] : 0;
- $userType = isset($params['user_type'])? $params['user_type'] : 0;
- $coinType = isset($params['coin_type'])? $params['coin_type'] : 0;
- $userId = isset($params['user_id'])? $params['user_id'] : 0;
- if($status>0){
- $where['status'] = $status;
- }
- if($type>0){
- $where['type'] = $type;
- }
- if($userId>0){
- $where['user_id'] = $userId;
- }
- if($coinType>0){
- $where['coin_type'] = $coinType;
- }
- $year = isset($params['year']) && $params['year']? $params['year'] : '';
- $month = isset($params['month']) && $params['month']? $params['month'] : '';
- $date = $year&&$month? "{$year}-{$month}" : '';
- $date = $date? $date : date('Y');
- $model = $this->model->where($where)->where(function($query) use($userType,$year,$month){
- if($userType>0){
- $query->whereIn('user_type', [0, $userType]);
- }
- $date = $year&&$month? "{$year}-{$month}" : '';
- $date = $date? $date : date('Y-m');
- if($month){
- $query->where('date', 'like', "{$date}%");
- }else{
- $query->where('date', 'like', "{$year}%");
- }
- });
- // 统计
- $countModel = clone $model;
- $countModel1 = clone $model;
- $counts = [
- 'wait'=> moneyFormat($countModel->where(['status'=>1])->sum('money'), 2),
- 'checked'=> moneyFormat($countModel1->where(['status'=>2])->sum('money'), 2),
- ];
- $list = $model->select(['*'])
- ->orderBy('create_time','desc')
- ->orderBy('id','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list? $list->toArray() :[];
- if($list){
- foreach($list['data'] as &$item){
- $item['time_text'] = $item['create_time']? dateFormat($item['create_time'],'m月d日 H:i') : date('Y年m月');
- $item['create_time'] = $item['create_time']? datetime($item['create_time'],'Y-m-d H:i:s') : '';
- $item['pay_at'] = $item['pay_at'] && $item['pay_at'] !='0000-00-00 00:00:00'? $item['pay_at'] : $item['create_time'];
- }
- unset($item);
- }
- return [
- 'pageSize'=> $pageSize,
- 'counts'=> $counts,
- 'date'=> $date,
- 'total'=>isset($list['total'])? $list['total'] : 0,
- 'list'=> isset($list['data'])? $list['data'] : []
- ];
- }
- }
|