activity.js 21 KB

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