my_request.dart 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. 'seq': int.parse(MyCookie().prefs.getString('serverID'))
  65. },
  66. sCallBack,
  67. fCallBack);
  68. }
  69. //发送消息
  70. sendMsg(String type, int receiverUid, String content, SCallBack sCallBack,
  71. FCallBack fCallBack) {
  72. MyDio().post(
  73. '/chat/send',
  74. {
  75. 'type': type,
  76. 'receiver_uid': receiverUid,
  77. 'sender_uid': MyCookie().getUID(),
  78. 'content': content,
  79. },
  80. sCallBack,
  81. fCallBack);
  82. }
  83. //撤回消息
  84. revokeMsg(
  85. String uuid, int receiverUid, SCallBack sCallBack, FCallBack fCallBack) {
  86. MyDio().post(
  87. '/chat/revoke',
  88. {
  89. 'uuid': uuid,
  90. 'receiver_uid': receiverUid,
  91. 'sender_uid': MyCookie().getUID()
  92. },
  93. sCallBack,
  94. fCallBack);
  95. }
  96. //提交申请
  97. submitApplication(StoreBeanDataData data) {
  98. MyDio().save({
  99. 'key': 'shop_user',
  100. 'object': {'user_uid': MyCookie().getUID(), 'shop_uid': data.uid, 'role': 2}
  101. }, (response, hasError) {
  102. if (!hasError) {
  103. showToast('申请已提交');
  104. }
  105. }, (error) {});
  106. }
  107. //重置订单
  108. resetOrder(int orderUID) {
  109. MyDio().post('/pay/cancelPayOrder', {'order_uid': orderUID},
  110. (response, hasError) {}, (error) {});
  111. }
  112. //删除订单
  113. revokePayOrder(int orderUID) {
  114. MyDio().post('/pay/revokePayOrder', {'order_uid': orderUID},
  115. (response, hasError) {}, (error) {});
  116. }
  117. //检查更新
  118. checkForUpdates(BuildContext context, {bool showT = false}) {
  119. //TODO:
  120. MyDio().query({
  121. "key": "android_app",
  122. "dims": ["id", "version", "download", "size", "force"],
  123. "filters": {}
  124. }, (response, hasError) {
  125. if (!hasError) {
  126. AndroidAppVersionBeanEntity entity = AndroidAppVersionBeanEntity()
  127. .fromJson(json.decode(response.data.toString()));
  128. print(
  129. '${entity.data[0].version} -- ${MyCookie().packageInfo.version}=====${'${entity.data[0].version}'.compareTo('${MyCookie().packageInfo.version}')}');
  130. if (entity.data[0].version.compareTo(MyCookie().packageInfo.version) ==
  131. 1) {
  132. updateDialog(entity.data[0], context);
  133. } else {
  134. if (showT) {
  135. showToast('当前已是最新版本');
  136. }
  137. }
  138. }
  139. }, (error) {});
  140. }
  141. //广告定价
  142. advertisingPricing(SCallBack sCallBack) {
  143. MyDio().query({
  144. "key": "ad_pricing",
  145. "dims": ["id", "type", "pricing", "left"],
  146. "filters": {}
  147. }, sCallBack, (error) {});
  148. }
  149. //首页轮播
  150. homeCarousel() {
  151. MyDio().query({
  152. "key": "carousel",
  153. "dims": ["id", "page", "path"],
  154. "filters": {
  155. 'conditions': ['page == 1']
  156. }
  157. }, (response, hasError) {
  158. if (!hasError) {
  159. HomeCarouselBeanEntity entity = HomeCarouselBeanEntity()
  160. .fromJson(json.decode(response.data.toString()));
  161. EventBus().emit('homeCarousel', entity);
  162. }
  163. }, (error) {});
  164. }
  165. //抢优惠券
  166. grabACoupon(int id) {
  167. MyDio().post(
  168. '/model/applyForCoupon',
  169. {'id': id, 'user_uid': MyCookie().getUID()},
  170. (response, hasError) {},
  171. (error) {});
  172. }
  173. //查询第三方未付订单
  174. void checkUnpaidThirdPartyOrders() {
  175. var dJson;
  176. var conditions1 = [
  177. "role!=$shopUserOwner",
  178. "user_uid==${MyCookie().getUID()}",
  179. "review_state==1"
  180. ];
  181. var conditions2 = [
  182. "role==$shopUserOwner",
  183. "user_uid==${MyCookie().getUID()}"
  184. ];
  185. conditions1.add('private_shop==true');
  186. dJson = {
  187. "key": "shop_user",
  188. "filters": {
  189. "or": true,
  190. "conditions": conditions1,
  191. "filters": [
  192. {"conditions": conditions2}
  193. ]
  194. },
  195. "dims": shopUserDims,
  196. "paging": [1, 1000],
  197. "order_by": ["shop_name,DESC"]
  198. };
  199. MyDio().query(dJson, (response, hasError) {
  200. if (!hasError) {
  201. MyShopBeanEntity entity =
  202. MyShopBeanEntity().fromJson(json.decode(response.data.toString()));
  203. List<int> myShopUIDs = [];
  204. entity.data.data.forEach((element) {
  205. myShopUIDs.add(element.shopUid);
  206. });
  207. if(myShopUIDs.length==0){
  208. return;
  209. }
  210. MyDio().query({
  211. "key": "order",
  212. "filters": {
  213. "or": true,
  214. "conditions": [
  215. "state == $orderStateUnpaid",
  216. 'buyer_uid==0',
  217. 'buyer_name LIKE ${MyCookie().getName()}',
  218. 'shop_uid IN $myShopUIDs'
  219. ],
  220. "filters": [
  221. {
  222. "conditions": [
  223. "state == $orderStateUnpaid",
  224. 'buyer_uid==${MyCookie().getUID()}'
  225. ]
  226. }
  227. ]
  228. },
  229. "dims": orderDims,
  230. "paging": [1, 20],
  231. "order_by": ["create_time,DESC"]
  232. }, (response, hasError) {
  233. if (!hasError) {
  234. SmartOrderBeanEntity entity = SmartOrderBeanEntity()
  235. .fromJson(json.decode(response.data.toString()));
  236. MyCookie().haveNoPay = entity.data.data.isNotEmpty;
  237. EventBus().emit('hasNoPay');
  238. }
  239. }, (error) {});
  240. }
  241. }, (error) {});
  242. }