| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 | 
							- <?php
 
- namespace App\Services;
 
- use App\Services\BaseService;
 
- use App\Models\User;
 
- use Illuminate\Support\Facades\DB;
 
- use Illuminate\Support\Collection;
 
- use Illuminate\Support\Facades\Cache;
 
- class UserService extends BaseService
 
- {
 
-     /**
 
-      * @description: 模型
 
-      * @return {string}
 
-      */
 
-     public static function model(): string
 
-     {
 
-         return User::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['id']) && !empty($search['id'])) {
 
-             $where[] = ['id', '=', $search['id']];
 
-         }
 
-         if (isset($search['game_id']) && !empty($search['game_id'])) {
 
-             $where[] = ['game_id', '=', $search['game_id']];
 
-         }
 
-         if (isset($search['member_id']) && !empty($search['member_id'])) {
 
-             $where[] = ['member_id', '=', $search['member_id']];
 
-         }
 
-         if (isset($search['first_name']) && !empty($search['first_name'])) {
 
-             $where[] = ['first_name', '=', $search['first_name']];
 
-         }
 
-         if (isset($search['username']) && !empty($search['username'])) {
 
-             $where[] = ['username', '=', $search['username']];
 
-         }
 
-         if (isset($search['like_first_name']) && !empty($search['like_first_name'])) {
 
-             $where[] = ['first_name', 'like', "%" . $search['like_first_name'] . "%"];
 
-         }
 
-         return $where;
 
-     }
 
-     /**
 
-      * @description: 查询单条数据
 
-      * @param array $search
 
-      * @return \App\Models\User|null
 
-      */
 
-     public static function findOne(array $search): ?User
 
-     {
 
-         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))->with('wallet:user_id,member_id,address,available_balance')->paginate($limit);
 
-         return ['total' => $paginator->total(), 'data' => $paginator->items()];
 
-     }
 
-     //设置游戏ID
 
-     public function setGameID($chatId, $gameId)
 
-     {
 
-         $gameId = trim($gameId);
 
-         if(!$gameId)return ['chat_id' => $chatId, 'text' => '❌游戏ID设置失败,请输入正确的游戏ID'];
 
-         if (User::where('game_id', $gameId)->where('member_id', '<>', $chatId)->first()) {
 
-             return ['chat_id' => $chatId, 'text' => '❌游戏ID设置失败,游戏ID已绑定其他用户'];
 
-         }
 
-         $user = User::where('member_id', $chatId)->first();
 
-         $user->game_id = $gameId;
 
-         $user->save();
 
-         return ['chat_id' => $chatId, 'text' => "✅ 游戏ID设置成功\n游戏ID:{$gameId}"];
 
-     }
 
- }
 
 
  |