Browse Source

统计接口

Rorschach 5 years ago
parent
commit
3ccae1284a

+ 2 - 0
component/share/share.js

@@ -123,6 +123,7 @@ Component({
           author: data.author,
           iconImg: data.iconImg,
           title: data.title,
+          productId: data.productId,
           // path: data.path,
           QRData: {
             page: data.path,
@@ -394,6 +395,7 @@ Component({
         success: (res) => {
           console.log(res)
           const data = {};
+          console.log('productId',this.data.productId)
           // 团购分享记录
           if(this.data.shareType === 'group'){
             data.shareTypeEnum = 'POSTER';

+ 8 - 17
pages/groupPage/collage-details/collage-details.js

@@ -180,27 +180,18 @@ Page({
     }
 
     const id = this.data.orderId;
+    const data = {
+      shareTypeEnum: 'LINK',
+      shareContentEnum: 'GROUP',
+      productId: this.data.productId
+    }
+    httpRequestApi.shareRecord(data).success((res) => {
+      console.log(res)
+    })
     return {
       title: '老师同学都在玩的配音show,你还在等什么?',
       path: `pages/groupPage/group-details/group-details?share=true&shareId=${id}`,
       imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/group_${this.data.productId}.jpg`,
-      success: function (res) {
-        // 转发成功
-        console.log("转发成功:" + JSON.stringify(res));
-        var shareTickets = res.shareTickets;
-        const data = {
-          shareTypeEnum: 'LINK',
-          shareContentEnum: 'GROUP',
-          productId: this.data.productId
-        }
-        httpRequestApi.shareRecord(data).success((res) => {
-          console.log(res)
-        })
-      },
-      fail: function (res) {
-        // 转发失败
-        console.log("转发失败:" + JSON.stringify(res));
-      }
     }
   }
 })

+ 1 - 0
pages/groupPage/group-details/group-details.js

@@ -530,6 +530,7 @@ Page({
 
       }
     }, (error) => {
+      
       this.setData({
         hide: !this.data.hide,
         onLoadOption: options

+ 13 - 10
pages/index/index.js

@@ -3,7 +3,9 @@
 import {
   getOpenidSessionKey
 } from '../../utils/httpUtil';
-import {formatDate} from '../../utils/util';
+import {
+  formatDate
+} from '../../utils/util';
 
 const app = getApp()
 
@@ -59,7 +61,7 @@ Page({
     hotInput: '12345',
     mineSettingInfo: '528',
     hide: true,
-    isIOS:app.globalData.isIOS,
+    isIOS: app.globalData.isIOS,
   },
   jurisdiction: function () {
     //隐藏弹框
@@ -73,7 +75,7 @@ Page({
   switcher: function ({
     currentTarget
   }) {
-    if(currentTarget.dataset.index === this.data.myIndex) return;
+    if (currentTarget.dataset.index === this.data.myIndex) return;
     this.updateData(currentTarget.dataset.index);
   },
   // 根据index 更新template
@@ -140,6 +142,7 @@ Page({
   init: function () {
     httputil.getOpenidSessionKey((res) => {
       console.log('微信的用户信息', res)
+      
     }, (error) => {
       console.log(error);
       this.jurisdiction()
@@ -153,9 +156,9 @@ Page({
     console.log(wx.getStorageSync('user'));
     httpRequestApi.getUserWorksInfo().success(res => {
       this.data.myData.user = res.data.data; //直接赋值 给 myData的user对象。
-      this.data.myData.user.user.birthday = this.data.myData.user.user.birthday ?  formatDate(res.data.data.user.birthday,4) : '2018年1月1日';
-      httpRequestApi.userIntoPage('pages/index/index','首页我的').success((res)=>{
-        
+      this.data.myData.user.user.birthday = this.data.myData.user.user.birthday ? formatDate(res.data.data.user.birthday, 4) : '2018年1月1日';
+      httpRequestApi.userIntoPage('pages/index/index', '首页我的').success((res) => {
+
       })
       this.setData({
         myData: this.data.myData,
@@ -198,13 +201,13 @@ Page({
     if (this.data.myIndex === 0) {
       groupInit(this);
     }
-    
+
     wx.showNavigationBarLoading() //在标题栏中显示加载
     //模拟加载
-    setTimeout(function(){
+    setTimeout(function () {
       wx.hideNavigationBarLoading() //完成停止加载
       wx.stopPullDownRefresh() //停止下拉刷新
-    },1500);
+    }, 1500);
   }
-  
+
 })

+ 2 - 1
pages/social/replyDetail/replyDetail.js

@@ -32,6 +32,7 @@ Page({
       });
     },
     replyDone:function(){
+        console.log(this.data.productId)
       const data = {
         postsId: this.data.postId,
         productId: this.data.productId,
@@ -41,7 +42,7 @@ Page({
         httpRequestApi.postReplyComment(this.uid, data).success(res => {
           this.setData({
             replyModal: false,
-            replyInfo: ''
+            replyInfo: '',
           });
           this.getReplyDetail();//更新 变化后的 replyTemp。
         });

+ 29 - 43
pages/social/works/works.js

@@ -62,6 +62,9 @@ Page({
                     goBackHome: true
                 })
             }
+            // wx.setNavigationBarTitle({
+            //     title: option.title //页面标题为路由参数
+            // })
             this.uid = wx.getStorageSync('uid');
             let stackSize = 1;
             if (option.stackSize) {
@@ -71,8 +74,7 @@ Page({
                 // title: option.title,
                 id,
                 myUid: this.uid,
-                stackSize,
-                option
+                stackSize
             })
             this.getWorks(this.uid, id);
         }, (error) => {
@@ -83,33 +85,25 @@ Page({
             return;
         });
     },
-    addRecord: function(){
-        const data = {
-            "shareTypeEnum": "POSTER",
-            "shareContentEnum": "READ",
-            "productId": this.data.productId
-        }
-        if(this.data.option.shareCard){
-            data.shareTypeEnum = 'LINK'
-            httpRequestApi.shareTagRecord(data).success(res=>{
-                console.log(res)
-            })
-        }
-        if(this.data.option.scene){
-            httpRequestApi.shareTagRecord(data).success(res=>{
-                console.log(res)
-            })
-        }
-    },
     onHide: function () {
         // this.data.stackSize >= 2
-        console.log(this.data.stackSize)
+        
         if (this.innerAudioContext) {
             this.innerAudioContext.pause();
         }
         this.videoCtx = null
     },
     onUnload: function () {
+        const data = {
+            "title": this.data.title,
+            "lessonId": this.data.classId,
+            "productId": this.data.productId,
+            "playStopTime": this.videoPlayTime || 0,
+            "userReadId": this.data.userReadId
+        }
+        httpRequestApi.playLogReport(data).success(res =>{
+            console.log(res)
+        })
         if (this.innerAudioContext) {
             this.innerAudioContext.destroy();
         }
@@ -147,17 +141,14 @@ Page({
                 classId: works.lessonId,
                 isLike: res.data.data.isLike,
                 isFans: res.data.data.isFans,
-                title: works.title
-            });
-            httpRequestApi.userIntoPage('pages/social/works/works','用户作品页面').success((res)=>{
-        
+                title: works.title,
+                userReadId: works.id
             })
             httpRequestApi.checkLesson(works.lessonId).success(res => {
                 const productId = res.data.data[0];
                 this.setData({
                     productId
                 })
-                this.addRecord();
             });
             // 设置音频路径
             this.innerAudioContext = wx.createInnerAudioContext();
@@ -260,7 +251,9 @@ Page({
         });
     },
     // 视频播放完毕销毁录音
-    videoEnd: function () {
+    videoEnd: function (e) {
+        console.log(e)
+        
         this.innerAudioContext.stop();
     },
     videoPause: function () {
@@ -283,6 +276,7 @@ Page({
     videoTimeupdate: function (e) {
         console.log('视频播放进度发生变化')
         console.log('视频当前时长', e.detail.currentTime);
+        this.videoPlayTime = e.detail.currentTime
         console.log('音频当前时长', this.innerAudioContext.currentTime)
         if (e.detail.currentTime - this.innerAudioContext.currentTime >= 1) {
             this.innerAudioContext.seek(e.detail.currentTime - 0.1);
@@ -338,26 +332,16 @@ Page({
         console.log(this.data.productId);
         const data = {
             shareTypeEnum: 'LINK',
-            shareContentEnum: 'READ'
-        }
-        httpRequestApi.shareRecord(data).success((res)=>{
+            shareContentEnum: 'READ',
+            productId: this.data.productId
+          }
+          httpRequestApi.shareRecord(data).success((res) => {
             console.log(res)
           })
         return {
             title: '一样的课文,不一样的味道!我的配音表演已开始,求各位大咖围观、点评!',
             path: `pages/social/works/works?id=${this.data.id}&title=${this.data.title}&shareCard=true`,
             imageUrl: `https://efunbox.lingjiao.cn/reader/resource/share/read_${this.data.productId}.jpg`,
-            success: function (res) {
-                // 转发成功
-                const data = {
-                    shareTypeEnum: 'LINK',
-                    shareContentEnum: 'READ',
-                    productId:this.data.productId
-                }
-                httpRequestApi.shareRecord(data).success((res)=>{
-                    console.log(res)
-                  })
-              },
         }
     },
     follow: function () {
@@ -473,6 +457,7 @@ Page({
     },
     // 发布回复
     sendHandler: function () {
+        console.log(this.data.productId)
         if (this.data.inputValue !== '') {
             // let uid = wx.getStorageSync('uid');
             let data = {
@@ -480,7 +465,7 @@ Page({
                 colunmNames: 'what',
                 // "detailDesc": encodeURI(this.data.inputValue)
                 "detailDesc": this.data.inputValue,
-                "productId": this.data.productId
+                productId: this.data.productId
             }
             httpRequestApi.postReply(this.uid, data).success(res => {
                 this.setData({
@@ -519,7 +504,8 @@ Page({
     replySB: function () {
         const data = {
             postsId: this.data.replySBId,
-            content: this.data.inputSBValue
+            content: this.data.inputSBValue,
+            productId: this.data.productId
         }
         httpRequestApi.postReplyComment(this.uid, data).success(res => {
             const replyWho = this.data.replyList[this.data.replyIndex];

+ 1 - 1
project.config.json

@@ -12,7 +12,7 @@
 	},
 	"compileType": "miniprogram",
 	"libVersion": "2.3.2",
-	"appid": "wxdfa8a4f1623d28db",
+	"appid": "wx8961a3e5512f307c",
 	"projectname": "%E5%B0%8F%E5%AD%A6%E8%AF%BE%E6%96%87%E6%9C%97%E8%AF%BB%E9%85%8D%E9%9F%B3",
 	"debugOptions": {
 		"hidedInDevtools": []

+ 9 - 2
utils/APIClient.js

@@ -403,10 +403,10 @@ module.exports = {
     }).data(data).url(url).method('POST').send();
   },
   // 用户登录记录
-  userLoginRecord(uid) {
+  userLoginRecord() {
     let url = getBaseUrl('wx/loginLog');
     return request.getInstance().header({
-      uid
+      uid: wx.getStorageSync('uid')
     }).url(url).send();
   },
   // 用户进入页面统计
@@ -419,4 +419,11 @@ module.exports = {
       actionName
     }).url(url).method('POST').send();
   },
+  // 用户播放视频时长统计
+  playLogReport(data) {
+    let url = getBaseUrl('base/playLog');
+    return request.getInstance().header({
+      uid: wx.getStorageSync('uid')
+    }).data(data).url(url).method('POST').send();
+  },
 }

+ 65 - 51
utils/httpUtil.js

@@ -7,7 +7,7 @@ const HOST = url.baseApi;
 
 
 function genAPIUrl(action) {
-	return HOST + action;
+    return HOST + action;
 }
 
 // 登录
@@ -16,83 +16,97 @@ function wxLogin(successcallback, failcallback) {
         title: '登录中...',
         icon: 'loading',
         duration: 1500,
-        mask:true
+        mask: true
     })
-    wx.login({  
-        success: function(res) {
+    wx.login({
+        success: function (res) {
             if (res.code) {
                 // 获取openid
-                 let url = genAPIUrl('wx/user/openId')
-                 let data = { code: res.code }
-                 return request.getInstance().url(url).data(data).send().success(successcallback).fail(failcallback);
+                console.log('openId', res.code)
+                let url = genAPIUrl('wx/user/openId')
+                let data = {
+                    code: res.code
+                }
+                return request.getInstance().url(url).data(data).send().success(successcallback).fail(failcallback);
             } else {
                 console.log('获取用户登录态失败!' + res.errMsg)
             }
         }
     })
 }
+
+function userLoginRecord(uid) {
+    if (wx.getStorageSync('uid')) {
+        console.log('调用方法')
+        let url = genAPIUrl('wx/loginLog');
+        return request.getInstance().header({
+            uid: wx.getStorageSync('uid')
+        }).method('POST').url(url).send().success(()=>{}).fail(()=>{});
+    }
+
+}
 //登录
 function getLoginSchedule(sessionKey, openId, successcallback, failcallback) {
     wx.getSetting({
-        success: function(res) {
+        success: function (res) {
             // 已经授权,可以直接调用 getUserInfo 获取头像昵称
             wx.getUserInfo({
                 withCredentials: true,
                 success: function (res) {
-                  let url = genAPIUrl('wx/user/loginRegist');
-                  const userData = {
-                      encryptedData: res.encryptedData,
-                      sessionKey: sessionKey,
-                      iv: res.iv
-                  }
-                  request.getInstance().url(url).header({
-                      "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
-                  }).data(userData).method('POST').send().success(res => {
-                      wx.hideToast()
-                      wx.showToast({
-                          title: '登录成功',
-                          icon: 'success',
-                          duration: 1500,
-                          mask: true
-                      })
-                      wx.setStorageSync('uid', res.data.data.data.uid)
-                      wx.setStorageSync('user', res.data.data.data)
-                      httpRequestApi.userLoginRecord(res.data.data.data.uid).success((res)=>{
-                          console.log('用户登录记一次')
-                      })
-                      console.log(res)
-                      successcallback(res)
-                  });
+                    let url = genAPIUrl('wx/user/loginRegist');
+                    const userData = {
+                        encryptedData: res.encryptedData,
+                        sessionKey: sessionKey,
+                        iv: res.iv
+                    }
+                    request.getInstance().url(url).header({
+                        "content-type": "application/x-www-form-urlencoded; charset=UTF-8"
+                    }).data(userData).method('POST').send().success(res => {
+                        wx.hideToast()
+                        wx.showToast({
+                            title: '登录成功',
+                            icon: 'success',
+                            duration: 1500,
+                            mask: true
+                        })
+                        wx.setStorageSync('uid', res.data.data.data.uid)
+                        wx.setStorageSync('user', res.data.data.data)
+                        userLoginRecord()
+                        successcallback(res)
+
+                    });
                 },
-                fail: function(res) {
+                fail: function (res) {
                     failcallback(res)
                 }
             })
-          } 
-      })
+        }
+    })
+
 }
+
 // 获取原来的 openid 和 session_key
 function getOpenidSessionKey(successcallback, failcallback) {
     if (wx.getStorageSync('user')) {
-      successcallback(
-        wx.getStorageSync('user'),
-        //分享小程序按钮
-        wx.showShareMenu({
-          withShareTicket: true
-        })
-      );
-      return;
+        successcallback(
+            wx.getStorageSync('user'),
+            //分享小程序按钮
+            wx.showShareMenu({
+                withShareTicket: true
+            })
+        );
+        return;
     }
-    wxLogin(function(res) {
-      if(res.data.code == 200){
-        let sessionKey = res.data.data.session_key;
-        let openId = res.data.data.openid;
-        getLoginSchedule(sessionKey, openId, successcallback, failcallback);
-      }
+    wxLogin(function (res) {
+        if (res.data.code == 200) {
+            let sessionKey = res.data.data.session_key;
+            let openId = res.data.data.openid;
+            getLoginSchedule(sessionKey, openId, successcallback, failcallback);
+        }
 
-    },function(res) {
+    }, function (res) {
         failcallback(res);
-    })    
+    })
 }