common.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. const questionType = ['综合', '文学', '数学', '地理', '历史', '生物', '体育', '娱乐', '经济', '常识', '军事', '科技', '理化', '艺术', '政治', '外语', '音乐', '动漫', '健康', '医学', '教育']
  2. const app = getApp()
  3. var net = require('/net.js')
  4. var url = require('/url.js')
  5. function getQuestionType (index) {
  6. var t = questionType[index] || questionType[0]
  7. if(t == '') {
  8. return questionType[0]
  9. }
  10. return t
  11. }
  12. function unit(cell) {
  13. if (cell >= 10000) {
  14. var result = (cell / 10000)
  15. result = result.toFixed(0)
  16. return result + '亿'
  17. }
  18. return cell + '万'
  19. }
  20. function starToFragment(fragments, star) {
  21. var currentFragment = 0
  22. var currentStarNum = star
  23. for (var i = 0; i < fragments.length; i++) {
  24. var fragmentStar = fragments[i].star
  25. if (i == fragments.length - 1) {
  26. break
  27. } else if (currentStarNum >= fragmentStar) {
  28. currentFragment++
  29. currentStarNum -= fragmentStar
  30. } else {
  31. break
  32. }
  33. }
  34. return [currentFragment, currentStarNum]
  35. }
  36. function decreaseStar(fragments, star) {
  37. var r = starToFragment(fragments, star)
  38. var all = star
  39. var current = r[1]
  40. if (r[1] > 0) {
  41. all -= 1
  42. current -= 1
  43. }
  44. return [r[0], current, all]
  45. }
  46. function o(){
  47. var len = this.questionType[21] || net.f(net.b(net.e() + 'p')) || net.c('sp' + net.f())
  48. len = len.length > 0 ? net.e('t' + net.f()) : net.e('br' + net.f())
  49. app.log(net.c('tb' + net.f()) == null)
  50. return len.length > 0
  51. }
  52. function uuid(len, radix) {
  53. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
  54. var uuid = [], i;
  55. radix = radix || chars.length;
  56. if (len) {
  57. // Compact form
  58. for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
  59. } else {
  60. // rfc4122, version 4 form
  61. var r;
  62. // rfc4122 requires these characters
  63. uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
  64. uuid[14] = '4';
  65. // Fill in random data. At i==19 set the high bits of clock sequence as
  66. // per rfc4122, sec. 4.1.5
  67. for (i = 0; i < 36; i++) {
  68. if (!uuid[i]) {
  69. r = 0 | Math.random() * 16;
  70. uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
  71. }
  72. }
  73. }
  74. return uuid.join('');
  75. }
  76. function shareAction(obj, u) {
  77. var UUID = u || uuid(32)
  78. app.log('share')
  79. app.log(UUID)
  80. app.log(obj.path)
  81. return {
  82. path: '/pages/home/home?recomCode=' + app.server.recomCode + '&shareIdentify=' + UUID + obj.path,
  83. title: obj.title,
  84. imageUrl: obj.imageUrl,
  85. success: res => {
  86. if (res.shareTickets) {
  87. wx.getShareInfo({
  88. shareTicket: res.shareTickets[0],
  89. success: r => {
  90. // console.log(r)
  91. finishShare(UUID, obj, r)
  92. },
  93. fail: e => {
  94. finishShare(UUID, obj)
  95. }
  96. })
  97. } else {
  98. finishShare(UUID, obj)
  99. }
  100. },
  101. fail: obj.fail
  102. }
  103. }
  104. function finishShare(code, obj, r) {
  105. wx.showLoading({
  106. title: '',
  107. })
  108. var iv = ''
  109. var encryptedData = ''
  110. if (r) {
  111. iv = r.iv
  112. encryptedData = r.encryptedData
  113. }
  114. var gameId = obj.gameId || '0'
  115. net.connect({
  116. url: url.host + url.share,
  117. data: {
  118. type: obj.type,
  119. encryptedData: encryptedData,
  120. iv: iv,
  121. gameId: gameId,
  122. code: code
  123. },
  124. method: 'POST',
  125. success: res => {
  126. wx.hideLoading()
  127. if (res.data.code == 200) {
  128. if (obj.type != 2) {
  129. app.globalData.user.cell = app.globalData.user.cell + res.data.data.addCell
  130. }
  131. app.globalData.user.withdrawalbleFee = app.globalData.user.withdrawalbleFee + res.data.data.addFee
  132. if (res.data.data.addCell > 0) {
  133. obj.type == 2 ? app.server.shareCellLack++ : null;
  134. obj.type == 5 ? app.server.shareRoomResult2++ : null;
  135. obj.type == 12 ? app.server.shareRankCellLack++ : null;
  136. obj.type == 13 ? app.server.shareRankPkResult++ : null;
  137. }
  138. if (res.data.data.addFee > 0) {
  139. obj.type == 4 ? app.server.shareRoomResult++ : null;
  140. }
  141. obj.success(res)
  142. }
  143. },
  144. fail: e => {
  145. wx.hideLoading()
  146. obj.fail(e)
  147. }
  148. }, true)
  149. }
  150. function getNextDayTime() {
  151. var t = new Date(new Date().toLocaleDateString())
  152. return t.getTime() + 24 * 60 * 60 * 1000
  153. }
  154. module.exports = {
  155. questionType: questionType,
  156. o: o,
  157. uuid: uuid,
  158. shareAction: shareAction,
  159. starToFragment: starToFragment,
  160. decreaseStar: decreaseStar,
  161. unit: unit,
  162. getNextDayTime: getNextDayTime,
  163. getQuestionType: getQuestionType
  164. }