my_request.dart 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/android_app_version_bean_entity.dart';
  4. import 'package:bbyyy/beans/home_carousel_bean_entity.dart';
  5. import 'package:bbyyy/beans/store_bean_entity.dart';
  6. import 'package:bbyyy/my_tools/event_bus.dart';
  7. import 'package:bbyyy/my_tools/my_cookie.dart';
  8. import 'package:bbyyy/my_tools/my_tools.dart';
  9. import 'package:bbyyy/my_tools/my_views.dart';
  10. import 'package:dio/dio.dart';
  11. import 'package:flutter/material.dart';
  12. import 'MyDio.dart';
  13. //上传文件
  14. upload(File file, SCallBack sCallBack, FCallBack fCallBack) async {
  15. var s = '/file/upload';
  16. logger.info(MyCookie().getServer() + s);
  17. var name =
  18. file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
  19. print(file.path);
  20. FormData formData = new FormData.fromMap({
  21. 'files': await MultipartFile.fromFile(
  22. file.path,
  23. filename: name,
  24. ),
  25. });
  26. print(formData.files.toString());
  27. MyDio().post(s, formData, sCallBack, fCallBack);
  28. }
  29. uploadFiles(List<File> files, SCallBack sCallBack, FCallBack fCallBack) async {
  30. var s = '/file/upload';
  31. logger.info(MyCookie().getServer() + s);
  32. FormData formData = new FormData();
  33. files.forEach((file) async {
  34. var name =
  35. file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
  36. print(file.path);
  37. formData.files.add(
  38. MapEntry(
  39. "files",
  40. MultipartFile.fromFileSync(file.path,
  41. filename: name),
  42. ));
  43. });
  44. MyDio().post(s, formData, sCallBack, fCallBack);
  45. }
  46. //注册
  47. registeredAccountNumber(data, SCallBack sCallBack, FCallBack fCallBack) {
  48. MyDio().post('/model/registerUser', data, sCallBack, fCallBack);
  49. }
  50. //登录账号
  51. loginAccount(data, SCallBack sCallBack, FCallBack fCallBack) {
  52. MyDio().post('/ap/login', data, sCallBack, fCallBack);
  53. }
  54. //检查登录
  55. checkLogin(SCallBack sCallBack, FCallBack fCallBack) {
  56. MyDio().post('/ap/checkLogin', {'__user__': MyCookie().getUser(),
  57. 'version':MyCookie().packageInfo.version}, sCallBack,
  58. fCallBack);
  59. }
  60. //发送消息
  61. sendMsg(String type, int receiverUid, String content, SCallBack sCallBack,
  62. FCallBack fCallBack) {
  63. MyDio().post(
  64. '/chat/send',
  65. {
  66. 'type': type,
  67. 'receiver_uid': receiverUid,
  68. 'sender_uid': MyCookie().getUID(),
  69. 'content': content,
  70. },
  71. sCallBack,
  72. fCallBack);
  73. }
  74. //撤回消息
  75. revokeMsg(
  76. String uuid, int receiverUid, SCallBack sCallBack, FCallBack fCallBack) {
  77. MyDio().post(
  78. '/chat/revoke',
  79. {
  80. 'uuid': uuid,
  81. 'receiver_uid': receiverUid,
  82. 'sender_uid': MyCookie().getUID()
  83. },
  84. sCallBack,
  85. fCallBack);
  86. }
  87. //提交申请
  88. submitApplication(StoreBeanDataData data) {
  89. MyDio().save({
  90. 'key': 'shop_user',
  91. 'object': {'user_uid': MyCookie().getUID(), 'shop_uid': data.uid, 'role': 2}
  92. }, (response, hasError) {
  93. if (!hasError) {
  94. showToast('申请已提交');
  95. }
  96. }, (error) {});
  97. }
  98. //重置订单
  99. resetOrder(int orderUID) {
  100. MyDio().post('/pay/cancelPayOrder', {'order_uid': orderUID},
  101. (response, hasError) {}, (error) {});
  102. }
  103. //删除订单
  104. revokePayOrder(int orderUID) {
  105. MyDio().post('/pay/revokePayOrder', {'order_uid': orderUID},
  106. (response, hasError) {}, (error) {});
  107. }
  108. //检查更新
  109. checkForUpdates(BuildContext context, {bool showT = false}) {
  110. //TODO:
  111. MyDio().query({
  112. "key": "android_app",
  113. "dims": ["id", "version", "download", "size", "force"],
  114. "filters": {}
  115. }, (response, hasError) {
  116. if (!hasError) {
  117. AndroidAppVersionBeanEntity entity = AndroidAppVersionBeanEntity()
  118. .fromJson(json.decode(response.data.toString()));
  119. print(
  120. '${entity.data[0].version} -- ${MyCookie().packageInfo.version}=====${'${entity.data[0].version}'.compareTo('${MyCookie().packageInfo.version}')}');
  121. if (entity.data[0].version.compareTo(MyCookie().packageInfo.version) ==
  122. 1) {
  123. updateDialog(entity.data[0], context);
  124. } else {
  125. if (showT) {
  126. showToast('当前已是最新版本');
  127. }
  128. }
  129. }
  130. }, (error) {});
  131. }
  132. //广告定价
  133. advertisingPricing(SCallBack sCallBack) {
  134. MyDio().query({
  135. "key": "ad_pricing",
  136. "dims": ["id", "type", "pricing", "left"],
  137. "filters": {}
  138. }, sCallBack, (error) {});
  139. }
  140. //首页轮播
  141. homeCarousel() {
  142. MyDio().query({
  143. "key": "carousel",
  144. "dims": ["id", "page", "path"],
  145. "filters": {
  146. 'conditions': ['page == 1']
  147. }
  148. }, (response, hasError) {
  149. if (!hasError) {
  150. HomeCarouselBeanEntity entity = HomeCarouselBeanEntity()
  151. .fromJson(json.decode(response.data.toString()));
  152. EventBus().emit('homeCarousel', entity);
  153. }
  154. }, (error) {});
  155. }
  156. //抢优惠券
  157. grabACoupon(int id) {
  158. MyDio().post(
  159. '/model/applyForCoupon',
  160. {'id': id, 'user_uid': MyCookie().getUID()},
  161. (response, hasError) {},
  162. (error) {});
  163. }