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.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. MyApis.getApi('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. }