share.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. * @desc : onLoad生命周期回调
  60. * @date : 2024/7/30 09:11
  61. * @author : 刘尧
  62. */
  63. loadInit() {
  64. wx.hideShareMenu({})
  65. // 版本
  66. this.setData({
  67. staffName: app.globalData.user.staffName,
  68. staffPhone: app.globalData.user.staffPhone,
  69. companyName: app.globalData.company.cpName,
  70. versionName: this.data.freeVersionFlag ? mixins.$t('standardVersion') : mixins.$t('professionalVersion')
  71. })
  72. // 策略
  73. this.getIntegralTactic()
  74. // 获取优惠劵助力信息
  75. this.getCouponTactic()
  76. // 积分
  77. this.getIntegral()
  78. // 获取用户头像
  79. this.getUser()
  80. // 优惠劵
  81. this.getCouponNumber()
  82. },
  83. /**
  84. * @desc : 显示活动卡片明细
  85. * @author : 刘尧
  86. * @date : 2024/7/29 15:23
  87. */
  88. showCardItem(e) {
  89. this.setData({
  90. cilckViewId: e.currentTarget.dataset.name
  91. })
  92. if (e.currentTarget.dataset.name != 'toShare') {
  93. switch (e.currentTarget.dataset.name) {
  94. case 'toPower':
  95. this.getPowerItem().then(res => {
  96. const data = res.data.data
  97. if (data) {
  98. const that = this
  99. const endDate = data.endDate
  100. const nowTime = data.nowTime
  101. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  102. that.setData({
  103. time: time,
  104. couponSendItem: data
  105. })
  106. }
  107. })
  108. break;
  109. case 'toRegister':
  110. const that = this
  111. this.getRegisterItem().then(res => {
  112. const item = res.data.data
  113. const endDate = item.endDate
  114. const nowTime = item.nowDate
  115. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  116. that.setData({
  117. time: time,
  118. integralShareItem: item
  119. })
  120. })
  121. break;
  122. }
  123. }
  124. },
  125. /**
  126. * @desc : 获取助力明细
  127. * @author : 刘尧
  128. * @date : 2024/7/30
  129. */
  130. getPowerItem() {
  131. let params = {
  132. cpId: app.globalData.company.cpId,
  133. couponId: this.data.couponItem.couponId,
  134. sendUser: app.globalData.user.userId,
  135. }
  136. let service = app.globalData['couponSendService']
  137. return this.excute(service, 'get_item', params)
  138. },
  139. /**
  140. * @desc : 获取助力明细
  141. * @author : 刘尧
  142. * @date : 2024/7/30
  143. */
  144. getRegisterItem(){
  145. let service = app.globalData['integralShareService']
  146. const params = {
  147. cpId: app.globalData.company.cpId,
  148. tacticId: this.data.integralTacticItem.tacticId,
  149. flgValid: true,
  150. integralType: Constants.integralType.invite,
  151. userId: app.globalData.user.userId,
  152. staffName: app.globalData.user.staffName,
  153. }
  154. return this.excute(service, 'select_share_item', params)
  155. },
  156. /**
  157. * @desc : 倒计时事件
  158. * @author : 刘尧
  159. * @date : 2024/7/30
  160. */
  161. onCountDownChange(e) {
  162. this.setData({
  163. timeData: e.detail,
  164. });
  165. },
  166. /**
  167. * @desc : 服务器的日期
  168. * @author : 姜永辉
  169. * @date : 2024/4/1
  170. */
  171. getCurrentDate() {
  172. let _this = this
  173. let service = app.globalData['commonService']
  174. return _this.excute(service, service.getCurrentDate, { 'DateFormat': 'yyyy-MM-dd hh:mm:ss' });
  175. },
  176. /**
  177. * @desc : 积分策略
  178. * @author : 刘尧
  179. * @date : 2024/7/25 14:32
  180. */
  181. getIntegralTactic() {
  182. let params = {}
  183. let service = app.globalData['integralTacticService']
  184. this.excute(service, service.selectByCond, params).then(res => {
  185. if (res.data.code == Constants.SUCESS_CODE) {
  186. if (res.data && res.data.data.list && res.data.data.list.length > 0) {
  187. this.setData({
  188. integralTacticItem: res.data.data.list[0],
  189. })
  190. this.getShareNumber()
  191. }
  192. }
  193. });
  194. },
  195. /**
  196. * @desc : 获取优惠劵策略
  197. * @author : 刘尧
  198. * @date : 2024/7/30 09:42
  199. */
  200. getCouponTactic() {
  201. let params = {
  202. flgValid: true
  203. }
  204. let service = app.globalData['couponService']
  205. this.excute(service, service.selectByCond, params).then(res => {
  206. const list = res.data.data.list
  207. if (list.length > 0) {
  208. this.setData({
  209. couponItem: list[0]
  210. })
  211. }
  212. });
  213. },
  214. /**
  215. * @desc : 公司积分
  216. * @author : 刘尧
  217. * @date : 2024/7/25 14:32
  218. */
  219. getIntegral() {
  220. let params = {}
  221. let service = app.globalData['integralService']
  222. this.excute(service, app.globalData.company.cpId, params).then(res => {
  223. if (res.data.code == Constants.SUCESS_CODE) {
  224. if (res.data && res.data.data) {
  225. this.setData({
  226. integral: res.data.data.integral,
  227. })
  228. }
  229. }
  230. });
  231. },
  232. /**
  233. * @desc : 优惠劵数量获取
  234. * @author : 刘尧
  235. * @date : 2024/7/29 15:54
  236. */
  237. getCouponNumber() {
  238. let params = {
  239. couponStatus: Constants.couponStatus.unused,
  240. flgValid: true
  241. }
  242. let service = app.globalData['couponUseService']
  243. this.excute(service, service.countByCond, params).then(res => {
  244. this.setData({
  245. couponNumber: res.data.data
  246. })
  247. });
  248. },
  249. /**
  250. * @desc : 点击立即助力按钮调后台服务插入优惠劵发出数据
  251. * @author : 刘尧
  252. * @date : 2024/7/25 14:32
  253. */
  254. insertNewPowerItem() {
  255. let params = {
  256. cpId: app.globalData.company.cpId,
  257. couponId: this.data.couponItem.couponId,
  258. userNum: this.data.couponItem.userNum,
  259. sendStaff: app.globalData.user.staffName,
  260. sendUser: app.globalData.user.userId,
  261. flgValid: true
  262. }
  263. let service = app.globalData['couponSendService']
  264. return this.excute(service, service.insert, params)
  265. },
  266. /**
  267. * @desc : 点击立即邀请按钮调后台服务插入优惠劵发出数据
  268. * @author : 刘尧
  269. * @date : 2024/8/1 11:32
  270. */
  271. insertNewRegisterItem(){
  272. const params = {
  273. cpId: app.globalData.company.cpId,
  274. tacticId: this.data.integralTacticItem.tacticId,
  275. flgValid: true,
  276. integralType: Constants.integralType.invite,
  277. userId: app.globalData.user.userId,
  278. staffName: app.globalData.user.staffName,
  279. }
  280. let service = app.globalData['integralShareService']
  281. return this.excute(service, service.insert, params)
  282. },
  283. /**
  284. * @desc : 将两个时间进行作差计算
  285. * @author : 刘尧
  286. * @date : 2024/7/30 15:40
  287. */
  288. calculateTimeDifference(date1, date2) {
  289. // 将日期转换为时间戳
  290. const timestamp1 = date1.getTime();
  291. const timestamp2 = date2.getTime();
  292. // 计算时间戳之差
  293. const diff = Math.abs(timestamp2 - timestamp1);
  294. // 返回结果
  295. return diff;
  296. },
  297. /**
  298. * @desc : 分享调用
  299. * @author : 刘尧
  300. * @date : 2024/7/30 15:40
  301. */
  302. shareIntegral(){
  303. let service = app.globalData['integralShareService']
  304. const params = {
  305. cpId: app.globalData.company.cpId,
  306. tacticId: this.data.integralTacticItem.tacticId,
  307. flgValid: true,
  308. integralType: Constants.integralType.share,
  309. userId: app.globalData.user.userId,
  310. staffName: app.globalData.user.staffName,
  311. }
  312. return this.excute(service, service.insert, params)
  313. },
  314. /**
  315. * @desc : 获取用户剩余分享次数
  316. * @author : 刘尧
  317. * @date : 2024/7/30 15:40
  318. */
  319. getShareNumber(){
  320. let service = app.globalData['integralShareService']
  321. const params = {
  322. cpId: app.globalData.company.cpId,
  323. tacticId: this.data.integralTacticItem.tacticId,
  324. flgValid: true,
  325. integralType: Constants.integralType.share,
  326. userId: app.globalData.user.userId,
  327. staffName: app.globalData.user.staffName,
  328. }
  329. this.excute(service, 'select_share_number', params).then(res => {
  330. const integralTacticItem = this.data.integralTacticItem
  331. integralTacticItem.shareRemainderNum = integralTacticItem.shareDayNum - res.data.data
  332. this.setData({
  333. integralTacticItem: integralTacticItem
  334. })
  335. })
  336. },
  337. /**
  338. * 用户点击右上角分享
  339. */
  340. onShareAppMessage: async function(e) {
  341. const url = this.data.imageUrl + 'share-background.png'
  342. this.setData({
  343. cilckViewId: e.target.dataset.detail
  344. })
  345. if (e.target.dataset.detail === "toShare") {
  346. const integralTacticItem = this.data.integralTacticItem
  347. if(integralTacticItem.shareDayNum > 0){
  348. const res = await this.shareIntegral()
  349. if (res.data.code == Constants.SUCESS_CODE) {
  350. this.getShareNumber()
  351. this.getIntegral()
  352. return {
  353. title: '分享好友获取云币',
  354. desc: '分享不停歇',
  355. path: '/pages/welcome/welcome',
  356. imageUrl: url
  357. }
  358. }
  359. }else {
  360. util.showToast('今日分享已达上限!')
  361. }
  362. }
  363. if (e.target.dataset.detail === "toRegister") {
  364. let item = await this.getRegisterItem()
  365. item = item.data.data
  366. if(item){
  367. const that = this
  368. const endDate = item.endDate
  369. const nowTime = item.nowDate
  370. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  371. that.setData({
  372. time: time,
  373. integralShareItem: item
  374. })
  375. }
  376. if(!this.data.integralShareItem){
  377. const res = await this.insertNewRegisterItem()
  378. if (res.data.code == Constants.SUCESS_CODE) {
  379. const that = this
  380. const data = res.data.data
  381. const endDate = data.endDate
  382. const nowTime = data.nowDate
  383. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  384. that.setData({
  385. time: time,
  386. integralShareItem: data
  387. })
  388. return {
  389. title: '邀请好友,互利共赢',
  390. desc: '邀请注册拿云币',
  391. path: '/pages/welcome/welcome?cpIdForm=' + app.globalData.company.cpId + '&shareType=1&shareEndDate=' + endDate + '&staffNameFrom=' + app.globalData.user.staffName + 'userIdForm=' + app.globalData.user.userId,
  392. imageUrl: url
  393. }
  394. }
  395. }else {
  396. return {
  397. title: '邀请好友,互利共赢',
  398. desc: '邀请注册拿云币',
  399. path: '/pages/welcome/welcome?cpIdForm=' + app.globalData.company.cpId + '&shareType=1&shareEndDate=' + that.data.integralShareItem.endDate + '&staffNameFrom=' + app.globalData.user.staffName + 'userIdForm=' + app.globalData.user.userId,
  400. imageUrl: url
  401. }
  402. }
  403. }
  404. if (e.target.dataset.detail === "toPower") {
  405. const couponDesc = this.data.couponItem.couponDesc
  406. let item = await this.getPowerItem()
  407. item = item.data.data
  408. if (item) {
  409. const that = this
  410. const endDate = item.endDate
  411. const nowTime = item.nowTime
  412. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  413. that.setData({
  414. time: time,
  415. couponSendItem: item
  416. })
  417. }
  418. if(!this.data.couponSendItem){
  419. const that = this
  420. const res = await this.insertNewPowerItem()
  421. if (res.data.code == Constants.SUCESS_CODE) {
  422. const data = res.data.data
  423. const endDate = data.endDate
  424. const nowTime = data.nowTime
  425. const time = that.calculateTimeDifference(new Date(nowTime), new Date(endDate))
  426. that.setData({
  427. time: time,
  428. couponSendItem: data
  429. })
  430. }
  431. }
  432. const that = this
  433. return {
  434. title: couponDesc,
  435. desc: '助力拿福利',
  436. 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,
  437. imageUrl: url
  438. }
  439. }
  440. }
  441. })