Commit 4df36adf313514785534956fd3ea12b427222bf2

Authored by weixin_45529955
1 parent d8aa8c04

买单前送消费金 OK

@@ -36,6 +36,7 @@ class ReturnMoneySunModel { @@ -36,6 +36,7 @@ class ReturnMoneySunModel {
36 String? isTogether; 36 String? isTogether;
37 TogetherJsonModel? togetherJson; 37 TogetherJsonModel? togetherJson;
38 String? cdate; 38 String? cdate;
  39 + BeforePayJson? beforePayJson;
39 40
40 ReturnMoneySunModel( 41 ReturnMoneySunModel(
41 {this.id, 42 {this.id,
@@ -44,7 +45,8 @@ class ReturnMoneySunModel { @@ -44,7 +45,8 @@ class ReturnMoneySunModel {
44 this.returnJson, 45 this.returnJson,
45 this.isTogether, 46 this.isTogether,
46 this.togetherJson, 47 this.togetherJson,
47 - this.cdate}); 48 + this.cdate,
  49 + this.beforePayJson});
48 50
49 ReturnMoneySunModel.fromJson(Map<String, dynamic> json) { 51 ReturnMoneySunModel.fromJson(Map<String, dynamic> json) {
50 id = json['id']; 52 id = json['id'];
@@ -60,6 +62,15 @@ class ReturnMoneySunModel { @@ -60,6 +62,15 @@ class ReturnMoneySunModel {
60 } 62 }
61 } 63 }
62 64
  65 + if (json['before_pay_json'] != null && json['before_pay_json'] != '') {
  66 + if (json['before_pay_json'] is Map) {
  67 + beforePayJson = new BeforePayJson.fromJson(json['before_pay_json']);
  68 + } else {
  69 + beforePayJson =
  70 + new BeforePayJson.fromJson(jsonDecode(json['before_pay_json']));
  71 + }
  72 + }
  73 +
63 isTogether = json['is_together']; 74 isTogether = json['is_together'];
64 75
65 if (json['together_json'] != null && json['together_json'] != '') { 76 if (json['together_json'] != null && json['together_json'] != '') {
@@ -175,3 +186,84 @@ class TogetherJsonModel { @@ -175,3 +186,84 @@ class TogetherJsonModel {
175 return data; 186 return data;
176 } 187 }
177 } 188 }
  189 +
  190 +class BeforePayJson {
  191 + NewUser? newUser;
  192 + NewUser? oldUser;
  193 + String? isOld;
  194 + String? isNew;
  195 +
  196 + BeforePayJson({this.newUser, this.oldUser, this.isOld, this.isNew});
  197 +
  198 + BeforePayJson.fromJson(Map<String, dynamic> json) {
  199 + if (json['new'] is Map) {
  200 + newUser = json['new'] != null ? new NewUser.fromJson(json['new']) : null;
  201 + } else {
  202 + newUser = json['new'] != null
  203 + ? new NewUser.fromJson(jsonDecode(json['new']))
  204 + : null;
  205 + }
  206 +
  207 + if (json['old'] is Map) {
  208 + oldUser = json['old'] != null ? new NewUser.fromJson(json['old']) : null;
  209 + } else {
  210 +
  211 +
  212 + oldUser = json['old'] != null ? new NewUser.fromJson(jsonDecode(json['old'])) : null;
  213 + }
  214 +
  215 +
  216 + isOld = json['is_old'];
  217 + isNew = json['is_new'];
  218 + }
  219 +
  220 + Map<String, dynamic> toJson() {
  221 + final Map<String, dynamic> data = new Map<String, dynamic>();
  222 + if (this.newUser != null) {
  223 + data['new'] = this.newUser!.toJson();
  224 + }
  225 + if (this.oldUser != null) {
  226 + data['old'] = this.oldUser!.toJson();
  227 + }
  228 + data['is_old'] = this.isOld;
  229 + data['is_new'] = this.isNew;
  230 + return data;
  231 + }
  232 +}
  233 +
  234 +class NewUser {
  235 + String? stime;
  236 + String? etime;
  237 + String? isFix;
  238 + String? randomMin;
  239 + String? randomMax;
  240 + String? fixPrice;
  241 +
  242 + NewUser(
  243 + {this.stime,
  244 + this.etime,
  245 + this.isFix,
  246 + this.randomMin,
  247 + this.randomMax,
  248 + this.fixPrice});
  249 +
  250 + NewUser.fromJson(Map<String, dynamic> json) {
  251 + stime = json['stime'];
  252 + etime = json['etime'];
  253 + isFix = json['is_fix'];
  254 + randomMin = json['random_min'];
  255 + randomMax = json['random_max'];
  256 + fixPrice = json['fix_price'];
  257 + }
  258 +
  259 + Map<String, dynamic> toJson() {
  260 + final Map<String, dynamic> data = new Map<String, dynamic>();
  261 + data['stime'] = this.stime;
  262 + data['etime'] = this.etime;
  263 + data['is_fix'] = this.isFix;
  264 + data['random_min'] = this.randomMin;
  265 + data['random_max'] = this.randomMax;
  266 + data['fix_price'] = this.fixPrice;
  267 + return data;
  268 + }
  269 +}
@@ -661,4 +661,7 @@ class HttpUrl { @@ -661,4 +661,7 @@ class HttpUrl {
661 661
662 static const get_free_meal_config_by_seller = 662 static const get_free_meal_config_by_seller =
663 "?service=App.Activity.GetFreeMealConfigBySeller"; // 获取当餐免费的配置信息 663 "?service=App.Activity.GetFreeMealConfigBySeller"; // 获取当餐免费的配置信息
  664 +
  665 +
  666 +
664 } 667 }
@@ -81,9 +81,9 @@ class _FinanceManageHomePageState extends State<FinanceManageHomePage> { @@ -81,9 +81,9 @@ class _FinanceManageHomePageState extends State<FinanceManageHomePage> {
81 NavigatorUtil.goReturnMoneyPage(context); 81 NavigatorUtil.goReturnMoneyPage(context);
82 }), 82 }),
83 83
84 - // _item('买单前送消费金', () {  
85 - // NavigatorUtil.goGiveMoneyBeforePayPage(context);  
86 - // }), 84 + _item('买单前送消费金', () {
  85 + NavigatorUtil.goGiveMoneyBeforePayPage(context);
  86 + }),
87 87
88 _item('交易记录', () { 88 _item('交易记录', () {
89 NavigatorUtil.goTransactionRecordHomePage(context); 89 NavigatorUtil.goTransactionRecordHomePage(context);
  1 +import 'dart:convert';
  2 +
1 import 'package:common_utils/common_utils.dart'; 3 import 'package:common_utils/common_utils.dart';
2 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
3 import 'package:flutter/services.dart'; 5 import 'package:flutter/services.dart';
@@ -68,176 +70,228 @@ class _GiveMoneyBeforePayPageState extends State<GiveMoneyBeforePayPage> { @@ -68,176 +70,228 @@ class _GiveMoneyBeforePayPageState extends State<GiveMoneyBeforePayPage> {
68 super.initState(); 70 super.initState();
69 71
70 WidgetsBinding.instance.addPostFrameCallback((_) { 72 WidgetsBinding.instance.addPostFrameCallback((_) {
71 - // _getConsumeConfig(); 73 + _getConsumeConfig();
72 }); 74 });
73 } 75 }
74 76
75 - // _getConsumeConfig() async {  
76 - // Map<String, String?> pramas = {  
77 - // 'sellerid':  
78 - // Provider.of<UserModel>(context, listen: false).user!.sellerid!,  
79 - // };  
80 -  
81 - // await financeProvider!.getConsumeConfig(context, pramas);  
82 - // if (financeProvider!.returnMoneySunModel != null) {  
83 - // isOld =  
84 - // financeProvider!.returnMoneySunModel?.isReturn == '1' ? true : false;  
85 - // if (financeProvider!.returnMoneySunModel!.returnJson?.stime != null) {  
86 - // DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(  
87 - // financeProvider!.returnMoneySunModel!.returnJson!.stime  
88 - // .toString()) *  
89 - // 1000);  
90 - // fromDateNew =  
91 - // DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);  
92 - // }  
93 - // if (financeProvider!.returnMoneySunModel!.returnJson?.etime != null) {  
94 - // DateTime dateTimee = DateTime.fromMillisecondsSinceEpoch(int.parse(  
95 - // financeProvider!.returnMoneySunModel!.returnJson!.etime  
96 - // .toString()) *  
97 - // 1000);  
98 - // endDateNew =  
99 - // DateUtil.formatDate(dateTimee, format: DateFormats.y_mo_d);  
100 - // }  
101 - // isRandom = financeProvider!.returnMoneySunModel!.returnJson?.isRandom == '1'  
102 - // ? true  
103 - // : false;  
104 - // ratioC.text =  
105 - // financeProvider!.returnMoneySunModel!.returnJson?.ratioData ?? '';  
106 - // ladderSelectFree =  
107 - // financeProvider!.returnMoneySunModel!.returnJson?.ladderData ?? [];  
108 -  
109 - // if (ladderSelectFree.length == 0) {  
110 - // LadderData ladderReturnMoneyModel = LadderData();  
111 - // ladderSelectFree.add(ladderReturnMoneyModel);  
112 - // }  
113 -  
114 - // isCoexist = financeProvider!.returnMoneySunModel!.isTogether == '1'  
115 - // ? true  
116 - // : false;  
117 - // proportionC.text =  
118 - // financeProvider!.returnMoneySunModel!.togetherJson?.ratioData ?? '';  
119 -  
120 - // setState(() {});  
121 - // }  
122 - // } 77 + _getConsumeConfig() async {
  78 + Map<String, String?> pramas = {
  79 + 'sellerid':
  80 + Provider.of<UserModel>(context, listen: false).user!.sellerid!,
  81 + };
  82 +
  83 + await financeProvider!.getConsumeConfig(context, pramas);
  84 + if (financeProvider!.returnMoneySunModel?.beforePayJson != null) {
  85 + isNew = financeProvider!.returnMoneySunModel?.beforePayJson?.isNew == '1'
  86 + ? true
  87 + : false;
  88 + isOld = financeProvider!.returnMoneySunModel?.beforePayJson?.isOld == '1'
  89 + ? true
  90 + : false;
  91 + if (financeProvider!.returnMoneySunModel!.beforePayJson?.newUser !=
  92 + null) {
  93 + DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
  94 + financeProvider!
  95 + .returnMoneySunModel!.beforePayJson!.newUser!.stime!
  96 + .toString()) *
  97 + 1000);
  98 + fromDateNew =
  99 + DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);
  100 +
  101 + DateTime dateTimeEnd = DateTime.fromMillisecondsSinceEpoch(int.parse(
  102 + financeProvider!
  103 + .returnMoneySunModel!.beforePayJson!.newUser!.etime!
  104 + .toString()) *
  105 + 1000);
  106 + endDateNew =
  107 + DateUtil.formatDate(dateTimeEnd, format: DateFormats.y_mo_d);
  108 + isRandomNew = financeProvider!
  109 + .returnMoneySunModel!.beforePayJson!.newUser!.isFix ==
  110 + '1'
  111 + ? false
  112 + : true;
  113 + fixCNew.text = financeProvider!
  114 + .returnMoneySunModel!.beforePayJson!.newUser!.fixPrice ??
  115 + '';
  116 +
  117 + minCNew.text = financeProvider!
  118 + .returnMoneySunModel!.beforePayJson!.newUser!.randomMin ??
  119 + '';
  120 + maxCNew.text = financeProvider!
  121 + .returnMoneySunModel!.beforePayJson!.newUser!.randomMax ??
  122 + '';
  123 + }
  124 +
  125 + if (financeProvider!.returnMoneySunModel!.beforePayJson?.oldUser !=
  126 + null) {
  127 + DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
  128 + financeProvider!
  129 + .returnMoneySunModel!.beforePayJson!.oldUser!.stime!
  130 + .toString()) *
  131 + 1000);
  132 + fromDateOld =
  133 + DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);
  134 +
  135 + DateTime dateTimeEnd = DateTime.fromMillisecondsSinceEpoch(int.parse(
  136 + financeProvider!
  137 + .returnMoneySunModel!.beforePayJson!.oldUser!.etime!
  138 + .toString()) *
  139 + 1000);
  140 + endDateOld =
  141 + DateUtil.formatDate(dateTimeEnd, format: DateFormats.y_mo_d);
  142 + isRandomOld = financeProvider!
  143 + .returnMoneySunModel!.beforePayJson!.oldUser!.isFix ==
  144 + '1'
  145 + ? false
  146 + : true;
  147 + fixCOld.text = financeProvider!
  148 + .returnMoneySunModel!.beforePayJson!.oldUser!.fixPrice ??
  149 + '';
  150 +
  151 + minC.text = financeProvider!
  152 + .returnMoneySunModel!.beforePayJson!.oldUser!.randomMin ??
  153 + '';
  154 + maxC.text = financeProvider!
  155 + .returnMoneySunModel!.beforePayJson!.oldUser!.randomMax ??
  156 + '';
  157 + }
  158 +
  159 + setState(() {});
  160 + }
  161 + }
123 162
124 //提交接口 163 //提交接口
125 - // _setConsumeConfig() async {  
126 - // FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘  
127 - // Map<String, String?> fullReductionData = {};  
128 -  
129 - // if (isOld) {  
130 - // if (fromDateNew == '选择日期') {  
131 - // Utils.showToast('请选择活动的开始时间!');  
132 - // return;  
133 - // }  
134 - // if (endDateNew == '选择日期') {  
135 - // Utils.showToast('请选择活动的结束时间!');  
136 - // return;  
137 - // }  
138 -  
139 - // if (isRandom) {  
140 - // //按照比例返还  
141 - // //需要填写比例百分比  
142 - // if (ratioC.text.trim().length == 0) {  
143 - // Utils.showToast('请输入返还消费金占实际支付金额的百分比!');  
144 - // return;  
145 - // }  
146 -  
147 - // fullReductionData['is_ratio'] = '1';  
148 - // fullReductionData['ratio_data'] = ratioC.text;  
149 - // } else {  
150 - // //按阶梯返还  
151 - // //没有数据时,提示新增阶梯设置数据  
152 - // if (ladderSelectFree.length == 0) {  
153 - // Utils.showToast('请点击增加阶梯设置数据!');  
154 - // return;  
155 - // }  
156 -  
157 - // //判断阶梯里面的数据 实际支付金额是否输入  
158 -  
159 - // bool canPrice =  
160 - // ladderSelectFree.any((e) => e.givePriceC.text.trim().length == 0);  
161 - // if (canPrice) {  
162 - // int index = ladderSelectFree  
163 - // .indexWhere((e) => e.givePriceC.text.trim().length == 0);  
164 -  
165 - // Utils.showToast('请输入阶梯(${index + 1})的实际支付金额!');  
166 - // return;  
167 - // }  
168 -  
169 - // //判断返回消费金额是否输入  
170 -  
171 - // bool can =  
172 - // ladderSelectFree.any((e) => e.backPriceC.text.trim().length == 0);  
173 - // if (can) {  
174 - // int index = ladderSelectFree  
175 - // .indexWhere((e) => e.backPriceC.text.trim().length == 0);  
176 -  
177 - // Utils.showToast('请输入阶梯(${index + 1})的返还消费金额!');  
178 - // return;  
179 - // }  
180 -  
181 - // fullReductionData['is_ratio'] = '0'; //按阶梯  
182 -  
183 - // List<Map<String, String>> ladderData = [];  
184 - // ladderSelectFree.forEach((e) {  
185 - // Map<String, String> price = {  
186 - // 'give_price': e.givePriceC.text,  
187 - // 'back_price': e.backPriceC.text,  
188 - // };  
189 - // ladderData.add(price);  
190 - // });  
191 -  
192 - // fullReductionData['ladder_data'] =  
193 - // (ladderData.length == 0 ? null : jsonEncode(ladderData));  
194 - // }  
195 -  
196 - // //设置数据  
197 -  
198 - // if (fromDateNew != '选择日期') {  
199 - // String fromfull = fromDateNew + ' 00:00:00';  
200 -  
201 - // String sfull =  
202 - // '${(DateUtil.getDateMsByTimeStr(fromfull)! / 1000).floor()}';  
203 -  
204 - // fullReductionData['stime'] = sfull;  
205 - // }  
206 - // if (endDateNew != '选择日期') {  
207 - // String endfull = endDateNew + ' 23:59:59';  
208 -  
209 - // String efull =  
210 - // '${(DateUtil.getDateMsByTimeStr(endfull)! / 1000).floor()}';  
211 -  
212 - // fullReductionData['etime'] = efull;  
213 - // }  
214 - // }  
215 - // if (proportionC.text.trim().length == 0) {  
216 - // Utils.showToast('请输入消费金支付占实际消费金额的百分比!');  
217 - // return;  
218 - // }  
219 -  
220 - // Map<String, String?> togetherJson = {};  
221 - // togetherJson['is_coexist'] = isCoexist ? '1' : '0';  
222 - // togetherJson['ratio_data'] = proportionC.text;  
223 -  
224 - // Map<String, String?> pramas = {  
225 - // 'sellerid':  
226 - // Provider.of<UserModel>(context, listen: false).user!.sellerid!,  
227 - // 'is_return': isOld ? '1' : '0',  
228 - // 'return_json':  
229 - // fullReductionData.length == 0 ? null : jsonEncode(fullReductionData),  
230 - // 'is_together': isCoexist ? '1' : '0',  
231 - // 'together_json':  
232 - // togetherJson.length == 0 ? null : jsonEncode(togetherJson),  
233 - // };  
234 - // bool success = await financeProvider!.setConsumeConfig(context, pramas);  
235 - // if (success) {  
236 - // if (Navigator.canPop(context)) {  
237 - // Navigator.pop(context);  
238 - // }  
239 - // }  
240 - // } 164 + _setConsumeConfig() async {
  165 + FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
  166 +
  167 + if (isNew) {
  168 + // 新用户买单开关打开
  169 + if (fromDateNew == '选择日期') {
  170 + Utils.showToast('请选择新用户活动的开始时间!');
  171 + return;
  172 + }
  173 + if (endDateNew == '选择日期') {
  174 + Utils.showToast('请选择新用户活动的结束时间!');
  175 + return;
  176 + }
  177 +
  178 + if (isRandomNew) {
  179 + //随机
  180 + if (minCNew.text.trim().length == 0) {
  181 + Utils.showToast('请输入新用户随机金额的最少值!');
  182 + return;
  183 + }
  184 + if (maxCNew.text.trim().length == 0) {
  185 + Utils.showToast('请输入新用户随机金额的最多值!');
  186 + return;
  187 + }
  188 + } else {
  189 + //固定
  190 + if (fixCNew.text.trim().length == 0) {
  191 + Utils.showToast('请设置新用户固定金额!');
  192 + return;
  193 + }
  194 + }
  195 + }
  196 + //设置数据
  197 + Map<String, String> newData = {};
  198 + if (fromDateNew != '选择日期') {
  199 + String fromfull = fromDateNew + ' 00:00:00';
  200 +
  201 + String sfull =
  202 + '${(DateUtil.getDateMsByTimeStr(fromfull)! / 1000).floor()}';
  203 +
  204 + newData['stime'] = sfull;
  205 + }
  206 + if (endDateNew != '选择日期') {
  207 + String endfull = endDateNew + ' 23:59:59';
  208 +
  209 + String efull =
  210 + '${(DateUtil.getDateMsByTimeStr(endfull)! / 1000).floor()}';
  211 +
  212 + newData['etime'] = efull;
  213 + }
  214 + newData['is_fix'] = isRandomNew ? '0' : '1';
  215 + if (isRandomNew) {
  216 + newData['random_min'] = minCNew.text;
  217 + newData['random_max'] = maxCNew.text;
  218 + } else {
  219 + newData['fix_price'] = fixCNew.text;
  220 + }
  221 +
  222 + if (isOld) {
  223 + // 老用户买单开关打开
  224 + if (fromDateOld == '选择日期') {
  225 + Utils.showToast('请选择老用户活动的开始时间!');
  226 + return;
  227 + }
  228 + if (endDateOld == '选择日期') {
  229 + Utils.showToast('请选择老用户活动的结束时间!');
  230 + return;
  231 + }
  232 +
  233 + if (isRandomOld) {
  234 + //随机
  235 + if (minC.text.trim().length == 0) {
  236 + Utils.showToast('请输入老用户随机金额的最少值!');
  237 + return;
  238 + }
  239 + if (maxC.text.trim().length == 0) {
  240 + Utils.showToast('请输入老用户随机金额的最多值!');
  241 + return;
  242 + }
  243 + } else {
  244 + //固定
  245 + if (fixCOld.text.trim().length == 0) {
  246 + Utils.showToast('请设置老用户固定金额!');
  247 + return;
  248 + }
  249 + }
  250 + }
  251 + //设置数据
  252 + Map<String, String> oldData = {};
  253 + if (fromDateOld != '选择日期') {
  254 + String fromfull = fromDateOld + ' 00:00:00';
  255 +
  256 + String sfull =
  257 + '${(DateUtil.getDateMsByTimeStr(fromfull)! / 1000).floor()}';
  258 +
  259 + oldData['stime'] = sfull;
  260 + }
  261 + if (endDateOld != '选择日期') {
  262 + String endfull = endDateOld + ' 23:59:59';
  263 +
  264 + String efull =
  265 + '${(DateUtil.getDateMsByTimeStr(endfull)! / 1000).floor()}';
  266 +
  267 + oldData['etime'] = efull;
  268 + }
  269 + oldData['is_fix'] = isRandomOld ? '0' : '1';
  270 + if (isRandomOld) {
  271 + oldData['random_min'] = minC.text;
  272 + oldData['random_max'] = maxC.text;
  273 + } else {
  274 + oldData['fix_price'] = fixCOld.text;
  275 + }
  276 +
  277 + Map<String, String?> beforePayJson = {};
  278 + beforePayJson['new'] = jsonEncode(newData);
  279 + beforePayJson['old'] = jsonEncode(oldData);
  280 + beforePayJson['is_old'] = isOld ? '1' : '0';
  281 + beforePayJson['is_new'] = isNew ? '1' : '0';
  282 +
  283 + Map<String, String?> pramas = {
  284 + 'sellerid':
  285 + Provider.of<UserModel>(context, listen: false).user!.sellerid!,
  286 + 'before_pay_json': jsonEncode(beforePayJson),
  287 + };
  288 + bool success = await financeProvider!.setConsumeConfig(context, pramas);
  289 + if (success) {
  290 + if (Navigator.canPop(context)) {
  291 + Navigator.pop(context);
  292 + }
  293 + }
  294 + }
241 295
242 ///是否立即启用 296 ///是否立即启用
243 Widget _canUse( 297 Widget _canUse(
@@ -808,7 +862,7 @@ class _GiveMoneyBeforePayPageState extends State<GiveMoneyBeforePayPage> { @@ -808,7 +862,7 @@ class _GiveMoneyBeforePayPageState extends State<GiveMoneyBeforePayPage> {
808 fontSize: 32, 862 fontSize: 32,
809 onPressed: () { 863 onPressed: () {
810 // 调用接口 864 // 调用接口
811 - // _setConsumeConfig() 865 + _setConsumeConfig();
812 }, 866 },
813 ), 867 ),
814 ) 868 )