useTableData.ts 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. import { useReducer } from 'react'
  2. import { channel_analysis_select,pitcher_channel,channel_analysis_select_daily,ad_rank,bookOverview, bookRank, bookTrend, bossSummary,
  3. getAccApi, channelActive, getUserApi, channelAgainOrderTrend, channelOrderTrend, channelOverview, channelStatChannel, imageRank,
  4. Params, pitcherOverview, pitcherTrend, getRechargeHisApi, getRechargeHisYaerApi, channelOrderTrendPay, setPayApi, recoveryQueryapi, getOsoRoiApi } from '@/services/dataStatistics/dataCenter'
  5. import { useAjax } from '@/Hook/useAjax'
  6. type State = {
  7. tableDate?: string,//table搜索单日期值
  8. channel?: string,//table搜索公众号名称
  9. channels?: string[],// 多选公众号
  10. tableId?: string,//table搜索公众号ID
  11. date_range?: string,//table搜索公众号n天
  12. start?: string,//开始时间
  13. end?: string,//结束时间
  14. start15?: string,//开始时间
  15. end15?: string,//结束时间
  16. cost_time_start?: string,//消耗开始时间
  17. cost_time_end?: string,//结束时间
  18. order_time_start?: string,//订单开始时间
  19. order_time_end?: string,//结束时间
  20. cost_year?: string, // 消耗所在年(格式:2021)
  21. order_month?: string, // 订单所在月份 (格式:2021-11)
  22. pitcher?: string,//投手名称
  23. book?: any,//table搜索书名
  24. dataSource?: any[]//table数据
  25. loding?: boolean//请求
  26. order_by?: string//排序字段
  27. order?: 'asc' | 'desc',//升序降序
  28. location?: 'MP' | 'GDT',//投放位置老
  29. type?: 'MP' | 'GDT',//投放位置新
  30. targetKeys?: any[],//
  31. platform?:string,//书城
  32. selectedKeys?: any[],//
  33. tableValue?: '1' | '2',
  34. stage?: string,//期数
  35. tabKey?: string,
  36. st?:string,//充值开始
  37. et?:string,//充值结束
  38. is_video?: number,
  39. is_pitcher_self?: boolean,
  40. }
  41. export type Action = {
  42. type: 'tableDate' | 'channel'| 'channels' | 'isVideo' | 'tableId' | 'book' | 'date_range' | 'tableDateArr' | 'tableDateArr15' | 'isPitcherSelf' | 'depleteDateDateArr' | 'orderDateDateArr' | 'costYear' | 'orderMonth' | 'tabKey' | 'init' | 'setState' | 'dataSource',
  43. params?: State
  44. }
  45. export function reducer(state: State, action: Action) {
  46. let { type, params } = action
  47. let newState = JSON.parse(JSON.stringify(state))
  48. switch (type) {
  49. case 'tableDate':
  50. return { ...state, tableDate: params?.tableDate }
  51. case 'channel':
  52. return { ...state, channel: params?.channel }
  53. case 'costYear':
  54. return { ...state, cost_year: params?.cost_year }
  55. case 'orderMonth':
  56. return { ...state, order_month: params?.order_month }
  57. case 'isPitcherSelf':
  58. return { ...state, is_pitcher_self: params?.is_pitcher_self }
  59. case 'channels':
  60. return { ...state, channels: params?.channels }
  61. case 'isVideo':
  62. return { ...state, is_video: params?.is_video }
  63. case 'tableId':
  64. return { ...state, tableId: params?.tableId }
  65. case 'book':
  66. return { ...state, book: params?.book }
  67. case 'date_range':
  68. return { ...state, date_range: params?.date_range }
  69. case 'tableDateArr':
  70. return { ...state, start: params?.start, end: params?.end }
  71. case 'tableDateArr15':
  72. return { ...state, start15: params?.start15, end15: params?.end15 }
  73. case 'depleteDateDateArr':
  74. return { ...state, cost_time_start: params?.start, cost_time_end: params?.end }
  75. case 'orderDateDateArr':
  76. return { ...state, order_time_start: params?.start, order_time_end: params?.end }
  77. case 'dataSource':
  78. return { ...state, dataSource: params?.dataSource }
  79. case 'tabKey':
  80. return { ...state, tabKey: params?.tabKey }
  81. case 'setState':
  82. Object.keys(params as State).forEach((key: string) => {
  83. newState[key] = (params as State)[key]
  84. })
  85. return newState
  86. case 'init':
  87. return {}
  88. default:
  89. return state;
  90. }
  91. }
  92. const initData: State = {
  93. date_range:'7'
  94. }
  95. export default function useTableData() {
  96. const [state, dispatch] = useReducer(reducer, initData)
  97. /**广告投放详细数据 */
  98. const getChannelOverview = useAjax((params: Params) => channelOverview(params), { formatResult: true })
  99. /**今日消耗排行榜 */
  100. const getBookRank = useAjax((params: Params) => bookRank(params), { formatResult: true })
  101. /**公众号付费趋势表 */
  102. const getChannelOrderTrend = useAjax((params: Params) => channelOrderTrend(params), { formatResult: true })
  103. /**公众号付费趋势(含赔付金) */
  104. const getChannelOrderTrendPay = useAjax((params: Params) => channelOrderTrendPay(params), { formatResult: true })
  105. /** 公众号7日复重趋势*/
  106. const getChannelAgainOrderTrend = useAjax((params: Params) => channelAgainOrderTrend(params), { formatResult: true })
  107. /**公众号付费粉丝激活数据 */
  108. const getChannelActive = useAjax((params: Params) => channelActive(params), { formatResult: true })
  109. /**公众号汇总 */
  110. const getChannelStatChannel = useAjax((params: Params) => channelStatChannel(params), { formatResult: true })
  111. /**投手付费趋势 */
  112. const getPitcherTrend = useAjax((params: Params) => pitcherTrend(params), { formatResult: true })
  113. /**投手回收查询 */
  114. const getRecoveryQuery = useAjax((params: Params) => recoveryQueryapi(params), { formatResult: true })
  115. /**公众号回收查询 */
  116. const getOsoRoi = useAjax((params: Params) => getOsoRoiApi(params), { formatResult: true })
  117. /**投手总数据 */
  118. const getPitcherOverview = useAjax((params: Params) => pitcherOverview(params), { formatResult: true })
  119. /**充值历史 */
  120. const getRechargeHis = useAjax((params: Params) => getRechargeHisApi(params), { formatResult: true })
  121. /**充值历史(年) */
  122. const getRechargeHisYaer = useAjax((params: Params) => getRechargeHisYaerApi(params), { formatResult: true })
  123. /**小说付费趋势 */
  124. const getBookTrend = useAjax((params: Params) => bookTrend(params), { formatResult: true })
  125. /**小说总数据 */
  126. /**小说付总数据 */
  127. const getBookOverview = useAjax((params: Params) => bookOverview(params), { formatResult: true })
  128. /**整体概况 */
  129. const getBossSummary = useAjax((params: Params) => bossSummary(params), { formatResult: true })
  130. /**素材库 */
  131. const getImageRank = useAjax((params: Params) => imageRank(params), { formatResult: true })
  132. /**素材消耗排行榜 */
  133. const getAdrank = useAjax((params: Params) => ad_rank(params), { formatResult: true })
  134. /** 搜索公众号 */
  135. const getAccAjax = useAjax((params: Params) => getAccApi(params), { formatResult: true })
  136. /** 获取拥有用户 */
  137. const getUserAjax = useAjax((params: Params) => getUserApi(params), { formatResult: true })
  138. /** 投手投放号 */
  139. const getPitcherChannel = useAjax((params: Params) => pitcher_channel(params), { formatResult: true })
  140. /** 公众号用户充值查询 */
  141. const getChannelAnalysis = useAjax((params: Params) => channel_analysis_select(params), { formatResult: true })
  142. /** 公众号用户充值查询详情 */
  143. const getChannelAnalysisDetails = useAjax((params: Params) => channel_analysis_select_daily(params), { formatResult: true })
  144. /** 设置赔付金 */
  145. const setPay = useAjax((params: { date: string, channel: string, pay: number }) => setPayApi(params), { formatResult: true })
  146. return {
  147. state,
  148. dispatch,
  149. getChannelOverview,
  150. getChannelOrderTrend,
  151. getChannelOrderTrendPay,
  152. getChannelAgainOrderTrend,
  153. getChannelActive,
  154. getChannelStatChannel,
  155. getPitcherTrend,
  156. getRecoveryQuery,
  157. getBookRank,
  158. getBookTrend,
  159. getBookOverview,
  160. getPitcherOverview,
  161. getRechargeHis,
  162. getBossSummary,
  163. getImageRank,
  164. getAdrank,
  165. getAccAjax,
  166. getRechargeHisYaer,
  167. getUserAjax,
  168. getPitcherChannel,
  169. getChannelAnalysis,
  170. getChannelAnalysisDetails,
  171. setPay,
  172. getOsoRoi
  173. }
  174. }