| 558 | } |
| 559 | |
| 560 | function openBox(eventType = 'LUCKY_BOX_DROP', boxId) { |
| 561 | let body = { eventType, "eventRecordId": boxId} |
| 562 | return new Promise(async resolve => { |
| 563 | $.get(taskUrl('crazyJoy_event_getVideoAdvert', JSON.stringify(body)), async (err, resp, data) => { |
| 564 | try { |
| 565 | if (err) { |
| 566 | console.log(`${JSON.stringify(err)}`) |
| 567 | console.log(`${$.name} API请求失败,请检查网路重试`) |
| 568 | } else { |
| 569 | if (safeGet(data)) { |
| 570 | data = JSON.parse(data); |
| 571 | if (data['success']) { |
| 572 | $.log(`点击幸运盒子成功,剩余观看视频次数:${data.data.advertViewTimes}, ${data.data.advertViewTimes > 0 ? '等待32秒' : '跳出'}`) |
| 573 | if (data.data.advertViewTimes > 0) { |
| 574 | await $.wait(32000) |
| 575 | await rewardBox(eventType, boxId); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | } catch (e) { |
| 581 | $.logErr(e, resp) |
| 582 | } finally { |
| 583 | resolve(); |
| 584 | } |
| 585 | }) |
| 586 | }) |
| 587 | } |
| 588 | |
| 589 | function rewardBox(eventType, boxId) { |
| 590 | let body = { eventType, "eventRecordId": boxId} |