services_respository.dart 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/garage_sale_history_entity.dart';
  3. import 'package:domain/entity/garage_sale_rent_detail_entity.dart';
  4. import 'package:domain/entity/garage_sale_rent_entity.dart';
  5. import 'package:domain/entity/myposts_sale_rent_entity.dart';
  6. import 'package:domain/entity/newsfeed_foryou_entity.dart';
  7. import 'package:domain/entity/newsfeed_news_entity.dart';
  8. import 'package:domain/entity/server_time.dart';
  9. import 'package:domain/entity/service_order_detail_entity.dart';
  10. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  11. import 'package:plugin_platform/platform_export.dart';
  12. import 'package:plugin_platform/http/dio_engine.dart';
  13. import 'package:plugin_platform/http/http_result.dart';
  14. import 'package:riverpod_annotation/riverpod_annotation.dart';
  15. import 'package:shared/utils/log_utils.dart';
  16. import 'package:shared/utils/util.dart';
  17. import 'package:flutter_riverpod/flutter_riverpod.dart';
  18. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  19. part 'services_respository.g.dart';
  20. @Riverpod(keepAlive: true)
  21. ServicesRespository servicesRespository(Ref ref) {
  22. final dioEngine = ref.watch(dioEngineProvider);
  23. return ServicesRespository(dioEngine: dioEngine);
  24. }
  25. /*
  26. * 数据仓库
  27. */
  28. class ServicesRespository {
  29. DioEngine dioEngine;
  30. ServicesRespository({required this.dioEngine});
  31. //服务 获取 分类 字典
  32. Future<HttpResult<Object>> fetchServiceCateGoryList(
  33. Map<String, dynamic>? data, {
  34. CancelToken? cancelToken,
  35. }) async {
  36. Map<String, dynamic> params = {};
  37. params = data!;
  38. Map<String, String> headers = {};
  39. headers["Content-Type"] = "application/x-www-form-urlencoded";
  40. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  41. final result = await dioEngine.requestNetResult(
  42. // ApiConstants.apiServerTime, // api 地址
  43. '/api/v1/user/service/category/index', // api 地址
  44. params: params,
  45. headers: headers,
  46. method: HttpMethod.GET,
  47. isShowLoadingDialog: true,
  48. //是否展示默认的Loading弹窗
  49. networkDebounce: true,
  50. //是否防抖防止重复请求
  51. cancelToken: cancelToken,
  52. );
  53. //根据返回的结果,封装原始数据为Bean/Entity对象
  54. if (result.isSuccess) {
  55. //重新赋值data或list
  56. final json = result.getDataJson();
  57. // var data = NewsfeedForyouEntity.fromJson(json!);
  58. //重新赋值data或list
  59. return result.convert(data: json);
  60. } else {
  61. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  62. ToastEngine.show("${result.errorMsg}");
  63. }
  64. }
  65. return result.convert();
  66. }
  67. // 付费服务 获取 列表
  68. Future<HttpResult<Object>> fetchPaidServiceDataList(
  69. Map<String, dynamic>? data, {
  70. CancelToken? cancelToken,
  71. }) async {
  72. Map<String, dynamic> params = {};
  73. params = data!;
  74. Map<String, String> headers = {};
  75. headers["Content-Type"] = "application/x-www-form-urlencoded";
  76. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  77. final result = await dioEngine.requestNetResult(
  78. // ApiConstants.apiServerTime, // api 地址
  79. '/api/v1/user/service/paid-service/index', // api 地址
  80. params: params,
  81. headers: headers,
  82. method: HttpMethod.GET,
  83. isShowLoadingDialog: false,
  84. //是否展示默认的Loading弹窗
  85. networkDebounce: true,
  86. //是否防抖防止重复请求
  87. cancelToken: cancelToken,
  88. );
  89. //根据返回的结果,封装原始数据为Bean/Entity对象
  90. if (result.isSuccess) {
  91. //重新赋值data或list
  92. final json = result.getDataJson();
  93. var data = GarageSaleRentEntity.fromJson(json!);
  94. //重新赋值data或list
  95. return result.convert(data: data);
  96. } else {
  97. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  98. ToastEngine.show("${result.errorMsg}");
  99. }
  100. }
  101. return result.convert();
  102. }
  103. // 付费/维修 服务 列表 点赞/取消点赞
  104. Future<HttpResult<Object>> fetchServiceLiked(
  105. Map<String, dynamic>? data, {
  106. CancelToken? cancelToken,
  107. }) async {
  108. Map<String, dynamic> params = {};
  109. params = data!;
  110. Map<String, String> headers = {};
  111. headers["Content-Type"] = "application/x-www-form-urlencoded";
  112. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  113. final result = await dioEngine.requestNetResult(
  114. // ApiConstants.apiServerTime, // api 地址
  115. '/api/v1/user/service/paid-service/liked', // api 地址
  116. params: params,
  117. headers: headers,
  118. method: HttpMethod.POST,
  119. isShowLoadingDialog: true,
  120. //是否展示默认的Loading弹窗
  121. networkDebounce: true,
  122. //是否防抖防止重复请求
  123. cancelToken: cancelToken,
  124. );
  125. //根据返回的结果,封装原始数据为Bean/Entity对象
  126. if (result.isSuccess) {
  127. //重新赋值data或list
  128. final json = result.getDataDynamic();
  129. // var data = NewsfeedForyouEntity.fromJson(json!);
  130. //重新赋值data或list
  131. return result.convert(data: json);
  132. } else {
  133. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  134. ToastEngine.show("${result.errorMsg}");
  135. }
  136. }
  137. return result.convert();
  138. }
  139. // 提交评价
  140. Future<HttpResult<Object>> fetchPublishEvaluation(
  141. Map<String, dynamic>? data, {
  142. CancelToken? cancelToken,
  143. }) async {
  144. Map<String, dynamic> params = {};
  145. params = data!;
  146. Map<String, String> headers = {};
  147. headers["Content-Type"] = "application/x-www-form-urlencoded";
  148. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  149. List<String> paths = data!["resources"] as List<String>;
  150. Map<String, String> files = {};
  151. if (paths != null && paths.isNotEmpty) {
  152. paths.asMap().forEach((index, path) {
  153. files["resources[$index]"] = path;
  154. });
  155. }
  156. // 删除 resources 属性
  157. params.remove("resources");
  158. final result = await dioEngine.requestNetResult(
  159. // ApiConstants.apiServerTime, // api 地址
  160. '/api/v1/user/service/evaluation/publish', // api 地址
  161. params: params,
  162. paths: files,
  163. headers: headers,
  164. method: HttpMethod.POST,
  165. isShowLoadingDialog: true,
  166. //是否展示默认的Loading弹窗
  167. networkDebounce: true,
  168. //是否防抖防止重复请求
  169. cancelToken: cancelToken,
  170. );
  171. //根据返回的结果,封装原始数据为Bean/Entity对象
  172. if (result.isSuccess) {
  173. //重新赋值data或list
  174. final json = result.getDataJson();
  175. // var data = NewsfeedForyouEntity.fromJson(json!);
  176. //重新赋值data或list
  177. return result.convert(data: json);
  178. } else {
  179. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  180. ToastEngine.show("${result.errorMsg}");
  181. }
  182. }
  183. return result.convert();
  184. }
  185. // 评价列表
  186. Future<HttpResult<Object>> fetchEvaluationDataList(
  187. Map<String, dynamic>? data, {
  188. CancelToken? cancelToken,
  189. }) async {
  190. Map<String, dynamic> params = {};
  191. params = data!;
  192. Map<String, String> headers = {};
  193. headers["Content-Type"] = "application/x-www-form-urlencoded";
  194. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  195. final result = await dioEngine.requestNetResult(
  196. // ApiConstants.apiServerTime, // api 地址
  197. '/api/v1/user/service/evaluation/index', // api 地址
  198. params: params,
  199. headers: headers,
  200. method: HttpMethod.GET,
  201. isShowLoadingDialog: false,
  202. //是否展示默认的Loading弹窗
  203. networkDebounce: true,
  204. //是否防抖防止重复请求
  205. cancelToken: cancelToken,
  206. );
  207. //根据返回的结果,封装原始数据为Bean/Entity对象
  208. if (result.isSuccess) {
  209. //重新赋值data或list
  210. final json = result.getDataJson();
  211. var data = GarageSaleRentEntity.fromJson(json!);
  212. //重新赋值data或list
  213. return result.convert(data: data);
  214. } else {
  215. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  216. ToastEngine.show("${result.errorMsg}");
  217. }
  218. }
  219. return result.convert();
  220. }
  221. // 获取 付费服务 详情信息
  222. Future<HttpResult<Object>> fetchPaidServiceCleanDetailInfo(
  223. Map<String, dynamic>? data, {
  224. CancelToken? cancelToken,
  225. }) async {
  226. Map<String, dynamic> params = {};
  227. params = data!;
  228. Map<String, String> headers = {};
  229. // headers["Content-Type"] = "application/x-www-form-urlencoded";
  230. // headers["Accept"] = "application/x.yyjobs-api.v1+json";
  231. final result = await dioEngine.requestNetResult(
  232. // ApiConstants.apiServerTime, // api 地址
  233. '/api/v1/user/service/paid-service/detail', // api 地址
  234. params: params,
  235. headers: headers,
  236. method: HttpMethod.GET,
  237. isShowLoadingDialog: false,
  238. //是否展示默认的Loading弹窗
  239. networkDebounce: true,
  240. //是否防抖防止重复请求
  241. cancelToken: cancelToken,
  242. );
  243. //根据返回的结果,封装原始数据为Bean/Entity对象
  244. if (result.isSuccess) {
  245. //重新赋值data或list
  246. final json = result.getDataJson();
  247. // var data = GarageSaleRentDetailEntity.fromJson(json!);
  248. //重新赋值data或list
  249. return result.convert(data: json);
  250. } else {
  251. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  252. ToastEngine.show("${result.errorMsg}");
  253. }
  254. }
  255. return result.convert();
  256. }
  257. // 付费服务 下单
  258. Future<HttpResult<Object>> fetchPaidServiceBook(
  259. Map<String, dynamic>? data, {
  260. CancelToken? cancelToken,
  261. }) async {
  262. Map<String, dynamic> params = {};
  263. params = data!;
  264. Map<String, String> headers = {};
  265. headers["Content-Type"] = "application/x-www-form-urlencoded";
  266. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  267. final result = await dioEngine.requestNetResult(
  268. // ApiConstants.apiServerTime, // api 地址
  269. '/api/v1/user/service/paid-service-order/book', // api 地址
  270. params: params,
  271. headers: headers,
  272. method: HttpMethod.POST,
  273. isShowLoadingDialog: true,
  274. //是否展示默认的Loading弹窗
  275. networkDebounce: true,
  276. //是否防抖防止重复请求
  277. cancelToken: cancelToken,
  278. );
  279. //根据返回的结果,封装原始数据为Bean/Entity对象
  280. if (result.isSuccess) {
  281. //重新赋值data或list
  282. final json = result.getDataJson();
  283. // var data = NewsfeedForyouEntity.fromJson(json!);
  284. //重新赋值data或list
  285. return result.convert(data: json);
  286. } else {
  287. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  288. ToastEngine.show("${result.errorMsg}");
  289. }
  290. }
  291. return result.convert();
  292. }
  293. // 付费服务 订单列表
  294. Future<HttpResult<GarageSaleHistoryEntity>> fetchPaidServiceOrderList({
  295. required String type,
  296. required int curPage,
  297. CancelToken? cancelToken,
  298. }) async {
  299. Map<String, String> params = {};
  300. params['type'] = type;
  301. params['page'] = curPage.toString();
  302. params['limit'] = "10";
  303. final result = await dioEngine.requestNetResult(
  304. '/api/v1/user/service/paid-service-order/index',
  305. params: params,
  306. method: HttpMethod.GET,
  307. isShowLoadingDialog: false,
  308. //是否展示默认的Loading弹窗
  309. networkDebounce: true,
  310. //是否防抖防止重复请求
  311. cancelToken: cancelToken,
  312. );
  313. if (result.isSuccess) {
  314. final json = result.getDataJson();
  315. var data = GarageSaleHistoryEntity.fromJson(json!);
  316. return result.convert<GarageSaleHistoryEntity>(data: data);
  317. }
  318. return result.convert();
  319. }
  320. // 获取 付费服务 订单详情
  321. Future<HttpResult<ServiceOrderDetailEntity>> fetchPaidServiceCleanOrderDetail({
  322. required String id,
  323. CancelToken? cancelToken,
  324. }) async {
  325. Map<String, dynamic> params = {};
  326. params['id'] = id;
  327. final result = await dioEngine.requestNetResult(
  328. '/api/v1/user/service/paid-service-order/detail',
  329. params: params,
  330. method: HttpMethod.GET,
  331. isShowLoadingDialog: false,
  332. //是否展示默认的Loading弹窗
  333. networkDebounce: true,
  334. //是否防抖防止重复请求
  335. cancelToken: cancelToken,
  336. );
  337. if (result.isSuccess) {
  338. final json = result.getDataJson();
  339. var data = ServiceOrderDetailEntity.fromJson(json!);
  340. return result.convert<ServiceOrderDetailEntity>(data: data);
  341. }
  342. return result.convert();
  343. }
  344. // 获取 付费订单实际需要支付的价格
  345. Future<HttpResult<Object>> fetchPaidServiceCleanOrderPrice(
  346. Map<String, dynamic>? data, {
  347. CancelToken? cancelToken,
  348. }) async {
  349. Map<String, dynamic> params = {};
  350. params = data!;
  351. Map<String, String> headers = {};
  352. // headers["Content-Type"] = "application/x-www-form-urlencoded";
  353. // headers["Accept"] = "application/x.yyjobs-api.v1+json";
  354. final result = await dioEngine.requestNetResult(
  355. // ApiConstants.apiServerTime, // api 地址
  356. '/api/v1/user/service/paid-service-order/price', // api 地址
  357. params: params,
  358. headers: headers,
  359. method: HttpMethod.GET,
  360. isShowLoadingDialog: false,
  361. //是否展示默认的Loading弹窗
  362. networkDebounce: true,
  363. //是否防抖防止重复请求
  364. cancelToken: cancelToken,
  365. );
  366. //根据返回的结果,封装原始数据为Bean/Entity对象
  367. if (result.isSuccess) {
  368. //重新赋值data或list
  369. final json = result.getDataJson();
  370. // var data = GarageSaleRentDetailEntity.fromJson(json!);
  371. //重新赋值data或list
  372. return result.convert(data: json);
  373. } else {
  374. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  375. ToastEngine.show("${result.errorMsg}");
  376. }
  377. }
  378. return result.convert();
  379. }
  380. // 付费服务 取消订单
  381. Future<HttpResult> fetchCancelPaidServiceOrder({
  382. required String? id,
  383. required String? reason,
  384. CancelToken? cancelToken,
  385. }) async {
  386. Map<String, String> params = {};
  387. params['id'] = id ?? "";
  388. params['cancel_reason'] = reason ?? "";
  389. final result = await dioEngine.requestNetResult(
  390. '/api/v1/user/service/paid-service-order/cancel',
  391. params: params,
  392. method: HttpMethod.POST,
  393. isShowLoadingDialog: true,
  394. networkDebounce: true,
  395. cancelToken: cancelToken,
  396. );
  397. if (result.isSuccess) {
  398. return result.convert();
  399. }
  400. return result.convert();
  401. }
  402. ///-------------------咨询类---------------------------------
  403. // 维修服务 列表
  404. Future<HttpResult<Object>> fetchRepairServiceList(
  405. Map<String, dynamic>? data, {
  406. CancelToken? cancelToken,
  407. }) async {
  408. Map<String, dynamic> params = {};
  409. params = data!;
  410. Map<String, String> headers = {};
  411. headers["Content-Type"] = "application/x-www-form-urlencoded";
  412. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  413. final result = await dioEngine.requestNetResult(
  414. // ApiConstants.apiServerTime, // api 地址
  415. '/api/v1/user/service/inquiry-service/index', // api 地址
  416. params: params,
  417. headers: headers,
  418. method: HttpMethod.GET,
  419. isShowLoadingDialog: false,
  420. //是否展示默认的Loading弹窗
  421. networkDebounce: true,
  422. //是否防抖防止重复请求
  423. cancelToken: cancelToken,
  424. );
  425. //根据返回的结果,封装原始数据为Bean/Entity对象
  426. if (result.isSuccess) {
  427. //重新赋值data或list
  428. final json = result.getDataJson();
  429. var data = GarageSaleRentEntity.fromJson(json!);
  430. //重新赋值data或list
  431. return result.convert(data: data);
  432. } else {
  433. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  434. ToastEngine.show("${result.errorMsg}");
  435. }
  436. }
  437. return result.convert();
  438. }
  439. // 获取 repair 详情信息
  440. Future<HttpResult<Object>> fetchServiceRepairDetailInfo(
  441. Map<String, dynamic>? data, {
  442. CancelToken? cancelToken,
  443. }) async {
  444. Map<String, dynamic> params = {};
  445. params = data!;
  446. Map<String, String> headers = {};
  447. // headers["Content-Type"] = "application/x-www-form-urlencoded";
  448. // headers["Accept"] = "application/x.yyjobs-api.v1+json";
  449. final result = await dioEngine.requestNetResult(
  450. // ApiConstants.apiServerTime, // api 地址
  451. '/api/v1/user/service/inquiry-service/detail', // api 地址
  452. params: params,
  453. headers: headers,
  454. method: HttpMethod.GET,
  455. isShowLoadingDialog: false,
  456. //是否展示默认的Loading弹窗
  457. networkDebounce: true,
  458. //是否防抖防止重复请求
  459. cancelToken: cancelToken,
  460. );
  461. //根据返回的结果,封装原始数据为Bean/Entity对象
  462. if (result.isSuccess) {
  463. //重新赋值data或list
  464. final json = result.getDataJson();
  465. var data = GarageSaleRentDetailEntity.fromJson(json!);
  466. //重新赋值data或list
  467. return result.convert(data: data);
  468. } else {
  469. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  470. ToastEngine.show("${result.errorMsg}");
  471. }
  472. }
  473. return result.convert();
  474. }
  475. // 维修服务 提交咨询
  476. Future<HttpResult<Object>> fetchRepairServiceSubmit(
  477. Map<String, dynamic>? data, {
  478. CancelToken? cancelToken,
  479. }) async {
  480. Map<String, dynamic> params = {};
  481. params = data!;
  482. Map<String, String> headers = {};
  483. headers["Content-Type"] = "application/x-www-form-urlencoded";
  484. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  485. final result = await dioEngine.requestNetResult(
  486. // ApiConstants.apiServerTime, // api 地址
  487. '/api/v1/user/service/inquiry-service-order/submit', // api 地址
  488. params: params,
  489. headers: headers,
  490. method: HttpMethod.POST,
  491. isShowLoadingDialog: true,
  492. //是否展示默认的Loading弹窗
  493. networkDebounce: true,
  494. //是否防抖防止重复请求
  495. cancelToken: cancelToken,
  496. );
  497. //根据返回的结果,封装原始数据为Bean/Entity对象
  498. if (result.isSuccess) {
  499. //重新赋值data或list
  500. final json = result.getDataJson();
  501. // var data = NewsfeedForyouEntity.fromJson(json!);
  502. //重新赋值data或list
  503. return result.convert(data: json);
  504. } else {
  505. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  506. ToastEngine.show("${result.errorMsg}");
  507. }
  508. }
  509. return result.convert();
  510. }
  511. // 维修服务 订单列表
  512. Future<HttpResult<Object>> fetchRepairServiceOrderList(
  513. Map<String, dynamic>? data, {
  514. CancelToken? cancelToken,
  515. }) async {
  516. Map<String, dynamic> params = {};
  517. params = data!;
  518. Map<String, String> headers = {};
  519. headers["Content-Type"] = "application/x-www-form-urlencoded";
  520. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  521. final result = await dioEngine.requestNetResult(
  522. // ApiConstants.apiServerTime, // api 地址
  523. '/api/v1/user/service/inquiry-service-order/index', // api 地址
  524. params: params,
  525. headers: headers,
  526. method: HttpMethod.GET,
  527. isShowLoadingDialog: false,
  528. //是否展示默认的Loading弹窗
  529. networkDebounce: true,
  530. //是否防抖防止重复请求
  531. cancelToken: cancelToken,
  532. );
  533. //根据返回的结果,封装原始数据为Bean/Entity对象
  534. if (result.isSuccess) {
  535. //重新赋值data或list
  536. final json = result.getDataJson();
  537. var data = GarageSaleRentEntity.fromJson(json!);
  538. //重新赋值data或list
  539. return result.convert(data: data);
  540. } else {
  541. if (result.errorMsg != null && result.errorMsg!.isNotEmpty) {
  542. ToastEngine.show("${result.errorMsg}");
  543. }
  544. }
  545. return result.convert();
  546. }
  547. }