Kaynağa Gözat

feat():增加服务开始和结束的按钮

geek 3 yıl önce
ebeveyn
işleme
d84203486c

+ 18 - 0
api/order.js

@@ -70,6 +70,24 @@ class order extends request {
         return res.data
     }
 
+    static async couponList(data) {
+        const res = await this.postRequest(`${this.COUPON_URL}/coupon/kd-sn-list`,data)
+        return res.data
+    }
+
+    static async writeOffCoupon(data) {
+        const res = await this.postRequest(`${this.COUPON_URL}/coupon/kd-coupon-writeOff`,data)
+        return res.data
+    }
+
+    static async writeOffStaff(data) {
+        const res = await this.postRequest(`${this.COUPON_URL}/coupon/kd-staff-auth`,data)
+        return res.data
+    }
+    static async couponInfo(data) {
+        const res = await this.postRequest(`${this.COUPON_URL}/coupon/kd-coupon-sn-info`,data)
+        return res.data
+    }
 }
 
 export default order

+ 1 - 1
api/user.js

@@ -7,7 +7,7 @@ class store extends request{
     // }
 
     static async userLogin(data) {
-        const res = await this.postRequest(`${this.BASE_URL}User/save`, data)
+        const res = await this.postRequest(`${this.COUPON_URL}tiktok/decode-login`, data)
         return res.data;
     }
 

+ 8 - 11
app.js

@@ -35,7 +35,7 @@ App({
       // this.userInfoReadyCallback(res)
     // }
     // if(this.globalData.userInfo){
-      await self.wxLogin({"type":"slince"});
+      // await self.wxLogin({"type":"slince"});
     // }
 
   },
@@ -58,13 +58,9 @@ App({
     data['code'] = res.code
     let info =  await userApi.userLogin(data)
     console.log(info)
-    wx.setStorageSync('token', info.userInfo.token)
-    requestApi.HEAD.token = info.userInfo.token
-    this.setUserInfo(info.userInfo)
-    if (this.checkLoginReadyCallback){
-      this.checkLoginReadyCallback(res);
-   }
-    return info.userInfo
+    wx.setStorageSync('token', "kd")
+    this.setUserInfo(info)
+    return info
   },
   getPhoneNumber: async function(data){
     let _self = this;
@@ -74,10 +70,11 @@ App({
       return
     }
     data['code'] = res.code
-    let info =  await userApi.getMobile(data)
+    data['type'] = 'mobile'
+    let info =  await userApi.userLogin(data)
     console.log(info)
-    _self.setUserInfo(info.userInfo)
-    return info.userInfo;
+    _self.setUserInfo(info)
+    return info;
   },
   setUserInfo: function(userInfo){
     wx.setStorage({

+ 15 - 17
app.json

@@ -1,10 +1,11 @@
 {
   "pages":[
+    "pages/person/person",
+    "pages/couponList/couponList",
     "pages/index/index",
     "pages/comments/comments",
     "pages/commentinfo/commentinfo",
     "pages/product/product",
-    "pages/person/person",
     "pages/personinfo/personinfo",
     "pages/order/order",
     "pages/appointment/appointment",
@@ -15,7 +16,8 @@
     "pages/food/food",
     "pages/foodOrder/foodOrder",
     "pages/recharge/recharge",
-    "pages/payMoney/payMoney"
+    "pages/payMoney/payMoney",
+    "pages/qrCode/qrCode"
 
   ],
   "window":{
@@ -29,24 +31,20 @@
     "color": "#444",
     "selectedColor": "#1296db",
     "backgroundColor": "#ffffff",
-    "list": [{
-      "pagePath": "pages/index/index",
-      "text": "首页",
-      "iconPath": "images/icons/index.png",
-      "selectedIconPath": "images/icons/index-active.png"
-    },
+    "list": [
+      {
+        "pagePath": "pages/person/person",
+        "text": "我的",
+        "iconPath": "images/icons/person.png",
+        "selectedIconPath": "images/icons/person-active.png"
+      },
     {
-      "pagePath": "pages/personorder/personorder",
-      "text": "订单",
+      "pagePath": "pages/couponList/couponList",
+      "text": "券包",
       "iconPath": "images/icons/order.png",
       "selectedIconPath": "images/icons/order-active.png"
-    },
-    {
-      "pagePath": "pages/person/person",
-      "text": "我的",
-      "iconPath": "images/icons/person.png",
-      "selectedIconPath": "images/icons/person-active.png"
-    }]
+    }
+    ]
   },
   "style": "v2",
   "sitemapLocation": "sitemap.json",

+ 147 - 0
pages/couponList/couponList.js

@@ -0,0 +1,147 @@
+// pages/orderDetail/orderDetail.js
+const app = getApp()
+import Order from '../../api/order'
+
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    nextPage: 1,
+    companyName: "康道"
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: async function (options) {
+    
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: async function () {
+    await app.wxLogin({"type":"slince"})
+    const userInfo = await app.getWxUserInfo()
+    this.setData({
+      userInfo
+    })
+    if (!userInfo.mobile) {
+      return
+    }
+    await this.couponList('init')
+  },
+  async couponList(type) {
+    const self = this
+    if (type === "init") {
+      self.setData({
+        nextPage: 1
+      })
+    }
+    const data = {
+      phone: this.data.userInfo.mobile,
+      nextPage: self.data.nextPage,
+      pageSize: 10
+    }
+    const rs = await Order.couponList(data)
+    if (type == "pull") {
+      const data = self.data.list.concat(rs.records)
+      self.setData({
+        list: data,
+        maxPage: rs.totalPage
+      })
+    }else {
+      self.setData({
+        list: rs.records,
+        // list: [],
+        maxPage: rs.totalPage
+      })
+    } 
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+    let page = this.data.nextPage
+    let maxPage = this.data.maxPage
+    if (page >= maxPage) {
+      wx.showToast({
+        title: '亲,到底了哦!', // 内容
+      });
+      return
+    }
+    this.setData({
+      nextPage: page + 1
+    })
+    this.couponList('pull')
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  },
+  jumpBuy (e) {
+    const sn = e.currentTarget.dataset.sn
+    const name = e.currentTarget.dataset.name
+    const status = e.currentTarget.dataset.status
+    if (status == 2 || status == 3) {
+      return
+    }
+    wx.navigateTo({
+      url: `/pages/qrCode/qrCode?sn=${sn}&name=${name}`,
+    })
+  },
+  getMobile: async function (params) {
+    console.log(params);
+    let _self = this
+    const data = {
+      encryptedData:params.detail.encryptedData,
+      iv: params.detail.iv
+    }
+    const userInfo = await app.getPhoneNumber(data)
+    console.log(userInfo)
+    let hasMobile = false
+    if (userInfo.mobile > 1) {
+      hasMobile:true
+    }
+    _self.setData({
+      hasMobile: hasMobile,
+      mobile: userInfo.mobile,
+      userInfo
+    })
+    _self.couponList('init')
+  },
+})

+ 4 - 0
pages/couponList/couponList.json

@@ -0,0 +1,4 @@
+{
+  "usingComponents": {},
+  "navigationBarTitleText": "优惠券列表"
+}

+ 46 - 0
pages/couponList/couponList.wxml

@@ -0,0 +1,46 @@
+<view class="container" wx:if="{{!userInfo.mobile}}">
+    <view class="logo">
+        <image class="logo-img" src="../../images/logo.jpg"  >
+        </image>
+        <view class="info ">{{companyName}}</view>
+    </view>
+    <view class="desc">
+        <view class="text-h f16">为提供更优质的服务,{{companyName}}需要获取以下信息:</view>
+        <view class="text-f ">你的手机号信息</view>
+    </view>
+    <view class="confirm">
+      <button open-type="getPhoneNumber" catchgetphonenumber="getMobile" type="primary" >获取手机号</button>
+        <!-- <button open-type="getUserInfo" bindgetuserinfo="getInfo" type="primary">确认</button> -->
+    </view>
+</view>
+
+<view class="cash" wx:if="{{userInfo.mobile && list.length !=0 }}">
+  <view class="coupon-list {{item['status'] == 1 ?'':'gray'}}" wx:for="{{list}}">
+    <view class="coupon-img cash-img">
+      <view class="cash-img-left">
+        <view class="cil-1">{{item['reduceMoney']}}元</view>
+        <view class="cil-2">代金券</view>
+      </view>
+      <view class="coupon-center">
+        <view class="coupon-center-name">{{item['reduceMoney'] == 0 ? '无门槛优惠券': item['couponName']}}</view>
+        <view class="coupon-center-date">{{item['isAll'] == 'yes' ? ' 全国通用': item['storeName']+'门店使用'}}</view>
+      </view>
+      <view class="cash-img-right" data-sn="{{item['couponSn']}}" data-status="{{item['status']}}" data-name="{{item['couponName']}}" bindtap="jumpBuy">
+      {{item['status'] == 1?'立即使用': item['status'] ==2 ? '已经核销' : 
+      '已经作废'}}
+      </view>
+    </view>
+    <!-- <view class="coupon-img discount-img">
+      <view class="cash-img-left">
+        <view class="cil-1">¥</view>
+        <view class="cil-2">10</view>
+      </view>
+      <view class="cil-3">lsjfsalk </view>
+      <view class="cash-img-right">立即使用</view>
+    </view> --> 
+  </view> 
+</view>
+<view class="discuss-info" wx:if="{{list.length ==0 }}">
+  <image style="height: 400rpx;width: 400rpx;" src="../../images/no-discuss.png"></image>
+  <view class="discuss">暂无优惠券</view>
+</view>

+ 172 - 0
pages/couponList/couponList.wxss

@@ -0,0 +1,172 @@
+page{
+  background-color: #F8F8F8;
+}
+
+.container .logo {
+  height: 400rpx;
+  position: relative;
+}
+
+.container .logo > .logo-img {
+  width: 200rpx;
+  height: 200rpx;
+  border-radius: 50%;
+  position: absolute;
+  bottom: 100rpx;
+  left: 50%;
+  transform: translateX(-50%);
+}
+
+.container .logo > .info {
+  width: 100%;
+  height: 50rpx;
+  text-align: center;
+  letter-spacing: 3rpx;
+  position: absolute;
+  bottom: 10rpx;
+  font-size: 22px;
+}
+
+.container .desc {
+  width: 90%;
+  margin: 50rpx auto;
+}
+
+.container .desc .text-h {
+  height: 50rpx;
+  padding: 0 20rpx 20rpx 20rpx;
+}
+
+.container .desc .text-f {
+  padding: 0 50rpx;
+  color: #999;
+  font-size: 13px;
+  position: relative;
+}
+
+.container .desc .text-f::before {
+  content: "";
+  width: 6rpx;
+  height: 6rpx;
+  background-color: #999;
+  position: absolute;
+  top: 15rpx;
+  left: 25rpx;
+  border-radius: 50%;
+}
+
+.container .confirm {
+  width: 80%;
+  margin: 80rpx auto;
+}
+
+.container .confirm > button {
+  width: 100%;
+  font-weight: 400;
+}
+
+
+.cash{
+  padding: 10px 10px;
+  box-sizing: border-box;
+  background-color:#fff;
+  margin-top: 14px;
+}
+.cash-img{
+  background-image: url("https://dy.shpr.top/xcxActivity/activityList_orange.png");
+}
+
+.discount-img{
+  background-image: url("https://dy.shpr.top/xcxActivity/activityList_skyblue.png");
+}
+.coupon-list {
+
+}
+.gray {
+  filter: grayscale(100%);
+}
+
+.discuss {
+  position: relative;
+  /* bottom: 100rpx; */
+  font-size: 38rpx;
+  color: #9E9E9E;
+  letter-spacing: 5rpx;
+}
+
+.discuss-info {
+  text-align: center;
+  position: absolute;
+  top: 13%;
+  left: 22%;
+}
+
+.coupon-img{
+  width: 100%;
+  height: 105px;
+  background-repeat: no-repeat;
+  background-size: 100% 100%;
+  -moz-background-size: 100% 100%;
+  color: #fff;
+  display: flex;
+  flex-flow: row nowrap;
+  justify-content: space-between;
+  margin-bottom: 20px;
+
+}
+
+
+.discount{
+  padding: 10px 10px;
+  box-sizing: border-box;
+  background-color:#fff;
+  margin-top: 14px;
+}
+
+.cash-img-left{
+  display: flex;
+  flex-direction: column;
+  /* flex-flow: row nowrap; */
+  justify-content: center;
+  align-items: center;
+  width: 220px;
+  
+}
+.cil-1{
+/* align-self: flex-start; */
+/* margin-left: 18px; */
+/* margin-top: 25px; */
+font-size: 18px;
+font-weight: bold;
+}
+.cil-2{
+  /* align-self: flex-start; */
+  /* margin-left: 2px; */
+  /* margin-top: 8px; */
+  font-size: 30px;
+  font-weight: bold;
+  }
+.coupon-center{
+  margin-left: 9px;
+  width: 360px;
+  display: flex;
+  flex-flow: column nowrap;
+  justify-content: center;
+}
+.coupon-center-date{
+height: 25px;
+font-size: 15rpx;
+font-weight: 400;
+line-height: 25px;
+color: #FFFFFF;
+}
+.cash-img-right{
+  width: 15px;
+  height: 70px;
+  font-size: 15px;
+  font-weight: 400;
+  line-height: 18px;
+  color: #FFFFFF;
+  margin:auto 0px;
+  margin-right: 29px;
+}

+ 2 - 2
pages/index/index.wxml

@@ -50,7 +50,7 @@
     <!-- </view>
     </block> -->
   </view>
-  <view  class="orderFood" bindtap="goSmdd" wx:if="isShowFood">
+  <!-- <view  class="orderFood" bindtap="goSmdd" wx:if="isShowFood">
     <image src='/images/canju.png'></image>
-  </view>
+  </view> -->
 </view>

+ 66 - 29
pages/person/person.js

@@ -1,28 +1,21 @@
 // pages/person/person.js
 const app = getApp()
+import Order from '../../api/order'
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
-    hasUserInfo: false
+    hasUserInfo: false,
+    canWriteOff: 'no'
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: async function (options) {
-    let userInfo = await app.getWxUserInfo()
-    if (userInfo) {
-
-      this.setData({
-        userInfo: userInfo,
-        hasUserInfo: userInfo.avatar.length > 1 ? true :false,
-        hasMobile: userInfo.mobile ? true : false
-      })
-    }
+    
   },
   /**
    * 生命周期函数--监听页面初次渲染完成
@@ -35,15 +28,25 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: async function () {
+    await app.wxLogin({"type":"slince"})
     let userInfo = await app.getWxUserInfo()
+
     if (userInfo) {
       console.log(userInfo)
       this.setData({
         userInfo: userInfo,
-        hasUserInfo: userInfo.avatar.length > 1 ? true :false,
+        hasUserInfo: userInfo.avatarUrl.length > 1 ? true :false,
         hasMobile: userInfo.mobile ? true : false
       })
     }
+    if (userInfo.mobile) {
+      const rs = await Order.writeOffStaff({phone: userInfo.mobile})
+      this.setData({
+        canWriteOff: rs.canWriteOff
+      })
+    }
+  
+    
   },
 
   /**
@@ -80,21 +83,33 @@ Page({
   onShareAppMessage: function () {
 
   },
-  getInfo: async function (e) {
+  getInfo: async function () {
     const _self = this
-    let userInfo = e.detail.userInfo
-    userInfo['encryptedData'] = e.detail.encryptedData
-    userInfo['iv'] = e.detail.iv
-    let info = await app.wxLogin(userInfo);
-    let hasMobile = false;
-    if (info.mobile) {
-      hasMobile = true
-    }
-    _self.setData({
-      hasUserInfo: true,
-      userInfo: info,
-      hasMobile: hasMobile,
+    // let userInfo = e.detail.userInfo
+    // userInfo['encryptedData'] = e.detail.encryptedData
+    // userInfo['iv'] = e.detail.iv
+    let userInfo = {}
+    userInfo['type'] = 'userInfo'
+    userInfo['openId'] = this.data.userInfo.openId
+    wx.getUserProfile({
+      desc: '用于完善会员资料',
+      success: async (res) =>{
+        console.log(res)
+        userInfo['encryptedData'] = res.encryptedData
+        userInfo['iv'] = res.iv
+        let info = await app.wxLogin(userInfo);
+        let hasMobile = false;
+        if (info.mobile) {
+          hasMobile = true
+        }
+        _self.setData({
+          hasUserInfo: true,
+          userInfo: info,
+          hasMobile: hasMobile,
+        })
+      }
     })
+    
   },
   gotoComment: async function (e) {
     console.log(this)
@@ -116,7 +131,7 @@ Page({
   },
   gotoOrder: function (e) {
     wx.switchTab({
-      url: '../personorder/personorder',
+      url: '../couponList/couponList',
     })
   },
   getMobile: async function (params) {
@@ -138,9 +153,31 @@ Page({
       userInfo
     })
   },
-  gotoMoney() {
-    wx.navigateTo({
-      url: '/pages/recharge/recharge',
+  async gotoMoney() {
+    const self = this
+    const rs = await wx.scanCode({onlyFromCamera: true, scanType: ['qrCode']})
+    const couponInfo = await Order.couponInfo({couponSn: rs.result})
+    console.log(couponInfo)
+    wx.showModal({
+      title: "提示",
+      content: '你确定要核销 '+couponInfo['couponName']+' 的优惠券吗?',
+      success:async (res) =>{
+        if (res.confirm) {
+          const data = {
+            heXiaoPhone: self.data.userInfo.mobile,
+            couponSn: rs.result,
+            errMsg: 'modal'
+          }
+          const writeOff = await Order.writeOffCoupon(data)
+          console.log(writeOff)
+          wx.showModal({
+            title: "提示",
+            content: "核销成功"
+          })
+        }
+      }
     })
+    
+    
   }
 })

+ 1 - 1
pages/person/person.json

@@ -2,7 +2,7 @@
   "usingComponents": {},
   "navigationBarBackgroundColor": "#fff",
   "navigationBarTextStyle": "black",
-  "navigationBarTitleText": "个人",
+  "navigationBarTitleText": "个人中心",
   "backgroundColor": "#fff",
   "backgroundTextStyle": "light"
 }

+ 7 - 7
pages/person/person.wxml

@@ -3,17 +3,17 @@
     <view class="person card" wx:if="{{hasUserInfo}}" >
         <view class="person-info">
             <view class="user-name f18 c-202020" bindtap = "gotoPersonInfo">
-                {{userInfo.name}}
+                {{userInfo.nickName}}
                 <!-- <open-data type="userNickName"></open-data> -->
                 <image class="next" src="../../images/icons/next.png" >
                 </image>
             </view>
             <view class="tel c-707070 fw300">{{userInfo.mobile}}</view>
-            <view> 余额:{{userInfo.money}}</view>
+            <!-- <view> 余额:{{userInfo.money}}</view> -->
             <button open-type="getPhoneNumber" catchgetphonenumber="getMobile" class="login-btn" wx:if="{{!userInfo.mobile}}" >获取手机号</button>
         </view>
         <view class="head-img">
-            <image class="" src="{{userInfo.avatar}}">
+            <image class="" src="{{userInfo.avatarUrl}}">
             </image>
             <!-- <open-data type="userAvatarUrl"></open-data> -->
         </view>
@@ -21,7 +21,7 @@
     <view wx:else class="user-login">
         <view class="person-info">
             <view class="user-name f18 c-202020">
-                <button open-type="getUserInfo" bindgetuserinfo="getInfo" class="login-btn"
+                <button bindtap="getInfo" class="login-btn"
             style="height: 100px;width: 200px;">请点击登录</button>
                 <image class="next" src="../../images/icons/next.png">
                 </image>
@@ -35,7 +35,7 @@
     <view class="order" bindtap = "gotoOrder">
         <image class="icons" src="../../images/icons/order.png">
         </image>
-        <view class="order-text">我的订单
+        <view class="order-text">我的优惠券
         </view>
         <image class="next-gray" src="../../images/icons/next-gray.png">
         </image>
@@ -48,9 +48,9 @@
         </image>
     </view> -->
 
-    <view class="assess" bindtap = "gotoMoney">
+    <view class="assess" bindtap = "gotoMoney" wx:if="{{canWriteOff == 'yes'}}">
         <image class="icons" src="../../images/recharge.png" style="margin: 32rpx 0 0 7rpx;width: 97rpx;"></image>
-        <view class="assess-text">充值
+        <view class="assess-text">核销
         </view>
         <image class="next-gray" src="../../images/icons/next-gray.png">
         </image>

+ 0 - 2
pages/prompt/prompt.wxml

@@ -2,14 +2,12 @@
 <view class="container">
     <view class="logo">
         <image class="logo-img" src="../../images/logo.jpg"  >
-            
         </image>
         <view class="info ">{{companyName}}</view>
     </view>
     <view class="desc">
         <view class="text-h f16">为提供更优质的服务,{{companyName}}需要获取以下信息:</view>
         <view class="text-f ">
-            
             你的公开信息(昵称,头像等)</view>
     </view>
     <view class="confirm">

+ 79 - 0
pages/qrCode/qrCode.js

@@ -0,0 +1,79 @@
+// pages/qrCode/qrCode.js
+import drawQrcodeApi from '../../utils/weapp.qrcode'
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    const sn = options.sn
+    const name = options.name
+    this.setData({
+      name: name
+    })
+    this.drawCode(sn)
+  },
+  drawCode: function (code) {
+    drawQrcodeApi({
+      width: 200,
+      height: 200,
+      canvasId: 'qrCode',
+      text: code,
+    })
+  },
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
pages/qrCode/qrCode.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 7 - 0
pages/qrCode/qrCode.wxml

@@ -0,0 +1,7 @@
+<view class="qrcode">
+    <view class="txt-top">{{name}}</view>
+    <canvas class="canvas-code" canvas-id="qrCode" style="width:210px;height:210px;" />
+    <view class="txt">请在门店识别使用</view>
+
+</view>
+

+ 29 - 0
pages/qrCode/qrCode.wxss

@@ -0,0 +1,29 @@
+.canvas-code {
+  background-color: #fff;
+  /* margin-left: 165rpx; */
+}
+
+.qrcode {
+    margin-top: 200rpx;
+    display: flex;
+    justify-content: center;
+    width: 100%;
+    flex-direction: column;
+    align-items: center;
+}
+
+.txt {
+    text-align: center;
+    color: #BF2637;
+    width: 100%;
+    position: absolute;
+    top: 321px;
+}
+
+.txt-top {
+  text-align: center;
+  color: #BF2637;
+  width: 100%;
+  position: absolute;
+  top: 73px;
+}

+ 5 - 4
project.config.json

@@ -35,14 +35,15 @@
       "outputPath": ""
     },
     "enableEngineNative": false,
-    "bundle": false,
     "useIsolateContext": true,
-    "useCompilerModule": true,
-    "userConfirmedUseCompilerModuleSwitch": false,
     "userConfirmedBundleSwitch": false,
     "packNpmManually": false,
     "packNpmRelationList": [],
-    "minifyWXSS": false
+    "minifyWXSS": false,
+    "disableUseStrict": false,
+    "minifyWXML": true,
+    "showES6CompileOption": false,
+    "useCompilerPlugins": false
   },
   "compileType": "miniprogram",
   "libVersion": "2.16.0",

+ 6 - 0
project.private.config.json

@@ -71,6 +71,12 @@
           "pathName": "pages/payMoney/payMoney",
           "query": "",
           "scene": null
+        },
+        {
+          "name": "pages/couponList/couponList",
+          "pathName": "pages/couponList/couponList",
+          "query": "",
+          "scene": null
         }
       ]
     }

+ 30 - 7
utils/request.js

@@ -1,7 +1,10 @@
 
+import {randomString, sha1} from "./util"
 class request {
 
-    static BASE_URL = 'https://llzlovesh.top/api/'
+    // static BASE_URL = 'http://127.0.0.1:8014/open/'
+    static BASE_URL = 'https://kd.llzlovesh.top/open/'
+    static COUPON_URL = this.BASE_URL
     static HEAD = {
         "Content-Type": "application/json",
         "defaultToken": 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2MTY5MDg3NjAsImV4cCI6MjQ4MDgyMjM2MCwidXNlcklkIjoxMjM0NTY3ODksInZpc2l0b3IiOiJ2aXNpdG9yNjA2MDExZDg4NTQwYyIsImlzQWRtaW4iOjAsImFkbWluSWQiOjB9.7XrRxA3WYMBlqJWIXEw-71AxOxQvCc4VVVN6rlqn3uc',
@@ -87,7 +90,7 @@ class request {
                 formData: ortherData,
                 success: (res => {
                     res.data = JSON.parse(res.data);
-                    if (res.data.code === 1) {
+                    if (res.data.code === 1 || res.data.code == 200) {
                         //200: 服务端业务处理正常结束
                         resolve(res.data)
                     } else {
@@ -125,6 +128,18 @@ class request {
      */
     static requestAll(url, data, header, method) {
         const _self = this
+        const timestamp = parseInt(new Date().getTime()/1000)
+        const nonce = randomString(16)
+        const msg = ''
+        const token = 'U6Watb875eCiX4Lq'
+        const strArr = timestamp + nonce + msg + token
+        const encodeStr = sha1(strArr)
+        header['NONCE'] = nonce
+        header['msg'] = msg
+        header['TIMESTAMP'] = timestamp
+        header['SIGN'] = encodeStr
+        header['VERSION'] = '1.8.0'
+        data['errMsg'] = data['errMsg'] ? 'modal' :'toast' 
         wx.showLoading()
         return new Promise((resolve, reject) => {
             wx.request({
@@ -134,14 +149,22 @@ class request {
                 method: method,
                 success: (res => {
                     wx.hideLoading()
-                    if (res.data.code === 1) {
+                    if (res.data.code === 1 || res.data.code == 200) {
                         //200: 服务端业务处理正常结束
                         resolve(res.data)
                     } else {
-                        if (res.data.code === 0){
-                            wx.showToast({
-                                title: res.data.message,
-                            })
+                        if (res.data.code === 401){
+                            if (data['errMsg'] == 'modal') {
+                                wx.showModal({
+                                  title: '错误',
+                                  content: res.data.msg,
+                                })
+                            }else {
+                                wx.showToast({
+                                    title: res.data.msg,
+                                })
+                            }
+                            
                         }
                         if (res.data.code === 901) {
                             _self.HEAD.token = ''

+ 95 - 1
utils/util.js

@@ -25,7 +25,101 @@ const getQueryString = (url)=> {
     return params
 } 
 
+function timestampToTime(timestamp, type) {
+  if (timestamp) {
+    var date = new Date(timestamp * 1000);
+  } else {
+    var date = new Date();
+  }
+  var Y = date.getFullYear();
+  var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
+  var D = formatNumber(date.getDate());
+  var h = formatNumber(date.getHours());
+  var m = formatNumber(date.getMinutes());
+  var s = formatNumber(date.getSeconds());
+  if (type) {
+    if (type == '0') {
+      return Y + '-' + M + '-' + D;
+    } else if (type == '1') {
+      return h + ":" + m;
+    } else if (type == '2') {
+      return Y + '年' + M + '月' + D + '日';
+    } else if (type == '3') {
+      return M + '月' + D + '日';
+    } else if(type==='5'){
+      return Y + '-' + M + '-' + D + ' ' + h + ":" + m + ":" + s;
+    }else if(type==='6'){
+      return M + '.' + D;
+    }else {
+      return Y + '.' + M + '.' + D;
+    }
+  } else {
+    return Y + '-' + M + '-' + D + ' ' + h + ":" + m + ":" + s;
+  }
+}
+
+const randomString = (len)  => {
+    len = len || 32;
+    var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
+    var maxPos = chars.length;
+    var pwd = '';
+    for (let i = 0; i < len; i++) {
+      pwd += chars.charAt(Math.floor(Math.random() * maxPos));
+    }
+    return pwd;
+  }
+  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;
+  }
+
+  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;
+  }
 module.exports = {
   formatTime: formatTime,
-  getQueryString: getQueryString
+  getQueryString: getQueryString,
+  timestampToTime: timestampToTime,
+  randomString: randomString,
+  sha1: sha1
 }