api.js 21 KB

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