add-confirm.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:增值定制
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 周兴 2024-5-15 1.00 新建
  8. *******************************************************************************/
  9. const Constants = require('@/utils/Constants.js');
  10. const mixins = require('@/mixins/index.js');
  11. const config = require('@/config/config.js');
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. regions: [],
  20. functionItems: [],
  21. funIds: [],
  22. imageUrl: config.image_url + '/static/img/',
  23. userEndDate: null,
  24. userEndDateFlg: false,
  25. userEndDateString: '',
  26. factAmt: 0,
  27. routeObjName: 'company',
  28. integral: 0,
  29. viewHeight: 302,
  30. couponList: [],
  31. couponUse: {},
  32. // 策略
  33. integralTacticItem: {},
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad(options) {
  39. // 用户到期日期
  40. if (app.globalData.company.userEndDate) {
  41. this.setData({
  42. userEndDate: app.globalData.company.userEndDate
  43. })
  44. }
  45. },
  46. /**
  47. * 生命周期函数--加载数据
  48. */
  49. loadInit() {
  50. let regions = this.data.regions
  51. regions.push(this.data.item)
  52. this.setData({
  53. regions: regions,
  54. })
  55. // 优惠券 积分 一个函数查询
  56. this.getCouponUse()
  57. },
  58. /**
  59. * @desc : 关闭所有的tip
  60. * @date : 2024/5/24 15:49
  61. * @author : 王英杰
  62. */
  63. closeAllTips() {
  64. this.closeTips(['tipIntegral','tipOrd'])
  65. },
  66. /**
  67. * @desc : 优惠劵数量获取 积分策略 积分
  68. * @author : 刘尧
  69. * @date : 2024/7/29 15:54
  70. */
  71. getCouponUse() {
  72. let params = {
  73. couponStatus: Constants.couponStatus.unused,
  74. flgValid: true,
  75. cpId: app.globalData.company.cpId,
  76. }
  77. let service = app.globalData['couponUseService']
  78. this.excute(service, service.listByCondUse, params).then(res => {
  79. if (res.data && res.data.data) {
  80. // 优惠劵数量获取
  81. if (res.data.data.list && res.data.data.list.length > 0) {
  82. this.setData({
  83. couponList: res.data.data.list,
  84. couponUse: res.data.data.list[0],
  85. viewHeight: this.data.viewHeight + 40
  86. })
  87. }
  88. // 积分
  89. if (res.data.data.integral) {
  90. this.setData({
  91. integral: res.data.data.integral,
  92. viewHeight: this.data.viewHeight + 40
  93. })
  94. }
  95. // 积分策略
  96. if (res.data.data.listIntegralTactic && res.data.data.listIntegralTactic.length > 0) {
  97. this.setData({
  98. integralTacticItem: res.data.data.listIntegralTactic[0],
  99. })
  100. }
  101. }
  102. //获取服务器的最新时间
  103. this.getCurrentDate()
  104. });
  105. },
  106. /**
  107. * @desc : 服务器的日期
  108. * @author : 姜永辉
  109. * @date : 2024/4/1
  110. */
  111. getCurrentDate() {
  112. let _this = this
  113. let service = app.globalData['commonService']
  114. _this.excute(service, service.getCurrentDate, {}).then(res => {
  115. if (res.data.code == Constants.SUCESS_CODE) {
  116. //服务器的时间
  117. let nowDate = res.data.data.currentDate
  118. let endDate = new Date(nowDate).addMonths(12).addDays(-1).toDateStr()
  119. // 积分转成现金
  120. let integralRateVal = Number((_this.data.integral / _this.data.integralTacticItem.exchangeRate).toFixed(2))
  121. // 折扣--数据库的值不能超过10
  122. let discount = _this.data.couponUse.discount ? _this.data.couponUse.discount / 10 : 1
  123. // couponUse.discount / 10
  124. // 用户到期日期
  125. if (_this.data.userEndDate == null || !_this.data.userEndDate) {
  126. // 积分兑换的大于订单详情的
  127. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)) {
  128. _this.setData({
  129. factAmt: 0.00,
  130. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)
  131. })
  132. } else {
  133. _this.setData({
  134. factAmt: Number((_this.data.item.wxPrice - integralRateVal) * discount.toFixed(2)),
  135. })
  136. }
  137. _this.setData({
  138. userEndDate: endDate,
  139. userEndDateFlg: true,
  140. userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
  141. // factAmt: _this.data.item.wxPrice,
  142. extendDays: 365,
  143. nowDate,
  144. })
  145. } else {
  146. // 和 服务器的时间一致
  147. if (_this.data.userEndDate == endDate) {
  148. // 积分兑换的大于订单详情的
  149. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)) {
  150. _this.setData({
  151. factAmt: 0.00,
  152. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * _this.data.item.wxPrice)
  153. })
  154. } else {
  155. _this.setData({
  156. factAmt: Number((_this.data.item.wxPrice - integralRateVal) * discount.toFixed(2)),
  157. })
  158. }
  159. _this.setData({
  160. userEndDateFlg: true,
  161. userEndDateString: _this.data.item.wxPrice + '元/年(' + _this.data.item.activityItemDescribe + ')',
  162. // factAmt: _this.data.item.wxPrice,
  163. extendDays: 365,
  164. nowDate,
  165. })
  166. } else {
  167. let extendDays = Math.ceil(new Date(_this.data.userEndDate).dayDiff(new Date(nowDate)) + 1);
  168. let price = (Math.round((_this.data.item.wxPrice / 365 + Number.EPSILON) * 100) / 100).toFixed(2)
  169. let factAmt = (Number(price) * extendDays).toFixed(2)
  170. // 积分兑换的大于订单详情的
  171. if (_this.data.integral > Math.ceil(_this.data.integralTacticItem.exchangeRate * factAmt)) {
  172. _this.setData({
  173. factAmt: 0.00,
  174. integral: Math.ceil(_this.data.integralTacticItem.exchangeRate * factAmt)
  175. })
  176. } else {
  177. _this.setData({
  178. factAmt: Number((factAmt - integralRateVal) * discount.toFixed(2)),
  179. })
  180. }
  181. _this.setData({
  182. userEndDateFlg: false,
  183. userEndDateString: price + '元/天(' + _this.data.item.activityItemDescribe + ')* ' + extendDays + '天=' + factAmt + '元',
  184. // factAmt: factAmt,
  185. extendDays,
  186. nowDate,
  187. })
  188. }
  189. }
  190. }
  191. });
  192. },
  193. /**
  194. * @desc : 设置保存参数
  195. * @author : 周兴
  196. * @date : 2024/4/1
  197. */
  198. setParams(params) {
  199. let funPackage = app.globalData.company.funPackage ? [...app.globalData.company.funPackage] : []
  200. params.endDate = app.globalData.company.endDate
  201. params.userEndDate = this.data.userEndDate
  202. params.gradeCode = app.globalData.company.gradeCode
  203. params.cpId = app.globalData.company.cpId
  204. params.tradeNo = this.generateRandomNo();
  205. params.wxUserId = app.globalData.user.userId
  206. params.tradeAmount = Number(this.data.factAmt)
  207. params.buyBeginDate = this.data.nowDate;
  208. params.buyEndDate = this.data.userEndDate
  209. params.extendDays = 0;
  210. params.wxMaxNum = app.globalData.company.wxMaxNum
  211. params.webMaxNum = app.globalData.company.webMaxNum
  212. params.activityId = this.data.item.activityId
  213. params.activityItemId = this.data.item.itemId
  214. params.remarks = this.data.userEndDateString
  215. params.reNew = app.globalData.company.reNew
  216. params.activityIds = [this.data.item.activityId]
  217. params.activityItemIds = [this.data.item.itemId]
  218. funPackage.push({
  219. funUuids: this.data.item.funUuids,
  220. activityId: this.data.item.activityId,
  221. })
  222. params.funPackage = funPackage
  223. if (app.globalData.company.vip) {
  224. params.vip = true;
  225. }
  226. params.buyLong = this.data.extendDays + '天'
  227. // 操作员
  228. params.staffNameFrom = app.globalData.user.staffName
  229. // 优惠券使用id 金额大于0
  230. params.couponUseId = this.data.couponUse.useId && Number(this.data.factAmt) > 0
  231. ? this.data.couponUse.useId : null
  232. params.integral = this.data.integral
  233. return params;
  234. },
  235. /**
  236. * @desc : 保存数据
  237. * @author : 周兴
  238. * @date : 2024/5/17
  239. */
  240. saveData(params) {
  241. return this.excute(this.data.service, this.data.service.saveFunc, this.data.params).then(res => {
  242. // 金额大于0 才调用支付
  243. if (res.data.code == Constants.SUCESS_CODE && Number(this.data.factAmt) > 0) {
  244. // 成功后跳转支付
  245. this.toPay(res.data.data);
  246. }
  247. })
  248. },
  249. })