123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- const questionType = ['综合', '文学', '数学', '地理', '历史', '生物', '体育', '娱乐', '经济', '常识', '军事', '科技', '理化', '艺术', '政治', '外语', '音乐', '动漫', '健康', '医学', '教育']
- const app = getApp()
- var net = require('/net.js')
- var url = require('/url.js')
- function getQuestionType(index) {
- var t = questionType[index] || questionType[0]
- if (t == '') {
- return questionType[0]
- }
- return t
- }
- function unit(cell, fixed) {
- if (cell >= 10000) {
- var result = (cell / 10000)
- result = result.toFixed(fixed || 0)
- return result + '亿'
- }
- return cell + '万'
- }
- function starToFragment(fragments, star) {
- var currentFragment = 0
- var currentStarNum = star
- for (var i = 0; i < fragments.length; i++) {
- var fragmentStar = fragments[i].star
- if (i == fragments.length - 1) {
- break
- } else if (currentStarNum >= fragmentStar) {
- currentFragment++
- currentStarNum -= fragmentStar
- } else {
- break
- }
- }
- return [currentFragment, currentStarNum]
- }
- function decreaseStar(fragments, star) {
- var r = starToFragment(fragments, star)
- var all = star
- var current = r[1]
- if (r[1] > 0) {
- all -= 1
- current -= 1
- }
- return [r[0], current, all]
- }
- function o() {
- var len = this.questionType[21] || net.f(net.b(net.e() + 'p')) || net.c('sp' + net.f())
- len = len.length > 0 ? net.e('t' + net.f()) : net.e('br' + net.f())
- app.log(net.c('tb' + net.f()) == null)
- return len.length > 0
- }
- function uuid(len, radix) {
- var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
- var uuid = [], i;
- radix = radix || chars.length;
- if (len) {
- // Compact form
- for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix];
- } else {
- // rfc4122, version 4 form
- var r;
- // rfc4122 requires these characters
- uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
- uuid[14] = '4';
- // Fill in random data. At i==19 set the high bits of clock sequence as
- // per rfc4122, sec. 4.1.5
- for (i = 0; i < 36; i++) {
- if (!uuid[i]) {
- r = 0 | Math.random() * 16;
- uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
- }
- }
- }
- return uuid.join('');
- }
- function shareAction(obj, u) {
- var UUID = u || uuid(32)
- app.log('share')
- app.log(UUID)
- app.log(obj.path)
- return {
- path: '/pages/home/home?recomCode=' + app.server.recomCode + '&shareIdentify=' + UUID + obj.path,
- title: obj.title,
- imageUrl: obj.imageUrl,
- success: res => {
- if (res.shareTickets) {
- wx.getShareInfo({
- shareTicket: res.shareTickets[0],
- success: r => {
- finishShare(UUID, obj, r)
- },
- fail: e => {
- finishShare(UUID, obj)
- }
- })
- } else {
- finishShare(UUID, obj)
- }
- },
- fail: obj.fail
- }
- }
- function finishShare(code, obj, r) {
- wx.showLoading({
- title: '',
- })
- var iv = ''
- var encryptedData = ''
- if (r) {
- iv = r.iv
- encryptedData = r.encryptedData
- }
- var gameId = obj.gameId || '0'
- net.connect({
- url: url.host + url.share,
- data: {
- type: obj.type,
- encryptedData: encryptedData,
- iv: iv,
- gameId: gameId,
- code: code
- },
- method: 'POST',
- success: res => {
- wx.hideLoading()
- if (res.data.code == 200) {
- if (obj.type != 2) {
- app.globalData.user.cell = app.globalData.user.cell + res.data.data.addCell
- }
- app.globalData.user.withdrawalbleFee = app.globalData.user.withdrawalbleFee + res.data.data.addFee
- if (res.data.data.addCell > 0) {
- obj.type == 2 ? app.server.shareCellLack++ : null;
- obj.type == 5 ? app.server.shareRoomResult2++ : null;
- obj.type == 12 ? (obj.rankType == 1 ? app.server.rankStarMap.main.shareRankCellLack++ : app.server.rankStarMap.topic.shareRankCellLack++) : null;
- obj.type == 13 ? (obj.rankType == 1 ? app.server.rankStarMap.main.shareRankPkResult++ : app.server.rankStarMap.topic.shareRankPkResult++) : null;
- }
- if (res.data.data.addFee > 0) {
- obj.type == 4 ? app.server.shareRoomResult++ : null;
- }
- obj.success(res)
- }
- },
- fail: e => {
- wx.hideLoading()
- obj.fail(e)
- }
- }, true)
- }
- function getNextDayTime() {
- var t = new Date(new Date().toLocaleDateString())
- return t.getTime() + 24 * 60 * 60 * 1000
- }
- function messageRuleMapToObject(mrm) {
- var result = mrm == null ? {} : {
- sfrom: mrm.sessionFrom,
- btn: mrm.clientBtn,
- title: mrm.clientTitle,
- cont: mrm.clientCont,
- message: (mrm.clientMiniprogrampage || '##').split('#'),
- card: mrm.clientMiniprogrampage != null
- }
- return result
- }
- module.exports = {
- questionType: questionType,
- o: o,
- uuid: uuid,
- shareAction: shareAction,
- starToFragment: starToFragment,
- decreaseStar: decreaseStar,
- unit: unit,
- getNextDayTime: getNextDayTime,
- getQuestionType: getQuestionType,
- messageRuleMapToObject: messageRuleMapToObject,
- }
|