| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- /*******************************************************************************
- * Copyright(c) 2022 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:增值定制
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 周兴 2024-5-15 1.00 新建
- *******************************************************************************/
- const Constants = require('@/utils/Constants.js');
- const mixins = require('@/mixins/index.js');
- const config = require('@/config/config.js');
- const app = getApp()
- Page({
- mixins: [mixins],
- /**
- * 页面的初始数据
- */
- data: {
- regions: [],
- functionItems: [],
- funIds: [],
- imageUrl: config.image_url + '/static/img/',
- userEndDate: null,
- userEndDateFlg: false,
- userEndDateString: '',
- factAmt: 0,
- routeObjName: 'company',
- integral: 0,
- viewHeight: 302,
- couponList: [],
- couponUse: {},
- // 策略
- integralTacticItem: {},
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- // 用户到期日期
- if (app.globalData.company.userEndDate) {
- this.setData({
- userEndDate: app.globalData.company.userEndDate
- })
- }
- },
- /**
- * 生命周期函数--加载数据
- */
- loadInit() {
- let regions = this.data.regions
- regions.push(this.data.item)
- this.setData({
- regions: regions,
- })
- // 优惠券 积分 一个函数查询
- 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
- */
- getCurrentDate() {
- let _this = this
- let service = app.globalData['commonService']
- _this.excute(service, service.getCurrentDate, {}).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- //服务器的时间
- 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) {
- // 积分兑换的大于订单详情的
- 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,
- extendDays: 365,
- nowDate,
- })
- } else {
- // 和 服务器的时间一致
- if (_this.data.userEndDate == endDate) {
- // 积分兑换的大于订单详情的
- 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,
- extendDays: 365,
- nowDate,
- })
- } else {
- 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)
- let factAmt = (Number(price) * extendDays).toFixed(2)
- // 积分兑换的大于订单详情的
- 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,
- extendDays,
- nowDate,
- })
- }
- }
- }
- });
- },
- /**
- * @desc : 设置保存参数
- * @author : 周兴
- * @date : 2024/4/1
- */
- 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
- params.cpId = app.globalData.company.cpId
- params.tradeNo = this.generateRandomNo();
- params.wxUserId = app.globalData.user.userId
- params.tradeAmount = Number(this.data.factAmt)
- params.buyBeginDate = this.data.nowDate;
- params.buyEndDate = this.data.userEndDate
- params.extendDays = 0;
- 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.remarks = this.data.userEndDateString
- params.reNew = app.globalData.company.reNew
- params.activityIds = [this.data.item.activityId]
- params.activityItemIds = [this.data.item.itemId]
- funPackage.push({
- funUuids: this.data.item.funUuids,
- activityId: this.data.item.activityId,
- })
- params.funPackage = funPackage
- if (app.globalData.company.vip) {
- params.vip = true;
- }
- params.buyLong = this.data.extendDays + '天'
- // 操作员
- params.staffNameFrom = app.globalData.user.staffName
- // 优惠券使用id 金额大于0
- params.couponUseId = this.data.couponUse.useId && Number(this.data.factAmt) > 0
- ? this.data.couponUse.useId : null
- params.integral = this.data.integral
- return params;
- },
- /**
- * @desc : 保存数据
- * @author : 周兴
- * @date : 2024/5/17
- */
- saveData(params) {
- return this.excute(this.data.service, this.data.service.saveFunc, this.data.params).then(res => {
- // 金额大于0 才调用支付
- if (res.data.code == Constants.SUCESS_CODE && Number(this.data.factAmt) > 0) {
- // 成功后跳转支付
- this.toPay(res.data.data);
- }
- })
- },
- })
|