activity.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 util = require('@/utils/util.js')
  11. const mixins = require('@/mixins/index.js');
  12. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. // 是否加载完毕
  20. loadFlag: false,
  21. // 是否显示vip
  22. showVip: false,
  23. // 升级标识
  24. upgradeFlag: false,
  25. gradeCode: null,
  26. freeFlag: false,
  27. // 企业名称
  28. companyName: null,
  29. cpManager: null,
  30. cpPhone: null,
  31. webMaxNum: null,
  32. wxMaxNum: null,
  33. cpEndDate: null,
  34. activityTable: null,
  35. vipTable: null,
  36. readFlag: false,
  37. staffCount: {
  38. maxNum: 1,
  39. webMaxNum: 0,
  40. wxMaxNum: 0
  41. },
  42. curentAdItem: null,
  43. // 选择的vip报表
  44. chooseVipFlag: false,
  45. summaryInfo: {},
  46. routeObjName: 'company',
  47. pageFlag: false,
  48. // 当前用户授权数
  49. currentUserCount: null,
  50. //按钮
  51. buttonSaveList: [
  52. { code: 'save', title: mixins.$t('save'), width: '120rpx' }
  53. ],
  54. noticeInfo: Constants.noticeInfo
  55. },
  56. /**
  57. * @desc : 选择活动明细
  58. * @author : 周兴
  59. * @date : 2024/4/1
  60. */
  61. chooseAdItem(e) {
  62. let item = e.currentTarget.dataset.item;
  63. let summaryInfo = this.data.summaryInfo
  64. // 计算截止日期
  65. let months = item.validLong + item.extraLong
  66. let endDate = app.globalData.company.endDate
  67. // 升级需要从当天开始算
  68. if (this.data.upgradeFlag) {
  69. endDate = new Date()
  70. }
  71. endDate = new Date(endDate).addMonths(months).addDays(-1)
  72. summaryInfo.endDate = endDate.toDateStr();
  73. this.setData({
  74. curentAdItem: item,
  75. summaryInfo: summaryInfo
  76. })
  77. // 计算金额
  78. this.countSummaryAmount(item);
  79. },
  80. /**
  81. * @desc : 选择VIP报表明细
  82. * @author : 周兴
  83. * @date : 2024/4/1
  84. */
  85. chooseVipItem(e) {
  86. let item = e.currentTarget.dataset.item;
  87. // let summaryInfo = this.data.summaryInfo
  88. // // 计算截止日期
  89. // let months = item.validLong + item.extraLong
  90. // let endDate = app.globalData.company.endDate
  91. // // 升级需要从当天开始算
  92. // if (this.data.upgradeFlag) {
  93. // endDate = new Date()
  94. // }
  95. // endDate = new Date(endDate).addMonths(months).addDays(-1)
  96. // summaryInfo.endDate = endDate.toDateStr();
  97. this.setData({
  98. chooseVipFlag: !this.data.chooseVipFlag,
  99. // summaryInfo: summaryInfo
  100. })
  101. // 计算金额
  102. this.countSummaryAmountSTD();
  103. },
  104. /**
  105. * @desc : 勾选已阅读表示
  106. * @author : 周兴
  107. * @date : 2024/5/17
  108. */
  109. handleChangeCheckbox(e) {
  110. this.setData({
  111. readFlag: e.detail
  112. })
  113. },
  114. /**
  115. * @desc : 计算金额
  116. * @author : 周兴
  117. * @date : 2024/4/1
  118. */
  119. countSummaryAmount() {
  120. let item = this.data.curentAdItem;
  121. if (!item) return;
  122. let staffCount = this.data.staffCount;
  123. let summaryInfo = this.data.summaryInfo
  124. let amount = 0;
  125. // 先清空
  126. summaryInfo.amountInfo = '';
  127. // 共通用户
  128. if (staffCount.maxNum) {
  129. summaryInfo.amountInfo = item.stdPrice + '(打包价格)*' + staffCount.maxNum
  130. amount += item.stdPrice * staffCount.maxNum
  131. }
  132. // 手机端用户
  133. if (staffCount.wxMaxNum) {
  134. if (summaryInfo.amountInfo) {
  135. summaryInfo.amountInfo += ' + '
  136. }
  137. summaryInfo.amountInfo += item.wxPrice + '(手机端价格)*' + staffCount.wxMaxNum
  138. amount += item.wxPrice * staffCount.wxMaxNum
  139. }
  140. // 电脑端用户
  141. if (staffCount.webMaxNum) {
  142. if (summaryInfo.amountInfo) {
  143. summaryInfo.amountInfo += ' + '
  144. }
  145. summaryInfo.amountInfo += item.webPrice + '(电脑端价格)*' + staffCount.webMaxNum
  146. amount += item.webPrice * staffCount.webMaxNum
  147. }
  148. if (summaryInfo.amountInfo) {
  149. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  150. summaryInfo.amount = amount;
  151. }
  152. this.setData({
  153. summaryInfo: summaryInfo
  154. })
  155. // 统计两端用户数
  156. this.countStaffInfo();
  157. },
  158. /**
  159. * @desc : 获取标准版的价格显示
  160. * @author : 周兴
  161. * @date : 2024/4/1
  162. */
  163. countSummaryAmountSTD() {
  164. let item = this.data.curentAdItem;
  165. let vipTable = this.data.vipTable
  166. let summaryInfo = this.data.summaryInfo
  167. let amount = 0;
  168. // 先清空
  169. summaryInfo.amountInfo = '';
  170. let extendDays = null;
  171. let nowDate = new Date(new Date().toDateStr());
  172. if (summaryInfo.reCountFlag) {
  173. // 手机端用户
  174. if (summaryInfo.wxMaxNum) {
  175. summaryInfo.amountInfo += item.wxPrice + '(元) * ' + summaryInfo.wxMaxNum + '(个) '
  176. amount += item.wxPrice * summaryInfo.wxMaxNum
  177. }
  178. // vip报表
  179. if (this.data.chooseVipFlag && vipTable && vipTable.length > 0) {
  180. let vipItem = vipTable[0]
  181. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/VIP) ';
  182. amount += vipItem.wxPrice;
  183. }
  184. if (summaryInfo.amountInfo) {
  185. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  186. summaryInfo.amount = amount;
  187. }
  188. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  189. } else {
  190. extendDays = new Date(summaryInfo.userEndDate).dayDiff(nowDate) + 1;
  191. if (summaryInfo.wxMaxNum) {
  192. summaryInfo.amountInfo += item.wxPrice + '(元) '
  193. amount += item.wxPrice * summaryInfo.wxMaxNum
  194. }
  195. // vip报表
  196. if (this.data.chooseVipFlag && vipTable && vipTable.length > 0) {
  197. let vipItem = vipTable[0]
  198. summaryInfo.amountInfo += ' + ' + vipItem.wxPrice + '(元/VIP) ';
  199. summaryInfo.amountInfo = '( ' + summaryInfo.amountInfo + ' ) ';
  200. amount += vipItem.wxPrice;
  201. }
  202. summaryInfo.amountInfo += ' / 365(天) * ' + extendDays + '(天) * ' + summaryInfo.wxMaxNum + '(个)'
  203. if (summaryInfo.amountInfo) {
  204. amount = (amount / 365 * extendDays).toFixed(2);
  205. summaryInfo.amountInfo += ' = ' + amount + '(元)'
  206. summaryInfo.amount = amount;
  207. }
  208. }
  209. // 计算一授权一天的单价
  210. if (summaryInfo.userEndDate) {
  211. let price = (summaryInfo.amount / summaryInfo.wxMaxNum / extendDays).toFixed(2);
  212. summaryInfo.priceInfo = price
  213. summaryInfo.extendDays = extendDays
  214. }
  215. this.setData({
  216. summaryInfo: summaryInfo
  217. })
  218. },
  219. /**
  220. * @desc : 统计电脑端和手机端的用户数
  221. * @author : 周兴
  222. * @date : 2024/4/1
  223. */
  224. countStaffInfo() {
  225. let summaryInfo = this.data.summaryInfo;
  226. let staffCount = this.data.staffCount;
  227. if (!staffCount) {
  228. return;
  229. }
  230. let webNum = staffCount.webMaxNum + staffCount.maxNum
  231. let wxNum = staffCount.wxMaxNum + staffCount.maxNum
  232. summaryInfo.staffInfo = '可配置手机端授权' + wxNum + '个;电脑端授权' + webNum + '个(包含当前用户)'
  233. summaryInfo.webMaxNum = webNum
  234. summaryInfo.wxMaxNum = wxNum
  235. // 升级从当天算
  236. if (this.data.upgradeFlag) {
  237. summaryInfo.buyBeginDate = new Date().addDays(1).toDateStr();
  238. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date().addDays(1));
  239. } else {
  240. summaryInfo.buyBeginDate = new Date(this.data.cpEndDate).addDays(1).toDateStr();
  241. summaryInfo.extendDays = new Date(summaryInfo.endDate).dayDiff(new Date(this.data.cpEndDate).addDays(1));
  242. }
  243. // 计算一授权一天的单价
  244. let price = (summaryInfo.amount / (webNum + wxNum) / summaryInfo.extendDays).toFixed(2);
  245. summaryInfo.priceInfo = price
  246. this.setData({
  247. summaryInfo: summaryInfo
  248. })
  249. },
  250. /**
  251. * @desc : 修改用户数
  252. * @author : 周兴
  253. * @date : 2024/4/1
  254. */
  255. changeStaffCount(e) {
  256. let staffCount = this.data.staffCount
  257. let ds = e.currentTarget.dataset
  258. if (ds.type == 'wx') {
  259. staffCount.wxMaxNum = e.detail
  260. } else if (ds.type == 'web') {
  261. staffCount.webMaxNum = e.detail
  262. } else {
  263. staffCount.maxNum = e.detail
  264. }
  265. this.setData({
  266. staffCount: staffCount
  267. })
  268. // 计算金额
  269. this.countSummaryAmount();
  270. },
  271. /**
  272. * @desc : 保存
  273. * @author : 周兴
  274. * @date : 2024/4/1
  275. */
  276. handleSave() {
  277. let summaryInfo = this.data.summaryInfo;
  278. let currentUserCount = this.data.currentUserCount
  279. if (!currentUserCount) {
  280. return;
  281. }
  282. if (this.data.gradeCode == Constants.gradeCode.STD) {
  283. // 必须要选择一个授权
  284. if (Number(summaryInfo.amount) <= 0) {
  285. util.showToast('请选择一个授权');
  286. return false
  287. }
  288. // 判断数量是否超出续约授权
  289. if (currentUserCount.wxNum > summaryInfo.wxMaxNum && summaryInfo.reCountFlag) {
  290. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, title: '当前授权', wxTitle: '手机授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, title: '续费授权', wxTitle: '手机授权', code: 'renew' }]
  291. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  292. } else {
  293. this.save({});
  294. }
  295. } else {
  296. // 判断数量是否超出续约授权
  297. if (currentUserCount.wxNum > summaryInfo.wxMaxNum || currentUserCount.webNum > summaryInfo.webMaxNum) {
  298. let staffInfo = [{ wxMaxNum: this.data.wxMaxNum, webMaxNum: this.data.webMaxNum, title: '当前授权', wxTitle: '手机授权', webTitle: (app.globalData.company.gradeCode == Constants.gradeCode.STD) ? '' : '电脑授权', code: 'current', userTitle: '当前用户' }, { wxMaxNum: summaryInfo.wxMaxNum, webMaxNum: summaryInfo.webMaxNum, title: '续费授权', wxTitle: '手机授权', webTitle: '电脑授权', code: 'renew' }]
  299. this.save({ saveFlag: false, url: '/package-basic-data/pages/activity/detail/detail?staffInfo=' + JSON.stringify(staffInfo) });
  300. } else {
  301. this.save({});
  302. }
  303. }
  304. },
  305. /**
  306. * @desc : 改变用户授权数
  307. * @author : 周兴
  308. * @date : 2024/4/1
  309. */
  310. changeUserSTD(e) {
  311. let summaryInfo = this.data.summaryInfo
  312. summaryInfo.wxMaxNum = e.detail
  313. this.setData({
  314. summaryInfo: summaryInfo
  315. })
  316. // 计算金额
  317. this.countSummaryAmountSTD();
  318. },
  319. /**
  320. * @desc : 校验
  321. * @author : 周兴
  322. * @date : 2024/4/1
  323. */
  324. validData() {
  325. // 专业版校验
  326. if (this.data.gradeCode == Constants.gradeCode.PRO) {
  327. if (!this.data.readFlag) {
  328. util.showToast('请勾选阅读须知');
  329. return false;
  330. }
  331. let curentAdItem = this.data.curentAdItem;
  332. if (!curentAdItem) {
  333. util.showToast('请选择活动');
  334. return false
  335. }
  336. // 必须要选择一个授权
  337. let staffCount = this.data.staffCount
  338. if (!staffCount.maxNum && !staffCount.webMaxNum && !staffCount.wxMaxNum) {
  339. util.showToast('请选择一个授权');
  340. return false
  341. }
  342. } else {
  343. let curentAdItem = this.data.curentAdItem;
  344. if (!curentAdItem) {
  345. util.showToast('请选择活动');
  346. return false
  347. }
  348. }
  349. return true;
  350. },
  351. /**
  352. * @desc : 设置保存参数
  353. * @author : 周兴
  354. * @date : 2024/4/1
  355. */
  356. setParams(params) {
  357. let summaryInfo = this.data.summaryInfo
  358. let curentAdItem = this.data.curentAdItem
  359. let cpEndDate = this.data.cpEndDate
  360. if (!summaryInfo || !cpEndDate) return;
  361. params.endDate = summaryInfo.endDate
  362. params.userEndDate = summaryInfo.userEndDate
  363. params.gradeCode = this.data.gradeCode
  364. params.cpId = app.globalData.company.cpId
  365. params.tradeNo = this.generateRandomNo();
  366. params.wxUserId = app.globalData.user.userId
  367. params.tradeAmount = summaryInfo.amount
  368. params.buyBeginDate = summaryInfo.buyBeginDate;
  369. params.buyEndDate = summaryInfo.endDate
  370. params.extendDays = summaryInfo.extendDays;
  371. if (this.data.gradeCode == Constants.gradeCode.STD) {
  372. params.buyEndDate = summaryInfo.userEndDate
  373. params.endDate = app.globalData.company.endDate
  374. params.wxMaxNum = summaryInfo.wxMaxNum
  375. if (this.data.showVip && this.data.chooseVipFlag) {
  376. params.vip = true;
  377. } else if (!this.data.showVip && app.globalData.company.vip) {
  378. params.vip = true;
  379. }
  380. if (this.data.chooseVipFlag) {
  381. params.vip = true;
  382. }
  383. if (!summaryInfo.reCountFlag && summaryInfo.wxMaxNumSocial) {
  384. params.wxMaxNum = summaryInfo.wxMaxNum + summaryInfo.wxMaxNumSocial
  385. }
  386. } else {
  387. params.webMaxNum = summaryInfo.webMaxNum
  388. params.wxMaxNum = summaryInfo.wxMaxNum
  389. }
  390. params.buyLong = curentAdItem.activityItemName
  391. return params;
  392. },
  393. /**
  394. * @desc : 保存数据
  395. * @author : 周兴
  396. * @date : 2024/5/17
  397. */
  398. saveData(params) {
  399. return this.excute(this.data.service, this.data.service.reNewCompany, this.data.params).then(res => {
  400. if (res.data.code == Constants.SUCESS_CODE) {
  401. // 成功后跳转支付
  402. this.toPay(res.data.data);
  403. }
  404. })
  405. },
  406. /**
  407. * @desc : 查询当前用户授权数
  408. * @author : 周兴
  409. * @date : 2024/4/1
  410. */
  411. getStaffCount() {
  412. let service = app.globalData['commonService']
  413. this.excute(service, service.selectUserCount, {}).then(res => {
  414. if (res.data.code == Constants.SUCESS_CODE) {
  415. if (res.data && res.data.data) {
  416. let currentUserCount = res.data.data;
  417. this.setData({
  418. currentUserCount: currentUserCount,
  419. //服务器的时间
  420. currentDate: new Date(currentUserCount.currentDate)
  421. })
  422. }
  423. }
  424. // 获取活动
  425. this.getActivity()
  426. this.setData({
  427. loadFlag: true
  428. })
  429. });
  430. },
  431. /**
  432. * @desc : 查询活动
  433. * @author : 周兴
  434. * @date : 2024/4/1
  435. */
  436. getActivity() {
  437. let params = {
  438. appCode: Constants.APP_CODE,
  439. activityStatus: Constants.kindCode.activityStatus,
  440. cpId: app.globalData.company.cpId,
  441. gradeCode: this.data.gradeCode
  442. }
  443. // 标准版
  444. if (this.data.gradeCode == Constants.gradeCode.STD) {
  445. params.activityTypeList = [Constants.kindCode.activityGrade];
  446. } else {
  447. params.activityTypeList = [Constants.kindCode.activityGrade, Constants.kindCode.activityVip];
  448. }
  449. let service = app.globalData['activityService']
  450. this.excute(service, service.selectActivityItems, params).then(res => {
  451. if (res.data.code == Constants.SUCESS_CODE) {
  452. if (res.data && res.data.data) {
  453. let activityTable = res.data.data;
  454. // 如果是标准版,需要进行截止日期的处理
  455. if (this.data.gradeCode == Constants.gradeCode.STD) {
  456. this.setData({
  457. activityTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityGrade),
  458. vipTable: activityTable.filter(it => it.activityType == Constants.kindCode.activityVip),
  459. })
  460. this.handleDataStd(activityTable);
  461. } else {
  462. this.setData({
  463. activityTable: activityTable
  464. })
  465. }
  466. }
  467. }
  468. });
  469. },
  470. /**
  471. * @desc : 标准版处理数据
  472. * @author : 周兴
  473. * @date : 2024/4/1
  474. */
  475. handleDataStd(activityTable) {
  476. if (activityTable && activityTable.length > 0) {
  477. let item = activityTable[0]
  478. this.setData({
  479. curentAdItem: item
  480. })
  481. let summaryInfo = this.data.summaryInfo
  482. let months = item.validLong + item.extraLong
  483. //服务器的时间
  484. let endDate = this.data.currentDate.addMonths(months).addDays(-1)
  485. let dayDiffs = null;
  486. if (summaryInfo.userEndDate) {
  487. dayDiffs = new Date(summaryInfo.userEndDate).dayDiff(new Date(new Date().toDateStr()))
  488. }
  489. // 如果截止日期是空,就取活动中的截止日期
  490. if (!summaryInfo.userEndDate || !dayDiffs || dayDiffs < 0) {
  491. summaryInfo.userEndDate = endDate.toDateStr();
  492. // 重新统计,到期续费或者第一次购买用户
  493. summaryInfo.reCountFlag = true;
  494. summaryInfo.wxMaxNum = summaryInfo.wxMaxNumSocial
  495. this.setData({
  496. showVip: true
  497. })
  498. } else {
  499. // 如果没有购买,需要显示
  500. if (!app.globalData.company.vip) {
  501. this.setData({
  502. showVip: true
  503. })
  504. }
  505. }
  506. summaryInfo.buyBeginDate = this.data.currentDate.toDateStr();
  507. this.setData({
  508. summaryInfo: summaryInfo
  509. })
  510. // 计算金额
  511. this.countSummaryAmountSTD();
  512. }
  513. },
  514. /**
  515. * 生命周期函数--监听页面加载
  516. */
  517. onLoad(options) {
  518. // 升级
  519. if (options && options.upgrade) {
  520. wx.setNavigationBarTitle({
  521. title: mixins.$t('updateSpecialized'),
  522. })
  523. this.setData({
  524. gradeCode: Constants.gradeCode.PRO,
  525. upgradeFlag: true
  526. })
  527. } else {
  528. // 购买授权 和续费
  529. if (options.buyUser) {
  530. wx.setNavigationBarTitle({
  531. title: mixins.$t('buyUser'),
  532. })
  533. } else {
  534. wx.setNavigationBarTitle({
  535. title: mixins.$t('reNew'),
  536. })
  537. }
  538. this.setData({
  539. gradeCode: app.globalData.company.gradeCode
  540. })
  541. }
  542. this.setData({
  543. companyName: app.globalData.company.cpName,
  544. cpManager: app.globalData.company.cpManager,
  545. cpPhone: app.globalData.company.cpPhone,
  546. cpEndDate: app.globalData.company.endDate,
  547. webMaxNum: app.globalData.company.webMaxNum,
  548. wxMaxNum: app.globalData.company.wxMaxNum,
  549. })
  550. // 如果是标准版,需要获取用户授权数(手机)
  551. let summaryInfo = {}
  552. summaryInfo.wxMaxNum = 1
  553. summaryInfo.wxMaxNumSocial = this.data.wxMaxNum
  554. // 续费用户到期日期
  555. summaryInfo.userEndDate = app.globalData.company.userEndDate
  556. this.setData({
  557. summaryInfo: summaryInfo
  558. })
  559. // 获取活动
  560. // this.getActivity();
  561. // 获取当前用户授权数
  562. this.getStaffCount();
  563. },
  564. })