diff --git a/._config.js b/._config.js new file mode 100644 index 0000000..528b5da Binary files /dev/null and b/._config.js differ diff --git a/._project.config.json b/._project.config.json new file mode 100644 index 0000000..528b5da Binary files /dev/null and b/._project.config.json differ diff --git a/._project.private.config.json b/._project.private.config.json new file mode 100644 index 0000000..528b5da Binary files /dev/null and b/._project.private.config.json differ diff --git a/app.json b/app.json index 1589233..7c51b6a 100644 --- a/app.json +++ b/app.json @@ -52,12 +52,7 @@ "selectedIconPath": "images/nav/index-on.png", "text": "点餐" }, - { - "pagePath": "pages/queue/index", - "iconPath": "images/nav/qh-off.png", - "selectedIconPath": "images/nav/qh-on.png", - "text": "取号" - }, + { "pagePath": "pages/order-details/doing", "iconPath": "images/nav/qc-off.png", diff --git a/config.js b/config.js index 737046b..15ecd9d 100644 --- a/config.js +++ b/config.js @@ -1,9 +1,14 @@ module.exports = { - apiHost: 'http://127.0.0.1:18083', + apiHost: 'https://9kuai8coffee.asia', + //apiHost: 'http://localhost:8081', // apiHost: 'https://api.it120.cc',//api工厂的值 - subDomain: "cocktailBeeOrder", // 固定值 - version: "6.1.1", - note: '已点菜品,合计按钮显示不正确', + subDomain: "9kuai8coffee.asia", // 固定值 + + + version: "20.1.2", + + note: '标签机 会员价 ', + merchantId: 27, // 商户ID,可在后台工厂设置-->商户信息查看 customerServiceType: 'QW' // 客服类型,QW为企业微信,需要在后台系统参数配置企业ID和客服URL,否则为小程序的默认客服 } diff --git a/i18n/index.js b/i18n/index.js index c80025b..e53e47a 100644 --- a/i18n/index.js +++ b/i18n/index.js @@ -29,16 +29,10 @@ function setTabBarLanguage(){ text: $t.index.order }) - wx.setTabBarItem({ - index: 1, - pagePath: "pages/queue/index", - iconPath: "images/nav/qh-off.png", - selectedIconPath: "images/nav/qh-on.png", - text: $t.queue.t - }) + wx.setTabBarItem({ - index: 2, + index: 1, pagePath: "pages/order-details/doing", iconPath: "images/nav/qc-off.png", selectedIconPath: "images/nav/qc-on.png", @@ -46,7 +40,7 @@ function setTabBarLanguage(){ }) wx.setTabBarItem({ - index: 3, + index: 2, pagePath: "pages/my/index", iconPath: "images/nav/my-off.png", selectedIconPath: "images/nav/my-on.png", diff --git a/i18n/zh_CN.js b/i18n/zh_CN.js index 0c4b4f9..d96d040 100644 --- a/i18n/zh_CN.js +++ b/i18n/zh_CN.js @@ -239,12 +239,12 @@ module.exports = { title: '会员', consumption: '累计消费', notVIP: '非会员', - tip: '消费达到金额可自动成为会员', + tip: '余额达到100可自动成为会员 余额少于9.8失去会员资格,重新充值100元以上恢复会员资格', growth: '会员成长体系', growthName: '级别名称', growthDiscount: '购物折扣', growthConsumption: '消费标准(元)', - profile: '注:当购物消费达指定标准自动成为该级别会员', + profile: '注:', }, feedback: { title: '意见反馈', diff --git a/images/coupon.png b/images/coupon.png index f713578..44793be 100644 Binary files a/images/coupon.png and b/images/coupon.png differ diff --git a/miniprogram_npm/._.DS_Store b/miniprogram_npm/._.DS_Store new file mode 100644 index 0000000..a5b28df Binary files /dev/null and b/miniprogram_npm/._.DS_Store differ diff --git a/miniprogram_npm/apifm-wxapi/._index.js b/miniprogram_npm/apifm-wxapi/._index.js new file mode 100644 index 0000000..528b5da Binary files /dev/null and b/miniprogram_npm/apifm-wxapi/._index.js differ diff --git a/miniprogram_npm/apifm-wxapi/index.js b/miniprogram_npm/apifm-wxapi/index.js index d18a9c7..28395f9 100644 --- a/miniprogram_npm/apifm-wxapi/index.js +++ b/miniprogram_npm/apifm-wxapi/index.js @@ -980,6 +980,12 @@ module.exports = { token: token }); }, + balance_pay: function balance_pay(token, orderId) { + return request('/order/balance_pay', true, 'post', { + orderId: orderId, + token: token + }); + }, orderPayV2: function orderPayV2(data) { return request('/order/pay', true, 'post', data); }, diff --git a/pages/all-orders/index.js b/pages/all-orders/index.js index c1e5495..980cfc6 100644 --- a/pages/all-orders/index.js +++ b/pages/all-orders/index.js @@ -2,12 +2,14 @@ const wxpay = require('../../utils/pay.js') const WXAPI = require('apifm-wxapi') const AUTH = require('../../utils/auth') const APP = getApp() +var util = require('../../utils/util.js') APP.configLoadOK = () => { } Page({ data: { - apiOk: false + apiOk: false, + dataP:'' }, cancelOrderTap: function(e) { const that = this; @@ -89,14 +91,48 @@ Page({ }, _toPayTap: function (orderId, money){ const _this = this + // console.log(orderId) + // console.log(wx.getStorageSync(orderId)) + //未支付的现金订单,从本地缓存中获取订单信息 + _this.data.dataP = '' + try{ + _this.data.dataP = wx.getStorageSync(orderId +"O") + console.log("缓存中取出的打印数据:", _this.data.dataP) + } + catch(e){ + console.log("缓存中取出的打印数据报错:",e) + } + if (money <= 0) { // 直接使用余额支付 WXAPI.orderPay(wx.getStorageSync('token'), orderId).then(function (res) { + console.log("余额支付:",r) + if(r.code==700 &&_this.data.dataP){ + //打印的数据 + if(_this.data.dataP && _this.data.dataP ===true){ + + //小票 + that.print2(_this.data.dataP) + //标签 + that.print(_this.data.dataP) + } + + } _this.onShow(); }) } else { - wxpay.wxpay('order', money, orderId, "/pages/all-orders/index"); - } + //缓存中有打印信息 + if(_this.data.dataP){ + wxpay.wxpay('order', money, orderId, "/pages/all-orders/index",_this.data.dataP); + + }//缓存中无打印信息 + else{ + wxpay.wxpay('order', money, orderId, "/pages/all-orders/index"); + } + + + + } }, onLoad: function(options) { getApp().initLanguage(this) @@ -201,4 +237,194 @@ Page({ phoneNumber: res.data.info.linkPhone, }) }, + //打印标签,参数为支付返回的data数据 + print(data){ + var that = this + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/printLabel' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //打印机序列号,店铺id对应打印机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '32817SCU1VAF54B' + + }//未来店 + else if (data.shopInfo.id==1){ + sn = '32EL21088705948' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '325Z1VC2ANA044B' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '32EVUCUVY0B4848' + } + + + + + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = that.getDate() + let content = '' + + for(let i=0;i# '+(i+1) +'/' + data.goodsList.length + ' 总金额:'+data.data.amountReal + ''+ + ''+ data.goodsList[i].name +'' + for(let j=0;j'+ data.goodsList[i].sku[j].optionValueName +'' + } + content+= ''+'单价: ¥'+data.goodsList[i].price + ''+ + ''+ data.data.orderNumber+ ''+ + ''+ timeStr + ''+ + ''+ data.shopInfo.name + '' + '' + + } + } + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("标签打印返回:",res) + } + + + }) + }, + //打印小票,参数为支付返回的data数据 + print2(data){ + var that = this + + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/print' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //小票机序列号,店铺id对应小票机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '74Y4LWMD9R9AF4B' + } + //未来店 + else if (data.shopInfo.id==1){ + sn = '742N30GDRND8E4A' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '74S8LPEQ3584048' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '744905VQE26ED4A' + } + + + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = that.getDate() + let content = '9.8 COFFEE


' +' ' + + for(let i=0;i' + data.goodsList[i].number +'' + content+='|' + for(let j=0;j
' + + content+= '下单时间: '+ timeStr + '
'+ + '订单编号: '+ data.data.orderNumber + '
' + + '用户电话: '+ data.mobile + '
' + if(data.peisongType =='pszq'){ + content+= '用户地址: '+ data.address + '
' + } + // if(that.data.peisongType=='zq'){ + // content+= ' 取单号: '+that.data.curAddressData.address + '
' + // } + content+= '门店名称: ' + data.shopInfo.name +'
'+ + '备注: ' + data.remark +'
' + content+= '
' + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("小票打印返回:",res) + } + + + }) + }, + //获取当前年月日时分秒,打印时间 +getDate(){ + var now = new Date(); +var year = now.getFullYear(); // 年 +var month = now.getMonth() + 1; // 月 +var day = now.getDate(); // 日 +var hour = now.getHours(); // 时 +var minute = now.getMinutes(); // 分 +var second = now.getSeconds(); // 秒 + +// 格式化输出 +var timeString = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second); +return timeString + +} }) \ No newline at end of file diff --git a/pages/asset/index.js b/pages/asset/index.js index e2f87e0..51bab50 100644 --- a/pages/asset/index.js +++ b/pages/asset/index.js @@ -85,6 +85,7 @@ Page({ const postData = { token: wx.getStorageSync('token'), money: money, + shopId: wx.getStorageSync('shopInfo').id, payName: "在线充值", remark: "在线充值", } diff --git a/pages/coupons/index.js b/pages/coupons/index.js index d55eca9..2134c02 100644 --- a/pages/coupons/index.js +++ b/pages/coupons/index.js @@ -77,7 +77,7 @@ Page({ wx.showLoading({ title: '', }) - WXAPI.coupons().then(function (res) { + WXAPI.coupons({token: wx.getStorageSync('token')}).then(function (res) { wx.hideLoading({ success: (res) => {}, }) diff --git a/pages/coupons/index.wxml b/pages/coupons/index.wxml index b4fd557..2ed6b80 100644 --- a/pages/coupons/index.wxml +++ b/pages/coupons/index.wxml @@ -1,3 +1,4 @@ + @@ -14,8 +15,8 @@ {{ $t.coupons.over }} {{item.moneyHreshold}} - {{item.moneyMin}} - {{item.moneyMin}}% + {{item.money}} + {{filters.formatNumber(item.money)*100}}% {{ $t.coupons.btn }} @@ -28,9 +29,9 @@ {{item.name}} - ({{item.dateEnd}} {{ $t.coupons.expire }}) {{ $t.coupons.over }} {{item.moneyHreshold}} + ({{filters.parseTime(item.expiryMillis,'date')}} {{ $t.coupons.expire }}) {{ $t.coupons.over }} {{item.moneyHreshold}} {{item.money}} - {{item.money}}% + {{filters.formatNumber(item.money)*100}}% {{ $t.coupons.toUse }} @@ -45,7 +46,7 @@ {{ $t.coupons.over }} {{item.moneyHreshold}} {{item.money}} - {{item.money}}% + {{filters.formatNumber(item.money)*100}}% {{ item.statusStr }} diff --git a/pages/goods-details/index.js b/pages/goods-details/index.js index ed1ba7e..02ee42f 100644 --- a/pages/goods-details/index.js +++ b/pages/goods-details/index.js @@ -118,7 +118,7 @@ Page({ if (goodsDetailRes.data.properties) { that.setData({ hasMoreSelect: true, - selectSizePrice: goodsDetailRes.data.basicInfo.minPrice, + selectSizePrice: goodsDetailRes.data.basicInfo.vipPrice>0?goodsDetailRes.data.basicInfo.vipPrice:goodsDetailRes.data.basicInfo.minPrice, selectSizeOPrice: goodsDetailRes.data.basicInfo.originalPrice, totalScoreToPay: goodsDetailRes.data.basicInfo.minScore }); diff --git a/pages/index/index.js b/pages/index/index.js index 2a077cd..8342080 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -18,6 +18,11 @@ Page({ menuButtonBoundingClientRect: wx.getMenuButtonBoundingClientRect(), }, onLoad: function (e) { + + // 清除店铺缓存 + wx.removeStorageSync('shopInfo') + wx.removeStorageSync('shopIds') + getApp().initLanguage(this) const _data = {} // 测试拼团入口 @@ -83,6 +88,11 @@ Page({ mallName }) } + const isVip = wx.getStorageSync('isVip') + this.setData({ + isVip + }) + APP.configLoadOK = () => { const mallName = wx.getStorageSync('mallName') if (mallName) { @@ -146,20 +156,43 @@ Page({ wx.getLocation({ type: 'wgs84', //wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: (res) => { - // console.log(res) this.data.latitude = res.latitude this.data.longitude = res.longitude this.fetchShops(res.latitude, res.longitude, '') }, fail: (e) => { if (e.errMsg.indexOf('fail auth deny') != -1) { - AUTH.checkAndAuthorize('scope.userLocation') + // 定位权限被拒绝,提供友好提示 + wx.showModal({ + title: this.data.$t.common.tips || '提示', + content: '为了给您推荐最近的门店,需要获取您的位置信息', + confirmText: this.data.$t.common.confirm || '去开启', + cancelText: this.data.$t.common.cancel || '暂不开启', + success: (res) => { + if (res.confirm) { + AUTH.checkAndAuthorize('scope.userLocation') + } else { + // 用户选择不开启定位,跳转到店铺列表 + wx.navigateTo({ + url: '/pages/shop/select?type=index' + }) + } + } + }) } else { + // 其他定位错误 wx.showModal({ - confirmText: this.data.$t.common.confirm, - cancelText: this.data.$t.common.cancel, - content: e.errMsg, - showCancel: false + title: this.data.$t.common.tips || '提示', + content: '无法获取您的位置,是否手动选择门店?', + confirmText: this.data.$t.common.confirm || '去选择', + cancelText: this.data.$t.common.cancel || '取消', + success: (res) => { + if (res.confirm) { + wx.navigateTo({ + url: '/pages/shop/select?type=index' + }) + } + } }) } } @@ -170,9 +203,12 @@ Page({ curlatitude: latitude, curlongitude: longitude, nameLike: kw, - pageSize: 1 + orderBy: 'distance', // 按距离排序 + sortBy: 'asc' // 升序排列 }) if (res.code == 0) { + res.data.sort((a, b) => parseFloat(a.distance) - parseFloat(b.distance)) + res.data.forEach(ele => { ele.distance = ele.distance.toFixed(1) // 距离保留3位小数 }) @@ -407,6 +443,9 @@ Page({ price = res.data.price if (this.data.shopType == 'toPingtuan') { price = res.data.pingtuanPrice + } else if (wx.getStorageSync('isVip')) { + console.log('isVip') + price = res.data.vipPrice > 0?res.data.vipPrice:res.data.price } originalPrice = res.data.originalPrice totalScoreToPay = res.data.score @@ -669,6 +708,7 @@ Page({ } wx.hideTabBar() res.data.price = res.data.basicInfo.minPrice + res.data.vipPrice = res.data.basicInfo.vipPrice res.data.number = res.data.basicInfo.minBuyNumber const _data = { curGoodsMap: res.data, diff --git a/pages/index/index.wxml b/pages/index/index.wxml index b82b1c8..69aa99f 100644 --- a/pages/index/index.wxml +++ b/pages/index/index.wxml @@ -54,12 +54,16 @@ centered="true" lazy-load="true" origin-price="{{ (item.originalPrice > 0 && item.originalPrice != item.minPrice) ? item.originalPrice : '' }}" - price="{{item.minPrice}}" + price="{{isVip?(item.vipPrice>0?item.vipPrice:item.minPrice):item.minPrice}}" + price-class="van-price-{{isVip&&item.vipPrice>0}}" thumb-mode="aspectFill" tag="{{ item.badge ? item.badge : '' }}" title="{{item.name}}" thumb-link="/pages/goods-details/index?id={{ item.id }}" thumb="{{item.pic}}"> + + ¥{{item.minPrice}} + @@ -138,7 +142,7 @@ - ¥{{curGoodsMap.price}} + ¥{{isVip && curGoodsMap.vipPrice>0 ?curGoodsMap.vipPrice:curGoodsMap.price}} @@ -171,7 +175,7 @@ - ¥{{ item.price }} + ¥{{ isVip&&item.vipPrice>0?item.vipPrice:item.price }} @@ -226,10 +230,11 @@ - + - + + diff --git a/pages/index/index.wxss b/pages/index/index.wxss index b729641..8de1110 100644 --- a/pages/index/index.wxss +++ b/pages/index/index.wxss @@ -379,4 +379,15 @@ page { .count-downno-start .van-count-down { color: #ed6a0c; padding: 8rpx 0; +} + +.van-price-true { + color: goldenrod !important; +} +.van-price-false { + color: red !important; +} +.noVip-price { + font-weight: 500; + color: rgb(240, 134, 134); } \ No newline at end of file diff --git a/pages/member-center/index.js b/pages/member-center/index.js index 7e1ee92..fb0d523 100644 --- a/pages/member-center/index.js +++ b/pages/member-center/index.js @@ -44,6 +44,13 @@ Page({ async getUserApiInfo() { const res = await WXAPI.userDetail(wx.getStorageSync('token')) if (res.code == 0) { + // 判断会员 + if (res.data.base.vipLevel > 0) { + res.data.userLevel = {name: this.data.$t.vip.title} + wx.setStorageSync('isVip', true) + } else { + wx.setStorageSync('isVip', false) + } this.setData({ apiUserInfoMap: res.data }); diff --git a/pages/my/index.js b/pages/my/index.js index 40c7ee0..c1e8cf4 100644 --- a/pages/my/index.js +++ b/pages/my/index.js @@ -45,6 +45,13 @@ Page({ const res = await WXAPI.userDetail(wx.getStorageSync('token')) if (res.code == 0) { const _data = {} + // 判断会员 + if (res.data.base.vipLevel > 0) { + res.data.userLevel = {name: this.data.$t.vip.title} + wx.setStorageSync('isVip', true) + } else { + wx.setStorageSync('isVip', false) + } _data.apiUserInfoMap = res.data _data.nick = res.data.base.nick if (this.data.order_hx_uids && this.data.order_hx_uids.indexOf(res.data.base.id) != -1) { diff --git a/pages/my/index.wxml b/pages/my/index.wxml index 8e6ce97..04b56ac 100644 --- a/pages/my/index.wxml +++ b/pages/my/index.wxml @@ -40,16 +40,16 @@ - - + - - + v{{version}} diff --git a/pages/pay/index.js b/pages/pay/index.js index 2b9709a..aceffa3 100644 --- a/pages/pay/index.js +++ b/pages/pay/index.js @@ -3,6 +3,7 @@ const AUTH = require('../../utils/auth') const wxpay = require('../../utils/pay.js') const CONFIG = require('../../config.js') const APP = getApp() +var util = require('../../utils/util.js') APP.configLoadOK = () => { } @@ -30,6 +31,7 @@ Page({ peisongType: '', // 配送方式 kd,zq 分别表示快递/到店自取【默认值到onshow修改,这里修改无效】 submitLoding: false, remark: '', + dataP: '',//打印信息保存 currentDate: new Date().getHours() + ':' + (new Date().getMinutes() % 10 === 0 ? new Date().getMinutes() : Math.ceil(new Date().getMinutes() / 10) * 10), minHour: new Date().getHours(), @@ -324,7 +326,7 @@ Page({ moneyUnit = '%' } if (ele.moneyHreshold) { - ele.nameExt = ele.name + + ' ['+ that.data.$t.pay.Fullconsumption +'' + ele.moneyHreshold + that.data.$t.pay.RMBreduced + ele.money + moneyUnit +']' + ele.nameExt = ele.name + ' ['+ that.data.$t.pay.Fullconsumption +'' + ele.moneyHreshold + that.data.$t.pay.RMBreduced + ele.money + moneyUnit +']' } else { ele.nameExt = ele.name + ' ['+ that.data.$t.pay.Fullconsumption +'' + ele.money + moneyUnit + ']' } @@ -354,6 +356,41 @@ Page({ }) }, async processAfterCreateOrder(res) { + var that = this + //保存支付相关信息,以订单号key + let address = '' + if(that.data.curAddressData){ + if(that.data.curAddressData.address){ + address = that.data.curAddressData.address + + } + } + + that.data.dataP = { + data: res.data, //订单信息 + goodsList:that.data.goodsList, //商品列表 + shopInfo: that.data.shopInfo, //商铺信息 + mobile: that.data.mobile,//用户电话 + address: address,//配送地址 + remark: that.data.remark, //用户备注 + peisongType: that.data.peisongType,//zq,kd + + isPrint: true //打印标志 + + } + // + console.log("缓存前的打印数据",that.data.dataP) + try{ + //存储打印数据 + wx.setStorage({ + key: that.data.dataP.data.id +"O", + data: that.data.dataP + }) + } + catch(e){ + console.log("存储打印数据报错:",e) + } + const token = wx.getStorageSync('token') if (res.data.status != 0) { // 待支付状态才需要支付 @@ -374,16 +411,34 @@ Page({ }); return } + + const money = res.data.amountReal * 1 - res1.data.balance*1 if (money <= 0) { // 使用余额支付 - await WXAPI.orderPay(token, res.data.id) + await WXAPI.balance_pay(token, res.data.id).then(r=>{ + console.log(r) + + if(r.code==700){ + + //标签 + that.print(that.data.dataP) + //小票 + that.print2(that.data.dataP) + + } + + }) // 跳到订单列表 wx.redirectTo({ url: "/pages/all-orders/index" }) } else { - wxpay.wxpay('order', money, res.data.id, "/pages/all-orders/index"); + + console.log("微信支付:") + wxpay.wxpay('order', money, res.data.id, "/pages/all-orders/index",that.data.dataP) + + } }, async getDistance(curAddressData) { @@ -641,4 +696,190 @@ Page({ }) this.createOrder() }, + //打印标签,参数为支付返回的data数据 + print(data){ + var that = this + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/printLabel' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //打印机序列号,店铺id对应打印机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '32817SCU1VAF54B' + }//未来店 + else if (data.shopInfo.id==1){ + sn = '32EL21088705948' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '325Z1VC2ANA044B' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '32EVUCUVY0B4848' + } + + + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = that.getDate() + let content = '' + + for(let i=0;i# '+(i+1) +'/' + data.goodsList.length + ' 总金额:'+data.data.amountReal + ''+ + ''+ data.goodsList[i].name +'' + for(let j=0;j'+ data.goodsList[i].sku[j].optionValueName +'' + } + content+= ''+'单价: ¥'+data.goodsList[i].price + ''+ + ''+ data.data.orderNumber+ ''+ + ''+ timeStr + ''+ + ''+ data.shopInfo.name + '' + '' + + } + } + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("标签打印返回:",res) + } + + + }) + }, + //打印小票,参数为支付返回的data数据 + print2(data){ + var that = this + + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/print' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //打印机序列号,店铺id对应打印机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '74Y4LWMD9R9AF4B' + } + //未来店 + else if (data.shopInfo.id==1){ + sn = '742N30GDRND8E4A' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '74S8LPEQ3584048' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '744905VQE26ED4A' + } + + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = that.getDate() + let content = '9.8 COFFEE


' +'
' + data.goodsList[i].price + '元
' + + for(let i=0;i' + data.goodsList[i].number +'' + content+='|' + for(let j=0;j
' + + content+= '下单时间: '+ timeStr + '
'+ + '订单编号: '+ data.data.orderNumber + '
' + + '用户电话: '+ data.mobile + '
' + if(data.peisongType =='pszq'){ + content+= '用户地址: '+ data.address + '
' + } + // if(that.data.peisongType=='zq'){ + // content+= ' 取单号: '+that.data.curAddressData.address + '
' + // } + content+= '门店名称: ' + data.shopInfo.name +'
'+ + '备注: ' + data.remark +'
' + content+= '
' + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("小票打印返回:",res) + } + + + }) + }, + //获取当前年月日时分秒,打印时间 + getDate(){ + var now = new Date(); +var year = now.getFullYear(); // 年 +var month = now.getMonth() + 1; // 月 +var day = now.getDate(); // 日 +var hour = now.getHours(); // 时 +var minute = now.getMinutes(); // 分 +var second = now.getSeconds(); // 秒 + +// 格式化输出 +var timeString = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second); + return timeString + + } }) \ No newline at end of file diff --git a/pages/pay/index.wxml b/pages/pay/index.wxml index d70cecf..da700a0 100644 --- a/pages/pay/index.wxml +++ b/pages/pay/index.wxml @@ -5,14 +5,14 @@ {{ $t.index.pickup }} - - + + {{ $t.index.Delivery }} - + {{ $t.pay.Addaddress }} @@ -98,10 +98,10 @@ wx:if="{{ nick && avatarUrl }}" price="{{ amountReal*100 }}" label="{{ $t.PickingUp.total }}" - button-text="{{peisongType == 'kd' && amountReal < shopInfo.serviceAmountMin ? ('¥' + shopInfo.serviceAmountMin + $t.pay.qisong) : $t.order.toPayTap }}" + button-text="{{peisongType == 'pszq' && amountReal < shopInfo.serviceAmountMin ? ('¥' + shopInfo.serviceAmountMin + $t.pay.qisong) : $t.order.toPayTap }}" bind:submit="goCreateOrder" button-class="pay-btn" - disabled="{{(peisongType == 'kd' && amountReal < shopInfo.serviceAmountMin) || submitLoding }}" + disabled="{{(peisongType == 'pszq' && amountReal < shopInfo.serviceAmountMin) || submitLoding }}" /> { @@ -33,27 +35,45 @@ Page({ this.fetchShops(res.latitude, res.longitude, '') }, fail(e){ - console.error(e) - AUTH.checkAndAuthorize('scope.userLocation') + // 定位失败时也获取店铺列表,但不传入位置参数 + this.fetchShops(null, null, '') } }) }, async fetchShops(latitude, longitude, kw){ - const res = await WXAPI.fetchShops({ - curlatitude: latitude, - curlongitude: longitude, - nameLike: kw - }) - if (res.code == 0) { - res.data.forEach(ele => { - ele.distance = ele.distance.toFixed(1) // 距离保留3位小数 - }) - this.setData({ - shops: res.data - }) - } else { - this.setData({ - shops: null + const params = { + nameLike: kw || '' + } + // 如果有位置信息,添加到请求参数中 + if (latitude && longitude) { + params.curlatitude = latitude + params.curlongitude = longitude + } + try { + const res = await WXAPI.fetchShops(params) + if (res.code == 0) { + if (latitude && longitude) { + res.data.forEach(ele => { + ele.distance = ele.distance.toFixed(1) + }) + } else { + res.data.forEach(ele => { + ele.distance = '-' + }) + } + this.setData({ + shops: res.data + }) + } else { + this.setData({ + shops: null + }) + } + } catch (error) { + console.error('获取店铺列表失败:', error) + wx.showToast({ + title: '获取店铺列表失败', + icon: 'none' }) } }, diff --git a/project.config.json b/project.config.json index 5093020..284d797 100644 --- a/project.config.json +++ b/project.config.json @@ -37,7 +37,11 @@ "lazyloadPlaceholderEnable": false, "useStaticServer": true, "ignoreUploadUnusedFiles": true, - "condition": false + "condition": false, + "compileWorklet": false, + "localPlugins": false, + "swc": false, + "disableSWC": true }, "compileType": "miniprogram", "simulatorType": "wechat", @@ -61,9 +65,10 @@ "tabIndent": "insertSpaces", "tabSize": 2 }, - "appid": "wxeae6fe143af7d025", + "appid": "wxf9be667c59929008", "packOptions": { "ignore": [], "include": [] - } + }, + "libVersion": "3.4.10" } \ No newline at end of file diff --git a/project.private.config.json b/project.private.config.json index 7c9dedc..609fd9d 100644 --- a/project.private.config.json +++ b/project.private.config.json @@ -1,7 +1,22 @@ { "setting": { "compileHotReLoad": true, - "urlCheck": false + "urlCheck": false, + "coverView": true, + "lazyloadPlaceholderEnable": false, + "skylineRenderEnable": false, + "preloadBackgroundData": false, + "autoAudits": false, + "useApiHook": true, + "useApiHostProcess": true, + "showShadowRootInWxmlPanel": true, + "useStaticServer": true, + "useLanDebug": false, + "showES6CompileOption": false, + "checkInvalidKey": true, + "ignoreDevUnusedFiles": true, + "bigPackageSizeSupport": false, + "useIsolateContext": false }, "condition": { "miniprogram": { @@ -307,7 +322,7 @@ ] } }, - "projectname": "%E5%B0%8F%E8%9C%9C%E8%9C%82%E7%82%B9%E9%A4%90", + "projectname": "bee-gitee", "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html", "libVersion": "3.4.10" } \ No newline at end of file diff --git a/utils/pay.js b/utils/pay.js index 0e63222..5e6189c 100644 --- a/utils/pay.js +++ b/utils/pay.js @@ -1,6 +1,7 @@ const WXAPI = require('apifm-wxapi') const i18n = require("../i18n/index") const $t = i18n.$t() +var util = require('../utils/util.js') /** * type: order 支付订单 recharge 充值 paybill 优惠买单 @@ -52,6 +53,15 @@ function wxpay(type, money, orderId, redirectUrl, data) { } }, success: function () { + //打印 + if(data &&data.isPrint ==true){ + //打印标签 + print(data) + //打印小票 + print2(data) + } + + // 提示支付成功 wx.showToast({ title: $t.asset.success @@ -74,6 +84,192 @@ function wxpay(type, money, orderId, redirectUrl, data) { }) } + //打印标签,参数为支付返回的data数据 + function print(data){ + + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/printLabel' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //打印机序列号,店铺id对应打印机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '32817SCU1VAF54B' + }//未来店 + else if (data.shopInfo.id==1){ + sn = '32EL21088705948' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '325Z1VC2ANA044B' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '32EVUCUVY0B4848' + } + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = getDate() + let content = '' + + for(let i=0;i# '+(i+1) +'/' + data.goodsList.length + ' 总金额:'+data.data.amountReal + ''+ + ''+ data.goodsList[i].name +'' + for(let j=0;j'+ data.goodsList[i].sku[j].optionValueName +'' + } + content+= ''+'单价: ¥'+data.goodsList[i].price + ''+ + ''+ data.data.orderNumber+ ''+ + ''+ timeStr + ''+ + ''+ data.shopInfo.name + '' + '' + + } + } + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("标签打印返回:",res) + } + + + }) + } + //打印小票,参数为支付返回的data数据 + function print2(data){ + + + //芯烨云打印接口 + let url = 'https://open.xpyun.net/api/openapi/xprinter/print' + //开发者密钥 + let userKey = 'b2e9014204774a058bc7e8640e36e8ed' + //开发者id xu1271669848@gmail.com + let userId = 'xu1271669848@gmail.com' + let timstamp = Math.trunc(new Date().getTime()/1000) + "" + let sign = userId + userKey + timstamp + //打印机序列号,店铺id对应打印机序列号 + let sn = '' + //紫金店 + if(data.shopInfo.id==2){ + sn = '74Y4LWMD9R9AF4B' + } + //未来店 + else if (data.shopInfo.id==1){ + sn = '742N30GDRND8E4A' + } + //塘下店 + else if (data.shopInfo.id==4){ + sn = '74S8LPEQ3584048' + } + //瑞安店 + else if (data.shopInfo.id==3){ + sn = '744905VQE26ED4A' + } + //如果没有打印机,则返回 + if(!sn){ + return + } + //当前日期 时分秒 + let timeStr = getDate() + let content = '9.8 COFFEE


' +'
' + data.goodsList[i].price + '元
' + + for(let i=0;i' + data.goodsList[i].number +'' + content+='|' + for(let j=0;j
' + + content+= '下单时间: '+ timeStr + '
'+ + '订单编号: '+ data.data.orderNumber + '
' + + '用户电话: '+ data.mobile + '
' + if(data.peisongType =='pszq'){ + content+= '用户地址: '+ data.address + '
' + } + // if(that.data.peisongType=='zq'){ + // content+= ' 取单号: '+that.data.curAddressData.address + '
' + // } + content+= '门店名称: ' + data.shopInfo.name +'
'+ + '备注: ' + data.remark +'
' + content+= '
' + + + //请求参数 + let param = { + user: userId, + timestamp: timstamp, + sign: util.sha1(sign), + sn: sn, + content: content + } + console.log(param) + + let header = { + "Content-Type": "application/json;charset=UTF-8" + } + + wx.request({ + url: url, + data: param, + method: "post", + header:header, + success: res=>{ + console.log("小票打印返回:",res) + } + + + }) + } + //获取当前年月日时分秒,打印时间 + function getDate(){ + var now = new Date(); +var year = now.getFullYear(); // 年 +var month = now.getMonth() + 1; // 月 +var day = now.getDate(); // 日 +var hour = now.getHours(); // 时 +var minute = now.getMinutes(); // 分 +var second = now.getSeconds(); // 秒 + +// 格式化输出 +var timeString = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second); +return timeString + +} + + + module.exports = { wxpay: wxpay } \ No newline at end of file diff --git a/utils/time.wxs b/utils/time.wxs new file mode 100644 index 0000000..4432081 --- /dev/null +++ b/utils/time.wxs @@ -0,0 +1,61 @@ +var filter = { + formatNumber: function (n) { + n = n.toString() + return n[1] ? n : '0' + n + }, + //写法一: + parseTime: function (time, type) { + if (time == null || type == '') { + return '' + } + if (arguments.length === 0) { + return null + } + var date = getDate(time);//在wxs中不能使用new Date()来处理日期 + var y = date.getFullYear(); + var m = filter.formatNumber(date.getMonth() + 1); + var d = filter.formatNumber(date.getDate()); + var h = filter.formatNumber(date.getHours()); + var i = filter.formatNumber(date.getMinutes()); + var s = filter.formatNumber(date.getSeconds()); + var a = filter.formatNumber(date.getDay()); + var time_str = ""; + if (type == 'month') { + time_str = y + '-' + m; + } else if (type == 'date') { + time_str = y + '-' + m + '-' + d; + } else if (type == 'datetime') { + time_str = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s; + } else if (type == 'onlyMonth') { + time_str = m; + } else if (type == 'onlyYear') { + time_str = y; + } + return time_str + }, + //写法二: + //用法 {{filters.formatDate(current,'Y-M-D h:m:s')}} + parseTime2: function (time, format) { + if (time == null || format == '' || time == "" || time == undefined) { + return '' + } + if (arguments.length === 0) { + return null + } + var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'], arr = [], date = getDate(time); + arr.push(date.getFullYear());//Y + arr.push(filter.formatNumber(date.getMonth() + 1));//M + arr.push(filter.formatNumber(date.getDate()));//D + arr.push(filter.formatNumber(date.getHours()));//h + arr.push(filter.formatNumber(date.getMinutes()));//m + arr.push(filter.formatNumber(date.getSeconds()));//s + for (var i = 0; i < arr.length; i++) { + format = format.replace(formateArr[i], arr[i]) + } + return format + }, +} +module.exports = { + parseTime: filter.parseTime, + formatNumber: filter.formatNumber +} \ No newline at end of file diff --git a/utils/util.js b/utils/util.js index dbadbb8..c32cf4a 100644 --- a/utils/util.js +++ b/utils/util.js @@ -14,6 +14,59 @@ const formatNumber = n => { return n[1] ? n : '0' + n } + +function encodeUTF8(s) { + var i, r = [], c, x; + for (i = 0; i < s.length; i++) + if ((c = s.charCodeAt(i)) < 0x80) r.push(c); + else if (c < 0x800) r.push(0xC0 + (c >> 6 & 0x1F), 0x80 + (c & 0x3F)); + else { + if ((x = c ^ 0xD800) >> 10 == 0) //对四字节UTF-16转换为Unicode + c = (x << 10) + (s.charCodeAt(++i) ^ 0xDC00) + 0x10000, + r.push(0xF0 + (c >> 18 & 0x7), 0x80 + (c >> 12 & 0x3F)); + else r.push(0xE0 + (c >> 12 & 0xF)); + r.push(0x80 + (c >> 6 & 0x3F), 0x80 + (c & 0x3F)); + }; + return r; +}; + +// 字符串加密成 hex 字符串,芯烨云打印加密 +function sha1(s) { + var data = new Uint8Array(encodeUTF8(s)) + var i, j, t; + var l = ((data.length + 8) >>> 6 << 4) + 16, s = new Uint8Array(l << 2); + s.set(new Uint8Array(data.buffer)), s = new Uint32Array(s.buffer); + for (t = new DataView(s.buffer), i = 0; i < l; i++)s[i] = t.getUint32(i << 2); + s[data.length >> 2] |= 0x80 << (24 - (data.length & 3) * 8); + s[l - 1] = data.length << 3; + var w = [], f = [ + function () { return m[1] & m[2] | ~m[1] & m[3]; }, + function () { return m[1] ^ m[2] ^ m[3]; }, + function () { return m[1] & m[2] | m[1] & m[3] | m[2] & m[3]; }, + function () { return m[1] ^ m[2] ^ m[3]; } + ], rol = function (n, c) { return n << c | n >>> (32 - c); }, + k = [1518500249, 1859775393, -1894007588, -899497514], + m = [1732584193, -271733879, null, null, -1009589776]; + m[2] = ~m[0], m[3] = ~m[1]; + for (i = 0; i < s.length; i += 16) { + var o = m.slice(0); + for (j = 0; j < 80; j++) + w[j] = j < 16 ? s[i + j] : rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1), + t = rol(m[0], 5) + f[j / 20 | 0]() + m[4] + w[j] + k[j / 20 | 0] | 0, + m[1] = rol(m[1], 30), m.pop(), m.unshift(t); + for (j = 0; j < 5; j++)m[j] = m[j] + o[j] | 0; + }; + t = new DataView(new Uint32Array(m).buffer); + for (var i = 0; i < 5; i++)m[i] = t.getUint32(i << 2); + + var hex = Array.prototype.map.call(new Uint8Array(new Uint32Array(m).buffer), function (e) { + return (e < 16 ? "0" : "") + e.toString(16); + }).join(""); + + return hex; +}; + module.exports = { - formatTime: formatTime -} + formatTime: formatTime, + sha1:sha1 +} \ No newline at end of file
' + data.goodsList[i].price + '元