| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?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\Services\BaseService;
- use App\Services\RedisService;
- /**
- * 账户-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services\Api
- */
- class AccountLogService extends BaseService
- {
- protected static $instance;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- */
- public function __construct()
- {
- $this->model = new AccountLogModel();
- }
- /**
- * 静态入口
- */
- public static function make()
- {
- if (!self::$instance) {
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 账单明细/收益明细
- * @param $userId 用户ID
- * @param int $coinType 币种:1-USDT,2-SBT,3-收益/奖励
- * @param int $type 明细类型
- * @param int $page 分页
- * @param int $pageSize 页数
- * @return array|mixed
- */
- public function getDataList($userId, $coinType=1, $type=0, $page=1, $pageSize=12)
- {
- $cacheKey = "caches:account:list_{$userId}_{$coinType}{$type}{$page}{$pageSize}";
- $datas = RedisService::get($cacheKey);
- if($datas){
- return $datas;
- }
- $where = ['a.user_id'=> $userId,'a.status'=>1,'a.mark'=>1];
- if($type){
- $where['a.type'] = $type;
- }
- $list = $this->model->from('account_log as a')
- ->where($where)
- ->leftJoin('balance_logs as b',function($join) {
- $join->on('b.order_no','=','a.order_no')->on('b.user_id','=','a.user_id');
- })
- ->leftJoin('pledge_orders as c',function($join) {
- $join->on('c.order_no','=','a.order_no')->on('c.user_id','=','a.user_id');
- })
- ->where(function($query) use($coinType){
- if($coinType>0){
- $query->where('a.coin_type', $coinType);
- }
- })
- ->select(['a.user_id','a.type','a.order_no','a.source_uid','a.money','a.coin_type','a.before_money','a.create_time','a.remark','a.status','b.status as b_status','b.audit_remark','b.pay_status','b.pay_at','c.status as c_status','c.expired_at','c.settle_at'])
- ->orderBy('a.create_time','desc')
- ->orderBy('a.id','desc')
- ->paginate($pageSize > 0 ? $pageSize : 9999999);
- $list = $list ? $list->toArray() : [];
- $datas = [
- 'page' => $page,
- 'pageSize' => $pageSize,
- 'total' => 0,
- 'list' => []
- ];
- if ($list && $list['data']) {
- $types = config('dapp.accountTypes');
- foreach ($list['data'] as &$item){
- $item['time_text'] = isset($item['create_time']) && $item['create_time']>0? date('Y.m.d H:i:s', strtotime($item['create_time'])):'';
- $remark = isset($item['remark']) && $item['remark']? $item['remark'] : '交易明细';
- $type = isset($item['type'])? $item['type'] : 0;
- $item['type_text'] = isset($types[$type])? $types[$type] : $remark;
- }
- $datas = [
- 'page' => $page,
- 'pageSize' => $pageSize,
- 'total' => isset($list['total']) ? $list['total'] : 0,
- 'list' => isset($list['data']) ? $list['data'] : []
- ];
- RedisService::set($cacheKey, $datas, rand(3,5));
- }
- return $datas;
- }
- /**
- * 账户统计
- * @param int $userId 用户ID
- * @param $type 类型:1-质押交易,2-闪兑交易,3-充值,4-提现,5-链上充值(平台上分),6-链上扣除(平台下分),7-质押收益,8-推荐分享奖励,9-管理奖,10-平级奖,11-全网分红奖励,12-质押退还,99-其他
- * @param $coinType 币种类型:1-USDT,2-SBT,3-收益
- * @return array|mixed
- */
- public function getCountByType(int $userId=0, $type=1,$coinType=0)
- {
- $cacheKey = "caches:account:counts_{$userId}_{$type}_{$coinType}";
- $counts = RedisService::get($cacheKey);
- if($counts){
- return $counts;
- }
- $where = ['user_id'=> $userId,'type'=>$type,'status'=>2,'mark'=>1];
- if($coinType){
- $where['coin_type'] = $coinType;
- }
- $data = $this->model->where($where)->sum('money');
- RedisService::set($cacheKey, abs($data), rand(10, 20));
- return abs($data);
- }
- }
|