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. }
  112. that.setData({
  113. couponSendItem: data
  114. })
  115. })
  116. break;
  117. case 'toRegister':
  118. const that = this
  119. this.getRegisterItem().then(res => {
  120. const item = res.data.data
  121. if(item){
  122. const endDate = item.endDate
  123. const nowTime = item.nowDate
  124. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  125. that.setData({
  126. time: time,
  127. integralShareItem: item
  128. })
  129. }
  130. that.setData({
  131. integralShareItem: item
  132. })
  133. })
  134. break;
  135. }
  136. }
  137. },
  138. /**
  139. * @desc : 获取助力明细
  140. * @author : 刘尧
  141. * @date : 2024/7/30
  142. */
  143. getPowerItem() {
  144. let params = {
  145. cpId: app.globalData.company.cpId,
  146. couponId: this.data.couponItem.couponId,
  147. sendUser: app.globalData.user.userId,
  148. }
  149. let service = app.globalData['couponSendService']
  150. return this.excute(service, 'get_item', params)
  151. },
  152. formatDate(isoDateString) {
  153. // 首先,尝试将ISO 8601格式的日期字符串转换为Date对象
  154. const date = new Date(isoDateString);
  155. // 然后,使用Date对象的方法获取年、月、日、时、分、秒
  156. // 注意月份是从0开始的,所以要+1
  157. const year = date.getUTCFullYear();
  158. const month = String(date.getUTCMonth() + 1).padStart(2, '0');
  159. const day = String(date.getUTCDate()).padStart(2, '0');
  160. const hours = String(date.getUTCHours()).padStart(2, '0');
  161. const minutes = String(date.getUTCMinutes()).padStart(2, '0');
  162. const seconds = String(date.getUTCSeconds()).padStart(2, '0');
  163. // 最后,按照yyyy-MM-ddTHH:mm:ss的格式拼接字符串
  164. return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`;
  165. },
  166. /**
  167. * @desc : 获取助力明细
  168. * @author : 刘尧
  169. * @date : 2024/7/30
  170. */
  171. getRegisterItem() {
  172. let service = app.globalData['integralShareService']
  173. const params = {
  174. cpId: app.globalData.company.cpId,
  175. tacticId: this.data.integralTacticItem.tacticId,
  176. flgValid: true,
  177. integralType: Constants.integralType.invite,
  178. userId: app.globalData.user.userId,
  179. staffName: app.globalData.user.staffName,
  180. }
  181. return this.excute(service, 'select_share_item', params)
  182. },
  183. /**
  184. * @desc : 倒计时事件
  185. * @author : 刘尧
  186. * @date : 2024/7/30
  187. */
  188. onCountDownChange(e) {
  189. this.setData({
  190. timeData: e.detail,
  191. });
  192. },
  193. /**
  194. * @desc : 服务器的日期
  195. * @author : 姜永辉
  196. * @date : 2024/4/1
  197. */
  198. getCurrentDate() {
  199. let _this = this
  200. let service = app.globalData['commonService']
  201. return _this.excute(service, service.getCurrentDate, { 'DateFormat': 'yyyy-MM-dd hh:mm:ss' });
  202. },
  203. /**
  204. * @desc : 积分策略
  205. * @author : 刘尧
  206. * @date : 2024/7/25 14:32
  207. */
  208. getIntegralTactic() {
  209. let params = {}
  210. let service = app.globalData['integralTacticService']
  211. this.excute(service, service.selectByCond, params).then(res => {
  212. if (res.data.code == Constants.SUCESS_CODE) {
  213. if (res.data && res.data.data.list && res.data.data.list.length > 0) {
  214. this.setData({
  215. integralTacticItem: res.data.data.list[0],
  216. })
  217. this.getShareNumber()
  218. }
  219. }
  220. });
  221. },
  222. /**
  223. * @desc : 获取优惠劵策略
  224. * @author : 刘尧
  225. * @date : 2024/7/30 09:42
  226. */
  227. getCouponTactic() {
  228. let params = {
  229. flgValid: true
  230. }
  231. let service = app.globalData['couponService']
  232. this.excute(service, service.selectByCond, params).then(res => {
  233. const list = res.data.data.list
  234. if (list.length > 0) {
  235. this.setData({
  236. couponItem: list[0]
  237. })
  238. }
  239. });
  240. },
  241. /**
  242. * @desc : 公司积分
  243. * @author : 刘尧
  244. * @date : 2024/7/25 14:32
  245. */
  246. getIntegral() {
  247. let params = {}
  248. let service = app.globalData['integralService']
  249. this.excute(service, app.globalData.company.cpId, params).then(res => {
  250. if (res.data.code == Constants.SUCESS_CODE) {
  251. if (res.data && res.data.data) {
  252. this.setData({
  253. integral: res.data.data.integral,
  254. })
  255. }
  256. }
  257. });
  258. },
  259. /**
  260. * @desc : 优惠劵数量获取
  261. * @author : 刘尧
  262. * @date : 2024/7/29 15:54
  263. */
  264. getCouponNumber() {
  265. let params = {
  266. couponStatus: Constants.couponStatus.unused,
  267. flgValid: true
  268. }
  269. let service = app.globalData['couponUseService']
  270. this.excute(service, service.countByCond, params).then(res => {
  271. this.setData({
  272. couponNumber: res.data.data
  273. })
  274. });
  275. },
  276. /**
  277. * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
  278. * @author : 刘尧
  279. * @date : 2024/7/25 14:32
  280. */
  281. insertNewPowerItem() {
  282. let params = {
  283. cpId: app.globalData.company.cpId,
  284. couponId: this.data.couponItem.couponId,
  285. userNum: this.data.couponItem.userNum,
  286. sendStaff: app.globalData.user.staffName,
  287. sendUser: app.globalData.user.userId,
  288. flgValid: true
  289. }
  290. let service = app.globalData['couponSendService']
  291. return this.excute(service, service.insert, params)
  292. },
  293. /**
  294. * @desc : 点击立即邀请按钮调后台服务插入优惠劵发出数据
  295. * @author : 刘尧
  296. * @date : 2024/8/1 11:32
  297. */
  298. insertNewRegisterItem() {
  299. const params = {
  300. cpId: app.globalData.company.cpId,
  301. tacticId: this.data.integralTacticItem.tacticId,
  302. flgValid: true,
  303. integralType: Constants.integralType.invite,
  304. userId: app.globalData.user.userId,
  305. staffName: app.globalData.user.staffName,
  306. }
  307. let service = app.globalData['integralShareService']
  308. return this.excute(service, service.insert, params)
  309. },
  310. /**
  311. * @desc : 将两个时间进行作差计算
  312. * @author : 刘尧
  313. * @date : 2024/7/30 15:40
  314. */
  315. calculateTimeDifference(date1, date2) {
  316. // 将日期转换为时间戳
  317. const timestamp1 = date1.getTime();
  318. const timestamp2 = date2.getTime();
  319. // 计算时间戳之差
  320. const diff = Math.abs(timestamp2 - timestamp1);
  321. // 返回结果
  322. return diff;
  323. },
  324. /**
  325. * @desc : 分享调用
  326. * @author : 刘尧
  327. * @date : 2024/7/30 15:40
  328. */
  329. shareIntegral() {
  330. let service = app.globalData['integralShareService']
  331. const params = {
  332. cpId: app.globalData.company.cpId,
  333. tacticId: this.data.integralTacticItem.tacticId,
  334. flgValid: true,
  335. integralType: Constants.integralType.share,
  336. userId: app.globalData.user.userId,
  337. staffName: app.globalData.user.staffName,
  338. }
  339. return this.excute(service, service.insert, params)
  340. },
  341. /**
  342. * @desc : 获取用户剩余分享次数
  343. * @author : 刘尧
  344. * @date : 2024/7/30 15:40
  345. */
  346. getShareNumber() {
  347. let service = app.globalData['integralShareService']
  348. const params = {
  349. cpId: app.globalData.company.cpId,
  350. tacticId: this.data.integralTacticItem.tacticId,
  351. flgValid: true,
  352. integralType: Constants.integralType.share,
  353. userId: app.globalData.user.userId,
  354. staffName: app.globalData.user.staffName,
  355. }
  356. this.excute(service, 'select_share_number', params).then(res => {
  357. const integralTacticItem = this.data.integralTacticItem
  358. integralTacticItem.shareRemainderNum = integralTacticItem.shareDayNum - res.data.data
  359. this.setData({
  360. integralTacticItem: integralTacticItem
  361. })
  362. })
  363. },
  364. /**
  365. * @desc : 跳转云币规则
  366. * @author : 刘尧
  367. * @date : 2024/8/2 14:54
  368. */
  369. toIntegralRules() {
  370. let url = config.knowledge_url + '/agreement-index?agId=10002024-0802-0000-0000-000009ff303e'
  371. let toUrl = '/pages/product/product'
  372. if (url) {
  373. wx.navigateTo({
  374. url: toUrl,
  375. success: function (res) {
  376. res.eventChannel.emit('url', url);
  377. }
  378. })
  379. }
  380. },
  381. /**
  382. * 用户点击右上角分享
  383. */
  384. onShareAppMessage: async function (e) {
  385. const url = this.data.imageUrl + 'share-background.png'
  386. this.setData({
  387. cilckViewId: e.target.dataset.detail
  388. })
  389. if (e.target.dataset.detail === "toShare") {
  390. const integralTacticItem = this.data.integralTacticItem
  391. if (integralTacticItem.shareDayNum > 0) {
  392. const res = await this.shareIntegral()
  393. if (res.data.code == Constants.SUCESS_CODE) {
  394. this.getShareNumber()
  395. this.getIntegral()
  396. return {
  397. title: '分享好友获取云币',
  398. desc: '分享不停歇',
  399. path: '/pages/welcome/welcome',
  400. imageUrl: url
  401. }
  402. }
  403. } else {
  404. util.showToast('今日分享已达上限!')
  405. }
  406. }
  407. if (e.target.dataset.detail === "toRegister") {
  408. let item = await this.getRegisterItem()
  409. item = item.data.data
  410. if (item) {
  411. const that = this
  412. const endDate = item.endDate
  413. const nowTime = item.nowDate
  414. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  415. that.setData({
  416. time: time,
  417. integralShareItem: item
  418. })
  419. }
  420. if (!this.data.integralShareItem) {
  421. const res = await this.insertNewRegisterItem()
  422. if (res.data.code == Constants.SUCESS_CODE) {
  423. const that = this
  424. const data = res.data.data
  425. const endDate = data.endDate
  426. const nowTime = data.nowTime
  427. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  428. that.setData({
  429. time: time,
  430. integralShareItem: data
  431. })
  432. }
  433. }
  434. const that = this
  435. 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
  436. console.log("path",path);
  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. }
  458. this.setData({
  459. couponSendItem: item
  460. })
  461. console.log('66', !this.data.couponSendItem);
  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,
  481. imageUrl: url
  482. }
  483. }
  484. }
  485. })