石广澎
2024-11-04 90169550c9f6836e715360b3fc2163e159432814
feat(支付): 增加校验经纬度功能,暂时先关闭
3个文件已修改
84 ■■■■ 已修改文件
common/config.js 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
manifest.json 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
pay/scanpay.vue 76 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
common/config.js
@@ -24,8 +24,10 @@
}
module.exports = {
    config: process.env.NODE_ENV === 'development' ? dev : prod,
    config: process.env.NODE_ENV === 'development' ? dev : test,
    ACCESSTOKEN: "Authorization",
    /* 是否打印请求日志 */
    DEBUG: false
    DEBUG: false,
    /* 是否校验位置经纬度 */
    CHECK_LOCATION: false
}
manifest.json
@@ -74,7 +74,7 @@
        "devServer" : {
            "proxy" : {
                "/dev-api" : {
                    "target" : "http://172.16.2.117:8080",
                    "target" : "http://172.16.2.121:8080",
                    "changeOrigin" : true,
                    "secure" : false,
                    "pathRewrite" : {
pay/scanpay.vue
@@ -88,11 +88,11 @@
          </view>
        </view>
      </block>
      <button class="pay-it" @click="pay">付款</button>
      <button class="pay-it" @click="checkLocation">付款</button>
      <view v-if="bordShow" style="height: 470rpx"></view>
      <!-- 数字键盘 -->
      <u-popup zIndex="500" :show="bordShow" :overlay="false" @close="bordShow = false">
        <key-bord @changeMoney="changeMoney" :num.sync="money" @close="bordShow = false" @pay="pay"></key-bord>
        <key-bord @changeMoney="changeMoney" :num.sync="money" @close="bordShow = false" @pay="checkLocation"></key-bord>
      </u-popup>
      <!-- 优惠券弹窗 -->
      <u-popup v-if="payWay==2" mode="bottom" :closeable="true" :show="couponShow" @close="couponShow = false" :round="10">
@@ -153,7 +153,8 @@
<script>
import {
  config,
  ACCESSTOKEN
  ACCESSTOKEN,
  CHECK_LOCATION
} from 'common/config.js';
import {
  queryShopByCid,
@@ -165,8 +166,7 @@
  saveOrder,
} from 'common/api/index'
import wx from 'weixin-js-sdk';
import {accMul, fenToYuan} from 'common/util' // 使用js-sdk
import wx from 'weixin-js-sdk'; // 使用js-sdk
export default {
  data() {
@@ -192,6 +192,8 @@
        useScoreFlag: -1, //商铺是否可用积分 0否 1是
        userCouponFlag: -1, //商铺是否可用优惠券 0否 1是
      },
      lat: '', //纬度
      lng: '', //经度
      money: '', // 金额
      token: null,
      isNew: false, // 是否新用户,新用户查询不到积分和银行卡
@@ -216,7 +218,7 @@
        return 0
      }
      if (this.checkCoupon.discountType == 1) {
        const num = this.$utils.fenToYuan(this.couponInfo.discount)
        const num = this.$utils.fenToYuan(this.checkCoupon.discount)
        return parseFloat(num);
      }
      const dis = 1 - parseFloat(this.checkCoupon.discount)
@@ -425,18 +427,48 @@
            timestamp: res.timestamp, // 必填,生成签名的时间戳
            nonceStr: res.noncestr, // 必填,生成签名的随机串
            signature: res.signature, // 必填,签名
            jsApiList: ['hideAllNonBaseMenuItem'], // 必填,需要使用的JS接口列表
            jsApiList: ['hideAllNonBaseMenuItem','getLocation'], // 必填,需要使用的JS接口列表
            openTagList: ['wx-open-launch-weapp'] //可选,需要使用的开放标签列表
          });
          wx.ready(function () {
          wx.ready( ()=> {
            wx.hideAllNonBaseMenuItem();
            if(CHECK_LOCATION){
              this.wxGetLocation()
            }
          })
        })
      }
    },
    wxGetLocation(callback){
      wx.getLocation({
        type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
        complete:  (res)=> {
          if(res.errMsg==="getLocation:ok"){
            this.lat = parseFloat(res.latitude).toFixed(6); // 纬度,浮点数,范围为90 ~ -90
            this.lng = parseFloat(res.longitude).toFixed(6); // 经度,浮点数,范围为180 ~ -180。
            if(callback) callback()
          }else{
            uni.showModal({
              title: '提示',
              content: "获取地理位置失败,无法进行支付!",
              confirmText: '重新授权',
              cancelText: '退出',
              success: ret=>{
                if(ret.confirm){
                  this.wxGetLocation()
                }else{
                  this.clickDone()
                }
              }
            })
          }
        }
      });
    },
    // 获取会员相关信息
    showCoupon() {
      if (this.UNIONID) {
      if (this.UNIONID||this.payWay==5) {
        if (uni.$u.test.isEmpty(this.money)) {
          uni.$u.toast('请输入金额!')
          return
@@ -450,10 +482,15 @@
    },
    //获取用户优惠券
    queryUseSweepPayCoupon() {
      const applyPayWayStr = {
        2: 1,
        5: 2,
        15: 3
      }
      queryUseSweepPayCoupon({
        params: {
          score: 0,
          applyPayWayStr: this.payWay,
          applyPayWayStr: applyPayWayStr[this.payWay],
          cusid: this.shopInfo.id,
          money: this.$utils.accMul(this.money,100),
        }
@@ -481,6 +518,21 @@
      this.couponInfo = this.checkCoupon;
      this.couponShow = false;
    },
    checkLocation(){
      if(!CHECK_LOCATION){
        this.pay()
        return
      }
      if (uni.$u.test.isEmpty(this.money)) {
        uni.$u.toast('请输入金额!')
        return
      }
      if(!this.lat){
        this.wxGetLocation(this.pay)
      }else{
        this.pay()
      }
    },
    //确认支付
    pay() {
      if (uni.$u.test.isEmpty(this.money)) {
@@ -496,7 +548,9 @@
        payWay: this.payWay,
        buyerNote: this.buyerNote,
        score: 0,
        couponDetailId: this.couponInfo.id
        couponDetailId: this.couponInfo.id,
        lat: this.lat,
        lng: this.lng
      }
      if (this.activityQrcodeId) {
        params.activityQrcodeId = this.activityQrcodeId