my_model.dart
4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/constant/error.dart';
import 'package:one_key/constant/state.dart';
import 'package:one_key/models/integral_model.dart';
import 'package:one_key/models/sms_info.dart';
import 'package:one_key/net/base_resp.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/net/http_url.dart';
import 'package:one_key/provider/SmsModel.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/utils/time_machine_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
class MyModel extends ChangeNotifier {
String smsInfo = '';
IntegralSunModel integralSunModel;
String reserveTotal = '';
PageState pageState = PageState.Loading;
/// 短信余量查询及套餐查询接口
Future<SmsInfoData> getSmsInfo(BuildContext context,
{bool selfDismiss = false}) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String> params = {"seller_id": userModel.user.sellerid};
try {
BaseResp<Map<String, dynamic>> baseResp = await DioUtil()
.request<Map<String, dynamic>>(context, Method.post, HttpUrl.sms_info,
data: params, showLoading: false, selfDismiss: selfDismiss)
.catchError((error) {
print(error.toString());
pageState = PageState.ConnectivityError;
});
SmsInfoData data;
if (baseResp?.code == Constant.status_success) {
SmsInfo sms = SmsInfo.fromJson(baseResp.responseData);
if (sms.ret == 200) {
data = sms.data;
smsInfo = data.lastNum;
pageState = PageState.Success;
} else {
pageState = PageState.Empty;
Utils.showToast(sms.msg ?? '');
}
} else {
print('查询失败');
}
notifyListeners();
return data;
} catch (error) {
if (error is MyError) {
switch (error.type) {
case 1:
print('错误');
break;
case 2:
print('超时');
break;
default:
print('错误');
break;
}
}
}
}
/// 获取客户经理积分列表
Future<IntegralSunModel> getMyIntegral(BuildContext context) async {
Map<String, String> params = {
"uid": Provider.of<UserModel>(context, listen: false).user.openid
};
try {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(context, Method.post, HttpUrl.get_integral_list,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
});
if (baseResp?.code == Constant.status_success) {
integralSunModel = IntegralModel.fromJson(baseResp.responseData).data;
print(integralSunModel);
} else {
print('查询失败');
}
notifyListeners();
return integralSunModel;
} catch (error) {
if (error is MyError) {
switch (error.type) {
case 1:
print('错误');
break;
case 2:
print('超时');
break;
default:
print('错误');
break;
}
}
}
}
/// 获取商家时间区间内订单数量
getSellerReserveTotal(BuildContext context) async {
Map<String, String> dateMap = TimeMachineUtil.getMonthDate(0);
Map<String, String> params = {
"sid": Provider.of<UserModel>(context, listen: false).user.sellerid,
"stime":
((int.parse(dateMap['startDateStamp']) / 1000).floor()).toString(),
"etime": ((int.parse(dateMap['endDateStamp']) / 1000).floor()).toString(),
};
print(params);
try {
BaseResp<dynamic> baseResp = await DioUtil()
.request<dynamic>(
context, Method.post, HttpUrl.get_seller_reserve_total,
data: params, showLoading: false)
.catchError((error) {
print(error.toString());
});
if (baseResp?.code == Constant.status_success) {
reserveTotal = baseResp.data;
} else {}
notifyListeners();
} catch (error) {
if (error is MyError) {
switch (error.type) {
case 1:
print('错误');
break;
case 2:
print('超时');
break;
default:
print('错误');
break;
}
}
}
}
}