api.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /**
  2. * desc: 接口请求类
  3. * author: wangyang
  4. * date: 2015-04-11
  5. */
  6. // define(['config', 'base', '$'], function(config, base, $) {
  7. define(['config', 'base'], function (config, base) {
  8. var API = function () {
  9. if (typeof API.instance === 'object') {
  10. return API.instance;
  11. }
  12. API.instance = this;
  13. this.isLoading = false;
  14. }
  15. API.prototype = new base();
  16. var apiErrorResult = {
  17. success: false,
  18. message: '网页加载失败,请您返回首页重新访问 <( ̄︶ ̄)>'
  19. };
  20. //获取预约信息
  21. API.prototype.geteservation = function (data, callback) {
  22. var that = this;
  23. this.isLoading = true;
  24. $.signAjax({
  25. url: config.apiPath + '/index.php?r=moonclub/reserve/myService',
  26. data: data,
  27. dataType: 'JSON',
  28. success: function (res) {
  29. that.isLoading = false;
  30. if (callback) {
  31. callback(res);
  32. }
  33. },
  34. error: function (res) {
  35. that.isLoading = false;
  36. if (callback) {
  37. callback(apiErrorResult);
  38. }
  39. }
  40. });
  41. };
  42. //获取用户信息
  43. API.prototype.getUserInfo = function (data, callback) {
  44. var that = this;
  45. this.isLoading = true;
  46. $.signAjax({
  47. url: config.apiPath + '/index.php?r=api/user/info',
  48. data: data,
  49. dataType: 'JSON',
  50. success: function (res) {
  51. that.isLoading = false;
  52. if (callback) {
  53. callback(res);
  54. }
  55. },
  56. error: function (res) {
  57. that.isLoading = false;
  58. if (callback) {
  59. callback(apiErrorResult);
  60. }
  61. }
  62. });
  63. };
  64. API.prototype.getO2oUserInfo = function (data, callback) {
  65. var that = this;
  66. this.isLoading = true;
  67. $.signAjax({
  68. url: config.apiPath + '/index.php?r=moonclub/user/info',
  69. data: data,
  70. dataType: 'JSON',
  71. success: function (res) {
  72. that.isLoading = false;
  73. if (callback) {
  74. callback(res);
  75. }
  76. },
  77. error: function (res) {
  78. that.isLoading = false;
  79. if (callback) {
  80. callback(apiErrorResult);
  81. }
  82. }
  83. });
  84. };
  85. //获取商品列表
  86. API.prototype.getProductList = function (data, callback) {
  87. var that = this;
  88. this.isLoading = true;
  89. $.signAjax({
  90. url: config.apiPath + '/index.php?r=moonclub/product/list',
  91. data: data,
  92. dataType: 'JSON',
  93. success: function (res) {
  94. that.isLoading = false;
  95. if (callback) {
  96. callback(res);
  97. }
  98. },
  99. error: function (res) {
  100. that.isLoading = false;
  101. if (callback) {
  102. callback(apiErrorResult);
  103. }
  104. }
  105. });
  106. };
  107. API.prototype.getAgreement = function (data, callback) {
  108. var that = this;
  109. this.isLoading = true;
  110. $.signAjax({
  111. url: config.apiPath + '/index.php?r=api/common/staticSource&key=agreement',
  112. data: data,
  113. dataType: 'JSON',
  114. success: function (res) {
  115. that.isLoading = false;
  116. if (callback) {
  117. callback(res);
  118. }
  119. },
  120. error: function (res) {
  121. that.isLoading = false;
  122. if (callback) {
  123. callback(apiErrorResult);
  124. }
  125. }
  126. });
  127. };
  128. API.prototype.getHelp = function (data, callback) {
  129. var that = this;
  130. this.isLoading = true;
  131. $.signAjax({
  132. url: config.apiPath + '/index.php?r=api/common/staticSource&key=help_center',
  133. data: data,
  134. dataType: 'JSON',
  135. success: function (res) {
  136. that.isLoading = false;
  137. if (callback) {
  138. callback(res);
  139. }
  140. },
  141. error: function (res) {
  142. that.isLoading = false;
  143. if (callback) {
  144. callback(apiErrorResult);
  145. }
  146. }
  147. });
  148. };
  149. API.prototype.getAbout = function (data, callback) {
  150. var that = this;
  151. this.isLoading = true;
  152. $.signAjax({
  153. url: config.apiPath + '/index.php?r=api/common/staticSource&key=about_us',
  154. data: data,
  155. dataType: 'JSON',
  156. success: function (res) {
  157. that.isLoading = false;
  158. if (callback) {
  159. callback(res);
  160. }
  161. },
  162. error: function (res) {
  163. that.isLoading = false;
  164. if (callback) {
  165. callback(apiErrorResult);
  166. }
  167. }
  168. });
  169. };
  170. //获取优惠券列表
  171. API.prototype.getCouponList = function (data, callback) {
  172. var that = this;
  173. $.signAjax({
  174. url: config.apiPath + '/index.php?r=moonclub/order/usableCoupon',
  175. data: data,
  176. dataType: 'JSON',
  177. success: function (res) {
  178. that.isLoading = false;
  179. if (callback) {
  180. callback(res);
  181. }
  182. },
  183. error: function (res) {
  184. that.isLoading = false;
  185. if (callback) {
  186. callback(apiErrorResult);
  187. }
  188. }
  189. });
  190. };
  191. //兑换优惠券
  192. API.prototype.exchangeCoupon = function (data, callback) {
  193. var that = this;
  194. $.signAjax({
  195. url: config.apiPath + '/index.php?r=moonclub/user/exchangeCoupon',
  196. data: data,
  197. dataType: 'JSON',
  198. success: function (res) {
  199. that.isLoading = false;
  200. if (callback) {
  201. callback(res);
  202. }
  203. },
  204. error: function (res) {
  205. that.isLoading = false;
  206. if (callback) {
  207. callback(apiErrorResult);
  208. }
  209. }
  210. });
  211. };
  212. //检查用户的地址是否在服务站内
  213. API.prototype.checkAddress = function (data, callback) {
  214. var that = this;
  215. $.signAjax({
  216. url: config.apiPath + '/index.php?r=moonclub/order/checkAddress',
  217. data: data,
  218. dataType: 'JSON',
  219. success: function (res) {
  220. that.isLoading = false;
  221. if (callback) {
  222. callback(res);
  223. }
  224. },
  225. error: function (res) {
  226. that.isLoading = false;
  227. if (callback) {
  228. callback(apiErrorResult);
  229. }
  230. }
  231. });
  232. };
  233. //提交订单
  234. API.prototype.addOrder = function (data, callback) {
  235. var that = this;
  236. $.signAjax({
  237. url: config.apiPath + '/index.php?r=moonclub/order/add',
  238. data: data,
  239. dataType: 'JSON',
  240. success: function (res) {
  241. that.isLoading = false;
  242. if (callback) {
  243. callback(res);
  244. }
  245. },
  246. error: function (res) {
  247. that.isLoading = false;
  248. if (callback) {
  249. callback(apiErrorResult);
  250. }
  251. }
  252. });
  253. };
  254. //取消订单
  255. API.prototype.cancelOrder = function (data, callback) {
  256. var that = this;
  257. $.signAjax({
  258. url: config.apiPath + '/index.php?r=moonclub/order/del',
  259. data: data,
  260. dataType: 'JSON',
  261. success: function (res) {
  262. that.isLoading = false;
  263. if (callback) {
  264. callback(res);
  265. }
  266. },
  267. error: function (res) {
  268. that.isLoading = false;
  269. if (callback) {
  270. callback(apiErrorResult);
  271. }
  272. }
  273. });
  274. };
  275. // 追加订单
  276. API.prototype.appendOrder = function (data, callback) {
  277. var that = this;
  278. $.signAjax({
  279. url: config.apiPath + '/index.php?r=moonclub/order/append',
  280. data: data,
  281. dataType: 'JSON',
  282. success: function (res) {
  283. that.isLoading = false;
  284. if (callback) {
  285. callback(res);
  286. }
  287. },
  288. error: function (res) {
  289. that.isLoading = false;
  290. if (callback) {
  291. callback(apiErrorResult);
  292. }
  293. }
  294. });
  295. };
  296. // 订单详情
  297. API.prototype.getOrderDetail = function (data, callback) {
  298. var that = this;
  299. $.signAjax({
  300. url: config.apiPath + '/index.php?r=moonclub/order/detail',
  301. data: data,
  302. dataType: 'JSON',
  303. success: function (res) {
  304. that.isLoading = false;
  305. if (callback) {
  306. callback(res);
  307. }
  308. },
  309. error: function (res) {
  310. that.isLoading = false;
  311. if (callback) {
  312. callback(apiErrorResult);
  313. }
  314. }
  315. });
  316. };
  317. //获取支付信息
  318. API.prototype.getPayCharge = function (data, callback) {
  319. var that = this;
  320. $.signAjax({
  321. url: config.apiPath + '/index.php?r=moonclub/order/pay',
  322. data: data,
  323. dataType: 'JSON',
  324. success: function (res) {
  325. that.isLoading = false;
  326. if (callback) {
  327. callback(res);
  328. }
  329. },
  330. error: function (res) {
  331. that.isLoading = false;
  332. if (callback) {
  333. callback(apiErrorResult);
  334. }
  335. }
  336. });
  337. };
  338. // 获取追加订单信息
  339. API.prototype.getAppendPayCharge = function (data, callback) {
  340. var that = this;
  341. $.signAjax({
  342. url: config.apiPath + '/index.php?r=moonclub/order/appendPay',
  343. data: data,
  344. dataType: 'JSON',
  345. success: function (res) {
  346. that.isLoading = false;
  347. if (callback) {
  348. callback(res);
  349. }
  350. },
  351. error: function (res) {
  352. that.isLoading = false;
  353. if (callback) {
  354. callback(apiErrorResult);
  355. }
  356. }
  357. });
  358. };
  359. //获取我的订单列表
  360. API.prototype.getMyOrderList = function (data, callback) {
  361. var that = this;
  362. $.signAjax({
  363. url: config.apiPath + '/index.php?r=moonclub/order/list',
  364. data: data,
  365. dataType: 'JSON',
  366. success: function (res) {
  367. that.isLoading = false;
  368. if (callback) {
  369. callback(res);
  370. }
  371. },
  372. error: function (res) {
  373. that.isLoading = false;
  374. if (callback) {
  375. callback(apiErrorResult);
  376. }
  377. }
  378. });
  379. };
  380. //发表评价
  381. API.prototype.postReview = function (data, callback) {
  382. var that = this;
  383. $.signAjax({
  384. url: config.apiPath + '/index.php?r=moonclub/product/comment',
  385. data: data,
  386. dataType: 'JSON',
  387. success: function (res) {
  388. that.isLoading = false;
  389. if (callback) {
  390. callback(res);
  391. }
  392. },
  393. error: function (res) {
  394. that.isLoading = false;
  395. if (callback) {
  396. callback(apiErrorResult);
  397. }
  398. }
  399. });
  400. };
  401. //评价列表
  402. API.prototype.getReviewList = function (data, callback) {
  403. var that = this;
  404. $.signAjax({
  405. url: config.apiPath + '/index.php?r=moonclub/product/commentList',
  406. data: data,
  407. dataType: 'JSON',
  408. success: function (res) {
  409. that.isLoading = false;
  410. if (callback) {
  411. callback(res);
  412. }
  413. },
  414. error: function (res) {
  415. that.isLoading = false;
  416. if (callback) {
  417. callback(apiErrorResult);
  418. }
  419. }
  420. });
  421. };
  422. //地址列表
  423. API.prototype.getAddressList = function (data, callback) {
  424. var that = this;
  425. $.signAjax({
  426. url: config.apiPath + '/index.php?r=api/shop/addressList',
  427. data: data,
  428. dataType: 'JSON',
  429. success: function (res) {
  430. that.isLoading = false;
  431. if (callback) {
  432. callback(res);
  433. }
  434. },
  435. error: function (res) {
  436. that.isLoading = false;
  437. if (callback) {
  438. callback(apiErrorResult);
  439. }
  440. }
  441. });
  442. };
  443. //新增地址
  444. API.prototype.addAddress = function (data, callback) {
  445. var that = this;
  446. $.signAjax({
  447. url: config.apiPath + '/index.php?r=api/shop/addAddress',
  448. data: data,
  449. dataType: 'JSON',
  450. success: function (res) {
  451. that.isLoading = false;
  452. if (callback) {
  453. callback(res);
  454. }
  455. },
  456. error: function (res) {
  457. that.isLoading = false;
  458. if (callback) {
  459. callback(apiErrorResult);
  460. }
  461. }
  462. });
  463. };
  464. //删除地址
  465. API.prototype.deleteAddress = function (data, callback) {
  466. var that = this;
  467. $.signAjax({
  468. url: config.apiPath + '/index.php?r=api/shop/delAddress',
  469. data: data,
  470. dataType: 'JSON',
  471. success: function (res) {
  472. that.isLoading = false;
  473. if (callback) {
  474. callback(res);
  475. }
  476. },
  477. error: function (res) {
  478. that.isLoading = false;
  479. if (callback) {
  480. callback(apiErrorResult);
  481. }
  482. }
  483. });
  484. };
  485. // 修改地址
  486. API.prototype.editAddress = function (data, callback) {
  487. var that = this;
  488. $.signAjax({
  489. url: config.apiPath + '/index.php?r=api/shop/editAddress',
  490. data: data,
  491. dataType: 'JSON',
  492. success: function (res) {
  493. that.isLoading = false;
  494. if (callback) {
  495. callback(res);
  496. }
  497. },
  498. error: function (res) {
  499. that.isLoading = false;
  500. if (callback) {
  501. callback(apiErrorResult);
  502. }
  503. }
  504. });
  505. };
  506. // 获取上传图片token
  507. API.prototype.gettoken = function (data, callback) {
  508. var that = this;
  509. $.signAjax({
  510. url: config.apiPath + '/index.php?r=api/upload/gettoken',
  511. data: data,
  512. dataType: 'JSON',
  513. success: function (res) {
  514. that.isLoading = false;
  515. if (callback) {
  516. callback(res);
  517. }
  518. },
  519. error: function (res) {
  520. that.isLoading = false;
  521. if (callback) {
  522. callback(apiErrorResult);
  523. }
  524. }
  525. });
  526. };
  527. // 退款
  528. API.prototype.refundOrder = function (data, callback) {
  529. var that = this;
  530. $.signAjax({
  531. url: config.apiPath + '/index.php?r=moonclub/order/retrieve',
  532. data: data,
  533. dataType: 'JSON',
  534. success: function (res) {
  535. that.isLoading = false;
  536. if (callback) {
  537. callback(res);
  538. }
  539. },
  540. error: function (res) {
  541. that.isLoading = false;
  542. if (callback) {
  543. callback(apiErrorResult);
  544. }
  545. }
  546. });
  547. };
  548. // 确认完成
  549. API.prototype.finishOrder = function (data, callback) {
  550. var that = this;
  551. $.signAjax({
  552. url: config.apiPath + '/index.php?r=moonclub/order/confirmComplete',
  553. data: data,
  554. dataType: 'JSON',
  555. success: function (res) {
  556. that.isLoading = false;
  557. if (callback) {
  558. callback(res);
  559. }
  560. },
  561. error: function (res) {
  562. that.isLoading = false;
  563. if (callback) {
  564. callback(apiErrorResult);
  565. }
  566. }
  567. });
  568. };
  569. // 触宝 获取加密支付信息
  570. API.prototype.getTradeStr = function (data, callback) {
  571. var that = this;
  572. $.signAjax({
  573. url: config.apiPath + '/index.php?r=moonclub/chubao/chubaoPay',
  574. data: data,
  575. dataType: 'JSON',
  576. success: function (res) {
  577. that.isLoading = false;
  578. if (callback) {
  579. callback(res);
  580. }
  581. },
  582. error: function (res) {
  583. that.isLoading = false;
  584. if (callback) {
  585. callback(apiErrorResult);
  586. }
  587. }
  588. });
  589. };
  590. // 选择保洁师
  591. API.prototype.selectTech = function (data, callback) {
  592. var that = this;
  593. $.signAjax({
  594. url: config.apiPath + '/index.php?r=moonclub/order/selectTech',
  595. data: data,
  596. dataType: 'JSON',
  597. success: function (res) {
  598. that.isLoading = false;
  599. if (callback) {
  600. callback(res);
  601. }
  602. },
  603. error: function (res) {
  604. that.isLoading = false;
  605. if (callback) {
  606. callback(apiErrorResult);
  607. }
  608. }
  609. });
  610. };
  611. API.prototype.techComment = function (data, callback) {
  612. var that = this;
  613. $.signAjax({
  614. url: config.apiPath + '/index.php?r=moonclub/order/techComment',
  615. data: data,
  616. dataType: 'JSON',
  617. success: function (res) {
  618. that.isLoading = false;
  619. if (callback) {
  620. callback(res);
  621. }
  622. },
  623. error: function (res) {
  624. that.isLoading = false;
  625. if (callback) {
  626. callback(apiErrorResult);
  627. }
  628. }
  629. });
  630. };
  631. //创建充值卡订单
  632. API.prototype.addRechargeorder = function (data, callback) {
  633. var that = this;
  634. $.signAjax({
  635. url: config.apiPath + '/index.php?r=moonclub/recharge/addRechargeorder',
  636. data: data,
  637. dataType: 'JSON',
  638. success: function (res) {
  639. that.isLoading = false;
  640. if (callback) {
  641. callback(res);
  642. }
  643. },
  644. error: function (res) {
  645. that.isLoading = false;
  646. if (callback) {
  647. callback(apiErrorResult);
  648. }
  649. }
  650. });
  651. };
  652. //充值卡支付
  653. API.prototype.payRecharge = function (data, callback) {
  654. var that = this;
  655. $.signAjax({
  656. url: config.apiPath + '/index.php?r=moonclub/recharge/payRecharge',
  657. data: data,
  658. dataType: 'JSON',
  659. success: function (res) {
  660. that.isLoading = false;
  661. if (callback) {
  662. callback(res);
  663. }
  664. },
  665. error: function (res) {
  666. that.isLoading = false;
  667. if (callback) {
  668. callback(apiErrorResult);
  669. }
  670. }
  671. });
  672. };
  673. //充值卡列表
  674. API.prototype.getRechargeList = function (data, callback) {
  675. var that = this;
  676. $.signAjax({
  677. url: config.apiPath + '/index.php?r=moonclub/recharge/rechargeList',
  678. data: data,
  679. dataType: 'JSON',
  680. success: function (res) {
  681. that.isLoading = false;
  682. if (callback) {
  683. callback(res);
  684. }
  685. },
  686. error: function (res) {
  687. that.isLoading = false;
  688. if (callback) {
  689. callback(apiErrorResult);
  690. }
  691. }
  692. });
  693. };
  694. return new API();
  695. })