Browse Source

优惠券

姜永辉 1 year ago
parent
commit
1c24304fe4

+ 2 - 1
api/pages/sharesign/couponUse.js

@@ -11,7 +11,8 @@ module.exports = {
 	couponUseService: { 
 		// 前缀
     prefix: 'oauth-server/oauth/couponUse/',
-    countByCond: 'count_by',
+	countByCond: 'count_by',
+	listByCondUse: 'list_by_use',
 	},
 	routeUrl: {
 		couponUse: {

+ 45 - 23
mixins/index.js

@@ -91,9 +91,9 @@ module.exports = {
     // 页面的员工和部门
     orgStaffInfo: null,
     // 组件加载完毕(避免组件晃动,加载完毕后再可见)
-    okFlag:false,
+    okFlag: false,
     // 下拉刷新控制标识
-    pullRefreshFlag:false,
+    pullRefreshFlag: false,
   },
   /**
    * @desc : 获取路由信息,供data中的对象使用
@@ -142,12 +142,12 @@ module.exports = {
    * @author : 周兴
    * @date : 2024/6/24
    */
-  clickPreview(e){
-    setTimeout(()=>{
+  clickPreview(e) {
+    setTimeout(() => {
       this.setData({
         loading: false,
       })
-    },500)
+    }, 500)
   },
   /**
    * @desc : 上传附件成功
@@ -492,7 +492,7 @@ module.exports = {
   * @date : 2024/4/22
   */
   print(docName, layoutId, dataId) {
-    let address = config.image_url.replace('file','')
+    let address = config.image_url.replace('file', '')
     wx.navigateTo({
       url: '/package-base-select/pages/web-view-select/web-view-select',
       success: function (res) {
@@ -506,16 +506,16 @@ module.exports = {
    * @date : 2024/7/5 13:22
    * @author : 王英杰
    */
-  formatDateOnly(datetime) {  
+  formatDateOnly(datetime) {
     // 创建Date对象  
-    var date = new Date(datetime);  
+    var date = new Date(datetime);
     // 提取年、月、日  
-    var year = date.getFullYear();  
+    var year = date.getFullYear();
     var month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份加1,并使用padStart确保为两位数  
     var day = date.getDate().toString().padStart(2, '0'); // 使用padStart确保为两位数  
-      
+
     // 拼接年月日  
-    return year + '-' + month + '-' + day;  
+    return year + '-' + month + '-' + day;
   },
   /**
    * @desc : 执行保存方法
@@ -776,9 +776,31 @@ module.exports = {
    * @date : 2024/5/24 15:49
    * @author : 王英杰
    */
-  handleTap(){  
-    this.selectComponent('#'+this.data.formName).handleTap() 
+  handleTap() {
+    this.selectComponent('#' + this.data.formName).handleTap()
+  },
+  /**
+   * @desc : 关闭所有的tip
+   * @date : 2024/5/24 15:49
+   * @author : 王英杰
+   */
+  setShowTipFlag(id) {
+    this.selectComponent('#' + id).setShowTipFlag(false)
+  },
+
+  /**
+  * @desc : 关闭所有的tip
+  * @date : 2024/5/24 15:49
+  * @author : 王英杰
+  */
+  closeTips(ids) {
+    ids.forEach(item => {
+      if (this.selectComponent('#' + item)) {
+        this.selectComponent('#' + item).setShowTipFlag(false)
+      }
+    })
   },
+
   /**
    * @desc   : 查询明细的方法(不给外部调用)
    * @author : 周兴
@@ -1207,7 +1229,7 @@ module.exports = {
     // 新建后关闭新建后刷新页面  
     if (this.data.refreshByAdd) {
       this.searchData();
-      if(this.customQuery){
+      if (this.customQuery) {
         //自定义查询
         this.customQuery();
       }
@@ -1237,7 +1259,7 @@ module.exports = {
         })
       }
     }
-    if( app.globalData.company){
+    if (app.globalData.company) {
       let gradeCode = app.globalData.company.gradeCode
       this.setData({
         gradeCode: gradeCode,
@@ -1298,12 +1320,12 @@ module.exports = {
           })
         }
         // 控制选择商品页面是否显示去入库
-        if(data.noWarehouseFlag){
+        if (data.noWarehouseFlag) {
           _this.setData({
-            noWarehouseFlag:data.noWarehouseFlag
+            noWarehouseFlag: data.noWarehouseFlag
           })
         }
-        
+
         if (data.item) {
           _this.setData({
             item: data.item
@@ -1409,11 +1431,11 @@ module.exports = {
     this.setData({
       noMore: true
     })
-    if(this.data.pullRefreshFlag){
+    if (this.data.pullRefreshFlag) {
       return;
     }
     this.setData({
-      pullRefreshFlag:true
+      pullRefreshFlag: true
     })
     setTimeout(() => {
       // 执行查询方法
@@ -1421,11 +1443,11 @@ module.exports = {
       //停止刷新
       wx.stopPullDownRefresh()
     }, 300)
-    setTimeout(()=>{
+    setTimeout(() => {
       this.setData({
-        pullRefreshFlag:false
+        pullRefreshFlag: false
       })
-    },1000)
+    }, 1000)
   },
   /**
    * 获取自定义导航栏高度

+ 117 - 15
package-basic-data/pages/func-buy/add-confirm/add-confirm.js

@@ -25,19 +25,24 @@ Page({
         userEndDateString: '',
         factAmt: 0,
         routeObjName: 'company',
+        integral: 0,
+        viewHeight: 302,
+        couponList: [],
+        couponUse: {},
+        // 策略
+        integralTacticItem: {},
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad(options) {
-        console.log("app.globalData.company.funPackage",app.globalData.company.funPackage);
         // 用户到期日期
         if (app.globalData.company.userEndDate) {
             this.setData({
                 userEndDate: app.globalData.company.userEndDate
             })
-        } 
+        }
     },
 
     /**
@@ -50,11 +55,62 @@ Page({
             regions: regions,
         })
 
-        //获取服务器的最新时间
-        this.getCurrentDate()
+        // 优惠券 积分 一个函数查询
+        this.getCouponUse()
+    },
+
+    /**
+    * @desc : 关闭所有的tip
+    * @date : 2024/5/24 15:49
+    * @author : 王英杰
+    */
+    closeAllTips() {
+        this.closeTips(['tipIntegral','tipOrd'])
     },
 
     /**
+    * @desc : 优惠劵数量获取
+    * @author : 刘尧
+    * @date : 2024/7/29 15:54
+    */
+    getCouponUse() {
+        let params = {
+            couponStatus: Constants.couponStatus.unused,
+            flgValid: true,
+            cpId: app.globalData.company.cpId,
+        }
+        let service = app.globalData['couponUseService']
+        this.excute(service, service.listByCondUse, params).then(res => {
+            if (res.data && res.data.data) {
+                if (res.data.data.list && res.data.data.list.length > 0) {
+                    this.setData({
+                        couponList: res.data.data.list,
+                        couponUse: res.data.data.list[0],
+                        viewHeight: this.data.viewHeight + 40
+                    })
+                }
+                if (res.data.data.integral) {
+                    this.setData({
+                        integral: res.data.data.integral,
+                        viewHeight: this.data.viewHeight + 40
+                    })
+                }
+                // 积分策略
+                if (res.data.data.listIntegralTactic && res.data.data.listIntegralTactic.length > 0) {
+                    this.setData({
+                        integralTacticItem: res.data.data.listIntegralTactic[0],
+                    })
+                }
+
+            }
+            //获取服务器的最新时间
+            this.getCurrentDate()
+
+        });
+    },
+
+
+    /**
     * @desc : 服务器的日期
     * @author : 姜永辉
     * @date : 2024/4/1
@@ -67,24 +123,53 @@ Page({
                 //服务器的时间  
                 let nowDate = res.data.data.currentDate
                 let endDate = new Date(nowDate).addMonths(12).addDays(-1).toDateStr()
+                // 积分转成现金                
+                let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
+                // 折扣--数据库的值不能超过10
+                let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
+                // couponUse.discount / 10              
 
                 // 用户到期日期
                 if (_this.data.userEndDate == null || !_this.data.userEndDate) {
-                    this.setData({
+                    // 积分兑换的大于订单详情的
+                    if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)) {
+                        _this.setData({
+                            factAmt: 0.00,
+                            integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)
+                        })
+
+                    } else {
+                        _this.setData({
+                            factAmt: Number((_this.data.item.wxPrice - integralRateVal) * discount.toFixed(2)),
+                        })
+                    }
+                    _this.setData({
                         userEndDate: endDate,
                         userEndDateFlg: true,
                         userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
-                        factAmt: _this.data.item.wxPrice,
+                        // factAmt: _this.data.item.wxPrice,
                         extendDays: 365,
                         nowDate,
                     })
                 } else {
                     // 和 服务器的时间一致
                     if (_this.data.userEndDate == endDate) {
-                        this.setData({
+                        // 积分兑换的大于订单详情的
+                        if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)) {
+                            _this.setData({
+                                factAmt: 0.00,
+                                integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)
+                            })
+
+                        } else {
+                            _this.setData({
+                                factAmt: Number((_this.data.item.wxPrice - integralRateVal) * discount.toFixed(2)),
+                            })
+                        }
+                        _this.setData({
                             userEndDateFlg: true,
                             userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
-                            factAmt: _this.data.item.wxPrice,
+                            // factAmt: _this.data.item.wxPrice,
                             extendDays: 365,
                             nowDate,
                         })
@@ -92,12 +177,23 @@ Page({
                         let extendDays = Math.ceil(new Date(_this.data.userEndDate).dayDiff(new Date(nowDate)) + 1);
 
                         let price = (Math.round((_this.data.item.wxPrice / 365 + Number.EPSILON) * 100) / 100).toFixed(2)
-                        console.log(price);
                         let factAmt = (Number(price) * extendDays).toFixed(2)
-                        this.setData({
+                        // 积分兑换的大于订单详情的
+                        if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * factAmt)) {
+                            _this.setData({
+                                factAmt: 0.00,
+                                integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * factAmt)
+                            })
+
+                        } else {
+                            _this.setData({
+                                factAmt: Number((factAmt - integralRateVal) * discount.toFixed(2)),
+                            })
+                        }
+                        _this.setData({
                             userEndDateFlg: false,
                             userEndDateString: price + '元/天(' + _this.data.item.activityItemDescribe + ')* ' + extendDays + '天=' + factAmt + '元',
-                            factAmt: factAmt,
+                            // factAmt: factAmt,
                             extendDays,
                             nowDate,
                         })
@@ -114,8 +210,8 @@ Page({
     * @author : 周兴
     * @date : 2024/4/1
     */
-    setParams(params) { 
-        let funPackage = app.globalData.company.funPackage? [...app.globalData.company.funPackage] : []
+    setParams(params) {
+        let funPackage = app.globalData.company.funPackage ? [...app.globalData.company.funPackage] : []
         params.endDate = app.globalData.company.endDate
         params.userEndDate = this.data.userEndDate
         params.gradeCode = app.globalData.company.gradeCode
@@ -129,7 +225,7 @@ Page({
         params.wxMaxNum = app.globalData.company.wxMaxNum
         params.webMaxNum = app.globalData.company.webMaxNum
         params.activityId = this.data.item.activityId
-        params.activityItemId = this.data.item.itemId       
+        params.activityItemId = this.data.item.itemId
         params.remarks = this.data.userEndDateString
         params.reNew = app.globalData.company.reNew
         params.activityIds = [this.data.item.activityId]
@@ -143,7 +239,12 @@ Page({
             params.vip = true;
         }
         params.buyLong = this.data.extendDays + '天'
+        // 操作员
         params.staffNameFrom = app.globalData.user.staffName
+        // 优惠券使用id 金额大于0
+        params.couponUseId = this.data.couponUse.userId && Number(this.data.factAmt) > 0
+                 ? this.data.couponUse.userId : null
+        params.integral = this.data.integral
         return params;
     },
     /**
@@ -153,7 +254,8 @@ Page({
      */
     saveData(params) {
         return this.excute(this.data.service, this.data.service.saveFunc, this.data.params).then(res => {
-            if (res.data.code == Constants.SUCESS_CODE) {
+            // 金额大于0 才调用支付
+            if (res.data.code == Constants.SUCESS_CODE && Number(this.data.factAmt) > 0) {
                 // 成功后跳转支付
                 this.toPay(res.data.data);
             }

+ 9 - 4
package-basic-data/pages/func-buy/add-confirm/add-confirm.wxml

@@ -18,15 +18,20 @@
 </view>
 
 
-<view class="bottom-class">
+<view class="bottom-class" style="{{'height:' + viewHeight + 'rpx'}}" bind:tap="closeAllTips">
 	<view class="view-margin">
 		<view style="display: flex;justify-content: space-between;align-items: center;">
-			<view>订单详情 <van-icon slot="label-icon" name="question-o" data-item="{{item}}" catchtap="showTip" /></view>
+			<view>订单详情
+				<dk-tip slot="label-icon" style="display: inline-block;" id="tipOrd" Up="{{true}}" Right="{{true}}" tipContent='账户有效期标准化至统一到期日' bind:clickTip="closeAllTips"/>
+			</view>
 			<view>{{userEndDateString}}</view>
 		</view>
 	</view>
-	<view wx:if="{{false}}" class="view-margin" style="text-align: right;margin-top: 35rpx;">
-		减少100积分<van-icon slot="label-icon" name="question-o" data-item="{{item}}" catchtap="showTip" />
+	<view wx:if="{{integral > 0 }}" class="view-margin" style="text-align: right;margin-top: 35rpx;">
+		减少{{integral}}积分 <dk-tip slot="label-icon" style="display: inline-block;" id="tipIntegral" Up="{{true}}" Left="{{true}}" tipContent='每{{integralTacticItem.exchangeRate}}云币等于1人民币' bind:clickTip="closeAllTips"/> 
+	</view>
+	<view wx:if="{{couponList.length > 0 && factAmt > 0 }}" class="view-margin" style="text-align: right;margin-top: 35rpx;">
+		使用{{couponUse.discount}}折优惠券
 	</view>
 	<view class="view-margin" style="display: flex;justify-content:space-between; align-items:center;   ">
 		<view style="display: flex;justify-content: center;align-items: center;">

+ 1 - 1
package-basic-data/pages/func-buy/add-confirm/add-confirm.wxss

@@ -151,7 +151,7 @@ page {
 	position: fixed;
 	bottom: 0;
 	width: 100%;
-	height: 302rpx;
+	height: 302rpx; 
 	border-top: 1px solid #efefef;
 	padding: 20rpx;
 	z-index: 7;