初始化
This commit is contained in:
99
utils/api.js
Normal file
99
utils/api.js
Normal file
@@ -0,0 +1,99 @@
|
||||
const app = getApp()
|
||||
|
||||
function getCode(obj) {
|
||||
var md4 = objKeySort(obj)
|
||||
console.log(md4)
|
||||
var md5 = require("md5.js");
|
||||
console.log(md5.hex_md5(md4).toUpperCase());
|
||||
var md5 = md5.hex_md5(md4).toUpperCase();
|
||||
return md5;
|
||||
}
|
||||
|
||||
function getTimestamp() {
|
||||
var myDate = new Date();
|
||||
var timestamp = formatTime(myDate.getTime(), "YMDHMS");
|
||||
console.log(timestamp);
|
||||
return timestamp;
|
||||
|
||||
}
|
||||
|
||||
function formatTime(value, type) {
|
||||
// console.log("............" + value);
|
||||
var dataTime = "";
|
||||
var data = new Date();
|
||||
data.setTime(value);
|
||||
var year = data.getFullYear();
|
||||
var month = addZero(data.getMonth() + 1);
|
||||
var day = addZero(data.getDate());
|
||||
var hour = addZero(data.getHours());
|
||||
var minute = addZero(data.getMinutes());
|
||||
var second = addZero(data.getSeconds());
|
||||
if (type == "YMD") {
|
||||
dataTime = year + "-" + month + "-" + day;
|
||||
} else if (type == "YMDHMS") {
|
||||
dataTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
} else if (type == "MDHMS") {
|
||||
dataTime = month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
// dataTime =123;
|
||||
} else if (type == "HMS") {
|
||||
dataTime = hour + ":" + minute + ":" + second;
|
||||
} else if (type == "YM") {
|
||||
dataTime = year + "-" + month;
|
||||
|
||||
}
|
||||
return dataTime; //灏嗘牸寮忓寲鍚庣殑瀛楃涓茶緭鍑哄埌鍓嶇鏄剧ず
|
||||
|
||||
};
|
||||
|
||||
function addZero(val) {
|
||||
if (val < 10) {
|
||||
return "0" + val;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
function apiHeader(obj) {
|
||||
var timestamp = getTimestamp();
|
||||
var sign = getCode(obj);
|
||||
var data = {
|
||||
appkey: 'mini_program_7ece3406-77f7-4939-8772-6918910f1c9f',
|
||||
version: '2.0',
|
||||
timestamp: timestamp,
|
||||
sign: sign,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
return data
|
||||
}
|
||||
function objKeySort(obj) {//排序的函数
|
||||
var timestamp = getTimestamp();
|
||||
|
||||
obj.appkey = 'mini_program_7ece3406-77f7-4939-8772-6918910f1c9f';
|
||||
obj.version = '2.0';
|
||||
obj.timestamp = timestamp;
|
||||
|
||||
var newkey = Object.keys(obj).sort();
|
||||
//先用Object内置类的keys方法获取要排序对象的属性名,再利用Array原型上的sort方法对获取的属性名进行排序,newkey是一个数组
|
||||
var newObj = {};//创建一个新的对象,用于存放排好序的键值对
|
||||
for (var i = 0; i < newkey.length; i++) {//遍历newkey数组
|
||||
newObj[newkey[i]] = obj[newkey[i]];//向新创建的对象中按照排好的顺序依次增加键值对
|
||||
}
|
||||
console.log(newObj)
|
||||
var objToStr=""
|
||||
for (var key in newObj) {
|
||||
objToStr = objToStr+ key + newObj[key]
|
||||
}
|
||||
delete obj.appkey;
|
||||
delete obj.version;
|
||||
delete obj.timestamp;
|
||||
|
||||
return objToStr;//返回排好序的新对象
|
||||
}
|
||||
// var obj = { name: "zhangsan", age: 8, ace: 5, nbme: "lisi" };//要排序的对象
|
||||
// objKeySort(obj); //函数执行
|
||||
|
||||
|
||||
module.exports = {
|
||||
objKeySort: objKeySort,
|
||||
apiHeader: apiHeader
|
||||
}
|
||||
11
utils/filter.wxs
Normal file
11
utils/filter.wxs
Normal file
@@ -0,0 +1,11 @@
|
||||
function extractLastFourDigits(text) {
|
||||
if (text&&text.indexOf('1') !== -1 && text.length >= 11) {
|
||||
var lastFourDigits = text.slice(-4);
|
||||
return lastFourDigits;
|
||||
} else {
|
||||
return "****";
|
||||
}
|
||||
}
|
||||
module.exports = {
|
||||
extractLastFourDigits: extractLastFourDigits,
|
||||
};
|
||||
228
utils/http.js
Normal file
228
utils/http.js
Normal file
@@ -0,0 +1,228 @@
|
||||
// var devUrl = "http://39.106.44.112:8701"; // 测试
|
||||
var devUrl = "https://oil-server.sxlyb.com"; //生产
|
||||
// var devUrl = "http://192.168.8.48:8701"; // 开发
|
||||
var picImg = "http://static.sxlyb.com/images/";
|
||||
|
||||
const app = getApp();
|
||||
|
||||
function getCode(phone) {
|
||||
var md4 =
|
||||
"appkeyandroid_ea031a3f-f130-43c4-8c95-6897d8a03697phone" +
|
||||
phone +
|
||||
"role1timestamp" +
|
||||
getTimestamp() +
|
||||
"type3version2.0";
|
||||
|
||||
var md5 = require("../utils/md5.js");
|
||||
var md5 = md5.hex_md5(md4).toUpperCase();
|
||||
return md5;
|
||||
}
|
||||
|
||||
function getTimestamp() {
|
||||
var myDate = new Date();
|
||||
var timestamp = formatTime(myDate.getTime(), "YMDHMS");
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
function formatTime(value, type) {
|
||||
var dataTime = "";
|
||||
var data = new Date();
|
||||
data.setTime(value);
|
||||
var year = data.getFullYear();
|
||||
var month = addZero(data.getMonth() + 1);
|
||||
var day = addZero(data.getDate());
|
||||
var hour = addZero(data.getHours());
|
||||
var minute = addZero(data.getMinutes());
|
||||
var second = addZero(data.getSeconds());
|
||||
if (type == "YMD") {
|
||||
dataTime = year + "-" + month + "-" + day;
|
||||
} else if (type == "YMDHMS") {
|
||||
dataTime =
|
||||
year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
} else if (type == "MDHMS") {
|
||||
dataTime = month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
// dataTime =123;
|
||||
} else if (type == "HMS") {
|
||||
dataTime = hour + ":" + minute + ":" + second;
|
||||
} else if (type == "YM") {
|
||||
dataTime = year + "-" + month;
|
||||
}
|
||||
return dataTime; //灏嗘牸寮忓寲鍚庣殑瀛楃涓茶緭鍑哄埌鍓嶇鏄剧ず
|
||||
}
|
||||
|
||||
function addZero(val) {
|
||||
if (val < 10) {
|
||||
return "0" + val;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
function maskFlag(that) {
|
||||
if (that.data.maskFlag == true) {
|
||||
that.setData({
|
||||
maskFlag: false,
|
||||
});
|
||||
} else {
|
||||
that.setData({
|
||||
maskFlag: true,
|
||||
boxDetail: true,
|
||||
payBox: true,
|
||||
showNotice: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function weChat(that) {
|
||||
// 登录
|
||||
wx.login({
|
||||
success: function (res) {
|
||||
if (res.code) {
|
||||
//发起网络请求
|
||||
wx.request({
|
||||
url: devUrl + "/api/v1/cooperation/openId",
|
||||
data: {
|
||||
code: res.code,
|
||||
},
|
||||
success: function (res) {
|
||||
if (res.data.code == 0) {
|
||||
wx.setStorageSync("sessionKey", res.data.data.sessionKey);
|
||||
if (res.data.data.state == 1) {
|
||||
if(res.data.cooperations){
|
||||
wx.setStorageSync("cooperations", res.data.cooperations);
|
||||
}
|
||||
if(res.data.data.cooperation){
|
||||
wx.setStorageSync("cooperation", res.data.data.cooperation);
|
||||
}
|
||||
wx.reLaunch({
|
||||
url: "/pages/oilManage/oilManage",
|
||||
});
|
||||
} else if (res.data.data.state == 0) {
|
||||
wx.setStorageSync("weChatId", res.data.data.weChatId);
|
||||
wx.switchTab({
|
||||
url:
|
||||
"/pages/login-wx/login-wx?weChatId=" +
|
||||
res.data.data.weChatId,
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (res) {
|
||||
console.log(res.data);
|
||||
},
|
||||
fail: function (data) {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: "网络传输异常",
|
||||
showCancel: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
} else {
|
||||
wx.redirectTo({
|
||||
url: "../login/login",
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: function () {
|
||||
// wx.showModal({
|
||||
// title: '警告通知',
|
||||
// content: '您点击了拒绝授权,将无法正常显示个人信息,点击确定重新获取授权。',
|
||||
// })
|
||||
|
||||
wx.navigateTo({
|
||||
url: "../login/login",
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function findId(that) {
|
||||
wx.setStorageSync("name", "");
|
||||
wx.setStorageSync("number", "");
|
||||
// var that = this;
|
||||
wx.request({
|
||||
url: devUrl + "/api/v1/supply/detail/info",
|
||||
data: {
|
||||
phone: wx.getStorageSync("phone"),
|
||||
},
|
||||
success: function (res) {
|
||||
if (res.data.code == 0) {
|
||||
wx.setStorageSync("id", res.data.data.id);
|
||||
// wx.setStorageSync('payPassword', res.data.object.user.payPassword)
|
||||
wx.setStorageSync("name", res.data.data.name);
|
||||
if (res.data.data.vehicle) {
|
||||
wx.setStorageSync("number", res.data.data.vehicle);
|
||||
}
|
||||
// var state = res.data.object.user.state;
|
||||
// 1 "审核状态:审核中"
|
||||
// 2 "审核状态:审核失败(认证通过,即可发货)"
|
||||
// 3 "审核状态:已认证"
|
||||
// 4 "审核状态:未认证(认证通过,即可发货)
|
||||
// if (state == 1) {
|
||||
// state = "审核中"
|
||||
// } else if (state == 2) {
|
||||
// state = "审核失败"
|
||||
// } else if (state == 3) {
|
||||
// state = "已认证"
|
||||
// } else if (state == 4) {
|
||||
// state = "未认证"
|
||||
// }
|
||||
// wx.setStorageSync('state', state)
|
||||
}
|
||||
},
|
||||
error: function () {
|
||||
wx.hideLoading();
|
||||
console.log(res);
|
||||
},
|
||||
fail: function (data) {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: "网络传输异常",
|
||||
showCancel: false,
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function showMsg(msg) {
|
||||
wx.showModal({
|
||||
title: "提示",
|
||||
content: msg,
|
||||
showCancel: false,
|
||||
});
|
||||
}
|
||||
function ifNull(str) {
|
||||
if (str == null) {
|
||||
str = "";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function ifNullMoney(str) {
|
||||
if (str == null) {
|
||||
str = "";
|
||||
} else {
|
||||
str = str + "元";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
function renderTime(date) {
|
||||
var dateee = new Date(date).toJSON();
|
||||
return new Date(+new Date(dateee) + 8 * 3600 * 1000)
|
||||
.toISOString()
|
||||
.replace(/T/g, " ")
|
||||
.replace(/\.[\d]{3}Z/, "")
|
||||
.replace(/-/g, "/");
|
||||
}
|
||||
module.exports = {
|
||||
devUrl: devUrl,
|
||||
picImg:picImg,
|
||||
formatTime: formatTime,
|
||||
maskFlag: maskFlag,
|
||||
weChat: weChat,
|
||||
findId: findId,
|
||||
showMsg: showMsg,
|
||||
ifNull: ifNull,
|
||||
ifNullMoney: ifNullMoney,
|
||||
renderTime: renderTime,
|
||||
};
|
||||
231
utils/md5.js
Normal file
231
utils/md5.js
Normal file
@@ -0,0 +1,231 @@
|
||||
|
||||
var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
|
||||
var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
|
||||
var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
|
||||
|
||||
/*
|
||||
* These are the functions you'll usually want to call
|
||||
* They take string arguments and return either hex or base-64 encoded strings
|
||||
*/
|
||||
function hex_md5(s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }
|
||||
function b64_md5(s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }
|
||||
function str_md5(s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }
|
||||
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
|
||||
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
|
||||
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
|
||||
|
||||
/*
|
||||
* Perform a simple self-test to see if the VM is working
|
||||
*/
|
||||
function md5_vm_test() {
|
||||
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the MD5 of an array of little-endian words, and a bit length
|
||||
*/
|
||||
function core_md5(x, len) {
|
||||
/* append padding */
|
||||
x[len >> 5] |= 0x80 << ((len) % 32);
|
||||
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
||||
|
||||
var a = 1732584193;
|
||||
var b = -271733879;
|
||||
var c = -1732584194;
|
||||
var d = 271733878;
|
||||
|
||||
for (var i = 0; i < x.length; i += 16) {
|
||||
var olda = a;
|
||||
var oldb = b;
|
||||
var oldc = c;
|
||||
var oldd = d;
|
||||
|
||||
a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
|
||||
d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
|
||||
c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
|
||||
b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
||||
a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
|
||||
d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
||||
c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
||||
b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
|
||||
a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
||||
d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
||||
c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
|
||||
b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
||||
a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
||||
d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
|
||||
c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
||||
b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
||||
|
||||
a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
|
||||
d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
||||
c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
|
||||
b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
|
||||
a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
|
||||
d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
|
||||
c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
|
||||
b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
|
||||
a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
|
||||
d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
||||
c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
|
||||
b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
||||
a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
||||
d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
|
||||
c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
||||
b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
||||
|
||||
a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
|
||||
d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
||||
c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
||||
b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
|
||||
a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
||||
d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
||||
c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
|
||||
b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
||||
a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
|
||||
d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
|
||||
c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
|
||||
b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
|
||||
a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
|
||||
d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
|
||||
c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
|
||||
b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
|
||||
|
||||
a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
|
||||
d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
||||
c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
||||
b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
|
||||
a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
||||
d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
||||
c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
|
||||
b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
||||
a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
||||
d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
|
||||
c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
||||
b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
||||
a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
|
||||
d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
||||
c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
|
||||
b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
|
||||
|
||||
a = safe_add(a, olda);
|
||||
b = safe_add(b, oldb);
|
||||
c = safe_add(c, oldc);
|
||||
d = safe_add(d, oldd);
|
||||
}
|
||||
return Array(a, b, c, d);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions implement the four basic operations the algorithm uses.
|
||||
*/
|
||||
function md5_cmn(q, a, b, x, s, t) {
|
||||
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
|
||||
}
|
||||
function md5_ff(a, b, c, d, x, s, t) {
|
||||
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
|
||||
}
|
||||
function md5_gg(a, b, c, d, x, s, t) {
|
||||
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
|
||||
}
|
||||
function md5_hh(a, b, c, d, x, s, t) {
|
||||
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
|
||||
}
|
||||
function md5_ii(a, b, c, d, x, s, t) {
|
||||
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the HMAC-MD5, of a key and some data
|
||||
*/
|
||||
function core_hmac_md5(key, data) {
|
||||
var bkey = str2binl(key);
|
||||
if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
|
||||
|
||||
var ipad = Array(16), opad = Array(16);
|
||||
for (var i = 0; i < 16; i++) {
|
||||
ipad[i] = bkey[i] ^ 0x36363636;
|
||||
opad[i] = bkey[i] ^ 0x5C5C5C5C;
|
||||
}
|
||||
|
||||
var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
|
||||
return core_md5(opad.concat(hash), 512 + 128);
|
||||
}
|
||||
|
||||
/*
|
||||
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
|
||||
* to work around bugs in some JS interpreters.
|
||||
*/
|
||||
function safe_add(x, y) {
|
||||
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
|
||||
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
||||
return (msw << 16) | (lsw & 0xFFFF);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bitwise rotate a 32-bit number to the left.
|
||||
*/
|
||||
function bit_rol(num, cnt) {
|
||||
return (num << cnt) | (num >>> (32 - cnt));
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert a string to an array of little-endian words
|
||||
* If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
|
||||
*/
|
||||
function str2binl(str) {
|
||||
var bin = Array();
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for (var i = 0; i < str.length * chrsz; i += chrsz)
|
||||
bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
|
||||
return bin;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a string
|
||||
*/
|
||||
function binl2str(bin) {
|
||||
var str = "";
|
||||
var mask = (1 << chrsz) - 1;
|
||||
for (var i = 0; i < bin.length * 32; i += chrsz)
|
||||
str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a hex string.
|
||||
*/
|
||||
function binl2hex(binarray) {
|
||||
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
|
||||
var str = "";
|
||||
for (var i = 0; i < binarray.length * 4; i++) {
|
||||
str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
|
||||
hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert an array of little-endian words to a base-64 string
|
||||
*/
|
||||
function binl2b64(binarray) {
|
||||
var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
var str = "";
|
||||
for (var i = 0; i < binarray.length * 4; i += 3) {
|
||||
var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16)
|
||||
| (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8)
|
||||
| ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
|
||||
for (var j = 0; j < 4; j++) {
|
||||
if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
|
||||
else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
hex_md5: hex_md5,
|
||||
|
||||
}
|
||||
253
utils/pay.js
Normal file
253
utils/pay.js
Normal file
@@ -0,0 +1,253 @@
|
||||
const app = getApp()
|
||||
// var pay = require('../../utils/pay.js');
|
||||
function operation(a, b, digits, op) {
|
||||
var o1 = toInteger(a)
|
||||
var o2 = toInteger(b)
|
||||
var n1 = o1.num
|
||||
var n2 = o2.num
|
||||
var t1 = o1.times
|
||||
var t2 = o2.times
|
||||
var max = t1 > t2 ? t1 : t2
|
||||
var result = null
|
||||
switch (op) {
|
||||
case 'add':
|
||||
if (t1 === t2) { // 两个小数位数相同
|
||||
result = n1 + n2
|
||||
} else if (t1 > t2) { // o1 小数位 大于 o2
|
||||
result = n1 + n2 * (t1 / t2)
|
||||
} else { // o1 小数位 小于 o2
|
||||
result = n1 * (t2 / t1) + n2
|
||||
}
|
||||
return result / max
|
||||
case 'subtract':
|
||||
if (t1 === t2) {
|
||||
result = n1 - n2
|
||||
} else if (t1 > t2) {
|
||||
result = n1 - n2 * (t1 / t2)
|
||||
} else {
|
||||
result = n1 * (t2 / t1) - n2
|
||||
}
|
||||
return result / max
|
||||
case 'multiply':
|
||||
result = (n1 * n2) / (t1 * t2)
|
||||
return result
|
||||
case 'divide':
|
||||
result = (n1 / n2) * (t2 / t1)
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
function nullRes(a) {
|
||||
if (a == 'null') {
|
||||
a = "";
|
||||
return a;
|
||||
} else if (a == null) {
|
||||
a = "";
|
||||
return a;
|
||||
} else {
|
||||
return a;
|
||||
};
|
||||
}
|
||||
|
||||
function toFixed(num, s) {
|
||||
var times = Math.pow(10, s)
|
||||
var des = num * times + 0.6
|
||||
des = parseInt(des, 10) / times
|
||||
return des + ''
|
||||
}
|
||||
|
||||
/*
|
||||
* 将一个浮点数转成整数,返回整数和倍数。如 3.14 >> 314,倍数是 100
|
||||
* @param floatNum {number} 小数
|
||||
* @return {object}
|
||||
* {times:100, num: 314}
|
||||
*/
|
||||
function toInteger(floatNum) {
|
||||
var ret = {
|
||||
times: 1,
|
||||
num: 0
|
||||
}
|
||||
if (isInteger(floatNum)) {
|
||||
ret.num = floatNum
|
||||
return ret
|
||||
}
|
||||
var strfi = floatNum + ''
|
||||
var dotPos = strfi.indexOf('.')
|
||||
var len = strfi.substr(dotPos + 1).length
|
||||
var times = Math.pow(10, len)
|
||||
var intNum = parseInt(floatNum * times + 0.5, 10)
|
||||
ret.times = times
|
||||
ret.num = intNum
|
||||
return ret
|
||||
}
|
||||
/** 判断obj是否为一个整数*/
|
||||
function isInteger(obj) {
|
||||
return Math.floor(obj) === obj
|
||||
}
|
||||
|
||||
function wxpay(phone, money, originalPrice, uuid, cooperationId, that, number) {
|
||||
wx.showLoading({
|
||||
title: '支付请求中....',
|
||||
});
|
||||
wx.request({
|
||||
url: app.globalData.devUrl + "/api/v1/wxpay/pay/pre/" + phone,
|
||||
header: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
data: {
|
||||
phone: phone,
|
||||
// openId: wx.getStorageSync("weChatId"),
|
||||
// tradeType: "JSAPI",
|
||||
// type: 3,
|
||||
actualMoney: toFixed(operation(money, 100, 2, "multiply"), 2),
|
||||
totalMoney: toFixed(operation(originalPrice, 100, 2, "multiply"), 2),
|
||||
// uuid: uuid,
|
||||
cooperationId: cooperationId,
|
||||
number: number,
|
||||
},
|
||||
|
||||
method: 'POST',
|
||||
success: function(res) {
|
||||
|
||||
wx.hideLoading()
|
||||
if (res.data.code == 0) {
|
||||
// 发起支付
|
||||
var param = res.data.data;
|
||||
|
||||
var outTradeNo = param.outTradeNo;
|
||||
|
||||
wx.requestPayment({
|
||||
// appId: param.appid,
|
||||
timeStamp: param.timeStamp,
|
||||
nonceStr: param.nonceStr,
|
||||
package: param.package,
|
||||
signType: param.signType,
|
||||
paySign: param.paySign,
|
||||
fail: function(res) {
|
||||
|
||||
that.setData({
|
||||
maskFlag: true,
|
||||
})
|
||||
wx.showToast({
|
||||
title: '支付取消'
|
||||
})
|
||||
},
|
||||
success: function() {
|
||||
that.setData({
|
||||
maskFlag: true,
|
||||
})
|
||||
payResult(cooperationId, outTradeNo);
|
||||
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: res.data.msg,
|
||||
showCancel: false,
|
||||
})
|
||||
that.setData({
|
||||
maskFlag: true,
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
|
||||
that.setData({
|
||||
maskFlag: true,
|
||||
})
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: res.data.msg,
|
||||
showCancel: false,
|
||||
})
|
||||
|
||||
|
||||
},
|
||||
fail: function(data) {
|
||||
wx.hideLoading()
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: '网络传输异常',
|
||||
showCancel: false,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function payResult(cooperationId, outTradeNo) {
|
||||
wx.request({
|
||||
url: app.globalData.devUrl + "/api/v1/wxpay/pay/status",
|
||||
data: {
|
||||
cooperationId: cooperationId,
|
||||
outTradeNo: outTradeNo
|
||||
},
|
||||
method: 'GET',
|
||||
error: function(res) {
|
||||
console.log(res);
|
||||
},
|
||||
success: function(res) {
|
||||
if (res.data.code == 0) {
|
||||
wx.showModal({
|
||||
title: '提示',
|
||||
content: res.data.msg,
|
||||
showCancel: false,
|
||||
success: function() {
|
||||
findId()
|
||||
wx.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
setInterval(payResult(orderNo), 1000);
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function throttle(fn, gapTime) {
|
||||
if (gapTime == null || gapTime == undefined) {
|
||||
gapTime = 1500
|
||||
}
|
||||
|
||||
let _lastTime = null
|
||||
|
||||
// 返回新的函数
|
||||
return function() {
|
||||
let _nowTime = +new Date()
|
||||
if (_nowTime - _lastTime > gapTime || !_lastTime) {
|
||||
fn.apply(this, arguments) //将this和参数传给原函数
|
||||
_lastTime = _nowTime
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findId() {
|
||||
var that = this;
|
||||
wx.request({
|
||||
url: app.globalData.devUrl + '/api/v1/user/detail/info/' + wx.getStorageSync("phone"),
|
||||
success: function(res) {
|
||||
if (res.data.code == 0) {
|
||||
wx.setStorageSync('id', res.data.data.name)
|
||||
wx.setStorageSync('number', res.data.data.number)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
module.exports = {
|
||||
wxpay: wxpay,
|
||||
payResult: payResult,
|
||||
isInteger: isInteger,
|
||||
toInteger: toInteger,
|
||||
toFixed: toFixed,
|
||||
nullRes: nullRes,
|
||||
operation: operation,
|
||||
throttle: throttle
|
||||
}
|
||||
61
utils/qrPay.js
Normal file
61
utils/qrPay.js
Normal file
@@ -0,0 +1,61 @@
|
||||
const app = getApp();
|
||||
const host = app.globalData.devUrl;
|
||||
|
||||
// 我的油卡收钱
|
||||
const qcodePay = function (qrdata) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/api/v1/cooperation/pay/qcodePay`,
|
||||
method: `POST`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
cooId: wx.getStorageSync("cooperation").id,
|
||||
...qrdata,
|
||||
},
|
||||
success: function (e) {
|
||||
if (e.data.code == 0) {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 获取加油站统计信息
|
||||
const count = function (data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/api/v1/cooperation/coo/count`,
|
||||
method: `POST`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
},
|
||||
data: {
|
||||
cooId: wx.getStorageSync("cooperation").id,
|
||||
...data,
|
||||
},
|
||||
success: function (e) {
|
||||
if (e.data.code == 0) {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
qcodePay,
|
||||
count,
|
||||
};
|
||||
312
utils/url.js
Normal file
312
utils/url.js
Normal file
@@ -0,0 +1,312 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// url地址配置参数 start
|
||||
$.getUrlParam = function (name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = window.location.search.substr(1).match(reg);
|
||||
if (r != null)
|
||||
return unescape(r[2]);
|
||||
return null;
|
||||
};
|
||||
// url地址配置参数 end
|
||||
function operation(a, b, digits, op) {
|
||||
var o1 = toInteger(a)
|
||||
var o2 = toInteger(b)
|
||||
var n1 = o1.num
|
||||
var n2 = o2.num
|
||||
var t1 = o1.times
|
||||
var t2 = o2.times
|
||||
var max = t1 > t2 ? t1 : t2
|
||||
var result = null
|
||||
switch (op) {
|
||||
case 'add':
|
||||
if (t1 === t2) { // 两个小数位数相同
|
||||
result = n1 + n2
|
||||
} else if (t1 > t2) { // o1 小数位 大于 o2
|
||||
result = n1 + n2 * (t1 / t2)
|
||||
} else { // o1 小数位 小于 o2
|
||||
result = n1 * (t2 / t1) + n2
|
||||
}
|
||||
return result / max
|
||||
case 'subtract':
|
||||
if (t1 === t2) {
|
||||
result = n1 - n2
|
||||
} else if (t1 > t2) {
|
||||
result = n1 - n2 * (t1 / t2)
|
||||
} else {
|
||||
result = n1 * (t2 / t1) - n2
|
||||
}
|
||||
return result / max
|
||||
case 'multiply':
|
||||
result = (n1 * n2) / (t1 * t2)
|
||||
return result
|
||||
case 'divide':
|
||||
result = (n1 / n2) * (t2 / t1)
|
||||
return result
|
||||
}
|
||||
}
|
||||
function toFixed(num, s) {
|
||||
var times = Math.pow(10, s)
|
||||
var des = num * times + 0.6
|
||||
des = parseInt(des, 10) / times
|
||||
return des + ''
|
||||
}
|
||||
|
||||
/*
|
||||
* 将一个浮点数转成整数,返回整数和倍数。如 3.14 >> 314,倍数是 100
|
||||
* @param floatNum {number} 小数
|
||||
* @return {object}
|
||||
* {times:100, num: 314}
|
||||
*/
|
||||
function toInteger(floatNum) {
|
||||
var ret = { times: 1, num: 0 }
|
||||
if (isInteger(floatNum)) {
|
||||
ret.num = floatNum
|
||||
return ret
|
||||
}
|
||||
var strfi = floatNum + ''
|
||||
var dotPos = strfi.indexOf('.')
|
||||
var len = strfi.substr(dotPos + 1).length
|
||||
var times = Math.pow(10, len)
|
||||
var intNum = parseInt(floatNum * times + 0.5, 10)
|
||||
ret.times = times
|
||||
ret.num = intNum
|
||||
return ret
|
||||
}
|
||||
/*
|
||||
* 判断obj是否为一个整数
|
||||
*/
|
||||
function isInteger(obj) {
|
||||
return Math.floor(obj) === obj
|
||||
}
|
||||
function getRequest() {
|
||||
var url = window.location.search; //获取url中"?"符后的字串
|
||||
var theRequest = new Object();
|
||||
if (url.indexOf("?") != -1) {
|
||||
var str = url.substr(1);
|
||||
strs = str.split("&");
|
||||
for (var i = 0; i < strs.length; i++) {
|
||||
//就是这句的问题
|
||||
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
|
||||
//之前用了unescape()
|
||||
//才会出现乱码
|
||||
}
|
||||
}
|
||||
return theRequest;
|
||||
}
|
||||
var arr = getRequest();
|
||||
var searchtxt = arr['n']; //参数名
|
||||
|
||||
|
||||
// })(jQuery);
|
||||
|
||||
|
||||
//元素的补零计算
|
||||
function addZero(val) {
|
||||
if (val < 10) {
|
||||
return "0" + val;
|
||||
} else {
|
||||
return val;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
//实现vue中的过滤器功能 先定义过滤器 在使用 value是过滤器前面的值,type是过滤器中定义的字段
|
||||
function formatTime(value, type) {
|
||||
var dataTime = "";
|
||||
var data = new Date();
|
||||
data.setTime(value);
|
||||
var year = data.getFullYear();
|
||||
var month = addZero(data.getMonth() + 1);
|
||||
var day = addZero(data.getDate());
|
||||
var hour = addZero(data.getHours());
|
||||
var minute = addZero(data.getMinutes());
|
||||
var second = addZero(data.getSeconds());
|
||||
if (type == "YMD") {
|
||||
dataTime = year + "-" + month + "-" + day;
|
||||
} else if (type == "YMDHMS") {
|
||||
dataTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
} else if (type == "MDHMS") {
|
||||
dataTime = month + "-" + day + " " + hour + ":" + minute + ":" + second;
|
||||
// dataTime =123;
|
||||
} else if (type == "HMS") {
|
||||
dataTime = hour + ":" + minute + ":" + second;
|
||||
} else if (type == "YM") {
|
||||
dataTime = year + "-" + month;
|
||||
|
||||
}
|
||||
return dataTime; //将格式化后的字符串输出到前端显示
|
||||
|
||||
};
|
||||
|
||||
|
||||
//司机
|
||||
function getCode(phone) {
|
||||
|
||||
var md4 = "appkeyandroid_ea031a3f-f130-43c4-8c95-6897d8a03697phone" + phone + "role1timestamp" + getTimestamp() +
|
||||
"type1version2.0"
|
||||
|
||||
var md5 = hex_md5(md4).toUpperCase();
|
||||
return md5;
|
||||
|
||||
}
|
||||
//加油
|
||||
function YougetCode(phone) {
|
||||
|
||||
var md4 = "appkeyandroid_ea031a3f-f130-43c4-8c95-6897d8a03697phone" + phone + "role3timestamp" + getTimestamp() +
|
||||
"type3version2.0"
|
||||
|
||||
var md5 = hex_md5(md4).toUpperCase();
|
||||
return md5;
|
||||
|
||||
}
|
||||
function getTimestamp() {
|
||||
var myDate = new Date(); //获取系统当前时间
|
||||
var timestamp = formatTime(myDate.getTime(), "YMDHMS");
|
||||
;
|
||||
return timestamp;
|
||||
|
||||
}
|
||||
|
||||
|
||||
function findId(phone) {
|
||||
var rst;
|
||||
// 通过电话号码查id
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
url: devUrl + "/user/userGet?phone=" + phone,
|
||||
|
||||
})
|
||||
.done(function (res) {
|
||||
|
||||
var id = res.object.user.id;
|
||||
sessionStorage.setItem('id', id);
|
||||
rst = id;
|
||||
})
|
||||
.fail(function (err) {
|
||||
|
||||
//提示
|
||||
layer.open({
|
||||
content: '呜呜呜,出问题了。。。'
|
||||
, skin: 'msg'
|
||||
, time: 2 //2秒后自动关闭
|
||||
});
|
||||
})
|
||||
.always(function () {
|
||||
});
|
||||
return rst;
|
||||
}
|
||||
|
||||
//判断是否授权
|
||||
function weChatLogin() {
|
||||
var rst;
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
async: false,
|
||||
url: "http://www.kamo56.com/service/weChatAccess?type=1&code=" + $.getUrlParam('code'),
|
||||
})
|
||||
.done(function (res) {
|
||||
|
||||
if (res.code == 0) {
|
||||
sessionStorage.setItem('weChatId', res.object.weChatId); // 存入一个值
|
||||
if (res.object.state === 1) {
|
||||
|
||||
var phone = res.object.phone;
|
||||
sessionStorage.setItem('phone', res.object.phone);
|
||||
|
||||
rst = phone;
|
||||
} else {
|
||||
|
||||
sessionStorage.setItem('phone', false);
|
||||
rst = false;
|
||||
}
|
||||
} else {
|
||||
layer.open({
|
||||
content: res.msg,
|
||||
time: 2,
|
||||
});
|
||||
sessionStorage.setItem('phone', false);
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
.fail(function (err) {
|
||||
console.log(err);
|
||||
})
|
||||
.always(function () {
|
||||
});
|
||||
return rst;
|
||||
}
|
||||
|
||||
|
||||
function nullRes(a) {
|
||||
if (a == 'null') {
|
||||
a = "";
|
||||
return a;
|
||||
} else if (a == null) {
|
||||
a = "";
|
||||
return a;
|
||||
}
|
||||
|
||||
else {
|
||||
return a;
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
// 查询司机认证状态状态
|
||||
|
||||
function jumpLogin() {
|
||||
layer.open({
|
||||
content: "请获取短信验证码绑定微信与手机号码,绑定后下次可在公众号里直接使用微信登陆",
|
||||
time: 5,
|
||||
end: function () {
|
||||
window.location.href = "wxlogin.html?weChatId=" + sessionStorage.getItem('weChatId');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
layui.use('layer', function () {
|
||||
var $ = layui.jquery,
|
||||
layer = layui.layer; //独立版的layer无需执行这一句
|
||||
|
||||
layui.use(['form', 'layedit', 'laydate'], function () {
|
||||
|
||||
var form = layui.form,
|
||||
layer = layui.layer,
|
||||
layedit = layui.layedit,
|
||||
laydate = layui.laydate;
|
||||
|
||||
form.verify({
|
||||
must: function (value, item) {
|
||||
if (value == "") {
|
||||
return '吨位和照片为必输项';
|
||||
}
|
||||
},
|
||||
num: function (value, item) {
|
||||
if (!value || isNaN(value)) return '吨位只能填写数字'
|
||||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function ImagesScale() {
|
||||
ImagesZoom.init({
|
||||
"elem": ".imgScale"
|
||||
});
|
||||
}
|
||||
55
utils/util.js
Normal file
55
utils/util.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const formatTime = (date) => {
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const day = date.getDate();
|
||||
const hour = date.getHours();
|
||||
const minute = date.getMinutes();
|
||||
const second = date.getSeconds();
|
||||
|
||||
return (
|
||||
[year, month, day].map(formatNumber).join("/") +
|
||||
" " +
|
||||
[hour, minute, second].map(formatNumber).join(":")
|
||||
);
|
||||
};
|
||||
const formatNumber = (n) => {
|
||||
n = n.toString();
|
||||
return n[1] ? n : "0" + n;
|
||||
};
|
||||
|
||||
// 用法 timeStr('YYYY-MM-DD hh:mm:ss') => '2018-3-22 12:12:12'
|
||||
// 用法 timeStr('hh:mm:ss') => '12:12:12'
|
||||
// 也可使用第二参数格式化指定时间
|
||||
// timeStr('YYYY-MM-DD hh:mm:ss', '2018-3-22 12:12:12') => '2018-3-22 12:12:12'
|
||||
export function timeStr(time, type = "YYYY-MM-DD hh:mm") {
|
||||
let data = time ? new Date(time - 0) : new Date();
|
||||
let year = data.getFullYear();
|
||||
let month =
|
||||
data.getMonth() + 1 >= 10
|
||||
? data.getMonth() + 1
|
||||
: "0" + (data.getMonth() + 1);
|
||||
let day =
|
||||
data.getDate() >= 10 ? data.getDate().toString() : "0" + data.getDate();
|
||||
let hour =
|
||||
data.getHours() >= 10 ? data.getHours().toString() : "0" + data.getHours();
|
||||
let minutes =
|
||||
data.getMinutes() >= 10
|
||||
? data.getMinutes().toString()
|
||||
: "0" + data.getMinutes();
|
||||
let seconds =
|
||||
data.getSeconds() >= 10
|
||||
? data.getSeconds().toString()
|
||||
: "0" + data.getSeconds();
|
||||
return type
|
||||
.replace("YYYY", year)
|
||||
.replace("MM", month)
|
||||
.replace("DD", day)
|
||||
.replace("hh", hour)
|
||||
.replace("mm", minutes)
|
||||
.replace("ss", seconds);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
formatTime: formatTime,
|
||||
timeStr,
|
||||
};
|
||||
290
utils/withdraw.js
Normal file
290
utils/withdraw.js
Normal file
@@ -0,0 +1,290 @@
|
||||
const app = getApp();
|
||||
const host = app.globalData.devUrl;
|
||||
|
||||
|
||||
function handleRequest() {
|
||||
// wx.clearStorage();
|
||||
wx.showModal({
|
||||
title: '系统提示',
|
||||
content: '登录信息已过期,请重新登录',
|
||||
confirmText: "确认",
|
||||
confirmColor: '#1890FF',
|
||||
showCancel: false,
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
wx.reLaunch({
|
||||
url: '/pages/login-wx/login-wx',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 获取加油站列表
|
||||
export function oilStations(data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/list/oil/stations`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data,
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// 可提取金额
|
||||
export function totalMoney(stationId) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/wallet/total-money/${stationId}`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
// 查询油站的钱包详情
|
||||
export function walletDetail() {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/wallet/list/${wx.getStorageSync("cooperation").id}`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 获取验证码
|
||||
export function getCode() {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/send-code`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data: {
|
||||
phone: wx.getStorageSync("cooperation").phone,
|
||||
},
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// 修改密码
|
||||
export function resetPassword(data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/reset-password`,
|
||||
method: `post`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data,
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// 查询油站提现账户
|
||||
export function bankList() {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/user-bank/list/${wx.getStorageSync("cooperation").id}`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data: { state: 1 },
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// 提现
|
||||
export function handleWithdrawl(data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/withdrawl`,
|
||||
method: `post`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data,
|
||||
success: function (e) {
|
||||
let code = e.data.code
|
||||
if (code == 0 || code == '0000' || code == 2222 || code == 1250 || code == 2224 || code == 3802) {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
//提现记录
|
||||
export function withdrawlList(data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/draw/list`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data,
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//查询司机的钱包余额
|
||||
export function getDriverMoney(data) {
|
||||
return new Promise((reslove, reject) => {
|
||||
wx.request({
|
||||
url: `${host}/web/v1/coo/getDriverMoney`,
|
||||
method: `get`,
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded",
|
||||
"AccessToken": wx.getStorageSync("kybUser").accessToken,
|
||||
},
|
||||
data,
|
||||
success: function (e) {
|
||||
if (e.data.code == 0 || e.data.code === "0000") {
|
||||
reslove(e.data);
|
||||
} else {
|
||||
if (e.data.code == 10) {
|
||||
handleRequest()
|
||||
} else {
|
||||
reject(e.data);
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: function (e) {
|
||||
reject(e);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
2046
utils/wxcharts.js
Normal file
2046
utils/wxcharts.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user