api.js 20 KB

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