api.js 21 KB

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