api.js 20 KB

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