share.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. // package-basic-data/pages/share/share.js
  2. const Constants = require('@/utils/Constants.js');
  3. const mixins = require('@/mixins/index.js');
  4. const config = require('@/config/config.js');
  5. const util = require('@/utils/util.js')
  6. const app = getApp()
  7. Page({
  8. mixins: [mixins],
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. routeObjName: 'share',
  14. staffName: '',
  15. staffPhone: '',
  16. companyName: '',
  17. versionName: '',
  18. gradeCode: null,
  19. integral: 0,
  20. couponNumber: 0,
  21. cilckViewId: 'toShare',
  22. integralTacticItem: {},
  23. avatarUrl: config.image_url + '/static/img/' + '/order_billing_detail_01.png',
  24. couponItem: undefined,
  25. time: 129600000,
  26. timeData: {},
  27. couponSendItem: undefined,
  28. integralShareItem: undefined,
  29. settingFlg: false,
  30. },
  31. /**
  32. * @desc : 头像
  33. * @date : 2024/7/1 15:49
  34. * @author : 姜永辉
  35. */
  36. getUser() {
  37. let service = app.globalData['oauthService']
  38. return this.excute(service, service.getUser + '/' + app.globalData.user.userId, {}).then(res => {
  39. if (res.data.code == Constants.SUCESS_CODE) {
  40. let avatarUrl = res.data.data.userImage || this.data.defaultAvatarUrl
  41. this.setData({
  42. avatarUrl: avatarUrl
  43. })
  44. }
  45. });
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad(options) {
  51. // 从我的进入 和 首页进入 不同
  52. if (options.settingFlg) {
  53. this.setData({
  54. settingFlg: options.settingFlg
  55. })
  56. }
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow() {
  62. // 积分
  63. this.getIntegral()
  64. },
  65. /**
  66. * @desc : onLoad生命周期回调
  67. * @date : 2024/7/30 09:11
  68. * @author : 刘尧
  69. */
  70. loadInit() {
  71. wx.hideShareMenu({})
  72. // 版本
  73. this.setData({
  74. staffName: app.globalData.user.staffName,
  75. staffPhone: app.globalData.user.staffPhone,
  76. companyName: app.globalData.company.cpName,
  77. versionName: this.data.freeVersionFlag ? mixins.$t('standardVersion') : mixins.$t('professionalVersion')
  78. })
  79. // 策略
  80. this.getIntegralTactic()
  81. // 获取优惠劵助力信息
  82. this.getCouponTactic()
  83. // 获取用户头像
  84. this.getUser()
  85. // 优惠劵
  86. this.getCouponNumber()
  87. },
  88. /**
  89. * @desc : 显示活动卡片明细
  90. * @author : 刘尧
  91. * @date : 2024/7/29 15:23
  92. */
  93. showCardItem(e) {
  94. this.setData({
  95. cilckViewId: e.currentTarget.dataset.name
  96. })
  97. if (e.currentTarget.dataset.name != 'toShare') {
  98. switch (e.currentTarget.dataset.name) {
  99. case 'toPower':
  100. this.getPowerItem().then(res => {
  101. const data = res.data.data
  102. if (data) {
  103. const that = this
  104. const endDate = data.endDate
  105. const nowTime = data.nowTime
  106. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  107. that.setData({
  108. time: time,
  109. couponSendItem: data
  110. })
  111. }else{
  112. this.setData({
  113. couponSendItem: null
  114. })
  115. }
  116. })
  117. break;
  118. case 'toRegister':
  119. const that = this
  120. this.getRegisterItem().then(res => {
  121. const item = res.data.data
  122. if(item){
  123. const endDate = item.endDate
  124. const nowTime = item.nowDate
  125. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  126. that.setData({
  127. time: time,
  128. integralShareItem: item
  129. })
  130. }
  131. that.setData({
  132. integralShareItem: item
  133. })
  134. })
  135. break;
  136. }
  137. }
  138. },
  139. /**
  140. * @desc : 获取助力明细
  141. * @author : 刘尧
  142. * @date : 2024/7/30
  143. */
  144. getPowerItem() {
  145. let params = {
  146. cpId: app.globalData.company.cpId,
  147. couponId: this.data.couponItem.couponId,
  148. sendUser: app.globalData.user.userId,
  149. }
  150. let service = app.globalData['couponSendService']
  151. return this.excute(service, 'get_item', params)
  152. },
  153. formatDate(isoDateString) {
  154. // 首先,尝试将ISO 8601格式的日期字符串转换为Date对象
  155. const date = new Date(isoDateString);
  156. // 然后,使用Date对象的方法获取年、月、日、时、分、秒
  157. // 注意月份是从0开始的,所以要+1
  158. const year = date.getUTCFullYear();
  159. const month = String(date.getUTCMonth() + 1).padStart(2, '0');
  160. const day = String(date.getUTCDate()).padStart(2, '0');
  161. const hours = String(date.getUTCHours()).padStart(2, '0');
  162. const minutes = String(date.getUTCMinutes()).padStart(2, '0');
  163. const seconds = String(date.getUTCSeconds()).padStart(2, '0');
  164. // 最后,按照yyyy-MM-ddTHH:mm:ss的格式拼接字符串
  165. return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
  166. },
  167. /**
  168. * @desc : 获取助力明细
  169. * @author : 刘尧
  170. * @date : 2024/7/30
  171. */
  172. getRegisterItem() {
  173. let service = app.globalData['integralShareService']
  174. const params = {
  175. cpId: app.globalData.company.cpId,
  176. tacticId: this.data.integralTacticItem.tacticId,
  177. flgValid: true,
  178. integralType: Constants.integralType.invite,
  179. userId: app.globalData.user.userId,
  180. staffName: app.globalData.user.staffName,
  181. }
  182. return this.excute(service, 'select_share_item', params)
  183. },
  184. /**
  185. * @desc : 倒计时事件
  186. * @author : 刘尧
  187. * @date : 2024/7/30
  188. */
  189. onCountDownChange(e) {
  190. this.setData({
  191. timeData: e.detail,
  192. });
  193. },
  194. /**
  195. * @desc : 服务器的日期
  196. * @author : 姜永辉
  197. * @date : 2024/4/1
  198. */
  199. getCurrentDate() {
  200. let _this = this
  201. let service = app.globalData['commonService']
  202. return _this.excute(service, service.getCurrentDate, { 'DateFormat': 'yyyy-MM-dd hh:mm:ss' });
  203. },
  204. /**
  205. * @desc : 积分策略
  206. * @author : 刘尧
  207. * @date : 2024/7/25 14:32
  208. */
  209. getIntegralTactic() {
  210. let params = {}
  211. let service = app.globalData['integralTacticService']
  212. this.excute(service, service.selectByCond, params).then(res => {
  213. if (res.data.code == Constants.SUCESS_CODE) {
  214. if (res.data && res.data.data.list && res.data.data.list.length > 0) {
  215. this.setData({
  216. integralTacticItem: res.data.data.list[0],
  217. })
  218. this.getShareNumber()
  219. }
  220. }
  221. });
  222. },
  223. /**
  224. * @desc : 获取优惠劵策略
  225. * @author : 刘尧
  226. * @date : 2024/7/30 09:42
  227. */
  228. getCouponTactic() {
  229. let params = {
  230. flgValid: true
  231. }
  232. let service = app.globalData['couponService']
  233. this.excute(service, service.selectByCond, params).then(res => {
  234. const list = res.data.data.list
  235. if (list.length > 0) {
  236. this.setData({
  237. couponItem: list[0]
  238. })
  239. }
  240. });
  241. },
  242. /**
  243. * @desc : 公司积分
  244. * @author : 刘尧
  245. * @date : 2024/7/25 14:32
  246. */
  247. getIntegral() {
  248. let params = {}
  249. let service = app.globalData['integralService']
  250. this.excute(service, app.globalData.company.cpId, params).then(res => {
  251. if (res.data.code == Constants.SUCESS_CODE) {
  252. if (res.data && res.data.data) {
  253. this.setData({
  254. integral: res.data.data.integral,
  255. })
  256. }
  257. }
  258. });
  259. },
  260. /**
  261. * @desc : 优惠劵数量获取
  262. * @author : 刘尧
  263. * @date : 2024/7/29 15:54
  264. */
  265. getCouponNumber() {
  266. let params = {
  267. couponStatus: Constants.couponStatus.unused,
  268. flgValid: true
  269. }
  270. let service = app.globalData['couponUseService']
  271. this.excute(service, service.countByCond, params).then(res => {
  272. this.setData({
  273. couponNumber: res.data.data
  274. })
  275. });
  276. },
  277. /**
  278. * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
  279. * @author : 刘尧
  280. * @date : 2024/7/25 14:32
  281. */
  282. insertNewPowerItem() {
  283. let params = {
  284. cpId: app.globalData.company.cpId,
  285. couponId: this.data.couponItem.couponId,
  286. userNum: this.data.couponItem.userNum,
  287. sendStaff: app.globalData.user.staffName,
  288. sendUser: app.globalData.user.userId,
  289. flgValid: true
  290. }
  291. let service = app.globalData['couponSendService']
  292. return this.excute(service, service.insert, params)
  293. },
  294. /**
  295. * @desc : 点击立即邀请按钮调后台服务插入优惠劵发出数据
  296. * @author : 刘尧
  297. * @date : 2024/8/1 11:32
  298. */
  299. insertNewRegisterItem() {
  300. const params = {
  301. cpId: app.globalData.company.cpId,
  302. tacticId: this.data.integralTacticItem.tacticId,
  303. flgValid: true,
  304. integralType: Constants.integralType.invite,
  305. userId: app.globalData.user.userId,
  306. staffName: app.globalData.user.staffName,
  307. }
  308. let service = app.globalData['integralShareService']
  309. return this.excute(service, service.insert, params)
  310. },
  311. /**
  312. * @desc : 将两个时间进行作差计算
  313. * @author : 刘尧
  314. * @date : 2024/7/30 15:40
  315. */
  316. calculateTimeDifference(date1, date2) {
  317. // 将日期转换为时间戳
  318. const timestamp1 = date1.getTime();
  319. const timestamp2 = date2.getTime();
  320. // 计算时间戳之差
  321. const diff = Math.abs(timestamp2 - timestamp1);
  322. // 返回结果
  323. return diff;
  324. },
  325. /**
  326. * @desc : 分享调用
  327. * @author : 刘尧
  328. * @date : 2024/7/30 15:40
  329. */
  330. shareIntegral() {
  331. let service = app.globalData['integralShareService']
  332. const params = {
  333. cpId: app.globalData.company.cpId,
  334. tacticId: this.data.integralTacticItem.tacticId,
  335. flgValid: true,
  336. integralType: Constants.integralType.share,
  337. userId: app.globalData.user.userId,
  338. staffName: app.globalData.user.staffName,
  339. }
  340. return this.excute(service, service.insert, params)
  341. },
  342. /**
  343. * @desc : 获取用户剩余分享次数
  344. * @author : 刘尧
  345. * @date : 2024/7/30 15:40
  346. */
  347. getShareNumber() {
  348. let service = app.globalData['integralShareService']
  349. const params = {
  350. cpId: app.globalData.company.cpId,
  351. tacticId: this.data.integralTacticItem.tacticId,
  352. flgValid: true,
  353. integralType: Constants.integralType.share,
  354. userId: app.globalData.user.userId,
  355. staffName: app.globalData.user.staffName,
  356. }
  357. this.excute(service, 'select_share_number', params).then(res => {
  358. const integralTacticItem = this.data.integralTacticItem
  359. integralTacticItem.shareRemainderNum = integralTacticItem.shareDayNum - res.data.data
  360. this.setData({
  361. integralTacticItem: integralTacticItem
  362. })
  363. })
  364. },
  365. /**
  366. * @desc : 跳转云币规则
  367. * @author : 刘尧
  368. * @date : 2024/8/2 14:54
  369. */
  370. toIntegralRules() {
  371. let url = config.knowledge_url + '/agreement-index?agId=10002024-0802-0000-0000-000009ff303e'
  372. let toUrl = '/pages/product/product'
  373. if (url) {
  374. wx.navigateTo({
  375. url: toUrl,
  376. success: function (res) {
  377. res.eventChannel.emit('url', url);
  378. }
  379. })
  380. }
  381. },
  382. /**
  383. * 用户点击右上角分享
  384. */
  385. onShareAppMessage: async function (e) {
  386. const url = this.data.imageUrl + 'share-background.png'
  387. this.setData({
  388. cilckViewId: e.target.dataset.detail
  389. })
  390. if (e.target.dataset.detail === "toShare") {
  391. const integralTacticItem = this.data.integralTacticItem
  392. if (integralTacticItem.shareDayNum > 0) {
  393. const res = await this.shareIntegral()
  394. if (res.data.code == Constants.SUCESS_CODE) {
  395. this.getShareNumber()
  396. this.getIntegral()
  397. return {
  398. title: '分享好友获取云币',
  399. desc: '分享不停歇',
  400. path: '/pages/welcome/welcome',
  401. imageUrl: url
  402. }
  403. }
  404. } else {
  405. util.showToast('今日分享已达上限!')
  406. }
  407. }
  408. if (e.target.dataset.detail === "toRegister") {
  409. let item = await this.getRegisterItem()
  410. item = item.data.data
  411. if (item) {
  412. const that = this
  413. const endDate = item.endDate
  414. const nowTime = item.nowDate
  415. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  416. that.setData({
  417. time: time,
  418. integralShareItem: item
  419. })
  420. }
  421. if (!this.data.integralShareItem) {
  422. const res = await this.insertNewRegisterItem()
  423. if (res.data.code == Constants.SUCESS_CODE) {
  424. const that = this
  425. const data = res.data.data
  426. const endDate = data.endDate
  427. const nowTime = data.nowTime
  428. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  429. that.setData({
  430. time: time,
  431. integralShareItem: data
  432. })
  433. }
  434. }
  435. const that = this
  436. let path = '/pages/welcome/welcome?cpIdFrom=' + app.globalData.company.cpId + '&shareType=1&shareEndDate=' + that.data.integralShareItem.endDate + '&staffNameFrom=' + app.globalData.user.staffName + '&userIdFrom=' + app.globalData.user.userId + '&shareId=' + that.data.integralShareItem.shareId
  437. return {
  438. title: '邀请好友,互利共赢',
  439. desc: '邀请注册拿云币',
  440. path: path,
  441. imageUrl: url
  442. }
  443. }
  444. if (e.target.dataset.detail === "toPower") {
  445. const couponDesc = this.data.couponItem.couponDesc
  446. let item = await this.getPowerItem()
  447. item = item.data.data
  448. if (item) {
  449. const that = this
  450. const endDate = item.endDate
  451. const nowTime = item.nowTime
  452. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  453. that.setData({
  454. time: time,
  455. couponSendItem: item
  456. })
  457. }else{
  458. this.setData({
  459. couponSendItem: null
  460. })
  461. }
  462. if (!this.data.couponSendItem) {
  463. const that = this
  464. const res = await this.insertNewPowerItem()
  465. if (res.data.code == Constants.SUCESS_CODE) {
  466. const data = res.data.data
  467. const endDate = data.endDate
  468. const nowTime = data.nowTime
  469. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  470. that.setData({
  471. time: time,
  472. couponSendItem: data
  473. })
  474. }
  475. }
  476. const that = this
  477. return {
  478. title: couponDesc,
  479. desc: '助力拿福利',
  480. path: '/package-basic-data/pages/share-power/share-power?cpId=' + app.globalData.company.cpId + '&couponId=' + that.data.couponItem.couponId + '&sendId=' + that.data.couponSendItem.sendId + '&discount=' + that.data.couponItem.discount + '&userIdForm=' + app.globalData.user.userId + '&userNum=' + this.data.couponItem.userNum + '&staffName=' + app.globalData.user.staffName,
  481. imageUrl: url
  482. }
  483. }
  484. }
  485. })