| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 | 
							- <?php
 
- namespace App\Services;
 
- use App\Services\BaseService;
 
- use App\Models\BalanceLog;
 
- // 余额额变动记录
 
- class BalanceLogService extends BaseService
 
- {
 
-     /**
 
-      * @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))
 
-             ->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($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
 
-         ];
 
-     }
 
- }
 
 
  |