File: /www/wwwroot//www.hkkuy.com/ttww/index_files/customer-api.js.下载
var SYSTEM_ID = 30;
var domain = location.host;
var SERVICE_PATH = "/service?";
var NEW_SERVICE_PATH = "/gservice?";
var customerApi = {
login: function (obj, success, fail) {
return _call('customer', 'login', obj, success, fail)
},
register: function (options, success, fail) {
/**
* options{
* collId:站點id
* account:电话或邮箱;
* validcode:验证码;
* password:密码;
* validType:验证码类型(register)
* }
* */
options.validType = 'register'
return _call('customer', 'register', options, success, fail)
},
forgetPassWord: function (options, success, fail) {
/**
* options{
* collId:站點id
* account:电话或邮箱;
* validcode:验证码;
* password:密码;
* validType:验证码类型(register)
* }
* */
return _call('customer', 'forgetPassword', options, success, fail, false, true)
},
// 修改密码
editPassword: function (options, success, fail) {
return _call('customer', 'editPassword', options, success, fail, false, true)
},
getValidCode: function (options, success, fail) {
/**
* options {
* coll_id:站点id,
* phone:接收验证码的手机号或者邮箱
* validType:验证类型
* }
* 注: 当validType为register时,会判断是否已经是重复注册;
* 当validType为forgetPwd时,会判断是否是自己当前登录的帐号;
* 当validType为login时,会判断是否已经注册;
* */
return _call('customer', 'getValidCode', options, success, fail)
},
getCust: function (options, success, fail) {
return _call('customer', 'getCust', options, success, fail)
},
getLogisticsInfo: function (options, success, fail) {
/**
* options{
orderNumber:订单编号
}
* */
return _call('customer', 'getLogisticsInfo', options, success, fail)
},
getOrderNumber: function (options, success, fail) {
/**
* options{
phone:手机号
coll_id:站点id,
}
* */
return _call('customer', 'getOrderByPhone', options, success, fail)
},
getOrderByONum: function (options, success, fail) {
/**
* options{
orderNumber:订单编号
}
* */
return _call('customer', 'getOrderByONum', options, success, fail)
},
myOrder: function (options, success, fail) {
// options {order_status:订单状态(0全部,1待发货,2待签收,3已完成,4已取消)cust_id:用户id(可选,缺失则为当前所登录用户id)}
return _call('customer', 'myOrder', options, success, fail)
},
getOrders: function (options, success, fail){
// {custId:'用户ID',status:'订单状态',pageNum:'页码',pageSize:'每页多少条',}
return _call('customer', 'getOrders',options, success, fail, false, true)
},
updateCustInfo: function (options, success, fail) {
/**
* options:{cust_id:用户id(可选,缺失则为当前所登录用户id);
type:修改类型(birthday:生日;sex:性别(1男,2女,3保密);name:姓名)
data:修改后的值}
* */
return _call('customer', 'updateCustInfo', options, success, fail,true)
},
updateCustInfos: function (options, success, fail) {
// 批量修改个人资料
return _call('customer', 'updateCustInfos', options, success, fail, true)
},
binding: function (options, success, fail) {
/**
* options{
type:绑定类型(phone:手机号;email:邮箱);
number:手机号/邮箱;
cust_id:用户id(可选,缺失则为当前所登录用户id)
}
* */
return _call('customer', 'binding', options, success, fail,true)
},
address: function (options, success, fail) {
/**
* options:{
* cust_id:用户id(可选,缺失则为当前所登录用户id)
* }
* */
return _call('customer', 'address', options, success, fail,true)
},
delAddress: function (options, success, fail) {
/**
* options:{
* cust_id:用户id(可选,缺失则为当前所登录用户id)
* id:地址id
* }
* */
return _call('customer', 'delAddress', options, success, fail,true)
},
setDefaultAddress: function (options, success, fail) {
/**
* options:{
* cust_id:用户id(可选,缺失则为当前所登录用户id)
* id:地址id
* }
* */
return _call('customer', 'setDefaultAddress', options, success, fail,true)
},
addAddress: function (options, success, fail) {
/**
* options:{
* cust_id:用户ID(可选,缺失则为当前所登录用户id);
receiver:收件人;
phone:手机号;
country:国家;
city:城市;
state:州;
county:县区;
address:详细地址;
zip:邮编;
isdef:是否默认(1/0);
email:邮件地址
* }
* */
return _call('customer', 'addAddress', options, success, fail,true)
},
editAddress: function (options, success, fail) {
/**
* options:{
* cust_id:用户ID(可选,缺失则为当前所登录用户id);
receiver:收件人;
phone:手机号;
country:国家;
city:城市;
state:州;
county:县区;
address:详细地址;
zip:邮编;
isdef:是否默认(1/0);
email:邮件地址
* }
* */
return _call('customer', 'editAddress', options, success, fail,true)
},
getHotWords: function (coll_id, success, fail) {
return _call('customer', 'getHotWords', {
coll_id: coll_id
}, success, fail)
},
//获取所有状态的优惠券
getAllCustCoupons:function(options, success, fail) {
/**
* options:{
* custId:用户id(可选,缺失则为当前所登录用户id)
* collId:商城id
* }
* */
return _call('coupon', 'getAllCustCoupons', options, success, fail, false, true)
},
//领取优惠券
addCustCoupon: function (coupon_id, success, fail) {
return _call('coupon', 'addCustCoupon', {
coupon_id: coupon_id
}, success, fail, false, true)
},
getCustCoupons:function (options, success, fail) {
/**
* options:{
* custId:用户id(可选,缺失则为当前所登录用户id)
* collId:商城id
* status:优惠券状态
* currencyId:币种id
* }
* */
return _call('coupon', 'getCustCoupons', options, success, fail, false, true)
},
getCheckCoupons:function (options, success, fail) {
/**
* options:{
* custId:用户id(可选,缺失则为当前所登录用户id)
* collId:商城id
* status:优惠券状态
* currencyId:币种id
* }
* */
return _call('coupon', 'getCheckCoupons', options, success, fail, false, true)
},
//邀请注册优惠券
getInviteCoupons: function (coll_id, success, fail) {
return _call('coupon', 'getInviteCoupons', {
coll_id: coll_id
}, success, fail)
},
//注册优惠券
getRegisterCoupons: function (coll_id, success, fail) {
return _call('coupon', 'getRegisterCoupons', {
coll_id: coll_id
}, success, fail)
},
getWallet:function (options, success, fail) {
/**
* options:{
* custId:用户id(可选,缺失则为当前所登录用户id)
* collId:商城id(暂不用传)
* status:余额状态
* }
* */
return _call('distribute', 'getWallet', options, success, fail)
},
//获取币种汇率
getRate:function (options, success, fail) {
/**
* options:{
* fromCurrencyId:原币种id
* toCurrencyId:目标币种id
* }
* */
return _call('exchange_rate', 'getRate', options, success, fail)
},
//用ip获取币种id
getCurrencyId: function (ip, success, fail) {
return _call('ip', 'getCurrencyId', {
ip: ip
}, success, fail)
},
//获取商品信息
getSaleInfo:function(options, success, fail){
/**
* options:{
* saleId:商品id
* }
* */
return _call('sale', 'sinfo', options, success, fail)
},
//获取时间戳
getTimestamp:function(options, success, fail){
/**
* options:{
*
* }
* */
return _call('tools', 'getTimestamp', options, success, fail, true, true)
},
}
function _call(name,action,data,success,fail,sync,isNew){
var servePath = isNew ? NEW_SERVICE_PATH : SERVICE_PATH;
var url = servePath + 'name=' + name + '&action=' + action;
var obj = {
'_SYSTEM': SYSTEM_ID,
'domain': domain,
}
var async = true;
if(sync){
async = false;
}
$.extend(data, obj);
$.ajax({
type: "POST",
url: url,
data: data,
dataType: "json",
async:async,
success: function (response) {
if (response.code == 0) {
success && success(response)
}else{
fail && fail(response)
}
},
fail:function(err){
fail && fail(err)
}
});
}
// 错误动画
function shake(text){
$(".error").text(text).show().stop().animate({left:"-10px"},100).animate({left:"+10px"},100).animate({left:"-10px"},100).animate({left:"0"},50)
}
//获取站点所有的优惠券
function getSiteCoupons(data) {
return request('coupon', 'getSiteCoupons',data);
}
//获取商品所有的优惠券
function getSaleCoupons(data) {
return request('coupon', 'getSaleCoupons',data);
}
//领取优惠券
function addCustCoupon(data) {
return request('coupon', 'addCustCoupon',data);
}
// 通过链接领取优惠券
function getSharedCoupon(data) {
return request('coupon', 'getSharedCoupon', data);
}
// 获取所有活动列表
function getSeckillActivity(data) {
return request('activity', 'getSeckillActivity', data)
}
// 获取当前时间下商品列表
function getSeckillActivitySales(data) {
return request('activity', 'getSeckillActivitySales', data)
}
// 根据id获取显示抢购单个商品信息
function getSeckillSale(data) {
return request('activity', 'getSeckillSale', data)
}
//分类id获取本分类下的商品
function getSalesCateSelf(data) {
return request('category', 'getSales', data)
}
//根据分类id获取商品
function getSalesCate(data) {
return request('category', 'getCategorySales', data)
}
//根据活动id获取商品
function getSalesActivity(data) {
return request('activity', 'getSales', data)
}
//新加坡根据邮编获取信息地址
function getDetailAddress(data) {
return request('postcode', 'getSingapore', data);
}
//结算页重复下单获取订单信息
function getOrderAgain(data){
return request('order', 'getOrderAgain', data);
};
//组合搭配
function getComposeList(data){
return request('compose', 'getComposeLists', data);
};
// 组合商品详情
function getComposeProductDetail(data){
return request('compose', 'getSaleContent', data);
};
function request(name, action, data, config) {
return new Promise(function(resove, reject) {
if(action == 'getTimestamp') return;
var localTime = $.cookie("time_stamp");
if(!localTime){
try {
var timeData = '';
customerApi.getTimestamp({},function(res){
timeData = res.data;
});
localTime = timeData;
var nowTime = new Date().getTime();
nowTimeM = parseInt(nowTime / 1000)
localTime = nowTimeM - localTime;
var date = new Date();
date.setTime(date.getTime() + (2*60 * 1000));
$.cookie('time_stamp', localTime, {expires:date,path:'/'});
} catch (error) {
console.log(error);
}
}
var timestamp = new Date().getTime();
timestamp = parseInt(timestamp / 1000)
timestamp = localTime ? (timestamp - localTime) : timestamp;
var token = getGserviceToken(name, action,timestamp);
data = data || {};
data.token = token;
data.timestamp = timestamp;
var url = `/gservice?name=${name}&action=${action}`;
config = Object.assign({
type: "post",
dataType: "json",
}, config)
$.ajax({
...config,
url: url,
data: data,
success: function (response) {
if (response.code == 0) {
resove(response.data)
} else {
reject(response)
}
},
fail: function (error) {
reject(error)
},
error: function (error) {
reject(error)
}
});
})
}