services_respository.dart 20 KB

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