5 Commits ca6df4c917 ... 470bcf7bc7

Author SHA1 Message Date
  zhoumuhao 470bcf7bc7 feat(卡券):跳转沪上阿姨小程序 3 years ago
  zhoumuhao 7e3b334c3d feat(卡券):跳转沪上阿姨小程序 3 years ago
  zhoumuhao 52d89ca9ee feat(卡券):领取 3 years ago
  zhoumuhao 30abdcd8ad feat(卡券):领取 3 years ago
  zhoumuhao 9daa5c2fa6 feat(卡券):领取 3 years ago

+ 89 - 1
api/activity.js

@@ -2,7 +2,12 @@ import request from '../utils/request.js'
 
 class activity extends request {
 
-
+/**
+ * 获取活动列表
+ * @param {*} nextPage 
+ * @param {*} pageSize 
+ * @param {*} status 
+ */
   static async getActivityList(nextPage,pageSize,status) {
     let params = {
       nextPage:nextPage,
@@ -16,6 +21,16 @@ class activity extends request {
 
     return res.data
   }
+
+  static async isShareByMobile(mobile) {
+    let params = {
+      mobile:mobile
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/is-share-by-mobile`, params)
+
+    return res.data
+  }
+
   /**
    * 获取活动详情
    * @param {*} activityId 活动id
@@ -28,6 +43,79 @@ class activity extends request {
 
     return res.data
   }
+
+  /**
+   * 领券
+   * @param {*} activityId 
+   * @param {*} memberMobile 
+   * @param {*} number 
+   * @param {*} shopId 
+   */
+  static async createOrder(activityId,memberMobile,num=1,shopId='') {
+    let params = {
+      activityId:activityId,
+      memberMobile:memberMobile,
+      num:num,
+      shopId:shopId
+    };
+    console.log('参数');
+    console.log(params);
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/create-order`, params)
+    return res.data
+  }
+
+  /**
+   * 分享活动的分享码
+   * @param {*} activityId 
+   * @param {*} mobile 
+   */
+  static async createShareActivityCode(activityId,mobile) {
+    let params = {
+      activityId:activityId,
+      mobile:mobile
+      // activityId:'Bg5740r78w',
+      // mobile:13205528979
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/create-share-activity-code`, params)
+    return res.data
+  }
+  //根据codeId 获取 分享活动的详细信息
+  static async getShareActivityCode(codeId) {
+    let params = {
+      codeId:codeId,
+    };
+    console.log(params)
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/get-share-activity-code`, params)
+    return res.data
+  }
+
+  /**
+   * 获取我的券列表
+   * @param {*} nextPage 
+   * @param {*} pageSize 
+   * @param {*} mobile 
+   */
+  static async getSnListMember(nextPage,pageSize,mobile) {
+    let params = {
+      nextPage:nextPage,
+      pageSize:pageSize,
+      condition:{
+        mobile:mobile
+      }
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/sn-list-member`, params)
+    return res.data
+  }
+
+  //绑定券与codeId之间的关系
+  static async bindShareCode(orderSn,codeId) {
+    let params = {
+      orderSn:orderSn,
+      codeId:codeId
+    };
+    const res = await this.postRequest(`${this.BASE_URL}open/activity/bind-share-code`, params)
+    return res.data
+  }
   
   static async getSessionKeyFromApi(code) {
     let params = {

+ 13 - 0
app.js

@@ -86,6 +86,19 @@ App({
       }
     });
   },
+
+  showToast(title,icon='success',time=2000,call='') {
+    wx.showToast({
+      title: title,
+      icon: icon,
+      duration: time,
+      success:function(){
+        if(typeof(call)=='function') {
+          call();
+        }
+      }
+    })
+  },
   globalData: {
     userInfo: null,
     appCode:'HSAY_SHARE_COUPON',

+ 1 - 0
app.json

@@ -3,6 +3,7 @@
     
     "pages/activityList/activityList",
     "pages/activityInfo/activityInfo",
+    "pages/couponReceive/couponReceive",
     "pages/myCoupons/myCoupons",
     "pages/index/index",
     "pages/receiveCoupon/receiveCoupon",

+ 52 - 2
pages/activityInfo/activityInfo.js

@@ -1,19 +1,38 @@
 const { default: activity } = require("../../api/activity");
+import drawQrcode from '../../utils/weapp.qrcode.js'
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    activityId:0, //活动id
+    userMobile:'', //电话
+    codeId:'',//code唯一码
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    console.log('接受参数');
+    console.log(options);
+    let _self = this;
     if(options.id){
       this.activityInfo(options.id)
+      _self.setData({
+        activityId:options.id,
+      })
+    }
+    //用户手机
+    if(options.mobile) {
+      _self.setData({
+        userMobile:options.mobile
+      })
+    }
+    if(_self.data.activityId!=0 && _self.data.userMobile!='') {
+      //获取code
+      _self.getCode()
     }
 
   },
@@ -66,8 +85,14 @@ Page({
   onShareAppMessage: function () {
 
   },
+
+  /**
+   * 获取活动详细信息
+   * @param {*} activityId 
+   */
    async activityInfo(activityId){
     let result = await activity.getActivityDetail(activityId);
+    console.log('获取活动详细信息');
     console.log(result)
     var objSwitch = getApp().globalData.typeSwitchObj
 
@@ -94,6 +119,31 @@ Page({
     this.setData({
       activityInfo:result
     })
-   
+  },
+
+  /**
+   * 获取分享码
+   */
+  async getCode() {
+    let _self = this;
+    let res = await activity.createShareActivityCode(_self.data.activityId,_self.data.userMobile);
+    _self.setData({
+      codeId:res.codeId,
+    })
+
+    //根据codeId 生成二维码
+    drawQrcode({
+      width: 200,
+      height: 200,
+      canvasId: 'myQrcode',
+      text: 'https://oapi.shpr.top?id='+_self.data.codeId,
+      image: {
+        imageResource: '../../images/logo.png',
+        dx: 70,
+        dy: 70,
+        dWidth: 60,
+        dHeight: 60
+      }
+    })
   }
 })

+ 3 - 1
pages/activityInfo/activityInfo.wxml

@@ -8,7 +8,9 @@
   <view class="coupon-info over-ellipsi">含 
   <span wx:for="{{activityInfo.couponTypeAndNumObj}}">{{item.typeText}} ({{item.num}}) </span>  
   </view>
-  <image class="qrcode-img" src="/images/logo.png"> </image>
+  <!-- 生成二维码 -->
+  <!-- <image class="qrcode-img" src="/images/logo.png"> </image> -->
+  <canvas class="qrcode-img" canvas-id="myQrcode"></canvas>
   <view class="qrcode-title over-ellipsi">扫二维码 获得卡券礼包</view>
   <view class="bottom-line"></view>
   <view class="flex-row bottom-date">

+ 26 - 4
pages/activityList/activityList.js

@@ -21,9 +21,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function () {
-    this.getList()
+    let _self = this;
+    //获取列表
+    _self.getList();
   },
-
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -86,13 +87,16 @@ Page({
   },
   goToShare(e){
     console.log(e)
+    let _self = this;
     wx.navigateTo({
-      url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id,
+      url: '/pages/activityInfo/activityInfo?id='+e.currentTarget.dataset.id+'&mobile='+_self.data.userMobile,
     })
   },
+  //获取手机号
   getPhoneNumber(e) {
     let _self = this;
     var encryptedData = e.detail.encryptedData;
+    console.log(encryptedData);
     var iv = e.detail.iv;
     if (!encryptedData || encryptedData.length == 0 || !iv || iv.length == 0) {
       return;
@@ -105,12 +109,16 @@ Page({
         _self.setData({
           userMobile: userMobile,
         })
+        //判断该手机号在不在分享名单里
+        _self.isShareByMobile();
       }
     
     });
   },
 
+  //获取活动列表
   getList: async function() {
+    let _self = this;
     var result = await activity.getActivityList(this.data.page,this.data.pageNum,2);
 
     var list = this.handleCouponList(result.list);
@@ -119,7 +127,11 @@ Page({
     }else{
       var nowResult = list
     }
-    
+    //判断该电话是否存在 如果不存在 取第一条
+    if(_self.data.userMobile=='') {
+      nowResult = nowResult.length>0?[nowResult[0]]:nowResult;
+    }
+   
     this.setData({
       list:nowResult,
       count:result.count,
@@ -127,6 +139,16 @@ Page({
     })
   },
 
+  async isShareByMobile(){
+    let _self = this;
+    var result = await activity.isShareByMobile(_self.data.userMobile);
+    if(result.isShare==1){
+      _self.setData({
+        page:1
+      })
+      _self.getList();
+    }
+  },
   handleCouponList(list) {
     if (list.length === 0) {
       return list;

+ 79 - 1
pages/myCoupons/myCoupons.js

@@ -1,18 +1,69 @@
 // pages/myCoupons/myCoupons.js
+const { default: activity } = require("../../api/activity");
+const util = require('../../utils/util.js');
+const app = getApp();
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-
+    couponList:[], //我的卡券列表
+    nextPage:1,
+    pageSize:12,
+    mobile:'', //我的手机号
+    totalPage:1, //总页码
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function (options) {
+    //获取我的卡券列表   api/supers/coupon/sn-list-member
+    let _self = this;
+    if(options.mobile) {
+      _self.setData({
+        mobile:options.mobile
+      })
+    }
+    _self.getSnListMember();  
+  },
+
+  //获取我的券列表
+  async getSnListMember(step='init') {
+    let _self = this;
+    let nextPage = _self.data.nextPage;
+    let pageSize = _self.data.pageSize;
+    let mobile = _self.data.mobile;
+    let res =await activity.getSnListMember(nextPage,pageSize,mobile);
+    let totalPage =Math.ceil(res.count/pageSize);
+    _self.setData({
+      totalPage:totalPage
+    })
+    let list =_self.handleList(res.list);
+    if(step=='init') {
+      _self.setData({
+        couponList:list
+      })
+    } else if(step=='pull') {
+      _self.setData({
+        couponList:_self.data.couponList.concat(list),
+      })
+    }
+
+  },
 
+  /**
+   * 处理数据
+   */
+  handleList(list) {
+    list.map((item,key)=>{
+      item.beignTime = util.format(item.beginTimestamp*1000);
+      item.endTime = util.format(item.endTimestamp*1000);
+      item.coupon.discount = item.coupon.type.value=='D'?item.coupon.discount/10:item.coupon.discount;
+      item.isFree = item.coupon.type.value=='D'&& item.coupon.discount==0?true:false;
+    })
+    return list;
   },
 
   /**
@@ -54,7 +105,34 @@ Page({
    * 页面上拉触底事件的处理函数
    */
   onReachBottom: function () {
+    let _self = this;
+    let nextPage = _self.data.nextPage;
+    let totalPage = _self.data.totalPage;
+    if(nextPage>=totalPage) {
+      app.showToast ('亲,到底了!');
+      return;
+    }
+    _self.setData({
+      nextPage:nextPage+1
+    })
+    _self.getSnListMember('pull')
+  },
 
+  /**
+   * 使用券跳转小程序
+   */
+  goUseCoupon() {
+    wx.navigateToMiniProgram({
+      appId: 'wxd92a2d29f8022f40',
+      path: 'pages/index/index',
+      extraData: {
+        foo: 'bar'
+      },
+      envVersion: 'develop',
+      success(res) {
+        // 打开成功
+      }
+    })
   },
 
   /**

+ 25 - 1
pages/myCoupons/myCoupons.wxml

@@ -1 +1,25 @@
-
+<!--我的卡券-->
+<view class="coupon_outer">
+  <view class="coupon_li" wx:for="{{couponList}}" wx:for-index="index" wx:for-item="item">
+  <block wx:if="{{item.isFree==false}}">
+    <view class="coupon_type" wx:if="{{item.coupon.type.value=='D'}}">折</view>
+    <view class="coupon_type" wx:if="{{item.coupon.type.value=='C'}}">元</view>
+    <view class="coupon-title">
+      <view class="coupon-price">{{item.coupon.discount?item.coupon.discount:'0'}}</view>
+      <!-- <view class="coupon-title-type">大福系列</view> -->
+    </view>
+  </block>
+  <block wx:else>
+    <view class="coupon-title-free">
+      <view>免</view>
+      <view>费</view>
+    </view>
+  </block>
+    <view class="coupon-li-line"></view>
+    <view class="coupon-detail">
+      <view class="coupon-detail-title">{{item.title}}</view>
+      <view class="coupon-detail-date">{{item.beignTime}}-{{item.endTime}}</view>
+    </view>
+    <view class="use-button" bindtap="goUseCoupon">去使用</view>
+  </view>
+</view>

+ 91 - 1
pages/myCoupons/myCoupons.wxss

@@ -1 +1,91 @@
-/* pages/myCoupons/myCoupons.wxss */
+/* pages/myCoupons/myCoupons.wxss */
+.coupon_outer {
+  padding-top: 20rpx;
+  width: 100%;
+}
+.coupon_li {
+  width: 90%;
+  height: 160rpx;
+  background-image: url("https://zhoumuhao-1993-1256250683.cos.ap-chengdu.myqcloud.com/coupon_list.png");
+  background-repeat: no-repeat;
+  background-size: 100% 100%;
+  margin: 0 auto;
+  position: relative;
+  color: #b82231;
+  display: flex;
+}
+.coupon_type {
+  position: absolute;
+  top: 20rpx;
+  left: 20rpx;
+  font-weight: 400;
+  width: 40rpx;
+  height: 40rpx;
+}
+.coupon-title {
+  display: flex;
+  flex-direction: column;
+  margin-left: 30rpx;
+  width: 144rpx;
+  padding-top: 42rpx;
+}
+.coupon-title>view {
+  text-align: center;
+}
+.coupon-price {
+  font-size: 55rpx;
+  font-weight: 600;
+}
+.coupon-title-type {
+  font-size: 22rpx;
+  font-weight: 400;
+}
+.coupon-li-line {
+  width: 2rpx;
+  height: 80%;
+  border-left: 2rpx dashed gray;
+  margin-top: 2%;
+}
+.coupon-detail {
+  margin-top: 30rpx;
+  margin-left: 18rpx;
+}
+.coupon-detail-title {
+  font-weight: 600;
+  font-size: 30rpx;
+}
+.coupon-detail-date {
+  font-size:20rpx;
+  margin-top: 16rpx;
+}
+
+.use-button {
+  width: 140rpx;
+  height: 50rpx;
+  background-color:#b82231;
+  color: #fff;
+  line-height: 50rpx;
+  text-align: center;
+  border-radius: 40rpx;
+  font-size: 24rpx;
+  margin: auto 0;
+  margin-left: 53rpx;
+  cursor: pointer;
+}
+
+.coupon_outer > .coupon_li {
+  margin-bottom: 20rpx;
+}
+
+.coupon-title-free {
+  display: flex;
+  margin-left: 30rpx;
+  width: 144rpx;
+  padding-top: 18rpx;
+}
+.coupon-title-free>view {
+  line-height: 123rpx;
+} 
+.coupon-title-free>view:first-child {
+  margin-left: 30rpx;
+}

+ 1 - 1
project.config.json

@@ -24,7 +24,7 @@
     "lazyloadPlaceholderEnable": false,
     "useMultiFrameRuntime": true,
     "useApiHook": true,
-    "useApiHostProcess": false,
+    "useApiHostProcess": true,
     "babelSetting": {
       "ignore": [],
       "disablePlugins": [],

+ 13 - 0
project.private.config.json

@@ -1,4 +1,5 @@
 {
+  "setting": {},
   "condition": {
     "plugin": {
       "list": []
@@ -16,6 +17,18 @@
           "pathName": "pages/activityInfo/activityInfo",
           "query": "id=Bg5740r78w",
           "scene": null
+        },
+        {
+          "name": "pages/couponReceive/couponReceive",
+          "pathName": "pages/couponReceive/couponReceive",
+          "query": "codeId=MYR72N738b",
+          "scene": null
+        },
+        {
+          "name": "pages/myCoupons/myCoupons",
+          "pathName": "pages/myCoupons/myCoupons",
+          "query": "mobile=18636653274",
+          "scene": null
         }
       ]
     }

+ 1 - 1
utils/request.js

@@ -2,7 +2,7 @@ import util from './util.js'
 class request {
 
     //本地的
-     static BASE_URL = 'http://www.lx.com:81/'
+     static BASE_URL = 'http://www.zmh.com:81/'
 //   pre环境的
 //   static BASE_URL = 'https://oapi.shpr.top/'
 //   正式的

+ 29 - 1
utils/util.js

@@ -64,7 +64,35 @@ function sha1(s) {
   return hex;
 }
 
+// 根据时间转换成时间戳
+function getUnixTime(dateStr){
+  var newstr = dateStr.replace(/-/g,'/'); 
+  var date =  new Date(newstr); 
+  var time_str = date.getTime().toString();
+  return time_str.substr(0, 10);
+}
+
+function format(shijianchuo,type=1)
+{
+//shijianchuo是整数,否则要parseInt转换
+var time = new Date(shijianchuo);
+var y = time.getFullYear();
+var m = time.getMonth()+1;
+var d = time.getDate();
+var h = time.getHours();
+var mm = time.getMinutes();
+var s = time.getSeconds();
+if(type==1) {
+  return y+'.'+add0(m)+'.'+add0(d)
+}
+// return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
+}
+function add0(m){return m<10?'0'+m:m }
+
 module.exports = {
   formatTime,
-  sha1
+  sha1,
+  getUnixTime,
+  format,
+  add0
 }