| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services\Api;
- use App\Models\BalanceLogModel;
- use App\Models\PledgeOrderModel;
- use App\Models\PriceLogModel;
- use App\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 余额账户-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class BalanceLogService extends BaseService
- {
- protected static $instance;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new BalanceLogModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 充值提现统计
- * @param int $userId 用户ID
- * @param $type 类型:1-充值,2-提现
- * @return array|mixed
- */
- public function getCountByType(int $userId=0, $type=1, $coinType=1, $status=2)
- {
- $cacheKey = "caches:balance:counts_{$userId}_{$type}_{$coinType}_{$status}";
- $counts = RedisService::get($cacheKey);
- if($counts){
- return $counts;
- }
- $where = ['user_id'=> $userId,'coin_type'=>0,'type'=>$type,'mark'=>1];
- if($coinType){
- $where['coin_type'] = $coinType;
- }else{
- unset($where['coin_type']);
- }
- $data = $this->model->where($where)->where(function ($query)use($status){
- if($status){
- $query->where('status', $status);
- }else{
- $query->whereIn('status', [1,2]);
- }
- })->sum('money');
- RedisService::set($cacheKey, $data, rand(3, 5));
- return $data;
- }
- }
|