Commit baabadcbf606953d6ea759d9f6198b0b50bb9138

Authored by weixin_45529955
1 parent 7704131f

支付返消费金设置页面功能 OK

  1 +import 'dart:convert';
  2 +
1 import 'package:flutter/material.dart'; 3 import 'package:flutter/material.dart';
2 4
  5 +class ReturnMoneyModel {
  6 + int? ret;
  7 + ReturnMoneySunModel? data;
  8 + String? msg;
  9 +
  10 + ReturnMoneyModel({this.ret, this.data, this.msg});
  11 +
  12 + ReturnMoneyModel.fromJson(Map<dynamic, dynamic> json) {
  13 + ret = json['ret'];
  14 + data = json['data'] != null
  15 + ? new ReturnMoneySunModel.fromJson(json['data'])
  16 + : null;
  17 + msg = json['msg'];
  18 + }
  19 +
  20 + Map<String, dynamic> toJson() {
  21 + final Map<String, dynamic> data = new Map<String, dynamic>();
  22 + data['ret'] = this.ret;
  23 + if (this.data != null) {
  24 + data['data'] = this.data!.toJson();
  25 + }
  26 + data['msg'] = this.msg;
  27 + return data;
  28 + }
  29 +}
  30 +
  31 +class ReturnMoneySunModel {
  32 + String? id;
  33 + String? sellerid;
  34 + String? isReturn;
  35 + ReturnJsonModel? returnJson;
  36 + String? isTogether;
  37 + TogetherJsonModel? togetherJson;
  38 + String? cdate;
  39 +
  40 + ReturnMoneySunModel(
  41 + {this.id,
  42 + this.sellerid,
  43 + this.isReturn,
  44 + this.returnJson,
  45 + this.isTogether,
  46 + this.togetherJson,
  47 + this.cdate});
  48 +
  49 + ReturnMoneySunModel.fromJson(Map<String, dynamic> json) {
  50 + id = json['id'];
  51 + sellerid = json['sellerid'];
  52 + isReturn = json['is_return'];
3 53
  54 + if (json['return_json'] != null && json['return_json'] != '') {
  55 + if (json['return_json'] is Map) {
  56 + returnJson = new ReturnJsonModel.fromJson(json['return_json']);
  57 + } else {
  58 + returnJson =
  59 + new ReturnJsonModel.fromJson(jsonDecode(json['return_json']));
  60 + }
  61 + }
  62 +
  63 + isTogether = json['is_together'];
4 64
5 -class LadderReturnMoneyModel {  
6 -/*  
7 -{  
8 - "price": "100",  
9 - "coupons": [  
10 - {  
11 - "id": "997",  
12 - "name": "免费券15" 65 + if (json['together_json'] != null && json['together_json'] != '') {
  66 + if (json['together_json'] is Map) {
  67 + togetherJson = new TogetherJsonModel.fromJson(json['together_json']);
  68 + } else {
  69 + togetherJson =
  70 + new TogetherJsonModel.fromJson(jsonDecode(json['together_json']));
  71 + }
13 } 72 }
14 - ]  
15 -}  
16 -*/ 73 + cdate = json['cdate'];
  74 + }
17 75
  76 + Map<String, dynamic> toJson() {
  77 + final Map<String, dynamic> data = new Map<String, dynamic>();
  78 + data['id'] = this.id;
  79 + data['sellerid'] = this.sellerid;
  80 + data['is_return'] = this.isReturn;
  81 + data['return_json'] = this.returnJson;
  82 + data['is_together'] = this.isTogether;
  83 + data['together_json'] = this.togetherJson;
  84 + data['cdate'] = this.cdate;
  85 + return data;
  86 + }
  87 +}
  88 +
  89 +class ReturnJsonModel {
  90 + String? isRatio;
  91 + String? ratioData;
  92 + List<LadderData>? ladderData;
  93 + String? stime;
  94 + String? etime;
  95 +
  96 + ReturnJsonModel(
  97 + {this.isRatio, this.ratioData, this.ladderData, this.stime, this.etime});
  98 +
  99 + ReturnJsonModel.fromJson(Map<String, dynamic> json) {
  100 + isRatio = json['is_ratio'];
  101 + ratioData = json['ratio_data'];
  102 + if (json['ladder_data'] != null) {
  103 + ladderData = <LadderData>[];
  104 +
  105 + if (json['ladder_data'] is List) {
  106 + json['ladder_data'].forEach((v) {
  107 + ladderData!.add(new LadderData.fromJson(v));
  108 + });
  109 + } else {
  110 + jsonDecode(json['ladder_data']).forEach((v) {
  111 + ladderData!.add(new LadderData.fromJson(v));
  112 + });
  113 + }
  114 + }
  115 + stime = json['stime'];
  116 + etime = json['etime'];
  117 + }
  118 +
  119 + Map<String, dynamic> toJson() {
  120 + final Map<String, dynamic> data = new Map<String, dynamic>();
  121 + data['is_ratio'] = this.isRatio;
  122 + data['ratio_data'] = this.ratioData;
  123 + if (this.ladderData != null) {
  124 + data['ladder_data'] = this.ladderData!.map((v) => v.toJson()).toList();
  125 + }
  126 + data['stime'] = this.stime;
  127 + data['etime'] = this.etime;
  128 + return data;
  129 + }
  130 +}
  131 +
  132 +class LadderData {
18 String? givePrice; 133 String? givePrice;
19 - TextEditingController givePriceC = TextEditingController();  
20 String? backPrice; 134 String? backPrice;
  135 +
  136 + TextEditingController givePriceC = TextEditingController();
21 TextEditingController backPriceC = TextEditingController(); 137 TextEditingController backPriceC = TextEditingController();
22 138
23 - LadderReturnMoneyModel({  
24 - this.givePrice,  
25 - this.backPrice,  
26 - });  
27 - LadderReturnMoneyModel.fromJson(Map<String, dynamic> json) {  
28 - givePrice = json['give_price']?.toString();  
29 - givePriceC.text = givePrice ?? '';  
30 - givePrice = json['back_price']?.toString(); 139 + LadderData({this.givePrice, this.backPrice});
  140 +
  141 + LadderData.fromJson(Map<String, dynamic> json) {
  142 + givePrice = json['give_price'];
  143 + backPrice = json['back_price'];
31 givePriceC.text = givePrice ?? ''; 144 givePriceC.text = givePrice ?? '';
  145 + backPriceC.text = backPrice ?? '';
32 } 146 }
  147 +
  148 + Map<String, dynamic> toJson() {
  149 + final Map<String, dynamic> data = new Map<String, dynamic>();
  150 + data['give_price'] = this.givePrice;
  151 + data['back_price'] = this.backPrice;
  152 + return data;
  153 + }
  154 +}
  155 +
  156 +class TogetherJsonModel {
  157 + String? isCoexist;
  158 + String? ratioData;
  159 +
  160 + TogetherJsonModel({
  161 + this.isCoexist,
  162 + this.ratioData,
  163 + });
  164 +
  165 + TogetherJsonModel.fromJson(Map<String, dynamic> json) {
  166 + isCoexist = json['is_coexist'];
  167 + ratioData = json['ratio_data'];
  168 + }
  169 +
33 Map<String, dynamic> toJson() { 170 Map<String, dynamic> toJson() {
34 - final data = <String, dynamic>{};  
35 - data['give_price'] = givePrice;  
36 - data['back_price'] = backPrice; 171 + final Map<String, dynamic> data = new Map<String, dynamic>();
  172 + data['is_coexist'] = this.isCoexist;
  173 + data['ratio_data'] = this.ratioData;
  174 +
37 return data; 175 return data;
38 } 176 }
39 } 177 }
@@ -39,7 +39,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -39,7 +39,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
39 ScrollController controller = ScrollController(); 39 ScrollController controller = ScrollController();
40 40
41 bool isBack = false; 41 bool isBack = false;
42 - bool isRatio = true; //是否按照比例返还 true按照比例/false按照阶梯返还 42 + bool isRatio = false; //是否按照比例返还 true按照比例/false按照阶梯返还
43 43
44 TextEditingController ratioC = TextEditingController(); //比例输入框 44 TextEditingController ratioC = TextEditingController(); //比例输入框
45 FocusNode ratioNode = FocusNode(); //比例输入框 45 FocusNode ratioNode = FocusNode(); //比例输入框
@@ -49,16 +49,66 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -49,16 +49,66 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
49 TextEditingController proportionC = TextEditingController(); //消费金支付占实际消费金额比例 49 TextEditingController proportionC = TextEditingController(); //消费金支付占实际消费金额比例
50 FocusNode proportionNode = FocusNode(); //消费金支付占实际消费金额比例 50 FocusNode proportionNode = FocusNode(); //消费金支付占实际消费金额比例
51 51
52 - List<LadderReturnMoneyModel> ladderSelectFree = []; 52 + List<LadderData> ladderSelectFree = [];
53 53
54 bool isCoexist = false; //消费金可与优惠券同时使用 54 bool isCoexist = false; //消费金可与优惠券同时使用
55 55
56 @override 56 @override
57 void initState() { 57 void initState() {
58 super.initState(); 58 super.initState();
59 - LadderReturnMoneyModel ladderReturnMoneyModel = LadderReturnMoneyModel();  
60 - ladderSelectFree.add(ladderReturnMoneyModel);  
61 - WidgetsBinding.instance.addPostFrameCallback((_) {}); 59 +
  60 + WidgetsBinding.instance.addPostFrameCallback((_) {
  61 + _getConsumeConfig();
  62 + });
  63 + }
  64 +
  65 + _getConsumeConfig() async {
  66 + Map<String, String?> pramas = {
  67 + 'sellerid':
  68 + Provider.of<UserModel>(context, listen: false).user!.sellerid!,
  69 + };
  70 +
  71 + await financeProvider!.getConsumeConfig(context, pramas);
  72 + if (financeProvider!.returnMoneySunModel != null) {
  73 + isBack =
  74 + financeProvider!.returnMoneySunModel?.isReturn == '1' ? true : false;
  75 + if (financeProvider!.returnMoneySunModel!.returnJson?.stime != null) {
  76 + DateTime dateTimes = DateTime.fromMillisecondsSinceEpoch(int.parse(
  77 + financeProvider!.returnMoneySunModel!.returnJson!.stime
  78 + .toString()) *
  79 + 1000);
  80 + fromDateFull =
  81 + DateUtil.formatDate(dateTimes, format: DateFormats.y_mo_d);
  82 + }
  83 + if (financeProvider!.returnMoneySunModel!.returnJson?.etime != null) {
  84 + DateTime dateTimee = DateTime.fromMillisecondsSinceEpoch(int.parse(
  85 + financeProvider!.returnMoneySunModel!.returnJson!.etime
  86 + .toString()) *
  87 + 1000);
  88 + endDateFull =
  89 + DateUtil.formatDate(dateTimee, format: DateFormats.y_mo_d);
  90 + }
  91 + isRatio = financeProvider!.returnMoneySunModel!.returnJson?.isRatio == '1'
  92 + ? true
  93 + : false;
  94 + ratioC.text =
  95 + financeProvider!.returnMoneySunModel!.returnJson?.ratioData ?? '';
  96 + ladderSelectFree =
  97 + financeProvider!.returnMoneySunModel!.returnJson?.ladderData ?? [];
  98 +
  99 + if (ladderSelectFree.length == 0) {
  100 + LadderData ladderReturnMoneyModel = LadderData();
  101 + ladderSelectFree.add(ladderReturnMoneyModel);
  102 + }
  103 +
  104 + isCoexist = financeProvider!.returnMoneySunModel!.isTogether == '1'
  105 + ? true
  106 + : false;
  107 + proportionC.text =
  108 + financeProvider!.returnMoneySunModel!.togetherJson?.ratioData ?? '';
  109 +
  110 + setState(() {});
  111 + }
62 } 112 }
63 113
64 //提交接口 114 //提交接口
@@ -66,7 +116,6 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -66,7 +116,6 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
66 FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘 116 FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
67 Map<String, String?> fullReductionData = {}; 117 Map<String, String?> fullReductionData = {};
68 118
69 -  
70 if (isBack) { 119 if (isBack) {
71 if (fromDateFull == '选择日期') { 120 if (fromDateFull == '选择日期') {
72 Utils.showToast('请选择活动的开始时间!'); 121 Utils.showToast('请选择活动的开始时间!');
@@ -477,7 +526,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -477,7 +526,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
477 shrinkWrap: true, 526 shrinkWrap: true,
478 itemCount: ladderSelectFree.length, 527 itemCount: ladderSelectFree.length,
479 itemBuilder: (context, index) { 528 itemBuilder: (context, index) {
480 - LadderReturnMoneyModel data = ladderSelectFree[index]; 529 + LadderData data = ladderSelectFree[index];
481 return Container( 530 return Container(
482 padding: EdgeInsets.only( 531 padding: EdgeInsets.only(
483 left: w(40), top: w(8), bottom: w(8), right: w(16)), 532 left: w(40), top: w(8), bottom: w(8), right: w(16)),
@@ -565,7 +614,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -565,7 +614,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
565 return KeyboardDismissOnTap( 614 return KeyboardDismissOnTap(
566 child: Scaffold( 615 child: Scaffold(
567 backgroundColor: MyColours.color_ffffff, 616 backgroundColor: MyColours.color_ffffff,
568 - appBar: SystemAppBar('支付返券'), 617 + appBar: SystemAppBar('支付返消费金'),
569 key: scaffoldKey, 618 key: scaffoldKey,
570 body: Column(children: [ 619 body: Column(children: [
571 Expanded( 620 Expanded(
@@ -596,7 +645,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -596,7 +645,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
596 format: 645 format:
597 DateFormats.y_mo_d))) < 646 DateFormats.y_mo_d))) <
598 0) { 647 0) {
599 - Utils.showToast('满减返券的活动开始时间不能迟于活动结束时间'); 648 + Utils.showToast('活动开始时间不能迟于活动结束时间');
600 return; 649 return;
601 } 650 }
602 } 651 }
@@ -637,7 +686,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -637,7 +686,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
637 .compareTo(DateUtil.getDateTime( 686 .compareTo(DateUtil.getDateTime(
638 fromDateFull)) < 687 fromDateFull)) <
639 0) { 688 0) {
640 - Utils.showToast('满减返券的活动结束时间不能早于活动开始时间'); 689 + Utils.showToast('活动结束时间不能早于活动开始时间');
641 return; 690 return;
642 } 691 }
643 } 692 }
@@ -679,8 +728,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> { @@ -679,8 +728,7 @@ class _ReturnMoneyPageState extends State<ReturnMoneyPage> {
679 if (!isRatio) 728 if (!isRatio)
680 InkWell( 729 InkWell(
681 onTap: () { 730 onTap: () {
682 - LadderReturnMoneyModel data =  
683 - LadderReturnMoneyModel(); 731 + LadderData data = LadderData();
684 ladderSelectFree.add(data); 732 ladderSelectFree.add(data);
685 setState(() {}); 733 setState(() {});
686 }, 734 },
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart'; @@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
6 import 'package:one_key/models/deposit_record_detail_model.dart'; 6 import 'package:one_key/models/deposit_record_detail_model.dart';
7 import 'package:one_key/models/deposit_record_model.dart'; 7 import 'package:one_key/models/deposit_record_model.dart';
8 import 'package:one_key/models/ladder_coupons_model.dart'; 8 import 'package:one_key/models/ladder_coupons_model.dart';
  9 +import 'package:one_key/models/ladder_return_money_model.dart';
9 import 'package:one_key/models/vip_record_detail_model.dart'; 10 import 'package:one_key/models/vip_record_detail_model.dart';
10 import 'package:one_key/models/vip_record_model.dart'; 11 import 'package:one_key/models/vip_record_model.dart';
11 import 'package:one_key/provider/user_model.dart'; 12 import 'package:one_key/provider/user_model.dart';
@@ -45,6 +46,8 @@ class FinanceProvider extends ChangeNotifier { @@ -45,6 +46,8 @@ class FinanceProvider extends ChangeNotifier {
45 46
46 PageState pageStateRecordDeposit = PageState.Loading; 47 PageState pageStateRecordDeposit = PageState.Loading;
47 48
  49 + ReturnMoneySunModel? returnMoneySunModel;
  50 +
48 ///客户经理获取所创建活动列表 51 ///客户经理获取所创建活动列表
49 Future createPayQrcode(BuildContext context, {isShowLoading = true}) async { 52 Future createPayQrcode(BuildContext context, {isShowLoading = true}) async {
50 try { 53 try {
@@ -236,7 +239,9 @@ class FinanceProvider extends ChangeNotifier { @@ -236,7 +239,9 @@ class FinanceProvider extends ChangeNotifier {
236 context, Method.post, HttpUrl.set_consume_config, 239 context, Method.post, HttpUrl.set_consume_config,
237 data: params, showLoading: showLoading); 240 data: params, showLoading: showLoading);
238 if (baseResp.code == Constant.status_success) { 241 if (baseResp.code == Constant.status_success) {
239 - if (baseResp.data == 0 || baseResp.data == 1) { 242 + if (baseResp.data == 0 ||
  243 + baseResp.data == 1 ||
  244 + (baseResp.data is Map)) {
240 if (needToast) { 245 if (needToast) {
241 Utils.showToast('设置成功'); 246 Utils.showToast('设置成功');
242 } 247 }
@@ -285,6 +290,33 @@ class FinanceProvider extends ChangeNotifier { @@ -285,6 +290,33 @@ class FinanceProvider extends ChangeNotifier {
285 } 290 }
286 } 291 }
287 292
  293 + ///获取商家消费金规则
  294 + Future getConsumeConfig(BuildContext context, Map<String, String?> params,
  295 + {isShowLoading = true}) async {
  296 + try {
  297 + BaseResp<dynamic> baseResp = await DioUtil().request<dynamic>(
  298 + context, Method.post, HttpUrl.get_consume_config,
  299 + data: params, showLoading: isShowLoading);
  300 + if (baseResp.code == Constant.status_success) {
  301 + ReturnMoneySunModel? temp =
  302 + ReturnMoneyModel.fromJson(baseResp.responseData!).data;
  303 + if (temp != false) {
  304 + returnMoneySunModel = temp;
  305 + }
  306 + } else {
  307 + if (baseResp != null) {
  308 + Utils.showToast(baseResp.msg ?? "");
  309 + }
  310 + }
  311 +
  312 + notifyListeners();
  313 + } catch (error) {
  314 + print(error.toString());
  315 + if (error is MyError) {}
  316 + notifyListeners();
  317 + }
  318 + }
  319 +
288 ///获取商家定金订单列表 320 ///获取商家定金订单列表
289 Future getReserveDepositOrderList( 321 Future getReserveDepositOrderList(
290 BuildContext context, Map<String, String?> params, 322 BuildContext context, Map<String, String?> params,