// +---------------------------------------------------------------------- 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 == 3){ $query->whereIn('a.coin_type',[2,3]); }else 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; // $order = isset($item['order'])? $item['order'] : []; // $pledgeOrder = isset($item['porder'])? $item['porder'] : []; // if($item['type'] == 4 && in_array($item['coin_type'],[1,3])){ // $item['status'] = isset($order['status'])? intval($order['status']) : $item['status']; // $item['pay_status'] = isset($order['pay_status'])? intval($order['pay_status']) : 10; // } } $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); } }