useAdAuthorize.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import { useAjax } from '@/Hook/useAjax'
  2. import {
  3. LoginProps, loginAdApi, updateChannelInfoApi, updateChannelInfoPrpps, loginResultApi, allOfLoginUserApi,
  4. adsChannelAccountAdqApi, adsChannelAccountMpApi, adqPrpps, uploadLoginAdApi, AddAnd, addAndCreateApi, adsSharePageApi,
  5. getSharePageDetailApi, getSharePageApi, getShare, adsSharePageEditApi, allOfAccountApi, addPlanApi, adsPlan, getAdsPlanApi,
  6. adsPlanList, getAdsPlanLogApi, adsPlanLogList, getAdsPlanXqApi, adsChannelAccountAdqAllApi, adsChannelAccountMpAllApi, getUserInfoApi,
  7. setCopyPlanApi, CopyPlan, delBatchAjax, delLogBatchAjax, getAdsTableConfigApi, getUserConfigApi, updateUserConfigApi, allOfAccountGodsApi,
  8. allOfAccountGodsDetailApi,delSharePageApi, allWechatInfoApi, allDataSourceApi
  9. } from '@/services/operating/adAuthorize'
  10. import { adqCollect, mpCollect } from '@/services/operating/adWeChat'
  11. import moment from 'moment'
  12. import { Dispatch, useReducer } from 'react'
  13. import { CreatePlan } from '../../pages/launchSystem/launchManage/req'
  14. let area = ["340100", "340200", "340300", "340400", "340500", "340600", "340700", "340800", "341000", "341100", "341200", "341300", "341500", "341600", "341700", "341800", "110000", "500000", "350100", "350200", "350300", "350400", "350500", "350600", "350700", "350800", "350900", "620100", "620200", "620300", "620400", "620500", "620600", "620700", "620800", "620900", "621000", "621100", "621200", "622900", "623000", "440100", "440200", "440300", "440400", "440500", "440600", "440700", "440800", "440900", "441200", "441300", "441400", "441500", "441600", "441700", "441800", "441900", "442000", "445100", "445200", "445300", "450100", "450200", "450300", "450400", "450500", "450600", "450700", "450800", "450900", "451000", "451100", "451200", "451300", "451400", "520100", "520200", "520300", "520400", "520500", "520600", "522300", "522600", "522700", "460100", "460200", "460300", "469001", "469002", "469003", "469005", "469006", "469007", "469021", "469022", "469023", "469024", "469025", "469026", "469027", "469028", "469029", "469030", "130100", "130200", "130300", "130400", "130500", "130600", "130700", "130800", "130900", "131000", "131100", "410100", "410200", "410300", "410400", "410500", "410600", "410700", "410800", "410900", "411000", "411100", "411200", "411300", "411400", "411500", "411600", "411700", "419001", "230100", "230200", "230300", "230400", "230500", "230600", "230700", "230800", "230900", "231000", "231100", "231200", "232700", "420100", "420200", "420300", "420500", "420600", "420700", "420800", "420900", "421000", "421100", "421200", "421300", "422800", "429004", "429005", "429006", "429021", "430100", "430200", "430300", "430400", "430500", "430600", "430700", "430800", "430900", "431000", "431100", "431200", "431300", "433100", "220100", "220200", "220300", "220400", "220500", "220600", "220700", "220800", "222400", "320100", "320200", "320300", "320400", "320500", "320600", "320700", "320800", "320900", "321000", "321100", "321200", "321300", "360100", "360200", "360300", "360400", "360500", "360600", "360700", "360800", "360900", "361000", "361100", "210100", "210200", "210300", "210400", "210500", "210600", "210700", "210800", "210900", "211000", "211100", "211200", "211300", "211400", "150100", "150200", "150300", "150400", "150500", "150600", "150700", "150800", "150900", "152200", "152500", "152900", "640100", "640200", "640300", "640400", "640500", "630100", "630200", "632200", "632300", "632500", "632600", "632700", "632800", "370100", "370200", "370300", "370400", "370500", "370600", "370700", "370800", "370900", "371000", "371100", "371200", "371300", "371400", "371500", "371600", "371700", "610100", "610200", "610300", "610400", "610500", "610600", "610700", "610800", "610900", "611000", "140100", "140200", "140300", "140400", "140500", "140600", "140700", "140800", "140900", "141000", "141100", "310000", "510100", "510300", "510400", "510500", "510600", "510700", "510800", "510900", "511000", "511100", "511300", "511400", "511500", "511600", "511700", "511800", "511900", "512000", "513200", "513300", "513400", "120000", "540100", "540200", "542100", "542200", "542400", "542500", "542600", "650100", "650200", "652100", "652200", "652300", "652700", "652800", "652900", "653000", "653100", "653200", "654000", "654200", "654300", "659001", "659002", "659003", "659004", "659005", "659006", "659007", "659008", "659009", "530100", "530300", "530400", "530500", "530600", "530700", "530800", "530900", "532300", "532500", "532600", "532800", "532900", "533100", "533300", "533400", "330100", "330200", "330300", "330400", "330500", "330600", "330700", "330800", "330900", "331000", "331100"]
  15. interface State extends CreatePlan {
  16. }
  17. export const initData: State = {
  18. first: {
  19. pos_type: 999,
  20. product: {
  21. product_type: 'PRODUCTTYPE_WECHAT',
  22. product_id: '',
  23. product_info: '',
  24. },
  25. campaign: {
  26. cid: 0,
  27. ctype: 'CAMPAIGNTYPE_AUCTION', //购买方式 CAMPAIGNTYPE_AUCTION=竞价购买 CAMPAIGNTYPE_SCHEDULE=合约购买
  28. cname: '',
  29. can_mix_product: 1,
  30. end_time: 0,
  31. begin_time: moment().startOf('day').add(5, 'M').unix(),
  32. exposure_frequency: 8
  33. },
  34. sub_product: {
  35. subordinate_product_id: '',
  36. product_type: 'PRODUCTTYPE_WECHAT',
  37. product_id: '',
  38. spname: ''
  39. },
  40. target_groups: [
  41. {
  42. target_group: {
  43. mp_conf: `{}`,
  44. },
  45. ad_groups: [{
  46. ad_group: {
  47. bid_strategy: 2, //优先跑量
  48. aid: 0,
  49. backup_aid: 0,
  50. aname: '', //广告名称 地域 性别 年龄组装
  51. timeset: '',
  52. product_id: "",//公众号appid
  53. product_type: 'PRODUCTTYPE_WECHAT',
  54. end_time: 0,
  55. begin_time: moment().startOf('day').add(5, 'M').unix(),
  56. strategy_opt: '{"bid_objective":7,"bid_action_type":7,"bid_objective_mode":1}',//"{\"bid_action_type\":1,\"bid_objective\":2,\"bid_objective_mode\":1}",
  57. bid: 10, //出价26274 = 262.74
  58. change_bid: 0,
  59. budget: 100000, //每日预算 5010表示50.1
  60. day_budget: 100000,//每日预算
  61. contract_flag: 2,
  62. pos_type: 999,
  63. exposure_frequency: 8,
  64. poi: "",
  65. expand_targeting_switch: 'EXPAND_TARGETING_SWITCH_CLOSE', // 自动扩量
  66. expand_targeting_setting: "[]",
  67. cold_start_audience_id_list: '[]',
  68. time_mode: 0,
  69. multi_slot_type: 0,
  70. auto_acquisition_switch: 0, //一键起量 0=关 1=开
  71. auto_acquisition_budget: null, //探索预算
  72. tracking_sourceid: ''
  73. },
  74. ad_target: {
  75. mid: 0,
  76. ad_behavior: '[{"in_action_list":[],"not_in_action_list":[101]}]',//in_action_list = 再营销 not_in_action_list = 排除营销,101 已关注你的公众号,301 曾领取你的微信卡券,401 曾对你的公众号广告感兴趣,501曾对你的朋友圈广告感兴趣,801已添加过企业微信
  77. education: "[]",//学历"[\"DOCTOR\",\"MASTER\",\"BACHELOR\",\"JUNIOR_COLLEGE\",\"SENIOR\",\"JUNIOR\",\"PRIMARY\"]" 依次代表 博士,硕士,本科,专科,高中,初中,小学
  78. device_price: "[]",//手机价格 "[\"1~14\",\"15~24\",\"25~34\",\"35~44\",\"45~100\"]" 依次代表1500元以下 1500~2500元 2500~3500元 3500~4500元 4500元以上
  79. area: area, //地域
  80. travel_area: "[]",
  81. area_type: "area",
  82. gender: JSON.stringify(['MALE']), //性别 MALE=男 FEMALE = 女 ""=全部
  83. sns_optimal_user_group: "",
  84. age: '["14~66"]', //年龄
  85. device_brand_model: "[]",//手机品牌 定向正直1 排除负值-1
  86. businessinterest: "[]",
  87. app_behavior: "{}",
  88. os: "[]",//手机系统 "[\"IOS\",\"ANDROID\"]"
  89. marriage_status: "[]",
  90. wechatflowclass: "[]",
  91. connection: "[]",//联网方式 "[\"WIFI\",\"NET4G\",\"NET3G\",\"NET2G\"]"
  92. telcom: "[]",//运营商 "[\"CTC\",\"CMC\",\"CUC\"]" CTC=电信 CMC=移动 CUC=联通
  93. payment: "[]",
  94. game_consumption_level: "[]",
  95. custom_poi: "[]",
  96. weapp_version: '{"min_ios_version":0,"min_android_version":0,"min_ios_os_version":"","min_android_os_version":""}',
  97. oversea: "[]",
  98. in_dmp_audience: "", //人群包
  99. not_in_dmp_audience: "[]",
  100. behavior_interest: "{}",
  101. star_fans: "",
  102. }
  103. }]
  104. }
  105. ],
  106. expected_ret: 0,
  107. materials: [{ tname: "", crt_size: 929 }],
  108. },
  109. second: {
  110. cid: '',
  111. pos_type: 999,
  112. page_name: '',//落地页名称
  113. materials: [{
  114. rid: '',
  115. cid: '',
  116. desc: '',
  117. link_hidden: 0,
  118. link_name: "阅读小说",
  119. is_show_friend: 0,
  120. show_first_comment: 0,
  121. interaction: 0,
  122. crt_size: 1480,
  123. tname: '',
  124. page_id: '',
  125. page_id_str: '',
  126. link_page_id: 2225950003,
  127. link_page_id_str: "0",
  128. page_type: 4,
  129. link_page_type: 4,
  130. dest_conf: "{}",
  131. ext_click_url: "",
  132. ext_exposure_url: "",
  133. dest_url: "",
  134. appmsg_info: "{}",
  135. title: "",
  136. scheme_url: "",
  137. is_hidden_comment: 0,
  138. crt_info: '',
  139. sns_dynamic_show_type: 0,
  140. sns_dynamic_show_text: "",
  141. }],
  142. product: {
  143. product_id: "",
  144. product_type: "PRODUCTTYPE_WECHAT",
  145. }
  146. },
  147. }
  148. export type Action = {
  149. type: 'setFirst' | 'setSecond' | 'setInit' | 'init',
  150. params: State
  151. }
  152. export function reducer(state: State, action: Action) {
  153. let { type, params } = action
  154. switch (type) {
  155. case 'setFirst':
  156. return { ...state, first: params?.first }
  157. case 'setSecond':
  158. return { ...state, second: params?.second }
  159. case 'setInit':
  160. return { ...state, ...params }
  161. case 'init':
  162. return { ...state, ...initData }
  163. default:
  164. return state;
  165. }
  166. }
  167. export default function useWeChat() {
  168. const [state, dispatch]: [state: State, dispatch: Dispatch<Action>] = useReducer(reducer, initData)
  169. const loginAd = useAjax((props: LoginProps) => loginAdApi(props), { formatResult: true })
  170. const uploadLoginAd = useAjax((props: LoginProps) => uploadLoginAdApi(props), { formatResult: true })
  171. const loginResult = useAjax((code: string) => loginResultApi(code), { formatResult: true })
  172. const updateChannelInfo = useAjax((props: updateChannelInfoPrpps) => updateChannelInfoApi(props), { formatResult: true })
  173. const allOfLoginUser = useAjax(() => allOfLoginUserApi(), { formatResult: true })
  174. const adsChannelAccountAdq = useAjax((props: adqPrpps) => adsChannelAccountAdqApi(props), { formatResult: true })
  175. const adsChannelAccountMp = useAjax((props: adqPrpps) => adsChannelAccountMpApi(props), { formatResult: true })
  176. const adsChannelAccountAdq1 = useAjax((props: adqPrpps) => adsChannelAccountAdqApi(props), { formatResult: true })
  177. const adsChannelAccountMp1 = useAjax((props: adqPrpps) => adsChannelAccountMpApi(props), { formatResult: true })
  178. const adsChannelAccountAdqAll = useAjax((channelId: number) => adsChannelAccountAdqAllApi(channelId), { formatResult: true })
  179. const adsChannelAccountMpAll = useAjax((channelId: number) => adsChannelAccountMpAllApi(channelId), { formatResult: true })
  180. const addAndCreate = useAjax((props: AddAnd) => addAndCreateApi(props), { formatResult: true })
  181. const adsSharePage = useAjax((props: any) => adsSharePageApi(props), { formatResult: true })
  182. const getSharePageDetail = useAjax((pageId: number) => getSharePageDetailApi(pageId), { formatResult: true })
  183. const getSharePage = useAjax((props: getShare) => getSharePageApi(props), { formatResult: true })
  184. const delSharePage = useAjax((props: string) => delSharePageApi(props), { formatResult: true })
  185. const adsSharePageEdit = useAjax((props: any) => adsSharePageEditApi(props), { formatResult: true })
  186. const allOfAccount = useAjax((props: any) => allOfAccountApi(props), { formatResult: true })
  187. const allWechatInfo = useAjax((props: any) => allWechatInfoApi(props), { formatResult: true })
  188. const allDataSource = useAjax((props: any) => allDataSourceApi(props), { formatResult: true })
  189. const addPlan = useAjax((props: adsPlan) => addPlanApi(props), { formatResult: true })
  190. const getAdsPlan = useAjax((props: adsPlanList) => getAdsPlanApi(props), { formatResult: true })
  191. const getAdsPlanLog = useAjax((props: adsPlanLogList) => getAdsPlanLogApi(props), { formatResult: true })
  192. const getAdsPlanXq = useAjax((planId: number) => getAdsPlanXqApi(planId), { formatResult: true })
  193. const getUserInfo = useAjax(() => getUserInfoApi(), { formatResult: true })
  194. // 删除
  195. const delBatch = useAjax((props: { taskIds: string }) => delBatchAjax(props), { formatResult: true, msgNmae: '删除' })
  196. const delLogBatch = useAjax((props: { logIds: string }) => delLogBatchAjax(props), { formatResult: true, msgNmae: '删除' })
  197. // 批量复制
  198. const setCopyPlan = useAjax((props: CopyPlan) => setCopyPlanApi(props))
  199. // 收藏
  200. const mpSc = useAjax((props: any) => mpCollect(props), { formatResult: true })
  201. const adqSc = useAjax((props: any) => adqCollect(props), { formatResult: true })
  202. const getAdsTableConfig = useAjax((props: { update: boolean }) => getAdsTableConfigApi(props), { formatResult: true })
  203. const getUserConfig = useAjax(() => getUserConfigApi(), { formatResult: true })
  204. const updateUserConfig = useAjax((props: {idList: string[], tableConfig: string}) => updateUserConfigApi(props), { formatResult: true })
  205. // 商品
  206. const allOfAccountGods = useAjax((props: any) => allOfAccountGodsApi(props), { formatResult: true })
  207. const allOfAccountGodsDetail = useAjax((props: any) => allOfAccountGodsDetailApi(props), { formatResult: true })
  208. return {
  209. getUserInfo,
  210. adsChannelAccountAdqAll,
  211. adsChannelAccountMpAll,
  212. getAdsPlanXq,
  213. getAdsPlanLog,
  214. loginAd,
  215. uploadLoginAd,
  216. updateChannelInfo,
  217. loginResult,
  218. allOfLoginUser,
  219. adsChannelAccountAdq,
  220. adsChannelAccountMp,
  221. adsChannelAccountAdq1,
  222. adsChannelAccountMp1,
  223. getAdsTableConfig,
  224. getUserConfig,
  225. updateUserConfig,
  226. addAndCreate,
  227. adsSharePage,
  228. addPlan,
  229. delSharePage,
  230. getSharePageDetail,
  231. getSharePage,
  232. adsSharePageEdit,
  233. allOfAccount,
  234. allOfAccountGods,
  235. allOfAccountGodsDetail,
  236. getAdsPlan,
  237. setCopyPlan,
  238. dispatch,
  239. state,
  240. mpSc,
  241. adqSc,
  242. delBatch,
  243. delLogBatch,
  244. allWechatInfo,
  245. allDataSource
  246. }
  247. }