123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975 |
- var app = getApp() //实例化小程序,从而获取全局数据或者使用全局函数
- var MD5Util = require('../../utils/md5.js');
- // let URLINDEX=util.prefix();
- var addressList = [];
- var addressAll = [];
- Page({
- data: {
- user_phone: '',//绑定的手机号码
- hidden: 'hidden',
- cartsOrder:null, //给合成订单使用
- addressAll: addressAll,
- addressList: addressList,
- addressBg: "../../images/address_line.png",
- addressVal: "../../images/address_logo.png",
- addressAddImg: "../../images/add_address.png",
- addressEditImg: "../../images/gray_back.png",
- checkState: true,
- carts: [],
- gotJson2: {},
- total: 0,
- value: 0,
- checked: false,//发票默认不选中
- servalue: 1,
- serchecked: true,//服务协议默认选中
- isShow: false,
- address: '',
- total1: 0,
- total2: 0,
- province: '',
- city: '',
- area: '',
- adress: '',
- consignee: '',
- phone: '',
- hiddenmodal: true,
- minNum: 0,//优惠金额
- coupon_id: '',
- couponName: '', //优惠劵名称
- invoice: false,
- invCont: '我要开发票',
- //发票信息
- invoice_send_flag: 3,
- invoice_flag: 3, //发票标志位,如果为3,则为无需发票
- invoice_type_name: '',//发票类型名称
- invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: '', //纳税人识别号
- invoice_address: '',//注册地址
- invoice_telphone: '',//注册电话
- invoice_brandName: '',//开户银行
- invoice_brandNum: '',//银行账户
- invoice_company_content: '',//增值发票内容
- invoice_price: '',//发票金额
- invoice_title: '',//纸质个人发票抬头
- invoice_company_title: '',//纸质单位和增值发票抬头
- invoice_takeName: '',//收货姓名
- invoice_takeTelphone: '',//收货人联系方式
- invoice_takeAddress: '',//收货人地址
- invoiceTypeFlag: 0,
- orderState: 0,
- orderState1: 0,
- stateNum: 0,
- maskBg: false,//支付提示蒙层
- agrService: true,//同意服务协议
- stateNum:0,//记录定制商品数量
- allowPay : 0,//避免重复点击付款
- loginStatic:false, //判断是否是渠道登陆
- },
- onLoad: function (options) {
- wx.showNavigationBarLoading();
- var that = this;
- if (wx.getStorageSync('channelIdObj').channelId) {
- that.setData({
- loginStatic: true,
- })
- }
- //转义&符
- let cartsOrder = options.carts
- var carts = options.carts;
- carts = carts.replace(/zss/g, "&");
- carts = JSON.parse(carts);
- console.log(carts);
- that.setData({
- carts: carts,
- cartsOrder: cartsOrder
- })
- var total = 0;
- var total2 = 0;
- if(that.data.loginStatic){ // 表示渠道登陆
- for (var i = 0; i < carts.length; i++) {
- console.log(carts[i],"购物车")
- var boxPrice = carts[i].box_price;
- var goodsPrice = carts[i].product_channel_price ? carts[i].product_channel_price : carts[i].cost;
-
- if (boxPrice == '' && boxPrice == null) {
- boxPrice = 0;
- }
- total += ((parseFloat(goodsPrice) + parseFloat(boxPrice)) * parseInt(carts[i].num));
- }
- } else {
- for (var i = 0; i < carts.length; i++) {
- var boxPrice = carts[i].box_price;
- console.log("boxPrice:" + boxPrice);
- var goodsPrice = carts[i].cost;
- console.log("goodsPrice:" + goodsPrice);
- if (boxPrice == '' && boxPrice == null) {
- boxPrice = 0;
- }
- total += ((parseFloat(goodsPrice) + parseFloat(boxPrice)) * parseInt(carts[i].num));
- }
- }
-
- total = total.toFixed(2)
- total2 = total - that.data.minNum;
- if (total == 0) {
- total = 0.01;
- }
- if (total2 == 0) {
- total2 = 0.01;
- }
- that.setData({
- carts: carts,
- total1: total,
- total2: total2
- })
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- var openid = getApp().globalData.openid;
- wx.login({
- success: function (res) {
- //判断开始
- if ((un_id == undefined || un_id == '' || un_id == null) || (openid == undefined || openid == '' || openid == null)) {
- wx.navigateTo({
- url: '/pages/authorize/authorize?link=confirmOrder',
- })
- }else{
- //查询是否绑定手机号
- wx.request({
- url: host + "userapi/userGetPhone",
- data: {
- user_id: un_id,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- console.log("phone:"+res.data.result);
- that.setData({
- user_phone: res.data.result
- })
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- });
- //查询是否有发票信息
- wx.request({
- url: host + "invoiceapi/adressview",//发票
- data: {
- user_id: un_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- var flag = res.data.rows;
- if (res.data.total > 0) {
- if (res.data.rows[0].invoice_flag == 0) {
- that.setData({
- invoice_flag: 0,
- invoice_send_flag: 0,
- invCont: '纸质普通发票',
- invoice: true,
- invoice_type_name: '纸质普通发票',
- invoice_title: '个人',
- invoice_name: res.data.rows[0].invoice_name,//个人姓名
- invoice_content: res.data.rows[0].invoice_content,//发票内容
- invoice_price: res.data.rows[0].invoice_price//金额
- })
- } else if (res.data.rows[0].invoice_flag == 1) {
- that.setData({
- invoice_flag: 1,
- invoice_send_flag: 1,
- invCont: '纸质普通发票',
- invoice: true,
- invoice_type_name: '纸质普通发票',
- invoice_company_title: '单位',
- invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
- invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
- invoice_content: res.data.rows[0].invoice_content,//发票内容
- invoice_price: res.data.rows[0].invoice_price //金额
- })
- } else {
- that.setData({
- invoice_flag: 2,
- invoice_send_flag: 2,
- invCont: '增值税专用发票',
- invoice: true,
- invoice_type_name: '增值税专用发票',
- invoice_company_title: '单位',
- invoice_company_name: res.data.rows[0].invoice_company_name,//单位名称
- invoice_number: res.data.rows[0].invoice_number,//纳税人识别号
- invoice_address: res.data.rows[0].invoice_address,//注册地址
- invoice_telphone: res.data.rows[0].invoice_telphone,//注册电话
- invoice_brandName: res.data.rows[0].invoice_brandName,//开户银行
- invoice_brandNum: res.data.rows[0].invoice_brandNum,//银行账户
- invoice_company_content: '明细',//发票内容
- invoice_price: res.data.rows[0].invoice_price, //金额
- invoice_takeName: res.data.rows[0].invoice_takeName,
- invoice_takeTelphone: res.data.rows[0].invoice_takeTelphone,
- invoice_takeAddress: res.data.rows[0].invoice_takeAddress
- })
- }
- }
- wx.hideNavigationBarLoading(//加载完成后显示页面
- that.setData({
- hidden: ''
- })
- )
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- }
- //判断结束
- }
- })
- },
- onShow:function(){
- var that = this;
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- if (wx.getStorageSync('channelIdObj').channelId) {
- that.setData({
- loginStatic: true,
- })
- }
- },
- coupon: function () {//选择优惠劵
- wx.navigateTo({//把总价带过去,直接返回优惠之后的总价
- url: '/pages/mineCoupon/coupon?total2=' + this.data.total1
- })
- },
- invoice: function () {//我要开发票,把商品价钱带过来
- wx.navigateTo({
- url: '/pages/invoiceInfor/invoiceInfor?total1=' + this.data.total1
- })
- },
- checkboxChange: function (e) {
- var that = this;
- var datavalue = e.currentTarget.dataset.value;
- var invoice = this.data.invoice;
- if (invoice) {
- if (datavalue == 0) {
- that.setData({
- 'value': 1,
- 'checked': true,
- 'isShow': true,
- invCont: that.data.invoice_type_name
- })
- } else {
- that.setData({
- 'value': 0,
- 'checked': false,
- 'isShow': true,
- invCont: that.data.invoice_type_name
- })
- }
- }
- },
- agrService: function (e) {
- var that = this;
- var datavalue = e.currentTarget.dataset.value;
- if (datavalue == 0) {
- that.setData({
- servalue: 1,
- 'serchecked': true,
- allowPay : 0
- })
- } else {
- that.setData({
- servalue: 0,
- 'serchecked': false
- })
- }
- },
- save: function (e) {
- var that = this;
- var user_phone = that.data.user_phone;
- var formId = e.detail.formId;
- wx.showModal({
- title: '提示',
- content: '下单生成订单后不可更改',
- success(res) {
- if (res.confirm) {
- console.log("mineGiftList - formId1:" + formId);
- if (user_phone == '' || user_phone == null || user_phone == undefined) {
- wx.navigateTo({
- url: '/pages/bindingPhone/bindingPhone',
- })
- return false;
- }
- wx.showLoading({
- title: '订单合成中',
- })
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1]; //当前页面
- var prevPage = pages[pages.length - 2]; //上一个页面
- var prevPageUrl = prevPage.route;
- var len = that.data.carts.length;
- // wx.showLoading({//支付提示
- // title: '生成订单', //微信支付
- // icon: 'loading',
- // mask: true,
- // success: function () {
- // that.setData({
- // maskBg: true,
- // allowPay: 1
- // })
- // }
- // })
- that.setData({
- maskBg: true,
- allowPay: 1
- })
- if (that.data.value == 0) {
- that.setData({
- invoice_flag: 3,
- invoice_send_flag: 3,
- invoice_type_name: '',//发票类型名称
- invoice_name: '',//个人名字
- invoice_content: '',//纸质发票内容
- invoice_company_name: '',//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: '', //纳税人识别号
- invoice_address: '',//注册地址
- invoice_telphone: '',//注册电话
- invoice_brandName: '',//开户银行
- invoice_brandNum: '',//银行账户
- invoice_company_content: '',//增值发票内容
- invoice_price: '',//发票金额
- invoice_title: '',//纸质个人发票抬头
- invoice_company_title: '',//纸质单位和增值发票抬头
- invoice_takeName: '',//收货姓名
- invoice_takeTelphone: '',//收货人联系方式
- invoice_takeAddress: ''//收货人地址
- })
- }
- var timestamp = Date.parse(new Date());
- timestamp = timestamp / 1000;
- var timestamp1 = timestamp;
- wx.setStorageSync('orderId', timestamp1)
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- if (un_id != undefined && un_id != '' && un_id != null) {
- wx.request({
- url: host + "orderapi/insertorder",
- data: {
- order_userid: un_id,
- order_sta: '1',
- order_number: timestamp,
- order_type: '0',
- order_Consignee: that.data.consignee,
- order_phone: that.data.phone,
- order_address: '',
- order_commodityid: that.data.carts[0].id,
- order_num: that.data.carts[0].num,
- order_Price: that.data.total2,//////
- orderr_Coupon: that.data.minNum,
- coupon_id: that.data.coupon_id,
- order_Specifications: '',
- order_gixbox: '',
- invoice_send_flag: that.data.invoice_send_flag,
- invoice_flag: that.data.invoice_flag, //发票标志位
- invoice_type_name: that.data.invoice_type_name,//发票类型名称
- invoice_name: that.data.invoice_name,//个人名字
- invoice_content: that.data.invoice_content,//纸质发票内容
- invoice_company_name: that.data.invoice_company_name,//发票公司名字(纸质单位和增值单位的公司名称相同)
- invoice_number: that.data.invoice_number, //纳税人识别号
- invoice_address: that.data.invoice_address,//注册地址
- invoice_telphone: that.data.invoice_telphone,//注册电话
- invoice_brandName: that.data.invoice_brandName,//开户银行
- invoice_brandNum: that.data.invoice_brandNum,//银行账户
- invoice_company_content: that.data.invoice_company_content,//增值发票内容
- invoice_price: that.data.invoice_price,//发票金额
- invoice_title: that.data.invoice_title,//纸质个人发票抬头
- invoice_company_title: that.data.invoice_company_title,//纸质单位和增值发票抬头
- invoice_takeName: that.data.invoice_takeName,//收货姓名
- invoice_takeTelphone: that.data.invoice_takeTelphone,//收货人联系方式
- invoice_takeAddress: that.data.invoice_takeAddress,//收货人地址
- channel_account_id: wx.getStorageSync('channelIdObj').channelAccountId ? wx.getStorageSync('channelIdObj').channelAccountId : ""
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res.data.result == 1) {
- //插入订单
- that.insertOrder(len, timestamp, timestamp1, that.data.coupon_id, un_id, formId);
- } else {
- //删除当前订单
- that.deleteOrder(un_id, timestamp, that.data.coupon_id);
- wx.hideLoading();
- that.setData({
- maskBg: false,
- allowPay: 0,
- firstClick: 0
- })
- }
- if (res == null || res.data == null || res.data == '') {
- console.error('插入订单失败');
- //删除当前订单
- that.deleteOrder(un_id, timestamp, that.data.coupon_id);
- that.setData({
- maskBg: false,
- allowPay: 0,
- firstClick: 0
- })
- return;
- }
- }
- });
- }
- }
- }
- })
-
-
-
- },
- //插入订单
- insertOrder: function (i, timestamp, timestamp1, coupon_id, un_id, formId){
- var that = this;
- var host = getApp().globalData.servsers;
- var stateNum = that.data.stateNum;//记录带有定制的商品数量
- if(i == 0){
- if (stateNum > 0) {
- that.setData({
- orderState1: 2//待定制
- })
- } else {
- that.setData({
- orderState1: 10//待送礼 10
- })
- }
- //调起支付
- console.log("掉期支付")
- that.payOrder(timestamp, timestamp1, coupon_id, un_id, formId);
- // wx.showToast({
- // title: '订单已生成,后面待上传支付凭证',
- // icon:'none'
- // })
- // wx.navigateTo({
- // url: '/pages/orderCanvas/orderCanavs',
- // })
- }else{
- i -=1;
- var com_id = that.data.carts[i].com_id;
- var name = that.data.carts[i].name;//商品名称
- //检测商品是否下架
- wx.request({
- url: host + "commodityapi/commoditview",
- data: {
- com_id: com_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- //有此商品
- if (res.data.total > 0) {
- if (res.data.commodity.commodity_flag != 0) {//此商品为下架商品
- wx.hideLoading();
- that.setData({
- maskBg: false,
- hiddenmodal: false,
- modalCont: name + '已下架,请重新选购!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 2000)
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- wx.navigateBack({
- delta:1
- })
- return false;
- } else {
- //检测库存
- wx.request({
- url: host + "api/commodityGroup/checkCommodityGroupRepertory",
- data: {
- datasheetGroupId: that.data.carts[i].com_group_id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res.data.code == '200') {
- var canBuy = res.data.data.canBuy;
- //库存充足【当前选择的规格库存不为0,且库存数量大于起订量】
- if (res.data.data.canBuy == true) {
- if (res.data.data.repertory < that.data.carts[i].num) {
- wx.hideLoading();
- that.setData({
- maskBg: false,
- hiddenmodal: false,
- modalCont: '"' + that.data.carts[i].name + '"的库存不足,请重新选择购买数量!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- wx.navigateBack({
- delta: 1
- })
- }, 3000);
- return false;
- }else{
-
- var sumNum = parseInt(that.data.carts[i].num);
- for (var t = 0; t < i; t++) {
- if (that.data.carts[t].com_id == that.data.carts[i].com_id && that.data.carts[t].com_group_id == that.data.carts[i].com_group_id) {
- sumNum += parseInt(that.data.carts[t].num);
- }
- }
- console.log("立即购买-sumNum:" + sumNum);
- console.log("立即购买-repertory:" + res.data.data.repertory);
- if (sumNum > res.data.data.repertory) {
- wx.hideLoading();
- that.setData({
- maskBg: false,
- hiddenmodal: false,
- modalCont: '“' + that.data.carts[i].name + '”库存不足,请重新选择!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- wx.navigateBack({
- delta: 1
- })
- }, 3000);
- return false;
- } else {
- that.insertEachGoods(i, timestamp, timestamp1, coupon_id, un_id, formId);
- }
- }
- }else{
- wx.hideLoading();
- that.setData({
- maskBg: false,
- hiddenmodal: false,
- modalCont: '“' + that.data.carts[i].name + '”已售罄,请重新选购!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- wx.navigateBack({
- delta: 1
- })
- }, 3000);
- return false;
- }
- }
- }
- })
- }
- } else {
- wx.hideLoading();
- that.setData({
- maskBg: false,
- hiddenmodal: false,
- modalCont: '“' + that.data.carts[i].name + '”已下架,请重新选购!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- wx.navigateBack({
- delta: 1
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- }, 3000);
- return false;
- }
- }
- })
- }
-
- },
- //插入订单中的每一样商品
- insertEachGoods: function (i, timestamp, timestamp1, coupon_id, un_id, formId){
- var that = this;
- var host = getApp().globalData.servsers;
- console.log(that.data.carts);
- wx.request({
- url: host + "orderaffapi/insertOrderAff",
- data: {
- order_number: timestamp,
- cost: that.data.carts[i].cost,
- com_id: that.data.carts[i].com_id,
- logo: that.data.carts[i].logo,
- name: that.data.carts[i].name,
- num: that.data.carts[i].num,
- process: that.data.carts[i].process,
- giftbox_name: that.data.carts[i].giftbox_name,
- giftbox_id: that.data.carts[i].giftbox,
- box_price: that.data.carts[i].box_price,
- process_name: that.data.carts[i].process_name,
- process_id: that.data.carts[i].process,
- logo: that.data.carts[i].logo,
- style1: that.data.carts[i].style1,
- style1_name: that.data.carts[i].style1_name,
- style2: that.data.carts[i].style2,
- style2_name: that.data.carts[i].style2_name,
- style3: that.data.carts[i].style3,
- style3_name: that.data.carts[i].style3_name,
- style4: that.data.carts[i].style4,
- style4_name: that.data.carts[i].style4_name,
- style5: that.data.carts[i].style5,
- style5_name: that.data.carts[i].style5_name,
- comGroupId: that.data.carts[i].com_group_id,
- channel_account_id: wx.getStorageSync('channelIdObj').channelAccountId ? wx.getStorageSync('channelIdObj').channelAccountId : ""
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- console.log("插入");
- console.log(res);
- // wx.setStorageSync('orderImg', res.data)
- if ((that.data.carts[i].process_name != '') && (that.data.carts[i].process != -1)) {
- that.setData({
- stateNum: that.data.stateNum + 1
- })
- }
- //插入订单
- that.insertOrder(i, timestamp, timestamp1, coupon_id, un_id, formId);
- console.log("插入2");
- if (res == null || res.data == null || res.data == '') {
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- that.setData({
- maskBg: false,
- allowPay: 0,
- firstClick: 0
- })
- console.error('插入订单失败');
- return;
- }
- }
- })
- },
- //删除订单
- deleteOrder: function (un_id, timestamp, coupon_id){
- var that = this;
- var host = getApp().globalData.servsers;
- wx.request({
- url: host + "orderapi/deleteorder",
- data: {
- order_userid: un_id,
- order_number: timestamp,
- coupon_id: coupon_id,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res == null || res.data == null) {
- console.error('已下架-删除订单:失败');
- return;
- }
- }
- });
- },
- //调起付款
- payOrder:function(timestamp, timestamp1, coupon_id, un_id, formId){
-
- console.log("pay");
- console.log("pay-formId:" + formId);
- var that = this;
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1]; //当前页面
- var prevPage = pages[pages.length - 2]; //上一个页面
- var prevPageUrl = prevPage.route;
- var host = getApp().globalData.servsers;
- var carts = that.data.carts;
- var timestamp = String(Date.parse(new Date())); //时间戳
- //插入用于模板消息的formId
- wx.request({
- url: host + "userapi/insertadduserwxsend",
- data: {
- user_id: un_id,
- form_id_fh: formId,
- order_number: timestamp,
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- console.log("formid");
- console.log(res);
- if (res == null || res.data == null) {
- console.error('插入formId失败');
- return;
- }
- }
- })
-
- //获取用户登录状态
- wx.login({
- success: function (res) {
- //发起网络请求,发起的是HTTPS请求,向服务端请求预支付
- var code = res.code;
- var title = that.data.carts[0].name;
- var price = that.data.total2 * 100;
- price = 1;
-
- wx.request({
- url: host + 'prepay',
- data: {
- code: code,
- price: price,
- title: title,
- order_number: timestamp1,
- userid: un_id
- },
- success: function (res) {
- console.log("pay:");
- console.log(res);
- if (res.data.result) {
- wx.hideLoading();
- that.setData({
- maskBg: false
- })
- if (res.data.result == true) {
- var nonceStr = res.data.nonceStr;
- var prepayId = res.data.prepayId;
- // 按照字段首字母排序组成新字符串
- var payDataA = "appId=wx9e3f68fa2172f1c7&nonceStr=" + res.data.nonceStr + "&package=prepay_id=" + res.data.prepayId + "&signType=MD5&timeStamp=" + timestamp;
- var payDataB = payDataA + "&key=MlxMZWpZidKxCPPaOOztMP84XvQzqSOh";
- // 使用MD5加密算法计算加密字符串
- paySign = MD5Util.MD5(payDataB).toUpperCase();
- // 使用MD5加密算法计算加密字符串
- var paySign = MD5Util.MD5(payDataB).toUpperCase();
- // 发起微信支付
- // wx.requestPayment({
- // 'timeStamp': timestamp,
- // 'nonceStr': nonceStr,
- // 'package': 'prepay_id=' + prepayId,
- // 'signType': 'MD5',
- // 'paySign': paySign,
- // 'success': function (res) {
- // console.log(111);
- // console.log(res);
- // wx.request({
- // url: host + "orderapi/update",
- // data: {
- // order_sta: that.data.orderState1,
- // order_number: timestamp1,
- // orderState: that.data.orderState1,
- // order_userid: un_id
- // },
- // method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- // header: {
- // 'Accept': 'application/json'
- // },
- // success: function (res) {
- // console.log("支付");
- // console.log(res);
- // that.setData({
- // maskBg: false,
- // hiddenmodal: false,
- // modalCont: '支付成功'
- // })
- // setTimeout(function () {
- // that.setData({
- // hiddenmodal: true
- // })
- // wx.redirectTo({
- // url: '/pages/orderList/orderList?isSelect=0'
- // })
- // }, 2000);
- // if (res == null || res.data == null) {
- // //删除当前订单
- // that.deleteOrder(un_id, timestamp, that.data.coupon_id);
- // that.setData({
- // maskBg: false,
- // allowPay: 0,
- // firstClick: 0
- // })
- // return false;
- // }
- // }
- // });
- // },
- // 'fail': function (res) {
- // that.setData({
- // maskBg: false,
- // hiddenmodal: false,
- // modalCont: '取消支付'
- // })
- // setTimeout(function () {
- // that.setData({
- // hiddenmodal: true
- // })
- // wx.redirectTo({
- // url: '/pages/orderList/orderList?isSelect=0'
- // })
- // }, 2000);
- // }
- // })
- //如果是从购物车进入支付,则清空对应购物车商品
- if (prevPageUrl == 'pages/car/index' || prevPageUrl == 'pages/carInsert/carInsert') {
- for (var i = 0; i < that.data.carts.length; i++) {
- wx.request({
- url: host + "shoppingcartapi/deleteshoppingcart",
- data: {
- id: that.data.carts[i].id
- },
- method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (res == null || res.data == null) {
- console.error('清空对应购物车商品失败');
- return;
- }
- }
- });
- }
- }
- // 生产订单中
- wx.navigateTo({
- url: '/pages/orderCanvas/orderCanavs?orderId=' + timestamp1,
- })
- } else {
- that.setData({
- maskBg: false,
- allowPay: 0,
- firstClick: 0
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
- return false;
- }
- } else {
- that.setData({
- maskBg: false,
- allowPay: 0,
- firstClick: 0,
- hiddenmodal: false,
- modalCont: '网络错误,请重新操作!'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true,
- allowPay: 0
- })
- //删除当前订单
- that.deleteOrder(un_id, timestamp, coupon_id);
-
- }, 3000);
- return false;
- }
- }
- })
- }
- })
- },
- })
- var that;
- var Util = require('../../utils/util.js');
|