share.js 14 KB

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