彩票下单接口对接

master
laiiihz 5 years ago
parent 6c8bf384fb
commit b4544fb2c7

@ -370,4 +370,7 @@ class LotteryAPI {
///
static const String redeem_history = "/v1/ticket/order/list";
///
static const String redeem_shots = "/v1/ticket/bet";
}

@ -27,6 +27,7 @@ import 'package:redux/redux.dart';
class UserManager {
static bool shouldRefresh = false;
User user;
UserBrief userBrief;
//
HomeWeatherModel homeWeatherModel;
ValueNotifier<bool> login = ValueNotifier(false);
@ -63,6 +64,7 @@ class UserManager {
_instance = new UserManager._internal();
_instance.user = User.empty();
_instance.selectTabbarIndex = 0;
_instance.userBrief = UserBrief.empty();
}
return _instance;
}
@ -101,7 +103,7 @@ class UserManager {
return false;
}
_identifier = model.data == null ? '' : model.data.identifier;
_instance.userBrief = model.data;
store.dispatch(UpdateUserBriefAction(model.data));
return true;
}

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
import 'package:recook/utils/math/recook_math.dart';
@ -15,6 +16,7 @@ class LotteryCartModel {
@required this.focusedRedBalls,
@required this.focusedBlueBalls,
});
///
String get typeStr {
if (isDoubleLottery) {
@ -34,6 +36,24 @@ class LotteryCartModel {
}
}
int get lotteryTypeCode {
if (isDoubleLottery) {
if (redBalls.length == 6 && blueBalls.length == 1)
return 101;
else if (focusedRedBalls.length != 0 || focusedBlueBalls.length != 0)
return 103;
else
return 102;
} else {
if (redBalls.length == 5 && blueBalls.length == 2)
return 101;
else if (focusedRedBalls.length != 0 || focusedBlueBalls.length != 0)
return 103;
else
return 102;
}
}
///
int get shots => LotteryCartStore.countLotteryBalls(
type,
@ -43,6 +63,9 @@ class LotteryCartModel {
focusedBlueBalls: focusedBlueBalls,
);
/// recook coin
int get recookCoin => shots * 2;
///
bool get isDoubleLottery => type == LotteryType.DOUBLE_LOTTERY;
}
@ -51,14 +74,39 @@ class LotteryCartStore {
static List<LotteryCartModel> doubleLotteryModels = [];
static List<LotteryCartModel> bigLotteryModels = [];
static add1Shot(LotteryType type, LotteryCartModel model) {
switch (type) {
case LotteryType.DOUBLE_LOTTERY:
doubleLotteryModels.add(model);
break;
case LotteryType.BIG_LOTTERY:
bigLotteryModels.add(model);
break;
}
int normalType = 0;
int multiplyType = 0;
int withChildType = 0;
doubleLotteryModels.forEach((element) {
switch (element.lotteryTypeCode) {
case 101:
normalType++;
break;
case 102:
multiplyType++;
break;
case 103:
withChildType++;
break;
}
});
if (normalType >= 5 && model.lotteryTypeCode == 101)
showToast('一次只能兑换5注单式彩票');
else if (multiplyType >= 1 && model.lotteryTypeCode == 102)
showToast('一次只能兑换1注复式彩票');
else if (withChildType >= 1 && model.lotteryTypeCode == 103)
showToast('一次只能兑换1注脱胆彩票');
else
switch (type) {
case LotteryType.DOUBLE_LOTTERY:
doubleLotteryModels.add(model);
break;
case LotteryType.BIG_LOTTERY:
bigLotteryModels.add(model);
break;
}
}
static int countLotteryBalls(

@ -1,16 +1,25 @@
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:oktoast/oktoast.dart';
import 'package:recook/const/resource.dart';
import 'package:recook/constants/api.dart';
import 'package:recook/constants/app_image_resources.dart';
import 'package:recook/constants/constants.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/manager/user_manager.dart';
import 'package:recook/pages/home/widget/plus_minus_view.dart';
import 'package:recook/pages/lottery/lottery_cart_model.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
import 'package:recook/pages/lottery/tools/lottery_tool.dart';
import 'package:recook/pages/lottery/widget/lottery_grid_view.dart';
import 'package:recook/pages/lottery/widget/lottery_scaffold.dart';
import 'package:recook/widgets/alert.dart';
import 'package:recook/widgets/custom_image_button.dart';
class LotteryCartPage extends StatefulWidget {
final dynamic arguments;
LotteryCartPage({Key key, this.arguments}) : super(key: key);
final bool isDouble;
LotteryCartPage({Key key, @required this.isDouble}) : super(key: key);
@override
_LotteryCartPageState createState() => _LotteryCartPageState();
@ -20,7 +29,7 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
int multiply = 1;
@override
Widget build(BuildContext context) {
final models = widget.arguments['type']
final models = widget.isDouble
? LotteryCartStore.doubleLotteryModels
: LotteryCartStore.bigLotteryModels;
int doubleShots = 0;
@ -31,11 +40,11 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
LotteryCartStore.bigLotteryModels.forEach((element) {
bigShots += element.shots;
});
final countShots = widget.arguments['type'] ? doubleShots : bigShots;
final countShots = widget.isDouble ? doubleShots : bigShots;
return LotteryScaffold(
red: true,
whiteBg: true,
title: '双色球',
title: widget.isDouble ? '双色球' : '大乐透',
bottomNavi: Container(
color: Colors.white,
child: SafeArea(
@ -93,7 +102,7 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
'${countShots * 2}瑞币或$countShots彩票券',
'${countShots * 2 * multiply}瑞币或${countShots * multiply}彩票券',
style: TextStyle(
color: Color(0xFF666666),
fontSize: rSP(12),
@ -115,7 +124,53 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
),
color: Color(0xFFE02020),
splashColor: Colors.black38,
onPressed: () {},
onPressed: () {
showDialog(
context: context,
child: NormalContentDialog(
title: '兑换彩票',
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'确定使用${countShots * 2.0 * multiply}瑞币',
style: TextStyle(
color: Color(0xFF333333),
fontSize: rSP(16),
),
),
Text(
'当前瑞币余额:${UserManager.instance.userBrief.myAssets.coinNum}',
style: TextStyle(
color: Color(0xFF666666),
fontSize: rSP(15),
),
),
],
),
items: ['取消', '确定'],
listener: (index) {
_redeemLottery();
// switch (index) {
// case 0:
// Navigator.pop(context);
// break;
// case 1:
// if (UserManager
// .instance.userBrief.myAssets.coinNum <
// countShots * 2.0) {
// Navigator.pop(context);
// showToast('瑞币余额不足,无法兑换');
// } else {
// _redeemLottery();
// }
// break;
// }
},
),
);
},
child: Text(
'兑换彩票',
style: TextStyle(
@ -140,7 +195,7 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
children: [
CustomImageButton(
onPressed: () {
if (widget.arguments['type'])
if (widget.isDouble)
LotteryCartStore.doubleLotteryModels.clear();
else
LotteryCartStore.bigLotteryModels.clear();
@ -196,36 +251,110 @@ class _LotteryCartPageState extends State<LotteryCartPage> {
}
_buildChildBox(LotteryCartModel model) {
return InkWell(
onTap: () {},
child: Container(
padding: EdgeInsets.all(rSize(16)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: LotteryGridView(model: model),
),
SizedBox(width: rSize(34)),
Icon(
AppIcons.icon_next,
size: rSize(16),
color: Color(0xFF666666),
return Slidable(
child: InkWell(
onTap: () {},
child: Container(
padding: EdgeInsets.all(rSize(16)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: LotteryGridView(model: model),
),
SizedBox(width: rSize(34)),
Icon(
AppIcons.icon_next,
size: rSize(16),
color: Color(0xFF666666),
),
],
),
Text(
'${model.typeStr} ${model.shots}',
style: TextStyle(
color: Color(0xFF333333),
fontSize: rSize(14),
),
],
),
Text(
'${model.typeStr} ${model.shots}',
style: TextStyle(
color: Color(0xFF333333),
fontSize: rSize(14),
),
),
],
],
),
),
),
secondaryActions: [
SlideAction(
color: Color(0xFFFF4D4F),
child: Text(
'删除',
style: TextStyle(
color: Colors.white,
fontSize: rSP(15),
),
),
onTap: () {
final models = widget.isDouble
? LotteryCartStore.doubleLotteryModels
: LotteryCartStore.bigLotteryModels;
models.remove(model);
setState(() {});
},
),
],
actionPane: SlidableDrawerActionPane(),
);
}
_redeemLottery() async {
GSDialog.of(context).showLoadingDialog(context, '兑换中');
Map<String, dynamic> params = {
'lotteryId': widget.isDouble ? 1 : 2,
'num': multiply,
};
params.putIfAbsent('item', () {
List<Map> item = [];
Map singleLottery = lotteryItem(101);
Map multiLottery = lotteryItem(102);
Map childLottery = lotteryItem(103);
if (singleLottery != null) item.add(lotteryItem(101));
if (multiLottery != null) item.add(lotteryItem(102));
if (childLottery != null) item.add(lotteryItem(103));
return item;
});
ResultData resultData = await HttpManager.post(
LotteryAPI.redeem_shots,
params,
);
if (resultData.data['code'] == "SUCCESS") {
Navigator.pop(context);
GSDialog.of(context).dismiss(context);
} else {
Navigator.pop(context);
GSDialog.of(context).dismiss(context);
showToast('兑换失败');
}
}
lotteryItem(int code) {
final models = widget.isDouble
? LotteryCartStore.doubleLotteryModels
: LotteryCartStore.bigLotteryModels;
List<String> lotteryCodes = [];
int money = 0;
models.forEach((element) {
if (element.lotteryTypeCode == code) {
lotteryCodes.add(convertCartBalls(element));
money += element.shots * 2;
}
});
return lotteryCodes.length == 0
? null
: {
'anteCode': lotteryCodes,
'playType': code,
'money': money,
};
}
}

@ -1,9 +1,8 @@
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:recook/constants/api.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/manager/http_manager.dart';
import 'package:recook/pages/lottery/lottery_cart_model.dart';
import 'package:recook/pages/lottery/lottery_cart_page.dart';
import 'package:recook/pages/lottery/lottery_history_page.dart';
import 'package:recook/pages/lottery/models/lottery_list_model.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
@ -88,7 +87,9 @@ class _LotteryPickerPageState extends State<LotteryPickerPage> {
title: Column(
children: [
Text(
widget.isDouble ? '双色球' : '大乐透',
'${widget.isDouble ? '双色球' : '大乐透'}${widget.lotteryListModel.now.number.substring(
widget.lotteryListModel.now.number.length - 3,
)}',
style: TextStyle(
color: Colors.white,
fontSize: rSP(18),
@ -447,20 +448,17 @@ class _LotteryPickerPageState extends State<LotteryPickerPage> {
_helpRandom1Shot();
_addOneShot();
_clearAllSelect();
AppRouter.push(context, RouteName.LOTTERY_CART_PAGE,
arguments: {'type': widget.isDouble})
CRoute.push(context, LotteryCartPage(isDouble: widget.isDouble))
.then((value) => setState(() {}));
} else if (emptySelect && !emptyCart) {
AppRouter.push(context, RouteName.LOTTERY_CART_PAGE,
arguments: {'type': widget.isDouble})
CRoute.push(context, LotteryCartPage(isDouble: widget.isDouble))
.then((value) => setState(() {}));
} else if (shotZero) {
showToast(widget.isDouble ? '至少选6红球1蓝球' : '至少选5红球2蓝球');
} else {
_addOneShot();
_clearAllSelect();
AppRouter.push(context, RouteName.LOTTERY_CART_PAGE,
arguments: {'type': widget.isDouble})
CRoute.push(context, LotteryCartPage(isDouble: widget.isDouble))
.then((value) => setState(() {}));
}
}

@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';
import 'package:recook/constants/api.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/manager/http_manager.dart';
@ -23,13 +24,17 @@ class RedeemLotteryPage extends StatefulWidget {
}
class _RedeemLotteryPageState extends State<RedeemLotteryPage> {
List<LotteryListModel> _models = [];
List<LotteryListModel> _models;
@override
void initState() {
super.initState();
HttpManager.post(LotteryAPI.list, {}).then((resultData) {
setState(() {
if (resultData.data['code'] == 'FAIL') {
showToast(resultData.data['mesg']);
_models = [];
}
_models = resultData.data['data'] == null
? []
: (resultData.data['data'] as List)
@ -56,7 +61,7 @@ class _RedeemLotteryPageState extends State<RedeemLotteryPage> {
),
),
],
body: _models.isEmpty
body: _models == null
? Center(
child: CircularProgressIndicator(),
)

@ -1,4 +1,7 @@
import 'package:flutter/widgets.dart';
import 'package:recook/constants/header.dart';
import 'package:recook/pages/lottery/lottery_cart_model.dart';
import 'package:recook/pages/lottery/redeem_lottery_page.dart';
///
///
@ -20,3 +23,66 @@ List<int> parseBalls(String balls, {bool red: true}) {
.toList();
}
}
String convertCartBalls(LotteryCartModel model) {
return convertBalls(
redBalls: model.redBalls,
blueBalls: model.blueBalls,
focusRedBalls: model.focusedRedBalls,
focusBlueBalls: model.focusedBlueBalls,
lotteryType: model.type,
);
}
///Convert
String convertBalls({
@required List<int> redBalls,
@required List<int> blueBalls,
List<int> focusRedBalls = const [],
List<int> focusBlueBalls = const [],
@required LotteryType lotteryType,
}) {
StringBuffer ballsBuffer = StringBuffer();
switch (lotteryType) {
case LotteryType.DOUBLE_LOTTERY:
if (focusRedBalls.isNotEmpty) {
ballsBuffer.write(ballsToString(focusRedBalls));
ballsBuffer.write('\$');
}
ballsBuffer.write(ballsToString(redBalls));
ballsBuffer.write('#');
ballsBuffer.write(ballsToString(blueBalls));
return ballsBuffer.toString();
break;
case LotteryType.BIG_LOTTERY:
return '';
break;
default:
return '';
}
}
///int => string
///
/// ball to string
String ballToString(int ball) {
return ball < 10 ? '0$ball' : '$ball';
}
///string => int
///
/// ball to int
int stringToBall(String ball) {
return int.parse(ball);
}
///List\<int\> => String
///
/// balls to String
String ballsToString(List<int> balls) {
String focusTemp = "";
balls.forEach((element) {
focusTemp += ",${ballToString(element)}";
});
return focusTemp.substring(1);
}

@ -69,12 +69,28 @@ class LotteryGridView extends StatelessWidget {
: Color(0xFF0E89E7),
borderRadius: BorderRadius.circular(rSize(16)),
),
child: Text(
_computeBallDisplayValue(value),
style: TextStyle(
color: Colors.white,
fontSize: rSP(17),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
_computeBallDisplayValue(value),
style: TextStyle(
color: Colors.white,
fontSize: rSP(14),
height: 1.02,
),
),
isFocused
? Text(
'',
style: TextStyle(
color: Colors.white,
fontSize: rSP(14),
height: 1.02,
),
)
: SizedBox(),
],
),
);
}

@ -324,9 +324,6 @@ class RouteName {
///
static const String LOTTERY_ORDER_DETAIL_PAGE = "/LotteryOrderDetailPage";
///
static const String LOTTERY_CART_PAGE = "/LotteryCartPage";
}
typedef RouteBuilder = Widget Function(BuildContext context,
@ -636,8 +633,6 @@ final Map<String, RouteBuilder> _routes = {
RouteName.LOTTERY_ORDER_PAGE: (context, {arguments}) => LotteryOrderPage(),
RouteName.LOTTERY_ORDER_DETAIL_PAGE: (context, {arguments}) =>
LotteryOrderDetailPage(arguments: arguments),
RouteName.LOTTERY_CART_PAGE: (context, {arguments}) =>
LotteryCartPage(arguments: arguments),
};
///

@ -188,10 +188,10 @@ class NormalContentDialog extends Dialog {
final NormalTextDialogType type;
NormalContentDialog({
this.title,
@required this.title,
this.content,
this.deleteItem,
this.items,
@required this.items,
this.listener,
this.deleteListener,
this.type = NormalTextDialogType.normal,

@ -366,12 +366,10 @@ packages:
flutter_slidable:
dependency: "direct main"
description:
path: "."
ref: "4073e1ff7db967aad4f97f0eee5909c5f8f339b5"
resolved-ref: "4073e1ff7db967aad4f97f0eee5909c5f8f339b5"
url: "https://github.com/haysuperman/flutter_slidable"
source: git
version: "0.5.4"
name: flutter_slidable
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.5.7"
flutter_spinkit:
dependency: "direct main"
description:

@ -150,11 +150,11 @@ dependencies:
flutter_datetime_picker: ^1.3.8
# 侧滑item
# flutter_slidable: 0.5.3
flutter_slidable:
git:
url: https://github.com/haysuperman/flutter_slidable
ref: 4073e1ff7db967aad4f97f0eee5909c5f8f339b5
flutter_slidable: 0.5.7
# flutter_slidable:
# git:
# url: https://github.com/haysuperman/flutter_slidable
# ref: 4073e1ff7db967aad4f97f0eee5909c5f8f339b5
# 图片选择
photo: 0.5.0-dev.3

Loading…
Cancel
Save