| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import 'dart:convert';
- import 'dart:io';
- import 'package:bbyyy/beans/android_app_version_bean_entity.dart';
- import 'package:bbyyy/beans/home_carousel_bean_entity.dart';
- import 'package:bbyyy/beans/my_shop_bean_entity.dart';
- import 'package:bbyyy/beans/smart_order_bean_entity.dart';
- import 'package:bbyyy/beans/store_bean_entity.dart';
- import 'package:bbyyy/my_tools/const.dart';
- import 'package:bbyyy/my_tools/dims.dart';
- import 'package:bbyyy/my_tools/event_bus.dart';
- import 'package:bbyyy/my_tools/my_apis.dart';
- import 'package:bbyyy/my_tools/my_cookie.dart';
- import 'package:bbyyy/my_tools/my_tools.dart';
- import 'package:bbyyy/my_tools/my_views.dart';
- import 'package:dio/dio.dart';
- import 'package:flutter/material.dart';
- import 'MyDio.dart';
- //上传文件
- upload(File file, SCallBack sCallBack, FCallBack fCallBack) async {
- var s = MyApis.getApi('upload');
- logger.info(MyCookie().getServer() + s);
- var name =
- file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
- print(file.path);
- FormData formData = new FormData.fromMap({
- 'files': await MultipartFile.fromFile(
- file.path,
- filename: name,
- ),
- });
- print(formData.files.toString());
- MyDio().post(s, formData, sCallBack, fCallBack);
- }
- uploadFiles(List<File> files, SCallBack sCallBack, FCallBack fCallBack) async {
- var s = MyApis.getApi('upload');
- logger.info(MyCookie().getServer() + s);
- FormData formData = new FormData();
- files.forEach((file) async {
- var name =
- file.path.substring(file.path.lastIndexOf("/") + 1, file.path.length);
- print(file.path);
- formData.files.add(MapEntry(
- "files",
- MultipartFile.fromFileSync(file.path, filename: name),
- ));
- });
- MyDio().post(s, formData, sCallBack, fCallBack);
- }
- //注册
- registeredAccountNumber(data, SCallBack sCallBack, FCallBack fCallBack) {
- MyDio().post(MyApis.getApi('registerUser'), data, sCallBack, fCallBack);
- }
- //登录账号
- loginAccount(data, SCallBack sCallBack, FCallBack fCallBack) {
- MyDio().post(MyApis.getApi('login'), data, sCallBack, fCallBack);
- }
- //检查登录
- checkLogin(SCallBack sCallBack, FCallBack fCallBack) {
- MyDio().post(
- MyApis.getApi('checkLogin'),
- {
- 'user': MyCookie().getUser(),
- 'version': MyCookie().packageInfo.version,
- 'phone': Platform.isAndroid ? 'Android' : 'IOS',
- 'seq': int.parse(MyCookie().prefs.getString('serverID'))
- },
- sCallBack,
- fCallBack);
- }
- //发送消息
- sendMsg(String type, int receiverUid, String content, SCallBack sCallBack,
- FCallBack fCallBack) {
- MyDio().post(
- MyApis.getApi('send'),
- {
- 'type': type,
- 'receiver_uid': receiverUid,
- 'sender_uid': MyCookie().getUID(),
- 'content': content,
- },
- sCallBack,
- fCallBack);
- }
- //撤回消息
- revokeMsg(
- String uuid, int receiverUid, SCallBack sCallBack, FCallBack fCallBack) {
- MyDio().post(
- MyApis.getApi('revoke'),
- {
- 'uuid': uuid,
- 'receiver_uid': receiverUid,
- 'sender_uid': MyCookie().getUID()
- },
- sCallBack,
- fCallBack);
- }
- //提交申请
- submitApplication(StoreBeanDataData data) {
- MyDio().save({
- 'key': 'shop_user',
- 'object': {'user_uid': MyCookie().getUID(), 'shop_uid': data.uid, 'role': 2}
- }, (response, hasError) {
- if (!hasError) {
- showToast('申请已提交');
- }
- }, (error) {});
- }
- //重置订单
- resetOrder(int orderUID) {
- MyDio().post(MyApis.getApi('cancelPayOrder'), {'order_uid': orderUID},
- (response, hasError) {}, (error) {});
- }
- //删除订单
- revokePayOrder(int orderUID) {
- MyDio().post(MyApis.getApi('revokePayOrder'), {'order_uid': orderUID},
- (response, hasError) {}, (error) {});
- }
- //检查更新
- checkForUpdates(BuildContext context, {bool showT = false}) {
- //TODO:
- MyDio().query({
- "key": "android_app",
- "dims": ["id", "version", "download", "size", "force"],
- "filters": {}
- }, (response, hasError) {
- if (!hasError) {
- AndroidAppVersionBeanEntity entity =AndroidAppVersionBeanEntity.fromJson(json.decode(response.data.toString()));
- print(
- '${entity.data[0].version} -- ${MyCookie().packageInfo.version}=====${'${entity.data[0].version}'.compareTo('${MyCookie().packageInfo.version}')}');
- if (entity.data[0].version.compareTo(MyCookie().packageInfo.version) ==
- 1) {
- updateDialog(entity.data[0], context);
- } else {
- if (showT) {
- showToast('当前已是最新版本');
- }
- }
- }
- }, (error) {});
- }
- //广告定价
- advertisingPricing(SCallBack sCallBack) {
- MyDio().query({
- "key": "ad_pricing",
- "dims": ["id", "type", "pricing", "left"],
- "filters": {}
- }, sCallBack, (error) {});
- }
- //首页轮播
- homeCarousel() {
- MyDio().query({
- "key": "carousel",
- "dims": ["id", "page", "path"],
- "filters": {
- 'conditions': ['page == 1']
- }
- }, (response, hasError) {
- if (!hasError) {
- HomeCarouselBeanEntity entity = HomeCarouselBeanEntity
- .fromJson(json.decode(response.data.toString()));
- EventBus().emit('homeCarousel', entity);
- }
- }, (error) {});
- }
- //抢优惠券
- grabACoupon(int id) {
- MyDio().post(
- MyApis.getApi('applyForCoupon'),
- {'id': id, 'user_uid': MyCookie().getUID()},
- (response, hasError) {},
- (error) {});
- }
- //查询第三方未付订单
- void checkUnpaidThirdPartyOrders() {
- var dJson;
- var conditions1 = [
- "role!=$shopUserOwner",
- "user_uid==${MyCookie().getUID()}",
- "review_state==1"
- ];
- var conditions2 = [
- "role==$shopUserOwner",
- "user_uid==${MyCookie().getUID()}"
- ];
- conditions1.add('private_shop==true');
- dJson = {
- "key": "shop_user",
- "filters": {
- "or": true,
- "conditions": conditions1,
- "filters": [
- {"conditions": conditions2}
- ]
- },
- "dims": shopUserDims,
- "paging": [1, 1000],
- "order_by": ["shop_name,DESC"]
- };
- MyDio().query(dJson, (response, hasError) {
- if (!hasError) {
- MyShopBeanEntity entity =
- MyShopBeanEntity.fromJson(json.decode(response.data.toString()));
- List<int> myShopUIDs = [];
- entity.data.data.forEach((element) {
- myShopUIDs.add(element.shopUid);
- });
- if (myShopUIDs.length == 0) {
- return;
- }
- MyDio().query({
- "key": "order",
- "filters": {
- "or": true,
- "conditions": [
- "state == $orderStateUnpaid",
- 'buyer_uid==0',
- 'buyer_name LIKE ${MyCookie().getName()}',
- 'shop_uid IN $myShopUIDs'
- ],
- "filters": [
- {
- "conditions": [
- "state == $orderStateUnpaid",
- 'buyer_uid==${MyCookie().getUID()}'
- ]
- }
- ]
- },
- "dims": orderDims,
- "paging": [1, 20],
- "order_by": ["create_time,DESC"]
- }, (response, hasError) {
- if (!hasError) {
- SmartOrderBeanEntity entity = SmartOrderBeanEntity
- .fromJson(json.decode(response.data.toString()));
- MyCookie().haveNoPay = entity.data.data.isNotEmpty;
- EventBus().emit('hasNoPay');
- }
- }, (error) {});
- }
- }, (error) {});
- }
|