index.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // nova-werun/pages/home/signin/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. const {
  5. getConsecutiveSignIns
  6. } = require("../../../service/day")
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. //屏幕高度
  13. statusBarHeight: 0, // 状态栏高度
  14. screenHeight: 0, // 屏幕高度
  15. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  16. bottomNavHeight: 0, // 底部导航栏高度
  17. contentHeight: 0, // 可用内容高度
  18. contentHeight2: 0,
  19. contentpadding: 0, //顶部padding高度
  20. //是否打卡
  21. issigin: false,
  22. images: [
  23. // 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/1p97lf053250915.png',
  24. // 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/bt19fm050427168.png',
  25. 'https://file-cloud.fmode.cn/qpFbRRSZrO/20250113/191d1m053251615.png'
  26. ],
  27. randomImage: '',
  28. accumulateChink:0,
  29. continuousChink:0
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. // 计算
  36. const systemInfo = wx.getSystemInfoSync();
  37. const statusBarHeight = systemInfo.statusBarHeight || 0;
  38. const screenHeight = systemInfo.screenHeight || 0;
  39. const custom = wx.getMenuButtonBoundingClientRect();
  40. const customHeight = custom.height + 10 + 2 || 0;
  41. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  42. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  43. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  44. this.setData({
  45. statusBarHeight,
  46. screenHeight,
  47. customHeight,
  48. bottomNavHeight,
  49. contentpadding,
  50. contentHeight
  51. });
  52. this.showRandomImage()
  53. this.order()
  54. this.accumulateChink()
  55. this.continuousChink()
  56. },
  57. /**
  58. * 生命周期函数--监听页面初次渲染完成
  59. */
  60. onReady: function () {
  61. },
  62. /**
  63. * 生命周期函数--监听页面显示
  64. */
  65. onShow: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面隐藏
  69. */
  70. onHide: function () {
  71. },
  72. /**
  73. * 生命周期函数--监听页面卸载
  74. */
  75. onUnload: function () {
  76. },
  77. /**
  78. * 页面相关事件处理函数--监听用户下拉动作
  79. */
  80. onPullDownRefresh: function () {
  81. },
  82. /**
  83. * 页面上拉触底事件的处理函数
  84. */
  85. onReachBottom: function () {
  86. },
  87. /**
  88. * 用户点击右上角分享
  89. */
  90. onShareAppMessage: function () {
  91. },
  92. //检查当天是否签到
  93. async order() {
  94. const currentUser = Parse.User.current();
  95. let EventLogquery = new Parse.Query('EventLog');
  96. EventLogquery.equalTo('user', currentUser.id);
  97. EventLogquery.equalTo('company', company);
  98. EventLogquery.notEqualTo('isDeleted', true)
  99. // 获取今天的日期
  100. const today = new Date();
  101. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  102. const todayEnd = new Date(todayStart);
  103. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  104. // 在查询条件中添加对 createdAt 的限制
  105. EventLogquery.greaterThanOrEqualTo('createdAt', todayStart);
  106. EventLogquery.lessThanOrEqualTo('createdAt', todayEnd);
  107. let P = await EventLogquery.first();
  108. if (P) {
  109. this.setData({
  110. issigin: true
  111. })
  112. return;
  113. }
  114. },
  115. async submit() {
  116. const currentUser = Parse.User.current();
  117. let EventLogquery = new Parse.Query('EventLog');
  118. EventLogquery.equalTo('user', currentUser.id);
  119. EventLogquery.equalTo('company', company);
  120. EventLogquery.notEqualTo('isDeleted', true)
  121. // 获取今天的日期
  122. const today = new Date();
  123. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  124. const todayEnd = new Date(todayStart);
  125. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  126. // 在查询条件中添加对 createdAt 的限制
  127. EventLogquery.greaterThanOrEqualTo('createdAt', todayStart);
  128. EventLogquery.lessThanOrEqualTo('createdAt', todayEnd);
  129. let P = await EventLogquery.first();
  130. if (P) {
  131. this.setData({
  132. issigin: true
  133. })
  134. console.log('今日已打卡');
  135. return;
  136. } else {
  137. const currentUser = Parse.User.current();
  138. let userquery = new Parse.Query('_User');
  139. userquery.equalTo('company', company);
  140. userquery.equalTo('objectId', currentUser.id);
  141. userquery.notEqualTo('isDeleted', true)
  142. let user = await userquery.first();
  143. let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
  144. let EventLog = new Parse.Object('EventLog');
  145. EventLog.set('points', 10)
  146. EventLog.set('company', companyPointer);
  147. EventLog.set('user', user.toPointer());
  148. try {
  149. let saveDate = await EventLog.save();
  150. console.log(saveDate);
  151. this.accumulateChink()
  152. this.setData({
  153. issigin: true
  154. })
  155. console.log("打卡成功");
  156. } catch (error) {
  157. console.error("保存数据时出现错误:", error);
  158. }
  159. }
  160. },
  161. //随机展示图片
  162. showRandomImage: function () {
  163. const randomIndex = Math.floor(Math.random() * this.data.images.length);
  164. this.setData({
  165. randomImage: this.data.images[randomIndex]
  166. });
  167. },
  168. //积累打卡
  169. async accumulateChink(){
  170. const currentUser = Parse.User.current();
  171. let EventLogquery = new Parse.Query('EventLog');
  172. EventLogquery.equalTo('user', currentUser.id);
  173. EventLogquery.equalTo('company', company);
  174. EventLogquery.notEqualTo('isDeleted', true)
  175. let P = await EventLogquery.find();
  176. let chickList = P.map(item => item.toJSON());
  177. this.setData({
  178. accumulateChink:chickList.length
  179. })
  180. },
  181. //连续打卡
  182. async continuousChink() {
  183. const currentUser = Parse.User.current();
  184. let day = await getConsecutiveSignIns({
  185. userId: currentUser.id,
  186. });
  187. console.log('day',day);
  188. }
  189. })