hy_create_link.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //执行一个创建黑岩链接任务
  2. const CMD = {}
  3. const axios = require('axios');
  4. let get_hy_recharge_template = require('../src/api/hy/get_hy_recharge_template')
  5. let get_hy_paid_point = require('../src/api/hy/get_hy_paid_point')
  6. let get_hy_call_back_template = require('../src/api/hy/get_hy_call_back_template');
  7. const tools = require('../tools');
  8. const HttpClient = require('../src/HttpClient');
  9. const helper = require('../src/helper');
  10. //卡点
  11. function get_paid_point(book_id,kadian_name,call_back){
  12. let chapter_num = parseInt(kadian_name)
  13. if(chapter_num==0||chapter_num>10){
  14. return call_back("")
  15. }
  16. get_hy_paid_point.get_hy_paid_point(book_id,(data)=>{
  17. if(chapter_num>=data.rows.length){
  18. call_back("")
  19. }else{
  20. call_back(""+chapter_num)
  21. }
  22. })
  23. }
  24. //回传
  25. function get_call_back(huichuan_name,call_back){
  26. get_hy_call_back_template.get_callback_template((data)=>{
  27. if(data.code==200){
  28. let is_find = false
  29. for (let index = 0; index < data.data.length; index++) {
  30. const obj = data.data[index];
  31. if(obj.value==huichuan_name){
  32. is_find = true
  33. call_back(obj.key)
  34. break
  35. }
  36. }
  37. if(!is_find){
  38. call_back('6')
  39. }
  40. }else{
  41. call_back('6')
  42. }
  43. })
  44. }
  45. function get_recharge_template(book_id,chongzhi_name,call_back){
  46. get_hy_recharge_template.get_recharge_template(book_id,(data)=>{
  47. if(data.code==200){
  48. let is_find = false
  49. for (let index = 0; index < data.data.length; index++) {
  50. const obj = data.data[index];
  51. if(obj.value==chongzhi_name){
  52. is_find = true
  53. call_back(obj.key)
  54. break
  55. }
  56. }
  57. if(!is_find){
  58. call_back('0')
  59. }
  60. }else{
  61. call_back('0')
  62. }
  63. })
  64. }
  65. CMD.runTask = function(data,main_info,PlatformInfo,call_back){
  66. let group_id = main_info.group_id
  67. if(group_id==null){
  68. group_id = "35"
  69. }
  70. let tg_link_config = JSON.parse(main_info.tg_link_config)
  71. let kadian_id = tg_link_config['kadian_id']
  72. let chongzhi_id = tg_link_config['chongzhi_id']
  73. let huichuan_id = tg_link_config['huichuan_id']
  74. let chongzhi_list = JSON.parse(PlatformInfo.chongzhi)
  75. let huichuan_list = JSON.parse(PlatformInfo.huichuan)
  76. let kadian_list = JSON.parse(PlatformInfo.kadian)
  77. let chongzhi_name = null
  78. let huichuan_name = null
  79. let kadian_name = null
  80. let tg_config = {
  81. chongzhi_key:'',
  82. huichuan_key:'',
  83. kadian_key:''
  84. }
  85. for (let index = 0; index < chongzhi_list.length; index++) {
  86. const cz_obj = chongzhi_list[index];
  87. if(cz_obj.id==chongzhi_id){
  88. chongzhi_name = cz_obj.name
  89. tg_config.chongzhi_key = cz_obj.value
  90. break
  91. }
  92. }
  93. for (let index = 0; index < huichuan_list.length; index++) {
  94. const hc_obj = huichuan_list[index];
  95. if(hc_obj.id==huichuan_id){
  96. huichuan_name = hc_obj.name
  97. tg_config.huichuan_key = hc_obj.value
  98. break
  99. }
  100. }
  101. for (let index = 0; index < kadian_list.length; index++) {
  102. const kd_obj = kadian_list[index];
  103. if(kd_obj.id==kadian_id){
  104. kadian_name = kd_obj.name
  105. break
  106. }
  107. }
  108. let create_hy_link = async () =>{
  109. let topUpTemplateId = tg_config.chongzhi_key; //充值模板
  110. let passBackTemplateId = tg_config.huichuan_key; //回传模板
  111. let paidPoint = tg_config.kadian_key; //卡点
  112. console.log("tg_config:",tg_config)
  113. try{
  114. let clinet = new HttpClient()
  115. const postData = {
  116. cmd:"create_link",
  117. name:data.product_name,
  118. bookId:data.product_id,
  119. topUpTemplateId:topUpTemplateId,
  120. passBackTemplateId:passBackTemplateId,
  121. paidPoint:paidPoint,
  122. token:await tools.getHyToken()
  123. };
  124. let t_data = {
  125. "name": postData.name,
  126. "bookId": postData.bookId,
  127. "passBackTemplateId": postData.passBackTemplateId,
  128. "adPassbackTemplateId": "",
  129. "topUpTemplateId": postData.topUpTemplateId,
  130. "mediaChannel": "1",
  131. "group": group_id,
  132. "paidPoint": postData.paidPoint,
  133. "site": "5"
  134. }
  135. let res = await clinet.otherPost( helper.getHyCreateLinkOpt(postData.token) ,t_data)
  136. console.error('response:', res);
  137. let response = {
  138. "message": "create_link successfully",
  139. "received_data":{
  140. "appId":res["data"]["appId"],
  141. "launchPath":res["data"]["launchPath"],
  142. "fullPath":res["data"]["fullPath"],
  143. "wxMountLink":res["data"]["wxMountLink"]}
  144. }
  145. let params = response.received_data.fullPath.split('?')
  146. let start_page = params[0]
  147. let start_param = params[1]
  148. const linkId = start_param.match(/linkId=([^&]*)/)[1];
  149. data.promotion_id = linkId
  150. data.start_page = start_page
  151. data.start_param = start_param
  152. call_back(data)
  153. }catch(e){
  154. call_back(null)
  155. console.error('There was an error!', e);
  156. }
  157. }
  158. get_paid_point(data.book_id,kadian_name,(kadian_key)=>{
  159. tg_config.kadian_key = kadian_key
  160. create_hy_link()
  161. })
  162. }
  163. module.exports = CMD;