activity.js 19 KB

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