my_request.dart 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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/my_shop_bean_entity.dart';
  6. import 'package:bbyyy/beans/smart_order_bean_entity.dart';
  7. import 'package:bbyyy/beans/store_bean_entity.dart';
  8. import 'package:bbyyy/my_tools/const.dart';
  9. import 'package:bbyyy/my_tools/dims.dart';
  10. import 'package:bbyyy/my_tools/event_bus.dart';
  11. import 'package:bbyyy/my_tools/my_cookie.dart';
  12. import 'package:bbyyy/my_tools/my_tools.dart';
  13. import 'package:bbyyy/my_tools/my_views.dart';
  14. import 'package:dio/dio.dart';
  15. import 'package:flutter/material.dart';
  16. import 'MyDio.dart';
  17. //上传文件
  18. upload(File file, SCallBack sCallBack, FCallBack fCallBack) async {
  19. var s = '/file/upload';
  20. logger.info(MyCookie().getServer() + s);
  21. var name =
  22. file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
  23. print(file.path);
  24. FormData formData = new FormData.fromMap({
  25. 'files': await MultipartFile.fromFile(
  26. file.path,
  27. filename: name,
  28. ),
  29. });
  30. print(formData.files.toString());
  31. MyDio().post(s, formData, sCallBack, fCallBack);
  32. }
  33. uploadFiles(List<File> files, SCallBack sCallBack, FCallBack fCallBack) async {
  34. var s = '/file/upload';
  35. logger.info(MyCookie().getServer() + s);
  36. FormData formData = new FormData();
  37. files.forEach((file) async {
  38. var name =
  39. file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
  40. print(file.path);
  41. formData.files.add(MapEntry(
  42. "files",
  43. MultipartFile.fromFileSync(file.path, filename: name),
  44. ));
  45. });
  46. MyDio().post(s, formData, sCallBack, fCallBack);
  47. }
  48. //注册
  49. registeredAccountNumber(data, SCallBack sCallBack, FCallBack fCallBack) {
  50. MyDio().post('/model/registerUser', data, sCallBack, fCallBack);
  51. }
  52. //登录账号
  53. loginAccount(data, SCallBack sCallBack, FCallBack fCallBack) {
  54. MyDio().post('/ap/login', data, sCallBack, fCallBack);
  55. }
  56. //检查登录
  57. checkLogin(SCallBack sCallBack, FCallBack fCallBack) {
  58. MyDio().post(
  59. '/ap/checkLogin',
  60. {
  61. '__user__': MyCookie().getUser(),
  62. 'version': MyCookie().packageInfo.version,
  63. 'phone': Platform.isAndroid ? 'Android' : 'IOS'
  64. },
  65. sCallBack,
  66. fCallBack);
  67. }
  68. //发送消息
  69. sendMsg(String type, int receiverUid, String content, SCallBack sCallBack,
  70. FCallBack fCallBack) {
  71. MyDio().post(
  72. '/chat/send',
  73. {
  74. 'type': type,
  75. 'receiver_uid': receiverUid,
  76. 'sender_uid': MyCookie().getUID(),
  77. 'content': content,
  78. },
  79. sCallBack,
  80. fCallBack);
  81. }
  82. //撤回消息
  83. revokeMsg(
  84. String uuid, int receiverUid, SCallBack sCallBack, FCallBack fCallBack) {
  85. MyDio().post(
  86. '/chat/revoke',
  87. {
  88. 'uuid': uuid,
  89. 'receiver_uid': receiverUid,
  90. 'sender_uid': MyCookie().getUID()
  91. },
  92. sCallBack,
  93. fCallBack);
  94. }
  95. //提交申请
  96. submitApplication(StoreBeanDataData data) {
  97. MyDio().save({
  98. 'key': 'shop_user',
  99. 'object': {'user_uid': MyCookie().getUID(), 'shop_uid': data.uid, 'role': 2}
  100. }, (response, hasError) {
  101. if (!hasError) {
  102. showToast('申请已提交');
  103. }
  104. }, (error) {});
  105. }
  106. //重置订单
  107. resetOrder(int orderUID) {
  108. MyDio().post('/pay/cancelPayOrder', {'order_uid': orderUID},
  109. (response, hasError) {}, (error) {});
  110. }
  111. //删除订单
  112. revokePayOrder(int orderUID) {
  113. MyDio().post('/pay/revokePayOrder', {'order_uid': orderUID},
  114. (response, hasError) {}, (error) {});
  115. }
  116. //检查更新
  117. checkForUpdates(BuildContext context, {bool showT = false}) {
  118. //TODO:
  119. MyDio().query({
  120. "key": "android_app",
  121. "dims": ["id", "version", "download", "size", "force"],
  122. "filters": {}
  123. }, (response, hasError) {
  124. if (!hasError) {
  125. AndroidAppVersionBeanEntity entity = AndroidAppVersionBeanEntity()
  126. .fromJson(json.decode(response.data.toString()));
  127. print(
  128. '${entity.data[0].version} -- ${MyCookie().packageInfo.version}=====${'${entity.data[0].version}'.compareTo('${MyCookie().packageInfo.version}')}');
  129. if (entity.data[0].version.compareTo(MyCookie().packageInfo.version) ==
  130. 1) {
  131. updateDialog(entity.data[0], context);
  132. } else {
  133. if (showT) {
  134. showToast('当前已是最新版本');
  135. }
  136. }
  137. }
  138. }, (error) {});
  139. }
  140. //广告定价
  141. advertisingPricing(SCallBack sCallBack) {
  142. MyDio().query({
  143. "key": "ad_pricing",
  144. "dims": ["id", "type", "pricing", "left"],
  145. "filters": {}
  146. }, sCallBack, (error) {});
  147. }
  148. //首页轮播
  149. homeCarousel() {
  150. MyDio().query({
  151. "key": "carousel",
  152. "dims": ["id", "page", "path"],
  153. "filters": {
  154. 'conditions': ['page == 1']
  155. }
  156. }, (response, hasError) {
  157. if (!hasError) {
  158. HomeCarouselBeanEntity entity = HomeCarouselBeanEntity()
  159. .fromJson(json.decode(response.data.toString()));
  160. EventBus().emit('homeCarousel', entity);
  161. }
  162. }, (error) {});
  163. }
  164. //抢优惠券
  165. grabACoupon(int id) {
  166. MyDio().post(
  167. '/model/applyForCoupon',
  168. {'id': id, 'user_uid': MyCookie().getUID()},
  169. (response, hasError) {},
  170. (error) {});
  171. }
  172. //查询第三方未付订单
  173. void checkUnpaidThirdPartyOrders() {
  174. var dJson;
  175. var conditions1 = [
  176. "role!=$shopUserOwner",
  177. "user_uid==${MyCookie().getUID()}",
  178. "review_state==1"
  179. ];
  180. var conditions2 = [
  181. "role==$shopUserOwner",
  182. "user_uid==${MyCookie().getUID()}"
  183. ];
  184. conditions1.add('private_shop==true');
  185. dJson = {
  186. "key": "shop_user",
  187. "filters": {
  188. "or": true,
  189. "conditions": conditions1,
  190. "filters": [
  191. {"conditions": conditions2}
  192. ]
  193. },
  194. "dims": shopUserDims,
  195. "paging": [1, 1000],
  196. "order_by": ["shop_name,DESC"]
  197. };
  198. MyDio().query(dJson, (response, hasError) {
  199. if (!hasError) {
  200. MyShopBeanEntity entity =
  201. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  202. List<int> myShopUIDs = [];
  203. entity.data.data.forEach((element) {
  204. myShopUIDs.add(element.shopUid);
  205. });
  206. MyDio().query({
  207. "key": "order",
  208. "filters": {
  209. "or": true,
  210. "conditions": [
  211. "state == $orderStateUnpaid",
  212. 'buyer_uid==0',
  213. 'buyer_name LIKE ${MyCookie().getName()}',
  214. 'shop_uid IN $myShopUIDs'
  215. ],
  216. "filters": [
  217. {
  218. "conditions": [
  219. "state == $orderStateUnpaid",
  220. 'buyer_uid==${MyCookie().getUID()}'
  221. ]
  222. }
  223. ]
  224. },
  225. "dims": orderDims,
  226. "paging": [1, 20],
  227. "order_by": ["create_time,DESC"]
  228. }, (response, hasError) {
  229. if (!hasError) {
  230. SmartOrderBeanEntity entity = SmartOrderBeanEntity()
  231. .fromJson(json.decode(response.data.toString()));
  232. MyCookie().haveNoPay = entity.data.data.isNotEmpty;
  233. EventBus().emit('hasNoPay');
  234. }
  235. }, (error) {});
  236. }
  237. }, (error) {});
  238. }