import 'package:autosos_flutter/api/_api_client.dart'; import 'package:autosos_flutter/model/base_response.dart'; import 'package:autosos_flutter/model/misc.dart'; import 'package:autosos_flutter/model/payment.dart'; import 'package:autosos_flutter/model/user.dart'; /// 用户 / 认证 / 我的 相关 API class UserApi { static final UserApi instance = UserApi._(); UserApi._(); final _http = ApiClient.instance.http; // ===== 登录相关 ===== /// 账号密码登录 Future> login({ required String username, required String password, String? code, String? cid, String? wxOpenid, String? wxUnionid, }) async { final r = await _http.post('/v2/auth/get-access-token', { 'type': 1, 'username': username, 'password': password, 'code': code ?? '', 'getui_cid': cid ?? '', 'wx_openid': wxOpenid ?? '', 'wx_unionid': wxUnionid ?? '', }); return BaseResponse.fromJson(r as Map, (d) => LoginToken.fromJson(d as Map)); } /// 发送短信验证码 Future> sendSms(String mobile) async { final r = await _http.post('/v2/auth/send-sms', {'mobile': mobile}); return BaseResponse.fromJson(r as Map, (d) => SmsResult.fromJson(d as Map)); } /// 手机验证码登录 Future> loginBySms({ required String mobile, required String code, String? cid, }) async { final r = await _http.post('/v2/auth/login-by-sms', { 'mobile': mobile, 'code': code, 'cid': cid, }); return BaseResponse.fromJson(r as Map, (d) => LoginToken.fromJson(d as Map)); } /// 微信登录(前端通过 fluwx 拿到 code,调后端) Future> loginByWx({ required String wxCode, String? cid, }) async { final r = await _http.post('/v2/auth/login-by-wx', { 'wx_code': wxCode, 'cid': cid, }); return BaseResponse.fromJson(r as Map, (d) => LoginToken.fromJson(d as Map)); } /// 绑定手机号 Future> bindPhone({ required String mobile, required String code, }) async { final r = await _http.post('/v2/auth/bind-phone', { 'mobile': mobile, 'code': code, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 绑定微信 Future> bindWx({ required String wxCode, required String mobile, required String code, }) async { final r = await _http.post('/v2/auth/bind-wx', { 'wx_code': wxCode, 'mobile': mobile, 'code': code, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 退出登录 Future> logout() async { final r = await _http.post('/v2/auth/logout'); return BaseResponse.fromJson(r as Map, (d) => d as bool); } // ===== 我的 ===== /// 用户信息 Future> info() async { final r = await _http.get('/v2/user/info'); return BaseResponse.fromJson(r as Map, (d) => UserInfo.fromJson(d as Map)); } /// 完善资料 Future> perfectInfo(Map data) async { final r = await _http.post('/v2/user/perfect', data); return BaseResponse.fromJson(r as Map, (d) => UserInfo.fromJson(d as Map)); } /// 上传身份证照片 Future>> uploadIdCards(List paths) async { final r = await _http.post('/v2/user/upload-id', {'paths': paths}); return BaseResponse.fromJson(r as Map, (d) => (d as List).cast()); } /// 个人认证 Future> authPersonal({ required String name, required String idCard, required String idCardFront, required String idCardBack, }) async { final r = await _http.post('/v2/user/auth-personal', { 'name': name, 'id_card': idCard, 'id_card_front': idCardFront, 'id_card_back': idCardBack, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 企业认证 Future> authEnterprise({ required String companyName, required String licenseNo, required String licenseImg, String? legalPerson, String? legalIdCard, String? legalIdFront, String? legalIdBack, }) async { final r = await _http.post('/v2/user/auth-enterprise', { 'company_name': companyName, 'license_no': licenseNo, 'license_img': licenseImg, 'legal_person': legalPerson, 'legal_id_card': legalIdCard, 'legal_id_front': legalIdFront, 'legal_id_back': legalIdBack, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 司机认证 Future> authDriver({ required String driverNo, required String driverLicense, String? drivingLicenseFront, String? drivingLicenseBack, }) async { final r = await _http.post('/v2/user/auth-driver', { 'driver_no': driverNo, 'driver_license': driverLicense, 'driving_license_front': drivingLicenseFront, 'driving_license_back': drivingLicenseBack, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 提现申请 Future> applyWithdrawal({ required double amount, required String bankAccount, String? realName, }) async { final r = await _http.post('/v2/user/withdraw', { 'amount': amount, 'bank_account': bankAccount, 'real_name': realName, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 提现记录 Future>> withdrawalRecords({ int page = 1, int size = 20, }) async { final r = await _http.get('/v2/user/withdraw-records', { 'page': page, 'size': size, }); return BaseResponse.fromJson(r as Map, (d) => PageResult.fromJson(d as Map, (e) => WithdrawalRecord.fromJson(e as Map))); } /// 金额明细 Future>> amountList({ int page = 1, int size = 20, }) async { final r = await _http.get('/v2/user/amount-list', { 'page': page, 'size': size, }); return BaseResponse.fromJson(r as Map, (d) => PageResult.fromJson(d as Map, (e) => AmountItem.fromJson(e as Map))); } /// 充值 Future> recharge({ required double amount, required String payMethod, }) async { final r = await _http.post('/v2/user/recharge', { 'amount': amount, 'pay_method': payMethod, }); return BaseResponse.fromJson(r as Map, (d) => Recharge.fromJson(d as Map)); } /// 反馈 Future> submitFeedback({ required String content, String? contact, List? images, }) async { final r = await _http.post('/v2/user/feedback', { 'content': content, 'contact': contact, 'images': images, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 消息中心 Future>> messages({ int page = 1, int size = 20, }) async { final r = await _http.get('/v2/user/messages', { 'page': page, 'size': size, }); return BaseResponse.fromJson(r as Map, (d) => PageResult.fromJson(d as Map, (e) => MessengerItem.fromJson(e as Map))); } /// 标记消息已读 Future> readMessage(int id) async { final r = await _http.post('/v2/user/message/read', {'id': id}); return BaseResponse.fromJson(r as Map, (d) => d as bool); } /// 服务类型列表 Future>> serviceTypes() async { final r = await _http.get('/v2/order/service-types'); return BaseResponse.fromJson(r as Map, (d) => (d as List).map((e) => ServiceType.fromJson(e as Map)).toList()); } /// 检查更新 Future> checkUpdate() async { final r = await _http.get('/v2/app/check-update'); return BaseResponse.fromJson(r as Map, (d) => AppUpdate.fromJson(d as Map)); } /// 心跳 Future> heartbeat({ double? lat, double? lng, required int onlineTime, }) async { final r = await _http.post('/v2/user/heartbeat', { 'lat': lat, 'lng': lng, 'online_time': onlineTime, }); return BaseResponse.fromJson(r as Map, (d) => d as bool); } }