Authored by yyq

yas

... ... @@ -4,6 +4,7 @@ import event from './common/event';
import {verify} from './common/api';
import config from './common/config';
import Promise from './vendors/es6-promise';
import {MD5} from './vendors/crypto';
import { WeToast } from './vendors/toast/wetoast';
import { wechatAuthLogin, verifySessionKey } from './common/login';
import { logEvent } from './common/analytics';
... ... @@ -62,6 +63,8 @@ App({
this.doLogin();
});
this.globalData.sid = MD5(`${new Date().getTime()}`).toString();
wx.getSystemInfo().then(res => {
this.globalData.systemInfo = res;
});
... ...
import config from './config';
import api from './api';
import {MD5} from '../vendors/crypto';
export default class yas {
constructor(app) {
... ... @@ -11,7 +13,7 @@ export default class yas {
res: '', // 屏幕大小
osv: '', // 系统版本
ak: 'yohobuy_mp',
ch: this.app.getUnionType(),
ch: '',
udid: this.app.globalData.udid
};
... ... @@ -29,6 +31,23 @@ export default class yas {
}
});
}
uploadData(params) {
let sid = '';
if (this.app && this.app.globalData) {
sid = this.app.globalData.sid || '';
}
return wx.request({
url: config.domains.yasApi,
data: {'_mlogs': JSON.stringify(params)},
method: 'POST',
header: {
'content-type': "application/x-www-form-urlencoded",
'x-yoho-sid': MD5(sid).toString(),
},
});
}
report(event, info) {
let self = this;
let userInfo = info || {};
... ... @@ -36,37 +55,35 @@ export default class yas {
if (this.app) {
Object.assign(userInfo, {
C_ID: this.app.globalData.cid || '',
UNION_ID: this.app.getUnionID(),
APP_ID: this.app.getAppId()
});
}
wx.getNetworkType({
success(res) {
switch(res.networkType) {
case 'wifi':
statusInfo.net = '1';
break;
case '2g':
statusInfo.net = '2';
break;
case '3g':
statusInfo.net = '3';
break;
case '4g':
statusInfo.net = '1';
break;
default:
statusInfo.net = '0';
break;
}
},
complete() {
api.get({
api: 'yasApi',
data: {
return new Promise(resolve => {
wx.getNetworkType({
success(res) {
switch(res.networkType) {
case 'wifi':
statusInfo.net = '1';
break;
case '2g':
statusInfo.net = '2';
break;
case '3g':
statusInfo.net = '3';
break;
case '4g':
statusInfo.net = '1';
break;
default:
statusInfo.net = '0';
break;
}
},
complete() {
return resolve(self.uploadData({
status: statusInfo,
device: self.deviceInfo,
events: [{
... ... @@ -74,11 +91,12 @@ export default class yas {
'ts': new Date().getTime(),
'op': event,
'uid': self.app.getUid(),
'sid': this.app.globalData.sid || '',
'sid': self.app.globalData.sid || '',
}]
}
});
}
}));
}
});
});
}
};
... ...
... ... @@ -2,24 +2,22 @@ import ensureModel from '../../../models/cart/ensure';
import addressModel from '../../../models/home/address';
import wechatAddressUtil from '../../../utils/wechat-address';
import { wechatPay } from '../../../utils/wechat-pay';
import Yas from '../../../common/yas';
const SKU_TYPE = 'O';
// 支付类型
const PAYMENT = {
const PAYMENT = { // 支付类型
ID: 15,
TYPE: 1,
};
// 结算订单类型
const ORDER_TYPE = {
const ORDER_TYPE = { // 结算订单类型
BUYNOW: 'buynow'
};
const app = getApp();
const router = global.router;
const yas = new Yas(app);
function formatPaymentData(data) {
function formatPaymentData(data, yasInfo) {
data = data || {};
let info = {
... ... @@ -31,11 +29,17 @@ function formatPaymentData(data) {
paymentAmount: data.shopping_cart_data.last_order_amount
};
yasInfo = yasInfo || {};
info.goodsList.map(value => {
if (value.goods_type === 'gift' || value.goods_type === 'price_gift') {
value.sales_price = value.last_price;
}
yasInfo.skns && yasInfo.skns.push(value.product_skn);
yasInfo.skus && yasInfo.skus.push(value.product_sku);
yasInfo.pids && yasInfo.pids.push(value.product_id);
return value;
});
... ... @@ -98,6 +102,11 @@ Page({
},
onLoad(options) {
this.orderData = options;
this.yasInfo = {
skns: [],
skus: [],
pids: []
};
this.loadEnsurePayment({productSku: this.orderData.productSku});
},
loadEnsurePayment(options, reload) {
... ... @@ -120,7 +129,7 @@ Page({
return;
}
let data = formatPaymentData(res.data);
let data = formatPaymentData(res.data, this.yasInfo);
Object.assign(this.orderData, {
productSku: options.productSku,
... ... @@ -128,7 +137,7 @@ Page({
deliveryWayId: data.deliveryWayId,
deliveryTimeId: data.deliveryTimeId
});
console.log(this.yasInfo);
this.setData(data);
});
}
... ... @@ -331,6 +340,15 @@ Page({
this.orderSubmiting = false;
if (res.code === 200) {
// yas上报
yas.report('YB_SC_ORD', {
ORD_NUM: res.data.order_code,
PRD_SKN: this.yasInfo.skns.join(','),
RPD_SKU: this.yasInfo.skus.join(','),
PRD_ID: this.yasInfo.pids.join(','),
ORDER_TYPE: 102 // 101购物车下单,102立即购买下单
});
wechatPay(res.data);
} else {
wx.showModal({
... ...
... ... @@ -25,7 +25,7 @@
"list": []
},
"miniprogram": {
"current": -1,
"current": 12,
"list": [
{
"id": 1,
... ...