| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- namespace App\Services;
- use App\Services\BaseService;
- use App\Models\BalanceLog;
- // 余额额变动记录
- class BalanceLogService extends BaseService
- {
- public static $RW = ['充值','提现','人工充值','人工扣款','三方提现'];
- /**
- * @description: 模型
- * @return {string}
- */
- public static function model(): string
- {
- return BalanceLog::class;
- }
- /**
- * @description: 枚举
- * @return {*}
- */
- public static function enum(): string
- {
- return '';
- }
- /**
- * @description: 获取查询条件
- * @param {array} $search 查询内容
- * @return {array}
- */
- public static function getWhere(array $search = []): array
- {
- $where = [];
- if (isset($search['coin']) && !empty($search['coin'])) {
- $where[] = ['coin', '=', $search['coin']];
- }
- if (isset($search['net']) && !empty($search['net'])) {
- $where[] = ['net', '=', $search['net']];
- }
- if (isset($search['address']) && !empty($search['address'])) {
- $where[] = ['address', '=', $search['address']];
- }
- if (isset($search['id']) && !empty($search['id'])) {
- $where[] = ['id', '=', $search['id']];
- }
- if (isset($search['member_id']) && !empty($search['member_id'])) {
- $where[] = ['member_id', '=', $search['member_id']];
- }
- return $where;
- }
- /**
- * @description: 查询单条数据
- * @param array $search
- * @return \App\Models\Coin|null
- */
- public static function findOne(array $search): ?BalanceLog
- {
- return self::model()::where(self::getWhere($search))->first();
- }
- /**
- * @description: 查询所有数据
- * @param array $search
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function findAll(array $search = [])
- {
- return self::model()::where(self::getWhere($search))->get();
- }
- /**
- * @description: 分页查询
- * @param array $search
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
- */
- public static function paginate(array $search = [])
- {
- $limit = isset($search['limit']) ? $search['limit'] : 15;
- $paginator = self::model()::where(self::getWhere($search))
- ->when(isset($search['change_types']) && !empty($search['change_types']), function ($query) use ($search) {
- return $query->whereIn('change_type', $search['change_types']);
- })
- ->orderBy('updated_at', 'desc')
- ->paginate($limit);
- return ['total' => $paginator->total(), 'data' => $paginator->items()];
- }
- /**
- * @description: 生成资金变动日志
- * @param {*} $memberId
- * @param {*} $amount
- * @param {*} $before_balance
- * @param {*} $after_balance
- * @param {*} $change_type
- * @param {*} $related_id
- * @param {*} $remark
- * @return {*}
- */
- public static function addLog($memberId, $amount, $before_balance, $after_balance, $change_type, $related_id, $remark, $room_id = null)
- {
- $data = [];
- $data['member_id'] = $memberId;
- $data['amount'] = $amount;
- $data['before_balance'] = $before_balance;
- $data['after_balance'] = $after_balance;
- $data['change_type'] = $change_type;
- $data['related_id'] = $related_id;
- $data['remark'] = $remark;
- if ($room_id) $data['room_id'] = $room_id;
- return self::model()::create($data);
- }
- /**
- * @description: 获取今日流水
- * @param int $memberId
- * @param string|null $date
- * @return {*}
- */
- public static function getTodayFlowing($memberId, $date = null)
- {
- if (!$date) {
- $date = date('Y-m-d');
- }
- $startTime = date('Y-m-d H:i:s', strtotime($date . ' 00:00:00'));
- $endTime = date('Y-m-d H:i:s', strtotime($date . ' 23:59:59'));
- $flow = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '投注')
- ->sum('amount');
- $refund = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '返水')
- ->sum('amount');
- $profit = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '中奖') //嬴正数 输负数
- ->sum('amount');
- $walletInfo = WalletService::model()::where('member_id', $memberId)->first();
- $text = '';
- $text .= "当日流水: " . number_format((0-$flow), 2) . "\n";
- $text .= "返水额度: " . number_format($refund, 2) . "\n";
- $text .= "当日盈亏: " . number_format(($profit + $refund + $flow), 2) . "\n";
- $text .= "余额: " . number_format($walletInfo['available_balance'], 2) . "\n";
- return [
- 'chat_id' => $memberId,
- 'text' => $text
- ];
- }
- public static function getFlowingHistory($memberId, $messageId = null, $page = 1, $limit = 5)
- {
- $dateTime = date('Y-m-d 00:00:00');
- $list = [];
- for ($i = 0; $i < $limit; $i++) {
- $newIndex = ($page - 1) * $limit + $i;
- $date = date('Y-m-d', strtotime($dateTime . " -{$newIndex} day"));
- $startTime = date('Y-m-d H:i:s', strtotime($date . ' 00:00:00'));
- $endTime = date('Y-m-d H:i:s', strtotime($date . ' 23:59:59'));
- $flow = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '投注')
- ->sum('amount');
- $refund = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '返水')
- ->sum('amount');
- $profit = self::model()::where('member_id', $memberId)
- ->whereBetween('created_at', [$startTime, $endTime])
- ->where('change_type', '中奖') //嬴正数 输负数
- ->sum('amount');
- $list[] = [
- 'date' => $date,
- 'flow' => number_format($flow, 2),
- 'refund' => number_format($refund, 2),
- 'profit' => number_format(($profit + $refund + $flow), 2)
- ];
- }
- // $startTime = date('Y-m-d H:i:s',strtotime($date . ' 00:00:00'));
- // $endTime = date('Y-m-d H:i:s',strtotime($date . ' 23:59:59'));
- // $list = self::model()::where('member_id', $memberId)
- // ->whereBetween('created_at', [$startTime, $endTime])
- // ->orderBy('created_at', 'desc')
- // ->get();
- $text = "流水历史 \n";
- foreach ($list as $item) {
- $text .= "---------------------\n";
- $text .= "日期:{$item['date']} \n";
- $text .= "流水: {$item['flow']} \n";
- $text .= "返水: {$item['refund']} \n";
- $text .= "盈利: {$item['profit']} \n";
- }
- $keyboard = [[
- ['text' => "👇下一页", 'callback_data' => "FlowingHistoryPage@@" . ($page + 1)]
- ]];
- if ($page > 1) {
- array_unshift($keyboard[0], ['text' => "👆上一页", 'callback_data' => "FlowingHistoryPage@@" . ($page - 1)]);
- }
- return [
- 'chat_id' => $memberId,
- 'text' => $text,
- 'message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
- ];
- }
- }
|