daily_red_packet.dart 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'dart:convert';
  2. import 'package:bbyyy/beans/activity_bean_entity.dart';
  3. import 'package:bbyyy/beans/grab_a_red_envelope_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/my_tools/event_bus.dart';
  6. import 'package:bbyyy/my_tools/my_cookie.dart';
  7. import '../const.dart';
  8. import '../dims.dart';
  9. class DailyRedPacketTool {
  10. ActivityBeanData dailyRedPacket;
  11. GrabARedEnvelopeBeanData grabARedEnvelopeBeanData;
  12. DailyRedPacketTool._internal();
  13. static DailyRedPacketTool _singleton = DailyRedPacketTool._internal();
  14. factory DailyRedPacketTool() => _singleton;
  15. queryRedEnvelopeInformation() {
  16. MyDio().query({
  17. "key": "activity",
  18. "dims": activityDims,
  19. "filters": {
  20. 'conditions': ['type == $activityTypeLoginForCash']
  21. }
  22. }, (response, hasError) {
  23. if (!hasError) {
  24. ActivityBeanEntity entity =
  25. ActivityBeanEntity().fromJson(json.decode(response.toString()));
  26. if (entity.data.isNotEmpty) {
  27. dailyRedPacket = entity.data[0];
  28. // EventBus().emit('showRP');
  29. if(!dailyRedPacket.valid){
  30. return;
  31. }
  32. try {
  33. String lastShowTime = MyCookie().prefs.get('dailyRedPacket');
  34. DateTime dateTime = DateTime.now();
  35. String sT = '${MyCookie().getUID()}${dateTime.year}-${dateTime.month}-${dateTime.day}';
  36. if (lastShowTime == null || lastShowTime == '') {
  37. EventBus().emit('showRP');
  38. MyCookie().prefs.setString('dailyRedPacket', sT);
  39. }else{
  40. if(lastShowTime==sT){
  41. }else{
  42. EventBus().emit('showRP');
  43. MyCookie().prefs.setString('dailyRedPacket', sT);
  44. }
  45. }
  46. } catch (e) {}
  47. }
  48. }
  49. }, (error) {});
  50. }
  51. grabARedEnvelope() {
  52. MyDio().post(
  53. '/model/joinActivity',
  54. {'id': dailyRedPacket.id, 'user_uid': MyCookie().getUID()},
  55. (response, hasError) {
  56. if(!hasError){
  57. GrabARedEnvelopeBeanEntity entity = GrabARedEnvelopeBeanEntity().fromJson(json.decode(response.toString()));
  58. grabARedEnvelopeBeanData = entity.data;
  59. EventBus().emit('grabARedEnvelope',grabARedEnvelopeBeanData);
  60. }
  61. },
  62. (error) {});
  63. }
  64. }