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