diff --git a/app.js b/app.js index b53b42c..e6944c4 100644 --- a/app.js +++ b/app.js @@ -2,8 +2,8 @@ var t = require("setting.js"), o = require("./utils/auth.js"), a = require("./ut var os = t; var regeneratorRuntime = require('./utils/runtime.js'); var api = require("./api/api.js"); - var wxlog = require("./utils/wxlog.js"); +var md5 = require("./utils/md5.min.js"); //公共方法和变量 @@ -99,6 +99,9 @@ App({ //检查更新 this.checkUpdateVersion(); + wx.removeStorageSync('ukey'); + wx.removeStorageSync('api_token'); + var t = this.globalData.setting; //console.log(t) t.resourceUrl = t.url + "/template/mobile/rainbow"; @@ -149,7 +152,7 @@ App({ // }) // } // if(app.globalData.user_id){ //-- 启用默认的user_id -- - + // // app.promiseGet("/api/weshop/users/get/" + app.globalData.setting.stoid + "/" + app.globalData.user_id,{}).then(res=>{ // app.globalData.is_get_login=1; // if(res.data.code==0){ @@ -217,7 +220,6 @@ App({ } }) //} - } wx.getSystemInfo({ @@ -959,44 +961,91 @@ App({ }, - //---promise的使用get---- + + //---promise的使用get,data里面加一个参数,不需要默认带---- promiseGet: function (url, data) { + + var th=this; + + if (url.indexOf("http") == -1) url = this.globalData.setting.url + url; return new Promise((resolve, reject) => { + + th.ck_api_token((api_tk)=>{ data.isShowLoading && wx.showLoading(); + //增加门店id和配送方式 + //is_no_def不需要默认参数 + + var url1=url; + var arr_in_url=ut.getParams(url1); + + var header={ "content-type": "application/x-www-form-urlencoded" }; + var now=ut.gettimestamp(); + + var new_data={...arr_in_url,...data.data}; + var tk=a.set_req_sign(new_data,url1,now,api_tk); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + wx.request({ - url, - method: 'GET', - header: { "content-type": "application/x-www-form-urlencoded" }, - data: data.data, - success(res) { - data.isShowLoading && wx.hideLoading(); - resolve(res); - }, - fail(err) { data.isShowLoading && wx.hideLoading(); reject(err); } + url, + method: 'GET', + header: header, + data: data.data, + success(res) { + data.isShowLoading && wx.hideLoading(); + resolve(res); + }, + fail(err) { data.isShowLoading && wx.hideLoading(); reject(err); } }) }) + + + }) }, //---promise的使用get---- requestGet: function (url, data) { + + var url1=url; + var arr_in_url=ut.getParams(url1); if (url.indexOf("http") == -1) url = this.globalData.setting.url + url; + + this.ck_api_token((api_tk)=> { + data.isShowLoading && wx.showLoading(); + + var header= {"content-type": "application/x-www-form-urlencoded"}; + var now=ut.gettimestamp(); + + var new_data={...arr_in_url,...data.data}; + var tk=a.set_req_sign(new_data,url1,now,api_tk); + + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + wx.request({ url, method: 'GET', - header: { "content-type": "application/x-www-form-urlencoded" }, + header:header, data: data.data, success(res) { - data.isShowLoading && wx.hideLoading(); - data.success(res); + data.isShowLoading && wx.hideLoading(); + data.success(res); }, fail(err) { - data.isShowLoading && wx.hideLoading(); - if (data.fail) data.fail(err); + data.isShowLoading && wx.hideLoading(); + if (data.fail) data.fail(err); } }) + }) }, @@ -1792,8 +1841,150 @@ App({ if(type) url += "&type=1"; this.goto(url); + }, + + + + //判断有没有获取到api_token + ck_api_token(func){ + var api_token = wx.getStorageSync('api_token'); + var api_token_time = wx.getStorageSync('api_token_time'); + //token有存在本地的时候 + if(api_token){ + //判断有没有超出token的时间,超出的话就要重头拿token + var now=ut.formar_day(); + if(now!=api_token_time){ + //调用接口获取token + this.get_api_token(func); + return false; + } + func(api_token); + return false; } + this.get_api_token(func); + }, + + //获取api_token + get_api_token(func){ + + var api_token = wx.getStorageSync('api_token'); + var api_token_time = wx.getStorageSync('api_token_time'); + //token有存在本地的时候 + if(api_token){ + //判断有没有超出token的时间,超出的话就要重头拿token + var now=ut.formar_day(); + if(now==api_token_time){ + if(func) func(api_token); + return false; + } + } + + if(this.globalData.get_tking){ + setTimeout(()=>{ + this.get_api_token(func); + },1000) + return false; + } + + this.globalData.get_tking=1; + var th=this; + var ukey = wx.getStorageSync('ukey'); + if(!ukey){ + var url = th.globalData.setting.url + '/api/weshop/store/geStoreKey'; + var data={ + store_id:th.globalData.setting.stoid + } + var token1=md5(JSON.stringify(data)).toUpperCase(); + + console.log('tk1_fir:'+token1); + console.log('tk1_fir1:'+'GETSTOREKEY'+token1+th.globalData.setting.environment_key); + + var str = md5('GETSTOREKEY'+token1+th.globalData.setting.environment_key).toUpperCase(); + data.token=str; + + wx.request({ + url: url, + data: JSON.stringify(data), + method: "POST", + header: { + 'content-type': 'application/json' + },// 设置请求的 header + success: function (res) { + if(res.data.code==0){ + wx.setStorageSync("ukey", res.data.data.ukey); + th.get_api_token2(func); + }else{ + th.confirmBox(res.data.msg) + } + }, + fail: function (res) { + ut.m_toast('网络繁忙,请稍后重试'); + } + }) + return false; + } + + this.get_api_token2(func); + + }, + + get_api_token2(func){ + var th=this; + var ukey = wx.getStorageSync('ukey'); + var dd_json={ + store_id:th.globalData.setting.stoid, + ukey:ukey + } + + var ty= new Date(); + var c="-"; + + var m=ty.getMonth() + 1; + if(m<10) m="0"+m; + var day=ty.getDate(); + if(day<10) day="0"+day; + + var nday=ty.getFullYear() +c+m+c+day; + + //console.log('tk1_str:'+JSON.stringify(dd_json)); + var tk1=md5(JSON.stringify(dd_json)).toUpperCase(); + //console.log(tk1) + var tk2_str='GETAPITOKEN'+tk1+nday+th.globalData.setting.environment_key; + //console.log("tk2_str:"+tk2_str); + var tk2=md5(tk2_str).toUpperCase(); + //console.log(tk1) + var url = th.globalData.setting.url + '/api/weshop/store/getApiToken'; + var data1={ + 'store_id':th.globalData.setting.stoid, + 'ukey':ukey, + 'token':tk2 + } + wx.request({ + url: url, + data: JSON.stringify(data1), + method: "POST", + header: { + 'content-type': 'application/json' + },// 设置请求的 header + success: function (res) { + if(res.data.code==0){ + //记录当天,隔天就要重新刷新 + var now=ut.formar_day(); + var api_token =res.data.data; + wx.setStorageSync('api_token',api_token); + wx.setStorageSync('api_token_time',now); + th.globalData.get_tking=0; + if(func) func(api_token); + }else{ + getApp().confirmBox(res.data.msg) + } + }, + fail: function (res) { + ut.m_toast('网络繁忙,请稍后重试'); + } + }) + } diff --git a/components/diy_user_tools_services/diy_user_tools_services.js b/components/diy_user_tools_services/diy_user_tools_services.js index 7dc979a..64a5e97 100644 --- a/components/diy_user_tools_services/diy_user_tools_services.js +++ b/components/diy_user_tools_services/diy_user_tools_services.js @@ -232,12 +232,14 @@ Component({ } //-- 如果是有新的tool要添加进去 -- for (let ig = 0; ig 0) { - th.setData({ - isclose: 0 - }); - t_pay.set_pay_url("/api/weshop/order/pay/createRechargeOrder") - t_pay.pay( - { - parentSn: data.data.order_sn, - store_id: oo.stoid - },function (){ - wx.showToast({ - title: '购买成功', - icon: 'success', - duration: 2000 - }); - setTimeout(function () { - wx.reLaunch({ - url: "/packageG/pages/payment/pay_success/pay_success?card=1&order_id=" + th.data.order_id, - }) - }, 1000) - - },function (e){ - - console.log('kkkkkkk'); + getApp().request.promisePost("/api/weshop/recharge/saveRecharge", { + data: pdata, + is_json:1 + }).then(res => { + wx.hideLoading(); + if (res.statusCode == 200) { + var data = res.data; + if (data.code == 0) { + th.data.order_id = data.data.order_id; + // console.log('myyyyyyyyyyyyyyyyyy', data.data); + if (th.data.is_cart) { + var list = th.data.cartlist_y; + for (var i = 0; i < list.length; i++) { + //删除购物车 + a.delete("/api/weshop/cartService/del/" + oo.stoid + "/" + list[i].id, {}); + } + } + var order_amount = pdata.account; + //要进行判断,如果是用微信支付,就要跳转到支付界面 + if (order_amount > 0) { + th.setData({ + isclose: 0 + }); + t_pay.set_pay_url("/api/weshop/order/pay/createRechargeOrder") + t_pay.pay( + { + parentSn: data.data.order_sn, + store_id: oo.stoid + },function (){ wx.showToast({ - title: e, - icon: 'none', + title: '购买成功', + icon: 'success', duration: 2000 }); - setTimeout(function () { wx.reLaunch({ - url: "/pages/user/order_list/order_list?index=2&tabindex=1", + url: "/packageG/pages/payment/pay_success/pay_success?card=1&order_id=" + th.data.order_id, }) }, 1000) - } - ) - + },function (e){ - // getApp().request.post("/api/weshop/order/pay/createRechargeOrder", { - // data: { - // parentSn: data.data.order_sn, - // store_id: oo.stoid - // }, - // success: function(su) { - // - // if(su.data.code==0) { - // - // var n = su.data.data; - // // console.log('su---->', n); - // let order_id = data.data.order_id; - // th.weixinPay(n, - // function () { - // // getApp().showWarning("购买成功"); - // wx.showToast({ - // title: '购买成功', - // icon: 'success', - // duration: 2000 - // }); - // setTimeout(function () { - // wx.reLaunch({ - // url: "/packageG/pages/payment/pay_success/pay_success?card=1&order_id=" + order_id, - // }) - // }, 1000) - // }, - // function () { - // getApp().showWarning("支付失败"); - // setTimeout(function () { - // wx.reLaunch({ - // url: "/pages/user/order_list/order_list?index=2&tabindex=1", - // }) - // }, 1000) - // }) - // }else{ - // - // this.data.is_summit_ing = 0; - // - // wx.showToast({ - // title: su.data.msg, - // icon: 'none', - // duration: 2000 - // }); - // } - // } - // }) - } - } else { - th.data.is_summit_ing = 0; //是否提交中 - getApp().confirmBox(data.msg); + console.log('kkkkkkk'); + + wx.showToast({ + title: e, + icon: 'none', + duration: 2000 + }); + + setTimeout(function () { + wx.reLaunch({ + url: "/pages/user/order_list/order_list?index=2&tabindex=1", + }) + }, 1000) + + } + ) + + + // getApp().request.post("/api/weshop/order/pay/createRechargeOrder", { + // data: { + // parentSn: data.data.order_sn, + // store_id: oo.stoid + // }, + // success: function(su) { + // + // if(su.data.code==0) { + // + // var n = su.data.data; + // // console.log('su---->', n); + // let order_id = data.data.order_id; + // th.weixinPay(n, + // function () { + // // getApp().showWarning("购买成功"); + // wx.showToast({ + // title: '购买成功', + // icon: 'success', + // duration: 2000 + // }); + // setTimeout(function () { + // wx.reLaunch({ + // url: "/packageG/pages/payment/pay_success/pay_success?card=1&order_id=" + order_id, + // }) + // }, 1000) + // }, + // function () { + // getApp().showWarning("支付失败"); + // setTimeout(function () { + // wx.reLaunch({ + // url: "/pages/user/order_list/order_list?index=2&tabindex=1", + // }) + // }, 1000) + // }) + // }else{ + // + // this.data.is_summit_ing = 0; + // + // wx.showToast({ + // title: su.data.msg, + // icon: 'none', + // duration: 2000 + // }); + // } + // } + // }) } } else { th.data.is_summit_ing = 0; //是否提交中 - console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); + getApp().confirmBox(data.msg); } - }, - fail: function() { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function() {} - }) + } else { + th.data.is_summit_ing = 0; //是否提交中 + console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); + } + }).catch(function(err) { + // error + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); + }); }, cart_set_err: function(e) { diff --git a/packageA/pages/my_service/appment_main.js b/packageA/pages/my_service/appment_main.js index 065c292..42f1711 100644 --- a/packageA/pages/my_service/appment_main.js +++ b/packageA/pages/my_service/appment_main.js @@ -117,15 +117,11 @@ Page({ "isxz": 1 } - var data = JSON.stringify(json); - wx.request({ - url: url, - data: json, - method: 'post', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + //var data = JSON.stringify(json); + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { th.setData({ is_sub: 0 }) @@ -177,7 +173,6 @@ Page({ getApp().my_warnning(res.data.msg, 0, th); th.settime(); } - } }) }, diff --git a/packageA/pages/my_service/beauty_deta.js b/packageA/pages/my_service/beauty_deta.js index c89bb33..cd18067 100644 --- a/packageA/pages/my_service/beauty_deta.js +++ b/packageA/pages/my_service/beauty_deta.js @@ -170,14 +170,10 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning(res.data.data, 1, th); setTimeout(function() { @@ -189,7 +185,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } else { var pages = getCurrentPages(); //当前页面 @@ -374,20 +370,16 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("更改成功", 0, th); } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, //预览头像 diff --git a/packageA/pages/my_service/tment_details.js b/packageA/pages/my_service/tment_details.js index 7434cca..006aa4d 100644 --- a/packageA/pages/my_service/tment_details.js +++ b/packageA/pages/my_service/tment_details.js @@ -41,14 +41,9 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { my_confirm.open_cancel(0); if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); @@ -59,7 +54,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } ); diff --git a/packageA/pages/my_service/tment_eval.js b/packageA/pages/my_service/tment_eval.js index f51b9bf..c852830 100644 --- a/packageA/pages/my_service/tment_eval.js +++ b/packageA/pages/my_service/tment_eval.js @@ -177,15 +177,12 @@ Page({ "star": stars + 1, "storeId": a.stoid, }; - var data = JSON.stringify(json); //转换成json格式 - wx.request({ - url: url, - data: data, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + //var data = JSON.stringify(json); //转换成json格式 + + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.data.code == 0) { getApp().my_warnning("评价成功", 1, th); @@ -198,7 +195,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, diff --git a/packageA/pages/my_service/tment_order_list.js b/packageA/pages/my_service/tment_order_list.js index 7e0b0a7..d4b3a9d 100644 --- a/packageA/pages/my_service/tment_order_list.js +++ b/packageA/pages/my_service/tment_order_list.js @@ -154,14 +154,11 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); var id = th.data.activeCategoryId; @@ -180,7 +177,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }) diff --git a/packageA/pages/my_service2/appment_main.js b/packageA/pages/my_service2/appment_main.js index dbfcb61..fe9c571 100644 --- a/packageA/pages/my_service2/appment_main.js +++ b/packageA/pages/my_service2/appment_main.js @@ -137,17 +137,13 @@ Page({ req_arr.list.push(json); } } - console.log(req_arr); + //console.log(req_arr); //return false; - var js_data = JSON.stringify(req_arr); - wx.request({ - url: url, - data: js_data, - method: 'post', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + //var js_data = JSON.stringify(req_arr); + + getApp().request.promisePost(url, { + data: req_arr,is_json:1,is_normal:1 + }).then(res => { th.setData({ is_sub: 0}) wx.hideLoading(); if (res.data.code == 0) { @@ -170,7 +166,7 @@ Page({ getApp().my_warnning(res.data.msg, 0, th); th.settime(); } - } + }) }, diff --git a/packageA/pages/my_service2/beauty_deta.js b/packageA/pages/my_service2/beauty_deta.js index c89bb33..cd18067 100644 --- a/packageA/pages/my_service2/beauty_deta.js +++ b/packageA/pages/my_service2/beauty_deta.js @@ -170,14 +170,10 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning(res.data.data, 1, th); setTimeout(function() { @@ -189,7 +185,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } else { var pages = getCurrentPages(); //当前页面 @@ -374,20 +370,16 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("更改成功", 0, th); } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, //预览头像 diff --git a/packageA/pages/my_service2/tment_details.js b/packageA/pages/my_service2/tment_details.js index 7434cca..006aa4d 100644 --- a/packageA/pages/my_service2/tment_details.js +++ b/packageA/pages/my_service2/tment_details.js @@ -41,14 +41,9 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { my_confirm.open_cancel(0); if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); @@ -59,7 +54,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } ); diff --git a/packageA/pages/my_service2/tment_eval.js b/packageA/pages/my_service2/tment_eval.js index f51b9bf..71cd7f9 100644 --- a/packageA/pages/my_service2/tment_eval.js +++ b/packageA/pages/my_service2/tment_eval.js @@ -178,14 +178,10 @@ Page({ "storeId": a.stoid, }; var data = JSON.stringify(json); //转换成json格式 - wx.request({ - url: url, - data: data, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.data.code == 0) { getApp().my_warnning("评价成功", 1, th); @@ -198,7 +194,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, diff --git a/packageA/pages/my_service2/tment_order_list.js b/packageA/pages/my_service2/tment_order_list.js index 7e0b0a7..daf0b26 100644 --- a/packageA/pages/my_service2/tment_order_list.js +++ b/packageA/pages/my_service2/tment_order_list.js @@ -154,14 +154,10 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); var id = th.data.activeCategoryId; @@ -180,7 +176,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }) diff --git a/packageA/pages/profile/profile.js b/packageA/pages/profile/profile.js index 1033966..0834948 100644 --- a/packageA/pages/profile/profile.js +++ b/packageA/pages/profile/profile.js @@ -1066,7 +1066,7 @@ Page({ return false; } else { - return ut.m_toast("授权登入失败!" + e.data.msg); + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; wx.setStorageSync("userinfo", e.data.data); diff --git a/packageA/pages/serviceCard_pd/cart/cart.js b/packageA/pages/serviceCard_pd/cart/cart.js index 0257efc..70b2f3c 100644 --- a/packageA/pages/serviceCard_pd/cart/cart.js +++ b/packageA/pages/serviceCard_pd/cart/cart.js @@ -426,20 +426,17 @@ Page({ item.list.push(goods); pdata=item; if (pdata.length == 0) return false; - var str = JSON.stringify(pdata); - console.log(str,"----"); + //var str = JSON.stringify(pdata); + //console.log(str,"----"); wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/recharge/saveRecharge', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePost("/api/weshop/recharge/saveRecharge", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { + wx.hideLoading(); if (res.statusCode == 200) { @@ -492,13 +489,10 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function() { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function() {} + + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); }) }, diff --git a/packageA/pages/serviceCard_pd/cart_wk/cart_wk.js b/packageA/pages/serviceCard_pd/cart_wk/cart_wk.js index a32bccf..2744fb3 100644 --- a/packageA/pages/serviceCard_pd/cart_wk/cart_wk.js +++ b/packageA/pages/serviceCard_pd/cart_wk/cart_wk.js @@ -627,16 +627,11 @@ Page({ var arr = []; arr.push(dd); - console.log(JSON.stringify(arr)); + //console.log(JSON.stringify(arr)); - wx.request({ - url: oo.url + '/api/weshop/order/pay/payTuanWkCard', - data: JSON.stringify(arr), - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (t) { + getApp().request.promisePost("/api/weshop/order/pay/payTuanWkCard", { + data: arr,is_json:1,is_normal:1 + }).then(t => { //---用微信支付--- if (dd.tail_pay_type == 0) { @@ -678,8 +673,12 @@ Page({ getApp().my_warnning(t.data.msg, 1, th); } } - } - }); + + }).catch(function(err) { + th.data.paying=0; + wx.hideLoading(); + }) + }, //检查区域是不是包邮 diff --git a/packageB/pages/evaluate/evaluate.js b/packageB/pages/evaluate/evaluate.js index 3e6cef4..69c75b9 100644 --- a/packageB/pages/evaluate/evaluate.js +++ b/packageB/pages/evaluate/evaluate.js @@ -199,6 +199,11 @@ Page({ getApp().my_warnning("给点建议呗", 0, th); return false; } + + if(this.data.lding) return false; + this.data.lding=1; + + wx.showLoading({ title: '加载中', }) @@ -222,15 +227,12 @@ Page({ "star": stars + 1, "storeId": a.stoid }; - var data = JSON.stringify(json); //转换成json格式 - wx.request({ - url: url, - data: data, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + //var data = JSON.stringify(json); //转换成json格式 + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.data.code == 0) { getApp().my_warnning("评价成功", 1, th); @@ -247,9 +249,13 @@ Page({ }); }, 2000); } else { + th.data.lding=0; getApp().my_warnning(res.data.msg, 0, th); } - } + + }).catch(function(err) { + th.data.lding=0; + wx.hideLoading(); }) }, diff --git a/packageC/pages/luckyGo/luckyGo_cart/luckyGo_cart.js b/packageC/pages/luckyGo/luckyGo_cart/luckyGo_cart.js index 6a2761a..202cb85 100644 --- a/packageC/pages/luckyGo/luckyGo_cart/luckyGo_cart.js +++ b/packageC/pages/luckyGo/luckyGo_cart/luckyGo_cart.js @@ -2836,15 +2836,10 @@ Page({ var str = JSON.stringify(pdata); wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -2951,14 +2946,11 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { - } + + }).catch(function(err) { + th.data.is_summit_ing = 0; + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); }) }, diff --git a/packageC/pages/luckyGo/luckyGo_cart_ct/luckyGo_cart_ct.js b/packageC/pages/luckyGo/luckyGo_cart_ct/luckyGo_cart_ct.js index 7a3dd58..0577b28 100644 --- a/packageC/pages/luckyGo/luckyGo_cart_ct/luckyGo_cart_ct.js +++ b/packageC/pages/luckyGo/luckyGo_cart_ct/luckyGo_cart_ct.js @@ -1620,21 +1620,18 @@ Page({ }) // pdata.keyid = th.data.bn_goods.keyid } - var str = JSON.stringify(pdata); - console.log("支付数据"); - console.log(str); + + //var str = JSON.stringify(pdata); + //console.log("支付数据"); + //console.log(str); //return false; wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function (res) { + + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -1779,13 +1776,11 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { } + + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); }) }, diff --git a/packageC/pages/payForAnother/payForAnother.js b/packageC/pages/payForAnother/payForAnother.js index fc2cd17..f069cdb 100644 --- a/packageC/pages/payForAnother/payForAnother.js +++ b/packageC/pages/payForAnother/payForAnother.js @@ -2512,15 +2512,10 @@ Page({ var str = JSON.stringify(pdata); wx.showLoading({title: "加载中"}); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -2627,16 +2622,14 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { - } + + }).catch(function(err) { + th.data.is_summit_ing = 0; + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); }) + }, //---确认线下门店的数量足不足--- async check_store_num(goods_id, pick, goods_num, func){ diff --git a/packageC/pages/presell/cart/cart.js b/packageC/pages/presell/cart/cart.js index b7a27b6..c8c4a0b 100644 --- a/packageC/pages/presell/cart/cart.js +++ b/packageC/pages/presell/cart/cart.js @@ -3183,14 +3183,11 @@ Page({ dd.scene = getApp().globalData.scene; console.log(JSON.stringify(dd)); - wx.request({ - url: wk_url, - data: JSON.stringify(dd), - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (t) { + + getApp().request.promisePost(wk_url, { + data: dd,is_json:1,is_normal:1 + }).then(t => { + th.close_show_pay(); //---用微信支付--- @@ -3258,8 +3255,11 @@ Page({ } th.data.paying = 0; } - } - }); + }).catch(function(err) { + th.data.paying = 0; + wx.hideLoading(); + th.updateOrderCoupon() + }) }, //------调起支付框-------- diff --git a/packageC/pages/presell/cart/cart2.js b/packageC/pages/presell/cart/cart2.js index 1d998be..d013806 100644 --- a/packageC/pages/presell/cart/cart2.js +++ b/packageC/pages/presell/cart/cart2.js @@ -1381,21 +1381,17 @@ Page({ item.list.push(goods); pdata = item; - var str = JSON.stringify(pdata); - console.log("支付数据"); - console.log(str); + //var str = JSON.stringify(pdata); + //console.log("支付数据"); + //console.log(str); //return false; wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/recharge/saveRecharge', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function (res) { + + getApp().request.promisePost("/api/weshop/recharge/saveRecharge", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -1462,13 +1458,10 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { } + + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); }) }, @@ -2030,15 +2023,9 @@ Page({ var str = JSON.stringify(pdata); wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { - + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -2147,14 +2134,10 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { - } + + }).catch(function(err) { + th.data.is_summit_ing = 0; + wx.hideLoading(); }) }, diff --git a/packageC/pages/presell/cart/cart2_pre.js b/packageC/pages/presell/cart/cart2_pre.js index 65071be..5f68779 100644 --- a/packageC/pages/presell/cart/cart2_pre.js +++ b/packageC/pages/presell/cart/cart2_pre.js @@ -947,21 +947,17 @@ Page({ item.list.push(goods); pdata = item; - var str = JSON.stringify(pdata); - console.log("支付数据"); - console.log(str); + //var str = JSON.stringify(pdata); + //console.log("支付数据"); + //console.log(str); //return false; wx.showLoading({ title: "加载中" }); - wx.request({ - url: os.url + '/api/weshop/recharge/saveRecharge', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePost("/api/weshop/recharge/saveRecharge", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -1023,13 +1019,10 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function() { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function() {} + + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); }) }, @@ -1184,14 +1177,10 @@ Page({ var str = JSON.stringify(pdata); wx.showLoading({ title: "加载中" }); - wx.request({ - url: os.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -1267,13 +1256,9 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { } + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); }) }, //订阅消息提醒 diff --git a/packageD/components/diy_login/login.js b/packageD/components/diy_login/login.js index beee326..4bc3b96 100644 --- a/packageD/components/diy_login/login.js +++ b/packageD/components/diy_login/login.js @@ -379,7 +379,7 @@ Component({ return false; } else { - return app.showWarning("授权登入失败!" + e.data.msg); + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; wx.setStorageSync("userinfo", e.data.data); diff --git a/packageD/pages/AI-test-skin/analyse/analyse.js b/packageD/pages/AI-test-skin/analyse/analyse.js index fd10228..a065b24 100644 --- a/packageD/pages/AI-test-skin/analyse/analyse.js +++ b/packageD/pages/AI-test-skin/analyse/analyse.js @@ -674,17 +674,44 @@ Page({ json_post: function (url, data, succ, fail, mathod) { var Mathod = "POST"; if (mathod) Mathod = mathod; + + var url1=url; + var arr_in_url=ut.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - var str = JSON.stringify(data); - wx.request({ - url: url, - data: str, - method: Mathod, - header: { + + getApp().request.ck_api_token((api_tk)=> { + + var header={ 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { succ(res); }, - fail: function (res) { fail(res); } + };// 设置请求的 header + + var dd= ut.deep_cp(data); + dd={...arr_in_url,...dd}; + + var now=ut.gettimestamp(); + var tk=getApp().request.set_req_sign(dd,url1,now,api_tk,1); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + + + var str = JSON.stringify(data); + wx.request({ + url: url, + data: str, + method: Mathod, + header:header,// 设置请求的 header + success: function (res) { + succ(res); + }, + fail: function (res) { + fail(res); + } + }) }) }, + }) \ No newline at end of file diff --git a/packageD/pages/AI-test-skin/index/aiskin.js b/packageD/pages/AI-test-skin/index/aiskin.js index 54ebde4..c72e1c9 100644 --- a/packageD/pages/AI-test-skin/index/aiskin.js +++ b/packageD/pages/AI-test-skin/index/aiskin.js @@ -198,19 +198,46 @@ Page({ json_post: function (url, data, succ, fail, mathod) { var Mathod = "POST"; if (mathod) Mathod = mathod; + + var url1=url; + var arr_in_url=ut.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - var str = JSON.stringify(data); - wx.request({ - url: url, - data: str, - method: Mathod, - header: { + + getApp().request.ck_api_token((api_tk)=> { + + var header={ 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { succ(res); }, - fail: function (res) { fail(res); } + };// 设置请求的 header + + var dd= ut.deep_cp(data); + dd={...arr_in_url,...dd}; + + var now=ut.gettimestamp(); + var tk=getApp().request.set_req_sign(dd,url1,now,api_tk,1); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + + + var str = JSON.stringify(data); + wx.request({ + url: url, + data: str, + method: Mathod, + header:header,// 设置请求的 header + success: function (res) { + succ(res); + }, + fail: function (res) { + fail(res); + } + }) }) }, + }) \ No newline at end of file diff --git a/packageD/pages/AI-test-skin/select_photo/select_photo.js b/packageD/pages/AI-test-skin/select_photo/select_photo.js index ab9dc5e..a8ed379 100644 --- a/packageD/pages/AI-test-skin/select_photo/select_photo.js +++ b/packageD/pages/AI-test-skin/select_photo/select_photo.js @@ -264,17 +264,44 @@ Page({ json_post: function (url, data, succ, fail, mathod) { var Mathod = "POST"; if (mathod) Mathod = mathod; + + var url1=url; + var arr_in_url=ut.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - var str = JSON.stringify(data); - wx.request({ - url: url, - data: str, - method: Mathod, - header: { + + getApp().request.ck_api_token((api_tk)=> { + + var header={ 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { succ(res); }, - fail: function (res) { fail(res); } + };// 设置请求的 header + + var dd= ut.deep_cp(data); + dd={...arr_in_url,...dd}; + + var now=ut.gettimestamp(); + var tk=getApp().request.set_req_sign(dd,url1,now,api_tk,1); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + + + var str = JSON.stringify(data); + wx.request({ + url: url, + data: str, + method: Mathod, + header:header,// 设置请求的 header + success: function (res) { + succ(res); + }, + fail: function (res) { + fail(res); + } + }) }) }, + }) \ No newline at end of file diff --git a/packageD/pages/AI-test-skin/shoot_notice/shoot_notice.js b/packageD/pages/AI-test-skin/shoot_notice/shoot_notice.js index a42b0b6..fc2b9a0 100644 --- a/packageD/pages/AI-test-skin/shoot_notice/shoot_notice.js +++ b/packageD/pages/AI-test-skin/shoot_notice/shoot_notice.js @@ -291,17 +291,44 @@ Page({ json_post: function (url, data, succ, fail, mathod) { var Mathod = "POST"; if (mathod) Mathod = mathod; + + var url1=url; + var arr_in_url=ut.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - var str = JSON.stringify(data); - wx.request({ - url: url, - data: str, - method: Mathod, - header: { + + getApp().request.ck_api_token((api_tk)=> { + + var header={ 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { succ(res); }, - fail: function (res) { fail(res); } + };// 设置请求的 header + + var dd= ut.deep_cp(data); + dd={...arr_in_url,...dd}; + + var now=ut.gettimestamp(); + var tk=getApp().request.set_req_sign(dd,url1,now,api_tk,1); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + + + var str = JSON.stringify(data); + wx.request({ + url: url, + data: str, + method: Mathod, + header:header,// 设置请求的 header + success: function (res) { + succ(res); + }, + fail: function (res) { + fail(res); + } + }) }) }, + }) \ No newline at end of file diff --git a/packageD/pages/user/member/bring/bring.js b/packageD/pages/user/member/bring/bring.js index e63b67f..77c94f6 100644 --- a/packageD/pages/user/member/bring/bring.js +++ b/packageD/pages/user/member/bring/bring.js @@ -213,16 +213,11 @@ Page({ delete user_infor.type; user_infor.source_type=1; - var str = JSON.stringify(user_infor); + //var str = JSON.stringify(user_infor); // wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/users/saveWithdrawals', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + getApp().request.promisePost("/api/weshop/users/saveWithdrawals", { + data: user_infor,is_json:1,is_normal:1 + }).then(res => { th.data.tx_ing=0; if (res.data.code != -1) { @@ -232,12 +227,10 @@ Page({ } else { getApp().showWarning("提现金额不足"); } - }, - fail: function() { - getApp().showWarning("出现错误"); - }, - + }).catch(function(err) { + getApp().showWarning("网络繁忙,请稍后重试"); + th.data.tx_ing=0; }) }, diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 3291d9b..4555068 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -6005,14 +6005,10 @@ Page({ wx.showLoading({ title: "加载中" }); th.setData({ submit: 1, }) - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -6178,17 +6174,17 @@ Page({ submit: 0, }) } - }, - fail: function () { - th.data.is_summit_ing = 0; - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - th.setData({ - submit: 0, - }) - } + + }).catch(function(err) { + th.data.is_summit_ing = 0; + wx.hideLoading(); + console.log("index.js wx.request CheckCallUser fail"); + th.setData({ + submit: 0, + }) }) + }, //看一下有没有选择搭配的商品 has_collocation(goods, prom_id) { diff --git a/packageE/pages/cart/cart2_inte/cart2_inte.js b/packageE/pages/cart/cart2_inte/cart2_inte.js index 5178ac6..36a70fd 100644 --- a/packageE/pages/cart/cart2_inte/cart2_inte.js +++ b/packageE/pages/cart/cart2_inte/cart2_inte.js @@ -1478,14 +1478,11 @@ Page({ var str = JSON.stringify(pdata); wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + + + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { var data = res.data; @@ -1587,14 +1584,11 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.setData({submit:0}) - th.data.is_summit_ing = 0; - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { } + + }).catch(function(err) { + th.setData({ submit: 0 }) + th.data.is_summit_ing = 0; + wx.hideLoading(); }) }, diff --git a/packageE/pages/cart/cart2_pt/cart2_pt.js b/packageE/pages/cart/cart2_pt/cart2_pt.js index 9bc99d5..d2dc440 100644 --- a/packageE/pages/cart/cart2_pt/cart2_pt.js +++ b/packageE/pages/cart/cart2_pt/cart2_pt.js @@ -1664,14 +1664,11 @@ Page({ console.log(str); //return false; wx.showLoading({ title: "加载中" }); - wx.request({ - url: oo.url + '/api/weshop/order/createWxdOrder', - data: str, - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { + + + getApp().request.promisePost("/api/weshop/order/createWxdOrder", { + data: pdata,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.statusCode == 200) { @@ -1767,14 +1764,10 @@ Page({ th.data.is_summit_ing = 0; //是否提交中 console.log("index.js wx.request CheckCallUser statusCode" + res.statusCode); } - }, - fail: function () { - th.data.is_summit_ing = 0; //是否提交中 - wx.hideLoading(); - console.log("index.js wx.request CheckCallUser fail"); - }, - complete: function () { - } + + }).catch(function(err) { + th.data.is_summit_ing = 0; //是否提交中 + wx.hideLoading(); }) }, useCoupon: function () { diff --git a/packageE/pages/cart/cart_wk/cart_wk.js b/packageE/pages/cart/cart_wk/cart_wk.js index 8270739..f21e805 100644 --- a/packageE/pages/cart/cart_wk/cart_wk.js +++ b/packageE/pages/cart/cart_wk/cart_wk.js @@ -783,15 +783,11 @@ Page({ var arr = []; arr.push(dd); - console.log(JSON.stringify(arr)); - wx.request({ - url: oo.url + '/api/weshop/order/pay/payTuanWk', - data: JSON.stringify(arr), - method: 'POST', - header: { - 'content-type': 'application/json' - },// 设置请求的 header - success: function (t) { + //console.log(JSON.stringify(arr)); + + getApp().request.promisePost("/api/weshop/order/pay/payTuanWk", { + data: arr,is_json:1,is_normal:1 + }).then(t => { //---用微信支付--- if (dd.tail_pay_type == 0) { @@ -840,13 +836,13 @@ Page({ }) }, 1000) } else { - th.data.paying=0; getApp().my_warnning(t.data.msg, 1, th); } } - } - }); + }).catch(function(err) { + th.data.paying=0; + }) }, //检查区域是不是包邮 diff --git a/packageE/pages/giftpack/giftpacklistshop/giftpacklistshop.wxml b/packageE/pages/giftpack/giftpacklistshop/giftpacklistshop.wxml index bff8d9d..da36db1 100644 --- a/packageE/pages/giftpack/giftpacklistshop/giftpacklistshop.wxml +++ b/packageE/pages/giftpack/giftpacklistshop/giftpacklistshop.wxml @@ -222,7 +222,7 @@ - + diff --git a/packageE/pages/qy/contactMe/contactMe.js b/packageE/pages/qy/contactMe/contactMe.js index e73bc7a..6b583d9 100644 --- a/packageE/pages/qy/contactMe/contactMe.js +++ b/packageE/pages/qy/contactMe/contactMe.js @@ -615,8 +615,21 @@ Page({ success: function (e) { if (e.data.code == 0) { app.globalData.user_id = e.data.data.user_id; - } else { - return app.showWarning("授权登入失败!" + e.data.msg); + } + else if(e.data.code==-3){ + wx.showModal({ + title: e.data.msg, + success: function (e) { + if(e.confirm){ + dd.isreplacemobile=1; + th.zu_ce(dd); + } + } + }); + return false; + } + else { + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; wx.setStorageSync("userinfo", e.data.data); diff --git a/packageE/pages/togoin/togoin.js b/packageE/pages/togoin/togoin.js index 40268af..c05c817 100644 --- a/packageE/pages/togoin/togoin.js +++ b/packageE/pages/togoin/togoin.js @@ -448,6 +448,7 @@ Page({ wx.hideLoading(); th.setData({ sub: 0 }); + if (e.data.code == 0) { app.globalData.user_id = e.data.data.user_id; @@ -466,7 +467,7 @@ Page({ return false; } else { - return app.showWarning("授权登入失败!" + e.data.msg); + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; wx.setStorageSync("userinfo", e.data.data); diff --git a/packageE/pages/user/labels/labels.js b/packageE/pages/user/labels/labels.js index af1028d..15c2375 100644 --- a/packageE/pages/user/labels/labels.js +++ b/packageE/pages/user/labels/labels.js @@ -256,6 +256,9 @@ Page({ data: getApp().globalData.zc_dd, success: function (e) { wx.hideLoading(); + + e.data.code=-5; + if (e.data.code == 0) { app.globalData.user_id = e.data.data.user_id; } @@ -276,7 +279,7 @@ Page({ else { th.setData({loading: 0,is_check:0}); - return app.showWarning("授权登入失败!" + e.data.msg); + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; @@ -464,6 +467,8 @@ Page({ wx.hideLoading(); th.setData({loading: 0,is_check:0}); + e.data.code=-5; + if (e.data.code == 0) { app.globalData.user_id = e.data.data.user_id; } @@ -484,7 +489,7 @@ Page({ } else { - return app.showWarning("授权登入失败!" + e.data.msg); + return app.my_warnning("授权登入失败!" + e.data.msg,0,th); } getApp().globalData.login_back = 1; wx.setStorageSync("userinfo", e.data.data); diff --git a/packageF/pages/giftpack/evaluategift/evaluategift.js b/packageF/pages/giftpack/evaluategift/evaluategift.js index dc668fd..a283b84 100644 --- a/packageF/pages/giftpack/evaluategift/evaluategift.js +++ b/packageF/pages/giftpack/evaluategift/evaluategift.js @@ -43,19 +43,29 @@ Page({ title: '加载中', }) var url = "/api/weshop/marketing/giftbag/bound/get"; + + var data={ + "actId": th.data.getActId, //活动Id + "actType": 2, //活动类型 1:新人礼、2:评价有礼、3:节日营销、4:生日营销 + "storeId": a.stoid, //商家Id + "userId": d.user_id, //用户ID + "orderNumber": th.data.orderNumber, + "orderType": th.data.orderType, + "isdg": th.data.isdg + }; + + if(th.data.orderGoodsId){ + data["orderGoodsId"]=th.data.orderGoodsId; + } + + if(th.data.giftBagId){ + data["gifbagid"]= th.data.giftBagId; + } + + getApp().request.promiseGet(url, { isShowLoading: true, - data: { - "actId": th.data.getActId, //活动Id - "actType": 2, //活动类型 1:新人礼、2:评价有礼、3:节日营销、4:生日营销 - "storeId": a.stoid, //商家Id - "userId": d.user_id, //用户ID - "orderNumber": th.data.orderNumber, - "orderType": th.data.orderType, - "orderGoodsId": th.data.orderGoodsId, - "gifbagid": th.data.giftBagId, - "isdg": th.data.isdg - } + data:data }).then(res => { if (res.data.code == 0) { if (res.data.data.lbCoupons.length > 0 && res.data.data.lbCoupons != null) { @@ -190,10 +200,18 @@ Page({ "userId": d.user_id, //用户ID "orderNumber": th.data.orderNumber, "orderType": th.data.orderType, - "orderGoodsId": th.data.orderGoodsId, - "giftBagId": th.data.giftBagId, "buyFrom": 2 }; + + if(th.data.orderGoodsId){ + json.orderGoodsId=th.data.orderGoodsId; + } + + if(th.data.giftBagId){ + json.giftBagId=th.data.giftBagId + } + + if (th.data.isdg) { json.isdg=th.data.isdg } diff --git a/packageF/pages/user/return_goods_info/return_goods_info.js b/packageF/pages/user/return_goods_info/return_goods_info.js index 8a75923..b9aac96 100644 --- a/packageF/pages/user/return_goods_info/return_goods_info.js +++ b/packageF/pages/user/return_goods_info/return_goods_info.js @@ -176,5 +176,19 @@ Page({ current: r[e.currentTarget.dataset.idx], urls: r }); - } + }, + + + //---图片失败,默认图片--- + bind_bnerr2: function (e) { + var _errImg = e.target.dataset.errorimg; + var _errurl = e.target.dataset.url; + var ii = _errurl.indexOf(os.imghost); + if (ii != -1) { + var _errObj = {}; + _errObj[_errImg] = "/miniapp/images/default_g_img.gif"; + this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; + } + }, + }); \ No newline at end of file diff --git a/packageF/pages/user/return_goods_info/return_goods_info.wxml b/packageF/pages/user/return_goods_info/return_goods_info.wxml index 11657a4..8efd59c 100644 --- a/packageF/pages/user/return_goods_info/return_goods_info.wxml +++ b/packageF/pages/user/return_goods_info/return_goods_info.wxml @@ -7,9 +7,15 @@ + - + + {{item.goods_name}} 退款金额 : ¥{{return_goods.back_money}} diff --git a/packageG/pages/user/express/exp_filter.wxs b/packageG/pages/user/express/exp_filter.wxs new file mode 100644 index 0000000..906db3a --- /dev/null +++ b/packageG/pages/user/express/exp_filter.wxs @@ -0,0 +1,16 @@ +module.exports = { + + state_format:function (express){ + if(!express) return '无轨迹'; + if(express.State==-1) return '无轨迹'; + if(express.State==0) return '已揽件'; + if(express.State==1) return '在途中'; + if(express.State==2) return '正在派件'; + if(express.State==3) return '已签收'; + if(express.State==4) return '派送失败'; + if(express.State==5) return '疑难件'; + if(express.State==6) return '退件签收'; + return '其他'; + } + +} \ No newline at end of file diff --git a/packageG/pages/user/express/express.js b/packageG/pages/user/express/express.js index a3571af..a10ea45 100644 --- a/packageG/pages/user/express/express.js +++ b/packageG/pages/user/express/express.js @@ -1,4 +1,5 @@ var e = getApp(), s = e.request,oo=e.globalData,os=oo.setting; +var ut = require("../../../../utils/util.js"); Page({ data: { @@ -7,35 +8,227 @@ Page({ delivery: null, express: null, re_arr:null,//反转后的数组 - error: "快递信息异常" + error: "快递信息异常", + active:0, + has_connaect:1, + is_get:0 }, onLoad: function(e) { - this.requestDelivery(e.order_id); + + var th=this; + //----获取系统参数----- + getApp().getConfig2(function (ee) { + var is_connaect=1; + + if(ee.switch_list){ + var json_d = JSON.parse(ee.switch_list); + if(json_d.weapp_customertype==0){ + is_connaect=0; + } + th.setData({ + store_config: ee, + sys_switch: json_d, + has_connaect:is_connaect + }) + + }else{ + th.setData({ + has_connaect:0 + }) + } + + th.requestDelivery(e.order_id); + }) + + + }, requestDelivery: function(e) { var r = this; s.get("/api/order/deliverydoc/page", { - data: { order_id: e,store_id:os.stoid }, + data: { order_id: e,store_id:os.stoid,pageSize:100}, success: function(e) { - r.setData({ - delivery: e.data.data.pageData[0], - }), r.requestExpress(); + + if(ut.ajax_ok(e)){ + var list=e.data.data.pageData; + + for (let i = 0; i < list.length; i++) { + list[i].all_gd_num=0; + var json=list[i].erp_ck_warelist; + if(json){ + json=JSON.parse(json); + for (let j = 0; j < json.length; j++) { + list[i].all_gd_num+=json[j].qty; + } + } + + list[i].erp_sender_city=r.sheng_lue(list[i].erp_sender_city,4); + list[i].erp_receiver_city=r.sheng_lue(list[i].erp_receiver_city,4); + } + + + + r.setData({ + delivery: list[0], + delivery_arr:list + }), r.requestExpress(); + } + + + } }); }, requestExpress: function() { var s = this; - wx.request({ - url: this.data.url + "/api/weshop/order/wuliu/" + this.data.delivery.shipping_code + "/" + this.data.delivery.invoice_no + "/" + this.data.delivery.mobile, success: function(e) { - - var re_arr = e.data.data.Traces.reverse(); + var url="/api/weshop/order/wuliu/" + this.data.delivery.shipping_code + "/" + this.data.delivery.invoice_no + "/" + this.data.delivery.mobile; + getApp().request.promiseGet(url, {}).then(e => { + wx.hideLoading(); + s.setData({is_get:1}) + + if(e.data.code==0 && e.data.data){ + var re_arr = e.data.data.Traces.reverse(); s.setData({ - express: e.data.data, re_arr: re_arr, + express: e.data.data, re_arr: re_arr, }); - }, - fail: function(s) { - e.showWarning("请求失败"); } + + }).catch(function(err) { + wx.hideLoading(); + e.showWarning("请求失败"); + }) + + }, + + + click_bao_btn(e){ + var index= parseInt(e.currentTarget.dataset.idx); + var item=this.data.delivery_arr[index]; + this.setData({ + delivery: item, + active:index, + express:null, + re_arr:[], + is_get:0 + }); + wx.showLoading(); + this.requestExpress(); + }, + + //打开客服操作菜单 + openCS() { + let self=this; + // 判断会员状态 + let user_info = getApp().globalData.userInfo; + if (user_info == null || user_info.mobile == undefined || user_info.mobile == '' || user_info.mobile == null) { + wx.navigateTo({ + url: '/packageE/pages/togoin/togoin', + }) + return false; + }; + // csType/在线客服设置: + // 0关闭(如果有设置热线电话,则显示拨打热线电话)、 + // 1小程序客服、 + // 2企业微信客服 + if (this.data.sys_switch) { + let csType = this.data.sys_switch.weapp_customertype; + if (csType == 0) { + // 拨打电话号码 + this.contactService(); + } else { + this.getTel() + .then(() => { + self.setData({ + hiddenCS: false, + }); + }); + }; + }; + + }, + + //关闭客服操作菜单 + closeCS() { + this.setData({ + hiddenCS: true, }); + }, + + // 获取客服电话 + getTel() { + var self=this; + return new Promise((resolve, reject) => { + getApp().getConfig(function (t) { + if (t.store_tel == undefined) { + getApp().request.get("/api/weshop/store/get/" + os.stoid, { + isShowLoading: 1, + data: {}, + success: function (rs) { + getApp().globalData.config = rs.data.data; + if (rs.data.data.store_tel == null && rs.data.data.store_tel == undefined) { + getApp().my_warnning("商家未设置电话", 0, th); + return false; + } + self.setData({ + store_tel: rs.data.data.store_tel, + }); + // s.confirmBox("请联系客服:" + rs.data.data.store_tel); + } + }) + } else { + self.setData({ + store_tel: t.store_tel, + }); + // s.confirmBox("请联系客服:" + t.store_tel); + }; + resolve(); + }); + }); + }, + + + customer_chat: function () { + getApp().customer_chat(""); + }, + + //---------联系客服------------ + contactService: function () { + getApp().com_call(this); + }, + + //---------联系微信客服------------ + con_weixin: function () { + var url = this.data.sys_switch.weapp_customertype_url; + var id = this.data.sys_switch.weapp_customertype_appid; + wx.openCustomerServiceChat({ + extInfo: { url: url }, + corpId: id, + success(res) { } + }) + }, + + // 内容复制到剪贴板 + copy() { + // console.log('点击了复制按钮'); + wx.setClipboardData({ + data: this.data.delivery.invoice_no, + success(res) { + wx.getClipboardData({ + success(res) { + console.log(res.data); + } + }) + } + }) + }, + + sheng_lue(txt,maxLength){ + if(!txt) return ''; + if (txt.length > maxLength) { + txt = txt.substr(0, maxLength) + '...'; + } + return txt } + + }); \ No newline at end of file diff --git a/packageG/pages/user/express/express.json b/packageG/pages/user/express/express.json index 251518d..4724a58 100644 --- a/packageG/pages/user/express/express.json +++ b/packageG/pages/user/express/express.json @@ -1,3 +1,6 @@ { - "navigationBarTitleText": "查看物流信息" + "navigationBarTitleText": "查看物流信息", + "usingComponents": { + "nodata": "/components/nodata/nodata" + } } \ No newline at end of file diff --git a/packageG/pages/user/express/express.wxml b/packageG/pages/user/express/express.wxml index de1d85e..5b8a273 100644 --- a/packageG/pages/user/express/express.wxml +++ b/packageG/pages/user/express/express.wxml @@ -1,3 +1,109 @@ + + + + + + + {{delivery.shipping_name}}:{{delivery.invoice_no}} + + + + + + + + {{util.state_format(express)}} + + + + + + + + + + + + + + {{util.state_format(express)}} + + + + {{delivery.erp_sender_city || '无'}} + + {{delivery.erp_receiver_city || '无'}} + + + + + + + + + + + + + + 拨打电话 + + + + + + + + + + + + + + + 联系客服 + + + + + + + 联系客服 + + + + + + + + + + + + - - - {{item.AcceptStation}} - {{item.AcceptTime}} +--> + + + + + + + + 包裹{{index+1}}(数量{{item.all_gd_num}}) + + + 物流详情 + + + + {{item.AcceptStation}} + {{item.AcceptTime}} + + + + + + + + + + + + + + + - - {{express.Reason}} - + diff --git a/packageG/pages/user/express/express.wxss b/packageG/pages/user/express/express.wxss index 112d0a9..fd9a664 100644 --- a/packageG/pages/user/express/express.wxss +++ b/packageG/pages/user/express/express.wxss @@ -1,3 +1,7 @@ +page{ + background-color: #f1f1f1; color:#313131; +} + .logistics-mes { padding: 20rpx 30rpx; background-color: #fff; @@ -12,6 +16,7 @@ .logistics-title { color: #777; margin-right: 20rpx; + position: relative;top: 2rpx; } .logistics-cont { @@ -19,14 +24,12 @@ } .apply-state { - margin-top: 20rpx; + margin: 20rpx 17rpx 0; background-color: #fff; - padding-left: 50rpx; - padding-top: 60rpx; + border-radius: 17rpx; } .state-item { - border-left: 1px solid #ccc; padding:0 40rpx; } @@ -34,31 +37,124 @@ position: relative; margin-bottom: 20rpx; padding-bottom: 20rpx; - border-bottom: 1px solid #eee; + /* border-bottom: 1px solid #eee; */ font-size: 24rpx; color: #aaa; line-height: 1; } +.item-wrap .line{ + height: 100%;width: 1rpx; background-color: #bfbfbf; + position: absolute;top: 22rpx; left: -40rpx; +} + .item-wrap::before { content: ''; position: absolute; - left: -61rpx; + left: -52rpx; top: 0; - width: 26rpx; - height: 26rpx; + width: 22rpx; + height: 22rpx; border-radius: 50%; - background-color: #e23435; - border: 4px solid #ed8182; + background-color: #fff; + border: 1px solid #bfbfbf; + z-index: 100; } -.state-title { - font-size: 28rpx; - font-weight: bold; - color: #666; +.item-wrap.fir::before{ + background-color: #e23435; + border: 5px solid #fdcfcd; + left: -61rpx; +} +.item-wrap .state-title { + font-size: 27rpx; + color: #898989; padding-bottom: 20rpx; line-height: 40rpx } + +.item-wrap.fir .state-title { + color: #313131; +} +.item-wrap.fir .state-time{ + color: #fe0002; +} + .no_msg{ text-align: center;color: #999; font-size: 32rpx -} \ No newline at end of file +} + +.deli_btn_box{ + overflow-x:auto ; overflow-y:hidden ; +} +.bao_btn{ + background-color: #f1f1f1; color: #313131;padding:0 34rpx; flex-shrink: 0; border-radius: 15rpx; + font-size: 26rpx; width: auto; height: 62rpx; line-height: 62rpx; +} +.bao_btn~.bao_btn{ + margin-left: 18rpx; +} +.xq_title{ + font-size: 34rpx; font-weight: bolder;color: #313131; line-height: 34rpx;margin-top: 50rpx;padding-bottom: 37rpx; +} + +.xq_title.c_top{ + margin-top: 20rpx; +} + +.fir_top{ + height: 328rpx; + margin: 20rpx 17rpx 0;overflow: hidden; + background-color: #fff; + border-radius: 17rpx; +} + +.fir_top.small{ + height: 145rpx; +} + +.f_title{ + height: 66rpx; line-height: 66rpx; background-color: #170a02; color: #fff; font-size: 25rpx; +} +.fir_top_mid{ + height: 183rpx; border-bottom: 1rpx solid #eee; +} +.left_mid{ + width:auto; flex-shrink: 0; margin-left: 24rpx; flex:1; + color: #fe0002; font-size: 35rpx; font-weight: bolder; +} +.right_mid{ + width:440; flex-shrink: 0; +} + +.bold_color{ + color: #fe0002; font-size: 35rpx; font-weight: bolder; +} + +.right_mid_btn{ + height:109rpx; background-color: #f1f1f1; border-radius: 109rpx; + font-size: 26rpx; font-weight: bolder; color: #313131; + margin-right: 17rpx; width: 430rpx; +} + +.fir_top_third{ + height: 79rpx; color: #313131; font-size: 26rpx; +} +.fir_top_third_lin { + border-right: 1rpx solid #eee; + margin: 15rpx 11rpx; width: 2rpx; + height: 56rpx; +} +.addimg3{ + width: 27rpx; + height: 27rpx; + padding: 0 12rpx; +} +.fir_top_third_btn{ + width: 100%; height: 100%; +} + +.bao_btn.b_active{ + background-color:#fefbea;color: #fe0000; font-weight: bolder; border: 1rpx solid #fe0000; +} + diff --git a/packageG/pages/user/my_service/appment_main.js b/packageG/pages/user/my_service/appment_main.js index fcc4b48..b66f357 100644 --- a/packageG/pages/user/my_service/appment_main.js +++ b/packageG/pages/user/my_service/appment_main.js @@ -116,14 +116,10 @@ Page({ "validay": validay } var data = JSON.stringify(json); - wx.request({ - url: url, - data: json, - method: 'post', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { th.setData({ is_sub: 0 }) @@ -132,7 +128,7 @@ Page({ getApp().my_warnning("预约成功", 1, th); var store_name = th.data.store_name; //预约门店 var number = res.data.data.Number; - var temp_url = "/api/wx/open/app/user/sendSubscribeMsg"; //模版接口 + var temp_url = "/api/weshop/wx/open/app/user/sendSubscribeMsg"; //模版接口 var userinfo = getApp().globalData.userInfo; var name = d.userInfo.nickname; var json = { @@ -156,16 +152,12 @@ Page({ "userId": d.user_id }; var data = JSON.stringify(json); - //调用发送预约成功模版接口 - wx.request({ - url: th.data.inurl + temp_url, - data: data, - method: 'post', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(data) {} - }) + + getApp().request.promisePost(temp_url, { + data: json, is_json: 1, is_normal: 1 + }).then( r =>{}) + + setTimeout(function() { wx.redirectTo({ url: "/packageG/pages/user/my_service/tment_details?number=" + number @@ -175,7 +167,7 @@ Page({ getApp().my_warnning(res.data.msg, 0, th); th.settime(); } - } + }) }, diff --git a/packageG/pages/user/my_service/beauty_deta.js b/packageG/pages/user/my_service/beauty_deta.js index d49c9c3..f7345a8 100644 --- a/packageG/pages/user/my_service/beauty_deta.js +++ b/packageG/pages/user/my_service/beauty_deta.js @@ -167,14 +167,10 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function (res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning(res.data.data, 1, th); setTimeout(function () { @@ -186,7 +182,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } else { var pages = getCurrentPages(); //当前页面 @@ -373,20 +369,16 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.inurl + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function (res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("更改成功", 0, th); } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, //预览头像 diff --git a/packageG/pages/user/my_service/tment_details.js b/packageG/pages/user/my_service/tment_details.js index 1898051..d94d323 100644 --- a/packageG/pages/user/my_service/tment_details.js +++ b/packageG/pages/user/my_service/tment_details.js @@ -40,14 +40,9 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { my_confirm.open_cancel(0); if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); @@ -58,7 +53,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) } ); diff --git a/packageG/pages/user/my_service/tment_eval.js b/packageG/pages/user/my_service/tment_eval.js index a77bc7b..214855e 100644 --- a/packageG/pages/user/my_service/tment_eval.js +++ b/packageG/pages/user/my_service/tment_eval.js @@ -178,14 +178,10 @@ Page({ "storeId": a.stoid }; var data = JSON.stringify(json); //转换成json格式 - wx.request({ - url: url, - data: data, - method: 'POST', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePost(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { wx.hideLoading(); if (res.data.code == 0) { getApp().my_warnning("评价成功", 1, th); @@ -198,7 +194,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }, diff --git a/packageG/pages/user/my_service/tment_order_list.js b/packageG/pages/user/my_service/tment_order_list.js index 8ad4b7f..0ef616f 100644 --- a/packageG/pages/user/my_service/tment_order_list.js +++ b/packageG/pages/user/my_service/tment_order_list.js @@ -151,14 +151,10 @@ Page({ }; var data = JSON.stringify(json); var url = th.data.url + "/api/weshop/marketing/reservation/reservation/update"; //预约接口地址 - wx.request({ - url: url, - data: data, - method: 'put', - header: { - 'content-type': 'application/json' - }, // 设置请求的 header - success: function(res) { + + getApp().request.promisePut(url, { + data: json,is_json:1,is_normal:1 + }).then(res => { if (res.data.code == 0) { getApp().my_warnning("取消成功", 1, th); var id = th.data.activeCategoryId; @@ -177,7 +173,7 @@ Page({ } else { getApp().my_warnning(res.data.msg, 0, th); } - } + }) }) diff --git a/packageG/pages/user/order_detail/order_detail.js b/packageG/pages/user/order_detail/order_detail.js index 82722e7..ce3dc32 100644 --- a/packageG/pages/user/order_detail/order_detail.js +++ b/packageG/pages/user/order_detail/order_detail.js @@ -137,7 +137,7 @@ Page({ r.order_status_detail = "待收货";r.receive_btn=1; if (r.exp_type == 0) r.shipping_btn=1; } - if (r.order_status == 1 && r.pay_status == 1 && r.shipping_status == 2){ + if (r.order_status == 1 && r.pay_status == 1 && (r.shipping_status == 2 || r.shipping_status == 3)){ r.order_status_detail = "待收货"; r.receive_btn = 1; if (r.exp_type == 0) r.shipping_btn = 1; } diff --git a/pages/user/assistance/task_assistance.wxml b/pages/user/assistance/task_assistance.wxml index 50574ce..6fe5896 100644 --- a/pages/user/assistance/task_assistance.wxml +++ b/pages/user/assistance/task_assistance.wxml @@ -195,5 +195,5 @@ - + diff --git a/pages/user/index/index.js b/pages/user/index/index.js index 1c0be8d..a9400f7 100644 --- a/pages/user/index/index.js +++ b/pages/user/index/index.js @@ -903,7 +903,7 @@ Page({ getApp().goto("/packageE/pages/user/user_fw/user_fw?gradeId=" + th.data.gradeId + "&FormId=" + item.Id); break; case "03": - getApp().goto("/pages/user/user_spsy/user_spsy?img=" + + getApp().goto("/packageH/pages/user/user_spsy/user_spsy?img=" + url + "&gradeId=" + th.data.gradeId + "&FormId=" + item.Id); break; case "10": @@ -1146,6 +1146,13 @@ Page({ d_list[i]["weappurl"]="/packageF/pages/giftpack/mygiftpack/mygiftpack"; d_list[i]["new_weappurl"]="/packageF/pages/giftpack/mygiftpack/mygiftpack"; } + if (ite.id==26) + { + d_list[i]["weappurl"]="/pages/user/order_list/order_list?index=1"; + d_list[i]["new_weappurl"]="/pages/user/order_list/order_list?index=1"; + } + + t_map[ite.name]=ite.id+''; } this.setData({ diff --git a/pages/user/order_list/order_list.wxml b/pages/user/order_list/order_list.wxml index e238a77..4e34502 100644 --- a/pages/user/order_list/order_list.wxml +++ b/pages/user/order_list/order_list.wxml @@ -267,6 +267,8 @@ hidden="{{!(item.exp_type==0&&item.pay_status==1&&item.shipping_status==1)}}" data-url="/packageG/pages/user/express/express?order_id={{item.order_id}}">查看物流 + 订单详情 订单详情 diff --git a/utils/md5.min.js b/utils/md5.min.js new file mode 100644 index 0000000..7418ff8 --- /dev/null +++ b/utils/md5.min.js @@ -0,0 +1,10 @@ +/** + * [js-md5]{@link https://github.com/emn178/js-md5} + * + * @namespace md5 + * @version 0.7.3 + * @author Chen, Yi-Cyuan [emn178@gmail.com] + * @copyright Chen, Yi-Cyuan 2014-2017 + * @license MIT + */ +!function(){"use strict";function t(t){if(t)d[0]=d[16]=d[1]=d[2]=d[3]=d[4]=d[5]=d[6]=d[7]=d[8]=d[9]=d[10]=d[11]=d[12]=d[13]=d[14]=d[15]=0,this.blocks=d,this.buffer8=l;else if(a){var r=new ArrayBuffer(68);this.buffer8=new Uint8Array(r),this.blocks=new Uint32Array(r)}else this.blocks=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this.h0=this.h1=this.h2=this.h3=this.start=this.bytes=this.hBytes=0,this.finalized=this.hashed=!1,this.first=!0}var r="input is invalid type",e="object"==typeof window,i=e?window:{};i.JS_MD5_NO_WINDOW&&(e=!1);var s=!e&&"object"==typeof self,h=!i.JS_MD5_NO_NODE_JS&&"object"==typeof process&&process.versions&&process.versions.node;h?i=global:s&&(i=self);var f=!i.JS_MD5_NO_COMMON_JS&&"object"==typeof module&&module.exports,o="function"==typeof define&&define.amd,a=!i.JS_MD5_NO_ARRAY_BUFFER&&"undefined"!=typeof ArrayBuffer,n="0123456789abcdef".split(""),u=[128,32768,8388608,-2147483648],y=[0,8,16,24],c=["hex","array","digest","buffer","arrayBuffer","base64"],p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),d=[],l;if(a){var A=new ArrayBuffer(68);l=new Uint8Array(A),d=new Uint32Array(A)}!i.JS_MD5_NO_NODE_JS&&Array.isArray||(Array.isArray=function(t){return"[object Array]"===Object.prototype.toString.call(t)}),!a||!i.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW&&ArrayBuffer.isView||(ArrayBuffer.isView=function(t){return"object"==typeof t&&t.buffer&&t.buffer.constructor===ArrayBuffer});var b=function(r){return function(e){return new t(!0).update(e)[r]()}},v=function(){var r=b("hex");h&&(r=w(r)),r.create=function(){return new t},r.update=function(t){return r.create().update(t)};for(var e=0;e>2]|=t[f]<>6,u[h++]=128|63&s):s<55296||s>=57344?(u[h++]=224|s>>12,u[h++]=128|s>>6&63,u[h++]=128|63&s):(s=65536+((1023&s)<<10|1023&t.charCodeAt(++f)),u[h++]=240|s>>18,u[h++]=128|s>>12&63,u[h++]=128|s>>6&63,u[h++]=128|63&s);else for(h=this.start;f>2]|=s<>2]|=(192|s>>6)<>2]|=(128|63&s)<=57344?(n[h>>2]|=(224|s>>12)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<>2]|=(240|s>>18)<>2]|=(128|s>>12&63)<>2]|=(128|s>>6&63)<>2]|=(128|63&s)<=64?(this.start=h-64,this.hash(),this.hashed=!0):this.start=h}return this.bytes>4294967295&&(this.hBytes+=this.bytes/4294967296<<0,this.bytes=this.bytes%4294967296),this}},t.prototype.finalize=function(){if(!this.finalized){this.finalized=!0;var t=this.blocks,r=this.lastByteIndex;t[r>>2]|=u[3&r],r>=56&&(this.hashed||this.hash(),t[0]=t[16],t[16]=t[1]=t[2]=t[3]=t[4]=t[5]=t[6]=t[7]=t[8]=t[9]=t[10]=t[11]=t[12]=t[13]=t[14]=t[15]=0),t[14]=this.bytes<<3,t[15]=this.hBytes<<3|this.bytes>>>29,this.hash()}},t.prototype.hash=function(){var t,r,e,i,s,h,f=this.blocks;this.first?r=((r=((t=((t=f[0]-680876937)<<7|t>>>25)-271733879<<0)^(e=((e=(-271733879^(i=((i=(-1732584194^2004318071&t)+f[1]-117830708)<<12|i>>>20)+t<<0)&(-271733879^t))+f[2]-1126478375)<<17|e>>>15)+i<<0)&(i^t))+f[3]-1316259209)<<22|r>>>10)+e<<0:(t=this.h0,r=this.h1,e=this.h2,r=((r+=((t=((t+=((i=this.h3)^r&(e^i))+f[0]-680876936)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[1]-389564586)<<12|i>>>20)+t<<0)&(t^r))+f[2]+606105819)<<17|e>>>15)+i<<0)&(i^t))+f[3]-1044525330)<<22|r>>>10)+e<<0),r=((r+=((t=((t+=(i^r&(e^i))+f[4]-176418897)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[5]+1200080426)<<12|i>>>20)+t<<0)&(t^r))+f[6]-1473231341)<<17|e>>>15)+i<<0)&(i^t))+f[7]-45705983)<<22|r>>>10)+e<<0,r=((r+=((t=((t+=(i^r&(e^i))+f[8]+1770035416)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[9]-1958414417)<<12|i>>>20)+t<<0)&(t^r))+f[10]-42063)<<17|e>>>15)+i<<0)&(i^t))+f[11]-1990404162)<<22|r>>>10)+e<<0,r=((r+=((t=((t+=(i^r&(e^i))+f[12]+1804603682)<<7|t>>>25)+r<<0)^(e=((e+=(r^(i=((i+=(e^t&(r^e))+f[13]-40341101)<<12|i>>>20)+t<<0)&(t^r))+f[14]-1502002290)<<17|e>>>15)+i<<0)&(i^t))+f[15]+1236535329)<<22|r>>>10)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[1]-165796510)<<5|t>>>27)+r<<0)^r))+f[6]-1069501632)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[11]+643717713)<<14|e>>>18)+i<<0)^i))+f[0]-373897302)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[5]-701558691)<<5|t>>>27)+r<<0)^r))+f[10]+38016083)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[15]-660478335)<<14|e>>>18)+i<<0)^i))+f[4]-405537848)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[9]+568446438)<<5|t>>>27)+r<<0)^r))+f[14]-1019803690)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[3]-187363961)<<14|e>>>18)+i<<0)^i))+f[8]+1163531501)<<20|r>>>12)+e<<0,r=((r+=((i=((i+=(r^e&((t=((t+=(e^i&(r^e))+f[13]-1444681467)<<5|t>>>27)+r<<0)^r))+f[2]-51403784)<<9|i>>>23)+t<<0)^t&((e=((e+=(t^r&(i^t))+f[7]+1735328473)<<14|e>>>18)+i<<0)^i))+f[12]-1926607734)<<20|r>>>12)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[5]-378558)<<4|t>>>28)+r<<0))+f[8]-2022574463)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[11]+1839030562)<<16|e>>>16)+i<<0))+f[14]-35309556)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[1]-1530992060)<<4|t>>>28)+r<<0))+f[4]+1272893353)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[7]-155497632)<<16|e>>>16)+i<<0))+f[10]-1094730640)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[13]+681279174)<<4|t>>>28)+r<<0))+f[0]-358537222)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[3]-722521979)<<16|e>>>16)+i<<0))+f[6]+76029189)<<23|r>>>9)+e<<0,r=((r+=((h=(i=((i+=((s=r^e)^(t=((t+=(s^i)+f[9]-640364487)<<4|t>>>28)+r<<0))+f[12]-421815835)<<11|i>>>21)+t<<0)^t)^(e=((e+=(h^r)+f[15]+530742520)<<16|e>>>16)+i<<0))+f[2]-995338651)<<23|r>>>9)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[0]-198630844)<<6|t>>>26)+r<<0)|~e))+f[7]+1126891415)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[14]-1416354905)<<15|e>>>17)+i<<0)|~t))+f[5]-57434055)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[12]+1700485571)<<6|t>>>26)+r<<0)|~e))+f[3]-1894986606)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[10]-1051523)<<15|e>>>17)+i<<0)|~t))+f[1]-2054922799)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[8]+1873313359)<<6|t>>>26)+r<<0)|~e))+f[15]-30611744)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[6]-1560198380)<<15|e>>>17)+i<<0)|~t))+f[13]+1309151649)<<21|r>>>11)+e<<0,r=((r+=((i=((i+=(r^((t=((t+=(e^(r|~i))+f[4]-145523070)<<6|t>>>26)+r<<0)|~e))+f[11]-1120210379)<<10|i>>>22)+t<<0)^((e=((e+=(t^(i|~r))+f[2]+718787259)<<15|e>>>17)+i<<0)|~t))+f[9]-343485551)<<21|r>>>11)+e<<0,this.first?(this.h0=t+1732584193<<0,this.h1=r-271733879<<0,this.h2=e-1732584194<<0,this.h3=i+271733878<<0,this.first=!1):(this.h0=this.h0+t<<0,this.h1=this.h1+r<<0,this.h2=this.h2+e<<0,this.h3=this.h3+i<<0)},t.prototype.hex=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return n[t>>4&15]+n[15&t]+n[t>>12&15]+n[t>>8&15]+n[t>>20&15]+n[t>>16&15]+n[t>>28&15]+n[t>>24&15]+n[r>>4&15]+n[15&r]+n[r>>12&15]+n[r>>8&15]+n[r>>20&15]+n[r>>16&15]+n[r>>28&15]+n[r>>24&15]+n[e>>4&15]+n[15&e]+n[e>>12&15]+n[e>>8&15]+n[e>>20&15]+n[e>>16&15]+n[e>>28&15]+n[e>>24&15]+n[i>>4&15]+n[15&i]+n[i>>12&15]+n[i>>8&15]+n[i>>20&15]+n[i>>16&15]+n[i>>28&15]+n[i>>24&15]},t.prototype.toString=t.prototype.hex,t.prototype.digest=function(){this.finalize();var t=this.h0,r=this.h1,e=this.h2,i=this.h3;return[255&t,t>>8&255,t>>16&255,t>>24&255,255&r,r>>8&255,r>>16&255,r>>24&255,255&e,e>>8&255,e>>16&255,e>>24&255,255&i,i>>8&255,i>>16&255,i>>24&255]},t.prototype.array=t.prototype.digest,t.prototype.arrayBuffer=function(){this.finalize();var t=new ArrayBuffer(16),r=new Uint32Array(t);return r[0]=this.h0,r[1]=this.h1,r[2]=this.h2,r[3]=this.h3,t},t.prototype.buffer=t.prototype.arrayBuffer,t.prototype.base64=function(){for(var t,r,e,i="",s=this.array(),h=0;h<15;)t=s[h++],r=s[h++],e=s[h++],i+=p[t>>>2]+p[63&(t<<4|r>>>4)]+p[63&(r<<2|e>>>6)]+p[63&e];return t=s[h],i+=p[t>>>2]+p[t<<4&63]+"=="};var _=v();f?module.exports=_:(i.md5=_,o&&define(function(){return _}))}(); \ No newline at end of file diff --git a/utils/request.js b/utils/request.js index b4e3bbb..9e37e30 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,4 +1,7 @@ var t = require("util.js"); +var md5 = require("md5.min.js"); +var setting = require("../setting.js"); +var ut=t; module.exports = { uniqueId: "", @@ -7,35 +10,59 @@ module.exports = { // s: data // a: header request: function (e, i, o, delay = 1000) { + + var arr_in_url=t.getParams(i); this.check_timeout(i, delay, () => { var n = this, a = o.header ? o.header : { "content-type": "application/x-www-form-urlencoded" //"content-type": "application/texts" - }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; - i = this.modifyUrl(i, o), + }; + + //-- 获取一下token -- + this.ck_api_token((api_tk)=>{ + + console.log("--- api_tk ---"); + var dd= t.deep_cp(o.data); + var new_data={...arr_in_url,...dd}; + + var now=t.gettimestamp(); + var tk=this.set_req_sign(new_data,i,now,api_tk); + if(tk){ + a.reqtime=now; + a.token=tk; + a.ukey=api_tk.userkey + } + + var s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; + i = this.modifyUrl(i, o), o.isShowLoading && this.showLoading(); - var req = wx.request(Object.assign({}, o, { - url: i, - method: e, - data: s, - header: a, - success: function (t) { - o.isShowLoading && n.hideLoading(), n.doSuccess(o, t); - }, - fail(err) { - o.isShowLoading && n.hideLoading(); - if (err && err.errMsg && err.errMsg.indexOf('timeout') != -1) { - getApp().globalData.fail_url.set(t.gettimestamp(), i); - console.log('请求超时url---', getApp().globalData.fail_url); - n.doTimeOut(o, t); - } else { - n.doFail(o, t); + + var req = wx.request(Object.assign({}, o, { + url: i, + method: e, + data: s, + header: a, + success: function (t) { + o.isShowLoading && n.hideLoading(), n.doSuccess(o, t); + }, + fail(err) { + o.isShowLoading && n.hideLoading(); + if (err && err.errMsg && err.errMsg.indexOf('timeout') != -1) { + getApp().globalData.fail_url.set(t.gettimestamp(), i); + console.log('请求超时url---', getApp().globalData.fail_url); + n.doTimeOut(o, t); + } else { + n.doFail(o, t); + } } - } - })); - return req; + })); + return req; + }) + + }) }, + get: function (t, e) { console.log(t, e); return this.request("GET", t, e); @@ -153,24 +180,41 @@ module.exports = { }); }, + request2: function (e, i, o) { + var n = this, a = o.header ? o.header : { "content-type": "application/x-www-form-urlencoded" }, s = "GET" != (e = e.toUpperCase()) && o.data ? t.json2Form(o.data) : o.data; - i = this.modifyUrl2(i, o), o.isShowLoading = void 0 === o.isShowLoading || o.isShowLoading, - o.isShowLoading && this.showLoading(), console.log("app.request", i, o), wx.request(Object.assign({}, o, { - url: i, - method: e, - data: s, - header: a, - success: function (t) { - o.isShowLoading && n.hideLoading(), n.doSuccess2(o, t); - }, - fail: function (t) { - o.isShowLoading && n.hideLoading(), n.doFail(o, t); + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var dd= t.deep_cp(o.data); + var now=t.gettimestamp(); + var tk=this.set_req_sign(dd,i,now,api_tk); + if(tk){ + a.reqtime=now; + a.token=tk; + a.ukey=api_tk.userkey } - })); + + i = this.modifyUrl2(i, o), o.isShowLoading = void 0 === o.isShowLoading || o.isShowLoading, + o.isShowLoading && this.showLoading(), console.log("app.request", i, o), wx.request(Object.assign({}, o, { + url: i, + method: e, + data: s, + header: a, + success: function (t) { + o.isShowLoading && n.hideLoading(), n.doSuccess2(o, t); + }, + fail: function (t) { + o.isShowLoading && n.hideLoading(), n.doFail(o, t); + } + })); + }) }, + get2: function (t, e) { this.request2("GET", t, e); }, @@ -210,32 +254,107 @@ module.exports = { typeof func === "function" && func() }, + //---promise的使用get---- promiseGet: function (url, data, delay = 10000) { + + var th = this; + return new Promise((resolve, reject) => { this.check_timeout(url, delay, () => { - var th = this; - if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - data.isShowLoading && th.showLoading(); - wx.request({ - url, - method: 'GET', - header: { "content-type": "application/x-www-form-urlencoded" }, - data: data.data, - success(res) { - data.isShowLoading && th.hideLoading(); - resolve(res); - }, - fail(err) { - data.isShowLoading && th.hideLoading(); - if (err && err.errMsg && err.errMsg.indexOf('timeout') != -1) { - getApp().globalData.fail_url.set(t.gettimestamp(), url); - console.log('请求超时url---', getApp().globalData.fail_url); - th.doTimeOut() - }else{ - reject(err); + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; + data.isShowLoading && th.showLoading(); + + var url1=url; + var arr_in_url=t.getParams(url1); + + var header={"content-type": "application/x-www-form-urlencoded"}; + var now = t.gettimestamp(); + + var new_data={...arr_in_url,...data.data}; + var tk = this.set_req_sign(new_data, url1, now, api_tk); + + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey + } + + wx.request({ + url, + method: 'GET', + header: header, + data: data.data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { + data.isShowLoading && th.hideLoading(); + if (err && err.errMsg && err.errMsg.indexOf('timeout') != -1) { + getApp().globalData.fail_url.set(t.gettimestamp(), url); + console.log('请求超时url---', getApp().globalData.fail_url); + th.doTimeOut() + } else { + reject(err); + } } + }) + + }) + }) + }) + }, + //---promise的使用get---- + promiseGetNodef: function (url, data, delay = 10000) { + var url1=url; + var arr_in_url=t.getParams(url1); + return new Promise((resolve, reject) => { + this.check_timeout(url, delay, () => { + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var th = this; + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; + data.isShowLoading && th.showLoading(); + + var header = {"content-type": "application/x-www-form-urlencoded"}; + var now = t.gettimestamp(); + + var new_data={...arr_in_url,...data.data}; + var tk = this.set_req_sign(new_data, url1, now, api_tk); + + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey } + + wx.request({ + url, + method: 'GET', + header: header, + data: data.data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { + data.isShowLoading && th.hideLoading(); + if (err && err.errMsg && err.errMsg.indexOf('timeout') != -1) { + getApp().globalData.fail_url.set(t.gettimestamp(), url); + console.log('请求超时url---', getApp().globalData.fail_url); + th.doTimeOut() + } else { + reject(err); + } + } + }) + }) }) }) @@ -244,47 +363,153 @@ module.exports = { //---promise的使用post---- promisePost: function (url, data) { var th = this; + var url1=url; + + var arr_in_url=t.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; var post_data = data.data; - var header = { "content-type": "application/x-www-form-urlencoded" }; - if (data.is_json) { - header = { 'content-type': 'application/json' }; - post_data = JSON.stringify(post_data); - }; + return new Promise((resolve, reject) => { - data.isShowLoading && th.showLoading(); - wx.request({ - url, - method: 'POST', - header: header, - data: post_data, - success(res) { - data.isShowLoading && th.hideLoading(); - resolve(res); - }, - fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } - }) + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var header = { "content-type": "application/x-www-form-urlencoded" }; + var now = t.gettimestamp(); + + var new_data=null; + if(!Array.isArray(post_data)) { + //-- 拼接连接中带有的参数 -- + new_data = {...arr_in_url, ...post_data}; + }else{ + new_data=post_data + } + + var tk = this.set_req_sign(new_data, url1, now, api_tk); + + if (data.is_json) { + header = { 'content-type': 'application/json' }; + tk = this.set_req_sign(new_data, url1, now, api_tk,1); + post_data = JSON.stringify(post_data); + }; + + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey + } + + data.isShowLoading && th.showLoading(); + wx.request({ + url, + method: 'POST', + header: header, + data: post_data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } + }) + }) + + }) + }, + //---promise的使用post---- + promisePostNodef: function (url, data) { + var th = this; + var url1=url; + var arr_in_url=t.getParams(url1); + + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; + + return new Promise((resolve, reject) => { + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + var post_data = data.data; + var header = { "content-type": "application/x-www-form-urlencoded" }; + + var now = t.gettimestamp(); + + //-- 拼接连接中带有的参数 -- + var new_data={...arr_in_url,...post_data}; + + var tk = this.set_req_sign(new_data, url1, now, api_tk); + + if (data.is_json) { + header = { 'content-type': 'application/json' }; + tk = this.set_req_sign(new_data, url1, now, api_tk,1); + post_data = JSON.stringify(post_data); + }; + + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey + } + + data.isShowLoading && th.showLoading(); + wx.request({ + url, + method: 'POST', + header: header, + data: post_data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } + }) + }) + }) }, //---promise的使用delete---- promiseDelete: function (url, data) { var th = this; - if(!data) data={}; + var url1=url; + var arr_in_url=t.getParams(url1); + + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; return new Promise((resolve, reject) => { - data && data.isShowLoading && th.showLoading(); - wx.request({ - url, - method: 'DELETE', - header: { "content-type": "application/x-www-form-urlencoded" }, - data: data.data, - success(res) { - data && data.isShowLoading && th.hideLoading(); - resolve(res); - }, - fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } - }) + data.isShowLoading && th.showLoading(); + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var header={"content-type": "application/x-www-form-urlencoded"}; + var now = t.gettimestamp(); + + //-- 拼接连接中带有的参数 -- + var new_data={...arr_in_url,...data.data}; + + var tk = this.set_req_sign(new_data, url1, now, api_tk); + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey + } + + wx.request({ + url, + method: 'DELETE', + header: header, + data: data.data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { + data.isShowLoading && th.hideLoading(); + reject(err); + } + }) + + }) }) }, @@ -292,27 +517,58 @@ module.exports = { //---promise的使用put---- promisePut: function (url, data) { var th = this; + var url1=url; + + var arr_in_url=t.getParams(url1); + if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; var post_data = data.data; - var header = { "content-type": "application/x-www-form-urlencoded" }; - if (data.is_json) { - header = { 'content-type': 'application/json' }; - post_data = JSON.stringify(post_data); - }; - return new Promise((resolve, reject) => { - data.isShowLoading && th.showLoading(); - wx.request({ - url, - method: 'PUT', - header: header, - data: post_data, - success(res) { - data.isShowLoading && th.hideLoading(); - resolve(res); - }, - fail(err) { data.isShowLoading && th.hideLoading(); reject(err); } - }) - }) + + + var y_post_data=t.deep_cp(post_data); + if(!Array.isArray(post_data)) { + y_post_data = {...arr_in_url, ...y_post_data}; + } + + return new Promise((resolve, reject) => { + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var header = {"content-type": "application/x-www-form-urlencoded"}; + var now = t.gettimestamp(); + var tk = this.set_req_sign(y_post_data, url1, now, api_tk); + + if (data.is_json) { + header = {'content-type': 'application/json'}; + tk = this.set_req_sign(y_post_data, url1, now, api_tk, 1); + post_data = JSON.stringify(post_data); + } + + if (tk) { + header.reqtime = now; + header.token = tk; + header.ukey = api_tk.userkey + } + + data.isShowLoading && th.showLoading(); + wx.request({ + url, + method: 'PUT', + header: header, + data: post_data, + success(res) { + data.isShowLoading && th.hideLoading(); + resolve(res); + }, + fail(err) { + data.isShowLoading && th.hideLoading(); + reject(err); + } + }) + }) + }) + }, //--------具有时间限制的读取接口---------- @@ -333,21 +589,51 @@ module.exports = { var th = this; var Mathod = "POST"; + var url1=url; + var arr_in_url=t.getParams(url1); + if (mathod) Mathod = mathod; this.showLoading(); if (url.indexOf("http") == -1) url = getApp().globalData.setting.url + url; - var str = JSON.stringify(data); - wx.request({ - url: url, - data: str, - method: Mathod, - header: { + + //-- 获取一下token -- + this.ck_api_token((api_tk)=> { + + var header={ 'content-type': 'application/json' - },// 设置请求的 header - success: function (res) { succ(res); th.hideLoading(); }, - fail: function (res) { fail(res); } + }; + + var dd= t.deep_cp(data); + if(!Array.isArray(data)) { + dd = {...arr_in_url, ...dd}; + } + + var now=t.gettimestamp(); + var tk=this.set_req_sign(dd,url1,now,api_tk,1); + if(tk){ + header.reqtime=now; + header.token=tk; + header.ukey=api_tk.userkey + } + + var str = JSON.stringify(data); + wx.request({ + url: url, + data: str, + method: Mathod, + header: header,// 设置请求的 header + success: function (res) { + succ(res); + th.hideLoading(); + }, + fail: function (res) { + fail(res); + } + }) }) }, + + promise_downimg(url) { return new Promise((resolve, reject) => { @@ -362,6 +648,78 @@ module.exports = { } }); }) + }, + + //判断有没有获取到api_token + ck_api_token(func){ + var api_token = wx.getStorageSync('api_token'); + var api_token_time = wx.getStorageSync('api_token_time'); + //token有存在本地的时候 + if(api_token){ + //判断有没有超出token的时间,超出的话就要重头拿token + var now=t.formar_day(); + if(now!=api_token_time){ + //调用接口获取token + getApp().get_api_token(func); + return false; + } + func(api_token); + return false; + } + getApp().get_api_token(func); + }, + + //接口加密过程 + set_req_sign(data,url,now,api_tk,is_json){ + if(!url) return ''; + var name2=url.split('?')[0]; + if(!name2) return ''; + + //确保不要有前缀 + name2=name2.replace(setting.url,'') + + if(!now) now=t.gettimestamp(); + if(!api_tk){ + api_tk=wx.getStorageSync('api_token'); + } + var userkey = api_tk; + var token2=""; + + if(data && Object.keys(data).length>0) { + + for(var i in data){ + var item=data[i]; + if (typeof item === 'string') { + try { + data[i]=decodeURIComponent(item); //urldecode + }catch (err) { + + } + } + } + + var req4 =''; + if(is_json){ + req4 = JSON.stringify(data); + }else { + // 自定义序列化函数 + function stringifyReplacer(key, value) { + if (typeof value === 'number') { + return String(value); + } + return value; + } + req4 = JSON.stringify(data, stringifyReplacer); + } + //console.log(req4+':---token0'); + token2 = md5(req4).toUpperCase(); + //console.log(name2+':---token1:'+token2); + } + var str=name2.toUpperCase()+token2+now+userkey.token+setting.environment_key; + //console.log('---tk_str:'+str); + var tk = md5(str).toUpperCase(); + return tk; } + }; \ No newline at end of file diff --git a/utils/util.js b/utils/util.js index 2f1cbdb..50830c6 100644 --- a/utils/util.js +++ b/utils/util.js @@ -633,6 +633,18 @@ module.exports = { return t.getFullYear() +c+(t.getMonth() + 1)+c+t.getDate(); }, + formar_day(e,char){ + var t= new Date(); + if(e) t=new Date(1e3 * e); + + var c="-"; + if(char) c=char; + var ck=function (e){ + return e>=10? e : "0" + e; + } + return t.getFullYear() +c+ck(t.getMonth() + 1)+c+ck(t.getDate()); + }, + json2Form: function(e) { var r = []; for (var t in e) r.push(encodeURIComponent(t) + "=" + encodeURIComponent(e[t])); @@ -1019,5 +1031,16 @@ module.exports = { //判断e是不是对象类型 var new_e = JSON.parse(JSON.stringify(e)); return new_e; + }, + getParams(url) { + const search = url.split('?')[1]; + if (!search) return {}; + const paramArr = search.split('&'); + const paramObj = {}; + for (const param of paramArr) { + const [key, value] = param.split('='); + paramObj[key] = value; + } + return paramObj; } };