APIClient.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. var constant = require('const.js');
  2. const HOST_PRODUCT = constant.productApi;
  3. const HOST_BASE = constant.baseApi;
  4. let request = require('WXHttpRequest.js');
  5. const httputil = require('httpUtil.js');
  6. function getProductUrl(action) {
  7. return HOST_PRODUCT + action;
  8. }
  9. function getBaseUrl(action) {
  10. return HOST_BASE + action;
  11. }
  12. module.exports = {
  13. //获取推荐首页信息
  14. getIndex(uid) {
  15. let url = getProductUrl('wx/index');
  16. return request.getInstance().header({
  17. uid
  18. }).url(url).send();
  19. },
  20. // 获取首页人气推荐
  21. getHotRecommend(uid, pageNo, pageSize) {
  22. let url = getBaseUrl('wx/userRead/recommend');
  23. return request.getInstance().header({
  24. uid
  25. }).data({
  26. pageNo,
  27. pageSize,
  28. }).url(url).send();
  29. },
  30. // 获取用户朗读详细信息
  31. getWorksDetail(uid, readId) {
  32. let url = getBaseUrl(`wx/userRead/info/${readId}`);
  33. return request.getInstance().header({
  34. uid
  35. }).url(url).send();
  36. },
  37. // 获取全部课本
  38. getAllBooks(pageNo, pageSize) {
  39. let url = getProductUrl('wx/product');
  40. return request.getInstance().header({
  41. uid: wx.getStorageSync('uid')
  42. }).url(url).data({
  43. pageNo,
  44. pageSize
  45. }).send();
  46. },
  47. // 获取课本详情
  48. getBookDetail(uid, id) {
  49. let url = getProductUrl(`wx/product/${id}`);
  50. return request.getInstance().header({
  51. uid
  52. }).url(url).send();
  53. },
  54. // 获取单课详情
  55. getClassDetail(uid, id) {
  56. let url = getProductUrl(`wx/lesson/${id}`);
  57. return request.getInstance().header({
  58. uid
  59. }).url(url).send();
  60. },
  61. // 检查是否收藏过课程
  62. classIsLike(uid, data) {
  63. let url = getProductUrl(`wx/favorites/isLike`);
  64. return request.getInstance().header({
  65. uid
  66. }).url(url).data(data).send();
  67. },
  68. getClassDetail(uid, id) {
  69. let url = getProductUrl(`wx/lesson/${id}`);
  70. return request.getInstance().header({
  71. uid
  72. }).url(url).send();
  73. },
  74. // 获取单课朗读信息
  75. getClassRead(uid, data) {
  76. let url = getBaseUrl(`wx/userRead`);
  77. return request.getInstance().header({
  78. uid
  79. }).data(data).url(url).send();
  80. },
  81. // 作品播放了+1
  82. playWorks(uid, readId) {
  83. let url = getBaseUrl(`wx/userRead/play/${readId}`);
  84. return request.getInstance().header({
  85. uid
  86. }).url(url).send();
  87. },
  88. // 发布作品
  89. postWork(uid, data) {
  90. console.log(data);
  91. let url = getBaseUrl(`wx/userRead`);
  92. return request.getInstance().header({
  93. uid
  94. }).url(url).data(data).method('POST').send();
  95. },
  96. // 点赞作品
  97. likeWorks(uid, readId) {
  98. let url = getBaseUrl(`wx/userRead/like/${readId}`);
  99. return request.getInstance().header({
  100. uid
  101. }).url(url).send();
  102. },
  103. // 关注用户
  104. followUser(uid, followUid) {
  105. let url = getBaseUrl(`wx/fans`);
  106. return request.getInstance().header({
  107. uid
  108. }).url(url).data({
  109. "uid": followUid
  110. }).method('POST').send();
  111. },
  112. // 取消关注
  113. cancerFollow(uid, followUid) {
  114. let url = getBaseUrl(`wx/fans`);
  115. return request.getInstance().header({
  116. uid
  117. }).url(url).data({
  118. "uid": followUid
  119. }).method('PUT').send();
  120. },
  121. //获取关注的用户列表
  122. getFollowUsers(uid, pageNo, pageSize) {
  123. let url = getBaseUrl(`wx/fans`);
  124. return request.getInstance().header({
  125. uid
  126. }).url(url).data({
  127. pageNo: pageNo,
  128. pageSize: pageSize
  129. }).send();
  130. },
  131. // 获取关注用户的作品列表
  132. getFollowWorks(uid, pageNo, pageSize) {
  133. let url = getBaseUrl(`wx/fans/interest`);
  134. return request.getInstance().header({
  135. uid
  136. }).url(url).data({
  137. pageNo: pageNo,
  138. pageSize: pageSize
  139. }).send();
  140. },
  141. // 搜索
  142. getSearchResult(uid, key, pageNo, pageSize) {
  143. let url = getProductUrl(`wx/lesson`);
  144. return request.getInstance().header({
  145. uid
  146. }).url(url).data({
  147. title: key,
  148. productId: '',
  149. pageNo: pageNo,
  150. pageSize: pageSize
  151. }).send();
  152. },
  153. // 获取回复信息
  154. getReply(uid, columnId, pageNo, pageSize) {
  155. let url = getBaseUrl(`wx/posts/reply`);
  156. return request.getInstance().header({
  157. uid
  158. }).url(url).data({
  159. columnId: columnId,
  160. pageNo: pageNo,
  161. pageSize: pageSize
  162. }).send();
  163. },
  164. // 获取回复(楼中楼)
  165. getReplyComment(uid, postId) {
  166. let url = getBaseUrl(`wx/posts/one/${postId}`);
  167. return request.getInstance().header({
  168. uid
  169. }).url(url).send();
  170. },
  171. // 发布回复(楼中楼)
  172. postReplyComment(uid, data) {
  173. let url = getBaseUrl(`wx/reply`);
  174. return request.getInstance().header({
  175. uid
  176. }).url(url).data(data).method('POST').send();
  177. },
  178. // 点赞评论
  179. likeCommend(uid, likeUid) {
  180. let url = getBaseUrl(`wx/posts/attribute/${likeUid}`);
  181. return request.getInstance().header({
  182. uid
  183. }).url(url).method('GET').send();
  184. },
  185. // 发布讨论
  186. postReply(uid, data) {
  187. let url = getBaseUrl(`wx/posts`);
  188. return request.getInstance().header({
  189. uid
  190. }).url(url).data(data).method('POST').send();
  191. },
  192. // 获取推荐团购信息
  193. getGroupList() {
  194. let url = getBaseUrl(`wx/groupPurchaseInfo/recommend`);
  195. return request.getInstance().header({
  196. uid: wx.getStorageSync('uid')
  197. }).url(url).send();
  198. },
  199. // 获取课程团购信息
  200. getGroupPurchaseInfo(productId) {
  201. let url = getBaseUrl(`wx/groupPurchaseInfo/info/${productId}`);
  202. return request.getInstance().header({
  203. uid: wx.getStorageSync('uid')
  204. }).url(url).send();
  205. },
  206. // 发起团购
  207. SendGroupPurchas(data) {
  208. let url = getBaseUrl(`wx/groupPurchase/create`);
  209. return request.getInstance().header({
  210. uid: wx.getStorageSync('uid')
  211. }).url(url).data(data).method('POST').send();
  212. },
  213. // 参加团购
  214. JoinGroupPurchas(orderId) {
  215. let url = getBaseUrl(`wx/groupPurchase/join`);
  216. return request.getInstance().header({
  217. uid: wx.getStorageSync('uid')
  218. }).url(url).data({
  219. orderId
  220. }).method('POST').send();
  221. },
  222. // 收藏课程
  223. collectClass(uid, data) {
  224. let url = getProductUrl(`wx/favorites`);
  225. return request.getInstance().header({
  226. uid
  227. }).url(url).data(data).method('POST').send();
  228. },
  229. //我的团
  230. getMygroup() {
  231. let url = getBaseUrl(`wx/groupPurchase/my`);
  232. return request.getInstance().header({
  233. uid: wx.getStorageSync('uid')
  234. }).url(url).data({
  235. pageNo: 1,
  236. pageSize: 100
  237. }).send();
  238. },
  239. //获取团购详情
  240. getMygroupInfo(orderId) {
  241. let url = getBaseUrl(`wx/groupPurchase/info/${orderId}`);
  242. return request.getInstance().header({
  243. uid: wx.getStorageSync('uid')
  244. }).url(url).send();
  245. },
  246. //团购是否成功
  247. groupSuccess(orderId) {
  248. let url = getBaseUrl(`wx/groupPurchase/joinStatus`);
  249. return request.getInstance().header({
  250. uid: wx.getStorageSync('uid')
  251. }).url(url).data({
  252. orderId
  253. }).send();
  254. },
  255. // 发起奖励
  256. rewardMoney(uid, data) {
  257. let url = getBaseUrl(`wx/wallet/award`);
  258. return request.getInstance().header({
  259. uid
  260. }).url(url).data(data).method('POST').send();
  261. },
  262. // 修改资料
  263. settingUserInfo(data) {
  264. let url = getBaseUrl(`wx/user`);
  265. return request.getInstance().header({
  266. uid: wx.getStorageSync('uid')
  267. }).data(data).url(url).method('PUT').send();
  268. },
  269. //获取个人信息
  270. getUserInfo() {
  271. let url = getBaseUrl(`wx/user`);
  272. return request.getInstance().header({
  273. uid: wx.getStorageSync('uid')
  274. }).url(url).send();
  275. },
  276. // 获取播放量等数据
  277. getUserWorksInfo() {
  278. let url = getBaseUrl(`wx/user/my`);
  279. return request.getInstance().header({
  280. uid: wx.getStorageSync('uid')
  281. }).url(url).send();
  282. },
  283. // 生成二维码
  284. createQRCode(data) {
  285. let url = getBaseUrl(`wx/qrCode`);
  286. return request.getInstance().header({
  287. uid: wx.getStorageSync('uid')
  288. }).data(data).url(url).send();
  289. },
  290. // 我的奖金
  291. myWallet() {
  292. let url = getBaseUrl('wx/wallet/bonus');
  293. return request.getInstance().header({
  294. uid: wx.getStorageSync('uid')
  295. }).url(url).send();
  296. },
  297. // 資金明細
  298. myWalletDetails() {
  299. let url = getBaseUrl('wx/wallet/record');
  300. return request.getInstance().header({
  301. uid: wx.getStorageSync('uid')
  302. }).url(url).send();
  303. },
  304. // 我的課程
  305. myCourse() {
  306. let url = getBaseUrl('wx/groupPurchase/myCourse');
  307. return request.getInstance().header({
  308. uid: wx.getStorageSync('uid')
  309. }).url(url).send();
  310. },
  311. // 我的朗读
  312. myRead() {
  313. let url = getBaseUrl('wx/userRead/my');
  314. return request.getInstance().header({
  315. uid: wx.getStorageSync('uid')
  316. }).url(url).send();
  317. },
  318. // 我的收藏
  319. myFavorites() {
  320. let url = getProductUrl(`wx/favorites`);
  321. return request.getInstance().header({
  322. uid: wx.getStorageSync('uid')
  323. }).url(url).send();
  324. },
  325. // 我的关注
  326. myFans() {
  327. let url = getBaseUrl(`wx/fans`);
  328. return request.getInstance().header({
  329. uid: wx.getStorageSync('uid')
  330. }).url(url).send();
  331. },
  332. // 产品鉴权
  333. areYouSuper(productArr){
  334. let url = getBaseUrl(`wx/groupPurchase/auth`);
  335. return request.getInstance().header({
  336. uid: wx.getStorageSync('uid')
  337. }).url(url).data(productArr).method('POST').send();
  338. },
  339. // 找到课程对应的课本
  340. checkLesson(lessonId){
  341. let url = getProductUrl(`wx/lesson/product/${lessonId}`);
  342. return request.getInstance().header({
  343. uid: wx.getStorageSync('uid')
  344. }).url(url).send();
  345. }
  346. }