Browse Source

购物车,秒杀bug处理

zyh
w-R 3 years ago
parent
commit
16e7c313a5
  1. 172
      lib/retrofit/data/activity_area_list.dart
  2. 28
      lib/retrofit/min_api.dart
  3. 39
      lib/retrofit/min_api.g.dart
  4. 8
      lib/retrofit/retrofit_api.dart
  5. 2
      lib/retrofit/retrofit_api.g.dart
  6. 134
      lib/store/shopping/activity_prefecture_details.dart
  7. 11
      lib/store/shopping/shopping_cart/shopping_cart_page.dart
  8. 5
      lib/store/shopping/shopping_home/recommend_goods_list_view.dart
  9. 7
      lib/utils/flutter_utils.dart

172
lib/retrofit/data/activity_area_list.dart

File diff suppressed because one or more lines are too long

28
lib/retrofit/min_api.dart

@ -31,14 +31,14 @@ part 'min_api.g.dart';
// const base_url = "http://user.prod.kunqi.lotus-wallet.com/app/"; ///222
// const baseUrl = "http://user.prod.kunqi.lotus-wallet.com/app/"; ///222
const base_url = "http://192.168.10.236:8765/app/";///
const baseUrl = "http://192.168.10.236:8765/app/";///
// const base_url = "http://192.168.10.236:8765/app/";///
// const baseUrl = "http://192.168.10.236:8765/app/";///
// const base_url = "http://192.168.10.37:8766/app/";
// const baseUrl = "http://192.168.10.37:8766/app/";
// const base_url = "http://192.168.10.142:8765/app/";///
// const baseUrl = "http://192.168.10.142:8765/app/";///
const base_url = "http://192.168.10.142:8765/app/";///
const baseUrl = "http://192.168.10.142:8765/app/";///
///
@RestApi(baseUrl: baseUrl)
@ -168,7 +168,7 @@ abstract class MinApiService {
///
@PUT("shoppingcart/single")
Future<BaseData<List<ShoppingCart>>> shoppingCartSingle(@Body() Map<String, dynamic> param);
Future<BaseData> shoppingCartSingle(@Body() Map<String, dynamic> param);
///
@POST("order/getOrderInfo")
@ -215,8 +215,24 @@ abstract class MinApiService {
Future<BaseData<ShoppingHomeConfig>> homeConfig();
///,,,
@GET("/actTemplate/findActListByType?allDay={allDay}&type={type}")
@GET("actTemplate/findActListByType?allDay={allDay}&type={type}")
Future<BaseData<ActivityAreaList>> findActListByType(@Path("allDay") bool allDay,
@Path("type") String type);
// /// APP
// @GET("actTemplate/viewProduct?actProductId={actProductId}&type={type}")
// Future<BaseData<List<HomeRecommendList>>> viewProduct();
//
// ///
// @POST("actTemplate/actPay")
// Future<BaseData> actPay(@Body() Map<String, dynamic> param);
//
// ///
// @POST("actTemplate/joinAct")
// Future<BaseData> joinAct(@Body() Map<String, dynamic> param);
//
// ///
// @POST("actTemplate/launchAct")
// Future<BaseData> launchAct(@Body() Map<String, dynamic> param);
}

39
lib/retrofit/min_api.g.dart

@ -9,7 +9,7 @@ part of 'min_api.dart';
class _MinApiService implements MinApiService {
_MinApiService(this._dio, {this.baseUrl}) {
ArgumentError.checkNotNull(_dio, '_dio');
baseUrl ??= 'http://192.168.10.236:8765/app/';
baseUrl ??= 'http://192.168.10.142:8765/app/';
}
final Dio _dio;
@ -176,14 +176,13 @@ class _MinApiService implements MinApiService {
}
@override
Future<BaseData<List<ShoppingCart>>> shoppingCartSingle(param) async {
Future<BaseData<dynamic>> shoppingCartSingle(param) async {
ArgumentError.checkNotNull(param, 'param');
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(param ?? <String, dynamic>{});
final _result = await _dio.request<Map<String, dynamic>>(
'shoppingcart/single',
final _result = await _dio.request<Map<String, dynamic>>('shoppingcart/single',
queryParameters: queryParameters,
options: RequestOptions(
method: 'PUT',
@ -191,15 +190,14 @@ class _MinApiService implements MinApiService {
extra: _extra,
baseUrl: baseUrl),
data: _data);
final value = BaseData<List<ShoppingCart>>.fromJson(
final value = BaseData<dynamic>.fromJson(
_result.data,
(json) => (json as List<dynamic>)
.map<ShoppingCart>(
(i) => ShoppingCart.fromJson(i as Map<String, dynamic>))
.toList());
(json) => json as dynamic,
);
return value;
}
@override
Future<BaseData<SettleOrderInfo>> getOrderInfo(param) async {
ArgumentError.checkNotNull(param, 'param');
@ -467,4 +465,27 @@ class _MinApiService implements MinApiService {
return value;
}
// @override
// Future<BaseData<ActivityAreaList>> viewProduct (actProductId,type) async {
// ArgumentError.checkNotNull(actProductId, 'actProductId');
// ArgumentError.checkNotNull(type, 'type');
// const _extra = <String, dynamic>{};
// final queryParameters = <String, dynamic>{};
// final _data = <String, dynamic>{};
// final _result = await _dio.request<Map<String, dynamic>>(
// 'actTemplate/viewProduct?actProductId=$actProductId&type=$type',
// queryParameters: queryParameters,
// options: RequestOptions(
// method: 'GET',
// headers: <String, dynamic>{},
// extra: _extra,
// baseUrl: baseUrl),
// data: _data);
// final value = BaseData<ActivityAreaList>.fromJson(
// _result.data,
// (json) => ActivityAreaList.fromJson(json),
// );
// return value;
// }
}

8
lib/retrofit/retrofit_api.dart

@ -60,15 +60,15 @@ part 'retrofit_api.g.dart';
// const base_url = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222
// const baseUrl = "http://platform.prod.kunqi.lotus-wallet.com/app/"; ///222
const base_url = "http://192.168.10.236:8766/app/"; ///
const baseUrl = "http://192.168.10.236:8766/app/"; ///
// const base_url = "http://192.168.10.236:8766/app/"; ///
// const baseUrl = "http://192.168.10.236:8766/app/"; ///
// const base_url = "http://192.168.10.37:8766/app/";
// const baseUrl = "http://192.168.10.37:8766/app/";
// const base_url = "http://192.168.10.142:8766/app/";///
// const baseUrl = "http://192.168.10.142:8766/app/";///
const base_url = "http://192.168.10.142:8766/app/";///
const baseUrl = "http://192.168.10.142:8766/app/";///
@RestApi(baseUrl: baseUrl)
abstract class ApiService {

2
lib/retrofit/retrofit_api.g.dart

@ -9,7 +9,7 @@ part of 'retrofit_api.dart';
class _ApiService implements ApiService {
_ApiService(this._dio, {this.baseUrl}) {
ArgumentError.checkNotNull(_dio, '_dio');
baseUrl ??= 'http://192.168.10.236:8766/app/';
baseUrl ??= 'http://192.168.10.142:8766/app/';
}
final Dio _dio;

134
lib/store/shopping/activity_prefecture_details.dart

@ -12,6 +12,7 @@ import 'package:huixiang/retrofit/data/store_info.dart';
import 'package:huixiang/retrofit/min_api.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/view_widget/classic_header.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -21,6 +22,7 @@ class ActivityPrefectureDetails extends StatefulWidget {
final Map<String, dynamic> arguments;
ActivityPrefectureDetails({this.arguments});
@override
State<StatefulWidget> createState() {
return _ActivityPrefectureDetails();
@ -117,8 +119,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
storeId: storeId,
showLoading: false,
);
queryStoreInfo();
queryFindActListByType(pageType == "2" ? false : true);
EasyLoading.dismiss();
}
@ -127,8 +128,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
///
queryStoreInfo() async {
BaseData baseData = await apiService.queryStoreInfo(storeId).catchError((error) {
debugPrint(error);
BaseData baseData =
await apiService.queryStoreInfo(storeId).catchError((error) {
debugPrint(error.toString());
});
if (baseData != null && baseData.isSuccess) {
storeInfo = StoreInfo.fromJson(baseData.data);
@ -144,8 +146,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
/////
queryFindActListByType(allDay) async {
BaseData<ActivityAreaList> baseData =
await minService.findActListByType(allDay,pageType).catchError((error) {
BaseData<ActivityAreaList> baseData = await minService
.findActListByType(allDay, pageType)
.catchError((error) {
refreshController.refreshFailed();
});
setState(() {
@ -175,15 +178,14 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
///
startCountdownTimer() {
if(_timer != null)
return;
if (_timer != null) return;
const oneSec = const Duration(seconds: 1);
var callback = ((timer){
if(isDispose)
return;
var callback = ((timer) {
if (isDispose) return;
setState(() {
var tempDateTime = DateTime.parse(actTemplate.endTime).difference(DateTime.now());
if(tempDateTime.inSeconds <0){
var tempDateTime =
DateTime.parse(actTemplate.endTime).difference(DateTime.now());
if (tempDateTime.inSeconds < 0) {
tempDay = 0;
tempHour = 0;
tempM = 0;
@ -192,8 +194,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
}
tempDay = tempDateTime.inDays;
tempHour = tempDateTime.inHours - (tempDateTime.inDays * 24);
tempM = tempDateTime.inMinutes - (tempDateTime.inHours *60);
tempS = tempDateTime.inSeconds - (tempDateTime.inMinutes*60);
tempM = tempDateTime.inMinutes - (tempDateTime.inHours * 60);
tempS = tempDateTime.inSeconds - (tempDateTime.inMinutes * 60);
});
});
_timer = Timer.periodic(oneSec, callback);
@ -201,7 +203,19 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
return Container(
child: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
onRefresh: () {
setState(() {
queryFindActListByType(pageType == "2" ? false : true);
});
},
child:SingleChildScrollView(
physics: BouncingScrollPhysics(),
controller: _scrollController,
child: Column(
@ -212,6 +226,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
seckilList(),
],
),
),
),
);
}
@ -233,7 +249,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
child: Column(
children: [
swiper(),
pageType == "2"?(seckillIndex == 0
pageType == "2"
? (seckillIndex == 0
? Container(
width: double.infinity,
alignment: Alignment.center,
@ -264,10 +281,13 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
setState(() {
actTimeListIndex = position;
productList.clear();
productList.addAll(actTimeList[actTimeListIndex].productList);
productList.addAll(
actTimeList[actTimeListIndex]
.productList);
});
},
child: timeItem(actTimeList[position], position),
child:
timeItem(actTimeList[position], position),
);
},
)),
@ -408,7 +428,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
)
],
),
)) :Container(),
))
: Container(),
],
),
);
@ -422,7 +443,10 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
child: Stack(
children: [
Positioned(
top: 0,left: 0,right: 0,bottom: 0,
top: 0,
left: 0,
right: 0,
bottom: 0,
child: MImage(
actTemplate?.coverImg ?? "",
width: double.infinity,
@ -445,8 +469,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
),
),
),
pageType == "2" ?
Align(
pageType == "2"
? Align(
alignment: Alignment.topCenter,
child: Container(
margin: EdgeInsets.only(top: 52),
@ -455,7 +479,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
color: Color.fromRGBO(0, 0, 0, 69000000),
),
width: 160.w,
height:35.h,
height: 35.h,
child: Row(
children: [
GestureDetector(
@ -551,7 +575,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
],
),
),
) : Container(),
)
: Container(),
],
),
),
@ -566,19 +591,20 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
MediaQuery.of(context).padding.top,
padding: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 16.h),
color: Colors.white,
child: productList.length == 0 ?
Container(
child: productList.length == 0
? Container(
width: double.infinity,
alignment: Alignment.topCenter,
child:Text(
child: Text(
"暂无商品参与活动",
style: TextStyle(
fontSize:18.sp,
fontSize: 18.sp,
fontWeight: MyFontWeight.medium,
color: Colors.black,
),
),
):ListView.builder(
)
: ListView.builder(
padding: EdgeInsets.zero,
itemCount: productList?.length ?? 0,
scrollDirection: Axis.vertical,
@ -591,9 +617,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
Navigator.of(context).pushNamed(
'/router/shopping_goods_details',
arguments: {
"id":productList[position].id,
"storeId":storeId,
"tenant":tenant,
"id": productList[position].id,
"storeId": storeId,
"tenant": tenant,
},
);
});
@ -606,8 +632,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
}
int timeFlag(String time) {
if(time == null)
return 0;
if (time == null) return 0;
var now = DateTime.now().hour;
var tHour = int.tryParse(time.substring(0, 2));
if (now < tHour)
@ -752,7 +777,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
width: 12.w,
),
Expanded(
child:Column(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -774,7 +799,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
color: Color(0xFF4D4D4D),
),
),
if(pageType == "2")
if (pageType == "2")
Row(
children: [
ClipRRect(
@ -787,7 +812,13 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
color: Color(0xFFF5F5F5),
),
Container(
width:productList.sellCount == 0 ? 0 :(((productList?.sellCount ?? 0)/(productList?.productStock ?? 0)) * 180.w).toDouble(),
width: productList.sellCount == null
? 0
: (((productList?.sellCount ?? 0) /
(productList?.productStock ??
0)) *
180.w)
.toDouble(),
height: 8.h,
decoration: BoxDecoration(
gradient: LinearGradient(
@ -813,7 +844,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
),
],
),
if(pageType == "3")
if (pageType == "3")
Row(
children: [
Container(
@ -835,7 +866,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
Spacer(),
],
),
if(pageType == "1")
if (pageType == "1")
Container(
height: 22.h,
),
@ -849,7 +880,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
style: TextStyle(
fontSize: 14.sp,
fontWeight: MyFontWeight.semi_bold,
color: pageType == "3" ?Color(0xFF9476F7) : Color(0xFFFB2E2C),
color: pageType == "3"
? Color(0xFF9476F7)
: Color(0xFFFB2E2C),
),
),
TextSpan(
@ -857,7 +890,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
style: TextStyle(
fontSize: 18.sp,
fontWeight: MyFontWeight.semi_bold,
color:pageType == "3" ?Color(0xFF9476F7) : Color(0xFFFB2E2C),
color: pageType == "3"
? Color(0xFF9476F7)
: Color(0xFFFB2E2C),
),
),
],
@ -867,7 +902,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
child: Text(
productList.productPrice,
style: TextStyle(
fontSize:11.sp,
fontSize: 11.sp,
decoration: TextDecoration.lineThrough,
decorationColor: Color(0xFF353535),
fontWeight: MyFontWeight.regular,
@ -875,9 +910,9 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
),
),
),
if(pageType == "2")
(seckillIndex == 0 ?
(tStatus == 0
if (pageType == "2")
(seckillIndex == 0
? (tStatus == 0
? Container(
alignment: Alignment.center,
width: 60.w,
@ -953,7 +988,8 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
color: Color(0xFFADADAD),
),
),
))) : Container(
)))
: Container(
alignment: Alignment.center,
width: 60.w,
height: 24.h,
@ -978,7 +1014,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
),
),
)),
if(pageType == "1")
if (pageType == "1")
Container(
alignment: Alignment.center,
width: 60.w,
@ -1004,7 +1040,7 @@ class _ActivityPrefectureDetails extends State<ActivityPrefectureDetails> {
),
),
),
if(pageType == "3")
if (pageType == "3")
Container(
alignment: Alignment.center,
width: 60.w,

11
lib/store/shopping/shopping_cart/shopping_cart_page.dart

@ -53,10 +53,12 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
///
clearShopCar() async {
BaseData<bool> baseData = await minService.clearShoppingCart();
if (baseData.isSuccess) {
queryShopCar();
shopCarGoods[0].shoppingCartSkuItemList.forEach((element) {
if(element.selected == 1){
shopCartAdd(element,-element.buyNum,element.selected);
}
});
queryShopCar();
}
///
@ -154,7 +156,7 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
cartSkuItem.selected = selected;
shopCarTemp["selected"] = selected;
shopCarTemp["shoppingCartSkuItemList"] = [cartSkuItem.toJson()];
BaseData<List<ShoppingCart>> baseDate =
BaseData baseDate =
await minService.shoppingCartSingle(shopCarTemp);
if (baseDate.isSuccess) {
setState(() {
@ -267,6 +269,7 @@ class _ShoppingCartPage extends State<ShoppingCartPage>
isAllSelect = !isAllSelect;
shopCarGoods[0].shoppingCartSkuItemList.forEach((element) {
element.selected = isAllSelect?1:0;
shopCartAdd(element,0,element.selected);
});
});
},

5
lib/store/shopping/shopping_home/recommend_goods_list_view.dart

@ -145,14 +145,14 @@ class _RecommendGoodsListView extends State<RecommendGoodsListView> {
Container(
margin: EdgeInsets.only(top: 8, right: 8),
padding: EdgeInsets.only(left: 2, right: 2),
height: 17.h,
height: 18.h,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(2),
color: Color(0xFF5A5A5A),
),
child: Text(
homeRecommendList?.supplierName ?? "",
AppUtils.textSubStr(homeRecommendList?.supplierName ?? "",8),
style: TextStyle(
fontSize: 10.sp,
fontWeight: MyFontWeight.regular,
@ -226,4 +226,5 @@ class _RecommendGoodsListView extends State<RecommendGoodsListView> {
),
);
}
}

7
lib/utils/flutter_utils.dart

@ -164,4 +164,11 @@ class AppUtils {
}
}
}
static String textSubStr(String input, int length) {
length -= 1;
if(length < 0 || input.length < length)
return input;
return "${input.substring(0,length)}...";
}
}

Loading…
Cancel
Save