You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

452 lines
16 KiB

import 'dart:convert';
import 'dart:io';
import 'package:dio/dio.dart';
// import 'package:dio_log/interceptor/dio_log_interceptor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:huixiang/retrofit/data/day_count.dart';
import 'package:huixiang/retrofit/data/order_trend.dart';
import 'package:huixiang/retrofit/data/vip_counts_info.dart';
import 'package:retrofit/retrofit.dart';
import '../login/captcha/click_word_captcha.dart';
import 'data/add_vip_info.dart';
import 'data/balance_change_list.dart';
import 'data/balance_consumption_ranking_list.dart';
import 'data/base_data.dart';
import 'data/bus_recharge_list.dart';
import 'data/business_goods.dart';
import 'data/business_order_detail_info.dart';
import 'data/business_order_list.dart';
import 'data/business_store_list.dart';
import 'data/business_vip_list.dart';
import 'data/clerk_manage_list.dart';
import 'data/day_flow_list.dart';
import 'data/goods_category_list.dart';
import 'data/goods_type_sales_list.dart';
import 'data/order_user_detail.dart';
import 'data/phone_query_member_info.dart';
import 'data/popular_sales_list.dart';
import 'data/product_group_list.dart';
import 'data/recharge_flow_list.dart';
import 'data/refund_reason_list.dart';
import 'data/service_bug_list.dart';
import 'data/single_sales_list.dart';
import 'data/store_time_info_list.dart';
import 'data/store_total_money_info.dart';
import 'data/tenant_info.dart';
import 'data/tenant_package_calculate_details.dart';
import 'data/tenant_package_list.dart';
import 'data/ticket_details.dart';
import 'data/ticket_record.dart';
import 'data/ticket_show.dart';
import 'data/ticket_stats_list.dart';
import 'data/trade_summary_list.dart';
import 'data/upload_result.dart';
import 'data/user_info_edit.dart';
import 'data/vip_record_details_list.dart';
part 'business_api.g.dart';
///本地
const localBaseUrl = "http://admin-api.test.yixinhuixiang.com/";
///测试
// const localBaseUrl = "http://pos-test.admin.api.lotus-wallet.com/";
///线上
const serviceBaseUrl = "http://pos.tenant.lotus-wallet.com/test-merchant/";
@RestApi(baseUrl: localBaseUrl)
abstract class BusinessApiService {
factory BusinessApiService(
Dio dio, {
String baseUrl,
BuildContext context,
String token,
bool showLoading = false,
String url,
String tenant,
String storeId,
bool showErrorToast = true,
bool pay = false,
}) {
Map<String, dynamic> headers =
(token == null || token == "") ? {} : {'token': "Bearer $token"};
if (pay == true) {
headers["Environment"] = "app";
}
if (tenant != null && tenant != "") {
headers["tenant"] = tenant;
}
if (storeId != null && storeId != "") {
headers["store-id"] = storeId;
}
if (kReleaseMode) baseUrl = serviceBaseUrl;
if (url != null) baseUrl = url;
dio.options = BaseOptions(
connectTimeout: 30000,
receiveTimeout: 30000,
headers: headers,
responseType: ResponseType.json,
baseUrl: baseUrl,
);
// dio.interceptors.add(DioLogInterceptor());
dio.interceptors.add(
InterceptorsWrapper(onRequest: (RequestOptions options) {
debugPrint("\n======================= 请求数据 =======================");
debugPrint("method = ${options.method.toString()}");
debugPrint("url = ${options.uri.toString()}");
debugPrint("headers = ${options.headers}");
if (showLoading && !EasyLoading.isShow) {
//是否显示loading
EasyLoading.show(status: "正在加载...");
}
if (options.data is FormData) {
debugPrint("params data = FormData");
} else {
debugPrint("params data = ${jsonEncode(options.data)}");
}
debugPrint("params queryParameters = ${options.queryParameters}");
}, onResponse: (Response response) {
if (showLoading && EasyLoading.isShow) EasyLoading.dismiss();
debugPrint("\n======================= 响应数据开始 =======================");
debugPrint("code = ${response.statusCode}");
p(jsonEncode(response.data));
// debugPrint(jsonEncode(response.data), wrapWidth: response.data.toString().length * 10);
Map map = response.data;
// if (map["code"] != 0) {
// EasyLoading.dismiss();
// }
// if (map["code"] == 40005 || map["code"] == 40001) {
// if (!LoginTipsDialog().isShow) {
// print("show: ${LoginTipsDialog().isShow}");
// LoginTipsDialog().show(context);
// }
// }
if (showErrorToast &&
map["code"] == 404 &&
(map["msg"] ?? map["message"]) != null) {
SmartDialog.showToast(map["msg"] ?? map["message"],
alignment: Alignment.center);
}
debugPrint("======================= 响应数据结束 =======================\n");
}, onError: (DioError e) {
if (EasyLoading.isShow) EasyLoading.dismiss();
// SmartDialog.showToast("网络错误,请切换网络或稍后再试!", alignment: Alignment.center);
// SmartDialog.showToast(AppUtils.dioErrorTypeToString(e.type),
// alignment: Alignment.center);
debugPrint("\n======================= 错误响应数据 =======================");
debugPrint("type = ${e.type}");
debugPrint("message = ${e.message}");
debugPrint("\n");
}),
);
return _BusinessApiService(dio, baseUrl: baseUrl);
}
void dispose();
static void p(String msg) {
//因为String的length是字符数量不是字节数量所以为了防止中文字符过多,
// 把4*1024的MAX字节打印长度改为1000字符数
int maxStrLength = 900;
//大于1000时
while (msg.length > maxStrLength) {
debugPrint(msg.substring(0, maxStrLength), wrapWidth: maxStrLength);
msg = msg.substring(maxStrLength);
}
//剩余部分
debugPrint(msg, wrapWidth: maxStrLength);
}
/// 获取认证token/管理系统登录
@POST("anno/token")
Future<BaseData> annoToken(@Body() Map<String, dynamic> param);
///加载验证码
@POST("/captcha/get")
Future<ClickWordCaptchaModel> captchaGet(@Body() Map<String, dynamic> param);
///校验验证码
@POST("/captcha/check")
Future<bool> captchaCheck(@Body() Map<String, dynamic> param);
///发送验证码
@POST("auth/sendVerify")
Future<BaseData<dynamic>> busSendVerify(@Body() Map<String, dynamic> param);
///注册
@POST("auth/tenantAppLogin")
Future<BaseData> tenantAppLogin(@Body() Map<String, dynamic> param);
///找回密码
@POST("auth/tenantUserChangePsd")
Future<BaseData> tenantUserChangePsd(@Body() Map<String, dynamic> param);
/// 当日各种金额统计
@POST("comprehensiveReport/getDayCounts")
Future<BaseData<DayCount>> getDayCounts(@Body() Map<String, dynamic> param);
///商家概览/热销榜单,当天传0,昨天传1,最近7天传7,最近30天传30
@GET("dashBoard/store/?offsetDay={offsetDay}")
Future<BaseData<PopularSalesList>> popularList(
@Path("offsetDay") String offsetDay);
///生意总览/订单量趋势
@GET("trend/orderTrend")
Future<BaseData<List<OrderTrend>>> orderTrend();
///会员数量统计/用户概览
@GET("largeScreenReport/getDayCounts?date={date}")
Future<BaseData<VipCountsInfo>> vipCounts(@Path("date") String date);
///今日流水/isMonth=0(当月数据),isMonth=1(当日数据)
@GET("dashBoard/order?yearMonth={yearMonth}&isMonth={isMonth}")
Future<BaseData<List<DayFlowList>>> dayFlow(
@Path("yearMonth") String yearMonth, @Path("isMonth") String isMonth);
///每日单品销量/单品销量报表
@POST("audit/salesLeaderboard")
Future<BaseData<List<SingleSalesList>>> singleSales(
@Body() Map<String, dynamic> param);
///各类商品销售状况统计/商品种类销售数据
@POST("audit/allKindsSalesStatistics")
Future<BaseData<List<GoodsTypeSalesList>>> goodsSalesList(
@Body() Map<String, dynamic> param);
///经营分析/查询范围 day week month custom
@POST("largeScreenReport/saleBusinessAnalysis")
Future<BaseData<TradeSummaryList>> saleBusinessAnalysis(
@Body() Map<String, dynamic> param);
///订单列表
@POST("order/findAdminOrderList")
Future<BaseData<BusinessOrderList>> findAdminOrderList(
@Body() Map<String, dynamic> param);
///订单详情
@POST("order/getAdminOrderDetail")
Future<BaseData<BusinessOrderDetailInfo>> getAdminOrderDetail(
@Body() Map<String, dynamic> param);
///退款原因列表
@POST("reason/page")
Future<BaseData<RefundReasonList>> refundReason(
@Body() Map<String, dynamic> param);
///申请退款
@POST("order/refundOrder")
Future<BaseData> refundOrder(@Body() Map<String, dynamic> param);
///商品分页列表查询/商品分组列表
@POST("productGroup/page")
Future<BaseData<ProductGroupList>> productGroup(
@Body() Map<String, dynamic> param);
///后台查询商品列表/商品列表
@POST("product/findAdminProductListNew")
Future<BaseData<BusinessGoods>> findAdminProductLis(
@Body() Map<String, dynamic> param);
///修改密码
@PUT("user")
Future<BaseData> modifyPassword(@Body() Map<String, dynamic> param);
///商品上下架
@POST("product/putStatus")
Future<BaseData> goodsUpdate(@Body() Map<String, dynamic> param);
///商品删除
@POST("product/delProduct")
Future<BaseData> delProduct(@Body() Map<String, dynamic> param);
///新增或修改商品分组/商品分类-新增分类/编辑分类
@POST("productGroup/saveProductGroup")
Future<BaseData> saveProductGroup(@Body() Map<String, dynamic> param);
///删除分组分类
@POST("productGroup/delProductCategory")
Future<BaseData> delProductCategory(@Body() Map<String, dynamic> param);
///门店设置-列表
@GET(
"store/getStoreList?tenantCode={tenantCode}&pageIndex={pageIndex}&pageSize={pageSize}")
Future<BaseData<BusinessStoreList>> getStoreList(
@Path("tenantCode") String tenantCode,
@Path("pageIndex") String pageIndex,
@Path("pageSize") String pageSize);
///编辑门店信息
@PUT("store")
Future<BaseData> saveStoreInfo(@Body() Map<String, dynamic> param);
///文件上传
@POST("file/upload")
@MultiPart()
Future<BaseData<UploadResult>> upload(
@Part(name: "file") File data, @Part(name: "folderId") int folderId);
///批量核销
@POST("ticket/wipedBatchs")
Future<BaseData> wipedBatchs(@Body() String param);
///商品排序/一键置顶
@POST("product/productSortTop")
Future<BaseData> productSortTop(@Body() Map<String, dynamic> param);
///票券详情
@GET("ticket/code/{code}")
Future<BaseData<TicketDetails>> ticketCode(@Path("code") String code);
///票券列表
@POST("ticket/showList")
Future<BaseData<TicketShow>> showList(@Body() Map<String, dynamic> param);
///票券核销记录
@POST("ticket/wipedRecord")
Future<BaseData<TicketRecord>> wipedRecord(
@Body() Map<String, dynamic> param);
///票券核销统计
@POST("ticket/wipedStats")
Future<BaseData<List<TicketStatsList>>> wipedStats(
@Body() Map<String, dynamic> param);
///会员列表
@POST("member/page")
Future<BaseData<BusinessVipList>> vipDataList(
@Body() Map<String, dynamic> param);
///会员充值流水
@POST("audit/memberSourceRechargeDetial")
Future<BaseData<RechargeFlowList>> rechargeFlow(
@Body() Map<String, dynamic> param);
///会员余额变动
@POST("member/getTenantMemberBill")
Future<BaseData<BalanceChangeList>> getTenantMemberBill(
@Body() Map<String, dynamic> param);
///预约设置/店铺信息开启关闭时间
@GET("store/storeOpenTime/{storeId}")
Future<BaseData<StoreTimeInfoList>> storeOpenTime(
@Path("storeId") String storeId);
///预约信息保存
@POST("product/updateSubscribe")
Future<BaseData> updateSubscribe(@Body() Map<String, dynamic> param);
///确认扣款
@POST("order/balancePay")
Future<BaseData> balancePay(@Body() Map<String, dynamic> param);
///订单列表获取用户金额详情
@GET("order/getOrderUserDetail?orderId={orderId}")
Future<BaseData<OrderUserDetail>> getOrderUserDetail(
@Path("orderId") String storeId);
///根据手机号查询会员信息
@POST("member/queryMemberInfo")
Future<BaseData<PhoneQueryMemberInfo>> queryMemberInfo(
@Body() Map<String, dynamic> param);
///会员充值列表
@POST("rechargePreferential/get")
Future<BaseData<BusRechargeList>> getRechargePreferential(
@Body() Map<String, dynamic> param);
///会员充值支付
@POST("member/posMemberRecharge")
Future<BaseData> posMemberRecharge(@Body() Map<String, dynamic> param);
///充值订单手动查询
@POST("member/manualQuery")
Future<BaseData> manualQuery(@Body() Map<String, dynamic> param);
///新增会员
@GET("member/createMemberSourceByMobile?mobile={mobile}&nickName={nickName}")
Future<BaseData<AddVipInfo>> createMemberSourceByMobile(
@Path("mobile") String mobile, @Path("nickName") String nickName);
///店员列表
@POST("user/userPage")
Future<BaseData<ClerkManageList>> clerkList(
@Body() Map<String, dynamic> param);
///添加新店员,店员信息编辑
@POST("user")
Future<BaseData<UserInfoEdit>> userEdit(@Body() Map<String, dynamic> param);
///删除会员
@DELETE("user?ids[]={ids}")
Future<BaseData> delUser(@Path("ids") String ids);
///修改用户信息
@PUT("user")
Future<BaseData<UserInfoEdit>> userModify(@Body() Map<String, dynamic> param);
///会员余额统计/消费排名
@POST("dashBoard/storeMoney")
Future<BaseData<BalanceConsumptionRankingList>> storeMoney(
@Body() Map<String, dynamic> param);
///会员余额统计(总会员数,总余额数)查询/消费排名(消费会员数量,销售金额)查询
@POST("dashBoard/storeTotalMoney")
Future<BaseData<StoreTotalMoneyInfo>> storeTotalMoney(
@Body() Map<String, dynamic> param);
///收银台创建直付订单
@POST("order/createOrder")
Future<BaseData> createOrder(@Body() Map<String, dynamic> param);
///收银台支付
@POST("order/prePayOrder")
Future<BaseData> prePayOrder(@Body() Map<String, dynamic> param);
///收银台直付订单手动查询
@GET("order/queryOrder/{orderId}?login={login}")
Future<BaseData> queryCashierOrder(
@Path("orderId") String orderId, @Path("login") bool login);
///会员详情-查询会员消费/充值记录
@POST("member/getMemberSourceBillDetials")
Future<BaseData<VipRecordDetailsList>> getMemberSourceBillDetails(
@Body() Map<String, dynamic> param);
///新建商品
@POST("product/save")
Future<BaseData> productSave(@Body() Map<String, dynamic> param);
///分类查询
@GET("productCategory/findCategoryListByDepth/1")
Future<BaseData<List<GoodsCategoryList>>> findCategoryListByDepth();
///服务套餐列表
@GET("tenantApply/tenantPackageList")
Future<BaseData<List<TenantPackageList>>> tenantPackage();
///服务套餐包优惠计算
@POST("tenantApply/tenantPackageCalculate")
Future<BaseData<TenantPackageCalculateDetails>> tenantPackageCalculate(
@Body() Map<String, dynamic> param);
///服务套餐支付
@POST("tenantApply/tenantApplyPay")
Future<BaseData> tenantApplyPay(@Body() Map<String, dynamic> param);
///查询商户信息
@GET("tenant/tenantInfo/{tenantId}")
Future<BaseData<TenantInfo>> tenantInfo(@Path("tenantId") String tenantId);
///服务购买记录
@POST("tenantPackage/packageBuyList")
Future<BaseData<ServiceBugList>> packageBuyList(@Body() Map<String, dynamic> param);
}