提交 0742a081 authored 作者: yueweilu's avatar yueweilu

提交书豆支付订单

上级 a6bc143c
......@@ -163,4 +163,29 @@ abstract class CommonAPI {
return result.data['filesUrl'];
}
/// 11、创建订单
///
static Future <PayOrderModel> createOrder({
required String bookIdsList,
required String totalPrice,
required String couponRecId,
required String integral,
required String type
}) async {
final result = await HttpService.to.post(
'/v1/orders/Orders/createOrders',
params: {
'book_ids_list':bookIdsList,
'total_price':totalPrice,
'coupon_rec_id':couponRecId,
'integral':integral,
'type':type,
},
);
if (result.data is! Map) return PayOrderModel();
return PayOrderModel.fromJson(result.data);
}
}
\ No newline at end of file
......@@ -149,3 +149,71 @@ class CouponNumModel {
}
}
/// 创建订单模型
class PayOrderModel {
PayOrderModel({
this.appid,
this.partnerid,
this.prepayid,
this.package,
this.noncestr,
this.timestamp,
this.sign,
this.ordersnum,
this.encryptionOrder,});
PayOrderModel.fromJson(dynamic json) {
appid = json['appid'];
partnerid = json['partnerid'];
prepayid = json['prepayid'];
package = json['package'];
noncestr = json['noncestr'];
timestamp = json['timestamp'];
sign = json['sign'];
ordersnum = json['ordersnum'];
encryptionOrder = json['encryption_order'];
}
String? appid;
String? partnerid;
String? prepayid;
String? package;
String? noncestr;
num? timestamp;
String? sign;
String? ordersnum;
String? encryptionOrder;
PayOrderModel copyWith({ String? appid,
String? partnerid,
String? prepayid,
String? package,
String? noncestr,
num? timestamp,
String? sign,
String? ordersnum,
String? encryptionOrder,
}) => PayOrderModel( appid: appid ?? this.appid,
partnerid: partnerid ?? this.partnerid,
prepayid: prepayid ?? this.prepayid,
package: package ?? this.package,
noncestr: noncestr ?? this.noncestr,
timestamp: timestamp ?? this.timestamp,
sign: sign ?? this.sign,
ordersnum: ordersnum ?? this.ordersnum,
encryptionOrder: encryptionOrder ?? this.encryptionOrder,
);
Map<String, dynamic> toJson() {
final map = <String, dynamic>{};
map['appid'] = appid;
map['partnerid'] = partnerid;
map['prepayid'] = prepayid;
map['package'] = package;
map['noncestr'] = noncestr;
map['timestamp'] = timestamp;
map['sign'] = sign;
map['ordersnum'] = ordersnum;
map['encryption_order'] = encryptionOrder;
return map;
}
}
\ No newline at end of file
......@@ -2,10 +2,10 @@ part of book_pay;
class BookPayController extends GetxController {
// 购物车选中的书籍列表
final List<CourseModel>? buy;
BookPayController({this.buy});
final List<CourseModel> buy;
BookPayController({required this.buy});
// 积分模型
CreditPointModel creditPointModel = CreditPointModel();
CreditPointModel creditPointModel = CreditPointModel(deductibleIntegral: 0);
// 是否展示优惠券和积分模型
ShowModel showModel = ShowModel();
......@@ -14,7 +14,9 @@ class BookPayController extends GetxController {
// 优惠券可用不可用数量模型
CouponNumModel couponNumModel = CouponNumModel();
// 选择的优惠券模型
late CouponModel useCouponModel = CouponModel(couponId: 0,reducedPrice: '0.00');
late CouponModel useCouponModel = CouponModel(couponId: 0,reducedPrice: '0.00',couponRecId: 0);
// 创建订单模型
late PayOrderModel payOrderModel;
// 支付方式
List<PayModel> pays = Platform.isIOS ?[
......@@ -30,8 +32,8 @@ class BookPayController extends GetxController {
// 优惠前的原始价钱
late double originalPrice = getOriginalPrice();
late double finalPrice = 0.00;
// late double finalPrice = 0.00;
Decimal finalPrice = Decimal.zero;
@override
......@@ -119,17 +121,43 @@ class BookPayController extends GetxController {
/// 获取优惠后的价格
void computeFinalPrice(){
finalPrice = originalPrice;
finalPrice = Decimal.parse(originalPrice.toString());
if (useCreditPoint){
finalPrice = finalPrice - Decimal.parse(creditPointModel.deductibleAmount??'0.00').toDouble();
finalPrice = finalPrice - Decimal.parse(creditPointModel.deductibleAmount??'0.00');
}
// 不等0的时候证明使用了 优惠券
if (useCouponModel.couponId !=0){
finalPrice = finalPrice - Decimal.parse(useCouponModel.reducedPrice??'0.00').toDouble();
finalPrice = finalPrice - Decimal.parse(useCouponModel.reducedPrice??'0.00');
}
update();
}
/// 创建订单
void createOrder() async {
List<Map<String, dynamic>> bookIdsList = [];
for (CourseModel model in buy){
Map<String, dynamic> tempMap = {
'book_id': model.bookId,
'price': model.price,
'cart_id': model.cartId,
};
bookIdsList.add(tempMap);
}
final result = await CommonAPI.createOrder(
bookIdsList:jsonEncode(bookIdsList) ,
totalPrice: finalPrice.toString(),
couponRecId: useCouponModel.couponRecId.toString(),
integral: creditPointModel.deductibleIntegral.toString(),
type: payModel.type.toString()
);
payOrderModel = result;
}
}
\ No newline at end of file
library book_pay;
import 'dart:convert';
import 'dart:core';
import 'package:decimal/decimal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_book/apis/index.dart';
......
......@@ -104,7 +104,7 @@ class _BookPayPageState extends State<BookPayPage> {
bottomNavigationBar: SafeArea(child:BuildPayCount(
payTap: (){
Console.log('--------------支付------------------');
controller.createOrder();
},
showTap: (){
controller.show();
......
......@@ -15,7 +15,7 @@ class BuildPayCount extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetBuilder<BookPayController>(
init: BookPayController(),
init: BookPayController(buy: []),
builder:(controller)=> Container(
padding: EdgeInsets.symmetric(horizontal: 15.w),
height: 55.w,
......
......@@ -13,7 +13,7 @@ class CreditPointsPage extends StatelessWidget {
return false;
},
child: GetBuilder<BookPayController>(
init: BookPayController(),
init: BookPayController(buy: []),
builder:(controller)=> Scaffold(
extendBodyBehindAppBar: true,
appBar: AppBar(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论