book_set_time_model.dart
5.2 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
148
149
150
151
152
153
154
155
156
157
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:one_key/constant/constant.dart';
import 'package:one_key/models/get_seller_info_model.dart';
import 'package:one_key/models/seller_info.dart';
import 'package:one_key/models/set_seller_info_model.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/user_model.dart';
import 'package:one_key/utils/utils.dart';
import 'package:provider/provider.dart';
class BookSetTimeModel with ChangeNotifier {
//构造函数,初始化
BookSetTimeModel() {}
///获取某个商家下所有服务员信息 **** 取得某个商家的早市、午市、晚市营业时间
Future<SunSellerInfoModel?> getManagersInfo(BuildContext context) async {
try {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String?> params = {
"seller_id": userModel.user!.sellerid,
"seller_openid": userModel.user!.openid
};
BaseResp<Map<String, dynamic>?> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.sellerinfo,
data: params);
SunSellerInfoModel? itemModel;
if (baseResp.code == Constant.status_success) {
if (int.parse(baseResp.status!) != Constant.status_success) {
Utils.showToast(baseResp.msg ?? "");
return itemModel;
}
if (baseResp.responseData!['data'] != null) {
itemModel = SellerInfoModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
} else {
Utils.showToast(baseResp.msg ?? "");
}
return itemModel;
}
return itemModel;
} catch (error) {
print(error.toString());
}
;
return null;
}
///根据商家ID修改商家信息
Future<SetSellerInfoSunModel?> setSellerInfoById(
BuildContext context, Map daily) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String?> params = {
"id": userModel.user!.sellerid,
"daily": jsonEncode(daily)
};
try {
BaseResp<Map<String, dynamic>?> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.set_seller_info,
data: params);
SetSellerInfoSunModel? itemModel;
if (baseResp.code == Constant.status_success) {
if (int.parse(baseResp.status!) != Constant.status_success) {
Utils.showToast(baseResp.msg ?? "");
return itemModel;
}
if (baseResp.responseData!['data'] != null) {
itemModel = SetSellerInfoModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
} else {
Utils.showToast(baseResp.msg ?? "");
}
return itemModel;
}
} catch (error) {
print(error.toString());
}
return null;
}
///根据商家ID获取商家信息
Future<GetSellerInfoSunModel?> getSellerById(BuildContext context) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, String?> params = {
"sellerid": userModel.user!.sellerid,
};
try {
BaseResp<Map<String, dynamic>?> baseResp = await DioUtil()
.request<Map<String, dynamic>>(
context, Method.post, HttpUrl.get_seller_info,
data: params);
GetSellerInfoSunModel? itemModel;
if (baseResp.code == Constant.status_success) {
if (int.parse(baseResp.status!) != Constant.status_success) {
Utils.showToast(baseResp.msg ?? "");
return itemModel;
}
if (baseResp.responseData!['data'] != null) {
itemModel = GetSellerInfoModel.fromJson(
baseResp.responseData as Map<String, dynamic>)
.data;
} else {
Utils.showToast(baseResp.msg ?? "");
}
return itemModel;
}
} catch (error) {
print(error.toString());
}
return null;
}
///在线预订配置-接单时间
Future<bool> setReOrderTime(
BuildContext context, String? start, String? end) async {
UserModel userModel = Provider.of<UserModel>(context, listen: false);
Map<String, dynamic> params = {
"sellerid": int.parse(userModel.user!.sellerid!),
"start": start,
'end': end
};
try {
BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
context, Method.post, HttpUrl.set_order_time,
data: params);
if (baseResp.code == Constant.status_success) {
if (int.parse(baseResp.status!) != Constant.status_success) {
Utils.showToast(baseResp.msg ?? "");
return false;
}
if (baseResp.responseData!['ret'] == 200) {
// if (baseResp.responseData['data'] == 0) {
return true;
// } else {
// return false;
// }
} else {
Utils.showToast(baseResp.msg ?? "");
return false;
}
}
return false;
} catch (error) {
print(error.toString());
return false;
}
}
}