From 419e0f18a4ea2a9784cebeee08d96473d3c00dc1 Mon Sep 17 00:00:00 2001 From: "925116093-qq.com" <925116093@qq.com> Date: Wed, 2 Jul 2025 14:29:27 +0800 Subject: [PATCH] 202507021429 --- .../QuoteMaterial/index_20250521145928.vue | 350 - .../QuoteMaterial/index_20250521151302.vue | 350 - .../QuoteMaterial/index_20250521151456.vue | 356 - .../QuoteMaterial/index_20250521151520.vue | 356 - .../QuoteMaterial/index_20250521151604.vue | 358 - .../QuoteMaterial/index_20250521151647.vue | 358 - .../QuoteMaterial/index_20250521151709.vue | 352 - .../QuoteMaterial/index_20250521151753.vue | 362 - .../QuoteMaterial/index_20250521151826.vue | 363 - .../QuoteMaterial/index_20250521152442.vue | 381 - .../QuoteMaterial/index_20250521152609.vue | 385 - .../QuoteMaterial/index_20250521152611.vue | 385 - .../QuoteMaterial/index_20250521152622.vue | 385 - .../QuoteMaterial/index_20250521152626.vue | 385 - .../ServiceGoods/index_20250519125039.vue | 508 - .../ServiceGoods/index_20250520141155.vue | 508 - .../ServiceGoods/index_20250520141156.vue | 508 - .../ServiceGoods/index_20250520141226.vue | 508 - .../ServiceGoods/index_20250520141943.vue | 511 - .../ServiceGoods/index_20250520141946.vue | 511 - .../ServiceGoods/index_20250520142005.vue | 514 - .../ServiceGoods/index_20250520142010.vue | 514 - .../ServiceGoods/index_20250520173526.vue | 515 - .../ServiceGoods/index_20250520173556.vue | 515 - .../ServiceGoods/index_20250520174150.vue | 533 - .../ServiceGoods/index_20250520174407.vue | 533 - .../ServiceGoods/index_20250520174433.vue | 533 - .../ServiceGoods/index_20250520175313.vue | 532 - .../ServiceGoods/index_20250520175503.vue | 532 - .../ServiceGoods/index_20250520180349.vue | 532 - .../ServiceGoods/index_20250520180355.vue | 531 - .../ServiceGoods/index_20250520180416.vue | 530 - pom.xml | 6 +- ruoyi-common/pom.xml | 2 +- .../system/controller/AppletController.java | 9914 ++++++++--------- .../ruoyi/system/controller/CursorUtil.java | 6 +- .../controller/PayNotifyController.java | 86 +- .../controller/SiteConfigController.java | 17 + .../UserDemandQuotationController.java | 104 + .../controller/UserGroupBuyingController.java | 104 + .../system/controller/UsersController.java | 18 + .../controller/WorkerApplyController.java | 4 +- .../controllerUtil/AppletControllerUtil.java | 872 +- .../ruoyi/system/domain/QuoteMaterial.java | 46 + .../com/ruoyi/system/domain/ServiceGoods.java | 136 + .../system/domain/UserDemandQuotation.java | 173 + .../ruoyi/system/domain/UserGroupBuying.java | 217 + .../ruoyi/system/domain/UsersInvoiceInfo.java | 166 +- .../mapper/UserDemandQuotationMapper.java | 61 + .../system/mapper/UserGroupBuyingMapper.java | 61 + .../service/IUserDemandQuotationService.java | 61 + .../service/IUserGroupBuyingService.java | 61 + .../impl/UserDemandQuotationServiceImpl.java | 93 + .../impl/UserGroupBuyingServiceImpl.java | 93 + .../mapper/system/QuoteMaterialMapper.xml | 22 +- .../mapper/system/ServiceGoodsMapper.xml | 50 +- .../system/UserDemandQuotationMapper.xml | 95 + .../mapper/system/UserGroupBuyingMapper.xml | 105 + .../mapper/system/UsersInvoiceInfoMapper.xml | 50 +- ruoyi-ui/src/api/system/QuoteMaterial.js | 9 + ruoyi-ui/src/api/system/ServiceGoods.js | 8 +- ruoyi-ui/src/api/system/buying.js | 44 + ruoyi-ui/src/api/system/quotation.js | 44 + .../src/views/system/QuoteMaterial/index.vue | 91 +- .../src/views/system/QuoteMaterial/index1.vue | 100 +- .../src/views/system/ServiceGoods/index.vue | 262 +- .../src/views/system/SiteConfig/index.vue | 56 + .../src/views/system/UsersWorker/index.vue | 55 +- .../src/views/system/buying/index.vue | 225 +- ruoyi-ui/src/views/system/info/index.vue | 112 +- .../src/views/system/quotation/index.vue | 175 +- .../WorkerLevelSelectDialog.vue | 62 + 72 files changed, 7800 insertions(+), 20560 deletions(-) delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145928.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151302.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151456.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151520.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151604.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151647.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151709.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151753.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151826.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152442.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152609.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152611.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152622.vue delete mode 100644 .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152626.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250519125039.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141155.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141156.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141226.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141943.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141946.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142005.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142010.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173526.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173556.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174150.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174407.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174433.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175313.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175503.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180349.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180355.vue delete mode 100644 .history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180416.vue create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controller/UserDemandQuotationController.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/controller/UserGroupBuyingController.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserDemandQuotationMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/IUserDemandQuotationService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserDemandQuotationServiceImpl.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java create mode 100644 ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml create mode 100644 ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml create mode 100644 ruoyi-ui/src/api/system/buying.js create mode 100644 ruoyi-ui/src/api/system/quotation.js rename .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152617.vue => ruoyi-ui/src/views/system/QuoteMaterial/index1.vue (83%) rename .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145828.vue => ruoyi-ui/src/views/system/buying/index.vue (50%) rename .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250516150652.vue => ruoyi-ui/src/views/system/quotation/index.vue (58%) create mode 100644 ruoyi-ui/src/views/system/workerLevelSelect/WorkerLevelSelectDialog.vue diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145928.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145928.vue deleted file mode 100644 index 88385f0..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145928.vue +++ /dev/null @@ -1,350 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151302.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151302.vue deleted file mode 100644 index a8f0adb..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151302.vue +++ /dev/null @@ -1,350 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151456.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151456.vue deleted file mode 100644 index 75d7ce1..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151456.vue +++ /dev/null @@ -1,356 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151520.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151520.vue deleted file mode 100644 index 75d7ce1..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151520.vue +++ /dev/null @@ -1,356 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151604.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151604.vue deleted file mode 100644 index e2ac8d0..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151604.vue +++ /dev/null @@ -1,358 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151647.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151647.vue deleted file mode 100644 index 35d1b60..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151647.vue +++ /dev/null @@ -1,358 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151709.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151709.vue deleted file mode 100644 index 2401b7d..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151709.vue +++ /dev/null @@ -1,352 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151753.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151753.vue deleted file mode 100644 index f004121..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151753.vue +++ /dev/null @@ -1,362 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151826.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151826.vue deleted file mode 100644 index 1c7728a..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521151826.vue +++ /dev/null @@ -1,363 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152442.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152442.vue deleted file mode 100644 index 137b47f..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152442.vue +++ /dev/null @@ -1,381 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152609.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152609.vue deleted file mode 100644 index db47c62..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152609.vue +++ /dev/null @@ -1,385 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152611.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152611.vue deleted file mode 100644 index db47c62..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152611.vue +++ /dev/null @@ -1,385 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152622.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152622.vue deleted file mode 100644 index db47c62..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152622.vue +++ /dev/null @@ -1,385 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152626.vue b/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152626.vue deleted file mode 100644 index db47c62..0000000 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152626.vue +++ /dev/null @@ -1,385 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250519125039.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250519125039.vue deleted file mode 100644 index 3bb1f8e..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250519125039.vue +++ /dev/null @@ -1,508 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141155.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141155.vue deleted file mode 100644 index 40d7bf6..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141155.vue +++ /dev/null @@ -1,508 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141156.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141156.vue deleted file mode 100644 index 40d7bf6..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141156.vue +++ /dev/null @@ -1,508 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141226.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141226.vue deleted file mode 100644 index 40d7bf6..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141226.vue +++ /dev/null @@ -1,508 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141943.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141943.vue deleted file mode 100644 index 05c5017..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141943.vue +++ /dev/null @@ -1,511 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141946.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141946.vue deleted file mode 100644 index 05c5017..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520141946.vue +++ /dev/null @@ -1,511 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142005.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142005.vue deleted file mode 100644 index 29b1633..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142005.vue +++ /dev/null @@ -1,514 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142010.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142010.vue deleted file mode 100644 index 29b1633..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520142010.vue +++ /dev/null @@ -1,514 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173526.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173526.vue deleted file mode 100644 index 501fc23..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173526.vue +++ /dev/null @@ -1,515 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173556.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173556.vue deleted file mode 100644 index 501fc23..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520173556.vue +++ /dev/null @@ -1,515 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174150.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174150.vue deleted file mode 100644 index 79d338b..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174150.vue +++ /dev/null @@ -1,533 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174407.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174407.vue deleted file mode 100644 index 79d338b..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174407.vue +++ /dev/null @@ -1,533 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174433.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174433.vue deleted file mode 100644 index 874ad2a..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520174433.vue +++ /dev/null @@ -1,533 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175313.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175313.vue deleted file mode 100644 index 807f711..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175313.vue +++ /dev/null @@ -1,532 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175503.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175503.vue deleted file mode 100644 index 807f711..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520175503.vue +++ /dev/null @@ -1,532 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180349.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180349.vue deleted file mode 100644 index 807f711..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180349.vue +++ /dev/null @@ -1,532 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180355.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180355.vue deleted file mode 100644 index 21165f6..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180355.vue +++ /dev/null @@ -1,531 +0,0 @@ - - - diff --git a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180416.vue b/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180416.vue deleted file mode 100644 index 80513ca..0000000 --- a/.history/ruoyi-ui/src/views/system/ServiceGoods/index_20250520180416.vue +++ /dev/null @@ -1,530 +0,0 @@ - - - diff --git a/pom.xml b/pom.xml index d1bcd4f..be02b34 100644 --- a/pom.xml +++ b/pom.xml @@ -2,8 +2,8 @@ - 4.0.0 - + 4.0.0 + com.ruoyi hfrj 3.8.9 @@ -11,7 +11,7 @@ ruoyi http://www.ruoyi.vip 西安华府人家装饰工程有限公司 - + 3.8.9 UTF-8 diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index 9c1e349..05097ee 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -61,7 +61,7 @@ org.apache.commons commons-lang3 - + com.fasterxml.jackson.core diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java index ed7944f..fc01954 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/AppletController.java @@ -6,7 +6,6 @@ import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.ControllerUtil.*; import com.ruoyi.system.domain.*; import com.ruoyi.system.domain.AppleDoMain.OrderApple; @@ -124,16 +123,14 @@ public class AppletController extends BaseController { private IWorkerApplyService workerApplyService; @Autowired private IUserMemberRechargeProgramService userMemberRechargeProgramService; - @Autowired private IUserMemberRechargeLogService userMemberRechargeLogService; - @Autowired private IUserMemnerConsumptionLogService userMemnerConsumptionLogService; - @Autowired private IUsersInvoiceInfoService usersInvoiceInfoService; - + @Autowired + private IUserGroupBuyingService userGroupBuyingService; /** * 获取服务分类列表 * @@ -155,7 +152,6 @@ public class AppletController extends BaseController { ServiceCate serviceCateQuery = new ServiceCate(); serviceCateQuery.setStatus(1L); // 启用状态 // serviceCateQuery.setType(1L); // 服务类型 - // 查询分类列表 List categoryList = serviceCateService.selectServiceCateList(serviceCateQuery); @@ -244,8 +240,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("获取配置信息失败:" + e.getMessage()); } } - - /** * 查询用户收货地址列表 * @@ -258,22 +252,6 @@ public class AppletController extends BaseController { * - limit: 每页显示数量,默认15 * - page: 页码,默认1 *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [...], - * "from": 1, - * "last_page": 1, - * "next_page_url": null, - * "per_page": "15", - * "prev_page_url": null, - * "to": 1, - * "total": 1 - * } - * } */ @GetMapping("/api/user/address/list") public AjaxResult getaddresslist( @@ -321,7 +299,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("查询地址列表失败:" + e.getMessage()); } } - /** * 根据地址ID查询用户收货地址详情 * @@ -334,25 +311,6 @@ public class AppletController extends BaseController { * - 验证用户登录状态和地址归属权 * - 返回AddressApple格式的地址数据,用于前端修改页面 *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "id": 160, - * "uid": 302, - * "name": "赵先生", - * "phone": "18709185987", - * "latitude": "34.15643", - * "longitude": "108.86683", - * "address_name": "陕西省西安市长安区榆林北段与建设大道交叉口处北侧", - * "address_info": "陕西省西安市长安区榆林北段与建设大道交叉口处", - * "info": "14号楼2302", - * "is_default": 0, - * "created_at": null, - * "updated_at": null - * } - * } */ @GetMapping("/api/user/address/info/{id}") public AjaxResult getAddressInfo(@PathVariable("id") Long id, HttpServletRequest request) { @@ -403,32 +361,11 @@ public class AppletController extends BaseController { * @param params 地址修改参数 * @param request HTTP请求对象 * @return 修改结果 - *

- * 请求参数格式: - * { - * "id": 160, - * "name": "赵先生", - * "phone": "18709185987", - * "address_name": "陕西省西安市长安区榆林北段与建设大道交叉口处北侧", - * "address_info": "海菱路8号", - * "info": "14号楼2302", - * "is_default": 1, - * "latitude": "34.15643", - * "longitude": "108.86683" - * } - *

* 接口说明: * - 验证用户登录状态和地址归属权 * - 支持修改地址的所有字段 * - 自动处理默认地址逻辑(设为默认时会取消其他默认地址) * - 返回修改后的地址信息 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": "地址修改成功" - * } */ @PostMapping("/api/user/address/edit") public AjaxResult editAddress(@RequestBody Map params, HttpServletRequest request) { @@ -508,31 +445,11 @@ public class AppletController extends BaseController { * @param params 地址新增参数 * @param request HTTP请求对象 * @return 新增结果 - *

- * 请求参数格式: - * { - * "name": "何飞飞", - * "phone": "15002954325", - * "address_name": "陕西省西安市未央区未央路3号(龙首原地铁站C出口步行180米)", - * "address_info": "凤鑫城购物中心(未央路店)", - * "info": "458", - * "is_default": true, - * "latitude": 34.294248, - * "longitude": 108.948261 - * } - *

* 接口说明: * - 验证用户登录状态 * - 支持新增地址的所有字段 * - 自动处理默认地址逻辑(设为默认时会取消其他默认地址) * - 返回新增后的地址信息 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": "地址新增成功" - * } */ @PostMapping("/api/user/address/add") public AjaxResult addAddress(@RequestBody Map params, HttpServletRequest request) { @@ -724,8 +641,6 @@ public class AppletController extends BaseController { if (StringUtils.isNotNull(status) && !"".equals(status)) { order.setStatus(Long.valueOf(status)); } - - List orderList = orderService.selectOrderAppleList(order); for (OrderApple orderdata : orderList) { Map jsonObject = new HashMap<>(); @@ -763,47 +678,6 @@ public class AppletController extends BaseController { * - 支持按订单状态筛选 * - 返回带分页信息的订单列表 * - 包含完整的商品信息和订单状态文本 - *

- * 请求参数格式: - * { - * "limit": 15, - * "page": 1, - * "status": "2" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 1, - * "order_id": "C307236827627129", - * "order_no": "C307236827627129", - * "status": 2, - * "status_text": "待发货", - * "total_price": "4.90", - * "num": 1, - * "pay_time": "2024-08-31 12:02:07", - * "created_at": "2024-08-31 12:02:07", - * "product": { - * "id": 86, - * "title": "长青泉·饮用天然泉水", - * "sub_title": "长青泉 1.5L*1瓶 4.9元", - * "icon": "https://img.huafurenjia.cn/images/...", - * "price": "4.90", - * "num": 1 - * } - * } - * ], - * "total": 3, - * "per_page": 15, - * "current_page": 1, - * "last_page": 1 - * } - * } */ @PostMapping("/api/goods/order/lst") public AjaxResult getgoodsorderlst(@RequestBody Map params, @@ -896,13 +770,10 @@ public class AppletController extends BaseController { orderData.put("product", productInfo); } } - resultList.add(orderData); } - // 8. 构建分页信息 PageInfo pageInfo = new PageInfo<>(orderList); - // 9. 构建返回数据格式(简化版本,更适合小程序) Map responseData = new HashMap<>(); responseData.put("current_page", pageInfo.getPageNum()); @@ -929,7 +800,6 @@ public class AppletController extends BaseController { if (status == null) { return "未知状态"; } - switch (status.intValue()) { case 1: return "待付款"; @@ -1043,9 +913,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("查询服务商品列表失败:" + e.getMessage()); } } - - - /** * 获取服务商品详细信息 * @@ -1087,13 +954,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("查询商品详情失败:" + e.getMessage()); } } - - - - - - - /** * 获取广告图片列表 * @@ -1131,37 +991,12 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("获取广告图片失败:" + e.getMessage()); } } - /** * 微信用户登录接口 * * @param params 请求参数 * @param request HTTP请求对象 * @return 登录结果 - *

- * 请求参数格式: - * { - * "usercode": "微信小程序登录code", - * "code": "手机号授权code" - * } - *

- * 返回数据格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "user": { - * "id": 用户ID, - * "phone": "手机号", - * "name": "用户名", - * "openid": "微信openid", - * "remember_token": "用户token", - * "avatar": "头像地址", - * "isNewUser": true/false - * } - * } - * } - *

* 登录流程: * 1. 验证请求参数 * 2. 通过usercode获取微信openid @@ -1174,20 +1009,6 @@ public class AppletController extends BaseController { // 使用AppletLoginUtil执行完整的微信登录流程 return AppletLoginUtil.executeWechatLogin(params, usersService); } - - - /** - * 获取用户详细信息接口 - * - * @param request HTTP请求对象 - * @return 返回用户详细信息包含订单统计 - * - * 功能说明: - * - 通过token获取用户基本信息 - * - 返回用户的服务订单和商品订单统计数据 - * - 包含各种订单状态的数量统计 - * - 用于用户中心页面显示 - */ /** * 获取用户基本信息接口 * @@ -1199,28 +1020,6 @@ public class AppletController extends BaseController { * - 返回完整的用户数据 * - 需要用户登录验证 *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 302, - * "name": "微信用户", - * "nickname": null, - * "phone": "18709185987", - * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", - * "commission": 0, - * "created_at": "2024-08-31 12:02:07", - * "integral": 0, - * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", - * "remember_token": "G88BSThmFCprrT0uTZ9ghDzW7QHj19CrwSwdq3e", - * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], - * "skill_ids": ["19", "21", "25", "28", "35"], - * "status": 1, - * "total_integral": 100, - * "updated_at": "2025-06-11 10:35:44" - * } - * } */ @GetMapping(value = "/api/user/info") public AjaxResult getUserInfo(HttpServletRequest request) { @@ -1291,7 +1090,6 @@ public class AppletController extends BaseController { } - /** * 构建用户信息响应数据 * @@ -1394,39 +1192,6 @@ public class AppletController extends BaseController { * - 自动处理服务城市ID和技能ID数组 * - 需要用户登录验证 *

- * 请求参数格式: - * { - * "id": 302, - * "name": "微信用户P44455", - * "nickname": null, - * "phone": "18709185987", - * "avatar": "https://img.huafurenjia.cn/default/user_avatar.jpeg", - * "commission": 0, - * "integral": 0, - * "is_stop": 1, - * "job_number": null, - * "level": null, - * "login_status": 2, - * "margin": 0, - * "middle_auth": null, - * "openid": "oHIYB7DYezs7Myzn-yaF0amC3Bpc", - * "prohibit_time": null, - * "propose": "0.00", - * "service_city_ids": ["2", "5", "7", "10", "11", "12", "13", "14", "15", "16", "17"], - * "skill_ids": ["19", "21", "25", "20", "35"], - * "status": 1, - * "total_comm": 0, - * "total_integral": 100, - * "type": "1", - * "worker_time": null - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": [] - * } */ @PostMapping(value = "/api/user/edit/info") public AjaxResult editUserInfo(@RequestBody Map params, HttpServletRequest request) { @@ -1459,10 +1224,10 @@ public class AppletController extends BaseController { } // 5. 构建更新用户对象 - Users updateUser = buildUpdateUserFromParams(params, currentUser.getId()); + Users updateUser = AppletControllerUtil.buildUpdateUserFromdataParams(params, currentUser.getId()); // 6. 验证必要字段 - String validationResult = validateUserEditParams(updateUser); + String validationResult = validateUserEditdataParams(updateUser); if (validationResult != null) { return AppletControllerUtil.appletWarning(validationResult); } @@ -1482,142 +1247,10 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletError("修改用户信息失败:" + e.getMessage()); } } - - /** - * 从请求参数构建更新用户对象 - * - * @param params 请求参数 - * @param userId 用户ID - * @return 用户更新对象 - */ - private Users buildUpdateUserFromParams(Map params, Long userId) { - Users updateUser = new Users(); - updateUser.setId(userId); - - // 基本信息字段 - if (params.get("name") != null) { - updateUser.setName(params.get("name").toString().trim()); - } - - if (params.get("nickname") != null && !params.get("nickname").toString().trim().isEmpty()) { - updateUser.setNickname(params.get("nickname").toString().trim()); - } - - if (params.get("phone") != null) { - updateUser.setPhone(params.get("phone").toString().trim()); - } - - // 头像处理 - 去掉CDN前缀保存相对路径 - if (params.get("avatar") != null) { - String avatar = params.get("avatar").toString().trim(); - if (avatar.startsWith("https://img.huafurenjia.cn/")) { - avatar = avatar.replace("https://img.huafurenjia.cn/", ""); - } - updateUser.setAvatar(avatar); - } - - // 数值字段 - 根据Users实体类的实际字段类型 - if (params.get("integral") != null) { - updateUser.setIntegral(parseToLongForEdit(params.get("integral"))); - } - - if (params.get("is_stop") != null) { - Integer isStop = parseToIntegerForEdit(params.get("is_stop")); - updateUser.setIsStop(isStop); - } - - if (params.get("login_status") != null) { - Integer loginStatus = parseToIntegerForEdit(params.get("login_status")); - updateUser.setLoginStatus(loginStatus); - } - - if (params.get("status") != null) { - Integer status = parseToIntegerForEdit(params.get("status")); - updateUser.setStatus(status); - } - - if (params.get("total_integral") != null) { - updateUser.setTotalIntegral(parseToLongForEdit(params.get("total_integral"))); - } - - // 字符串和其他字段 - if (params.get("job_number") != null && !params.get("job_number").toString().trim().isEmpty()) { - Integer jobNumber = parseToIntegerForEdit(params.get("job_number")); - updateUser.setJobNumber(jobNumber); - } - - if (params.get("level") != null && !params.get("level").toString().trim().isEmpty()) { - Integer level = parseToIntegerForEdit(params.get("level")); - updateUser.setLevel(level); - } - - if (params.get("middle_auth") != null && !params.get("middle_auth").toString().trim().isEmpty()) { - Integer middleAuth = parseToIntegerForEdit(params.get("middle_auth")); - updateUser.setMiddleAuth(middleAuth); - } - - if (params.get("propose") != null) { - // propose字段是BigDecimal类型,需要转换 - String proposeStr = params.get("propose").toString().trim(); - try { - BigDecimal propose = new BigDecimal(proposeStr); - updateUser.setPropose(propose); - } catch (NumberFormatException e) { - // 忽略格式错误,保持原值 - } - } - - if (params.get("type") != null) { - // type字段是String类型 - updateUser.setType(params.get("type").toString().trim()); - } - - // 处理服务城市ID数组 - if (params.get("service_city_ids") != null) { - List serviceCityIds = (List) params.get("service_city_ids"); - if (!serviceCityIds.isEmpty()) { - updateUser.setServiceCityIds(String.join(",", serviceCityIds)); - } - } - - // 处理技能ID数组 - if (params.get("skill_ids") != null) { - List skillIds = (List) params.get("skill_ids"); - if (!skillIds.isEmpty()) { - updateUser.setSkillIds(String.join(",", skillIds)); - } - } - - // 设置更新时间 - updateUser.setUpdatedAt(new Date()); - - return updateUser; - } - - /** - * 解析对象为Long类型(用于编辑接口) - */ - private Long parseToLongForEdit(Object value) { - if (value == null) return null; - - if (value instanceof Integer) { - return ((Integer) value).longValue(); - } else if (value instanceof Long) { - return (Long) value; - } else if (value instanceof String) { - try { - return Long.parseLong((String) value); - } catch (NumberFormatException e) { - return null; - } - } - return null; - } - /** * 解析对象为Integer类型(用于编辑接口) */ - private Integer parseToIntegerForEdit(Object value) { + private Integer parseToIntegerdataForEdit(Object value) { if (value == null) return null; if (value instanceof Integer) { @@ -1633,26 +1266,23 @@ public class AppletController extends BaseController { } return null; } - /** * 验证用户编辑参数 * * @param user 用户对象 * @return 验证结果,null表示验证通过 */ - private String validateUserEditParams(Users user) { + private String validateUserEditdataParams(Users user) { // 验证手机号格式(如果提供了的话) if (user.getPhone() != null && !user.getPhone().isEmpty()) { if (!user.getPhone().matches("^1[3-9]\\d{9}$")) { return "手机号格式不正确"; } } - // 验证用户名长度 if (user.getName() != null && user.getName().length() > 50) { return "用户名长度不能超过50个字符"; } - // 验证昵称长度 if (user.getNickname() != null && user.getNickname().length() > 50) { return "昵称长度不能超过50个字符"; @@ -1667,22 +1297,6 @@ public class AppletController extends BaseController { * @param request HTTP请求对象 * @return 验证结果 *

- * 请求头格式: - * Authorization: Bearer - * 或 - * token: - *

- * 返回数据格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "valid": true, - * "userInfo": {...}, - * "message": "token验证成功" - * } - * } - *

* 接口说明: * - 验证用户token的有效性 * - 返回用户基本信息 @@ -1718,42 +1332,12 @@ public class AppletController extends BaseController { } } - - - - /** * 微信支付统一下单接口 * * @param params 支付参数 * @param request HTTP请求对象 * @return 支付结果 - *

- * 请求参数格式: - * { - * "orderNo": "订单号", - * "openid": "用户openid", - * "totalFee": 支付金额(分), - * "body": "商品描述", - * "notifyUrl": "回调地址" - * } - *

- * 返回数据格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "success": true, - * "payParams": { - * "timeStamp": "时间戳", - * "nonceStr": "随机字符串", - * "package": "prepay_id=xxx", - * "signType": "MD5", - * "paySign": "签名" - * }, - * "prepayId": "预支付交易会话ID" - * } - * } */ @PostMapping(value = "/api/pay/unifiedorder") public AjaxResult createPayOrder(@RequestBody Map params, HttpServletRequest request) { @@ -1820,17 +1404,6 @@ public class AppletController extends BaseController { * @param params 代付参数 * @param request HTTP请求对象 * @return 代付结果 - *

- * 请求参数格式: - * { - * "orderNo": "原订单号", - * "payerOpenid": "代付人openid", - * "payeeOpenid": "被代付人openid", - * "totalFee": 代付金额(分), - * "body": "商品描述", - * "notifyUrl": "回调地址", - * "remark": "代付备注" - * } */ @PostMapping(value = "/api/pay/payfor") public AjaxResult createPayForOrder(@RequestBody Map params, HttpServletRequest request) { @@ -1938,10 +1511,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("申请退款失败:" + e.getMessage()); } } - - - - /** * 查询用户售后返修列表 * @@ -2047,21 +1616,6 @@ public class AppletController extends BaseController { * - 保存合作申请记录 * - 设置默认状态为待处理 *

- * 请求参数格式: - * { - * "company": "河南公司", - * "name": "王令兵", - * "phone": "15002954234", - * "address": "来宾", - * "info": "情感咨询" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": "合作申请提交成功,我们会尽快联系您" - * } */ @PostMapping("/api/form/cooperate") public AjaxResult submitCooperateApplication(@RequestBody Map params, HttpServletRequest request) { @@ -2142,8 +1696,6 @@ public class AppletController extends BaseController { return AppletControllerUtil.appletWarning("合作申请提交失败:" + e.getMessage()); } } - - /** * 查询用户优惠券列表 * @@ -2171,75 +1723,65 @@ public class AppletController extends BaseController { Integer status = params.get("status") != null ? Integer.parseInt(params.get("status").toString()) : null; String productId = params.get("product_id") != null ? params.get("product_id").toString() : null; BigDecimal totalPrice = params.get("price") != null ? new BigDecimal(params.get("price").toString()) : null; - // 过期的优惠券标记为已过期 + // 过期的优惠券标记为已过期 CouponUser couponUser = new CouponUser(); couponUser.setStatus(1L); couponUser.setUid(user.getId()); - List couponUserList = couponUserService.selectCouponUserNoList(couponUser); - for (CouponUser c: couponUserList){ - c.setStatus(3L); - couponUserService.updateCouponUser(c); - } - //安状态进行赋值 - //待领取优惠券 - if (status==4){ + List couponUserList = couponUserService.selectCouponUserNoList(couponUser); + for (CouponUser c: couponUserList){ + c.setStatus(3L); + couponUserService.updateCouponUser(c); + } + //安状态进行赋值 + //待领取优惠券 + if (status==4){ // Coupons coupons = new Coupons(); // coupons.setSearchValue("12"); List couponsList =CouponUtil.iscoupon(userId,couponsService,couponUserService); if (!couponsList.isEmpty()){ - return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponDataList(couponsList,serviceCateService,serviceGoodsService)); + return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponDataList(couponsList,serviceCateService,serviceGoodsService)); } - }else{ - CouponUser couponUserData = new CouponUser(); - couponUserData.setStatus(Long.valueOf(status)); - couponUserData.setUid(user.getId()); - - - List couponUserDataList = couponUserService.selectCouponUserList(couponUserData); - if (couponUserDataList!=null){ - return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponUserList(couponUserDataList,serviceCateService,serviceGoodsService,productId,totalPrice)); - } - - - } + }else{ + CouponUser couponUserData = new CouponUser(); + couponUserData.setStatus(Long.valueOf(status)); + couponUserData.setUid(user.getId()); + List couponUserDataList = couponUserService.selectCouponUserList(couponUserData); + if (couponUserDataList!=null){ + return AppletControllerUtil.appletSuccess(AppletControllerUtil.buildCouponUserList(couponUserDataList,serviceCateService,serviceGoodsService,productId,totalPrice)); + } + } // 按is_use排序 - return AjaxResult.success(); } - - - /** * 积分订单收货确认接口 * @param request * @return AjaxResult * 订单状态 1:待支付 2:已支付,待发货3:待收货 4:待评价 5:已收货 6:取消 20:申请退款 21:同意退款 22:驳回退款 */ - @GetMapping("/api/integral/user/order/confirm/{id}") public AjaxResult confirmOrder(@PathVariable("id") String id,HttpServletRequest request) { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(Long.valueOf(id)); - if (integralOrder==null){ - return AppletControllerUtil.appletWarning("订单不存在"); - } - if(!user.getId().equals(integralOrder.getUid())){ - return AppletControllerUtil.appletWarning("确认收货失败,收货人和操作人应为同一人,请确认后再进行操作"); - } - if (!integralOrder.getStatus().equals("2")){ - return AppletControllerUtil.appletWarning("订单状态错误"); - } + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(Long.valueOf(id)); + if (integralOrder==null){ + return AppletControllerUtil.appletWarning("订单不存在"); + } + if(!user.getId().equals(integralOrder.getUid())){ + return AppletControllerUtil.appletWarning("确认收货失败,收货人和操作人应为同一人,请确认后再进行操作"); + } + if (!integralOrder.getStatus().equals("2")){ + return AppletControllerUtil.appletWarning("订单状态错误"); + } integralOrder.setStatus("3"); integralOrderService.updateIntegralOrder(integralOrder); IntegralOrderLog integralOrderLog = new IntegralOrderLog(); @@ -2258,9 +1800,6 @@ public class AppletController extends BaseController { } } - - - /** * 商品订单评价接口 * @param param {order_id, content, num, images} @@ -2311,2247 +1850,1735 @@ public class AppletController extends BaseController { comment.setContent(content); comment.setNum((long) num); comment.setUid(goodsOrder.getUid()); // 或uid - comment.setImages(imagesObj != null ? com.alibaba.fastjson2.JSON.toJSONString(imagesObj) : null); + comment.setImages(imagesObj != null ? JSON.toJSONString(imagesObj) : null); comment.setNumType(numType); comment.setCreatedAt(new java.util.Date()); comment.setUpdatedAt(new java.util.Date()); comment.setStatus(1); // 显示 int result = orderCommentService.insertOrderComment(comment); if (result > 0) { - goodsOrder.setStatus(5L); // 订单状态改为已收货 - goodsOrderService.updateGoodsOrder(goodsOrder); + goodsOrder.setStatus(5L); // 订单状态改为已收货 + goodsOrderService.updateGoodsOrder(goodsOrder); return AjaxResult.success(); } else { return AjaxResult.error("操作失败"); } } - - - -/** - * 解析参数为Long类型 - */ -private Long parseParamToLong(Object param, String errorMsg) { - if (param == null) return null; - - if (param instanceof Integer) { - return ((Integer) param).longValue(); - } else if (param instanceof String && !((String) param).trim().isEmpty()) { + /** + * 查询用户积分日志列表 + * + * @param params 请求参数,包含limit(每页数量)、page(页码) + * @param request HTTP请求对象 + * @return 返回分页的积分日志列表 + */ + @PostMapping("/api/integral/user/log/lst") + public AjaxResult getUserIntegralLogList(@RequestBody Map params, HttpServletRequest request) { try { - return Long.parseLong((String) param); - } catch (NumberFormatException e) { - throw new RuntimeException(errorMsg); + // 1. 获取分页参数 + int page = params.get("page") != null ? (Integer) params.get("page") : 1; + int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; + // 2. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); + } + // 3. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + // 4. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 5. 设置分页参数 + PageHelper.startPage(page, limit); + // 6. 构建查询条件并查询 + IntegralLog integralLogQuery = new IntegralLog(); + integralLogQuery.setUid(user.getId()); + List integralLogList = integralLogService.selectIntegralLogList(integralLogQuery); + + // 7. 构建分页信息 + PageInfo pageInfo = new PageInfo<>(integralLogList); + + // 8. 使用工具类处理数据格式化 + List> formattedLogList = AppletControllerUtil.buildIntegralLogList(integralLogList); + Map paginationData = AppletControllerUtil.buildPaginationResponse( + pageInfo, formattedLogList, "https://www.huafurenjia.cn/api/integral/user/log/lst"); + Map userData = AppletControllerUtil.buildUserDataInfo(user); + + // 9. 构建最终返回数据结构 + Map responseData = new HashMap<>(); + responseData.put("data", paginationData); + responseData.put("user", userData); + responseData.put("msg", "OK"); + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + System.err.println("查询用户积分日志列表异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分日志列表失败:" + e.getMessage()); } } - return null; -} -/** - * 解析参数为Integer类型 - */ -private Integer parseParamToInteger(Object param, String errorMsg) { - if (param == null) return null; - - if (param instanceof Integer) { - return (Integer) param; - } else if (param instanceof String && !((String) param).trim().isEmpty()) { + /** + * 查询用户积分商城订单列表 + * + * @param params 请求参数,包含limit(每页数量)、page(页码)、status(订单状态) + * @param request HTTP请求对象 + * @return 返回分页的积分商城订单列表 + */ + @PostMapping("/api/integral/user/order") + public AjaxResult getUserIntegralOrderList(@RequestBody Map params, HttpServletRequest request) { try { - return Integer.parseInt((String) param); - } catch (NumberFormatException e) { - throw new RuntimeException(errorMsg); - } - } - return null; -} - -/** - * 查询用户积分日志列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码) - * @param request HTTP请求对象 - * @return 返回分页的积分日志列表 - */ -@PostMapping("/api/integral/user/log/lst") -public AjaxResult getUserIntegralLogList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 获取分页参数 - int page = params.get("page") != null ? (Integer) params.get("page") : 1; - int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - - // 2. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { - return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } - - // 3. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 4. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 5. 设置分页参数 - PageHelper.startPage(page, limit); - - // 6. 构建查询条件并查询 - IntegralLog integralLogQuery = new IntegralLog(); - integralLogQuery.setUid(user.getId()); - List integralLogList = integralLogService.selectIntegralLogList(integralLogQuery); - - // 7. 构建分页信息 - PageInfo pageInfo = new PageInfo<>(integralLogList); - - // 8. 使用工具类处理数据格式化 - List> formattedLogList = AppletControllerUtil.buildIntegralLogList(integralLogList); - Map paginationData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedLogList, "https://www.huafurenjia.cn/api/integral/user/log/lst"); - Map userData = AppletControllerUtil.buildUserDataInfo(user); - - // 9. 构建最终返回数据结构 - Map responseData = new HashMap<>(); - responseData.put("data", paginationData); - responseData.put("user", userData); - responseData.put("msg", "OK"); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - System.err.println("查询用户积分日志列表异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询积分日志列表失败:" + e.getMessage()); - } -} - -/** - * 查询用户积分商城订单列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码)、status(订单状态) - * @param request HTTP请求对象 - * @return 返回分页的积分商城订单列表 - */ -@PostMapping("/api/integral/user/order") -public AjaxResult getUserIntegralOrderList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 获取分页参数 - int page = params.get("page") != null ? (Integer) params.get("page") : 1; - int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - String status = params.get("status") != null ? params.get("status").toString() : null; - - // 2. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { - return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } - - // 3. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 4. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 5. 设置分页参数 - PageHelper.startPage(page, limit); - - // 6. 构建查询条件并查询 - IntegralOrder integralOrderQuery = new IntegralOrder(); - integralOrderQuery.setUid(user.getId()); - if (status != null && !status.trim().isEmpty()) { - integralOrderQuery.setStatus(status.trim()); - } - List integralOrderList = integralOrderService.selectIntegralOrderList(integralOrderQuery); - - // 7. 构建分页信息 - PageInfo pageInfo = new PageInfo<>(integralOrderList); - - // 8. 使用工具类处理数据格式化 - List> formattedOrderList = AppletControllerUtil.buildIntegralOrderList( - integralOrderList, integralProductService); - Map responseData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedOrderList, "https://www.huafurenjia.cn/api/integral/user/order"); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - System.err.println("查询用户积分商城订单列表异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询积分商城订单列表失败:" + e.getMessage()); - } -} - -/** - * 查询积分订单详情 - * - * @param id 订单ID - * @param request HTTP请求对象 - * @return 返回积分订单详细信息 - */ -@GetMapping("/api/integral/user/order/info/{id}") -public AjaxResult getIntegralOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 1. 参数验证 - if (id == null || id <= 0) { - return AppletControllerUtil.appletWarning("订单ID无效"); - } - - // 2. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 3. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 4. 查询积分订单信息 - IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(id); - if (integralOrder == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - - // 5. 验证订单归属权 - if (!integralOrder.getUid().equals(user.getId())) { - return AppletControllerUtil.appletWarning("无权访问该订单信息"); - } - - // 6. 使用工具类构建订单详情数据 - Map orderData = AppletControllerUtil.buildIntegralOrderDetail( - integralOrder, integralProductService, integralOrderLogService); - - return AppletControllerUtil.appletSuccess(orderData); - - } catch (Exception e) { - System.err.println("查询积分订单详情异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询订单详情失败:" + e.getMessage()); - } -} - -/** - * 查询积分商品分类列表 - * - * @param request HTTP请求对象 - * @return 返回积分商品分类列表 - *

- * 功能说明: - * - 获取所有启用状态的积分商品分类 - * - 返回分类的ID和名称 - * - 用于积分商城分类展示 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 4, - * "title": "家清商品" - * } - * ] - * } - */ -@GetMapping("/api/integral/product/cate") -public AjaxResult getIntegralProductCateList(HttpServletRequest request) { - try { - // 1. 构建查询条件:查询启用状态的积分商品分类 - IntegralCate integralCateQuery = new IntegralCate(); - integralCateQuery.setStatus(1L); // 启用状态 - - // 2. 查询积分商品分类列表 - List integralCateList = integralCateService.selectIntegralCateList(integralCateQuery); - - // 3. 构建返回数据格式 - List> resultList = new ArrayList<>(); - for (IntegralCate integralCate : integralCateList) { - Map cateData = new HashMap<>(); - cateData.put("id", integralCate.getId()); - cateData.put("title", integralCate.getTitle()); - resultList.add(cateData); - } - - return AppletControllerUtil.appletSuccess(resultList); - - } catch (Exception e) { - System.err.println("查询积分商品分类列表异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询分类列表失败:" + e.getMessage()); - } -} - -/** - * 查询积分商品列表 - * - * @param params 请求参数,包含limit(每页数量)、page(页码)、type(分类ID) - * @param request HTTP请求对象 - * @return 返回分页的积分商品列表 - *

- * 功能说明: - * - 获取积分商品列表,支持分页 - * - 支持按分类筛选 - * - 返回商品详细信息和分页信息 - * - 按创建时间倒序排列 - *

- * 请求参数格式: - * { - * "limit": 15, // 每页显示数量 - * "page": 1, // 页码 - * "type": "1" // 分类ID(可选) - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 7, - * "title": "全无码食品火锅", - * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", - * "num": 11, - * "price": "53.90", - * "sales": 568, - * "tags": [] - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 2, - * "total": 2 - * } - * } - */ -@PostMapping("/api/integral/product/lst") -public AjaxResult getIntegralProductList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 获取分页参数 - int page = params.get("page") != null ? (Integer) params.get("page") : 1; - int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - String type = params.get("type") != null ? params.get("type").toString() : null; - - // 2. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { - return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } - - // 3. 设置分页参数 - PageHelper.startPage(page, limit); - - // 4. 构建查询条件 - IntegralProduct integralProductQuery = new IntegralProduct(); - integralProductQuery.setStatus(1L); // 只查询启用状态的商品 - - // 如果有分类参数,添加分类筛选 - if (type != null && !type.trim().isEmpty()) { - try { - Long cateId = Long.parseLong(type.trim()); - integralProductQuery.setCateId(cateId); - } catch (NumberFormatException e) { - return AppletControllerUtil.appletWarning("分类参数格式错误"); - } - } - - // 5. 查询积分商品列表 - List integralProductList = integralProductService.selectIntegralProductList(integralProductQuery); - - // 6. 构建分页信息 - PageInfo pageInfo = new PageInfo<>(integralProductList); - - // 7. 使用工具类处理数据格式化 - List> formattedProductList = AppletControllerUtil.buildIntegralProductList(integralProductList); - Map responseData = AppletControllerUtil.buildPaginationResponse( - pageInfo, formattedProductList, "https://www.huafurenjia.cn/api/integral/product/lst"); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - System.err.println("查询积分商品列表异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询积分商品列表失败:" + e.getMessage()); - } -} - -/** - * 查询积分商品详情 - * - * @param id 商品ID - * @param request HTTP请求对象 - * @return 返回积分商品详细信息 - *

- * 功能说明: - * - 根据商品ID获取积分商品详细信息 - * - 返回完整的商品数据包括图片、规格、库存等 - * - 自动处理图片URL添加CDN前缀 - * - 格式化轮播图和标签为数组格式 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 7, - * "title": "全无码食品火锅", - * "cate_id": 4, - * "contetnt": "

", - * "created_at": "2024-07-17 14:59:44", - * "image": "https://img.huafurenjia.cn/images/cb03ed40d32282bb47235568219ca26.png", - * "images": ["https://img.huafurenjia.cn/images/..."], - * "num": 11, - * "price": "53.90", - * "sales": 568, - * "sku": {"type": "single"}, - * "sku_type": 1, - * "sort": 1, - * "status": 1, - * "stock": 120, - * "tags": [], - * "updated_at": "2024-08-16 15:03:33" - * } - * } - */ -@GetMapping("/api/integral/product/info/{id}") -public AjaxResult getIntegralProductInfo(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 1. 参数验证 - if (id == null || id <= 0) { - return AppletControllerUtil.appletWarning("商品ID无效"); - } - - // 2. 查询积分商品信息 - IntegralProduct integralProduct = integralProductService.selectIntegralProductById(id); - if (integralProduct == null) { - return AppletControllerUtil.appletWarning("商品不存在"); - } - - // 3. 验证商品状态(只返回启用状态的商品) - if (integralProduct.getStatus() == null || integralProduct.getStatus() != 1) { - return AppletControllerUtil.appletWarning("商品已下架或不可用"); - } - - // 4. 使用工具类构建商品详情数据 - Map productDetail = AppletControllerUtil.buildIntegralProductDetail(integralProduct); - - return AppletControllerUtil.appletSuccess(productDetail); - - } catch (Exception e) { - System.err.println("查询积分商品详情异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询商品详情失败:" + e.getMessage()); - } -} - -/** - * 获取用户默认收货地址 - * - * @param request HTTP请求对象 - * @return 默认地址信息 - *

- * 接口说明: - * - 查询用户的默认收货地址(is_default = 1) - * - 如果没有默认地址,返回用户地址列表的第一条数据 - * - 验证用户登录状态和地址归属权 - * - 返回AddressApple格式的地址数据 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "id": 160, - * "uid": 302, - * "name": "赵先生", - * "phone": "18709185987", - * "latitude": "34.15643", - * "longitude": "108.86683", - * "address_name": "陕西省西安市长安区榆林北段与建设大道交叉口处北侧", - * "address_info": "陕西省西安市长安区榆林北段与建设大道交叉口处", - * "info": "14号楼2302", - * "is_default": 1, - * "created_at": null, - * "updated_at": null - * } - * } - */ -@GetMapping("/api/user/address/default") -public AjaxResult getUserDefaultAddress(HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 首先查询用户的默认地址 - UserAddress userAddressQuery = new UserAddress(); - userAddressQuery.setUid(user.getId()); - userAddressQuery.setIsDefault(1L); // 查询默认地址 - List defaultAddressList = userAddressService.selectUserAddressList(userAddressQuery); - - UserAddress targetAddress = null; - - if (!defaultAddressList.isEmpty()) { - // 找到默认地址 - targetAddress = defaultAddressList.get(0); - } else { - // 没有默认地址,查询用户的第一条地址 - UserAddress allAddressQuery = new UserAddress(); - allAddressQuery.setUid(user.getId()); - List allAddressList = userAddressService.selectUserAddressList(allAddressQuery); - - if (!allAddressList.isEmpty()) { - targetAddress = allAddressList.get(0); - } else { - return AppletControllerUtil.appletWarning("用户暂无收货地址"); - } - } - - // 4. 转换为AddressApple格式并返回 - AddressApple addressApple = AddressApple.fromUserAddress(targetAddress); - - return AppletControllerUtil.appletSuccess(addressApple); - - } catch (Exception e) { - System.err.println("查询用户默认地址异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询默认地址失败:" + e.getMessage()); - } -} - -/** - * 获取用户小程序通知订阅状态 - * - * @param request HTTP请求对象 - * @return 用户通知订阅状态 - *

- * 接口说明: - * - 查询用户对小程序消息模板的订阅状态 - * - 返回三个消息模板的订阅配置信息 - * - 支持不同业务场景的消息通知配置 - * - 验证用户登录状态 - *

- * 消息模板说明: - * - pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M: 积分相关通知模板 - * - YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8: 操作成功通知模板 - * - 5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU: 工作人员通知模板 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "integral": ["pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"], - * "make_success": ["YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8", "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"], - * "is": "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU", - * "new_success": ["pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"], - * "s": "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M", - * "workers": ["5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"], - * "a": "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU" - * } - * } - */ -@GetMapping("/api/user/notification/status") -public AjaxResult getUserNotificationStatus(HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 直接返回固定的消息模板配置数据 - Map notificationStatus = AppletControllerUtil.buildMiniProgramNotificationStatus(user); - - return AppletControllerUtil.appletSuccess(notificationStatus); - - } catch (Exception e) { - System.err.println("查询用户通知订阅状态异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("查询通知订阅状态失败:" + e.getMessage()); - } -} - - - - - -/** - * 用户订阅消息授权接口 - * - * @param params 请求参数,包含tmplIds(模板ID数组) - * @param request HTTP请求对象 - * @return 授权结果 - *

- * 接口说明: - * - 处理用户对消息模板的订阅授权 - * - 记录用户的授权状态 - * - 支持批量处理多个模板ID - *

- * 请求参数格式: - * { - * "tmplIds": ["pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M", "YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8"] - * } - */ -@PostMapping("/api/user/notification/subscribe") -public AjaxResult subscribeNotification(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 获取模板ID列表 - List tmplIds = (List) params.get("tmplIds"); - if (tmplIds == null || tmplIds.isEmpty()) { - return AppletControllerUtil.appletWarning("模板ID列表不能为空"); - } - - // 4. 验证模板ID的有效性 - List validTemplateIds = new ArrayList<>(); - validTemplateIds.add("pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"); - validTemplateIds.add("YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8"); - validTemplateIds.add("5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"); - - for (String tmplId : tmplIds) { - if (!validTemplateIds.contains(tmplId)) { - return AppletControllerUtil.appletWarning("无效的模板ID:" + tmplId); - } - } - - // 5. 处理订阅逻辑(这里可以记录到数据库或调用微信API) - Map subscribeResult = new HashMap<>(); - subscribeResult.put("user_id", user.getId()); - subscribeResult.put("template_ids", tmplIds); - subscribeResult.put("subscribe_time", new Date()); - subscribeResult.put("status", "success"); - - // 6. 这里可以将订阅状态保存到数据库 - // 例如:userNotificationService.saveSubscribeStatus(user.getId(), tmplIds); - - return AppletControllerUtil.appletSuccess(subscribeResult); - - } catch (Exception e) { - System.err.println("用户订阅消息异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("订阅消息失败:" + e.getMessage()); - } -} - - -/** - * 小程序下单时用户订阅消息推送接口(前端不传值,后端返回固定结构) - * - * @return 订阅消息推送ID分类结果 - */ -@GetMapping("/api/public/massge/notice") -public Map subscribeMessageNotice() { - Map data = new HashMap<>(); - data.put("make_success", Arrays.asList( - "YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8", - "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU" - )); - data.put("pay_success", Arrays.asList( - "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M" - )); - data.put("integral", Arrays.asList( - "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M" - )); - data.put("worker", Arrays.asList( - "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU" - )); - Map result = new HashMap<>(); - result.put("code", 200); - result.put("msg", "OK"); - result.put("data", data); - return result; -} - - -/** - * 积分商品兑换接口 - * - * @param params 请求参数,包含id(积分商品ID)、address_id(收货地址ID)、num(购买数量)、sku(规格)、mark(备注) - * @param request HTTP请求对象 - * @return 兑换结果 - *

- * 接口说明: - * - 使用积分兑换积分商品 - * - 验证用户积分是否足够支付 - * - 创建积分订单并扣除用户积分 - * - 记录积分变动日志 - *

- * 请求参数格式: - * { - * "id": 7, // 积分商品ID - * "num": 1, // 购买数量 - * "sku": "", // 商品规格(可选) - * "address_id": 2151, // 收货地址ID - * "mark": "" // 备注(可选) - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": { - * "order_id": "JF20241217143055", - * "message": "积分商品兑换成功" - * } - * } - */ -@PostMapping("/api/integral/user/exchange") -public AjaxResult exchangeIntegralProduct(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证请求参数 - String validationResult = AppletControllerUtil.validateIntegralExchangeParams(params); - if (validationResult != null) { - return AppletControllerUtil.appletWarning(validationResult); - } - - // 4. 获取并验证积分商品信息 - Long productId = Long.valueOf(params.get("id").toString()); - IntegralProduct product = integralProductService.selectIntegralProductById(productId); - if (product == null) { - return AppletControllerUtil.appletWarning("积分商品不存在"); - } - - if (product.getStatus() == null || product.getStatus() != 1) { - return AppletControllerUtil.appletWarning("积分商品已下架或不可用"); - } - - // 5. 获取并验证收货地址信息 - Long addressId = Long.valueOf(params.get("address_id").toString()); - UserAddress address = userAddressService.selectUserAddressById(addressId); - if (address == null) { - return AppletControllerUtil.appletWarning("收货地址不存在"); - } - - if (!address.getUid().equals(user.getId())) { - return AppletControllerUtil.appletWarning("无权使用该收货地址"); - } - - // 6. 计算所需积分并验证库存 - Integer num = Integer.valueOf(params.get("num").toString()); - if (product.getStock() != null && product.getStock() < num) { - return AppletControllerUtil.appletWarning("商品库存不足"); - } - - Long totalIntegral = product.getNum() * num; - - // 7. 验证用户积分是否足够 - if (!AppletControllerUtil.checkUserIntegralSufficient(user, totalIntegral)) { - // 积分不足,返回422状态码 - return AppletControllerUtil.appletWarning("积分不足"); - } - - // 8. 创建积分订单 - IntegralOrder order = AppletControllerUtil.buildIntegralOrder(params, user, product, address); - int orderResult = integralOrderService.insertIntegralOrder(order); - - if (orderResult <= 0) { - return AppletControllerUtil.appletWarning("订单创建失败"); - } - - // 9. 扣除用户积分 - Users updateUser = new Users(); - updateUser.setId(user.getId()); - updateUser.setIntegral(user.getIntegral() - totalIntegral); - int updateResult = usersService.updateUsers(updateUser); - - if (updateResult <= 0) { - return AppletControllerUtil.appletWarning("扣除积分失败"); - } - - // 10. 记录积分变动日志 - IntegralLog integralLog = AppletControllerUtil.buildIntegralLog( - user, -totalIntegral, order.getOrderId(), product.getTitle()); - integralLogService.insertIntegralLog(integralLog); - - // 11. 更新商品库存(如果有库存管理) - if (product.getStock() != null) { - IntegralProduct updateProduct = new IntegralProduct(); - updateProduct.setId(product.getId()); - updateProduct.setStock(product.getStock() - num); - updateProduct.setSales(product.getSales() != null ? product.getSales() + num : num.longValue()); - integralProductService.updateIntegralProduct(updateProduct); - } - // 12. 构建返回结果 - return AppletControllerUtil.appletSuccess("兑换成功"); - } catch (Exception e) { - System.err.println("积分商品兑换异常:" + e.getMessage()); - return AppletControllerUtil.appletError("积分商品兑换失败:" + e.getMessage()); - } -} - -/** - * 获取服务订单详情 - * - * @param id 订单ID - * @param request HTTP请求对象 - * @return 服务订单详细信息 - *

- * 接口说明: - * - 根据订单ID获取服务订单完整信息 - * - 包含订单基本信息、订单日志和商品信息 - * - 验证用户登录状态和订单归属权 - * - 返回完整的订单详情数据 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * // 订单基本信息 - * "id": 260, - * "order_id": "B831770908583777", - * // ... 其他订单字段 - * "log": [ - * // 订单日志数组 - * ], - * "product": { - * // 商品信息 - * } - * } - * } - */ -@GetMapping("/api/service/order/info/{id}") -public AjaxResult getServiceOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 1. 参数验证 - if (id == null || id <= 0) { - return AppletControllerUtil.appletWarning("订单ID无效"); - } - - // 2. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - - // 3. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 4. 查询订单信息并验证归属权 - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - - // 5. 验证订单归属权 - if (!order.getUid().equals(user.getId())) { - return AppletControllerUtil.appletWarning("无权访问该订单信息"); - } - - // 6. 使用工具类构建订单详情数据 - Map orderDetail = AppletControllerUtil.buildServiceOrderDetail( - order, orderLogService, serviceGoodsService); - - return AppletControllerUtil.appletSuccess(orderDetail); - - } catch (Exception e) { - System.err.println("查询服务订单详情异常:" + e.getMessage()); - return AppletControllerUtil.appletError("查询订单详情失败:" + e.getMessage()); - } -} - -/** - * 获取城市列表接口 - * - * @param request HTTP请求对象 - * @return 城市列表数据 - *

- * 接口说明: - * - 获取所有启用状态的城市列表 - * - 返回城市的ID、名称和父级ID - * - 用于小程序城市选择功能 - * - 无需用户登录验证 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 1, - * "title": "西安市", - * "pid": 0 - * } - * ] - * } - */ -@GetMapping(value = "/api/public/diy/city") -public AjaxResult getDiyCityList(HttpServletRequest request) { - try { - // 查询所有城市列表 - List cityList = diyCityService.selectDiyCityList(null); - - // 构建树状结构数据 - List> resultList = AppletControllerUtil.buildCityTree(cityList); - - return AppletControllerUtil.appletSuccess(resultList); - } catch (Exception e) { - System.err.println("获取城市列表异常:" + e.getMessage()); - return AppletControllerUtil.appletError("获取城市列表失败:" + e.getMessage()); - } -} - -/** - * 获取技能列表接口 - * - * @param request HTTP请求对象 - * @return 技能列表数据 - *

- * 接口说明: - * - 获取所有技能列表数据 - * - 返回技能的ID、名称、排序、状态等信息 - * - 用于小程序技能选择功能 - * - 无需用户登录验证 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "id": 47, - * "title": "燃气灶维修", - * "sort": 43, - * "status": 1, - * "created_at": "2025-04-10 09:36:35", - * "updated_at": "2025-04-10 09:36:35" - * } - * ] - * } - */ -@GetMapping(value = "/api/form/skill/lst") -public AjaxResult getSkillList(HttpServletRequest request) { - try { - // 查询技能列表 - List skillList = siteSkillService.selectSiteSkillList(null); - - // 构建返回数据格式 - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - for (SiteSkill skill : skillList) { - Map skillData = new HashMap<>(); - skillData.put("id", skill.getId()); - skillData.put("title", skill.getTitle()); - skillData.put("sort", skill.getSort()); - skillData.put("status", skill.getStatus()); - - // 格式化时间字段 - if (skill.getCreatedAt() != null) { - skillData.put("created_at", sdf.format(skill.getCreatedAt())); - } else { - skillData.put("created_at", null); + // 1. 获取分页参数 + int page = params.get("page") != null ? (Integer) params.get("page") : 1; + int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; + String status = params.get("status") != null ? params.get("status").toString() : null; + + // 2. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); } - if (skill.getUpdatedAt() != null) { - skillData.put("updated_at", sdf.format(skill.getUpdatedAt())); - } else { - skillData.put("updated_at", null); + // 3. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } - resultList.add(skillData); - } + // 4. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } - return AppletControllerUtil.appletSuccess(resultList); - } catch (Exception e) { - System.err.println("获取技能列表异常:" + e.getMessage()); - return AppletControllerUtil.appletError("获取技能列表失败:" + e.getMessage()); + // 5. 设置分页参数 + PageHelper.startPage(page, limit); + + // 6. 构建查询条件并查询 + IntegralOrder integralOrderQuery = new IntegralOrder(); + integralOrderQuery.setUid(user.getId()); + if (status != null && !status.trim().isEmpty()) { + integralOrderQuery.setStatus(status.trim()); + } + List integralOrderList = integralOrderService.selectIntegralOrderList(integralOrderQuery); + + // 7. 构建分页信息 + PageInfo pageInfo = new PageInfo<>(integralOrderList); + + // 8. 使用工具类处理数据格式化 + List> formattedOrderList = AppletControllerUtil.buildIntegralOrderList( + integralOrderList, integralProductService); + Map responseData = AppletControllerUtil.buildPaginationResponse( + pageInfo, formattedOrderList, "https://www.huafurenjia.cn/api/integral/user/order"); + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + System.err.println("查询用户积分商城订单列表异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分商城订单列表失败:" + e.getMessage()); + } } -} -/** - * 文件上传接口 - * - * @param file 上传的文件 - * @param request HTTP请求对象 - * @return 上传结果 - *

- * 接口说明: - * - 支持图片和视频文件上传 - * - 优先使用七牛云上传,未启用时使用本地上传 - * - 自动验证文件格式和大小 - * - 无需用户登录验证(public 接口) - *

- * 支持的文件格式: - * - 图片:jpg, jpeg, png, gif, bmp, webp, svg - * - 视频:mp4, avi, mov, wmv, flv, m4v, 3gp, rmvb, mkv - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "path": "images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg", - * "full_path": "http://img.huafurenjia.cn/images/2025-06-11/zvsZHNoFYlFkMCePQs1624hKwBSCozL9XM7pEUmo.jpg" - * } - * } - */ -@PostMapping(value = "/api/public/upload/file") -public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request) { - try { - // 1. 验证文件是否为空 - if (file == null || file.isEmpty()) { - return AppletControllerUtil.appletWarning("上传文件不能为空"); - } - - // 2. 只允许图片和视频格式 - String[] allowedTypes = { - // 图片格式 - "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", - // 视频格式 - "mp4", "avi", "mov", "wmv", "flv", "m4v", "3gp", "rmvb", "mkv" - }; - - if (!QiniuUploadUtil.isValidFileType(file.getOriginalFilename(), allowedTypes)) { - return AppletControllerUtil.appletWarning("只允许上传图片或视频文件"); - } - - // 3. 验证文件大小(10MB) - long maxSize = 10 * 1024 * 1024; - if (!QiniuUploadUtil.isFileSizeValid(file.getSize(), maxSize)) { - return AppletControllerUtil.appletWarning("文件大小不能超过10MB"); - } - - String fileUrl; - String filePath; - - // 4. 检查是否启用七牛云上传 - if (qiniuConfig.isEnabled()) { - // 使用七牛云上传 - fileUrl = QiniuUploadUtil.uploadFile(file); - // 从完整URL中提取路径部分 - filePath = AppletControllerUtil.extractPathFromUrl(fileUrl, "https://" + qiniuConfig.getDomain() + "/"); - } else { - // 使用本地上传(这里需要集成本地上传逻辑) - return AppletControllerUtil.appletError("本地上传功能暂未在此接口中实现,请启用七牛云上传"); - } - - // 5. 构建返回数据 - Map uploadResult = new HashMap<>(); - uploadResult.put("path", filePath); - uploadResult.put("full_path", fileUrl); - - return AppletControllerUtil.appletSuccess(uploadResult); - - } catch (Exception e) { - System.err.println("文件上传异常:" + e.getMessage()); - return AppletControllerUtil.appletError("文件上传失败:" + e.getMessage()); - } -} - - -/** - * 获取服务预约时间段接口 - * - * @param params 请求参数,包含day(预约日期) - * @param request HTTP请求对象 - * @return 时间段列表数据 - *

- * 接口说明: - * - 根据指定日期获取可预约的时间段列表 - * - 返回每个时间段的可用状态和剩余数量 - * - 支持动态时间段配置 - * - 无需用户登录验证 - *

- * 请求参数格式: - * { - * "day": "2025-06-11" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": [ - * { - * "click": true, - * "value": "8:00-10:00", - * "prove": "可预约", - * "residue_num": 99 - * } - * ] - * } - */ -@PostMapping(value = "/api/service/make/time") -public AjaxResult getServiceMakeTime(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 参数验证 - if (params == null || params.get("day") == null) { - return AppletControllerUtil.appletWarning("日期参数不能为空"); - } - - String day = params.get("day").toString().trim(); - if (day.isEmpty()) { - return AppletControllerUtil.appletWarning("日期参数不能为空"); - } - - // 2. 验证日期格式 - if (!AppletControllerUtil.isValidDateFormat(day)) { - return AppletControllerUtil.appletWarning("日期格式错误,请使用yyyy-MM-dd格式"); - } - - // 3. 检查日期是否为过去时间 - if (AppletControllerUtil.isPastDate(day)) { - return AppletControllerUtil.appletWarning("不能预约过去的日期"); - } - - // 4. 构建时间段列表 - List> timeSlotList = AppletControllerUtil.buildTimeSlotList(day); - - return AppletControllerUtil.appletSuccess(timeSlotList); - - } catch (Exception e) { - System.err.println("获取服务预约时间段异常:" + e.getMessage()); - return AppletControllerUtil.appletError("获取时间段失败:" + e.getMessage()); - } -} - - -/** - * 添加商品到购物车接口 - * - * @param params 请求参数,包含good_id(商品ID)、sku(商品规格) - * @param request HTTP请求对象 - * @return 添加结果 - *

- * 接口说明: - * - 将指定商品添加到用户购物车 - * - 验证商品是否存在和可用 - * - 支持商品规格选择 - * - 需要用户登录验证 - *

- * 请求参数格式: - * { - * "good_id": 86, - * "sku": "" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "操作成功", - * "data": "商品已添加到购物车" - * } - */ -@PostMapping(value = "/api/cart/add") -public AjaxResult addToCart(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证请求参数 - if (params == null || params.get("good_id") == null) { - return AppletControllerUtil.appletWarning("商品ID不能为空"); - } - - Long goodId; + /** + * 查询积分订单详情 + * + * @param id 订单ID + * @param request HTTP请求对象 + * @return 返回积分订单详细信息 + */ + @GetMapping("/api/integral/user/order/info/{id}") + public AjaxResult getIntegralOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { try { - goodId = Long.valueOf(params.get("good_id").toString()); - if (goodId <= 0) { + // 1. 参数验证 + if (id == null || id <= 0) { + return AppletControllerUtil.appletWarning("订单ID无效"); + } + // 2. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + // 3. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 4. 查询积分订单信息 + IntegralOrder integralOrder = integralOrderService.selectIntegralOrderById(id); + if (integralOrder == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + // 5. 验证订单归属权 + if (!integralOrder.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权访问该订单信息"); + } + // 6. 使用工具类构建订单详情数据 + Map orderData = AppletControllerUtil.buildIntegralOrderDetail( + integralOrder, integralProductService, integralOrderLogService); + return AppletControllerUtil.appletSuccess(orderData); + + } catch (Exception e) { + System.err.println("查询积分订单详情异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询订单详情失败:" + e.getMessage()); + } + } + + /** + * 查询积分商品分类列表 + * + * @param request HTTP请求对象 + * @return 返回积分商品分类列表 + *

+ * 功能说明: + * - 获取所有启用状态的积分商品分类 + * - 返回分类的ID和名称 + * - 用于积分商城分类展示 + */ + @GetMapping("/api/integral/product/cate") + public AjaxResult getIntegralProductCateList(HttpServletRequest request) { + try { + // 1. 构建查询条件:查询启用状态的积分商品分类 + IntegralCate integralCateQuery = new IntegralCate(); + integralCateQuery.setStatus(1L); // 启用状态 + + // 2. 查询积分商品分类列表 + List integralCateList = integralCateService.selectIntegralCateList(integralCateQuery); + + // 3. 构建返回数据格式 + List> resultList = new ArrayList<>(); + for (IntegralCate integralCate : integralCateList) { + Map cateData = new HashMap<>(); + cateData.put("id", integralCate.getId()); + cateData.put("title", integralCate.getTitle()); + resultList.add(cateData); + } + + return AppletControllerUtil.appletSuccess(resultList); + + } catch (Exception e) { + System.err.println("查询积分商品分类列表异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询分类列表失败:" + e.getMessage()); + } + } + + /** + * 查询积分商品列表 + * + * @param params 请求参数,包含limit(每页数量)、page(页码)、type(分类ID) + * @param request HTTP请求对象 + * @return 返回分页的积分商品列表 + *

+ * 功能说明: + * - 获取积分商品列表,支持分页 + * - 支持按分类筛选 + * - 返回商品详细信息和分页信息 + * - 按创建时间倒序排列 + */ + @PostMapping("/api/integral/product/lst") + public AjaxResult getIntegralProductList(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 获取分页参数 + int page = params.get("page") != null ? (Integer) params.get("page") : 1; + int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; + String type = params.get("type") != null ? params.get("type").toString() : null; + + // 2. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); + } + + // 3. 设置分页参数 + PageHelper.startPage(page, limit); + + // 4. 构建查询条件 + IntegralProduct integralProductQuery = new IntegralProduct(); + integralProductQuery.setStatus(1L); // 只查询启用状态的商品 + + // 如果有分类参数,添加分类筛选 + if (type != null && !type.trim().isEmpty()) { + try { + Long cateId = Long.parseLong(type.trim()); + integralProductQuery.setCateId(cateId); + } catch (NumberFormatException e) { + return AppletControllerUtil.appletWarning("分类参数格式错误"); + } + } + + // 5. 查询积分商品列表 + List integralProductList = integralProductService.selectIntegralProductList(integralProductQuery); + + // 6. 构建分页信息 + PageInfo pageInfo = new PageInfo<>(integralProductList); + + // 7. 使用工具类处理数据格式化 + List> formattedProductList = AppletControllerUtil.buildIntegralProductList(integralProductList); + Map responseData = AppletControllerUtil.buildPaginationResponse( + pageInfo, formattedProductList, "https://www.huafurenjia.cn/api/integral/product/lst"); + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + System.err.println("查询积分商品列表异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询积分商品列表失败:" + e.getMessage()); + } + } + + /** + * 查询积分商品详情 + * + * @param id 商品ID + * @param request HTTP请求对象 + * @return 返回积分商品详细信息 + *

+ * 功能说明: + * - 根据商品ID获取积分商品详细信息 + * - 返回完整的商品数据包括图片、规格、库存等 + * - 自动处理图片URL添加CDN前缀 + * - 格式化轮播图和标签为数组格式 + *

+ */ + @GetMapping("/api/integral/product/info/{id}") + public AjaxResult getIntegralProductInfo(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 1. 参数验证 + if (id == null || id <= 0) { return AppletControllerUtil.appletWarning("商品ID无效"); } - } catch (NumberFormatException e) { - return AppletControllerUtil.appletWarning("商品ID格式错误"); - } + // 2. 查询积分商品信息 + IntegralProduct integralProduct = integralProductService.selectIntegralProductById(id); + if (integralProduct == null) { + return AppletControllerUtil.appletWarning("商品不存在"); + } - // 4. 获取商品规格参数 - // String sku = params.get("sku") != null ? params.get("sku").toString().trim() : ""; - String sku = null; - if (params.get("sku") != null) { - Object skuParam = params.get("sku"); - if (skuParam instanceof Map) { - // 如果前端传递的是Map对象,转换为JSON字符串 - try { - sku = com.alibaba.fastjson2.JSON.toJSONString(skuParam); - } catch (Exception e) { - System.err.println("SKU转换JSON失败:" + e.getMessage()); - sku = skuParam.toString(); + // 3. 验证商品状态(只返回启用状态的商品) + if (integralProduct.getStatus() == null || integralProduct.getStatus() != 1) { + return AppletControllerUtil.appletWarning("商品已下架或不可用"); + } + + // 4. 使用工具类构建商品详情数据 + Map productDetail = AppletControllerUtil.buildIntegralProductDetail(integralProduct); + + return AppletControllerUtil.appletSuccess(productDetail); + + } catch (Exception e) { + System.err.println("查询积分商品详情异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询商品详情失败:" + e.getMessage()); + } + } + /** + * 获取用户默认收货地址 + * + * @param request HTTP请求对象 + * @return 默认地址信息 + *

+ * 接口说明: + * - 查询用户的默认收货地址(is_default = 1) + * - 如果没有默认地址,返回用户地址列表的第一条数据 + * - 验证用户登录状态和地址归属权 + * - 返回AddressApple格式的地址数据 + *

+ */ + @GetMapping("/api/user/address/default") + public AjaxResult getUserDefaultAddress(HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 3. 首先查询用户的默认地址 + UserAddress userAddressQuery = new UserAddress(); + userAddressQuery.setUid(user.getId()); + userAddressQuery.setIsDefault(1L); // 查询默认地址 + List defaultAddressList = userAddressService.selectUserAddressList(userAddressQuery); + + UserAddress targetAddress = null; + + if (!defaultAddressList.isEmpty()) { + // 找到默认地址 + targetAddress = defaultAddressList.get(0); + } else { + // 没有默认地址,查询用户的第一条地址 + UserAddress allAddressQuery = new UserAddress(); + allAddressQuery.setUid(user.getId()); + List allAddressList = userAddressService.selectUserAddressList(allAddressQuery); + + if (!allAddressList.isEmpty()) { + targetAddress = allAddressList.get(0); + } else { + return AppletControllerUtil.appletWarning("用户暂无收货地址"); + } + } + + // 4. 转换为AddressApple格式并返回 + AddressApple addressApple = AddressApple.fromUserAddress(targetAddress); + + return AppletControllerUtil.appletSuccess(addressApple); + + } catch (Exception e) { + System.err.println("查询用户默认地址异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询默认地址失败:" + e.getMessage()); + } + } + + /** + * 获取用户小程序通知订阅状态 + * + * @param request HTTP请求对象 + * @return 用户通知订阅状态 + *

+ * 接口说明: + * - 查询用户对小程序消息模板的订阅状态 + * - 返回三个消息模板的订阅配置信息 + * - 支持不同业务场景的消息通知配置 + * - 验证用户登录状态 + */ + @GetMapping("/api/user/notification/status") + public AjaxResult getUserNotificationStatus(HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 直接返回固定的消息模板配置数据 + Map notificationStatus = AppletControllerUtil.buildMiniProgramNotificationStatus(user); + + return AppletControllerUtil.appletSuccess(notificationStatus); + + } catch (Exception e) { + System.err.println("查询用户通知订阅状态异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("查询通知订阅状态失败:" + e.getMessage()); + } + } + + + + + + /** + * 用户订阅消息授权接口 + * + * @param params 请求参数,包含tmplIds(模板ID数组) + * @param request HTTP请求对象 + * @return 授权结果 + */ + @PostMapping("/api/user/notification/subscribe") + public AjaxResult subscribeNotification(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 获取模板ID列表 + List tmplIds = (List) params.get("tmplIds"); + if (tmplIds == null || tmplIds.isEmpty()) { + return AppletControllerUtil.appletWarning("模板ID列表不能为空"); + } + + // 4. 验证模板ID的有效性 + List validTemplateIds = new ArrayList<>(); + validTemplateIds.add("pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M"); + validTemplateIds.add("YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8"); + validTemplateIds.add("5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU"); + + for (String tmplId : tmplIds) { + if (!validTemplateIds.contains(tmplId)) { + return AppletControllerUtil.appletWarning("无效的模板ID:" + tmplId); + } + } + + // 5. 处理订阅逻辑(这里可以记录到数据库或调用微信API) + Map subscribeResult = new HashMap<>(); + subscribeResult.put("user_id", user.getId()); + subscribeResult.put("template_ids", tmplIds); + subscribeResult.put("subscribe_time", new Date()); + subscribeResult.put("status", "success"); + + // 6. 这里可以将订阅状态保存到数据库 + // 例如:userNotificationService.saveSubscribeStatus(user.getId(), tmplIds); + + return AppletControllerUtil.appletSuccess(subscribeResult); + + } catch (Exception e) { + System.err.println("用户订阅消息异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("订阅消息失败:" + e.getMessage()); + } + } + + + /** + * 小程序下单时用户订阅消息推送接口(前端不传值,后端返回固定结构) + * + * @return 订阅消息推送ID分类结果 + */ + @GetMapping("/api/public/massge/notice") + public Map subscribeMessageNotice() { + Map data = new HashMap<>(); + data.put("make_success", Arrays.asList( + "YKnuTCAD-oEEhNGoI3LUVkAqNsykOMTcyrf71S9vev8", + "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU" + )); + data.put("pay_success", Arrays.asList( + "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M" + )); + data.put("integral", Arrays.asList( + "pv3cba-wPoinUbBZSskp0KpDNnJwrHqS0rvGBfDNQ1M" + )); + data.put("worker", Arrays.asList( + "5lA-snytEPl25fBS7rf6rQi8Y0i5HOSdG0JMVdUnMcU" + )); + Map result = new HashMap<>(); + result.put("code", 200); + result.put("msg", "OK"); + result.put("data", data); + return result; + } + /** + * 积分商品兑换接口 + * + * @param params 请求参数,包含id(积分商品ID)、address_id(收货地址ID)、num(购买数量)、sku(规格)、mark(备注) + * @param request HTTP请求对象 + * @return 兑换结果 + */ + @PostMapping("/api/integral/user/exchange") + public AjaxResult exchangeIntegralProduct(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 验证请求参数 + String validationResult = AppletControllerUtil.validateIntegralExchangeParams(params); + if (validationResult != null) { + return AppletControllerUtil.appletWarning(validationResult); + } + + // 4. 获取并验证积分商品信息 + Long productId = Long.valueOf(params.get("id").toString()); + IntegralProduct product = integralProductService.selectIntegralProductById(productId); + if (product == null) { + return AppletControllerUtil.appletWarning("积分商品不存在"); + } + + if (product.getStatus() == null || product.getStatus() != 1) { + return AppletControllerUtil.appletWarning("积分商品已下架或不可用"); + } + + // 5. 获取并验证收货地址信息 + Long addressId = Long.valueOf(params.get("address_id").toString()); + UserAddress address = userAddressService.selectUserAddressById(addressId); + if (address == null) { + return AppletControllerUtil.appletWarning("收货地址不存在"); + } + + if (!address.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权使用该收货地址"); + } + + // 6. 计算所需积分并验证库存 + Integer num = Integer.valueOf(params.get("num").toString()); + if (product.getStock() != null && product.getStock() < num) { + return AppletControllerUtil.appletWarning("商品库存不足"); + } + + Long totalIntegral = product.getNum() * num; + + // 7. 验证用户积分是否足够 + if (!AppletControllerUtil.checkUserIntegralSufficient(user, totalIntegral)) { + // 积分不足,返回422状态码 + return AppletControllerUtil.appletWarning("积分不足"); + } + + // 8. 创建积分订单 + IntegralOrder order = AppletControllerUtil.buildIntegralOrder(params, user, product, address); + int orderResult = integralOrderService.insertIntegralOrder(order); + + if (orderResult <= 0) { + return AppletControllerUtil.appletWarning("订单创建失败"); + } + + // 9. 扣除用户积分 + Users updateUser = new Users(); + updateUser.setId(user.getId()); + updateUser.setIntegral(user.getIntegral() - totalIntegral); + int updateResult = usersService.updateUsers(updateUser); + + if (updateResult <= 0) { + return AppletControllerUtil.appletWarning("扣除积分失败"); + } + + // 10. 记录积分变动日志 + IntegralLog integralLog = AppletControllerUtil.buildIntegralLog( + user, -totalIntegral, order.getOrderId(), product.getTitle()); + integralLogService.insertIntegralLog(integralLog); + + // 11. 更新商品库存(如果有库存管理) + if (product.getStock() != null) { + IntegralProduct updateProduct = new IntegralProduct(); + updateProduct.setId(product.getId()); + updateProduct.setStock(product.getStock() - num); + updateProduct.setSales(product.getSales() != null ? product.getSales() + num : num.longValue()); + integralProductService.updateIntegralProduct(updateProduct); + } + // 12. 构建返回结果 + return AppletControllerUtil.appletSuccess("兑换成功"); + } catch (Exception e) { + System.err.println("积分商品兑换异常:" + e.getMessage()); + return AppletControllerUtil.appletError("积分商品兑换失败:" + e.getMessage()); + } + } + + /** + * 获取服务订单详情 + * + * @param id 订单ID + * @param request HTTP请求对象 + * @return 服务订单详细信息 + *

+ * 接口说明: + * - 根据订单ID获取服务订单完整信息 + * - 包含订单基本信息、订单日志和商品信息 + * - 验证用户登录状态和订单归属权 + * - 返回完整的订单详情数据 + *

+ */ + @GetMapping("/api/service/order/info/{id}") + public AjaxResult getServiceOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 1. 参数验证 + if (id == null || id <= 0) { + return AppletControllerUtil.appletWarning("订单ID无效"); + } + + // 2. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + + // 3. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 4. 查询订单信息并验证归属权 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + // 5. 验证订单归属权 + if (!order.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权访问该订单信息"); + } + + // 6. 使用工具类构建订单详情数据 + Map orderDetail = AppletControllerUtil.buildServiceOrderDetail( + order, orderLogService, serviceGoodsService); + + return AppletControllerUtil.appletSuccess(orderDetail); + + } catch (Exception e) { + System.err.println("查询服务订单详情异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询订单详情失败:" + e.getMessage()); + } + } + + /** + * 获取城市列表接口 + * + * @param request HTTP请求对象 + * @return 城市列表数据 + *

+ * 接口说明: + * - 获取所有启用状态的城市列表 + * - 返回城市的ID、名称和父级ID + * - 用于小程序城市选择功能 + * - 无需用户登录验证 + *

+ */ + @GetMapping(value = "/api/public/diy/city") + public AjaxResult getDiyCityList(HttpServletRequest request) { + try { + // 查询所有城市列表 + List cityList = diyCityService.selectDiyCityList(null); + + // 构建树状结构数据 + List> resultList = AppletControllerUtil.buildCityTree(cityList); + + return AppletControllerUtil.appletSuccess(resultList); + } catch (Exception e) { + System.err.println("获取城市列表异常:" + e.getMessage()); + return AppletControllerUtil.appletError("获取城市列表失败:" + e.getMessage()); + } + } + + /** + * 获取技能列表接口 + * + * @param request HTTP请求对象 + * @return 技能列表数据 + *

+ * 接口说明: + * - 获取所有技能列表数据 + * - 返回技能的ID、名称、排序、状态等信息 + * - 用于小程序技能选择功能 + * - 无需用户登录验证 + *

+ */ + @GetMapping(value = "/api/form/skill/lst") + public AjaxResult getSkillList(HttpServletRequest request) { + try { + // 查询技能列表 + List skillList = siteSkillService.selectSiteSkillList(null); + + // 构建返回数据格式 + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (SiteSkill skill : skillList) { + Map skillData = new HashMap<>(); + skillData.put("id", skill.getId()); + skillData.put("title", skill.getTitle()); + skillData.put("sort", skill.getSort()); + skillData.put("status", skill.getStatus()); + + // 格式化时间字段 + if (skill.getCreatedAt() != null) { + skillData.put("created_at", sdf.format(skill.getCreatedAt())); + } else { + skillData.put("created_at", null); + } + + if (skill.getUpdatedAt() != null) { + skillData.put("updated_at", sdf.format(skill.getUpdatedAt())); + } else { + skillData.put("updated_at", null); + } + + resultList.add(skillData); + } + + return AppletControllerUtil.appletSuccess(resultList); + } catch (Exception e) { + System.err.println("获取技能列表异常:" + e.getMessage()); + return AppletControllerUtil.appletError("获取技能列表失败:" + e.getMessage()); + } + } + /** + * 文件上传接口 + * + * @param file 上传的文件 + * @param request HTTP请求对象 + * @return 上传结果 + *

+ * 接口说明: + * - 支持图片和视频文件上传 + * - 优先使用七牛云上传,未启用时使用本地上传 + * - 自动验证文件格式和大小 + * - 无需用户登录验证(public 接口) + */ + @PostMapping(value = "/api/public/upload/file") + public AjaxResult uploadFile(@RequestParam("file") MultipartFile file, HttpServletRequest request) { + try { + // 1. 验证文件是否为空 + if (file == null || file.isEmpty()) { + return AppletControllerUtil.appletWarning("上传文件不能为空"); + } + + // 2. 只允许图片和视频格式 + String[] allowedTypes = { + // 图片格式 + "jpg", "jpeg", "png", "gif", "bmp", "webp", "svg", + // 视频格式 + "mp4", "avi", "mov", "wmv", "flv", "m4v", "3gp", "rmvb", "mkv" + }; + + if (!QiniuUploadUtil.isValidFileType(file.getOriginalFilename(), allowedTypes)) { + return AppletControllerUtil.appletWarning("只允许上传图片或视频文件"); + } + + // 3. 验证文件大小(10MB) + long maxSize = 10 * 1024 * 1024; + if (!QiniuUploadUtil.isFileSizeValid(file.getSize(), maxSize)) { + return AppletControllerUtil.appletWarning("文件大小不能超过10MB"); + } + + String fileUrl; + String filePath; + // 4. 检查是否启用七牛云上传 + if (qiniuConfig.isEnabled()) { + // 使用七牛云上传 + fileUrl = QiniuUploadUtil.uploadFile(file); + // 从完整URL中提取路径部分 + filePath = AppletControllerUtil.extractPathFromUrl(fileUrl, "https://" + qiniuConfig.getDomain() + "/"); + } else { + // 使用本地上传(这里需要集成本地上传逻辑) + return AppletControllerUtil.appletError("本地上传功能暂未在此接口中实现,请启用七牛云上传"); + } + + // 5. 构建返回数据 + Map uploadResult = new HashMap<>(); + uploadResult.put("path", filePath); + uploadResult.put("full_path", fileUrl); + + return AppletControllerUtil.appletSuccess(uploadResult); + + } catch (Exception e) { + System.err.println("文件上传异常:" + e.getMessage()); + return AppletControllerUtil.appletError("文件上传失败:" + e.getMessage()); + } + } + /** + * 获取服务预约时间段接口 + * + * @param params 请求参数,包含day(预约日期) + * @param request HTTP请求对象 + * @return 时间段列表数据 + *

+ * 接口说明: + * - 根据指定日期获取可预约的时间段列表 + * - 返回每个时间段的可用状态和剩余数量 + * - 支持动态时间段配置 + * - 无需用户登录验证 + *

+ */ + @PostMapping(value = "/api/service/make/time") + public AjaxResult getServiceMakeTime(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 参数验证 + if (params == null || params.get("day") == null) { + return AppletControllerUtil.appletWarning("日期参数不能为空"); + } + String day = params.get("day").toString().trim(); + if (day.isEmpty()) { + return AppletControllerUtil.appletWarning("日期参数不能为空"); + } + // 2. 验证日期格式 + if (!AppletControllerUtil.isValidDateFormat(day)) { + return AppletControllerUtil.appletWarning("日期格式错误,请使用yyyy-MM-dd格式"); + } + // 3. 检查日期是否为过去时间 + if (AppletControllerUtil.isPastDate(day)) { + return AppletControllerUtil.appletWarning("不能预约过去的日期"); + } + // 4. 构建时间段列表 + List> timeSlotList = AppletControllerUtil.buildTimeSlotList(day); + + return AppletControllerUtil.appletSuccess(timeSlotList); + + } catch (Exception e) { + System.err.println("获取服务预约时间段异常:" + e.getMessage()); + return AppletControllerUtil.appletError("获取时间段失败:" + e.getMessage()); + } + } + + /** + * 添加商品到购物车接口 + * + * @param params 请求参数,包含good_id(商品ID)、sku(商品规格) + * @param request HTTP请求对象 + * @return 添加结果 + *

+ * 接口说明: + * - 将指定商品添加到用户购物车 + * - 验证商品是否存在和可用 + * - 支持商品规格选择 + * - 需要用户登录验证 + *

+ */ + @PostMapping(value = "/api/cart/add") + public AjaxResult addToCart(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 3. 验证请求参数 + if (params == null || params.get("good_id") == null) { + return AppletControllerUtil.appletWarning("商品ID不能为空"); + } + Long goodId; + try { + goodId = Long.valueOf(params.get("good_id").toString()); + if (goodId <= 0) { + return AppletControllerUtil.appletWarning("商品ID无效"); + } + } catch (NumberFormatException e) { + return AppletControllerUtil.appletWarning("商品ID格式错误"); + } + // 4. 获取商品规格参数 + // String sku = params.get("sku") != null ? params.get("sku").toString().trim() : ""; + String sku = null; + if (params.get("sku") != null) { + Object skuParam = params.get("sku"); + if (skuParam instanceof Map) { + // 如果前端传递的是Map对象,转换为JSON字符串 + try { + sku = JSON.toJSONString(skuParam); + } catch (Exception e) { + System.err.println("SKU转换JSON失败:" + e.getMessage()); + sku = skuParam.toString(); + } + } else { + // 如果前端传递的是字符串,直接使用 + sku = skuParam.toString().trim(); } } else { - // 如果前端传递的是字符串,直接使用 - sku = skuParam.toString().trim(); + sku = null; + } + // 5. 查询商品信息并验证 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("商品不存在"); } - } else { - sku = null; - } - // 5. 查询商品信息并验证 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodId); - if (serviceGoods == null) { - return AppletControllerUtil.appletWarning("商品不存在"); - } - // 6. 验证商品状态 + // 6. 验证商品状态 // if (serviceGoods.getStatus() == null || !serviceGoods.getStatus().equals(1L)) { // return AppletControllerUtil.appletWarning("商品已下架或不可用"); // } - // 7. 检查商品库存(如果有库存管理) + // 7. 检查商品库存(如果有库存管理) // if (serviceGoods.getStock() != null && serviceGoods.getStock() <= 0L) { // return AppletControllerUtil.appletWarning("商品库存不足"); // } + // 8. 检查购物车中是否已存在该商品 + GoodsCart existingCartItem = AppletControllerUtil.findExistingCartItem(user.getId(), goodId, sku, goodsCartService); - // 8. 检查购物车中是否已存在该商品 - GoodsCart existingCartItem = AppletControllerUtil.findExistingCartItem(user.getId(), goodId, sku, goodsCartService); - - if (existingCartItem != null) { - // 如果已存在,更新数量 - return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService); - } else { - // 如果不存在,新增购物车记录 - return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService); - } - - } catch (Exception e) { - System.err.println("添加购物车异常:" + e.getMessage()); - return AppletControllerUtil.appletError("添加购物车失败:" + e.getMessage()); - } -} - - -/** - * 查询购物车列表接口 - * - * @param params 请求参数,包含limit(每页数量)、page(页码) - * @param request HTTP请求对象 - * @return 购物车列表数据 - *

- * 接口说明: - * - 获取当前登录用户的购物车商品列表 - * - 支持分页查询 - * - 返回完整的商品信息 - * - 需要用户登录验证 - *

- * 请求参数格式: - * { - * "limit": 15, - * "page": 1 - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 248, - * "uid": 302, - * "good_id": 86, - * "good_num": 1, - * "sku": null, - * "created_at": "2025-06-11 10:05:37", - * "updated_at": "2025-06-11 10:05:37", - * "good": { - * "id": 86, - * "title": "马桶漏水", - * "price": "0.00", - * "icon": "https://img.huafurenjia.cn/images/...", - * "stock": 232, - * "type": 1 - * } - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 1, - * "total": 1 - * } - * } - */ -@PostMapping(value = "/api/cart/lst") -public AjaxResult getCartList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 获取分页参数 - int page = params.get("page") != null ? (Integer) params.get("page") : 1; - int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - - // 4. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { - return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } - - // 5. 设置分页参数 - PageHelper.startPage(page, limit); - - // 6. 构建查询条件 - GoodsCart queryCart = new GoodsCart(); - queryCart.setUid(user.getId()); - - // 7. 查询购物车列表 - List cartList = goodsCartService.selectGoodsCartList(queryCart); - - // 8. 为每个购物车项目填充商品信息 - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - for (GoodsCart cart : cartList) { - Map cartData = new HashMap<>(); - - // 基本购物车信息 - cartData.put("id", cart.getId()); - cartData.put("uid", cart.getUid()); - cartData.put("good_id", cart.getGoodId()); - cartData.put("good_num", cart.getGoodNum()); - if (cart.getSku() != null || cart.getSku() != "") { - cartData.put("sku", JSONObject.parseObject(cart.getSku())); + if (existingCartItem != null) { + // 如果已存在,更新数量 + return AppletControllerUtil.updateCartItemQuantity(existingCartItem, serviceGoods, goodsCartService); } else { - cartData.put("sku", null); + // 如果不存在,新增购物车记录 + return AppletControllerUtil.addNewCartItem(user, serviceGoods, sku, goodsCartService); } - - // 格式化时间字段 - cartData.put("created_at", cart.getCreatedAt() != null ? - sdf.format(cart.getCreatedAt()) : null); - cartData.put("updated_at", cart.getUpdatedAt() != null ? - sdf.format(cart.getUpdatedAt()) : null); - - // 查询并添加商品详细信息 - Map goodInfo = AppletControllerUtil.getGoodDetailForCart(cart.getGoodId(), serviceGoodsService); - cartData.put("good", goodInfo); - - resultList.add(cartData); - } - - // 9. 构建分页信息 - PageInfo pageInfo = new PageInfo<>(cartList); - - // 10. 构建返回数据格式 - Map responseData = new HashMap<>(); - responseData.put("current_page", pageInfo.getPageNum()); - responseData.put("data", resultList); - responseData.put("from", pageInfo.getStartRow()); - responseData.put("last_page", pageInfo.getPages()); - responseData.put("per_page", pageInfo.getPageSize()); - responseData.put("to", pageInfo.getEndRow()); - responseData.put("total", pageInfo.getTotal()); - - // 构建分页链接信息 - String baseUrl = "https://www.huafurenjia.cn/api/cart/lst"; - responseData.put("first_page_url", baseUrl + "?page=1"); - responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); - responseData.put("path", baseUrl); - - // 构建links数组 - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - - Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - - responseData.put("links", links); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - System.err.println("查询购物车列表异常:" + e.getMessage()); - return AppletControllerUtil.appletError("查询购物车列表失败:" + e.getMessage()); - } -} - - -/** - * 服务/商品搜索接口 - * - * @param params 请求参数,包含limit(每页数量)、page(页码)、keywords(搜索关键词) - * @param request HTTP请求对象 - * @return 搜索结果列表 - *

- * 接口说明: - * - 根据关键词搜索服务商品 - * - 支持按商品标题进行模糊查询 - * - 支持分页查询 - * - 无需用户登录验证 - *

- * 请求参数格式: - * { - * "limit": 15, - * "page": 1, - * "keywords": "3" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "current_page": 1, - * "data": [ - * { - * "id": 161, - * "title": "238元套餐", - * "icon": "https://img.huafurenjia.cn/images/238元套餐.png", - * "cate_id": 8, - * "price": "238.00", - * "price_zn": "元起", - * "sales": 66, - * "stock": 942, - * "sub_title": "咖啡机(咖啡)冷台·洗衣机(空调)烘", - * "title": "238元套餐", - * "type": 1 - * } - * ], - * "from": 1, - * "last_page": 1, - * "per_page": 15, - * "to": 2, - * "total": 2 - * } - * } - */ -@PostMapping(value = "/api/service/search") -public AjaxResult searchServices(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 获取搜索参数 - int page = params.get("page") != null ? (Integer) params.get("page") : 1; - int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; - String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : ""; - - // 2. 验证分页参数 - Map pageValidation = PageUtil.validatePageParams(page, limit); - if (!(Boolean) pageValidation.get("valid")) { - return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); - } - - // 3. 设置分页参数 - PageHelper.startPage(page, limit); - - // 4. 构建查询条件 - ServiceGoods queryGoods = new ServiceGoods(); - - // 如果有关键词,设置标题模糊查询 - if (!keywords.isEmpty()) { - queryGoods.setTitle(keywords); // 这里依赖mapper中的like查询实现 - } - - // 5. 查询商品列表 - List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); - - // 6. 构建返回数据 - List> resultList = new ArrayList<>(); - for (ServiceGoods goods : goodsList) { - Map goodsData = AppletControllerUtil.buildServiceGoodsData(goods); - resultList.add(goodsData); - } - - // 7. 构建分页信息 - PageInfo pageInfo = new PageInfo<>(goodsList); - - // 8. 构建返回数据格式 - Map responseData = new HashMap<>(); - responseData.put("current_page", pageInfo.getPageNum()); - responseData.put("data", resultList); - responseData.put("from", pageInfo.getStartRow()); - responseData.put("last_page", pageInfo.getPages()); - responseData.put("per_page", pageInfo.getPageSize()); - responseData.put("to", pageInfo.getEndRow()); - responseData.put("total", pageInfo.getTotal()); - - // 构建分页链接信息 - String baseUrl = "https://www.huafurenjia.cn/api/service/search"; - responseData.put("first_page_url", baseUrl + "?page=1"); - responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); - responseData.put("next_page_url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); - responseData.put("path", baseUrl); - - // 构建links数组 - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? - baseUrl + "?page=" + pageInfo.getPrePage() : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - - Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? - baseUrl + "?page=" + pageInfo.getNextPage() : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - - responseData.put("links", links); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - System.err.println("搜索服务商品异常:" + e.getMessage()); - return AppletControllerUtil.appletError("搜索失败:" + e.getMessage()); - } -} - -/** - * 获取商品订单详情接口 - * - * @param id 订单ID - * @param request HTTP请求对象 - * @return 订单详细信息 - *

- * 接口说明: - * - 根据订单ID获取商品订单完整信息 - * - 包含订单基本信息、用户地址、商品信息等 - * - 验证用户登录状态和订单归属权 - * - 返回完整的订单详情数据 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "id": 2, - * "type": 2, - * "main_order_id": "WXBB08452049418556", - * "order_id": "BB08452049567554", - * // ... 其他订单字段 - * "address": { - * // 地址信息 - * }, - * "product": { - * // 商品信息 - * }, - * "comment": [], - * "delivery": [] - * } - * } - */ -@GetMapping("/api/goods/order/info/{id}") -public AjaxResult getGoodsOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 1. 参数验证 - if (id == null || id <= 0) { - return AppletControllerUtil.appletWarning("订单ID无效"); - } - - // 2. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - - // 3. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 4. 查询订单信息并验证归属权 - GoodsOrder order = goodsOrderService.selectGoodsOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - - // 5. 验证订单归属权 - if (!order.getUid().equals(user.getId())) { - return AppletControllerUtil.appletWarning("无权访问该订单信息"); - } - - // 6. 构建订单详情数据 - Map orderDetail = buildGoodsOrderDetail(order); - - return AppletControllerUtil.appletSuccess(orderDetail); - - } catch (Exception e) { - System.err.println("查询商品订单详情异常:" + e.getMessage()); - return AppletControllerUtil.appletError("查询订单详情失败:" + e.getMessage()); - } -} - -/** - * 构建商品订单详情数据 - * - * @param order 订单信息 - * @return 格式化的订单详情 - */ -private Map buildGoodsOrderDetail(GoodsOrder order) { - Map orderDetail = new HashMap<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - // 订单基本信息 - orderDetail.put("id", order.getId()); - orderDetail.put("type", order.getType()); - orderDetail.put("main_order_id", order.getMainOrderId()); - orderDetail.put("order_id", order.getOrderId()); - orderDetail.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); - orderDetail.put("uid", order.getUid()); - orderDetail.put("product_id", order.getProductId()); - orderDetail.put("name", order.getName()); - orderDetail.put("phone", order.getPhone()); - orderDetail.put("num", order.getNum()); - orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); - orderDetail.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); - orderDetail.put("service_price", order.getServicePrice()); - orderDetail.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); - orderDetail.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); - orderDetail.put("postage", order.getPostage()); - orderDetail.put("pay_time", order.getPayTime() != null ? sdf.format(order.getPayTime()) : null); - orderDetail.put("status", order.getStatus()); - orderDetail.put("delivery_id", order.getDeliveryId()); - orderDetail.put("delivery_num", order.getDeliveryNum() != null ? order.getDeliveryNum() : ""); - orderDetail.put("send_time", order.getSendTime() != null ? sdf.format(order.getSendTime()) : null); - orderDetail.put("mark", order.getMark()); - orderDetail.put("address_id", order.getAddressId()); - orderDetail.put("sku", order.getSku()); - - // 时间字段格式化 - orderDetail.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); - orderDetail.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); - orderDetail.put("deleted_at", order.getDeletedAt() != null ? sdf.format(order.getDeletedAt()) : null); - - // 查询并添加地址信息 - if (order.getAddressId() != null) { - UserAddress address = userAddressService.selectUserAddressById(order.getAddressId()); - if (address != null) { - Map addressInfo = new HashMap<>(); - addressInfo.put("id", address.getId()); - addressInfo.put("uid", address.getUid()); - addressInfo.put("name", address.getName()); - addressInfo.put("phone", address.getPhone()); - addressInfo.put("latitude", address.getLatitude()); - addressInfo.put("longitude", address.getLongitude()); - addressInfo.put("address_name", address.getAddressName()); - addressInfo.put("address_info", address.getAddressInfo()); - addressInfo.put("info", address.getInfo()); - addressInfo.put("is_default", address.getIsDefault()); - addressInfo.put("created_at", address.getCreatedAt() != null ? sdf.format(address.getCreatedAt()) : null); - addressInfo.put("updated_at", address.getUpdatedAt() != null ? sdf.format(address.getUpdatedAt()) : null); - addressInfo.put("deleted_at", null); // UserAddress可能没有deletedAt字段 - - orderDetail.put("address", addressInfo); + } catch (Exception e) { + System.err.println("添加购物车异常:" + e.getMessage()); + return AppletControllerUtil.appletError("添加购物车失败:" + e.getMessage()); } } - // 查询并添加商品信息 - if (order.getProductId() != null) { - ServiceGoods product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - if (product != null) { - Map productInfo = new HashMap<>(); - productInfo.put("id", product.getId()); - productInfo.put("title", product.getTitle()); - productInfo.put("sub_title", product.getSubTitle()); - productInfo.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); - - orderDetail.put("product", productInfo); - } - } - - // 添加评论和配送信息(暂时为空数组,后续可以扩展) - orderDetail.put("comment", new ArrayList<>()); - orderDetail.put("delivery", new ArrayList<>()); - - return orderDetail; -} - -/** - * 获取用户优惠券数量统计接口 - * - * @param request HTTP请求对象 - * @return 优惠券数量统计信息 - *

- * 接口说明: - * - 统计当前登录用户的优惠券数量 - * - 包含未使用、已使用、已过期、待领取数量 - * - 需要用户登录验证 - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": { - * "one": 1, // 未使用数量 - * "two": 0, // 已使用数量 - * "three": 0, // 已过期数量 - * "four": 13 // 待领取数量 - * } - * } - */ -@GetMapping("/api/coupon/my/count") -public AjaxResult getMyCouponCount(HttpServletRequest request) { - try { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 6. 构建返回数据 - Map countData = new HashMap<>(); - countData.put("one", couponUserService.selectCountCouponsByUid(user.getId(), 1L)); // 未使用数量 - countData.put("two",couponUserService.selectCountCouponsByUid(user.getId(), 3L)); // 已使用数量 - countData.put("three",couponUserService.selectCountCouponsByUid(user.getId(), 2L)); // 已过期数量 - countData.put("four", CouponUtil.iscoupon(user.getId(), couponsService, couponUserService).size()); // 待领取数量 - - return AppletControllerUtil.appletSuccess(countData); - - } catch (Exception e) { - System.err.println("查询用户优惠券数量统计异常:" + e.getMessage()); - return AppletControllerUtil.appletError("查询优惠券数量统计失败:" + e.getMessage()); - } -} - -/** - * 判断优惠券是否已过期 - * - * @param couponUser 用户优惠券 - * @param currentTime 当前时间戳(秒) - * @return 是否过期 - */ -private boolean isExpired(CouponUser couponUser, long currentTime) { - // 检查lose_time字段(失效时间),这是一个字符串时间戳 - if (couponUser.getLoseTime() != null && !couponUser.getLoseTime().isEmpty()) { + /** + * 查询购物车列表接口 + * + * @param params 请求参数,包含limit(每页数量)、page(页码) + * @param request HTTP请求对象 + * @return 购物车列表数据 + *

+ * 接口说明: + * - 获取当前登录用户的购物车商品列表 + * - 支持分页查询 + * - 返回完整的商品信息 + * - 需要用户登录验证 + *

+ */ + @PostMapping(value = "/api/cart/lst") + public AjaxResult getCartList(@RequestBody Map params, HttpServletRequest request) { try { - long loseTimeStamp = Long.parseLong(couponUser.getLoseTime()); - return currentTime > loseTimeStamp; - } catch (NumberFormatException e) { - // 如果解析失败,假设为日期格式,暂时认为未过期 - System.err.println("解析失效时间失败:" + couponUser.getLoseTime()); + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 获取分页参数 + int page = params.get("page") != null ? (Integer) params.get("page") : 1; + int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; + + // 4. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); + } + + // 5. 设置分页参数 + PageHelper.startPage(page, limit); + + // 6. 构建查询条件 + GoodsCart queryCart = new GoodsCart(); + queryCart.setUid(user.getId()); + + // 7. 查询购物车列表 + List cartList = goodsCartService.selectGoodsCartList(queryCart); + + // 8. 为每个购物车项目填充商品信息 + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (GoodsCart cart : cartList) { + Map cartData = new HashMap<>(); + + // 基本购物车信息 + cartData.put("id", cart.getId()); + cartData.put("uid", cart.getUid()); + cartData.put("good_id", cart.getGoodId()); + cartData.put("good_num", cart.getGoodNum()); + if (cart.getSku() != null || cart.getSku() != "") { + cartData.put("sku", JSONObject.parseObject(cart.getSku())); + } else { + cartData.put("sku", null); + } + + + // 格式化时间字段 + cartData.put("created_at", cart.getCreatedAt() != null ? + sdf.format(cart.getCreatedAt()) : null); + cartData.put("updated_at", cart.getUpdatedAt() != null ? + sdf.format(cart.getUpdatedAt()) : null); + + // 查询并添加商品详细信息 + Map goodInfo = AppletControllerUtil.getGoodDetailForCart(cart.getGoodId(), serviceGoodsService); + cartData.put("good", goodInfo); + + resultList.add(cartData); + } + + // 9. 构建分页信息 + PageInfo pageInfo = new PageInfo<>(cartList); + + // 10. 构建返回数据格式 + Map responseData = new HashMap<>(); + responseData.put("current_page", pageInfo.getPageNum()); + responseData.put("data", resultList); + responseData.put("from", pageInfo.getStartRow()); + responseData.put("last_page", pageInfo.getPages()); + responseData.put("per_page", pageInfo.getPageSize()); + responseData.put("to", pageInfo.getEndRow()); + responseData.put("total", pageInfo.getTotal()); + + // 构建分页链接信息 + String baseUrl = "https://www.huafurenjia.cn/api/cart/lst"; + responseData.put("first_page_url", baseUrl + "?page=1"); + responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("path", baseUrl); + + // 构建links数组 + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + + responseData.put("links", links); + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + System.err.println("查询购物车列表异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询购物车列表失败:" + e.getMessage()); } } - // 如果状态为3,表示已失效 - if (couponUser.getStatus() != null && couponUser.getStatus() == 3L) { - return true; + + /** + * 服务/商品搜索接口 + * + * @param params 请求参数,包含limit(每页数量)、page(页码)、keywords(搜索关键词) + * @param request HTTP请求对象 + * @return 搜索结果列表 + *

+ * 接口说明: + * - 根据关键词搜索服务商品 + * - 支持按商品标题进行模糊查询 + * - 支持分页查询 + * - 无需用户登录验证 + *

+ */ + @PostMapping(value = "/api/service/search") + public AjaxResult searchServices(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 获取搜索参数 + int page = params.get("page") != null ? (Integer) params.get("page") : 1; + int limit = params.get("limit") != null ? (Integer) params.get("limit") : 15; + String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : ""; + + // 2. 验证分页参数 + Map pageValidation = PageUtil.validatePageParams(page, limit); + if (!(Boolean) pageValidation.get("valid")) { + return AppletControllerUtil.appletWarning((String) pageValidation.get("message")); + } + + // 3. 设置分页参数 + PageHelper.startPage(page, limit); + + // 4. 构建查询条件 + ServiceGoods queryGoods = new ServiceGoods(); + + // 如果有关键词,设置标题模糊查询 + if (!keywords.isEmpty()) { + queryGoods.setTitle(keywords); // 这里依赖mapper中的like查询实现 + } + + // 5. 查询商品列表 + List goodsList = serviceGoodsService.selectServiceGoodsList(queryGoods); + + // 6. 构建返回数据 + List> resultList = new ArrayList<>(); + for (ServiceGoods goods : goodsList) { + Map goodsData = AppletControllerUtil.buildServiceGoodsData(goods); + resultList.add(goodsData); + } + + // 7. 构建分页信息 + PageInfo pageInfo = new PageInfo<>(goodsList); + + // 8. 构建返回数据格式 + Map responseData = new HashMap<>(); + responseData.put("current_page", pageInfo.getPageNum()); + responseData.put("data", resultList); + responseData.put("from", pageInfo.getStartRow()); + responseData.put("last_page", pageInfo.getPages()); + responseData.put("per_page", pageInfo.getPageSize()); + responseData.put("to", pageInfo.getEndRow()); + responseData.put("total", pageInfo.getTotal()); + + // 构建分页链接信息 + String baseUrl = "https://www.huafurenjia.cn/api/service/search"; + responseData.put("first_page_url", baseUrl + "?page=1"); + responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("path", baseUrl); + + // 构建links数组 + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? + baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? + baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + + responseData.put("links", links); + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + System.err.println("搜索服务商品异常:" + e.getMessage()); + return AppletControllerUtil.appletError("搜索失败:" + e.getMessage()); + } } - // 如果都没有设置,认为未过期 - return false; -} + /** + * 获取商品订单详情接口 + * + * @param id 订单ID + * @param request HTTP请求对象 + * @return 订单详细信息 + *

+ * 接口说明: + * - 根据订单ID获取商品订单完整信息 + * - 包含订单基本信息、用户地址、商品信息等 + * - 验证用户登录状态和订单归属权 + * - 返回完整的订单详情数据 + *

+ */ + @GetMapping("/api/goods/order/info/{id}") + public AjaxResult getGoodsOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 1. 参数验证 + if (id == null || id <= 0) { + return AppletControllerUtil.appletWarning("订单ID无效"); + } -/** - * 判断优惠券是否可以领取 - * - * @param coupon 优惠券 - * @param userId 用户ID - * @param currentTime 当前时间戳(秒) - * @return 是否可以领取 - */ -private boolean isCouponAvailableToReceive(Coupons coupon, Long userId, long currentTime) { - // 检查优惠券状态 - if (coupon.getStatus() == null || coupon.getStatus() != 1L) { + // 2. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + + // 3. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 4. 查询订单信息并验证归属权 + GoodsOrder order = goodsOrderService.selectGoodsOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + + // 5. 验证订单归属权 + if (!order.getUid().equals(user.getId())) { + return AppletControllerUtil.appletWarning("无权访问该订单信息"); + } + + // 6. 构建订单详情数据 + Map orderDetail = buildGoodsOrderDetail(order); + + return AppletControllerUtil.appletSuccess(orderDetail); + + } catch (Exception e) { + System.err.println("查询商品订单详情异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询订单详情失败:" + e.getMessage()); + } + } + + /** + * 构建商品订单详情数据 + * + * @param order 订单信息 + * @return 格式化的订单详情 + */ + private Map buildGoodsOrderDetail(GoodsOrder order) { + Map orderDetail = new HashMap<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + // 订单基本信息 + orderDetail.put("id", order.getId()); + orderDetail.put("type", order.getType()); + orderDetail.put("main_order_id", order.getMainOrderId()); + orderDetail.put("order_id", order.getOrderId()); + orderDetail.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); + orderDetail.put("uid", order.getUid()); + orderDetail.put("product_id", order.getProductId()); + orderDetail.put("name", order.getName()); + orderDetail.put("phone", order.getPhone()); + orderDetail.put("num", order.getNum()); + orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + orderDetail.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); + orderDetail.put("service_price", order.getServicePrice()); + orderDetail.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); + orderDetail.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); + orderDetail.put("postage", order.getPostage()); + orderDetail.put("pay_time", order.getPayTime() != null ? sdf.format(order.getPayTime()) : null); + orderDetail.put("status", order.getStatus()); + orderDetail.put("delivery_id", order.getDeliveryId()); + orderDetail.put("delivery_num", order.getDeliveryNum() != null ? order.getDeliveryNum() : ""); + orderDetail.put("send_time", order.getSendTime() != null ? sdf.format(order.getSendTime()) : null); + orderDetail.put("mark", order.getMark()); + orderDetail.put("address_id", order.getAddressId()); + orderDetail.put("sku", order.getSku()); + + // 时间字段格式化 + orderDetail.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); + orderDetail.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); + orderDetail.put("deleted_at", order.getDeletedAt() != null ? sdf.format(order.getDeletedAt()) : null); + + // 查询并添加地址信息 + if (order.getAddressId() != null) { + UserAddress address = userAddressService.selectUserAddressById(order.getAddressId()); + if (address != null) { + Map addressInfo = new HashMap<>(); + addressInfo.put("id", address.getId()); + addressInfo.put("uid", address.getUid()); + addressInfo.put("name", address.getName()); + addressInfo.put("phone", address.getPhone()); + addressInfo.put("latitude", address.getLatitude()); + addressInfo.put("longitude", address.getLongitude()); + addressInfo.put("address_name", address.getAddressName()); + addressInfo.put("address_info", address.getAddressInfo()); + addressInfo.put("info", address.getInfo()); + addressInfo.put("is_default", address.getIsDefault()); + addressInfo.put("created_at", address.getCreatedAt() != null ? sdf.format(address.getCreatedAt()) : null); + addressInfo.put("updated_at", address.getUpdatedAt() != null ? sdf.format(address.getUpdatedAt()) : null); + addressInfo.put("deleted_at", null); // UserAddress可能没有deletedAt字段 + orderDetail.put("address", addressInfo); + } + } + // 查询并添加商品信息 + if (order.getProductId() != null) { + ServiceGoods product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (product != null) { + Map productInfo = new HashMap<>(); + productInfo.put("id", product.getId()); + productInfo.put("title", product.getTitle()); + productInfo.put("sub_title", product.getSubTitle()); + productInfo.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); + + orderDetail.put("product", productInfo); + } + } + // 添加评论和配送信息(暂时为空数组,后续可以扩展) + orderDetail.put("comment", new ArrayList<>()); + orderDetail.put("delivery", new ArrayList<>()); + + return orderDetail; + } + + /** + * 获取用户优惠券数量统计接口 + * + * @param request HTTP请求对象 + * @return 优惠券数量统计信息 + *

+ * 接口说明: + * - 统计当前登录用户的优惠券数量 + * - 包含未使用、已使用、已过期、待领取数量 + * - 需要用户登录验证 + *

+ */ + @GetMapping("/api/coupon/my/count") + public AjaxResult getMyCouponCount(HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 6. 构建返回数据 + Map countData = new HashMap<>(); + countData.put("one", couponUserService.selectCountCouponsByUid(user.getId(), 1L)); // 未使用数量 + countData.put("two",couponUserService.selectCountCouponsByUid(user.getId(), 3L)); // 已使用数量 + countData.put("three",couponUserService.selectCountCouponsByUid(user.getId(), 2L)); // 已过期数量 + countData.put("four", CouponUtil.iscoupon(user.getId(), couponsService, couponUserService).size()); // 待领取数量 + + return AppletControllerUtil.appletSuccess(countData); + + } catch (Exception e) { + System.err.println("查询用户优惠券数量统计异常:" + e.getMessage()); + return AppletControllerUtil.appletError("查询优惠券数量统计失败:" + e.getMessage()); + } + } + + /** + * 判断优惠券是否已过期 + * + * @param couponUser 用户优惠券 + * @param currentTime 当前时间戳(秒) + * @return 是否过期 + */ + private boolean isExpired(CouponUser couponUser, long currentTime) { + // 检查lose_time字段(失效时间),这是一个字符串时间戳 + if (couponUser.getLoseTime() != null && !couponUser.getLoseTime().isEmpty()) { + try { + long loseTimeStamp = Long.parseLong(couponUser.getLoseTime()); + return currentTime > loseTimeStamp; + } catch (NumberFormatException e) { + // 如果解析失败,假设为日期格式,暂时认为未过期 + System.err.println("解析失效时间失败:" + couponUser.getLoseTime()); + } + } + // 如果状态为3,表示已失效 + if (couponUser.getStatus() != null && couponUser.getStatus() == 3L) { + return true; + } + // 如果都没有设置,认为未过期 return false; } - // 检查领取时间范围 - if (coupon.getStartTime() != null && currentTime < coupon.getStartTime()) { - return false; // 还未到领取时间 - } + /** + * 创建服务订单(支持多商品批量下单) + * + * @param params 请求参数,包含多个商品信息、地址信息和预约时间 + * @param request HTTP请求对象 + * @return 返回创建结果 + */ + @PostMapping("/api/service/create/order") + public AjaxResult createServiceOrder(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } - if (coupon.getEndTime() != null && currentTime > coupon.getEndTime()) { - return false; // 已过领取时间 - } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } - // 检查数量限制(如果不是无限领取) - if (coupon.getIsPermanent() == null || coupon.getIsPermanent() != 1L) { - if (coupon.getCount() != null && coupon.getCount() <= 0) { - return false; // 数量已用完 + // 3. 验证订单参数 + if (params == null || params.isEmpty()) { + return AppletControllerUtil.appletWarning("订单参数不能为空"); + } + + // 4. 生成主订单号 + String mainOrderId = GenerateCustomCode.generCreateOrder("WXB"); + + // 5. 存储所有订单信息 + List> orderList = new ArrayList<>(); + BigDecimal totalAmount = BigDecimal.ZERO; // 总金额 + + // 6. 遍历所有订单项 + for (String key : params.keySet()) { + // 跳过非数字键 + if (!key.matches("\\d+")) { + continue; + } + + Map orderParams = (Map) params.get(key); + + // 验证必要参数 + if (orderParams.get("product_id") == null || orderParams.get("address_id") == null) { + return AppletControllerUtil.appletWarning("商品ID或地址ID不能为空"); + } + + Long productId = Long.valueOf(orderParams.get("product_id").toString()); + Long addressId = Long.valueOf(orderParams.get("address_id").toString()); + Long num = orderParams.get("num") != null ? Long.valueOf(orderParams.get("num").toString()) : 1L; + + // 处理SKU参数 + String sku = AppletControllerUtil.processSkuParam(orderParams.get("sku")); + + // 查询商品信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("商品ID " + productId + " 不存在"); + } + + // 查询地址信息(只需要查询一次,假设所有订单使用相同地址) + UserAddress userAddress = userAddressService.selectUserAddressById(addressId); + if (userAddress == null) { + return AppletControllerUtil.appletWarning("地址不存在"); + } + + // 计算单个订单金额 + BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); + totalAmount = totalAmount.add(itemPrice); + + // 判断商品类型并创建相应订单 + BigDecimal DeductionPrice = new BigDecimal("0"); + if (serviceGoods.getType() == 2) { + // 创建服务订单 + String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; + CouponUser coupon=null; + if (coupon_id!=null){ + coupon = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); + if (coupon==null){ + return AppletControllerUtil.appletWarning("优惠券不存在"); + } + } + if (coupon != null) { + DeductionPrice= new BigDecimal(coupon.getCouponPrice()).divide(new BigDecimal(params.size()),2, RoundingMode.HALF_UP); + } + if (coupon != null) { + coupon.setStatus(2L); + } + couponUserService.updateCouponUser(coupon) ; + // 创建商品订单 + GoodsOrder goodsOrder = new GoodsOrder(); + goodsOrder.setType(2); + goodsOrder.setMainOrderId(mainOrderId); + goodsOrder.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 + goodsOrder.setUid(user.getId()); + goodsOrder.setProductId(productId); + goodsOrder.setName(userAddress.getName()); + goodsOrder.setPhone(userAddress.getPhone()); + goodsOrder.setAddress(userAddress.getAddressName()); + goodsOrder.setNum(num); + goodsOrder.setTotalPrice(itemPrice); + goodsOrder.setGoodPrice(serviceGoods.getPrice()); + goodsOrder.setPayPrice(itemPrice); + goodsOrder.setDeduction(DeductionPrice); + goodsOrder.setCouponId(Long.valueOf(coupon_id)); + goodsOrder.setStatus(1L); // 待支付状态 + goodsOrder.setAddressId(addressId); + goodsOrder.setSku(sku); + // 保存商品订单 + int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); + if (insertResult <= 0) { + return AppletControllerUtil.appletWarning("商品订单创建失败,请稍后重试"); + } + // 添加到订单列表 + Map orderInfo = new HashMap<>(); + orderInfo.put("type", "goods"); + orderInfo.put("orderId", goodsOrder.getId()); + orderInfo.put("orderNo", goodsOrder.getOrderId()); + orderInfo.put("productName", serviceGoods.getTitle()); + orderInfo.put("price", itemPrice.toString()); + orderList.add(orderInfo); + } else { + // 创建服务订单 + String makeTime = orderParams.get("make_time") != null ? orderParams.get("make_time").toString() : ""; + String fileData = orderParams.get("fileData") != null ? orderParams.get("fileData").toString() : ""; + Order order = new Order(); + order.setType(1); // 1:服务项目 + order.setCreateType(1); // 1:用户自主下单 + order.setUid(user.getId()); + order.setUname(user.getName()); + order.setProductId(productId); + order.setProductName(serviceGoods.getTitle()); + order.setName(userAddress.getName()); + order.setFileData(fileData != null ? JSON.toJSONString(fileData) : null); + order.setPhone(userAddress.getPhone()); + order.setAddress(userAddress.getAddressInfo()); + order.setAddressId(addressId); + order.setSku(sku); + order.setMainOrderId(mainOrderId); + order.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 + // 处理预约时间 + if (makeTime != null && !makeTime.isEmpty()) { + String[] makeTimeArr = makeTime.split(" "); + if (makeTimeArr.length == 2) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date date = sdf.parse(makeTimeArr[0]); + order.setMakeTime(date.getTime() / 1000); + order.setMakeHour(makeTimeArr[1]); + } catch (Exception e) { + logger.warn("预约时间格式错误: " + makeTime); + } + } + } + order.setNum(num); + order.setTotalPrice(itemPrice); + order.setGoodPrice(serviceGoods.getPrice()); + order.setServicePrice(BigDecimal.ZERO); + order.setPayPrice(itemPrice); + order.setStatus(1L); // 1:待接单 + order.setReceiveType(1L); // 1:自由抢单 + order.setIsAccept(0); + order.setIsComment(0); + order.setIsPause(1); + order.setDeduction(new BigDecimal(0)); + // 保存服务订单 + int result = orderService.insertOrder(order); + if (result <= 0) { + return AppletControllerUtil.appletWarning("服务订单创建失败,请稍后重试"); + } + // 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单生成"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "预约成功,将尽快为主人派单"); + orderLog.setType(new BigDecimal(1.0)); + orderLog.setContent(jsonObject.toString()); + orderLogService.insertOrderLog(orderLog); + + // 系统派单和消息通知逻辑 + Order orderNewData = orderService.selectOrderById(order.getId()); + String wxsendmsg = WXsendMsgUtil.sendMsgForUserInfo(user.getOpenid(), orderNewData, serviceGoods); + Users worker = AppletControllerUtil.creatWorkerForOrder(orderNewData); + + if (worker != null) { + // 更新订单状态为已派单 + orderNewData.setWorkerId(worker.getId()); + orderNewData.setStatus(2l); + orderNewData.setIsPause(1); + orderNewData.setReceiveTime(new Date()); + orderNewData.setReceiveType(3l); + orderNewData.setLogStatus(9); + JSONObject jSONObject = new JSONObject(); + jSONObject.put("type", 9); + orderNewData.setLogJson(jSONObject.toJSONString()); + orderService.updateOrder(orderNewData); + // 添加派单日志 + OrderLog orderLognew = new OrderLog(); + orderLognew.setOid(orderNewData.getId()); + orderLognew.setOrderId(orderNewData.getOrderId()); + orderLognew.setTitle("平台派单"); + orderLognew.setType(new BigDecimal(1.1)); + JSONObject jSONObject1 = new JSONObject(); + jSONObject1.put("name", "师傅收到派单信息"); + orderLognew.setContent(jSONObject1.toJSONString()); + orderLognew.setWorkerId(worker.getId()); + orderLognew.setWorkerLogId(worker.getId()); + orderLogService.insertOrderLog(orderLognew); + // 发送通知 + WXsendMsgUtil.sendMsgForWorkerInfo(worker.getOpenid(), orderNewData, serviceGoods); + YunXinPhoneUtilAPI.httpsAxbTransfer(worker.getPhone()); + } + + // 添加到订单列表 + Map orderInfo = new HashMap<>(); + orderInfo.put("type", "service"); + orderInfo.put("orderId", order.getId()); + orderInfo.put("orderNo", order.getOrderId()); + orderInfo.put("productName", serviceGoods.getTitle()); + orderInfo.put("price", itemPrice.toString()); + orderList.add(orderInfo); + } + } + // 7. 如果有商品订单,需要发起微信支付 + boolean hasGoodsOrder = orderList.stream().anyMatch(order -> "goods".equals(order.get("type"))); + if (hasGoodsOrder && totalAmount.compareTo(BigDecimal.ZERO) > 0) { + // 使用工具类简化微信支付参数组装 + Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("mainOrderId", mainOrderId); + responseData.put("orderList", orderList); + responseData.put("totalAmount", totalAmount.toString()); + responseData.put("prepayId", payResult.get("prepayId")); + // 直接合并所有支付参数 + responseData.putAll(payResult); + return AppletControllerUtil.appletSuccess(responseData); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } else { + // 没有商品订单,只有服务订单,直接返回成功 + Map responseData = new HashMap<>(); + responseData.put("mainOrderId", mainOrderId); + responseData.put("orderList", orderList); + responseData.put("totalAmount", totalAmount.toString()); + return AppletControllerUtil.appletSuccess(responseData); + } + } catch (Exception e) { + logger.error("创建订单异常:", e); + return AppletControllerUtil.appletWarning("创建订单失败:" + e.getMessage()); } } - // 检查用户是否已经领取过此优惠券(如果有限制的话) - // 这里可以根据业务规则进一步完善 - - return true; -} - -/** - * 创建服务订单(支持多商品批量下单) - * - * @param params 请求参数,包含多个商品信息、地址信息和预约时间 - * @param request HTTP请求对象 - * @return 返回创建结果 - */ -@PostMapping("/api/service/create/order") -public AjaxResult createServiceOrder(@RequestBody Map params, HttpServletRequest request) { - try { + /** + * 尾款结算 + */ + @PostMapping("api/service/order/pay/total/price") + public AjaxResult apiServiceOrderPayTotalPprice(@RequestBody Map params, HttpServletRequest request) { // 1. 验证用户登录状态 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { return AppletControllerUtil.appletWarning("用户未登录或token无效"); } - // 2. 获取用户信息 Users user = (Users) userValidation.get("user"); if (user == null) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - - // 3. 验证订单参数 - if (params == null || params.isEmpty()) { - return AppletControllerUtil.appletWarning("订单参数不能为空"); + // 3. 验证必要参数 + if (params == null || params.get("order_id") == null || params.get("worker_id") == null) { + return AppletControllerUtil.appletWarning("参数不能为空"); } - - // 4. 生成主订单号 - String mainOrderId = GenerateCustomCode.generCreateOrder("WXB"); - - // 5. 存储所有订单信息 - List> orderList = new ArrayList<>(); - BigDecimal totalAmount = BigDecimal.ZERO; // 总金额 - - // 6. 遍历所有订单项 - for (String key : params.keySet()) { - // 跳过非数字键 - if (!key.matches("\\d+")) { - continue; - } - - Map orderParams = (Map) params.get(key); - - // 验证必要参数 - if (orderParams.get("product_id") == null || orderParams.get("address_id") == null) { - return AppletControllerUtil.appletWarning("商品ID或地址ID不能为空"); - } - - Long productId = Long.valueOf(orderParams.get("product_id").toString()); - Long addressId = Long.valueOf(orderParams.get("address_id").toString()); - Long num = orderParams.get("num") != null ? Long.valueOf(orderParams.get("num").toString()) : 1L; - - // 处理SKU参数 - String sku = AppletControllerUtil.processSkuParam(orderParams.get("sku")); - - // 查询商品信息 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); - if (serviceGoods == null) { - return AppletControllerUtil.appletWarning("商品ID " + productId + " 不存在"); - } - - // 查询地址信息(只需要查询一次,假设所有订单使用相同地址) - UserAddress userAddress = userAddressService.selectUserAddressById(addressId); - if (userAddress == null) { - return AppletControllerUtil.appletWarning("地址不存在"); - } - - // 计算单个订单金额 - BigDecimal itemPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); - totalAmount = totalAmount.add(itemPrice); - - // 判断商品类型并创建相应订单 - BigDecimal DeductionPrice = new BigDecimal("0"); - if (serviceGoods.getType() == 2) { - // 创建服务订单 - String coupon_id = orderParams.get("coupon_id") != null ? orderParams.get("coupon_id").toString() : ""; - CouponUser coupon=null; - if (coupon_id!=null){ - coupon = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); - if (coupon==null){ - return AppletControllerUtil.appletWarning("优惠券不存在"); - } - } - if (coupon != null) { - DeductionPrice= new BigDecimal(coupon.getCouponPrice()).divide(new BigDecimal(params.size()),2, RoundingMode.HALF_UP); - } - if (coupon != null) { - coupon.setStatus(2L); - } - couponUserService.updateCouponUser(coupon) ; - // 创建商品订单 - GoodsOrder goodsOrder = new GoodsOrder(); - goodsOrder.setType(2); - goodsOrder.setMainOrderId(mainOrderId); - goodsOrder.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 - goodsOrder.setUid(user.getId()); - goodsOrder.setProductId(productId); - goodsOrder.setName(userAddress.getName()); - goodsOrder.setPhone(userAddress.getPhone()); - goodsOrder.setAddress(userAddress.getAddressName()); - goodsOrder.setNum(num); - goodsOrder.setTotalPrice(itemPrice); - goodsOrder.setGoodPrice(serviceGoods.getPrice()); - goodsOrder.setPayPrice(itemPrice); - goodsOrder.setDeduction(DeductionPrice); - goodsOrder.setCouponId(Long.valueOf(coupon_id)); - goodsOrder.setStatus(1L); // 待支付状态 - goodsOrder.setAddressId(addressId); - goodsOrder.setSku(sku); - - // 保存商品订单 - int insertResult = goodsOrderService.insertGoodsOrder(goodsOrder); - if (insertResult <= 0) { - return AppletControllerUtil.appletWarning("商品订单创建失败,请稍后重试"); - } - - // 添加到订单列表 - Map orderInfo = new HashMap<>(); - orderInfo.put("type", "goods"); - orderInfo.put("orderId", goodsOrder.getId()); - orderInfo.put("orderNo", goodsOrder.getOrderId()); - orderInfo.put("productName", serviceGoods.getTitle()); - orderInfo.put("price", itemPrice.toString()); - orderList.add(orderInfo); - - } else { - // 创建服务订单 - String makeTime = orderParams.get("make_time") != null ? orderParams.get("make_time").toString() : ""; - String fileData = orderParams.get("fileData") != null ? orderParams.get("fileData").toString() : ""; - Order order = new Order(); - order.setType(1); // 1:服务项目 - order.setCreateType(1); // 1:用户自主下单 - order.setUid(user.getId()); - order.setUname(user.getName()); - order.setProductId(productId); - order.setProductName(serviceGoods.getTitle()); - order.setName(userAddress.getName()); - order.setFileData(fileData); - order.setPhone(userAddress.getPhone()); - order.setAddress(userAddress.getAddressInfo()); - order.setAddressId(addressId); - order.setSku(sku); - order.setMainOrderId(mainOrderId); - order.setOrderId(GenerateCustomCode.generCreateOrder("B")); // 独立订单号 - - // 处理预约时间 - if (makeTime != null && !makeTime.isEmpty()) { - String[] makeTimeArr = makeTime.split(" "); - if (makeTimeArr.length == 2) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date date = sdf.parse(makeTimeArr[0]); - order.setMakeTime(date.getTime() / 1000); - order.setMakeHour(makeTimeArr[1]); - } catch (Exception e) { - logger.warn("预约时间格式错误: " + makeTime); - } - } - } - - order.setNum(num); - order.setTotalPrice(itemPrice); - order.setGoodPrice(serviceGoods.getPrice()); - order.setServicePrice(BigDecimal.ZERO); - order.setPayPrice(itemPrice); - order.setStatus(1L); // 1:待接单 - order.setReceiveType(1L); // 1:自由抢单 - order.setIsAccept(0); - order.setIsComment(0); - order.setIsPause(1); - order.setDeduction(new BigDecimal(0)); - - // 保存服务订单 - int result = orderService.insertOrder(order); - if (result <= 0) { - return AppletControllerUtil.appletWarning("服务订单创建失败,请稍后重试"); - } - - // 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("订单生成"); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", "预约成功,将尽快为主人派单"); - orderLog.setType(new BigDecimal(1.0)); - orderLog.setContent(jsonObject.toString()); - orderLogService.insertOrderLog(orderLog); - - // 系统派单和消息通知逻辑 - Order orderNewData = orderService.selectOrderById(order.getId()); - String wxsendmsg = WXsendMsgUtil.sendMsgForUserInfo(user.getOpenid(), orderNewData, serviceGoods); - Users worker = AppletControllerUtil.creatWorkerForOrder(orderNewData); - - if (worker != null) { - // 更新订单状态为已派单 - orderNewData.setWorkerId(worker.getId()); - orderNewData.setStatus(2l); - orderNewData.setIsPause(1); - orderNewData.setReceiveTime(new Date()); - orderNewData.setReceiveType(3l); - orderNewData.setLogStatus(9); - JSONObject jSONObject = new JSONObject(); - jSONObject.put("type", 9); - orderNewData.setLogJson(jSONObject.toJSONString()); - orderService.updateOrder(orderNewData); - - // 添加派单日志 - OrderLog orderLognew = new OrderLog(); - orderLognew.setOid(orderNewData.getId()); - orderLognew.setOrderId(orderNewData.getOrderId()); - orderLognew.setTitle("平台派单"); - orderLognew.setType(new BigDecimal(1.1)); - JSONObject jSONObject1 = new JSONObject(); - jSONObject1.put("name", "师傅收到派单信息"); - orderLognew.setContent(jSONObject1.toJSONString()); - orderLognew.setWorkerId(worker.getId()); - orderLognew.setWorkerLogId(worker.getId()); - orderLogService.insertOrderLog(orderLognew); - - // 发送通知 - WXsendMsgUtil.sendMsgForWorkerInfo(worker.getOpenid(), orderNewData, serviceGoods); - YunXinPhoneUtilAPI.httpsAxbTransfer(worker.getPhone()); - } - - // 添加到订单列表 - Map orderInfo = new HashMap<>(); - orderInfo.put("type", "service"); - orderInfo.put("orderId", order.getId()); - orderInfo.put("orderNo", order.getOrderId()); - orderInfo.put("productName", serviceGoods.getTitle()); - orderInfo.put("price", itemPrice.toString()); - orderList.add(orderInfo); + Long worker_id = Long.valueOf(params.get("worker_id").toString()); + String order_id = params.get("order_id").toString(); + Order order = orderService.selectOrderByOrderId(order_id); + // 2. 查询订单日志(取type=5评估报价,或最新一条) + List logList = orderLogService.selectOrderLogByOrderId(order.getOrderId()); + OrderLog log = null; + for (OrderLog l : logList) { + if (l.getType() != null && l.getType().intValue() == 5) { + log = l; + break; } } + if (log == null && !logList.isEmpty()) { + log = logList.get(0); + } + if (log == null) { + return AppletControllerUtil.appletWarning("未找到订单日志"); + } + if (params.get("coupon_id")!= null) { + String coupon_id = params.get("coupon_id").toString(); + if (coupon_id != null && !coupon_id.isEmpty()) { + CouponUser couponUser = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); + if (couponUser == null && couponUser.getStatus() != 1) { + return AppletControllerUtil.appletWarning("优惠券已被使用,或优惠券不存在"); + } + OrderLog orderLogQery = new OrderLog(); + orderLogQery.setOrderId(order.getOrderId()); + orderLogQery.setType(new BigDecimal(5)); + orderLogQery.setWorkerId(worker_id); + OrderLog orderLognew = orderLogService.selectOneByOidTypeWorkerIdPaid(orderLogQery); + if (orderLognew != null) { + orderLognew.setCouponId(couponUser.getCouponId()); + orderLognew.setDeduction(new BigDecimal(couponUser.getCouponPrice())); + orderLogService.updateOrderLog(orderLognew); + order.setCouponId(couponUser.getCouponId()); + order.setDeduction(new BigDecimal(couponUser.getCouponPrice())); + orderService.updateOrder(order); + } - // 7. 如果有商品订单,需要发起微信支付 - boolean hasGoodsOrder = orderList.stream().anyMatch(order -> "goods".equals(order.get("type"))); - if (hasGoodsOrder && totalAmount.compareTo(BigDecimal.ZERO) > 0) { - // 使用工具类简化微信支付参数组装 - Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), mainOrderId, new BigDecimal(0.01), orderList.size(), "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); - if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { - Map responseData = new HashMap<>(); - responseData.put("mainOrderId", mainOrderId); - responseData.put("orderList", orderList); - responseData.put("totalAmount", totalAmount.toString()); - responseData.put("prepayId", payResult.get("prepayId")); - // 直接合并所有支付参数 - responseData.putAll(payResult); - return AppletControllerUtil.appletSuccess(responseData); - } else { - String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } - } else { - // 没有商品订单,只有服务订单,直接返回成功 - Map responseData = new HashMap<>(); - responseData.put("mainOrderId", mainOrderId); - responseData.put("orderList", orderList); - responseData.put("totalAmount", totalAmount.toString()); - return AppletControllerUtil.appletSuccess(responseData); } - - } catch (Exception e) { - logger.error("创建订单异常:", e); - return AppletControllerUtil.appletWarning("创建订单失败:" + e.getMessage()); - } -} - -/** - * 尾款结算 - */ -@PostMapping("api/service/order/pay/total/price") -public AjaxResult apiServiceOrderPayTotalPprice(@RequestBody Map params, HttpServletRequest request) { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证必要参数 - if (params == null || params.get("order_id") == null || params.get("worker_id") == null) { - return AppletControllerUtil.appletWarning("参数不能为空"); - } - Long worker_id = Long.valueOf(params.get("worker_id").toString()); - String order_id = params.get("order_id").toString(); - Order order = orderService.selectOrderByOrderId(order_id); - // 2. 查询订单日志(取type=5评估报价,或最新一条) - List logList = orderLogService.selectOrderLogByOrderId(order.getOrderId()); - OrderLog log = null; - for (OrderLog l : logList) { - if (l.getType() != null && l.getType().intValue() == 5) { - log = l; - break; - } - } - if (log == null && !logList.isEmpty()) { - log = logList.get(0); - } - if (log == null) { - return AppletControllerUtil.appletWarning("未找到订单日志"); - } -if (params.get("coupon_id")!= null) { - String coupon_id = params.get("coupon_id").toString(); - if (coupon_id != null && !coupon_id.isEmpty()) { - CouponUser couponUser = couponUserService.selectCouponUserById(Long.valueOf(coupon_id)); - if (couponUser == null && couponUser.getStatus() != 1) { - return AppletControllerUtil.appletWarning("优惠券已被使用,或优惠券不存在"); - } - OrderLog orderLogQery = new OrderLog(); - orderLogQery.setOrderId(order.getOrderId()); - orderLogQery.setType(new BigDecimal(5)); - orderLogQery.setWorkerId(worker_id); - OrderLog orderLognew = orderLogService.selectOneByOidTypeWorkerIdPaid(orderLogQery); - if (orderLognew != null) { - orderLognew.setCouponId(couponUser.getCouponId()); - orderLognew.setDeduction(new BigDecimal(couponUser.getCouponPrice())); - orderLogService.updateOrderLog(orderLognew); - order.setCouponId(couponUser.getCouponId()); - order.setDeduction(new BigDecimal(couponUser.getCouponPrice())); - orderService.updateOrder(order); - } - - - } -} - - - Map payResult = wechatPayUtil.createBatchOrderAndPay( - user.getOpenid(), - String.valueOf(order_id), - new BigDecimal(0.01), - 1, - "https://7ce20b15.r5.cpolar.xyz/api/order/amount/pay/notify"); - if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { - Map responseData = new HashMap<>(); - responseData.put("mainOrderId", order_id); - //responseData.put("orderList", orderList); - responseData.put("totalAmount", log.getPrice()); - responseData.put("prepayId", payResult.get("prepayId")); - // 直接合并所有支付参数 - responseData.putAll(payResult); - return AppletControllerUtil.appletSuccess(responseData); - } else { - String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); - } - - -} - -/** - * 上门费支付接口 - */ - -@PostMapping("api/service/order/pay_fee") -public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, HttpServletRequest request) { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证必要参数 - if (params == null || params.get("id") == null) { - return AppletControllerUtil.appletWarning("参数不能为空"); - } - Long orderId = Long.valueOf(params.get("id").toString()); - OrderLog orderLog = orderLogService.selectOrderLogById(orderId); - if (orderLog != null) { - Map payResult = wechatPayUtil.createBatchOrderAndPay( user.getOpenid(), - String.valueOf(orderLog.getId()), + String.valueOf(order_id), new BigDecimal(0.01), 1, - "https://7ce20b15.r5.cpolar.xyz/api/door/fee/pay/notify"); + "https://7ce20b15.r5.cpolar.xyz/api/order/amount/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); - responseData.put("mainOrderId", String.valueOf(orderLog.getId())); + responseData.put("mainOrderId", order_id); //responseData.put("orderList", orderList); - responseData.put("totalAmount", orderLog.getPrice()); + responseData.put("totalAmount", log.getPrice()); responseData.put("prepayId", payResult.get("prepayId")); // 直接合并所有支付参数 responseData.putAll(payResult); @@ -4560,106 +3587,42 @@ public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); } - } + /** + * 上门费支付接口 + */ - - return AppletControllerUtil.appletWarning("支付失败"); -} - - -/** - * 定金支付接口 - */ - -@PostMapping("/api/service/order/pay/deposit") -public AjaxResult apiServiceOrderPaydeposit(@RequestBody Map params, HttpServletRequest request) { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证必要参数 - if (params == null || params.get("id") == null) { - return AppletControllerUtil.appletWarning("参数不能为空"); - } - Long orderId = Long.valueOf(params.get("id").toString()); - OrderLog orderLog = orderLogService.selectOrderLogById(orderId); - if (orderLog != null) { - - Map payResult = wechatPayUtil.createBatchOrderAndPay( - user.getOpenid(), - String.valueOf(orderLog.getId()), - new BigDecimal(0.01), - 1, - "https://7ce20b15.r5.cpolar.xyz/api/deposit/pay/notify"); - if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { - Map responseData = new HashMap<>(); - responseData.put("mainOrderId", String.valueOf(orderLog.getId())); - //responseData.put("orderList", orderList); - responseData.put("totalAmount", orderLog.getPrice()); - responseData.put("prepayId", payResult.get("prepayId")); - // 直接合并所有支付参数 - responseData.putAll(payResult); - return AppletControllerUtil.appletSuccess(responseData); - } else { - String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; - return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + @PostMapping("api/service/order/pay_fee") + public AjaxResult apiServiceOrderPayFee(@RequestBody Map params, HttpServletRequest request) { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); } - - } - - - return AppletControllerUtil.appletWarning("支付失败"); -} - - -/** - * 单个商品支付 - */ -@PostMapping("api/goods/order/once_pay") -public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, HttpServletRequest request) { - // 1. 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("用户未登录或token无效"); - } - - // 2. 获取用户信息 - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - // 3. 验证必要参数 - if (params == null || params.get("id") == null) { - return AppletControllerUtil.appletWarning("参数不能为空"); - } - Long orderId = Long.valueOf(params.get("id").toString()); - GoodsOrder goodsOrder = goodsOrderService.selectGoodsOrderById(orderId); - logger.info("orderId:{}", orderId); - logger.info("goodsOrder:{}", goodsOrder); - if (goodsOrder != null) { - goodsOrder.setMainOrderId(GenerateCustomCode.generCreateOrder("WXB")); - int flg = goodsOrderService.updateGoodsOrder(goodsOrder); - //修改成功就开始走支付功能 - if (flg > 0) { - goodsOrder.setMainOrderId(goodsOrder.getMainOrderId()); - Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), goodsOrder.getMainOrderId(), new BigDecimal(0.01), 1, "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 3. 验证必要参数 + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletWarning("参数不能为空"); + } + Long orderId = Long.valueOf(params.get("id").toString()); + OrderLog orderLog = orderLogService.selectOrderLogById(orderId); + if (orderLog != null) { + Map payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + String.valueOf(orderLog.getId()), + new BigDecimal(0.01), + 1, + "https://7ce20b15.r5.cpolar.xyz/api/door/fee/pay/notify"); if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { Map responseData = new HashMap<>(); - responseData.put("mainOrderId", goodsOrder.getMainOrderId()); + responseData.put("mainOrderId", String.valueOf(orderLog.getId())); //responseData.put("orderList", orderList); - responseData.put("totalAmount", goodsOrder.getTotalPrice()); + responseData.put("totalAmount", orderLog.getPrice()); responseData.put("prepayId", payResult.get("prepayId")); // 直接合并所有支付参数 responseData.putAll(payResult); @@ -4670,33 +3633,58 @@ public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, } } - - + return AppletControllerUtil.appletWarning("支付失败"); } - return AppletControllerUtil.appletWarning("支付失败"); -} - -/** - * 生成订单号 - * 格式:年月日时分秒 + 4位随机数 - */ -private String generateOrderId() { - SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); - String timeStr = sdf.format(new Date()); - int random = (int) ((Math.random() * 9 + 1) * 1000); - return timeStr + random; -} - -/** - * 取消服务订单 - * - * @param params 请求参数,包含订单ID和取消原因 - * @param request HTTP请求对象 - * @return 返回取消结果 - */ -@PostMapping("/api/service/cancel/order") -public AjaxResult cancelServiceOrder(@RequestBody Map params, HttpServletRequest request) { - try { + /** + * 定金支付接口 + */ + @PostMapping("/api/service/order/pay/deposit") + public AjaxResult apiServiceOrderPaydeposit(@RequestBody Map params, HttpServletRequest request) { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 3. 验证必要参数 + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletWarning("参数不能为空"); + } + Long orderId = Long.valueOf(params.get("id").toString()); + OrderLog orderLog = orderLogService.selectOrderLogById(orderId); + if (orderLog != null) { + Map payResult = wechatPayUtil.createBatchOrderAndPay( + user.getOpenid(), + String.valueOf(orderLog.getId()), + new BigDecimal(0.01), + 1, + "https://7ce20b15.r5.cpolar.xyz/api/deposit/pay/notify"); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("mainOrderId", String.valueOf(orderLog.getId())); + //responseData.put("orderList", orderList); + responseData.put("totalAmount", orderLog.getPrice()); + responseData.put("prepayId", payResult.get("prepayId")); + // 直接合并所有支付参数 + responseData.putAll(payResult); + return AppletControllerUtil.appletSuccess(responseData); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } + return AppletControllerUtil.appletWarning("支付失败"); + } + /** + * 单个商品支付 + */ + @PostMapping("api/goods/order/once_pay") + public AjaxResult apiGoodsOrderOncePay(@RequestBody Map params, HttpServletRequest request) { // 1. 验证用户登录状态 String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); @@ -4711,986 +3699,633 @@ public AjaxResult cancelServiceOrder(@RequestBody Map params, Ht } // 3. 验证必要参数 - if (params == null || params.get("id") == null || params.get("content") == null) { + if (params == null || params.get("id") == null) { return AppletControllerUtil.appletWarning("参数不能为空"); } Long orderId = Long.valueOf(params.get("id").toString()); - String cancelReason = params.get("content").toString(); - - // 4. 查询订单信息 - Order orderQuery = new Order(); - orderQuery.setId(orderId); - orderQuery.setUid(user.getId()); // 确保是用户自己的订单 - List orders = orderService.selectOrderList(orderQuery); - - if (orders == null || orders.isEmpty()) { - return AppletControllerUtil.appletWarning("订单不存在"); + GoodsOrder goodsOrder = goodsOrderService.selectGoodsOrderById(orderId); + logger.info("orderId:{}", orderId); + logger.info("goodsOrder:{}", goodsOrder); + if (goodsOrder != null) { + goodsOrder.setMainOrderId(GenerateCustomCode.generCreateOrder("WXB")); + int flg = goodsOrderService.updateGoodsOrder(goodsOrder); + //修改成功就开始走支付功能 + if (flg > 0) { + goodsOrder.setMainOrderId(goodsOrder.getMainOrderId()); + Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), goodsOrder.getMainOrderId(), new BigDecimal(0.01), 1, "https://7ce20b15.r5.cpolar.xyz/api/goods/pay/notify"); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("mainOrderId", goodsOrder.getMainOrderId()); + //responseData.put("orderList", orderList); + responseData.put("totalAmount", goodsOrder.getTotalPrice()); + responseData.put("prepayId", payResult.get("prepayId")); + // 直接合并所有支付参数 + responseData.putAll(payResult); + return AppletControllerUtil.appletSuccess(responseData); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } } - Order order = orders.get(0); - - // 5. 验证订单状态是否可以取消 - if (order.getStatus() != 1L) { - return AppletControllerUtil.appletWarning("当前订单状态不可取消"); - } - - // 6. 更新订单状态为已取消(5) - Order updateOrder = new Order(); - updateOrder.setId(orderId); - updateOrder.setStatus(5L); - int result = orderService.updateOrder(updateOrder); - - if (result > 0) { - // 7. 添加订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(orderId); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("订单取消"); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("name", "用户取消订单,原因:" + cancelReason); - orderLog.setType(new BigDecimal(9.0)); - orderLog.setContent(jsonObject.toString()); - orderLogService.insertOrderLog(orderLog); - - return AppletControllerUtil.appletSuccess("取消成功"); - } else { - return AppletControllerUtil.appletWarning("取消失败,请稍后重试"); - } - - } catch (Exception e) { - return AppletControllerUtil.appletWarning("取消失败:" + e.getMessage()); + return AppletControllerUtil.appletWarning("支付失败"); } -} -/** - * 师傅接单接口 - * 参考OrderController+OrderUtil+OrderLogHandler的json_status=2分支 - */ -@GetMapping("/api/worker/accept/order/{id}") -public AjaxResult workerAcceptOrder(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 1. 校验token并获取师傅信息 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users worker = (Users) userValidation.get("user"); - if (worker == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 2. 查询订单 - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - // 3. 仅允许待服务状态接单 - if (order.getStatus() == null || order.getStatus() != 2L) { - return AppletControllerUtil.appletWarning("当前订单状态不可接单"); - } - // 4. 设置接单相关字段 - order.setWorkerId(worker.getId()); - order.setWorkerPhone(worker.getPhone()); - order.setIsPause(1); // 1:未暂停 - order.setReceiveType(3L); // 3:平台派单 - order.setReceiveTime(new Date()); - order.setIsAccept(1); // 1:已接单 - order.setJsonStatus(2); // 服务进度:2=接单 - order.setStatus(2l); - order.setLogStatus(9); - JSONObject json = new JSONObject(); - json.put("type", 1); - order.setLogJson(json.toJSONString()); - orderService.updateOrder(order); + /** + * 取消服务订单 + * + * @param params 请求参数,包含订单ID和取消原因 + * @param request HTTP请求对象 + * @return 返回取消结果 + */ + @PostMapping("/api/service/cancel/order") + public AjaxResult cancelServiceOrder(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } - // 5. 写入日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setTitle("师傅接单"); - orderLog.setType(new BigDecimal(2.0)); - JSONObject js = new JSONObject(); - js.put("name", "同意系统配单"); - orderLog.setContent(js.toJSONString()); - orderLog.setWorkerId(order.getWorkerId()); - orderLog.setWorkerLogId(order.getWorkerId()); - orderLogService.insertOrderLog(orderLog); + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 验证必要参数 + if (params == null || params.get("id") == null || params.get("content") == null) { + return AppletControllerUtil.appletWarning("参数不能为空"); + } + Long orderId = Long.valueOf(params.get("id").toString()); + String cancelReason = params.get("content").toString(); + + // 4. 查询订单信息 + Order orderQuery = new Order(); + orderQuery.setId(orderId); + orderQuery.setUid(user.getId()); // 确保是用户自己的订单 + List orders = orderService.selectOrderList(orderQuery); + + if (orders == null || orders.isEmpty()) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + Order order = orders.get(0); + + // 5. 验证订单状态是否可以取消 + if (order.getStatus() != 1L) { + return AppletControllerUtil.appletWarning("当前订单状态不可取消"); + } + + // 6. 更新订单状态为已取消(5) + Order updateOrder = new Order(); + updateOrder.setId(orderId); + updateOrder.setStatus(5L); + int result = orderService.updateOrder(updateOrder); + if (result > 0) { + // 7. 添加订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(orderId); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("订单取消"); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", "用户取消订单,原因:" + cancelReason); + orderLog.setType(new BigDecimal(9.0)); + orderLog.setContent(jsonObject.toString()); + orderLogService.insertOrderLog(orderLog); + return AppletControllerUtil.appletSuccess("取消成功"); + } else { + return AppletControllerUtil.appletWarning("取消失败,请稍后重试"); + } + } catch (Exception e) { + return AppletControllerUtil.appletWarning("取消失败:" + e.getMessage()); + } + } + /** + * 师傅接单接口 + * 参考OrderController+OrderUtil+OrderLogHandler的json_status=2分支 + */ + @GetMapping("/api/worker/accept/order/{id}") + public AjaxResult workerAcceptOrder(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 1. 校验token并获取师傅信息 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users worker = (Users) userValidation.get("user"); + if (worker == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 查询订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + // 3. 仅允许待服务状态接单 + if (order.getStatus() == null || order.getStatus() != 2L) { + return AppletControllerUtil.appletWarning("当前订单状态不可接单"); + } + // 4. 设置接单相关字段 + order.setWorkerId(worker.getId()); + order.setWorkerPhone(worker.getPhone()); + order.setIsPause(1); // 1:未暂停 + order.setReceiveType(3L); // 3:平台派单 + order.setReceiveTime(new Date()); + order.setIsAccept(1); // 1:已接单 + order.setJsonStatus(2); // 服务进度:2=接单 + order.setStatus(2l); + order.setLogStatus(9); + JSONObject json = new JSONObject(); + json.put("type", 1); + order.setLogJson(json.toJSONString()); + orderService.updateOrder(order); + + // 5. 写入日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setTitle("师傅接单"); + orderLog.setType(new BigDecimal(2.0)); + JSONObject js = new JSONObject(); + js.put("name", "同意系统配单"); + orderLog.setContent(js.toJSONString()); + orderLog.setWorkerId(order.getWorkerId()); + orderLog.setWorkerLogId(order.getWorkerId()); + orderLogService.insertOrderLog(orderLog); // OrderUtil orderUtil = new OrderUtil(); // orderUtil.SaveOrderLog(order); - //绑定号码 - Map bindmap = OrderBindWorkerUtil.getOrderBindWorker(order.getId()); - //发送微信推送通知客户师傅已接单 - - - // 6. 返回成功 - return AjaxResult.success("接单成功"); - } catch (Exception e) { - return AppletControllerUtil.appletError("师傅接单失败:" + e.getMessage()); + //绑定号码 + Map bindmap = OrderBindWorkerUtil.getOrderBindWorker(order.getId()); + //发送微信推送通知客户师傅已接单 + // 6. 返回成功 + return AjaxResult.success("接单成功"); + } catch (Exception e) { + return AppletControllerUtil.appletError("师傅接单失败:" + e.getMessage()); + } } -} + /** + * 师傅端订单列表接口 + * 查询worker_id为当前师傅的订单,支持状态和预约日期筛选 + * + * @param params {"limit":10,"page":1,"status":0,"day":""} + * @param request HttpServletRequest + * @return AjaxResult 带分页的订单列表,结构与json.txt一致 + */ + @PostMapping("/api/worker/order/lst") + public AjaxResult getWorkerOrderList(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验token并获取师傅信息 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 解析分页和筛选参数 + int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 10; + int status = params.get("status") != null ? Integer.parseInt(params.get("status").toString()) : 0; + String day = params.get("day") != null ? params.get("day").toString() : ""; -/** - * 师傅端订单列表接口 - * 查询worker_id为当前师傅的订单,支持状态和预约日期筛选 - * - * @param params {"limit":10,"page":1,"status":0,"day":""} - * @param request HttpServletRequest - * @return AjaxResult 带分页的订单列表,结构与json.txt一致 - */ -@PostMapping("/api/worker/order/lst") -public AjaxResult getWorkerOrderList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 校验token并获取师傅信息 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); + // 3. 构建查询条件 + Order query = new Order(); + query.setWorkerId(user.getId()); + // 状态筛选 + if (status == 2) { + query.setStatus(2L); // 待服务 + } else if (status == 3) { + query.setStatus(3L); // 服务中 + } else if (status == 4) { + query.setStatus(5L); // 已结束 + } else if (status == 5) { + query.setStatus(6L); // 已取消 + } // status=0查全部 + + PageHelper.startPage(page, limit); + List orderList = orderService.selectOrderList(query); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date today = new Date(); + Date tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); + int todayCount = 0; + int tomorrowCount = 0; + for (Order order : orderList) { + // day筛选逻辑 + if (status == 2 && day != null && !day.isEmpty()) { + String orderDay = order.getMakeTime() != null ? sdf.format(new Date(order.getMakeTime() * 1000)) : ""; + if ("today".equals(day) && !orderDay.equals(sdf.format(today))) continue; + if ("tomorrow".equals(day) && !orderDay.equals(sdf.format(tomorrow))) continue; + } + // 统计今日/明日待服务订单数 + if (order.getStatus() != null && order.getStatus() == 2L && order.getMakeTime() != null) { + String orderDay = sdf.format(new Date(order.getMakeTime() * 1000)); + if (orderDay.equals(sdf.format(today))) todayCount++; + if (orderDay.equals(sdf.format(tomorrow))) tomorrowCount++; + } + Map map = new HashMap<>(); + map.put("id", order.getId()); + map.put("type", order.getType()); + map.put("main_order_id", order.getMainOrderId()); + map.put("order_id", order.getOrderId()); + map.put("transaction_id", order.getTransactionId()); + map.put("create_type", order.getCreateType()); + map.put("create_phone", order.getCreatePhone()); + map.put("uid", order.getUid()); + map.put("product_id", order.getProductId()); + map.put("name", order.getName()); + map.put("phone", order.getPhone()); + // make_time格式化 + if (order.getMakeTime() != null && order.getMakeHour() != null) { + map.put("make_time", sdf.format(new Date(order.getMakeTime() * 1000)) + " " + order.getMakeHour()); + } else { + map.put("make_time", null); + } + map.put("make_hour", order.getMakeHour()); + map.put("num", order.getNum()); + map.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + map.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); + map.put("service_price", order.getServicePrice()); + map.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); + map.put("coupon_id", order.getCouponId()); + map.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); + map.put("pay_time", order.getPayTime()); + map.put("status", order.getStatus()); + map.put("is_pause", order.getIsPause()); + map.put("mark", order.getMark()); + map.put("address_id", order.getAddressId()); + map.put("sku", order.getSku()); + map.put("worker_id", order.getWorkerId()); + map.put("first_worker_id", order.getFirstWorkerId()); + map.put("receive_time", order.getReceiveTime()); + map.put("is_comment", order.getIsComment()); + map.put("receive_type", order.getReceiveType()); + map.put("is_accept", order.getIsAccept()); + map.put("middle_phone", order.getMiddlePhone()); + map.put("user_phone", order.getUserPhone()); + map.put("worker_phone", order.getWorkerPhone()); + map.put("address_en", order.getAddressEn()); + map.put("uid_admin", order.getUidAdmin()); + map.put("address_admin", order.getAddressAdmin()); + map.put("log_status", order.getLogStatus()); + map.put("log_json", order.getLogJson()); + map.put("json_status", order.getJsonStatus()); + map.put("log_images", order.getLogImages()); + map.put("created_at", order.getCreatedAt() != null ? sdfFull.format(order.getCreatedAt()) : null); + map.put("updated_at", order.getUpdatedAt() != null ? sdfFull.format(order.getUpdatedAt()) : null); + map.put("deleted_at", order.getDeletedAt()); + //map.put("log_type", 1.1); + // 兼容log_type + // address/address_has + UserAddress address = null; + if (order.getAddressId() != null) { + address = userAddressService.selectUserAddressById(order.getAddressId()); + } + map.put("address", address); + map.put("address_has", address); + // product + ServiceGoods product = null; + if (order.getProductId() != null) { + product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + } + if (product != null) { + Map productMap = new HashMap<>(); + productMap.put("id", product.getId()); + productMap.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); + productMap.put("title", product.getTitle()); + productMap.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); + productMap.put("sku_type", product.getSkuType()); + productMap.put("price_zn", product.getPriceZn()); + map.put("product", productMap); + } else { + map.put("product", null); + } + resultList.add(map); + } + PageInfo pageInfo = new PageInfo<>(orderList); + Map dataPage = AppletControllerUtil.buildPageResult(pageInfo, resultList, "/api/worker/order/lst"); + // 外层data结构 + Map outerData = new HashMap<>(); + outerData.put("data", dataPage); + Map totalMap = new HashMap<>(); + totalMap.put("today", todayCount); + totalMap.put("tomorrow", tomorrowCount); + outerData.put("total", totalMap); + return AjaxResult.success(outerData); + } catch (Exception e) { + return AppletControllerUtil.appletError("查询师傅订单列表失败:" + e.getMessage()); } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + /** + * 获取师傅工作台统计数据 + * 返回格式见json.txt + */ + @GetMapping("/api/worker/stat") + public AjaxResult getWorkerStat(HttpServletRequest request) { + try { + // 1. 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 查询config_one配置 + SiteConfig configQuery = new SiteConfig(); + configQuery.setName("config_one"); + List configList = siteConfigService.selectSiteConfigList(configQuery); + Object configObj = null; + if (configList != null && !configList.isEmpty()) { + String configValue = configList.get(0).getValue(); + if (configValue != null && !configValue.trim().isEmpty()) { + configObj = JSONObject.parse(configValue); + } + } + // 3. 判断今日是否签到 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String todayStr = sdf.format(new Date()); + WorkerSign signQuery = new WorkerSign(); + signQuery.setUid(String.valueOf(user.getId())); + signQuery.setTime(sdf.parse(todayStr)); + boolean signed = false; + List signList = workerSignService.selectWorkerSignList(signQuery); + if (signList != null && !signList.isEmpty()) { + signed = true; + } + // 4. 构建user数据 + Map userMap = buildUserInfoResponse(user); + // 5. 构建返回结构 + Map data = new HashMap<>(); + data.put("day_count", 0); + data.put("mouth_count", 0); + data.put("income", 0); + data.put("user", userMap); + data.put("sign", signed); + data.put("config", configObj); + Map result = new HashMap<>(); + result.put("code", 200); + result.put("msg", "OK"); + result.put("data", data); + return AjaxResult.success(result); + } catch (Exception e) { + return AppletControllerUtil.appletError("获取师傅统计数据失败:" + e.getMessage()); } - // 2. 解析分页和筛选参数 - int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 10; - int status = params.get("status") != null ? Integer.parseInt(params.get("status").toString()) : 0; - String day = params.get("day") != null ? params.get("day").toString() : ""; - - // 3. 构建查询条件 - Order query = new Order(); - query.setWorkerId(user.getId()); - // 状态筛选 - if (status == 2) { - query.setStatus(2L); // 待服务 - } else if (status == 3) { - query.setStatus(3L); // 服务中 - } else if (status == 4) { - query.setStatus(5L); // 已结束 - } else if (status == 5) { - query.setStatus(6L); // 已取消 - } // status=0查全部 - - PageHelper.startPage(page, limit); - List orderList = orderService.selectOrderList(query); - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - SimpleDateFormat sdfFull = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Date today = new Date(); - Date tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000); - int todayCount = 0; - int tomorrowCount = 0; - for (Order order : orderList) { - // day筛选逻辑 - if (status == 2 && day != null && !day.isEmpty()) { - String orderDay = order.getMakeTime() != null ? sdf.format(new Date(order.getMakeTime() * 1000)) : ""; - if ("today".equals(day) && !orderDay.equals(sdf.format(today))) continue; - if ("tomorrow".equals(day) && !orderDay.equals(sdf.format(tomorrow))) continue; + } + /** + * 师傅端订单详情接口 + * 返回结构见json.txt + */ + @GetMapping("/api/worker/order/info/{id}") + public AjaxResult getWorkerOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { + try { + // 4. 处理时间字段 + java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 1. 校验token并获取师傅信息 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); } - // 统计今日/明日待服务订单数 - if (order.getStatus() != null && order.getStatus() == 2L && order.getMakeTime() != null) { - String orderDay = sdf.format(new Date(order.getMakeTime() * 1000)); - if (orderDay.equals(sdf.format(today))) todayCount++; - if (orderDay.equals(sdf.format(tomorrow))) tomorrowCount++; + Users worker = (Users) userValidation.get("user"); + if (worker == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); } - Map map = new HashMap<>(); - map.put("id", order.getId()); - map.put("type", order.getType()); - map.put("main_order_id", order.getMainOrderId()); - map.put("order_id", order.getOrderId()); - map.put("transaction_id", order.getTransactionId()); - map.put("create_type", order.getCreateType()); - map.put("create_phone", order.getCreatePhone()); - map.put("uid", order.getUid()); - map.put("product_id", order.getProductId()); - map.put("name", order.getName()); - map.put("phone", order.getPhone()); - // make_time格式化 - if (order.getMakeTime() != null && order.getMakeHour() != null) { - map.put("make_time", sdf.format(new Date(order.getMakeTime() * 1000)) + " " + order.getMakeHour()); - } else { - map.put("make_time", null); + // 2. 查询订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); } - map.put("make_hour", order.getMakeHour()); - map.put("num", order.getNum()); - map.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); - map.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); - map.put("service_price", order.getServicePrice()); - map.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); - map.put("coupon_id", order.getCouponId()); - map.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); - map.put("pay_time", order.getPayTime()); - map.put("status", order.getStatus()); - map.put("is_pause", order.getIsPause()); - map.put("mark", order.getMark()); - map.put("address_id", order.getAddressId()); - map.put("sku", order.getSku()); - map.put("worker_id", order.getWorkerId()); - map.put("first_worker_id", order.getFirstWorkerId()); - map.put("receive_time", order.getReceiveTime()); - map.put("is_comment", order.getIsComment()); - map.put("receive_type", order.getReceiveType()); - map.put("is_accept", order.getIsAccept()); - map.put("middle_phone", order.getMiddlePhone()); - map.put("user_phone", order.getUserPhone()); - map.put("worker_phone", order.getWorkerPhone()); - map.put("address_en", order.getAddressEn()); - map.put("uid_admin", order.getUidAdmin()); - map.put("address_admin", order.getAddressAdmin()); - map.put("log_status", order.getLogStatus()); - map.put("log_json", order.getLogJson()); - map.put("json_status", order.getJsonStatus()); - map.put("log_images", order.getLogImages()); - map.put("created_at", order.getCreatedAt() != null ? sdfFull.format(order.getCreatedAt()) : null); - map.put("updated_at", order.getUpdatedAt() != null ? sdfFull.format(order.getUpdatedAt()) : null); - map.put("deleted_at", order.getDeletedAt()); - //map.put("log_type", 1.1); - // 兼容log_type - - // address/address_has + // 3. 查询用户信息 + Users user = usersService.selectUsersById(order.getUid()); + // 4. 查询地址信息 UserAddress address = null; if (order.getAddressId() != null) { address = userAddressService.selectUserAddressById(order.getAddressId()); } - map.put("address", address); - map.put("address_has", address); - // product + // 5. 查询商品信息 ServiceGoods product = null; if (order.getProductId() != null) { product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); } - if (product != null) { - Map productMap = new HashMap<>(); - productMap.put("id", product.getId()); - productMap.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); - productMap.put("title", product.getTitle()); - productMap.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); - productMap.put("sku_type", product.getSkuType()); - productMap.put("price_zn", product.getPriceZn()); - map.put("product", productMap); - } else { - map.put("product", null); - } - resultList.add(map); - } - PageInfo pageInfo = new PageInfo<>(orderList); - Map dataPage = AppletControllerUtil.buildPageResult(pageInfo, resultList, "/api/worker/order/lst"); - // 外层data结构 - Map outerData = new HashMap<>(); - outerData.put("data", dataPage); - Map totalMap = new HashMap<>(); - totalMap.put("today", todayCount); - totalMap.put("tomorrow", tomorrowCount); - outerData.put("total", totalMap); - return AjaxResult.success(outerData); - } catch (Exception e) { - return AppletControllerUtil.appletError("查询师傅订单列表失败:" + e.getMessage()); - } -} + // 6. 查询订单日志 + OrderLog logQuery = new OrderLog(); + logQuery.setOid(order.getId()); + List logList = orderLogService.selectOrderLogList(logQuery); + List> logArr = new ArrayList<>(); + for (OrderLog log : logList) { + Map logMap = new HashMap<>(); + logMap.put("id", log.getId()); + logMap.put("oid", log.getOid()); + logMap.put("order_id", log.getOrderId()); + logMap.put("log_order_id", log.getLogOrderId()); + logMap.put("title", log.getTitle()); + logMap.put("type", log.getType()); + // content字段为json字符串,需转为对象 + Object contentObj = null; + try { + if (log.getContent() != null) { + contentObj = JSONObject.parse(log.getContent()); + } + } catch (Exception e) { -/** - * 获取师傅工作台统计数据 - * 返回格式见json.txt - */ -@GetMapping("/api/worker/stat") -public AjaxResult getWorkerStat(HttpServletRequest request) { - try { - // 1. 校验token并获取用户 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 2. 查询config_one配置 - SiteConfig configQuery = new SiteConfig(); - configQuery.setName("config_one"); - List configList = siteConfigService.selectSiteConfigList(configQuery); - Object configObj = null; - if (configList != null && !configList.isEmpty()) { - String configValue = configList.get(0).getValue(); - if (configValue != null && !configValue.trim().isEmpty()) { - configObj = JSONObject.parse(configValue); - } - } - // 3. 判断今日是否签到 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - String todayStr = sdf.format(new Date()); - WorkerSign signQuery = new WorkerSign(); - signQuery.setUid(String.valueOf(user.getId())); - signQuery.setTime(sdf.parse(todayStr)); - boolean signed = false; - List signList = workerSignService.selectWorkerSignList(signQuery); - if (signList != null && !signList.isEmpty()) { - signed = true; - } - // 4. 构建user数据 - Map userMap = buildUserInfoResponse(user); - // 5. 构建返回结构 - Map data = new HashMap<>(); - data.put("day_count", 0); - data.put("mouth_count", 0); - data.put("income", 0); - data.put("user", userMap); - data.put("sign", signed); - data.put("config", configObj); - Map result = new HashMap<>(); - result.put("code", 200); - result.put("msg", "OK"); - result.put("data", data); - return AjaxResult.success(result); - } catch (Exception e) { - return AppletControllerUtil.appletError("获取师傅统计数据失败:" + e.getMessage()); - } -} + if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { + contentObj = JSONArray.parseArray(log.getContent()); + } else { + contentObj = log.getContent(); + } -/** - * 师傅端订单详情接口 - * 返回结构见json.txt - */ -@GetMapping("/api/worker/order/info/{id}") -public AjaxResult getWorkerOrderInfo(@PathVariable("id") Long id, HttpServletRequest request) { - try { - // 4. 处理时间字段 - java.text.SimpleDateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // 1. 校验token并获取师傅信息 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users worker = (Users) userValidation.get("user"); - if (worker == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 2. 查询订单 - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - // 3. 查询用户信息 - Users user = usersService.selectUsersById(order.getUid()); - // 4. 查询地址信息 - UserAddress address = null; - if (order.getAddressId() != null) { - address = userAddressService.selectUserAddressById(order.getAddressId()); - } - // 5. 查询商品信息 - ServiceGoods product = null; - if (order.getProductId() != null) { - product = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - } - // 6. 查询订单日志 - OrderLog logQuery = new OrderLog(); - logQuery.setOid(order.getId()); - List logList = orderLogService.selectOrderLogList(logQuery); - List> logArr = new ArrayList<>(); - for (OrderLog log : logList) { - Map logMap = new HashMap<>(); - logMap.put("id", log.getId()); - logMap.put("oid", log.getOid()); - logMap.put("order_id", log.getOrderId()); - logMap.put("log_order_id", log.getLogOrderId()); - logMap.put("title", log.getTitle()); - logMap.put("type", log.getType()); - // content字段为json字符串,需转为对象 - Object contentObj = null; - try { - if (log.getContent() != null) { - contentObj = JSONObject.parse(log.getContent()); } - } catch (Exception e) { - - if (AppletControllerUtil.canParseToJSONArray(log.getContent())) { - contentObj = JSONArray.parseArray(log.getContent()); - } else { - contentObj = log.getContent(); - } - + logMap.put("content", contentObj); + logMap.put("deposit", log.getDeposit()); + logMap.put("dep_paid", log.getDepPaid()); + logMap.put("dep_pay_time", log.getDepPayTime()); + logMap.put("dep_log_id", log.getDepLogId()); + logMap.put("price", log.getPrice()); + logMap.put("paid", log.getPaid()); + logMap.put("pay_time", log.getPayTime()); + logMap.put("log_id", log.getLogId()); + logMap.put("worker_id", log.getWorkerId()); + logMap.put("first_worker_id", log.getFirstWorkerId()); + logMap.put("give_up", log.getGiveUp()); + logMap.put("worker_cost", log.getWorkerCost()); + logMap.put("reduction_price", log.getReductionPrice()); + logMap.put("is_pause", log.getIsPause()); + logMap.put("coupon_id", log.getCouponId()); + logMap.put("deduction", log.getDeduction()); + logMap.put("worker_log_id", log.getWorkerLogId()); + logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); + logMap.put("updated_at", log.getUpdatedAt() != null ? dateFormat.format(log.getUpdatedAt()) : null); + logMap.put("deleted_at", log.getDeletedAt()); + logArr.add(logMap); } - logMap.put("content", contentObj); - logMap.put("deposit", log.getDeposit()); - logMap.put("dep_paid", log.getDepPaid()); - logMap.put("dep_pay_time", log.getDepPayTime()); - logMap.put("dep_log_id", log.getDepLogId()); - logMap.put("price", log.getPrice()); - logMap.put("paid", log.getPaid()); - logMap.put("pay_time", log.getPayTime()); - logMap.put("log_id", log.getLogId()); - logMap.put("worker_id", log.getWorkerId()); - logMap.put("first_worker_id", log.getFirstWorkerId()); - logMap.put("give_up", log.getGiveUp()); - logMap.put("worker_cost", log.getWorkerCost()); - logMap.put("reduction_price", log.getReductionPrice()); - logMap.put("is_pause", log.getIsPause()); - logMap.put("coupon_id", log.getCouponId()); - logMap.put("deduction", log.getDeduction()); - logMap.put("worker_log_id", log.getWorkerLogId()); - logMap.put("created_at", log.getCreatedAt() != null ? dateFormat.format(log.getCreatedAt()) : null); - logMap.put("updated_at", log.getUpdatedAt() != null ? dateFormat.format(log.getUpdatedAt()) : null); - logMap.put("deleted_at", log.getDeletedAt()); - logArr.add(logMap); - } - // 7. 构建返回数据 - Map data = new HashMap<>(); - data.put("id", order.getId()); - data.put("type", order.getType()); - data.put("main_order_id", order.getMainOrderId()); - data.put("order_id", order.getOrderId()); - data.put("transaction_id", order.getTransactionId()); - data.put("create_type", order.getCreateType()); - data.put("create_phone", order.getCreatePhone()); - data.put("uid", order.getUid()); - data.put("product_id", order.getProductId()); - data.put("name", order.getName()); - data.put("phone", order.getPhone()); - data.put("address", address); - data.put("make_time", AppletControllerUtil.timeStamp2Date(order)); - data.put("make_hour", order.getMakeHour()); - data.put("num", order.getNum()); - data.put("total_price", order.getTotalPrice()); - data.put("good_price", order.getGoodPrice()); - data.put("service_price", order.getServicePrice()); - data.put("pay_price", order.getPayPrice()); - data.put("coupon_id", order.getCouponId()); - data.put("deduction", order.getDeduction()); - data.put("pay_time", order.getPayTime()); - data.put("status", order.getStatus()); - data.put("is_pause", order.getIsPause()); - data.put("mark", order.getMark()); - data.put("address_id", order.getAddressId()); - data.put("sku", order.getSku()); - data.put("worker_id", order.getWorkerId()); - data.put("first_worker_id", order.getFirstWorkerId()); - data.put("receive_time", order.getReceiveTime() != null ? dateFormat.format(order.getReceiveTime()) : null); - data.put("is_comment", order.getIsComment()); - data.put("receive_type", order.getReceiveType()); - data.put("is_accept", order.getIsAccept()); - data.put("middle_phone", order.getMiddlePhone()); - data.put("user_phone", order.getUserPhone()); - data.put("worker_phone", order.getWorkerPhone()); - data.put("address_en", order.getAddressEn()); - data.put("uid_admin", order.getUidAdmin()); - data.put("address_admin", order.getAddressAdmin()); - data.put("log_status", order.getLogStatus()); - data.put("log_json", order.getLogJson()); - data.put("json_status", order.getJsonStatus()); - data.put("log_images", order.getLogImages()); - data.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); - data.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); - data.put("deleted_at", order.getDeletedAt() != null ? dateFormat.format(order.getDeletedAt()) : null); - data.put("phone_xx", order.getPhone()); // 可脱敏处理 - data.put("user", user); - data.put("product", product); - if (order.getFileData() != null){ - data.put("file_data", JSON.parseArray(order.getFileData())); - }else{ - data.put("file_data", null); - } - data.put("log", logArr); - return AjaxResult.success(data); - } catch (Exception e) { - return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); - } -} - - -/** - * 支付尾款回调到页面的数据 - * 返回结构见json.txt - */ -@PostMapping("/api/service/order/pay/total/price/info") -public AjaxResult getOrderPayLastInfo(@RequestBody Map params) { - try { - String orderId = (String) params.get("order_id"); - if (StringUtils.isEmpty(orderId)) { - return AppletControllerUtil.appletWarning("订单号不能为空"); - } - - // 1. 查询订单 - Order order = orderService.selectOrderByOrderId(orderId); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - - // 2. 查询订单日志(取type=5评估报价,或最新一条) - List logList = orderLogService.selectOrderLogByOrderId(orderId); - OrderLog log = null; - for (OrderLog l : logList) { - if (l.getType() != null && l.getType().intValue() == 5) { - log = l; - break; + // 7. 构建返回数据 + Map data = new HashMap<>(); + data.put("id", order.getId()); + data.put("type", order.getType()); + data.put("main_order_id", order.getMainOrderId()); + data.put("order_id", order.getOrderId()); + data.put("transaction_id", order.getTransactionId()); + data.put("create_type", order.getCreateType()); + data.put("create_phone", order.getCreatePhone()); + data.put("uid", order.getUid()); + data.put("product_id", order.getProductId()); + data.put("name", order.getName()); + data.put("phone", order.getPhone()); + data.put("address", address); + data.put("make_time", AppletControllerUtil.timeStamp2Date(order)); + data.put("make_hour", order.getMakeHour()); + data.put("num", order.getNum()); + data.put("total_price", order.getTotalPrice()); + data.put("good_price", order.getGoodPrice()); + data.put("service_price", order.getServicePrice()); + data.put("pay_price", order.getPayPrice()); + data.put("coupon_id", order.getCouponId()); + data.put("deduction", order.getDeduction()); + data.put("pay_time", order.getPayTime()); + data.put("status", order.getStatus()); + data.put("is_pause", order.getIsPause()); + data.put("mark", order.getMark()); + data.put("address_id", order.getAddressId()); + data.put("sku", order.getSku()); + data.put("worker_id", order.getWorkerId()); + data.put("first_worker_id", order.getFirstWorkerId()); + data.put("receive_time", order.getReceiveTime() != null ? dateFormat.format(order.getReceiveTime()) : null); + data.put("is_comment", order.getIsComment()); + data.put("receive_type", order.getReceiveType()); + data.put("is_accept", order.getIsAccept()); + data.put("middle_phone", order.getMiddlePhone()); + data.put("user_phone", order.getUserPhone()); + data.put("worker_phone", order.getWorkerPhone()); + data.put("address_en", order.getAddressEn()); + data.put("uid_admin", order.getUidAdmin()); + data.put("address_admin", order.getAddressAdmin()); + data.put("log_status", order.getLogStatus()); + data.put("log_json", order.getLogJson()); + data.put("json_status", order.getJsonStatus()); + data.put("log_images", order.getLogImages()); + data.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); + data.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); + data.put("deleted_at", order.getDeletedAt() != null ? dateFormat.format(order.getDeletedAt()) : null); + data.put("phone_xx", order.getPhone()); // 可脱敏处理 + data.put("user", user); + data.put("product", product); + if (order.getFileData() != null){ + data.put("file_data", JSON.parseArray(order.getFileData())); + }else{ + data.put("file_data", null); } - } - if (log == null && !logList.isEmpty()) { - log = logList.get(0); - } - if (log == null) { - return AppletControllerUtil.appletWarning("未找到订单日志"); - } - - // 3. 组装content字段 - JSONObject contentJson; - try { - contentJson = JSONObject.parseObject(log.getContent()); + data.put("log", logArr); + return AjaxResult.success(data); } catch (Exception e) { - contentJson = new JSONObject(); + return AppletControllerUtil.appletError("查询师傅订单详情失败:" + e.getMessage()); } - - // 4. 组装返回数据 - Map data = new HashMap<>(); - data.put("id", log.getId()); - data.put("oid", log.getOid()); - data.put("order_id", log.getOrderId()); - data.put("log_order_id", log.getLogOrderId()); - data.put("title", log.getTitle()); - data.put("type", log.getType() != null ? log.getType().intValue() : null); - data.put("content", contentJson); - data.put("deposit", log.getDeposit() != null ? log.getDeposit().toString() : "0.00"); - data.put("dep_paid", log.getDepPaid()); - data.put("dep_pay_time", log.getDepPayTime()); - data.put("dep_log_id", log.getDepLogId()); - data.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); - data.put("paid", log.getPaid()); - data.put("pay_time", log.getPayTime() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(log.getPayTime() * 1000)) : null); - data.put("log_id", log.getLogId()); - data.put("worker_id", log.getWorkerId()); - data.put("first_worker_id", log.getFirstWorkerId()); - data.put("give_up", log.getGiveUp()); - data.put("worker_cost", log.getWorkerCost()); - data.put("reduction_price", log.getReductionPrice() != null ? log.getReductionPrice().toString() : "0.00"); - data.put("is_pause", log.getIsPause()); - data.put("coupon_id", log.getCouponId()); - data.put("deduction", log.getDeduction()); - data.put("worker_log_id", log.getWorkerLogId()); - data.put("created_at", log.getCreatedAt() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(log.getCreatedAt()) : null); - data.put("updated_at", log.getUpdatedAt() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(log.getUpdatedAt()) : null); - data.put("deleted_at", log.getDeletedAt()); - - return AppletControllerUtil.appletSuccess(data); - } catch (Exception e) { - return AppletControllerUtil.appletWarning("查询失败:" + e.getMessage()); } -} - - -/** - * 师傅列表接口 - * 返回结构见json.txt - */ -@PostMapping("/api/worker/user/lst") -public AjaxResult getWorkerUserList(@RequestBody Map params) { - try { - int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; - String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : null; - // 查询type=2的师傅 - Users query = new Users(); - query.setType("2"); - if (keywords != null && !keywords.isEmpty()) { - query.setName(keywords); - } - PageHelper.startPage(page, limit); - List userList = usersService.selectUsersList(query); - PageInfo pageInfo = new PageInfo<>(userList); - List> resultList = new ArrayList<>(); - for (Users user : userList) { - Map map = new HashMap<>(); - map.put("id", user.getId()); - map.put("name", user.getName()); - // 头像处理 - String avatar = user.getAvatar(); - if (avatar != null && !avatar.isEmpty()) { - if (!avatar.startsWith("http")) { - avatar = "https://img.huafurenjia.cn/" + avatar.replaceFirst("^/+", ""); - } - } else { - avatar = "https://img.huafurenjia.cn//default/user_avatar.jpeg"; + /** + * 支付尾款回调到页面的数据 + */ + @PostMapping("/api/service/order/pay/total/price/info") + public AjaxResult getOrderPayLastInfo(@RequestBody Map params) { + try { + String orderId = (String) params.get("order_id"); + if (StringUtils.isEmpty(orderId)) { + return AppletControllerUtil.appletWarning("订单号不能为空"); } - map.put("avatar", avatar); - map.put("phone", user.getPhone()); - map.put("service_city_ids", user.getServiceCityIds()); - map.put("skill_ids", user.getSkillIds()); - // city名称数组 - List cityNames = new ArrayList<>(); - List cityIds = AppletControllerUtil.parseStringToList(user.getServiceCityIds()); - for (String cityIdStr : cityIds) { - try { - if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { - Integer cityId = Integer.valueOf(cityIdStr); - DiyCity city = diyCityService.selectDiyCityById(cityId); - if (city != null && city.getTitle() != null) { - cityNames.add(city.getTitle()); - } - } - } catch (Exception ignore) { - } + // 1. 查询订单 + Order order = orderService.selectOrderByOrderId(orderId); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); } - map.put("city", cityNames); - // skill名称数组 - List skillNames = new ArrayList<>(); - List skillIds = AppletControllerUtil.parseStringToList(user.getSkillIds()); - for (String skillIdStr : skillIds) { - try { - if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { - Long skillId = Long.valueOf(skillIdStr); - SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); - if (skill != null && skill.getTitle() != null) { - skillNames.add(skill.getTitle()); - } - } - } catch (Exception ignore) { - } - } - map.put("skill", skillNames); - resultList.add(map); - } - // 构建分页数据 - Map data = new HashMap<>(); - data.put("current_page", pageInfo.getPageNum()); - data.put("data", resultList); - data.put("first_page_url", "https://www.huafurenjia.cn/api/worker/user/lst?page=1"); - data.put("from", pageInfo.getStartRow()); - data.put("last_page", pageInfo.getPages()); - data.put("last_page_url", "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPages()); - // 构建links - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPrePage() : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - for (int i = 1; i <= pageInfo.getPages(); i++) { - Map link = new HashMap<>(); - link.put("url", "https://www.huafurenjia.cn/api/worker/user/lst?page=" + i); - link.put("label", String.valueOf(i)); - link.put("active", i == pageInfo.getPageNum()); - links.add(link); - } - Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getNextPage() : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - data.put("links", links); - data.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getNextPage() : null); - data.put("path", "https://www.huafurenjia.cn/api/worker/user/lst"); - data.put("per_page", pageInfo.getPageSize()); - data.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPrePage() : null); - data.put("to", pageInfo.getEndRow()); - data.put("total", pageInfo.getTotal()); - return AjaxResult.success(data); - } catch (Exception e) { - return AjaxResult.error("查询师傅列表失败:" + e.getMessage()); - } -} - -/** - * 用户申请师傅接口 - */ -@PostMapping("/api/form/apply/worker") -public AjaxResult applyWorker(@RequestBody Map params, HttpServletRequest request) { - try { - // 验证用户登录状态 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 构建WorkerApply对象 - WorkerApply apply = new WorkerApply(); - apply.setUid(user.getId()); - apply.setName((String) params.getOrDefault("name", "")); - apply.setPhone((String) params.getOrDefault("phone", "")); - apply.setAddress((String) params.getOrDefault("address", "")); - apply.setCardNo((String) params.getOrDefault("card_no", "")); - // city_pid - Object cityPidObj = params.get("city_pid"); - if (cityPidObj != null) { - try { - apply.setCityPid(Long.valueOf(cityPidObj.toString())); - } catch (Exception ignore) {} - } - // city_ids - Object cityIdsObj = params.get("city_ids"); - if (cityIdsObj instanceof List) { - List cityIdsList = (List) cityIdsObj; - apply.setCityIds(cityIdsList.toString().replace(" ","")); // 存字符串如[5,7,10,11] - } else if (cityIdsObj != null) { - apply.setCityIds(cityIdsObj.toString()); - } - // skill_id - Object skillIdObj = params.get("skill_id"); - if (skillIdObj instanceof List) { - List skillIdList = (List) skillIdObj; - apply.setSkillId(skillIdList.toString().replace(" ","")); - } else if (skillIdObj != null) { - apply.setSkillId(skillIdObj.toString()); - } - // 图片相关 - apply.setSkill((String) params.getOrDefault("skill", "")); - apply.setCriminal((String) params.getOrDefault("criminal", "")); - apply.setDrive((String) params.getOrDefault("drive", "")); - apply.setEducation((String) params.getOrDefault("education", "")); - apply.setHealth((String) params.getOrDefault("health", "")); - apply.setImage((String) params.getOrDefault("image", "")); - // 其他字段可按需补充 - int result = workerApplyService.insertWorkerApply(apply); - if (result > 0) { - return AppletControllerUtil.appletSuccess("申请已提交"); - } else { - return AppletControllerUtil.appletWarning("申请提交失败,请稍后重试"); - } - } catch (Exception e) { - return AppletControllerUtil.appletError("申请失败:" + e.getMessage()); - } -} - -/** - * 师傅转单接口 - * - * @param orderId 订单ID - * @param newWorkerId 新师傅ID - * @return 操作结果 - */ -@GetMapping("/api/worker/change/order/{orderId}") -public AjaxResult changeWorkerOrder(@PathVariable("orderId") Long orderId, @RequestParam("id") Long newWorkerId) { - try { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // 1. 查询订单 - Order order = orderService.selectOrderById(orderId); - if (order == null) { - return AjaxResult.error("订单不存在"); - } - // 2. 查询新师傅信息 - Users newWorker = usersService.selectUsersById(newWorkerId); - if (newWorker == null) { - return AjaxResult.error("新师傅不存在"); - } - // 3. 查询原师傅信息 - Users oldWorker = null; - if (order.getWorkerId() != null) { - oldWorker = usersService.selectUsersById(order.getWorkerId()); - } - // 4. 修改订单的师傅id - order.setWorkerId(newWorkerId); - int updateOrder = orderService.updateOrder(order); - if (updateOrder <= 0) { - return AjaxResult.error("订单更新失败"); - } - //查询最新的订单日志 - OrderLog log = orderLogService.selectDataTheFirstNew(order.getId()); - OrderLog log1 = new OrderLog(); - log1.setOid(order.getId()); - //原订单日志下所有师傅id需更换为新的师傅id - List logList = orderLogService.selectOrderLogList(log1); - if (!logList.isEmpty()) { + // 2. 查询订单日志(取type=5评估报价,或最新一条) + List logList = orderLogService.selectOrderLogByOrderId(orderId); + OrderLog log = null; for (OrderLog l : logList) { - if (l.getWorkerId() != null) { - l.setWorkerId(newWorkerId); - orderLogService.updateOrderLog(l); + if (l.getType() != null && l.getType().intValue() == 5) { + log = l; + break; } } + if (log == null && !logList.isEmpty()) { + log = logList.get(0); + } + if (log == null) { + return AppletControllerUtil.appletWarning("未找到订单日志"); + } + // 3. 组装content字段 + JSONObject contentJson; + try { + contentJson = JSONObject.parseObject(log.getContent()); + } catch (Exception e) { + contentJson = new JSONObject(); + } + // 4. 组装返回数据 + Map data = new HashMap<>(); + data.put("id", log.getId()); + data.put("oid", log.getOid()); + data.put("order_id", log.getOrderId()); + data.put("log_order_id", log.getLogOrderId()); + data.put("title", log.getTitle()); + data.put("type", log.getType() != null ? log.getType().intValue() : null); + data.put("content", contentJson); + data.put("deposit", log.getDeposit() != null ? log.getDeposit().toString() : "0.00"); + data.put("dep_paid", log.getDepPaid()); + data.put("dep_pay_time", log.getDepPayTime()); + data.put("dep_log_id", log.getDepLogId()); + data.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); + data.put("paid", log.getPaid()); + data.put("pay_time", log.getPayTime() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(log.getPayTime() * 1000)) : null); + data.put("log_id", log.getLogId()); + data.put("worker_id", log.getWorkerId()); + data.put("first_worker_id", log.getFirstWorkerId()); + data.put("give_up", log.getGiveUp()); + data.put("worker_cost", log.getWorkerCost()); + data.put("reduction_price", log.getReductionPrice() != null ? log.getReductionPrice().toString() : "0.00"); + data.put("is_pause", log.getIsPause()); + data.put("coupon_id", log.getCouponId()); + data.put("deduction", log.getDeduction()); + data.put("worker_log_id", log.getWorkerLogId()); + data.put("created_at", log.getCreatedAt() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(log.getCreatedAt()) : null); + data.put("updated_at", log.getUpdatedAt() != null ? new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(log.getUpdatedAt()) : null); + data.put("deleted_at", log.getDeletedAt()); + return AppletControllerUtil.appletSuccess(data); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("查询失败:" + e.getMessage()); } - //如果订单状态为6就继续做 - if (log.getType().compareTo(new BigDecimal("6.0")) == 0) { - // 2. 组装日志内容为数组格式 - Map logItem = new LinkedHashMap<>(); - - JSONArray jsonArray = JSONArray.parseArray(log.getContent()); - logItem.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); - logItem.put("name", "暂停服务"); - logItem.put("image", ""); - logItem.put("reson", "由于订单师傅更换,自动暂停服务"); - logItem.put("next_time", ""); - logItem.put("type", 2); - logItem.put("date", sdf.format(new Date())); - jsonArray.add(logItem); - if (log != null) { - log.setIsPause(2); - log.setContent(jsonArray.toJSONString()); - orderLogService.updateOrderLog(log); - order.setIsPause(2); - order.setWorkerId(newWorkerId); - orderService.updateOrder(order); - } - - } else { - // 5. 插入转单日志 - OrderLog newlog = new OrderLog(); - if (log.getType().compareTo(new BigDecimal("5.0")) == 0) { - newlog.setType(new BigDecimal(6.0)); - } else { - newlog.setType(new BigDecimal(1.1)); - } - JSONObject jsonObjectnew = new JSONObject(); - jsonObjectnew.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); - jsonObjectnew.put("convert", oldWorker.getName() + "将订单转给" + newWorker.getName()); - newlog.setContent(jsonObjectnew.toJSONString()); - newlog.setOid(order.getId()); - newlog.setOrderId(order.getOrderId()); - newlog.setWorkerId(newWorkerId); - newlog.setWorkerLogId(newWorkerId); - newlog.setIsPause(2); - orderLogService.insertOrderLog(newlog); - //需要解绑原订单上原师傅和客户的虚拟号 - VoiceResponseResult resultObj = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone()); - if (resultObj.getResult().equals("000000")) { - order.setWorkerPhone(null); - order.setUserPhone(null); - order.setMiddlePhone(null); - orderService.updateOrder(order); - } - //给新师傅进行电话通知 - YunXinPhoneUtilAPI.httpsAxbTransfer(newWorker.getPhone()); - } - return AjaxResult.success("转单成功"); - } catch (Exception e) { - return AjaxResult.error("转单失败:" + e.getMessage()); } -} - -/** - * 师傅首页接口 - * 返回结构见json.txt - */ -@PostMapping("/api/worker/index") -public AjaxResult getWorkerIndex(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 校验token并获取师傅信息 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 2. 查询等级信息 - Object levelInfo = null; - String levelImg = null; - if (user.getLevel() != null) { - WorkerLevel level = workerLevelService.selectWorkerLevelById(Long.valueOf(user.getLevel())); - if (level != null) { - Map levelMap = new HashMap<>(); - levelMap.put("id", level.getId()); - levelMap.put("image", level.getImage()); - levelImg = level.getImage(); - levelMap.put("title", level.getTitle()); - levelInfo = levelMap; + /** + * 师傅列表接 + */ + @PostMapping("/api/worker/user/lst") + public AjaxResult getWorkerUserList(@RequestBody Map params) { + try { + int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + String keywords = params.get("keywords") != null ? params.get("keywords").toString().trim() : null; + // 查询type=2的师傅 + Users query = new Users(); + query.setType("2"); + if (keywords != null && !keywords.isEmpty()) { + query.setName(keywords); } - } - // 3. 查询技能数组 - List> skillArr = new ArrayList<>(); - List skillIds = AppletControllerUtil.parseStringToList(user.getSkillIds()); - for (String skillIdStr : skillIds) { - try { - if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { - Long skillId = Long.valueOf(skillIdStr); - SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); - if (skill != null) { - Map skillMap = new HashMap<>(); - skillMap.put("id", skill.getId()); - skillMap.put("title", skill.getTitle()); - skillArr.add(skillMap); - } - } - } catch (Exception ignore) { - } - } - // 4. 查询服务城市数组 - List> cityArr = new ArrayList<>(); - List cityIds = AppletControllerUtil.parseStringToList(user.getServiceCityIds()); - for (String cityIdStr : cityIds) { - try { - if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { - Integer cityId = Integer.valueOf(cityIdStr); - DiyCity city = diyCityService.selectDiyCityById(cityId); - if (city != null) { - Map cityMap = new HashMap<>(); - cityMap.put("id", city.getId()); - cityMap.put("title", city.getTitle()); - cityArr.add(cityMap); - } - } - } catch (Exception ignore) { - } - } - // 5. 统计评价 - OrderComment commentQuery = new OrderComment(); - commentQuery.setWorkerId(user.getId()); - List commentList = orderCommentService.selectOrderCommentList(commentQuery); - int one = 0, two = 0, three = 0; - for (OrderComment c : commentList) { - if (c.getNumType() != null) { - if (c.getNumType() == 1L) one++; - else if (c.getNumType() == 2L) two++; - else if (c.getNumType() == 3L) three++; - } - } - int total = commentList.size(); - Map commentStat = new HashMap<>(); - commentStat.put("one", one); - commentStat.put("two", two); - commentStat.put("three", three); - commentStat.put("total", total); - // 6. 构建user数据 - Map userMap = buildUserInfoResponse(user); - userMap.put("level_info", levelInfo); - userMap.put("skill_arr", skillArr); - userMap.put("service_city_arr", cityArr); - userMap.put("level_img", levelImg); - // 7. 处理分页和type筛选,默认参数 - int page = 1; - int limit = 15; - int type = 0; - List filteredList = new ArrayList<>(); - if (params != null) { - params = new HashMap<>(); - page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; - type = params.get("type") != null ? Integer.parseInt(params.get("type").toString()) : 0; - // 过滤type - for (OrderComment c : commentList) { - if (type == 0 || (type == 1 && c.getNumType() != null && c.getNumType() == 1L) - || (type == 2 && c.getNumType() != null && c.getNumType() == 2L) - || (type == 3 && c.getNumType() != null && c.getNumType() == 3L)) { - filteredList.add(c); - } - } - } else { - filteredList.addAll(commentList); - } - int totalCount = filteredList.size(); - int from = (page - 1) * limit; - int to = Math.min(from + limit, totalCount); - List> commentArr = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); - for (int i = from; i < to; i++) { - OrderComment c = filteredList.get(i); - Map cMap = new HashMap<>(); - cMap.put("id", c.getId()); - cMap.put("uid", c.getUid()); - cMap.put("images", c.getImages()); - cMap.put("content", c.getContent()); - cMap.put("num", c.getNum()); - cMap.put("created_at", c.getCreatedAt() != null ? sdf.format(c.getCreatedAt()) : null); - cMap.put("time", c.getCreatedAt() != null ? sdf2.format(c.getCreatedAt()) : null); - // 查询用户信息 - Map uMap = new HashMap<>(); - Users u = usersService.selectUsersById(c.getUid()); - if (u != null) { - uMap.put("id", u.getId()); - uMap.put("name", u.getName()); - String avatar = u.getAvatar(); + PageHelper.startPage(page, limit); + List userList = usersService.selectUsersList(query); + PageInfo pageInfo = new PageInfo<>(userList); + List> resultList = new ArrayList<>(); + for (Users user : userList) { + Map map = new HashMap<>(); + map.put("id", user.getId()); + map.put("name", user.getName()); + // 头像处理 + String avatar = user.getAvatar(); if (avatar != null && !avatar.isEmpty()) { if (!avatar.startsWith("http")) { avatar = "https://img.huafurenjia.cn/" + avatar.replaceFirst("^/+", ""); @@ -5698,447 +4333,819 @@ public AjaxResult getWorkerIndex(@RequestBody Map params, HttpSe } else { avatar = "https://img.huafurenjia.cn//default/user_avatar.jpeg"; } - uMap.put("avatar", avatar); + map.put("avatar", avatar); + map.put("phone", user.getPhone()); + map.put("service_city_ids", user.getServiceCityIds()); + map.put("skill_ids", user.getSkillIds()); + // city名称数组 + List cityNames = new ArrayList<>(); + List cityIds = AppletControllerUtil.parseStringToList(user.getServiceCityIds()); + for (String cityIdStr : cityIds) { + try { + if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { + Integer cityId = Integer.valueOf(cityIdStr); + DiyCity city = diyCityService.selectDiyCityById(cityId); + if (city != null && city.getTitle() != null) { + cityNames.add(city.getTitle()); + } + } + } catch (Exception ignore) { + } + } + map.put("city", cityNames); + // skill名称数组 + List skillNames = new ArrayList<>(); + List skillIds = AppletControllerUtil.parseStringToList(user.getSkillIds()); + for (String skillIdStr : skillIds) { + try { + if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { + Long skillId = Long.valueOf(skillIdStr); + SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); + if (skill != null && skill.getTitle() != null) { + skillNames.add(skill.getTitle()); + } + } + } catch (Exception ignore) { + } + } + map.put("skill", skillNames); + resultList.add(map); } - cMap.put("user", uMap); - commentArr.add(cMap); + // 构建分页数据 + Map data = new HashMap<>(); + data.put("current_page", pageInfo.getPageNum()); + data.put("data", resultList); + data.put("first_page_url", "https://www.huafurenjia.cn/api/worker/user/lst?page=1"); + data.put("from", pageInfo.getStartRow()); + data.put("last_page", pageInfo.getPages()); + data.put("last_page_url", "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPages()); + // 构建links + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + for (int i = 1; i <= pageInfo.getPages(); i++) { + Map link = new HashMap<>(); + link.put("url", "https://www.huafurenjia.cn/api/worker/user/lst?page=" + i); + link.put("label", String.valueOf(i)); + link.put("active", i == pageInfo.getPageNum()); + links.add(link); + } + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + data.put("links", links); + data.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getNextPage() : null); + data.put("path", "https://www.huafurenjia.cn/api/worker/user/lst"); + data.put("per_page", pageInfo.getPageSize()); + data.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/user/lst?page=" + pageInfo.getPrePage() : null); + data.put("to", pageInfo.getEndRow()); + data.put("total", pageInfo.getTotal()); + return AjaxResult.success(data); + } catch (Exception e) { + return AjaxResult.error("查询师傅列表失败:" + e.getMessage()); } - // 8. 构建分页结构 - Map pageData = new HashMap<>(); - pageData.put("current_page", page); - pageData.put("data", commentArr); - pageData.put("first_page_url", "https://www.huafurenjia.cn/api/worker/index?page=1"); - pageData.put("from", totalCount == 0 ? null : from + 1); - int lastPage = (int) Math.ceil((double) totalCount / limit); - pageData.put("last_page", lastPage); - pageData.put("last_page_url", "https://www.huafurenjia.cn/api/worker/index?page=" + lastPage); - // links - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", page > 1 ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page - 1) : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - for (int i = 1; i <= lastPage; i++) { - Map link = new HashMap<>(); - link.put("url", "https://www.huafurenjia.cn/api/worker/index?page=" + i); - link.put("label", String.valueOf(i)); - link.put("active", i == page); - links.add(link); - } - Map nextLink = new HashMap<>(); - nextLink.put("url", page < lastPage ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page + 1) : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - pageData.put("links", links); - pageData.put("next_page_url", page < lastPage ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page + 1) : null); - pageData.put("path", "https://www.huafurenjia.cn/api/worker/index"); - pageData.put("per_page", String.valueOf(limit)); - pageData.put("prev_page_url", page > 1 ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page - 1) : null); - pageData.put("to", totalCount == 0 ? null : to); - pageData.put("total", totalCount); - // 9. 构建最终返回结构 - Map data = new HashMap<>(); - data.put("user", userMap); - data.put("data", pageData); - data.put("comment", commentStat); - return AjaxResult.success(data); - } catch (Exception e) { - return AppletControllerUtil.appletError("获取师傅首页数据失败:" + e.getMessage()); } -} -/** - * 师傅签到日志接口 - * - * @param params {year: "2025", month: "06"} - * @param request - * @return 签到日志列表 - */ -@PostMapping("/api/worker/sign/log") -public AjaxResult getWorkerSignLog(@RequestBody Map params, HttpServletRequest request) { - try { - // 校验token并获取用户 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); + /** + * 用户申请师傅接口 + */ + @PostMapping("/api/form/apply/worker") + public AjaxResult applyWorker(@RequestBody Map params, HttpServletRequest request) { + try { + // 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 构建WorkerApply对象 + WorkerApply apply = new WorkerApply(); + apply.setUid(user.getId()); + apply.setName((String) params.getOrDefault("name", "")); + apply.setPhone((String) params.getOrDefault("phone", "")); + apply.setAddress((String) params.getOrDefault("address", "")); + apply.setCardNo((String) params.getOrDefault("card_no", "")); + // city_pid + Object cityPidObj = params.get("city_pid"); + if (cityPidObj != null) { + try { + apply.setCityPid(Long.valueOf(cityPidObj.toString())); + } catch (Exception ignore) {} + } + // city_ids + Object cityIdsObj = params.get("city_ids"); + if (cityIdsObj instanceof List) { + List cityIdsList = (List) cityIdsObj; + apply.setCityIds(cityIdsList.toString().replace(" ","")); // 存字符串如[5,7,10,11] + } else if (cityIdsObj != null) { + apply.setCityIds(cityIdsObj.toString()); + } + // skill_id + Object skillIdObj = params.get("skill_id"); + if (skillIdObj instanceof List) { + List skillIdList = (List) skillIdObj; + apply.setSkillId(skillIdList.toString().replace(" ","")); + } else if (skillIdObj != null) { + apply.setSkillId(skillIdObj.toString()); + } + // 图片相关 + apply.setSkill((String) params.getOrDefault("skill", "")); + apply.setCriminal((String) params.getOrDefault("criminal", "")); + apply.setDrive((String) params.getOrDefault("drive", "")); + apply.setEducation((String) params.getOrDefault("education", "")); + apply.setHealth((String) params.getOrDefault("health", "")); + apply.setImage((String) params.getOrDefault("image", "")); + // 其他字段可按需补充 + int result = workerApplyService.insertWorkerApply(apply); + if (result > 0) { + return AppletControllerUtil.appletSuccess("申请已提交"); + } else { + return AppletControllerUtil.appletWarning("申请提交失败,请稍后重试"); + } + } catch (Exception e) { + return AppletControllerUtil.appletError("申请失败:" + e.getMessage()); } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + /** + * 师傅转单接口 + * + * @param orderId 订单ID + * @param newWorkerId 新师傅ID + * @return 操作结果 + */ + @GetMapping("/api/worker/change/order/{orderId}") + public AjaxResult changeWorkerOrder(@PathVariable("orderId") Long orderId, @RequestParam("id") Long newWorkerId) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + // 1. 查询订单 + Order order = orderService.selectOrderById(orderId); + if (order == null) { + return AjaxResult.error("订单不存在"); + } + // 2. 查询新师傅信息 + Users newWorker = usersService.selectUsersById(newWorkerId); + if (newWorker == null) { + return AjaxResult.error("新师傅不存在"); + } + // 3. 查询原师傅信息 + Users oldWorker = null; + if (order.getWorkerId() != null) { + oldWorker = usersService.selectUsersById(order.getWorkerId()); + } + // 4. 修改订单的师傅id + order.setWorkerId(newWorkerId); + int updateOrder = orderService.updateOrder(order); + if (updateOrder <= 0) { + return AjaxResult.error("订单更新失败"); + } + //查询最新的订单日志 + OrderLog log = orderLogService.selectDataTheFirstNew(order.getId()); + OrderLog log1 = new OrderLog(); + log1.setOid(order.getId()); + //原订单日志下所有师傅id需更换为新的师傅id + List logList = orderLogService.selectOrderLogList(log1); + if (!logList.isEmpty()) { + for (OrderLog l : logList) { + if (l.getWorkerId() != null) { + l.setWorkerId(newWorkerId); + orderLogService.updateOrderLog(l); + } + } + } + //如果订单状态为6就继续做 + if (log.getType().compareTo(new BigDecimal("6.0")) == 0) { + // 2. 组装日志内容为数组格式 + Map logItem = new LinkedHashMap<>(); + JSONArray jsonArray = JSONArray.parseArray(log.getContent()); + logItem.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); + logItem.put("name", "暂停服务"); + logItem.put("image", ""); + logItem.put("reson", "由于订单师傅更换,自动暂停服务"); + logItem.put("next_time", ""); + logItem.put("type", 2); + logItem.put("date", sdf.format(new Date())); + jsonArray.add(logItem); + if (log != null) { + log.setIsPause(2); + log.setContent(jsonArray.toJSONString()); + orderLogService.updateOrderLog(log); + order.setIsPause(2); + order.setWorkerId(newWorkerId); + orderService.updateOrder(order); + } + } else { + // 5. 插入转单日志 + OrderLog newlog = new OrderLog(); + if (log.getType().compareTo(new BigDecimal("5.0")) == 0) { + newlog.setType(new BigDecimal(6.0)); + } else { + newlog.setType(new BigDecimal(1.1)); + } + JSONObject jsonObjectnew = new JSONObject(); + jsonObjectnew.put("name", "师傅" + newWorker.getName() + "将继续为您服务 不需要预约时间"); + jsonObjectnew.put("convert", oldWorker.getName() + "将订单转给" + newWorker.getName()); + newlog.setContent(jsonObjectnew.toJSONString()); + newlog.setOid(order.getId()); + newlog.setOrderId(order.getOrderId()); + newlog.setWorkerId(newWorkerId); + newlog.setWorkerLogId(newWorkerId); + newlog.setIsPause(2); + orderLogService.insertOrderLog(newlog); + //需要解绑原订单上原师傅和客户的虚拟号 + VoiceResponseResult resultObj = YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone()); + if (resultObj.getResult().equals("000000")) { + order.setWorkerPhone(null); + order.setUserPhone(null); + order.setMiddlePhone(null); + orderService.updateOrder(order); + } + //给新师傅进行电话通知 + YunXinPhoneUtilAPI.httpsAxbTransfer(newWorker.getPhone()); + } + return AjaxResult.success("转单成功"); + } catch (Exception e) { + return AjaxResult.error("转单失败:" + e.getMessage()); } - if (params == null || !params.containsKey("year") || !params.containsKey("month")) { - return AppletControllerUtil.appletWarning("参数year和month不能为空"); + } + + /** + * 师傅首页接口 + * 返回结构见json.txt + */ + @PostMapping("/api/worker/index") + public AjaxResult getWorkerIndex(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验token并获取师傅信息 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 查询等级信息 + Object levelInfo = null; + String levelImg = null; + if (user.getLevel() != null) { + WorkerLevel level = workerLevelService.selectWorkerLevelById(Long.valueOf(user.getLevel())); + if (level != null) { + Map levelMap = new HashMap<>(); + levelMap.put("id", level.getId()); + levelMap.put("image", level.getImage()); + levelImg = level.getImage(); + levelMap.put("title", level.getTitle()); + levelInfo = levelMap; + } + } + // 3. 查询技能数组 + List> skillArr = new ArrayList<>(); + List skillIds = AppletControllerUtil.parseStringToList(user.getSkillIds()); + for (String skillIdStr : skillIds) { + try { + if (skillIdStr != null && !skillIdStr.trim().isEmpty()) { + Long skillId = Long.valueOf(skillIdStr); + SiteSkill skill = siteSkillService.selectSiteSkillById(skillId); + if (skill != null) { + Map skillMap = new HashMap<>(); + skillMap.put("id", skill.getId()); + skillMap.put("title", skill.getTitle()); + skillArr.add(skillMap); + } + } + } catch (Exception ignore) { + } + } + // 4. 查询服务城市数组 + List> cityArr = new ArrayList<>(); + List cityIds = AppletControllerUtil.parseStringToList(user.getServiceCityIds()); + for (String cityIdStr : cityIds) { + try { + if (cityIdStr != null && !cityIdStr.trim().isEmpty()) { + Integer cityId = Integer.valueOf(cityIdStr); + DiyCity city = diyCityService.selectDiyCityById(cityId); + if (city != null) { + Map cityMap = new HashMap<>(); + cityMap.put("id", city.getId()); + cityMap.put("title", city.getTitle()); + cityArr.add(cityMap); + } + } + } catch (Exception ignore) { + } + } + // 5. 统计评价 + OrderComment commentQuery = new OrderComment(); + commentQuery.setWorkerId(user.getId()); + List commentList = orderCommentService.selectOrderCommentList(commentQuery); + int one = 0, two = 0, three = 0; + for (OrderComment c : commentList) { + if (c.getNumType() != null) { + if (c.getNumType() == 1L) one++; + else if (c.getNumType() == 2L) two++; + else if (c.getNumType() == 3L) three++; + } + } + int total = commentList.size(); + Map commentStat = new HashMap<>(); + commentStat.put("one", one); + commentStat.put("two", two); + commentStat.put("three", three); + commentStat.put("total", total); + // 6. 构建user数据 + Map userMap = buildUserInfoResponse(user); + userMap.put("level_info", levelInfo); + userMap.put("skill_arr", skillArr); + userMap.put("service_city_arr", cityArr); + userMap.put("level_img", levelImg); + // 7. 处理分页和type筛选,默认参数 + int page = 1; + int limit = 15; + int type = 0; + List filteredList = new ArrayList<>(); + if (params != null) { + params = new HashMap<>(); + page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + type = params.get("type") != null ? Integer.parseInt(params.get("type").toString()) : 0; + // 过滤type + for (OrderComment c : commentList) { + if (type == 0 || (type == 1 && c.getNumType() != null && c.getNumType() == 1L) + || (type == 2 && c.getNumType() != null && c.getNumType() == 2L) + || (type == 3 && c.getNumType() != null && c.getNumType() == 3L)) { + filteredList.add(c); + } + } + } else { + filteredList.addAll(commentList); + } + int totalCount = filteredList.size(); + int from = (page - 1) * limit; + int to = Math.min(from + limit, totalCount); + List> commentArr = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日"); + for (int i = from; i < to; i++) { + OrderComment c = filteredList.get(i); + Map cMap = new HashMap<>(); + cMap.put("id", c.getId()); + cMap.put("uid", c.getUid()); + cMap.put("images", c.getImages()); + cMap.put("content", c.getContent()); + cMap.put("num", c.getNum()); + cMap.put("created_at", c.getCreatedAt() != null ? sdf.format(c.getCreatedAt()) : null); + cMap.put("time", c.getCreatedAt() != null ? sdf2.format(c.getCreatedAt()) : null); + // 查询用户信息 + Map uMap = new HashMap<>(); + Users u = usersService.selectUsersById(c.getUid()); + if (u != null) { + uMap.put("id", u.getId()); + uMap.put("name", u.getName()); + String avatar = u.getAvatar(); + if (avatar != null && !avatar.isEmpty()) { + if (!avatar.startsWith("http")) { + avatar = "https://img.huafurenjia.cn/" + avatar.replaceFirst("^/+", ""); + } + } else { + avatar = "https://img.huafurenjia.cn//default/user_avatar.jpeg"; + } + uMap.put("avatar", avatar); + } + cMap.put("user", uMap); + commentArr.add(cMap); + } + // 8. 构建分页结构 + Map pageData = new HashMap<>(); + pageData.put("current_page", page); + pageData.put("data", commentArr); + pageData.put("first_page_url", "https://www.huafurenjia.cn/api/worker/index?page=1"); + pageData.put("from", totalCount == 0 ? null : from + 1); + int lastPage = (int) Math.ceil((double) totalCount / limit); + pageData.put("last_page", lastPage); + pageData.put("last_page_url", "https://www.huafurenjia.cn/api/worker/index?page=" + lastPage); + // links + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", page > 1 ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page - 1) : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + for (int i = 1; i <= lastPage; i++) { + Map link = new HashMap<>(); + link.put("url", "https://www.huafurenjia.cn/api/worker/index?page=" + i); + link.put("label", String.valueOf(i)); + link.put("active", i == page); + links.add(link); + } + Map nextLink = new HashMap<>(); + nextLink.put("url", page < lastPage ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page + 1) : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + pageData.put("links", links); + pageData.put("next_page_url", page < lastPage ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page + 1) : null); + pageData.put("path", "https://www.huafurenjia.cn/api/worker/index"); + pageData.put("per_page", String.valueOf(limit)); + pageData.put("prev_page_url", page > 1 ? "https://www.huafurenjia.cn/api/worker/index?page=" + (page - 1) : null); + pageData.put("to", totalCount == 0 ? null : to); + pageData.put("total", totalCount); + // 9. 构建最终返回结构 + Map data = new HashMap<>(); + data.put("user", userMap); + data.put("data", pageData); + data.put("comment", commentStat); + return AjaxResult.success(data); + } catch (Exception e) { + return AppletControllerUtil.appletError("获取师傅首页数据失败:" + e.getMessage()); } - String year = params.get("year").toString(); - String month = params.get("month").toString(); - // 构造当月起止日期 - String startDate = year + "-" + month + "-01"; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date start = sdf.parse(startDate); - Calendar cal = Calendar.getInstance(); - cal.setTime(start); - cal.set(Calendar.DAY_OF_MONTH, 1); - int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); - cal.set(Calendar.DAY_OF_MONTH, maxDay); - Date end = cal.getTime(); - // 查询签到记录 - WorkerSign query = new WorkerSign(); - query.setUid(String.valueOf(user.getId())); - List allList = workerSignService.selectWorkerSignList(query); - List> result = new ArrayList<>(); - for (WorkerSign sign : allList) { - if (sign.getTime() != null && !sign.getTime().before(start) && !sign.getTime().after(end)) { + } + + /** + * 师傅签到日志接口 + * + * @param params {year: "2025", month: "06"} + * @param request + * @return 签到日志列表 + */ + @PostMapping("/api/worker/sign/log") + public AjaxResult getWorkerSignLog(@RequestBody Map params, HttpServletRequest request) { + try { + // 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + if (params == null || !params.containsKey("year") || !params.containsKey("month")) { + return AppletControllerUtil.appletWarning("参数year和month不能为空"); + } + String year = params.get("year").toString(); + String month = params.get("month").toString(); + // 构造当月起止日期 + String startDate = year + "-" + month + "-01"; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date start = sdf.parse(startDate); + Calendar cal = Calendar.getInstance(); + cal.setTime(start); + cal.set(Calendar.DAY_OF_MONTH, 1); + int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH); + cal.set(Calendar.DAY_OF_MONTH, maxDay); + Date end = cal.getTime(); + // 查询签到记录 + WorkerSign query = new WorkerSign(); + query.setUid(String.valueOf(user.getId())); + List allList = workerSignService.selectWorkerSignList(query); + List> result = new ArrayList<>(); + for (WorkerSign sign : allList) { + if (sign.getTime() != null && !sign.getTime().before(start) && !sign.getTime().after(end)) { + Map map = new HashMap<>(); + map.put("id", sign.getId()); + map.put("date", sdf.format(sign.getTime())); + map.put("info", sign.getUname()); + result.add(map); + } + } + return AjaxResult.success(result); + } catch (Exception e) { + return AjaxResult.error("查询签到日志失败:" + e.getMessage()); + } + } + + /** + * 师傅质保金日志接口 + * + * @param params {"limit":15,"page":1} + * @param request + * @return 质保金日志分页数据和师傅信息 + */ + @PostMapping("/api/worker/mergin/log") + public AjaxResult getWorkerMarginLog(@RequestBody Map params, HttpServletRequest request) { + try { + // 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + // 查询质保金日志 + WorkerMarginLog query = new WorkerMarginLog(); + query.setUid(user.getId()); + PageHelper.startPage(page, limit); + List logList = workerMarginLogService.selectWorkerMarginLogList(query); + PageInfo pageInfo = new PageInfo<>(logList); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (WorkerMarginLog log : logList) { Map map = new HashMap<>(); - map.put("id", sign.getId()); - map.put("date", sdf.format(sign.getTime())); - map.put("info", sign.getUname()); - result.add(map); + map.put("id", log.getId()); + map.put("uid", log.getUid()); + map.put("oid", log.getOid()); + map.put("order_id", log.getOrderId()); + map.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); + map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); + map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); + resultList.add(map); } + // 构建分页结构 + Map dataPage = new HashMap<>(); + dataPage.put("current_page", pageInfo.getPageNum()); + dataPage.put("data", resultList); + dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=1"); + dataPage.put("from", pageInfo.getStartRow()); + dataPage.put("last_page", pageInfo.getPages()); + dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPages()); + // links + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + for (int i = 1; i <= pageInfo.getPages(); i++) { + Map link = new HashMap<>(); + link.put("url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + i); + link.put("label", String.valueOf(i)); + link.put("active", i == pageInfo.getPageNum()); + links.add(link); + } + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + dataPage.put("links", links); + dataPage.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getNextPage() : null); + dataPage.put("path", "https://www.huafurenjia.cn/api/worker/mergin/log"); + dataPage.put("per_page", limit); + dataPage.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPrePage() : null); + dataPage.put("to", pageInfo.getEndRow()); + dataPage.put("total", pageInfo.getTotal()); + // 构建user信息 + Map userMap = buildUserInfoResponse(user); + // 最终返回结构 + Map data = new HashMap<>(); + data.put("data", dataPage); + data.put("user", userMap); + return AjaxResult.success(data); + } catch (Exception e) { + return AjaxResult.error("查询质保金日志失败:" + e.getMessage()); } - return AjaxResult.success(result); - } catch (Exception e) { - return AjaxResult.error("查询签到日志失败:" + e.getMessage()); } -} -/** - * 师傅质保金日志接口 - * - * @param params {"limit":15,"page":1} - * @param request - * @return 质保金日志分页数据和师傅信息 - */ -@PostMapping("/api/worker/mergin/log") -public AjaxResult getWorkerMarginLog(@RequestBody Map params, HttpServletRequest request) { - try { - // 校验token并获取用户 + /** + * 师傅收益明细接口 + * + * @param params {"limit":15,"page":1,"type":"1"} + * @param request + * @return 收益明细分页数据 + */ + @PostMapping("/api/worker/money/log") + public AjaxResult getWorkerMoneyLog(@RequestBody Map params, HttpServletRequest request) { + try { + // 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + String type = params.get("type") != null ? params.get("type").toString() : null; + // 查询收益明细 + WorkerMoneyLog query = new WorkerMoneyLog(); + query.setWorkerId(user.getId()); + if (type != null && !type.isEmpty()) { + query.setType(Integer.valueOf(type)); + } + PageHelper.startPage(page, limit); + List logList = workerMoneyLogService.selectWorkerMoneyLogList(query); + PageInfo pageInfo = new PageInfo<>(logList); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (WorkerMoneyLog log : logList) { + Map map = new HashMap<>(); + map.put("id", log.getId()); + map.put("worker_id", log.getWorkerId()); + map.put("oid", log.getOid()); + map.put("order_id", log.getOrderId()); + map.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); + map.put("type", log.getType()); + map.put("service_price", log.getServicePrice() != null ? log.getServicePrice().toString() : "0.00"); + map.put("reduction_price", log.getReductionPrice() != null ? log.getReductionPrice().toString() : "0.00"); + map.put("cr", log.getCr()); + map.put("mergin", log.getMergin() != null ? log.getMergin().toString() : "0.00"); + map.put("door_price", log.getDoorPrice() != null ? log.getDoorPrice().toString() : null); + map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); + map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); + resultList.add(map); + } + // 构建分页结构 + Map dataPage = new HashMap<>(); + dataPage.put("current_page", pageInfo.getPageNum()); + dataPage.put("data", resultList); + dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=1"); + dataPage.put("from", pageInfo.getStartRow()); + dataPage.put("last_page", pageInfo.getPages()); + dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPages()); + // links + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + for (int i = 1; i <= pageInfo.getPages(); i++) { + Map link = new HashMap<>(); + link.put("url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + i); + link.put("label", String.valueOf(i)); + link.put("active", i == pageInfo.getPageNum()); + links.add(link); + } + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + dataPage.put("links", links); + dataPage.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getNextPage() : null); + dataPage.put("path", "https://www.huafurenjia.cn/api/worker/money/log"); + dataPage.put("per_page", limit); + dataPage.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPrePage() : null); + dataPage.put("to", pageInfo.getEndRow()); + dataPage.put("total", pageInfo.getTotal()); + return AjaxResult.success(dataPage); + } catch (Exception e) { + return AjaxResult.error("查询收益明细失败:" + e.getMessage()); + } + } + + /** + * 师傅提现记录接口 + * 查询当前师傅的提现记录,支持分页和类型筛选 + * + * @param params {"limit":15,"page":1,"type":2} + * @param request HttpServletRequest + * @return AjaxResult 分页提现记录 + */ + @PostMapping("/api/worker/withdraw_log") + public AjaxResult getWorkerWithdrawLog(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + // 2. 解析分页和筛选参数 + int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; + int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; + // 3. 构建查询条件 + WechatTransfer query = new WechatTransfer(); + query.setUid(user.getId()); + //if (type != null) query.setStatus(type); + PageHelper.startPage(page, limit); + List logList = wechatTransferService.selectWechatTransferList(query); + PageInfo pageInfo = new PageInfo<>(logList); + // 4. 数据组装 + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (WechatTransfer log : logList) { + Map map = new HashMap<>(); + map.put("id", log.getId()); + map.put("uid", log.getUid()); + map.put("batch_id", log.getBatchId()); + map.put("money", log.getMoney() != null ? log.getMoney().toString() : "0.00"); + map.put("status", log.getStatus()); + map.put("order_id", log.getOrderId()); + map.put("openid", log.getOpenid()); + map.put("paid", log.getPaid()); + map.put("pay_time", log.getPayTime() != null ? sdf.format(log.getPayTime()) : null); + map.put("time", log.getTime()); + map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); + map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); + resultList.add(map); + } + // 5. 构建分页响应结构 + String baseUrl = "https://www.huafurenjia.cn/api/worker/withdraw_log"; + Map dataPage = AppletControllerUtil.buildPageResult(pageInfo, resultList, baseUrl); + return AjaxResult.success(dataPage); + } catch (Exception e) { + return AppletControllerUtil.appletError("查询提现记录失败:" + e.getMessage()); + } + } + + /** + * 师傅设置上门费接口 + * 参数:{"id":订单id,"price":金额} + * 逻辑:查找订单最新日志,设置workerCost和price,并设置paid=1 + */ + @PostMapping("/api/worker/set/price") + public AjaxResult setWorkerPrice(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 校验token并获取用户 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + Long orderId = params.get("id") != null ? Long.parseLong(params.get("id").toString()) : null; + String priceStr = params.get("price") != null ? params.get("price").toString() : null; + if (orderId == null || StringUtils.isEmpty(priceStr)) { + return AppletControllerUtil.appletWarning("参数错误"); + } + BigDecimal price = new BigDecimal(priceStr); + // 查询订单 + Order order = orderService.selectOrderById(orderId); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + // 查询最新订单日志 + OrderLog neworderLog = orderLogService.selectDataTheFirstNew(order.getId()); + if (neworderLog != null) { + //修改订单日志添加费用 + neworderLog.setPrice(price); + neworderLog.setPaid(1L); + neworderLog.setWorkerCost(price); + neworderLog.setLogId(GenerateCustomCode.generCreateOrder("FEE")); + //修改订单状态 + order.setJsonStatus(3); + JSONObject jsonObject3 = new JSONObject(); + jsonObject3.put("type", 2); + order.setLogJson(jsonObject3.toJSONString()); + orderLogService.updateOrderLog(neworderLog); + orderService.updateOrder(order); + Users userinfo = usersService.selectUsersById(order.getUid()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + //给用户发送微信推送消息 + WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); + } + return AjaxResult.success("设置上门费成功"); + } catch (Exception e) { + return AppletControllerUtil.appletError("设置上门费失败:" + e.getMessage()); + } + } + + /** + * 师傅设置出发上门 + * GET /api/worker/start/door/{id} + * 逻辑参考OrderController的edit接口中jsonStatus=4的流程 + */ + @GetMapping("/api/worker/start/door/{id}") + public AjaxResult workerStartDoor(@PathVariable("id") Long id, HttpServletRequest request) throws Exception { + // 1. 获取当前登录师傅ID(token在header) String token = request.getHeader("token"); Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); + return AppletControllerUtil.appletWarning("未登录或token无效"); } Users user = (Users) userValidation.get("user"); if (user == null) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; - // 查询质保金日志 - WorkerMarginLog query = new WorkerMarginLog(); - query.setUid(user.getId()); - PageHelper.startPage(page, limit); - List logList = workerMarginLogService.selectWorkerMarginLogList(query); - PageInfo pageInfo = new PageInfo<>(logList); - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (WorkerMarginLog log : logList) { - Map map = new HashMap<>(); - map.put("id", log.getId()); - map.put("uid", log.getUid()); - map.put("oid", log.getOid()); - map.put("order_id", log.getOrderId()); - map.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); - map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); - map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); - resultList.add(map); - } - // 构建分页结构 - Map dataPage = new HashMap<>(); - dataPage.put("current_page", pageInfo.getPageNum()); - dataPage.put("data", resultList); - dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=1"); - dataPage.put("from", pageInfo.getStartRow()); - dataPage.put("last_page", pageInfo.getPages()); - dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPages()); - // links - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPrePage() : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - for (int i = 1; i <= pageInfo.getPages(); i++) { - Map link = new HashMap<>(); - link.put("url", "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + i); - link.put("label", String.valueOf(i)); - link.put("active", i == pageInfo.getPageNum()); - links.add(link); - } - Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getNextPage() : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - dataPage.put("links", links); - dataPage.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getNextPage() : null); - dataPage.put("path", "https://www.huafurenjia.cn/api/worker/mergin/log"); - dataPage.put("per_page", limit); - dataPage.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/mergin/log?page=" + pageInfo.getPrePage() : null); - dataPage.put("to", pageInfo.getEndRow()); - dataPage.put("total", pageInfo.getTotal()); - // 构建user信息 - Map userMap = buildUserInfoResponse(user); - // 最终返回结构 - Map data = new HashMap<>(); - data.put("data", dataPage); - data.put("user", userMap); - return AjaxResult.success(data); - } catch (Exception e) { - return AjaxResult.error("查询质保金日志失败:" + e.getMessage()); - } -} + Long workerId = user.getId(); -/** - * 师傅收益明细接口 - * - * @param params {"limit":15,"page":1,"type":"1"} - * @param request - * @return 收益明细分页数据 - */ -@PostMapping("/api/worker/money/log") -public AjaxResult getWorkerMoneyLog(@RequestBody Map params, HttpServletRequest request) { - try { - // 校验token并获取用户 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; - String type = params.get("type") != null ? params.get("type").toString() : null; - // 查询收益明细 - WorkerMoneyLog query = new WorkerMoneyLog(); - query.setWorkerId(user.getId()); - if (type != null && !type.isEmpty()) { - query.setType(Integer.valueOf(type)); - } - PageHelper.startPage(page, limit); - List logList = workerMoneyLogService.selectWorkerMoneyLogList(query); - PageInfo pageInfo = new PageInfo<>(logList); - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (WorkerMoneyLog log : logList) { - Map map = new HashMap<>(); - map.put("id", log.getId()); - map.put("worker_id", log.getWorkerId()); - map.put("oid", log.getOid()); - map.put("order_id", log.getOrderId()); - map.put("price", log.getPrice() != null ? log.getPrice().toString() : "0.00"); - map.put("type", log.getType()); - map.put("service_price", log.getServicePrice() != null ? log.getServicePrice().toString() : "0.00"); - map.put("reduction_price", log.getReductionPrice() != null ? log.getReductionPrice().toString() : "0.00"); - map.put("cr", log.getCr()); - map.put("mergin", log.getMergin() != null ? log.getMergin().toString() : "0.00"); - map.put("door_price", log.getDoorPrice() != null ? log.getDoorPrice().toString() : null); - map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); - map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); - resultList.add(map); - } - // 构建分页结构 - Map dataPage = new HashMap<>(); - dataPage.put("current_page", pageInfo.getPageNum()); - dataPage.put("data", resultList); - dataPage.put("first_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=1"); - dataPage.put("from", pageInfo.getStartRow()); - dataPage.put("last_page", pageInfo.getPages()); - dataPage.put("last_page_url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPages()); - // links - List> links = new ArrayList<>(); - Map prevLink = new HashMap<>(); - prevLink.put("url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPrePage() : null); - prevLink.put("label", "« Previous"); - prevLink.put("active", false); - links.add(prevLink); - for (int i = 1; i <= pageInfo.getPages(); i++) { - Map link = new HashMap<>(); - link.put("url", "https://www.huafurenjia.cn/api/worker/money/log?page=" + i); - link.put("label", String.valueOf(i)); - link.put("active", i == pageInfo.getPageNum()); - links.add(link); - } - Map nextLink = new HashMap<>(); - nextLink.put("url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getNextPage() : null); - nextLink.put("label", "Next »"); - nextLink.put("active", false); - links.add(nextLink); - dataPage.put("links", links); - dataPage.put("next_page_url", pageInfo.isHasNextPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getNextPage() : null); - dataPage.put("path", "https://www.huafurenjia.cn/api/worker/money/log"); - dataPage.put("per_page", limit); - dataPage.put("prev_page_url", pageInfo.isHasPreviousPage() ? "https://www.huafurenjia.cn/api/worker/money/log?page=" + pageInfo.getPrePage() : null); - dataPage.put("to", pageInfo.getEndRow()); - dataPage.put("total", pageInfo.getTotal()); - return AjaxResult.success(dataPage); - } catch (Exception e) { - return AjaxResult.error("查询收益明细失败:" + e.getMessage()); - } -} - -/** - * 师傅提现记录接口 - * 查询当前师傅的提现记录,支持分页和类型筛选 - * - * @param params {"limit":15,"page":1,"type":2} - * @param request HttpServletRequest - * @return AjaxResult 分页提现记录 - */ -@PostMapping("/api/worker/withdraw_log") -public AjaxResult getWorkerWithdrawLog(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 校验token并获取用户 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - // 2. 解析分页和筛选参数 - int page = params.get("page") != null ? Integer.parseInt(params.get("page").toString()) : 1; - int limit = params.get("limit") != null ? Integer.parseInt(params.get("limit").toString()) : 15; -// Long type = null; -// if (params.get("type") != null) { -// try { type = Long.valueOf(params.get("type").toString()); } catch (Exception ignore) {} -// } - // 3. 构建查询条件 - WechatTransfer query = new WechatTransfer(); - query.setUid(user.getId()); - //if (type != null) query.setStatus(type); - PageHelper.startPage(page, limit); - List logList = wechatTransferService.selectWechatTransferList(query); - PageInfo pageInfo = new PageInfo<>(logList); - // 4. 数据组装 - List> resultList = new ArrayList<>(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - for (WechatTransfer log : logList) { - Map map = new HashMap<>(); - map.put("id", log.getId()); - map.put("uid", log.getUid()); - map.put("batch_id", log.getBatchId()); - map.put("money", log.getMoney() != null ? log.getMoney().toString() : "0.00"); - map.put("status", log.getStatus()); - map.put("order_id", log.getOrderId()); - map.put("openid", log.getOpenid()); - map.put("paid", log.getPaid()); - map.put("pay_time", log.getPayTime() != null ? sdf.format(log.getPayTime()) : null); - map.put("time", log.getTime()); - map.put("created_at", log.getCreatedAt() != null ? sdf.format(log.getCreatedAt()) : null); - map.put("updated_at", log.getUpdatedAt() != null ? sdf.format(log.getUpdatedAt()) : null); - resultList.add(map); - } - // 5. 构建分页响应结构 - String baseUrl = "https://www.huafurenjia.cn/api/worker/withdraw_log"; - Map dataPage = AppletControllerUtil.buildPageResult(pageInfo, resultList, baseUrl); - return AjaxResult.success(dataPage); - } catch (Exception e) { - return AppletControllerUtil.appletError("查询提现记录失败:" + e.getMessage()); - } -} - -/** - * 师傅设置上门费接口 - * 参数:{"id":订单id,"price":金额} - * 逻辑:查找订单最新日志,设置workerCost和price,并设置paid=1 - */ -@PostMapping("/api/worker/set/price") -public AjaxResult setWorkerPrice(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 校验token并获取用户 - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletUnauthorized(); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - - Long orderId = params.get("id") != null ? Long.parseLong(params.get("id").toString()) : null; - String priceStr = params.get("price") != null ? params.get("price").toString() : null; - if (orderId == null || StringUtils.isEmpty(priceStr)) { - return AppletControllerUtil.appletWarning("参数错误"); - } - BigDecimal price = new BigDecimal(priceStr); - // 查询订单 - Order order = orderService.selectOrderById(orderId); + // 2. 获取订单 + Order order = orderService.selectOrderById(id); if (order == null) { return AppletControllerUtil.appletWarning("订单不存在"); } - // 查询最新订单日志 - OrderLog neworderLog = orderLogService.selectDataTheFirstNew(order.getId()); - System.out.println("######################" + order.getId()); - System.out.println("^^^^^^^^^^^^^^^^^^^^^^" + neworderLog.getId()); - if (neworderLog != null) { - //修改订单日志添加费用 - neworderLog.setPrice(price); - neworderLog.setPaid(1L); - neworderLog.setWorkerCost(price); - neworderLog.setLogId(GenerateCustomCode.generCreateOrder("FEE")); - //修改订单状态 - order.setJsonStatus(3); - JSONObject jsonObject3 = new JSONObject(); - jsonObject3.put("type", 2); - order.setLogJson(jsonObject3.toJSONString()); - orderLogService.updateOrderLog(neworderLog); - orderService.updateOrder(order); - Users userinfo = usersService.selectUsersById(order.getUid()); - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - //给用户发送微信推送消息 - WXsendMsgUtil.sendMsgForUserDoorMoney(userinfo.getOpenid(), order, serviceGoods); + if (!workerId.equals(order.getWorkerId())) { + return AppletControllerUtil.appletWarning("您不是该订单的师傅"); } -// List logList = orderLogService.selectOrderLogByOrderId(order.getOrderId()); -// if (logList == null || logList.isEmpty()) { -// return AppletControllerUtil.appletWarning("订单日志不存在"); -// } -// OrderLog latestLog = logList.get(0); -// latestLog.setWorkerCost(price); -// latestLog.setPrice(price); -// latestLog.setPaid(1L); -// orderLogService.updateOrderLog(latestLog); - return AjaxResult.success("设置上门费成功"); - } catch (Exception e) { - return AppletControllerUtil.appletError("设置上门费失败:" + e.getMessage()); - } -} - -/** - * 师傅设置出发上门 - * GET /api/worker/start/door/{id} - * 逻辑参考OrderController的edit接口中jsonStatus=4的流程 - */ -@GetMapping("/api/worker/start/door/{id}") -public AjaxResult workerStartDoor(@PathVariable("id") Long id, HttpServletRequest request) throws Exception { - // 1. 获取当前登录师傅ID(token在header) - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("未登录或token无效"); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - Long workerId = user.getId(); - - // 2. 获取订单 - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - if (!workerId.equals(order.getWorkerId())) { - return AppletControllerUtil.appletWarning("您不是该订单的师傅"); - } // if (order.getStatus() == null || order.getStatus() != 2L) { // return AppletControllerUtil.appletWarning("订单状态不正确"); // } @@ -6146,1153 +5153,1084 @@ public AjaxResult workerStartDoor(@PathVariable("id") Long id, HttpServletReques // return AppletControllerUtil.appletWarning("订单进度不正确"); // } - order.setJsonStatus(4); // 出发上门 - JSONObject typeJson = new JSONObject(); - typeJson.put("type", 3); - order.setLogJson(typeJson.toJSONString()); - // 5. 保存 - orderService.updateOrder(order); - // 4. 写订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setWorkerId(workerId); - orderLog.setWorkerLogId(workerId); - orderLog.setTitle("出发上门"); - JSONObject typeJson1 = new JSONObject(); - typeJson1.put("name", "师傅收到派单信息准备出发"); - orderLog.setType(new BigDecimal("3.0")); - orderLog.setContent(typeJson1.toJSONString()); - orderLogService.insertOrderLog(orderLog); - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - //小程序推送给用户师傅已经出发 - WXsendMsgUtil.sendStartDoorMoney(user.getOpenid(), order, serviceGoods); - return AppletControllerUtil.appletSuccess("出发上门成功"); -} - -/** - * 师傅确认到达(新版,校验手机号后两位) - * POST /api/worker/confirm/door - * 参数:{id: 订单id, phone_two: 用户手机号后两位} - */ -@PostMapping("/api/worker/confirm/door") -public AjaxResult workerConfirmDoor(@RequestBody Map params, HttpServletRequest request) throws Exception { - // 1. 获取参数 - if (params == null || !params.containsKey("id") || !params.containsKey("phone_two")) { - return AppletControllerUtil.appletWarning("参数不完整"); - } - Long id; - try { - id = Long.valueOf(params.get("id").toString()); - } catch (Exception e) { - return AppletControllerUtil.appletWarning("订单ID格式错误"); - } - String phoneTwo = params.get("phone_two").toString(); - if (phoneTwo.length() != 2) { - return AppletControllerUtil.appletWarning("请输入手机号后两位"); - } - - // 2. 获取当前登录师傅ID(token在header) - String token = request.getHeader("token"); - Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); - if (!(Boolean) userValidation.get("valid")) { - return AppletControllerUtil.appletWarning("未登录或token无效"); - } - Users user = (Users) userValidation.get("user"); - if (user == null) { - return AppletControllerUtil.appletWarning("用户信息获取失败"); - } - Long workerId = user.getId(); - - // 3. 获取订单 - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletWarning("订单不存在"); - } - if (!workerId.equals(order.getWorkerId())) { - return AppletControllerUtil.appletWarning("您不是该订单的师傅"); - } - // 校验用户手机号后两位 - String userPhone = order.getPhone(); - if (userPhone == null || userPhone.length() < 2) { - return AppletControllerUtil.appletWarning("用户手机号无效"); - } - String lastTwo = userPhone.substring(userPhone.length() - 2); - if (!phoneTwo.equals(lastTwo)) { - return AppletControllerUtil.appletWarning("手机号后两位不正确"); - } - - //解绑订单虚拟号 - YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone()); - - - // 4. 更新订单状态 - order.setJsonStatus(5); // 确认到达 - JSONObject typeJson = new JSONObject(); - typeJson.put("type", 4); - order.setLogJson(typeJson.toJSONString()); - // 6. 保存 - orderService.updateOrder(order); - - // 5. 写订单日志 - OrderLog orderLog = new OrderLog(); - orderLog.setOid(order.getId()); - orderLog.setOrderId(order.getOrderId()); - orderLog.setWorkerId(workerId); - orderLog.setWorkerLogId(workerId); - orderLog.setTitle("师傅到达"); - orderLog.setType(new BigDecimal("4.0")); - JSONObject content = new JSONObject(); - content.put("name", "师傅到达服务地点"); - orderLog.setContent(content.toJSONString()); - // 6. 保存 - orderLogService.insertOrderLog(orderLog); - - // 小程序推送给用户师傅已经到达 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - WXsendMsgUtil.sendMsgForWorkerInfo(user.getOpenid(), order, serviceGoods); - return AppletControllerUtil.appletSuccess("师傅已经上门"); -} - -/** - * 获取基检项目 - * GET /api/worker/basic/project/{id} - * 返回格式参考用户图片 - */ -@GetMapping("/api/worker/basic/project/{id}") -public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id) { - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(id); - if (serviceGoods == null) { - return AppletControllerUtil.appletError("商品不存在"); - } - String basic = serviceGoods.getBasic(); - List basicList = new ArrayList<>(); - if (basic != null && !basic.trim().isEmpty()) { - try { - JSONArray jsonArray = JSONArray.parseArray(basic); - for (int i = 0; i < jsonArray.size(); i++) { - String item = jsonArray.getString(i); - if (item != null && !item.trim().isEmpty()) { - basicList.add(item.trim()); - } - } - } catch (Exception e) { - String[] arr = basic.split("[\n,,]"); - for (String s : arr) { - if (!s.trim().isEmpty()) basicList.add(s.trim()); - } - } - } - Map data = new HashMap<>(); - data.put("basic", basicList); - return AjaxResult.success(data); -} - -/** - * 报价获取服务项目 - * GET /api/worker/quote/craft/{goodsId} - * 返回格式参考json.txt - */ -@GetMapping("/api/worker/quote/craft/{goodsId}") -public Object getWorkerQuoteCraft(@PathVariable("goodsId") Long goodsId) { - // 1. 查询商品基本信息 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); - if (serviceGoods == null) { - return AppletControllerUtil.appletError("商品不存在"); - } - // 2. 查询服务分类(IQuoteTypeService) - QuoteType typeQuery = new QuoteType(); - typeQuery.setGoodId("\"" + goodsId + "\""); - List typeList = quoteTypeService.selectQuoteTypeList(typeQuery); - List dataArr = new ArrayList<>(); - for (QuoteType type : typeList) { - Map typeMap = new HashMap<>(); - typeMap.put("id", type.getId()); - typeMap.put("title", type.getTitle()); - // 3. 查询工艺(IQuoteCraftService) - QuoteCraft craftQuery = new QuoteCraft(); - craftQuery.setTypeId("[\"" + type.getId() + "\"]"); - List craftList = quoteCraftService.selectQuoteCraftList(craftQuery); - List> craftArr = new ArrayList<>(); - for (QuoteCraft craft : craftList) { - Map craftMap = new HashMap<>(); - craftMap.put("id", craft.getId()); - craftMap.put("title", craft.getTitle()); - craftMap.put("price", craft.getPrice() != null ? craft.getPrice().toString() : "0.00"); - craftMap.put("unit", craft.getUnit()); - // type_id为数组,需解析 - List typeIdList = new ArrayList<>(); - String typeIdStr = craft.getTypeId(); - if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { - try { - typeIdList = JSON.parseArray(typeIdStr, String.class); - } catch (Exception e) { - typeIdList.add(typeIdStr); - } - } else if (typeIdStr != null) { - typeIdList.add(typeIdStr); - } - craftMap.put("type_id", typeIdList); - craftArr.add(craftMap); - } - typeMap.put("craft", craftArr); - dataArr.add(typeMap); - } - Map result = new HashMap<>(); - result.put("data", dataArr); - result.put("code", 200); - result.put("msg", "OK"); - return result; -} - -/** - * 报价所需物料查询 - * GET /api/worker/quote/material/{goodsId} - * 返回格式参考json.txt - */ -@GetMapping("/api/worker/quote/material/{goodsId}") -public Object getWorkerQuoteMaterial(@PathVariable("goodsId") Long goodsId) { - // 1. 查询商品基本信息 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); - if (serviceGoods == null) { - return AppletControllerUtil.appletError("商品不存在"); - } - // 2. 查询物料分类(IQuoteMaterialTypeService) - QuoteMaterialType typeQuery = new QuoteMaterialType(); - typeQuery.setGoodId("\"" + goodsId + "\""); - List typeList = quoteMaterialTypeService.selectQuoteMaterialTypeList(typeQuery); - List dataArr = new ArrayList<>(); - for (QuoteMaterialType type : typeList) { - Map typeMap = new HashMap<>(); - typeMap.put("id", type.getId()); - typeMap.put("title", type.getTitle()); - // 3. 查询物料信息(IQuoteMaterialService) - QuoteMaterial materialQuery = new QuoteMaterial(); - materialQuery.setTypeId("\"" + type.getId() + "\""); - List materialList = quoteMaterialService.selectQuoteMaterialList(materialQuery); - List> materialArr = new ArrayList<>(); - for (QuoteMaterial material : materialList) { - Map materialMap = new HashMap<>(); - materialMap.put("id", material.getId()); - materialMap.put("title", material.getTitle()); - materialMap.put("price", material.getPrice() != null ? material.getPrice().toString() : "0.00"); - materialMap.put("unit", material.getUnit()); - // type_id为数组,需解析 - List typeIdList = new ArrayList<>(); - String typeIdStr = material.getTypeId(); - if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { - try { - typeIdList = JSON.parseArray(typeIdStr, String.class); - } catch (Exception e) { - typeIdList.add(typeIdStr); - } - } else if (typeIdStr != null) { - typeIdList.add(typeIdStr); - } - materialMap.put("type_id", typeIdList); - materialArr.add(materialMap); - } - typeMap.put("material", materialArr); - dataArr.add(typeMap); - } - Map result = new HashMap<>(); - result.put("data", dataArr); - result.put("code", 200); - result.put("msg", "OK"); - return result; -} - -/** - * 师傅报价接口 - * POST /api/worker/estimate - * 参数格式参考json.txt - */ -@PostMapping("/api/worker/estimate") -public AjaxResult workerEstimate(@RequestBody Map params, HttpServletRequest request) throws Exception { - if (params == null) { - return AppletControllerUtil.appletError("参数错误"); - } - // 1. 计算金额 - BigDecimal GoodsAllPrice = BigDecimal.ZERO; - BigDecimal ServiceAllPrice = BigDecimal.ZERO; - BigDecimal totalPrice = BigDecimal.ZERO; - List> craftList = (List>) params.get("craft"); - if (craftList != null) { - for (Map craft : craftList) { - Long craftId = null; - try { - craftId = Long.valueOf(craft.get("id").toString()); - } catch (Exception ignore) { - } - if (craftId != null) { - QuoteCraft quoteCraft = quoteCraftService.selectQuoteCraftById(craftId); - if (quoteCraft != null) { - BigDecimal price = new BigDecimal(craft.get("price").toString()); - Integer count = craft.get("count") == null ? 1 : Integer.parseInt(craft.get("count").toString()); - totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); - ServiceAllPrice = ServiceAllPrice.add(price.multiply(BigDecimal.valueOf(count))); - } - } - } - } - List> materialList = (List>) params.get("material"); - if (materialList != null) { - for (Map material : materialList) { - Long materialId = null; - try { - materialId = Long.valueOf(material.get("id").toString()); - } catch (Exception ignore) { - } - if (materialId != null) { - QuoteMaterial quoteMaterial = quoteMaterialService.selectQuoteMaterialById(materialId); - if (quoteMaterial != null) { - BigDecimal price = new BigDecimal(material.get("price").toString()); - Integer count = material.get("count") == null ? 1 : Integer.parseInt(material.get("count").toString()); - totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); - GoodsAllPrice = GoodsAllPrice.add(price.multiply(BigDecimal.valueOf(count))); - } - } - } - } - BigDecimal reductionPrice = BigDecimal.ZERO; - String reduction = params.get("reduction").toString(); - if (reduction != null && !reduction.trim().isEmpty()) { - reductionPrice = new BigDecimal(reduction); - totalPrice = totalPrice.subtract(reductionPrice); - } - -// BigDecimal depositMoney = BigDecimal.ZERO; -// String deposit = params.get("price").toString(); -// if (deposit != null && !deposit.trim().isEmpty()) { -// depositMoney= new BigDecimal(deposit); -// } - - - // 2. 组装新json - Map resultJson = new LinkedHashMap<>(); - // project - Map project = new LinkedHashMap<>(); - project.put("name", "项目费用"); - project.put("price", totalPrice); - resultJson.put("project", project); - Map reductionproject = new LinkedHashMap<>(); - reductionproject.put("name", "优惠金额"); - reductionproject.put("price", params.get("reduction")); - resultJson.put("reduction", reductionproject); - Map depositproject = new LinkedHashMap<>(); - depositproject.put("name", "定金"); - depositproject.put("price", params.get("price")); - resultJson.put("deposit", depositproject); -// // project -// Map project = new LinkedHashMap<>(); -// project.put("name", "项目费用"); -// project.put("price", totalPrice); -// resultJson.put("project", project); - // basic - resultJson.put("basic", params.get("basic")); - - // craft - List> craftListNew = new ArrayList<>(); - if (craftList != null) { - for (Map craft : craftList) { - Map item = new LinkedHashMap<>(); - item.put("name", craft.get("title") != null ? craft.get("title") : craft.get("name")); - item.put("price", craft.get("price")); - item.put("count", craft.get("count")); - craftListNew.add(item); - } - } - resultJson.put("craft", craftListNew); - // material - List> materialListNew = new ArrayList<>(); - if (materialList != null) { - for (Map material : materialList) { - Map item = new LinkedHashMap<>(); - item.put("name", material.get("title") != null ? material.get("title") : material.get("name")); - item.put("price", material.get("price")); - item.put("count", material.get("count")); - materialListNew.add(item); - } - } - resultJson.put("material", materialListNew); - // 3. 转为字符串 - String contentStr = JSONObject.toJSONString(resultJson); - // 4. 订单相关处理 - Long orderId = null; - if (params.get("id") != null) { - try { - orderId = Long.valueOf(params.get("id").toString()); - } catch (Exception ignore) { - } - } - if (orderId == null) { - return AppletControllerUtil.appletError("订单ID格式错误"); - } - Order order = orderService.selectOrderById(orderId); - if (order == null) { - return AppletControllerUtil.appletError("订单不存在"); - } - order.setJsonStatus(6); - JSONObject jsonObject = new JSONObject(); - jsonObject.put("type", 5); - order.setLogJson(jsonObject.toJSONString()); - // order.setTotalPrice(totalPrice); - // order.setUpdatedAt(new Date()); - order.setGoodPrice(GoodsAllPrice); - order.setServicePrice(ServiceAllPrice); - int update = orderService.updateOrder(order); - if (update > 0) { - OrderLog log = new OrderLog(); - log.setOid(order.getId()); - log.setOrderId(order.getOrderId()); - log.setType(new BigDecimal(5)); - log.setContent(contentStr); - log.setTitle("已检查评估报价"); - if (params.get("price") != null) { - log.setDeposit(new BigDecimal(params.get("price").toString())); - log.setDepPaid(1); - log.setDepLogId(GenerateCustomCode.generCreateOrder("RED")); - }else { - log.setDeposit(BigDecimal.ZERO); - } - log.setPrice(totalPrice.add(reductionPrice)); - log.setPaid(1l); - if (params.get("reduction") != null) { - log.setReductionPrice(new BigDecimal(params.get("reduction").toString())); - } else { - log.setReductionPrice(BigDecimal.ZERO); - } - log.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); - //log.set - log.setLogId(GenerateCustomCode.generCreateOrder("EST")); - log.setWorkerLogId(order.getWorkerId()); - log.setWorkerId(order.getWorkerId()); - orderLogService.insertOrderLog(log); - Users user = usersService.selectUsersById(order.getUid()); + order.setJsonStatus(4); // 出发上门 + JSONObject typeJson = new JSONObject(); + typeJson.put("type", 3); + order.setLogJson(typeJson.toJSONString()); + // 5. 保存 + orderService.updateOrder(order); + // 4. 写订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setWorkerId(workerId); + orderLog.setWorkerLogId(workerId); + orderLog.setTitle("出发上门"); + JSONObject typeJson1 = new JSONObject(); + typeJson1.put("name", "师傅收到派单信息准备出发"); + orderLog.setType(new BigDecimal("3.0")); + orderLog.setContent(typeJson1.toJSONString()); + orderLogService.insertOrderLog(orderLog); ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - //小程序推送用户报价成功 - WXsendMsgUtil.sendWorkerADDmoney(user.getOpenid(), order, serviceGoods); - return AppletControllerUtil.appletSuccess("报价成功"); - } else { - return AppletControllerUtil.appletError("报价失败"); + //小程序推送给用户师傅已经出发 + WXsendMsgUtil.sendStartDoorMoney(user.getOpenid(), order, serviceGoods); + return AppletControllerUtil.appletSuccess("出发上门成功"); } -} -/** - * 师傅开始服务接口 - * POST /api/worker/do/service - * 参数:{"oid":订单id,"image":[图片url数组]} - */ -@PostMapping("/api/worker/do/service") -public AjaxResult workerDoService(@RequestBody Map params, HttpServletRequest request) { - Long oid = 0L; - if (params.get("oid") != null) { + /** + * 师傅确认到达(新版,校验手机号后两位) + * POST /api/worker/confirm/door + * 参数:{id: 订单id, phone_two: 用户手机号后两位} + */ + @PostMapping("/api/worker/confirm/door") + public AjaxResult workerConfirmDoor(@RequestBody Map params, HttpServletRequest request) throws Exception { + // 1. 获取参数 + if (params == null || !params.containsKey("id") || !params.containsKey("phone_two")) { + return AppletControllerUtil.appletWarning("参数不完整"); + } + Long id; try { - oid = Long.valueOf(params.get("oid").toString()); + id = Long.valueOf(params.get("id").toString()); + } catch (Exception e) { + return AppletControllerUtil.appletWarning("订单ID格式错误"); + } + String phoneTwo = params.get("phone_two").toString(); + if (phoneTwo.length() != 2) { + return AppletControllerUtil.appletWarning("请输入手机号后两位"); + } + + // 2. 获取当前登录师傅ID(token在header) + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("未登录或token无效"); + } + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + Long workerId = user.getId(); + + // 3. 获取订单 + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletWarning("订单不存在"); + } + if (!workerId.equals(order.getWorkerId())) { + return AppletControllerUtil.appletWarning("您不是该订单的师傅"); + } + // 校验用户手机号后两位 + String userPhone = order.getPhone(); + if (userPhone == null || userPhone.length() < 2) { + return AppletControllerUtil.appletWarning("用户手机号无效"); + } + String lastTwo = userPhone.substring(userPhone.length() - 2); + if (!phoneTwo.equals(lastTwo)) { + return AppletControllerUtil.appletWarning("手机号后两位不正确"); + } + //解绑订单虚拟号 + YunXinPhoneUtilAPI.httpsPrivacyUnbind(order.getWorkerPhone(), order.getUserPhone(), order.getMiddlePhone()); + // 4. 更新订单状态 + order.setJsonStatus(5); // 确认到达 + JSONObject typeJson = new JSONObject(); + typeJson.put("type", 4); + order.setLogJson(typeJson.toJSONString()); + // 6. 保存 + orderService.updateOrder(order); + // 5. 写订单日志 + OrderLog orderLog = new OrderLog(); + orderLog.setOid(order.getId()); + orderLog.setOrderId(order.getOrderId()); + orderLog.setWorkerId(workerId); + orderLog.setWorkerLogId(workerId); + orderLog.setTitle("师傅到达"); + orderLog.setType(new BigDecimal("4.0")); + JSONObject content = new JSONObject(); + content.put("name", "师傅到达服务地点"); + orderLog.setContent(content.toJSONString()); + // 6. 保存 + orderLogService.insertOrderLog(orderLog); + // 小程序推送给用户师傅已经到达 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + WXsendMsgUtil.sendMsgForWorkerInfo(user.getOpenid(), order, serviceGoods); + return AppletControllerUtil.appletSuccess("师傅已经上门"); + } + + /** + * 获取基检项目 + * GET /api/worker/basic/project/{id} + */ + @GetMapping("/api/worker/basic/project/{id}") + public AjaxResult getWorkerBasicProject(@PathVariable("id") Long id) { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(id); + if (serviceGoods == null) { + return AppletControllerUtil.appletError("商品不存在"); + } + String basic = serviceGoods.getBasic(); + List basicList = new ArrayList<>(); + if (basic != null && !basic.trim().isEmpty()) { + try { + JSONArray jsonArray = JSONArray.parseArray(basic); + for (int i = 0; i < jsonArray.size(); i++) { + String item = jsonArray.getString(i); + if (item != null && !item.trim().isEmpty()) { + basicList.add(item.trim()); + } + } + } catch (Exception e) { + String[] arr = basic.split("[\n,,]"); + for (String s : arr) { + if (!s.trim().isEmpty()) basicList.add(s.trim()); + } + } + } + Map data = new HashMap<>(); + data.put("basic", basicList); + return AjaxResult.success(data); + } + + /** + * 报价获取服务项目 + * GET /api/worker/quote/craft/{goodsId} + */ + @GetMapping("/api/worker/quote/craft/{goodsId}") + public Object getWorkerQuoteCraft(@PathVariable("goodsId") Long goodsId) { + // 1. 查询商品基本信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); + if (serviceGoods == null) { + return AppletControllerUtil.appletError("商品不存在"); + } + // 2. 查询服务分类(IQuoteTypeService) + QuoteType typeQuery = new QuoteType(); + typeQuery.setGoodId("\"" + goodsId + "\""); + List typeList = quoteTypeService.selectQuoteTypeList(typeQuery); + List dataArr = new ArrayList<>(); + for (QuoteType type : typeList) { + Map typeMap = new HashMap<>(); + typeMap.put("id", type.getId()); + typeMap.put("title", type.getTitle()); + // 3. 查询工艺(IQuoteCraftService) + QuoteCraft craftQuery = new QuoteCraft(); + craftQuery.setTypeId("[\"" + type.getId() + "\"]"); + List craftList = quoteCraftService.selectQuoteCraftList(craftQuery); + List> craftArr = new ArrayList<>(); + for (QuoteCraft craft : craftList) { + Map craftMap = new HashMap<>(); + craftMap.put("id", craft.getId()); + craftMap.put("title", craft.getTitle()); + craftMap.put("price", craft.getPrice() != null ? craft.getPrice().toString() : "0.00"); + craftMap.put("unit", craft.getUnit()); + // type_id为数组,需解析 + List typeIdList = new ArrayList<>(); + String typeIdStr = craft.getTypeId(); + if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { + try { + typeIdList = JSON.parseArray(typeIdStr, String.class); + } catch (Exception e) { + typeIdList.add(typeIdStr); + } + } else if (typeIdStr != null) { + typeIdList.add(typeIdStr); + } + craftMap.put("type_id", typeIdList); + craftArr.add(craftMap); + } + typeMap.put("craft", craftArr); + dataArr.add(typeMap); + } + Map result = new HashMap<>(); + result.put("data", dataArr); + result.put("code", 200); + result.put("msg", "OK"); + return result; + } + + /** + * 报价所需物料查询 + * GET /api/worker/quote/material/{goodsId} + */ + @GetMapping("/api/worker/quote/material/{goodsId}") + public Object getWorkerQuoteMaterial(@PathVariable("goodsId") Long goodsId) { + // 1. 查询商品基本信息 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(goodsId); + if (serviceGoods == null) { + return AppletControllerUtil.appletError("商品不存在"); + } + // 2. 查询物料分类(IQuoteMaterialTypeService) + QuoteMaterialType typeQuery = new QuoteMaterialType(); + typeQuery.setGoodId("\"" + goodsId + "\""); + List typeList = quoteMaterialTypeService.selectQuoteMaterialTypeList(typeQuery); + List dataArr = new ArrayList<>(); + for (QuoteMaterialType type : typeList) { + Map typeMap = new HashMap<>(); + typeMap.put("id", type.getId()); + typeMap.put("title", type.getTitle()); + // 3. 查询物料信息(IQuoteMaterialService) + QuoteMaterial materialQuery = new QuoteMaterial(); + materialQuery.setTypeId("\"" + type.getId() + "\""); + List materialList = quoteMaterialService.selectQuoteMaterialList(materialQuery); + List> materialArr = new ArrayList<>(); + for (QuoteMaterial material : materialList) { + Map materialMap = new HashMap<>(); + materialMap.put("id", material.getId()); + materialMap.put("title", material.getTitle()); + materialMap.put("price", material.getPrice() != null ? material.getPrice().toString() : "0.00"); + materialMap.put("unit", material.getUnit()); + // type_id为数组,需解析 + List typeIdList = new ArrayList<>(); + String typeIdStr = material.getTypeId(); + if (typeIdStr != null && typeIdStr.trim().startsWith("[") && typeIdStr.trim().endsWith("]")) { + try { + typeIdList = JSON.parseArray(typeIdStr, String.class); + } catch (Exception e) { + typeIdList.add(typeIdStr); + } + } else if (typeIdStr != null) { + typeIdList.add(typeIdStr); + } + materialMap.put("type_id", typeIdList); + materialArr.add(materialMap); + } + typeMap.put("material", materialArr); + dataArr.add(typeMap); + } + Map result = new HashMap<>(); + result.put("data", dataArr); + result.put("code", 200); + result.put("msg", "OK"); + return result; + } + + /** + * 师傅报价接口 + * POST /api/worker/estimate + */ + @PostMapping("/api/worker/estimate") + public AjaxResult workerEstimate(@RequestBody Map params, HttpServletRequest request) throws Exception { + if (params == null) { + return AppletControllerUtil.appletError("参数错误"); + } + // 1. 计算金额 + BigDecimal GoodsAllPrice = BigDecimal.ZERO; + BigDecimal ServiceAllPrice = BigDecimal.ZERO; + BigDecimal totalPrice = BigDecimal.ZERO; + List> craftList = (List>) params.get("craft"); + if (craftList != null) { + for (Map craft : craftList) { + Long craftId = null; + try { + craftId = Long.valueOf(craft.get("id").toString()); + } catch (Exception ignore) { + } + if (craftId != null) { + QuoteCraft quoteCraft = quoteCraftService.selectQuoteCraftById(craftId); + if (quoteCraft != null) { + BigDecimal price = new BigDecimal(craft.get("price").toString()); + Integer count = craft.get("count") == null ? 1 : Integer.parseInt(craft.get("count").toString()); + totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); + ServiceAllPrice = ServiceAllPrice.add(price.multiply(BigDecimal.valueOf(count))); + } + } + } + } + List> materialList = (List>) params.get("material"); + if (materialList != null) { + for (Map material : materialList) { + Long materialId = null; + try { + materialId = Long.valueOf(material.get("id").toString()); + } catch (Exception ignore) { + } + if (materialId != null) { + QuoteMaterial quoteMaterial = quoteMaterialService.selectQuoteMaterialById(materialId); + if (quoteMaterial != null) { + BigDecimal price = new BigDecimal(material.get("price").toString()); + Integer count = material.get("count") == null ? 1 : Integer.parseInt(material.get("count").toString()); + totalPrice = totalPrice.add(price.multiply(BigDecimal.valueOf(count))); + GoodsAllPrice = GoodsAllPrice.add(price.multiply(BigDecimal.valueOf(count))); + } + } + } + } + BigDecimal reductionPrice = BigDecimal.ZERO; + String reduction = params.get("reduction").toString(); + if (reduction != null && !reduction.trim().isEmpty()) { + reductionPrice = new BigDecimal(reduction); + totalPrice = totalPrice.subtract(reductionPrice); + } + // 2. 组装新json + Map resultJson = new LinkedHashMap<>(); + // project + Map project = new LinkedHashMap<>(); + project.put("name", "项目费用"); + project.put("price", totalPrice); + resultJson.put("project", project); + Map reductionproject = new LinkedHashMap<>(); + reductionproject.put("name", "优惠金额"); + reductionproject.put("price", params.get("reduction")); + resultJson.put("reduction", reductionproject); + Map depositproject = new LinkedHashMap<>(); + depositproject.put("name", "定金"); + depositproject.put("price", params.get("price")); + resultJson.put("deposit", depositproject); + // basic + resultJson.put("basic", params.get("basic")); + + // craft + List> craftListNew = new ArrayList<>(); + if (craftList != null) { + for (Map craft : craftList) { + Map item = new LinkedHashMap<>(); + item.put("name", craft.get("title") != null ? craft.get("title") : craft.get("name")); + item.put("price", craft.get("price")); + item.put("count", craft.get("count")); + craftListNew.add(item); + } + } + resultJson.put("craft", craftListNew); + // material + List> materialListNew = new ArrayList<>(); + if (materialList != null) { + for (Map material : materialList) { + Map item = new LinkedHashMap<>(); + item.put("name", material.get("title") != null ? material.get("title") : material.get("name")); + item.put("price", material.get("price")); + item.put("count", material.get("count")); + materialListNew.add(item); + } + } + resultJson.put("material", materialListNew); + // 3. 转为字符串 + String contentStr = JSONObject.toJSONString(resultJson); + // 4. 订单相关处理 + Long orderId = null; + if (params.get("id") != null) { + try { + orderId = Long.valueOf(params.get("id").toString()); + } catch (Exception ignore) { + } + } + if (orderId == null) { + return AppletControllerUtil.appletError("订单ID格式错误"); + } + Order order = orderService.selectOrderById(orderId); + if (order == null) { + return AppletControllerUtil.appletError("订单不存在"); + } + order.setJsonStatus(6); + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type", 5); + order.setLogJson(jsonObject.toJSONString()); + // order.setTotalPrice(totalPrice); + // order.setUpdatedAt(new Date()); + order.setGoodPrice(GoodsAllPrice); + order.setServicePrice(ServiceAllPrice); + int update = orderService.updateOrder(order); + if (update > 0) { + OrderLog log = new OrderLog(); + log.setOid(order.getId()); + log.setOrderId(order.getOrderId()); + log.setType(new BigDecimal(5)); + log.setContent(contentStr); + log.setTitle("已检查评估报价"); + if (params.get("price") != null) { + log.setDeposit(new BigDecimal(params.get("price").toString())); + log.setDepPaid(1); + log.setDepLogId(GenerateCustomCode.generCreateOrder("RED")); + }else { + log.setDeposit(BigDecimal.ZERO); + } + log.setPrice(totalPrice.add(reductionPrice)); + log.setPaid(1l); + if (params.get("reduction") != null) { + log.setReductionPrice(new BigDecimal(params.get("reduction").toString())); + } else { + log.setReductionPrice(BigDecimal.ZERO); + } + log.setWorkerCost(ServiceAllPrice.subtract(reductionPrice)); + //log.set + log.setLogId(GenerateCustomCode.generCreateOrder("EST")); + log.setWorkerLogId(order.getWorkerId()); + log.setWorkerId(order.getWorkerId()); + orderLogService.insertOrderLog(log); + Users user = usersService.selectUsersById(order.getUid()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + //小程序推送用户报价成功 + WXsendMsgUtil.sendWorkerADDmoney(user.getOpenid(), order, serviceGoods); + return AppletControllerUtil.appletSuccess("报价成功"); + } else { + return AppletControllerUtil.appletError("报价失败"); + } + } + + /** + * 师傅开始服务接口 + * POST /api/worker/do/service + * 参数:{"oid":订单id,"image":[图片url数组]} + */ + @PostMapping("/api/worker/do/service") + public AjaxResult workerDoService(@RequestBody Map params, HttpServletRequest request) { + Long oid = 0L; + if (params.get("oid") != null) { + try { + oid = Long.valueOf(params.get("oid").toString()); + } catch (Exception e) { + return AppletControllerUtil.appletError("订单ID格式错误"); + } + } + Order order = orderService.selectOrderById(oid); + // 获取当前师傅id + if (order != null) { + Long workerId = order.getWorkerId(); + if (order.getJsonStatus() == 6) { + //开始服务 + // 1. 修改订单状态 + order.setStatus(3L); // 服务中 + order.setJsonStatus(7); // 服务中 + order.setLogJson("{\"type\":6}"); + order.setIsPause(1); // 服务中 + order.setUpdatedAt(new Date()); + int update = orderService.updateOrder(order); + if (update > 0) { + // 2. 组装日志内容为数组格式 + Map logItem = new LinkedHashMap<>(); + logItem.put("name", "师傅开始服务"); + logItem.put("image", params.get("image")); + logItem.put("type", 1); + List logArr = new ArrayList<>(); + logArr.add(logItem); + String contentStr = JSONObject.toJSONString(logArr); + // 3. 写入订单日志 + OrderLog log = new OrderLog(); + log.setOid(order.getId()); + log.setOrderId(order.getOrderId()); + log.setTitle("开始服务"); + log.setType(new BigDecimal(6.0)); + log.setContent(contentStr); + log.setWorkerId(workerId); + log.setWorkerLogId(workerId); + log.setIsPause(1); + log.setCreatedAt(new Date()); + orderLogService.insertOrderLog(log); + return AppletControllerUtil.appletSuccess("服务已开始"); + } else { + return AppletControllerUtil.appletError("操作失败"); + } + } + } else { + OrderLog newlog = orderLogService.selectOrderLogById(Long.valueOf(params.get("id").toString())); + Order storder = orderService.selectOrderById(newlog.getOid()); + if (storder.getJsonStatus() == 7) { + if (newlog != null) { + newlog.setIsPause(2); + JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); + // 2. 组装日志内容为数组格式 + Map logItem = new LinkedHashMap<>(); + logItem.put("name", "暂停服务"); + logItem.put("image", params.get("image")); + logItem.put("reson", params.get("reson")); + logItem.put("next_time", params.get("next_time")); + logItem.put("time", new Date()); + logItem.put("type", 2); + jsonArray.add(logItem); + newlog.setContent(jsonArray.toJSONString()); + orderLogService.updateOrderLog(newlog); + + if (storder != null) { + // 1. 修改订单状态 + storder.setStatus(3L); // 服务中 + storder.setJsonStatus(8); // 服务中 + storder.setLogJson("{\"type\":6}"); + storder.setIsPause(2); // 服务中 + storder.setUpdatedAt(new Date()); + orderService.updateOrder(storder); + } + } + return AppletControllerUtil.appletSuccess("操作成功"); + } + if (storder.getJsonStatus() == 8) { + + if (newlog != null) { + newlog.setIsPause(1); + JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); + Map logItem = new LinkedHashMap<>(); + logItem.put("name", "继续服务"); + logItem.put("image", ""); + logItem.put("time", new Date()); + logItem.put("type", 1); + jsonArray.add(logItem); + newlog.setContent(jsonArray.toJSONString()); + orderLogService.updateOrderLog(newlog); + if (storder != null) { + //继续服务 + storder.setStatus(3L); // 服务中 + storder.setJsonStatus(7); // 服务中 + storder.setLogJson("{\"type\":6}"); + storder.setIsPause(1); // 服务中 + storder.setUpdatedAt(new Date()); + orderService.updateOrder(storder); + } + } + return AppletControllerUtil.appletSuccess("操作成功"); + } + } + return AppletControllerUtil.appletSuccess("操作成功"); + } + /** + * 师傅完成订单接口 + * POST /api/worker/finish/service + * 参数:{"id":订单id,"image":[图片url数组]} + */ + @PostMapping("/api/worker/finish/service") + public AjaxResult workerFinishService(@RequestBody Map params, HttpServletRequest request) throws Exception { + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletError("参数错误"); + } + Long id; + try { + id = Long.valueOf(params.get("id").toString()); } catch (Exception e) { return AppletControllerUtil.appletError("订单ID格式错误"); } - } - - Order order = orderService.selectOrderById(oid); - // 获取当前师傅id - - if (order != null) { - Long workerId = order.getWorkerId(); - if (order.getJsonStatus() == 6) { - //开始服务 - // 1. 修改订单状态 - order.setStatus(3L); // 服务中 - order.setJsonStatus(7); // 服务中 - order.setLogJson("{\"type\":6}"); - order.setIsPause(1); // 服务中 - order.setUpdatedAt(new Date()); - int update = orderService.updateOrder(order); - if (update > 0) { - // 2. 组装日志内容为数组格式 - Map logItem = new LinkedHashMap<>(); - logItem.put("name", "师傅开始服务"); - logItem.put("image", params.get("image")); - logItem.put("type", 1); - List logArr = new ArrayList<>(); - logArr.add(logItem); - String contentStr = JSONObject.toJSONString(logArr); - // 3. 写入订单日志 - OrderLog log = new OrderLog(); - log.setOid(order.getId()); - log.setOrderId(order.getOrderId()); - log.setTitle("开始服务"); - log.setType(new BigDecimal(6.0)); - log.setContent(contentStr); - log.setWorkerId(workerId); - log.setWorkerLogId(workerId); - log.setIsPause(1); - log.setCreatedAt(new Date()); - orderLogService.insertOrderLog(log); - return AppletControllerUtil.appletSuccess("服务已开始"); - } else { - return AppletControllerUtil.appletError("操作失败"); - } + Order order = orderService.selectOrderById(id); + if (order == null) { + return AppletControllerUtil.appletError("订单不存在"); } - } else { - OrderLog newlog = orderLogService.selectOrderLogById(Long.valueOf(params.get("id").toString())); - Order storder = orderService.selectOrderById(newlog.getOid()); - if (storder.getJsonStatus() == 7) { - if (newlog != null) { - newlog.setIsPause(2); - JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); - // 2. 组装日志内容为数组格式 - Map logItem = new LinkedHashMap<>(); - logItem.put("name", "暂停服务"); - logItem.put("image", params.get("image")); - logItem.put("reson", params.get("reson")); - logItem.put("next_time", params.get("next_time")); - logItem.put("time", new Date()); - logItem.put("type", 2); - jsonArray.add(logItem); - newlog.setContent(jsonArray.toJSONString()); - orderLogService.updateOrderLog(newlog); + // 1. 修改订单状态 + order.setStatus(6L); // 完成 + order.setReceiveType(3L); // 完成类型 + order.setJsonStatus(9); // 完成 + order.setLogJson("{\"type\":8}"); + int update = orderService.updateOrder(order); + if (update > 0) { + // 2. 组装日志内容 + Map logContent = new LinkedHashMap<>(); + logContent.put("name", "师傅服务完成"); + logContent.put("image", params.get("image")); + String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logContent); + // 3. 写入订单日志 + OrderLog log = new OrderLog(); + log.setOid(order.getId()); + log.setOrderId(order.getOrderId()); + log.setTitle("服务完成"); + log.setType(new java.math.BigDecimal(7)); + log.setContent(contentStr); + log.setWorkerId(order.getWorkerId()); + log.setCreatedAt(new Date()); + orderLogService.insertOrderLog(log); + Users users = usersService.selectUsersById(order.getUid()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + WXsendMsgUtil.sendWorkerFinishOrder(users.getOpenid(), order, serviceGoods); + return AppletControllerUtil.appletSuccess("服务已完成"); + } else { + return AppletControllerUtil.appletError("操作失败"); + } + } + /** + * 结束订单 + * POST + * 参数:{"id":订单id} + */ + @PostMapping("/api/worker/order/end") + public AjaxResult workerOrderEnd(@RequestBody Map params, HttpServletRequest request) { + // 1. 参数校验 + if (params.get("id") == null) { + return AjaxResult.error("系统错误"); + } + Long id = Long.valueOf(params.get("id").toString()); + Order orderInfo = orderService.selectOrderById(id); + if (orderInfo == null) { + return AjaxResult.error("订单不存在"); + } + Users workerInfo = usersService.selectUsersById(orderInfo.getWorkerId()); + if (workerInfo == null) { + return AjaxResult.error("师傅记录不存在"); + } + // 2. 状态判断 + String msg = null; + switch (orderInfo.getStatus().intValue()) { + case 1: + msg = "还未接单,不能结束订单"; + break; + case 3: + msg = "服务还在进行中,不能提前结束订单"; + break; + case 4: + msg = "订单已完成"; + break; + case 5: + msg = "订单已取消"; + break; + case 6: + case 7: + msg = "订单已结束"; + break; + } + if (msg != null) { + return AjaxResult.error(msg); + } + try { + // 3.1 更新订单状态为7(已结束) + Order updateOrder = new Order(); + updateOrder.setId(id); + updateOrder.setStatus(7L); + orderService.updateOrder(updateOrder); - if (storder != null) { - // 1. 修改订单状态 - storder.setStatus(3L); // 服务中 - storder.setJsonStatus(8); // 服务中 - storder.setLogJson("{\"type\":6}"); - storder.setIsPause(2); // 服务中 - storder.setUpdatedAt(new Date()); - orderService.updateOrder(storder); + // 3.2 插入订单日志 + OrderLog log = new OrderLog(); + log.setOid(orderInfo.getId()); + log.setOrderId(orderInfo.getOrderId()); + log.setTitle("结束订单"); + log.setType(BigDecimal.valueOf(10)); + log.setContent("{\"name\":\"师傅提前结束订单\"}"); + //Long workerId = getCurrentWorkerId(request); // 需实现 + log.setWorkerId(workerInfo.getId()); + log.setCreatedAt(new Date()); + log.setUpdatedAt(new Date()); + orderLogService.insertOrderLog(log); + + // 3.3 查询是否有上门费(type=2, paid=2) + OrderLog doorPriceLogself = new OrderLog(); + doorPriceLogself.setOid(orderInfo.getId()); + doorPriceLogself.setType(BigDecimal.valueOf(2)); + doorPriceLogself.setPaid(2L); + doorPriceLogself.setWorkerId(workerInfo.getId()); + OrderLog doorPriceLog = orderLogService.selectOneByOidTypeWorkerIdPaid(doorPriceLogself); + if (doorPriceLog != null && doorPriceLog.getPrice() != null) { + // 师傅等级信息 + //Users workerInfo = usersService.selectUsersById(workerId); + WorkerLevel levelInfo = workerLevelService.selectWorkerLevelByLevel(Long.valueOf(workerInfo.getLevel())); + // 更新师傅佣金 + BigDecimal price = doorPriceLog.getPrice(); + Users updateUser = new Users(); + updateUser.setId(workerInfo.getId()); + updateUser.setCommission(workerInfo.getCommission().add(price)); + updateUser.setTotalComm(workerInfo.getTotalComm().add(price)); + usersService.updateUsers(updateUser); + // 插入师傅金额记录 + WorkerMoneyLog moneyLog = new WorkerMoneyLog(); + moneyLog.setWorkerId(workerInfo.getId()); + moneyLog.setOid(orderInfo.getId()); + moneyLog.setOrderId(orderInfo.getOrderId()); + moneyLog.setPrice(price); + moneyLog.setType(1); + moneyLog.setServicePrice(BigDecimal.ZERO); + moneyLog.setReductionPrice(BigDecimal.ZERO); + moneyLog.setCr(Math.toIntExact(levelInfo != null ? levelInfo.getCr() : null)); + moneyLog.setMergin(BigDecimal.ZERO); + moneyLog.setDoorPrice(price); + + moneyLog.setStatus(1);//锁单 + moneyLog.setStatusType(0);//后台锁定 + moneyLog.setBeginlook(new Date()); + //7天锁单 + LocalDateTime ldt = LocalDateTime.now().plusDays(7); + Date end = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); + moneyLog.setEndlook(end); + moneyLog.setLookday(7); + moneyLog.setLookMoney(price); + workerMoneyLogService.insertWorkerMoneyLog(moneyLog); + } + // 3.4 解绑虚拟号 + if (orderInfo.getMiddlePhone() != null) { + VoiceResponseResult unbind = YunXinPhoneUtilAPI.httpsPrivacyUnbind(orderInfo.getWorkerPhone(), orderInfo.getUserPhone(), orderInfo.getMiddlePhone()); + if (unbind.getResult().equals("000000")) { + Order phoneUpdate = new Order(); + phoneUpdate.setId(orderInfo.getId()); + phoneUpdate.setMiddlePhone(null); + phoneUpdate.setUserPhone(null); + phoneUpdate.setWorkerPhone(null); + orderService.updateOrder(phoneUpdate); } } - return AppletControllerUtil.appletSuccess("操作成功"); - } - if (storder.getJsonStatus() == 8) { - - if (newlog != null) { - newlog.setIsPause(1); - JSONArray jsonArray = JSONArray.parseArray(newlog.getContent()); - Map logItem = new LinkedHashMap<>(); - logItem.put("name", "继续服务"); - logItem.put("image", ""); - logItem.put("time", new Date()); - logItem.put("type", 1); - jsonArray.add(logItem); - newlog.setContent(jsonArray.toJSONString()); - orderLogService.updateOrderLog(newlog); - if (storder != null) { - //继续服务 - storder.setStatus(3L); // 服务中 - storder.setJsonStatus(7); // 服务中 - storder.setLogJson("{\"type\":6}"); - storder.setIsPause(1); // 服务中 - storder.setUpdatedAt(new Date()); - orderService.updateOrder(storder); - } - - } - return AppletControllerUtil.appletSuccess("操作成功"); + return AjaxResult.success("订单结束成功"); + } catch (Exception e) { + return AjaxResult.error("订单结束失败:" + e.getMessage()); } } - return AppletControllerUtil.appletSuccess("操作成功"); -} - -/** - * 师傅完成订单接口 - * POST /api/worker/finish/service - * 参数:{"id":订单id,"image":[图片url数组]} - */ -@PostMapping("/api/worker/finish/service") -public AjaxResult workerFinishService(@RequestBody Map params, HttpServletRequest request) throws Exception { - if (params == null || params.get("id") == null) { - return AppletControllerUtil.appletError("参数错误"); - } - Long id; - try { - id = Long.valueOf(params.get("id").toString()); - } catch (Exception e) { - return AppletControllerUtil.appletError("订单ID格式错误"); - } - Order order = orderService.selectOrderById(id); - if (order == null) { - return AppletControllerUtil.appletError("订单不存在"); - } - // 1. 修改订单状态 - order.setStatus(6L); // 完成 - order.setReceiveType(3L); // 完成类型 - order.setJsonStatus(9); // 完成 - order.setLogJson("{\"type\":8}"); - int update = orderService.updateOrder(order); - if (update > 0) { - // 2. 组装日志内容 - Map logContent = new LinkedHashMap<>(); - logContent.put("name", "师傅服务完成"); - logContent.put("image", params.get("image")); - String contentStr = com.alibaba.fastjson2.JSONObject.toJSONString(logContent); - // 3. 写入订单日志 - OrderLog log = new OrderLog(); - log.setOid(order.getId()); - log.setOrderId(order.getOrderId()); - log.setTitle("服务完成"); - log.setType(new java.math.BigDecimal(7)); - log.setContent(contentStr); - log.setWorkerId(order.getWorkerId()); - log.setCreatedAt(new Date()); - orderLogService.insertOrderLog(log); - Users users = usersService.selectUsersById(order.getUid()); - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - WXsendMsgUtil.sendWorkerFinishOrder(users.getOpenid(), order, serviceGoods); - return AppletControllerUtil.appletSuccess("服务已完成"); - } else { - return AppletControllerUtil.appletError("操作失败"); - } -} - -/** - * 结束订单 - * POST - * 参数:{"id":订单id} - */ -@PostMapping("/api/worker/order/end") -public AjaxResult workerOrderEnd(@RequestBody Map params, HttpServletRequest request) { - // 1. 参数校验 - if (params.get("id") == null) { - return AjaxResult.error("系统错误"); - } - Long id = Long.valueOf(params.get("id").toString()); - Order orderInfo = orderService.selectOrderById(id); - if (orderInfo == null) { - return AjaxResult.error("订单不存在"); - } - Users workerInfo = usersService.selectUsersById(orderInfo.getWorkerId()); - if (workerInfo == null) { - return AjaxResult.error("师傅记录不存在"); - } - // 2. 状态判断 - String msg = null; - switch (orderInfo.getStatus().intValue()) { - case 1: - msg = "还未接单,不能结束订单"; - break; - case 3: - msg = "服务还在进行中,不能提前结束订单"; - break; - case 4: - msg = "订单已完成"; - break; - case 5: - msg = "订单已取消"; - break; - case 6: - case 7: - msg = "订单已结束"; - break; - } - if (msg != null) { - return AjaxResult.error(msg); - } - try { - // 3.1 更新订单状态为7(已结束) - Order updateOrder = new Order(); - updateOrder.setId(id); - updateOrder.setStatus(7L); - orderService.updateOrder(updateOrder); - - // 3.2 插入订单日志 - OrderLog log = new OrderLog(); - log.setOid(orderInfo.getId()); - log.setOrderId(orderInfo.getOrderId()); - log.setTitle("结束订单"); - log.setType(BigDecimal.valueOf(10)); - log.setContent("{\"name\":\"师傅提前结束订单\"}"); - //Long workerId = getCurrentWorkerId(request); // 需实现 - log.setWorkerId(workerInfo.getId()); - log.setCreatedAt(new Date()); - log.setUpdatedAt(new Date()); - orderLogService.insertOrderLog(log); - - // 3.3 查询是否有上门费(type=2, paid=2) - OrderLog doorPriceLogself = new OrderLog(); - doorPriceLogself.setOid(orderInfo.getId()); - doorPriceLogself.setType(BigDecimal.valueOf(2)); - doorPriceLogself.setPaid(2L); - doorPriceLogself.setWorkerId(workerInfo.getId()); - OrderLog doorPriceLog = orderLogService.selectOneByOidTypeWorkerIdPaid(doorPriceLogself); - if (doorPriceLog != null && doorPriceLog.getPrice() != null) { - // 师傅等级信息 - //Users workerInfo = usersService.selectUsersById(workerId); - WorkerLevel levelInfo = workerLevelService.selectWorkerLevelByLevel(Long.valueOf(workerInfo.getLevel())); - // 更新师傅佣金 - BigDecimal price = doorPriceLog.getPrice(); - Users updateUser = new Users(); - updateUser.setId(workerInfo.getId()); - updateUser.setCommission(workerInfo.getCommission().add(price)); - updateUser.setTotalComm(workerInfo.getTotalComm().add(price)); - usersService.updateUsers(updateUser); - // 插入师傅金额记录 - WorkerMoneyLog moneyLog = new WorkerMoneyLog(); - moneyLog.setWorkerId(workerInfo.getId()); - moneyLog.setOid(orderInfo.getId()); - moneyLog.setOrderId(orderInfo.getOrderId()); - moneyLog.setPrice(price); - moneyLog.setType(1); - moneyLog.setServicePrice(BigDecimal.ZERO); - moneyLog.setReductionPrice(BigDecimal.ZERO); - moneyLog.setCr(Math.toIntExact(levelInfo != null ? levelInfo.getCr() : null)); - moneyLog.setMergin(BigDecimal.ZERO); - moneyLog.setDoorPrice(price); - - moneyLog.setStatus(1);//锁单 - moneyLog.setStatusType(0);//后台锁定 - moneyLog.setBeginlook(new Date()); - //7天锁单 - LocalDateTime ldt = LocalDateTime.now().plusDays(7); - Date end = Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); - moneyLog.setEndlook(end); - moneyLog.setLookday(7); - moneyLog.setLookMoney(price); -// moneyLog.setCreatedAt(new Date()); -// moneyLog.setUpdatedAt(new Date()); - workerMoneyLogService.insertWorkerMoneyLog(moneyLog); + /** + * 云信交互式语音通知呼叫结果推送回调接口 + * 用于接收云信平台推送的交互式语音通知呼叫结果。 + * + * @param requestBody 云信平台推送的JSON字符串 + * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 + */ + @PostMapping("/api/voice/interactNotify/resultCallback") + public Map voiceInteractNotifyResultCallback(@RequestBody String requestBody) { + // 解析请求体(可根据业务需要保存或处理字段) + try { + JSONObject json = JSONObject.parseObject(requestBody); + // 可提取字段:accountId、callId、calleeNumber、startCallTime、endTime、duration等 + // String accountId = json.getString("accountId"); + // String callId = json.getString("callId"); + // ... 其他字段 + // 这里可以根据业务需求进行日志记录、数据库保存等操作 + } catch (Exception e) { + // 解析异常可记录日志 } - // 3.4 解绑虚拟号 - if (orderInfo.getMiddlePhone() != null) { - VoiceResponseResult unbind = YunXinPhoneUtilAPI.httpsPrivacyUnbind(orderInfo.getWorkerPhone(), orderInfo.getUserPhone(), orderInfo.getMiddlePhone()); - if (unbind.getResult().equals("000000")) { - Order phoneUpdate = new Order(); - phoneUpdate.setId(orderInfo.getId()); - phoneUpdate.setMiddlePhone(null); - phoneUpdate.setUserPhone(null); - phoneUpdate.setWorkerPhone(null); - orderService.updateOrder(phoneUpdate); - } - } - return AjaxResult.success("订单结束成功"); - } catch (Exception e) { - return AjaxResult.error("订单结束失败:" + e.getMessage()); + // 必须返回{"resultCode":"200"},否则云信会认为推送失败 + Map resp = new java.util.HashMap<>(); + resp.put("resultCode", "200"); + return resp; } -} - -/** - * 云信交互式语音通知呼叫结果推送回调接口 - * 用于接收云信平台推送的交互式语音通知呼叫结果。 - * - * @param requestBody 云信平台推送的JSON字符串 - * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 - */ -@PostMapping("/api/voice/interactNotify/resultCallback") -public Map voiceInteractNotifyResultCallback(@RequestBody String requestBody) { - // 解析请求体(可根据业务需要保存或处理字段) - try { - JSONObject json = JSONObject.parseObject(requestBody); - // 可提取字段:accountId、callId、calleeNumber、startCallTime、endTime、duration等 - // String accountId = json.getString("accountId"); - // String callId = json.getString("callId"); - // ... 其他字段 - // 这里可以根据业务需求进行日志记录、数据库保存等操作 - } catch (Exception e) { - // 解析异常可记录日志 - } - // 必须返回{"resultCode":"200"},否则云信会认为推送失败 - Map resp = new java.util.HashMap<>(); - resp.put("resultCode", "200"); - return resp; -} - - -/** - * 云信交互式小号呼叫结果推送结果推送回调接口 - * 用于接收云信平台推送的交互式语音通知呼叫结果。 - * - * @param requestBody 云信平台推送的JSON字符串 - * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 - */ -@PostMapping("/api/voice/middleNumberAXB/resultCallback") -public Map voiceInteractmiddleNumberAXBCallback(@RequestBody String requestBody) { - // 解析请求体(可根据业务需要保存或处理字段) - try { - JSONObject json = JSONObject.parseObject(requestBody); - // 可提取字段:accountId、callId、calleeNumber、startCallTime、endTime、duration等 - // String accountId = json.getString("accountId"); - // String callId = json.getString("callId"); - // ... 其他字段 - // 这里可以根据业务需求进行日志记录、数据库保存等操作 - } catch (Exception e) { - // 解析异常可记录日志 - } - // 必须返回{"resultCode":"200"},否则云信会认为推送失败 - Map resp = new java.util.HashMap<>(); - resp.put("resultCode", "200"); - return resp; -} - -/** - * 抢单大厅 - 获取可抢订单列表 - *

- * 功能说明: - * - 查询状态为1(待接单)的订单 - * - 支持分页查询 - * - 组装商品信息和系统配置 - * - 返回标准分页格式数据 - * - * @param params 请求参数,包含分页信息 - * @param request HTTP请求对象 - * @return 抢单大厅订单列表数据 - */ -@PostMapping(value = "/api/worker/grab/lst") -public AjaxResult getWorkerGrabOrderList(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 解析分页参数 - int page = 1; - int limit = 15; - - if (params.get("page") != null) { - try { - page = Integer.parseInt(params.get("page").toString()); - if (page < 1) page = 1; - } catch (NumberFormatException e) { - page = 1; - } + /** + * 云信交互式小号呼叫结果推送结果推送回调接口 + * 用于接收云信平台推送的交互式语音通知呼叫结果。 + * + * @param requestBody 云信平台推送的JSON字符串 + * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 + */ + @PostMapping("/api/voice/middleNumberAXB/resultCallback") + public Map voiceInteractmiddleNumberAXBCallback(@RequestBody String requestBody) { + // 解析请求体(可根据业务需要保存或处理字段) + try { + JSONObject json = JSONObject.parseObject(requestBody); + // 可提取字段:accountId、callId、calleeNumber、startCallTime、endTime、duration等 + // String accountId = json.getString("accountId"); + // String callId = json.getString("callId"); + // ... 其他字段 + // 这里可以根据业务需求进行日志记录、数据库保存等操作 + } catch (Exception e) { + // 解析异常可记录日志 } + // 必须返回{"resultCode":"200"},否则云信会认为推送失败 + Map resp = new java.util.HashMap<>(); + resp.put("resultCode", "200"); + return resp; + } + /** + * 抢单大厅 - 获取可抢订单列表 + *

+ * 功能说明: + * - 查询状态为1(待接单)的订单 + * - 支持分页查询 + * - 组装商品信息和系统配置 + * - 返回标准分页格式数据 + * + * @param params 请求参数,包含分页信息 + * @param request HTTP请求对象 + * @return 抢单大厅订单列表数据 + */ + @PostMapping(value = "/api/worker/grab/lst") + public AjaxResult getWorkerGrabOrderList(@RequestBody Map params, HttpServletRequest request) { + try { + // 1. 解析分页参数 + int page = 1; + int limit = 15; - if (params.get("limit") != null) { - try { - limit = Integer.parseInt(params.get("limit").toString()); - if (limit < 1) limit = 15; - if (limit > 100) limit = 100; // 限制最大每页数量 - } catch (NumberFormatException e) { - limit = 15; - } - } - - // 2. 设置分页 - PageHelper.startPage(page, limit); - - // 3. 查询状态为1(待接单)的订单 - Order orderQuery = new Order(); - orderQuery.setStatus(1L); // 待接单状态 - - List orderList = orderService.selectOrderList(orderQuery); - PageInfo pageInfo = new PageInfo<>(orderList); - - // 4. 组装订单数据 - List> formattedOrderList = new ArrayList<>(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - for (Order order : orderList) { - Map orderData = new HashMap<>(); - - // 基础订单信息 - orderData.put("id", order.getId()); - orderData.put("type", order.getType()); - orderData.put("main_order_id", order.getMainOrderId()); - orderData.put("order_id", order.getOrderId()); - orderData.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); - orderData.put("create_type", order.getCreateType()); - orderData.put("create_phone", order.getCreatePhone()); - orderData.put("uid", order.getUid()); - orderData.put("product_id", order.getProductId()); - orderData.put("name", order.getName()); - orderData.put("phone", order.getPhone()); - orderData.put("address", order.getAddress()); - - // 预约时间处理 - String makeTime = ""; - if (order.getMakeTime() != null) { + if (params.get("page") != null) { try { - // 将时间戳转换为日期格式 - Date makeDate = new Date(order.getMakeTime() * 1000L); - SimpleDateFormat makeDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - makeTime = makeDateFormat.format(makeDate); - if (order.getMakeHour() != null) { - makeTime += " " + order.getMakeHour(); + page = Integer.parseInt(params.get("page").toString()); + if (page < 1) page = 1; + } catch (NumberFormatException e) { + page = 1; + } + } + + if (params.get("limit") != null) { + try { + limit = Integer.parseInt(params.get("limit").toString()); + if (limit < 1) limit = 15; + if (limit > 100) limit = 100; // 限制最大每页数量 + } catch (NumberFormatException e) { + limit = 15; + } + } + + // 2. 设置分页 + PageHelper.startPage(page, limit); + + // 3. 查询状态为1(待接单)的订单 + Order orderQuery = new Order(); + orderQuery.setStatus(1L); // 待接单状态 + + List orderList = orderService.selectOrderList(orderQuery); + PageInfo pageInfo = new PageInfo<>(orderList); + + // 4. 组装订单数据 + List> formattedOrderList = new ArrayList<>(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + for (Order order : orderList) { + Map orderData = new HashMap<>(); + + // 基础订单信息 + orderData.put("id", order.getId()); + orderData.put("type", order.getType()); + orderData.put("main_order_id", order.getMainOrderId()); + orderData.put("order_id", order.getOrderId()); + orderData.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); + orderData.put("create_type", order.getCreateType()); + orderData.put("create_phone", order.getCreatePhone()); + orderData.put("uid", order.getUid()); + orderData.put("product_id", order.getProductId()); + orderData.put("name", order.getName()); + orderData.put("phone", order.getPhone()); + orderData.put("address", order.getAddress()); + + // 预约时间处理 + String makeTime = ""; + if (order.getMakeTime() != null) { + try { + // 将时间戳转换为日期格式 + Date makeDate = new Date(order.getMakeTime() * 1000L); + SimpleDateFormat makeDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + makeTime = makeDateFormat.format(makeDate); + if (order.getMakeHour() != null) { + makeTime += " " + order.getMakeHour(); + } + } catch (Exception e) { + makeTime = ""; } - } catch (Exception e) { - makeTime = ""; } - } - orderData.put("make_time", makeTime); - orderData.put("make_hour", order.getMakeHour()); + orderData.put("make_time", makeTime); + orderData.put("make_hour", order.getMakeHour()); - orderData.put("num", order.getNum()); - orderData.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); - orderData.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); - orderData.put("service_price", order.getServicePrice() != null ? order.getServicePrice().toString() : null); - orderData.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); - orderData.put("coupon_id", order.getCouponId()); - orderData.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); - orderData.put("pay_time", order.getPayTime()); - orderData.put("status", order.getStatus()); - orderData.put("is_pause", order.getIsPause()); - orderData.put("mark", order.getMark()); - orderData.put("address_id", order.getAddressId()); - orderData.put("sku", order.getSku()); - orderData.put("worker_id", order.getWorkerId()); - orderData.put("first_worker_id", order.getFirstWorkerId()); - orderData.put("receive_time", order.getReceiveTime() != null ? dateFormat.format(order.getReceiveTime()) : null); - orderData.put("is_comment", order.getIsComment()); - orderData.put("receive_type", order.getReceiveType()); - orderData.put("is_accept", order.getIsAccept()); - orderData.put("middle_phone", order.getMiddlePhone()); - orderData.put("user_phone", order.getUserPhone()); - orderData.put("worker_phone", order.getWorkerPhone()); - orderData.put("address_en", order.getAddressEn()); - orderData.put("uid_admin", order.getUidAdmin()); - orderData.put("address_admin", order.getAddressAdmin()); - orderData.put("log_status", order.getLogStatus()); - orderData.put("log_json", order.getLogJson()); - orderData.put("json_status", order.getJsonStatus()); - orderData.put("log_images", order.getLogImages()); - orderData.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); - orderData.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); - orderData.put("deleted_at", order.getDeletedAt()); + orderData.put("num", order.getNum()); + orderData.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + orderData.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); + orderData.put("service_price", order.getServicePrice() != null ? order.getServicePrice().toString() : null); + orderData.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); + orderData.put("coupon_id", order.getCouponId()); + orderData.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); + orderData.put("pay_time", order.getPayTime()); + orderData.put("status", order.getStatus()); + orderData.put("is_pause", order.getIsPause()); + orderData.put("mark", order.getMark()); + orderData.put("address_id", order.getAddressId()); + orderData.put("sku", order.getSku()); + orderData.put("worker_id", order.getWorkerId()); + orderData.put("first_worker_id", order.getFirstWorkerId()); + orderData.put("receive_time", order.getReceiveTime() != null ? dateFormat.format(order.getReceiveTime()) : null); + orderData.put("is_comment", order.getIsComment()); + orderData.put("receive_type", order.getReceiveType()); + orderData.put("is_accept", order.getIsAccept()); + orderData.put("middle_phone", order.getMiddlePhone()); + orderData.put("user_phone", order.getUserPhone()); + orderData.put("worker_phone", order.getWorkerPhone()); + orderData.put("address_en", order.getAddressEn()); + orderData.put("uid_admin", order.getUidAdmin()); + orderData.put("address_admin", order.getAddressAdmin()); + orderData.put("log_status", order.getLogStatus()); + orderData.put("log_json", order.getLogJson()); + orderData.put("json_status", order.getJsonStatus()); + orderData.put("log_images", order.getLogImages()); + orderData.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); + orderData.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); + orderData.put("deleted_at", order.getDeletedAt()); - // 5. 组装商品信息 - Map productData = new HashMap<>(); - if (order.getProductId() != null) { - try { - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - if (serviceGoods != null) { - productData.put("id", serviceGoods.getId()); - productData.put("title", serviceGoods.getTitle()); - productData.put("icon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); - productData.put("price", serviceGoods.getPrice() != null ? serviceGoods.getPrice().toString() : "0.00"); - } else { - // 商品不存在时的默认信息 + // 5. 组装商品信息 + Map productData = new HashMap<>(); + if (order.getProductId() != null) { + try { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods != null) { + productData.put("id", serviceGoods.getId()); + productData.put("title", serviceGoods.getTitle()); + productData.put("icon", AppletControllerUtil.buildImageUrl(serviceGoods.getIcon())); + productData.put("price", serviceGoods.getPrice() != null ? serviceGoods.getPrice().toString() : "0.00"); + } else { + // 商品不存在时的默认信息 + productData.put("id", order.getProductId()); + productData.put("title", "商品已下架"); + productData.put("icon", ""); + productData.put("price", "0.00"); + } + } catch (Exception e) { + // 查询异常时的默认信息 productData.put("id", order.getProductId()); - productData.put("title", "商品已下架"); + productData.put("title", "商品信息获取失败"); productData.put("icon", ""); productData.put("price", "0.00"); } - } catch (Exception e) { - // 查询异常时的默认信息 - productData.put("id", order.getProductId()); - productData.put("title", "商品信息获取失败"); + } else { + productData.put("id", null); + productData.put("title", ""); productData.put("icon", ""); productData.put("price", "0.00"); } - } else { - productData.put("id", null); - productData.put("title", ""); - productData.put("icon", ""); - productData.put("price", "0.00"); + orderData.put("product", productData); + + formattedOrderList.add(orderData); } - orderData.put("product", productData); - formattedOrderList.add(orderData); - } + // 6. 构建分页数据 + String baseUrl = request.getRequestURL().toString().split("\\?")[0]; + Map paginationData = AppletControllerUtil.buildPageResult(pageInfo, formattedOrderList, baseUrl); - // 6. 构建分页数据 - String baseUrl = request.getRequestURL().toString().split("\\?")[0]; - Map paginationData = AppletControllerUtil.buildPageResult(pageInfo, formattedOrderList, baseUrl); + // 7. 查询系统配置(config_one) + Map configData = new HashMap<>(); + try { + SiteConfig siteConfigQuery = new SiteConfig(); + siteConfigQuery.setName("config_one"); + List configList = siteConfigService.selectSiteConfigList(siteConfigQuery); - // 7. 查询系统配置(config_one) - Map configData = new HashMap<>(); - try { - SiteConfig siteConfigQuery = new SiteConfig(); - siteConfigQuery.setName("config_one"); - List configList = siteConfigService.selectSiteConfigList(siteConfigQuery); + if (!configList.isEmpty()) { + com.ruoyi.system.domain.SiteConfig config = configList.get(0); + String configValue = config.getValue(); - if (!configList.isEmpty()) { - com.ruoyi.system.domain.SiteConfig config = configList.get(0); - String configValue = config.getValue(); - - if (configValue != null && !configValue.trim().isEmpty()) { - try { - // 尝试解析JSON配置 - JSONObject configJson = JSONObject.parseObject(configValue); - configData.putAll(configJson); - } catch (Exception e) { - // JSON解析失败时的默认配置 + if (configValue != null && !configValue.trim().isEmpty()) { + try { + // 尝试解析JSON配置 + JSONObject configJson = JSONObject.parseObject(configValue); + configData.putAll(configJson); + } catch (Exception e) { + // JSON解析失败时的默认配置 + setDefaultConfig(configData); + } + } else { + // 配置值为空时的默认配置 setDefaultConfig(configData); } } else { - // 配置值为空时的默认配置 + // 配置不存在时的默认配置 setDefaultConfig(configData); } - } else { - // 配置不存在时的默认配置 + } catch (Exception e) { + // 查询配置异常时的默认配置 setDefaultConfig(configData); } + // 8. 构建最终返回数据 + Map responseData = new HashMap<>(); + responseData.put("data", paginationData); + responseData.put("config", configData); + return AppletControllerUtil.appletSuccess(responseData); } catch (Exception e) { - // 查询配置异常时的默认配置 - setDefaultConfig(configData); + logger.error("获取抢单大厅订单列表异常:", e); + return AppletControllerUtil.appletError("获取抢单大厅订单列表失败:" + e.getMessage()); } - - // 8. 构建最终返回数据 - Map responseData = new HashMap<>(); - responseData.put("data", paginationData); - responseData.put("config", configData); - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - logger.error("获取抢单大厅订单列表异常:", e); - return AppletControllerUtil.appletError("获取抢单大厅订单列表失败:" + e.getMessage()); } -} -/** - * 商品订单游标接口 - * - * @param params 请求参数,包含product_id(商品ID)、num(数量)、sku(规格信息) - * @param request HTTP请求对象 - * @return 返回商品ID - *

- * 接口说明: - * - 接收商品订单相关信息 - * - 调用IGoodsOrderCursorService新增一条数据 - * - 返回商品ID作为响应数据 - *

- * 请求参数格式: - * { - * "product_id": 2, - * "num": 1, - * "sku": "{\"价格\":\"长青泉 1.5L*6瓶 29.4元\",\"pic\":\"\",\"price\":\"29.4\",\"stock\":\"1000\"}" - * } - *

- * 返回格式: - * { - * "code": 200, - * "msg": "OK", - * "data": 79 - * } - */ -@PostMapping("/api/service/cursor") -public AjaxResult serviceCursor(@RequestBody Map params, HttpServletRequest request) { - try { - // 1. 参数验证 - if (params == null) { - return AppletControllerUtil.appletWarning("请求参数不能为空"); - } - - // 验证必要参数 - if (params.get("product_id") == null) { - return AppletControllerUtil.appletWarning("商品ID不能为空"); - } - - if (params.get("num") == null) { - return AppletControllerUtil.appletWarning("商品数量不能为空"); - } - - // 2. 解析参数 - Long productId; - Integer num; - String sku = params.get("sku") != null ? params.get("sku").toString() : ""; - + /** + * 商品订单游标接口 + * + * @param params 请求参数,包含product_id(商品ID)、num(数量)、sku(规格信息) + * @param request HTTP请求对象 + * @return 返回商品ID + *

+ * 接口说明: + * - 接收商品订单相关信息 + * - 调用IGoodsOrderCursorService新增一条数据 + * - 返回商品ID作为响应数据 + *

+ */ + @PostMapping("/api/service/cursor") + public AjaxResult serviceCursor(@RequestBody Map params, HttpServletRequest request) { try { - productId = Long.valueOf(params.get("product_id").toString()); - num = Integer.valueOf(params.get("num").toString()); - } catch (NumberFormatException e) { - return AppletControllerUtil.appletWarning("参数格式错误"); - } - - // 3. 验证参数有效性 - if (productId <= 0) { - return AppletControllerUtil.appletWarning("商品ID无效"); - } - - if (num <= 0) { - return AppletControllerUtil.appletWarning("商品数量必须大于0"); - } - - // 4. 验证商品是否存在 - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); - if (serviceGoods == null) { - return AppletControllerUtil.appletWarning("商品不存在"); - } - - // 5. 验证商品状态 - if (serviceGoods.getStatus() == null || !"1".equals(serviceGoods.getStatus())) { - return AppletControllerUtil.appletWarning("商品已下架或不可购买"); - } - - // 6. 验证库存(如果有库存管理) - if (serviceGoods.getStock() != null && serviceGoods.getStock() < num) { - return AppletControllerUtil.appletWarning("商品库存不足"); - } - - // 7. 解析并验证SKU信息(如果有的话) - if (sku != null && !sku.trim().isEmpty()) { + // 1. 参数验证 + if (params == null) { + return AppletControllerUtil.appletWarning("请求参数不能为空"); + } + // 验证必要参数 + if (params.get("product_id") == null) { + return AppletControllerUtil.appletWarning("商品ID不能为空"); + } + if (params.get("num") == null) { + return AppletControllerUtil.appletWarning("商品数量不能为空"); + } + // 2. 解析参数 + Long productId; + Integer num; + String sku = params.get("sku") != null ? params.get("sku").toString() : ""; try { - JSONObject skuJson = JSONObject.parseObject(sku); + productId = Long.valueOf(params.get("product_id").toString()); + num = Integer.valueOf(params.get("num").toString()); + } catch (NumberFormatException e) { + return AppletControllerUtil.appletWarning("参数格式错误"); + } + // 3. 验证参数有效性 + if (productId <= 0) { + return AppletControllerUtil.appletWarning("商品ID无效"); + } + if (num <= 0) { + return AppletControllerUtil.appletWarning("商品数量必须大于0"); + } + // 4. 验证商品是否存在 + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(productId); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("商品不存在"); + } + // 5. 验证商品状态 + if (serviceGoods.getStatus() == null || !"1".equals(serviceGoods.getStatus())) { + return AppletControllerUtil.appletWarning("商品已下架或不可购买"); + } - // 验证SKU中的库存 - if (skuJson.containsKey("stock")) { - String stockStr = skuJson.getString("stock"); - try { - int skuStock = Integer.parseInt(stockStr); - if (skuStock < num) { - return AppletControllerUtil.appletWarning("SKU库存不足"); + // 6. 验证库存(如果有库存管理) + if (serviceGoods.getStock() != null && serviceGoods.getStock() < num) { + return AppletControllerUtil.appletWarning("商品库存不足"); + } + // 7. 解析并验证SKU信息(如果有的话) + if (sku != null && !sku.trim().isEmpty()) { + try { + JSONObject skuJson = JSONObject.parseObject(sku); + // 验证SKU中的库存 + if (skuJson.containsKey("stock")) { + String stockStr = skuJson.getString("stock"); + try { + int skuStock = Integer.parseInt(stockStr); + if (skuStock < num) { + return AppletControllerUtil.appletWarning("SKU库存不足"); + } + } catch (NumberFormatException e) { + // SKU库存格式错误,忽略验证 } - } catch (NumberFormatException e) { - // SKU库存格式错误,忽略验证 } + } catch (Exception e) { + // SKU JSON格式错误,但不影响主流程 } - } catch (Exception e) { - // SKU JSON格式错误,但不影响主流程 } - } + // 8. 构建GoodsOrderCursor对象 + GoodsOrderCursor goodsOrderCursor = new GoodsOrderCursor(); + goodsOrderCursor.setProductId(productId); + goodsOrderCursor.setType(2l); + goodsOrderCursor.setNum(num.longValue()); + goodsOrderCursor.setSku(sku); - // 8. 构建GoodsOrderCursor对象 - GoodsOrderCursor goodsOrderCursor = new GoodsOrderCursor(); - goodsOrderCursor.setProductId(productId); - goodsOrderCursor.setType(2l); - goodsOrderCursor.setNum(num.longValue()); - goodsOrderCursor.setSku(sku); - - // 设置其他必要字段 -// goodsOrderCursor.setCreatedAt(new Date()); -// goodsOrderCursor.setUpdatedAt(new Date()); - - // 计算价格(从SKU或商品价格) - BigDecimal totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); - if (sku != null && !sku.trim().isEmpty()) { - try { - JSONObject skuJson = JSONObject.parseObject(sku); - if (skuJson.containsKey("price")) { - String priceStr = skuJson.getString("price"); - try { - BigDecimal skuPrice = new BigDecimal(priceStr); - totalPrice = skuPrice.multiply(BigDecimal.valueOf(num)); - } catch (NumberFormatException e) { - // SKU价格解析失败,使用商品原价 - totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); + // 设置其他必要字段 + // 计算价格(从SKU或商品价格) + BigDecimal totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); + if (sku != null && !sku.trim().isEmpty()) { + try { + JSONObject skuJson = JSONObject.parseObject(sku); + if (skuJson.containsKey("price")) { + String priceStr = skuJson.getString("price"); + try { + BigDecimal skuPrice = new BigDecimal(priceStr); + totalPrice = skuPrice.multiply(BigDecimal.valueOf(num)); + } catch (NumberFormatException e) { + // SKU价格解析失败,使用商品原价 + totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); + } } + } catch (Exception e) { + // SKU解析失败,使用商品原价 + totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); } - } catch (Exception e) { - // SKU解析失败,使用商品原价 - totalPrice = serviceGoods.getPrice().multiply(BigDecimal.valueOf(num)); } + goodsOrderCursor.setTotalPrice(totalPrice); + // goodsOrderCursor.setProductName(serviceGoods.getTitle()); + // 9. 调用服务新增数据 + int result = goodsOrderCursorService.insertGoodsOrderCursor(goodsOrderCursor); + + if (result > 0) { + // 10. 返回商品ID + return AppletControllerUtil.appletSuccess(goodsOrderCursor.getId()); + } else { + return AppletControllerUtil.appletWarning("数据保存失败"); + } + + } catch (Exception e) { + System.err.println("商品订单游标接口异常:" + e.getMessage()); + return AppletControllerUtil.appletWarning("操作失败:" + e.getMessage()); } - - goodsOrderCursor.setTotalPrice(totalPrice); - // goodsOrderCursor.setProductName(serviceGoods.getTitle()); - - // 9. 调用服务新增数据 - int result = goodsOrderCursorService.insertGoodsOrderCursor(goodsOrderCursor); - - if (result > 0) { - // 10. 返回商品ID - return AppletControllerUtil.appletSuccess(goodsOrderCursor.getId()); - } else { - return AppletControllerUtil.appletWarning("数据保存失败"); - } - - } catch (Exception e) { - System.err.println("商品订单游标接口异常:" + e.getMessage()); - return AppletControllerUtil.appletWarning("操作失败:" + e.getMessage()); } -} - - - - -/** - * 云信交互式小号呼叫结果推送结果推送回调接口 - * 用于接收云信平台推送的交互式语音通知呼叫结果。 - * - * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 - */ + /** + * 云信交互式小号呼叫结果推送结果推送回调接口 + * 用于接收云信平台推送的交互式语音通知呼叫结果。 + * + * @return 必须返回{"resultCode":"200"},否则云信认为推送失败 + */ @PostMapping("api/worker/withdraw") public Map withdraw(@RequestBody Map params, HttpServletRequest request) { // 1. 验证用户登录状态 @@ -7332,252 +6270,110 @@ public AjaxResult serviceCursor(@RequestBody Map params, HttpSer wechatTransfer.setStatus(1L); wechatTransfer.setPaid(0L); wechatTransfer.setOpenid(user.getOpenid()); - int flg= wechatTransferService.insertWechatTransfer(wechatTransfer); - if(flg>0){ - //减少师傅提现的余额 - user.setCommission(user.getCommission().subtract(moneyBigDecimal)); - //增加师傅的累计提现金额 - user.setPropose(user.getPropose().add(moneyBigDecimal)); - usersService.updateUsers(user); - } - - - - -// Map paramsMoney = new HashMap<>(); -// -// paramsMoney.put("nonce_str", GenerateCustomCode.generCreateOrder("VX")); -// paramsMoney.put("partner_trade_no", "T" + System.currentTimeMillis()); -// paramsMoney.put("partnerTradeNo", "T" + System.currentTimeMillis()); -// paramsMoney.put("openid", "oHTYB7ctO6k4ICmy73HnU0aNRZIo"); -// paramsMoney.put("check_name", "张潘"); -// paramsMoney.put("amount", "1"); -// paramsMoney.put("desc", "提现到零钱"); -// -// WechatPayUtil wechatApiUtil = new WechatPayUtil(); -// wechatApiUtil.transferToUser(paramsMoney); + int flg= wechatTransferService.insertWechatTransfer(wechatTransfer); + if(flg>0){ + //减少师傅提现的余额 + user.setCommission(user.getCommission().subtract(moneyBigDecimal)); + //增加师傅的累计提现金额 + user.setPropose(user.getPropose().add(moneyBigDecimal)); + usersService.updateUsers(user); + } Map resp = new java.util.HashMap<>(); resp.put("resultCode", "200"); return resp; } -/** - * 获取商品订单临时信息 - * - * @param id 订单临时ID - * @param request HTTP请求对象 - * @return 订单临时信息及关联商品信息 - *

- * 接口说明: - * - 根据ID查询商品订单临时数据 - * - 通过product_id关联查询商品信息 - * - 返回包含订单信息和商品详情的完整数据 - */ -@GetMapping(value = "/api/service/cursor/info/{id}") -public AjaxResult getGoodsOrderCursorInfo(@PathVariable("id") long id, HttpServletRequest request) { - try { - // 参数验证 - if (id <= 0) { - return AppletControllerUtil.appletError("订单ID无效"); + /** + * 获取商品订单临时信息 + * + * @param id 订单临时ID + * @param request HTTP请求对象 + * @return 订单临时信息及关联商品信息 + *

+ * 接口说明: + * - 根据ID查询商品订单临时数据 + * - 通过product_id关联查询商品信息 + * - 返回包含订单信息和商品详情的完整数据 + */ + @GetMapping(value = "/api/service/cursor/info/{id}") + public AjaxResult getGoodsOrderCursorInfo(@PathVariable("id") long id, HttpServletRequest request) { + try { + // 参数验证 + if (id <= 0) { + return AppletControllerUtil.appletError("订单ID无效"); + } + + // 1. 查询商品订单临时数据 + GoodsOrderCursor orderCursor = goodsOrderCursorService.selectGoodsOrderCursorById(id); + if (orderCursor == null) { + return AppletControllerUtil.appletError("订单信息不存在"); + } + + // 2. 根据product_id查询商品信息 + ServiceGoods product = null; + if (orderCursor.getProductId() != null) { + product = serviceGoodsService.selectServiceGoodsById(orderCursor.getProductId()); + } + + // 3. 构建返回数据 + Map responseData = new HashMap<>(); + + // 订单基本信息 + responseData.put("id", orderCursor.getId()); + responseData.put("product_id", orderCursor.getProductId()); + responseData.put("type", orderCursor.getType()); + responseData.put("num", orderCursor.getNum()); + responseData.put("sku", orderCursor.getSku()); + responseData.put("total_price", orderCursor.getTotalPrice() != null ? orderCursor.getTotalPrice().toString() : "0.00"); + responseData.put("postage", orderCursor.getPostage() != null ? orderCursor.getPostage().toString() : null); + responseData.put("created_at", AppletControllerUtil.formatDateToString(orderCursor.getCreatedAt())); + responseData.put("updated_at", AppletControllerUtil.formatDateToString(orderCursor.getUpdatedAt())); + + // 4. 添加商品信息 + if (product != null) { + Map productInfo = new HashMap<>(); + productInfo.put("id", product.getId()); + productInfo.put("title", product.getTitle()); + productInfo.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); + productInfo.put("stock", product.getStock()); + productInfo.put("sku_type", product.getSkuType()); + productInfo.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); + + responseData.put("product", productInfo); + } else { + // 商品不存在时的默认信息 + Map productInfo = new HashMap<>(); + productInfo.put("id", orderCursor.getProductId()); + productInfo.put("title", "商品已下架"); + productInfo.put("price", "0.00"); + productInfo.put("stock", 0); + productInfo.put("sku_type", 1); + productInfo.put("icon", ""); + + responseData.put("product", productInfo); + } + + return AppletControllerUtil.appletSuccess(responseData); + + } catch (Exception e) { + return AppletControllerUtil.appletError("查询订单信息失败:" + e.getMessage()); } - - // 1. 查询商品订单临时数据 - GoodsOrderCursor orderCursor = goodsOrderCursorService.selectGoodsOrderCursorById(id); - if (orderCursor == null) { - return AppletControllerUtil.appletError("订单信息不存在"); - } - - // 2. 根据product_id查询商品信息 - ServiceGoods product = null; - if (orderCursor.getProductId() != null) { - product = serviceGoodsService.selectServiceGoodsById(orderCursor.getProductId()); - } - - // 3. 构建返回数据 - Map responseData = new HashMap<>(); - - // 订单基本信息 - responseData.put("id", orderCursor.getId()); - responseData.put("product_id", orderCursor.getProductId()); - responseData.put("type", orderCursor.getType()); - responseData.put("num", orderCursor.getNum()); - responseData.put("sku", orderCursor.getSku()); - responseData.put("total_price", orderCursor.getTotalPrice() != null ? orderCursor.getTotalPrice().toString() : "0.00"); - responseData.put("postage", orderCursor.getPostage() != null ? orderCursor.getPostage().toString() : null); - responseData.put("created_at", AppletControllerUtil.formatDateToString(orderCursor.getCreatedAt())); - responseData.put("updated_at", AppletControllerUtil.formatDateToString(orderCursor.getUpdatedAt())); - - // 4. 添加商品信息 - if (product != null) { - Map productInfo = new HashMap<>(); - productInfo.put("id", product.getId()); - productInfo.put("title", product.getTitle()); - productInfo.put("price", product.getPrice() != null ? product.getPrice().toString() : "0.00"); - productInfo.put("stock", product.getStock()); - productInfo.put("sku_type", product.getSkuType()); - productInfo.put("icon", AppletControllerUtil.buildImageUrl(product.getIcon())); - - responseData.put("product", productInfo); - } else { - // 商品不存在时的默认信息 - Map productInfo = new HashMap<>(); - productInfo.put("id", orderCursor.getProductId()); - productInfo.put("title", "商品已下架"); - productInfo.put("price", "0.00"); - productInfo.put("stock", 0); - productInfo.put("sku_type", 1); - productInfo.put("icon", ""); - - responseData.put("product", productInfo); - } - - return AppletControllerUtil.appletSuccess(responseData); - - } catch (Exception e) { - return AppletControllerUtil.appletError("查询订单信息失败:" + e.getMessage()); } -} - - -/** - * 微信支付回调通知接口 - * - * @param request HTTP请求对象 - * @return XML格式的响应给微信服务器 - *

- * 接口说明: - * - 接收微信支付成功后的异步通知 - * - 验证签名确保数据安全性 - * - 处理支付成功后的业务逻辑 - * - 返回XML格式响应告知微信处理结果 - *

- * 微信支付回调特点: - * - 微信会POST XML数据到此接口 - * - 必须返回XML格式的成功/失败响应 - * - 如果返回失败,微信会重复发送通知 - * - 建议做幂等性处理,避免重复处理同一笔订单 - */ -@PostMapping(value = "/api/wechat/pay/notify") -public String handleWechatPayNotify(HttpServletRequest request) { - try { - // 记录回调日志(可选) - logger.info("收到微信支付回调通知,开始处理..."); - - // 1. 使用WechatPayUtil处理支付回调 - Map notifyResult = wechatPayUtil.handlePayNotify(request); - - // 2. 检查处理结果 - boolean success = (Boolean) notifyResult.get("success"); - String message = (String) notifyResult.get("message"); - - if (success) { - // 3. 获取支付信息 - Map paymentInfo = (Map) notifyResult.get("paymentInfo"); - - // 4. 处理支付成功的业务逻辑 - handlePaymentSuccessLogic(paymentInfo); - - // 5. 记录成功日志 - logger.info("微信支付回调处理成功:订单号={}, 微信交易号={}", - paymentInfo.get("outTradeNo"), paymentInfo.get("transactionId")); - - // 6. 返回成功响应给微信 - return buildSuccessResponse(); - - } else { - // 7. 处理失败情况 - logger.error("微信支付回调处理失败:{}", message); - - // 8. 返回失败响应给微信 - return buildFailResponse(message); - } - - } catch (Exception e) { - // 9. 异常处理 - logger.error("微信支付回调处理异常:", e); - - // 10. 返回异常响应给微信 - return buildFailResponse("处理异常:" + e.getMessage()); + /** + * 设置默认配置信息 + * + * @param configData 配置数据Map + */ + private void setDefaultConfig(Map configData) { + configData.put("phone", "02988256922"); + configData.put("loot_start", "00:59"); + configData.put("loot_end", "23:30"); + configData.put("margin", "10"); + configData.put("integral", "100"); + configData.put("hot", new String[]{"水电维修", "家电清洗", "灯具维修", "墙面翻新", "门窗家具", "改造维修", "防水维修"}); + configData.put("kf", ""); } -} - -/** - * 处理支付成功后的业务逻辑 - * - * @param paymentInfo 支付信息 - */ -private void handlePaymentSuccessLogic(Map paymentInfo) { - try { - String outTradeNo = (String) paymentInfo.get("outTradeNo"); - String transactionId = (String) paymentInfo.get("transactionId"); - String totalFee = (String) paymentInfo.get("totalFee"); - String timeEnd = (String) paymentInfo.get("timeEnd"); - String attach = (String) paymentInfo.get("attach"); - String openid = (String) paymentInfo.get("openid"); - - logger.info("开始处理支付成功业务逻辑:订单号={}, 金额={}", outTradeNo, totalFee); - - // TODO: 根据实际业务需求实现以下逻辑 - // 1. 更新订单状态为已支付 - // 2. 记录支付流水 - // 3. 发送支付成功通知给用户 - // 4. 触发后续业务流程(如发货、服务安排等) - // 5. 更新库存(如果是商品订单) - - // 示例:如果是商品订单临时表的支付 - if (attach != null && attach.startsWith("cursor_order:")) { - String cursorOrderId = attach.replace("cursor_order:", ""); - // 可以在这里处理商品订单临时表的状态更新 - logger.info("处理商品订单临时表支付:ID={}", cursorOrderId); - } - - // 调用AppletControllerUtil的通用支付成功处理方法 - AppletControllerUtil.handlePaymentSuccess(paymentInfo, false); - - logger.info("支付成功业务逻辑处理完成:订单号={}", outTradeNo); - - } catch (Exception e) { - logger.error("处理支付成功业务逻辑异常:", e); - // 注意:即使业务逻辑处理失败,也应该向微信返回成功响应 - // 避免微信重复发送通知,可以通过日志或其他方式处理业务异常 - } -} - -/** - * 构建成功响应XML - */ -private String buildSuccessResponse() { - return "" + - "" + - "" + - ""; -} - -/** - * 构建失败响应XML - */ -private String buildFailResponse(String message) { - return "" + - "" + - "" + - ""; -} - -/** - * 设置默认配置信息 - * - * @param configData 配置数据Map - */ -private void setDefaultConfig(Map configData) { - configData.put("phone", "02988256922"); - configData.put("loot_start", "00:59"); - configData.put("loot_end", "23:30"); - configData.put("margin", "10"); - configData.put("integral", "100"); - configData.put("hot", new String[]{"水电维修", "家电清洗", "灯具维修", "墙面翻新", "门窗家具", "改造维修", "防水维修"}); - configData.put("kf", ""); -} //---------------------------------------------------------会员模块------------------------------------------------------------------------ /** @@ -7600,7 +6396,6 @@ private void setDefaultConfig(Map configData) { if (user == null) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - // 新增参数判断逻辑:只允许 id 和 money 有一个有值,不允许两个都为空或 null,如果两个都有值,只走 id 有值的逻辑 Object idObj = params.get("id"); Object moneyObj = params.get("money"); @@ -7613,7 +6408,6 @@ private void setDefaultConfig(Map configData) { if (!idEmpty && !moneyEmpty) { moneyObj = null; } - String money = ""; UserMemberRechargeLog userMemberRechargeLog = new UserMemberRechargeLog(); userMemberRechargeLog.setUid(Math.toIntExact(user.getId())); @@ -7704,7 +6498,6 @@ private void setDefaultConfig(Map configData) { }else{ return AppletControllerUtil.appletWarning("暂无数据"); } - } catch (Exception e) { return AppletControllerUtil.appletError("获取充值类目失败:" + e.getMessage()); } @@ -7786,6 +6579,48 @@ private void setDefaultConfig(Map configData) { * @param request HTTP请求对象 * @return 保存结果 */ +// @PostMapping("/api/user/invoice/info") +// public AjaxResult saveOrUpdateUserInvoiceInfo(@RequestBody Map params, HttpServletRequest request) { +// // 1. 验证用户登录状态 +// String token = request.getHeader("token"); +// Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); +// if (!(Boolean) userValidation.get("valid")) { +// return AppletControllerUtil.appletWarning("用户未登录或token无效"); +// } +// // 2. 获取用户信息 +// Users user = (Users) userValidation.get("user"); +// if (user == null) { +// return AppletControllerUtil.appletWarning("用户信息获取失败"); +// } +// +// // 3. 构建发票信息对象 +// UsersInvoiceInfo info = new UsersInvoiceInfo(); +// info.setUid(user.getId().intValue()); +// info.setInvoiceTitle((String) params.get("invoiceTitle")); +// info.setTaxNumber((String) params.get("taxNumber")); +// info.setBankName((String) params.get("bankName")); +// info.setBankAccount((String) params.get("bankAccount")); +// info.setAddress((String) params.get("address")); +// info.setPhone((String) params.get("phone")); +// info.setEmail((String) params.get("email")); +// info.setWechat((String) params.get("wechat")); +// info.setType(Integer.parseInt(params.get("type").toString())); +// info.setCategory(Integer.parseInt(params.get("category").toString())); +// +// // 4. 保存或更新发票信息 +// Integer id = params.get("id") != null ? Integer.parseInt(params.get("id").toString()) : null; +// if (id != null) { +// info.setId(id); +// usersInvoiceInfoService.updateUsersInvoiceInfo(info); +// } else { +// usersInvoiceInfoService.insertUsersInvoiceInfo(info); +// } +// return AppletControllerUtil.appletSuccess(); +// } + + + + // ... existing code ... @PostMapping("/api/user/invoice/info") public AjaxResult saveOrUpdateUserInvoiceInfo(@RequestBody Map params, HttpServletRequest request) { // 1. 验证用户登录状态 @@ -7800,7 +6635,34 @@ private void setDefaultConfig(Map configData) { return AppletControllerUtil.appletWarning("用户信息获取失败"); } - // 3. 构建发票信息对象 + // 3. 获取新参数并校验必填 + Long orderId = params.get("orderid") != null ? Long.valueOf(params.get("orderid").toString()) : null; + Integer dataType = params.get("datatype") != null ? Integer.valueOf(params.get("datatype").toString()) : null; + if (orderId == null || dataType == null) { + return AppletControllerUtil.appletWarning("orderid和datatype不能为空"); + } + BigDecimal invoiceMoney = BigDecimal.ZERO; + String invoiceText = ""; + if (dataType == 1) { + GoodsOrder order = goodsOrderService.selectGoodsOrderById(orderId); + if (order != null) { + invoiceMoney = order.getTotalPrice(); + invoiceText = "商品订单-" + order.getOrderId(); + } + } else if (dataType == 2) { + Order order = orderService.selectOrderById(orderId); + if (order != null) { + invoiceMoney = order.getTotalPrice(); + invoiceText = "服务订单-" + order.getOrderId(); + } + } else if (dataType == 3) { + UserMemberRechargeLog recharge = userMemberRechargeLogService.selectUserMemberRechargeLogById(orderId.intValue()); + if (recharge != null) { + invoiceMoney = recharge.getInmoney(); + invoiceText = "充值订单-" + recharge.getInmoney(); + } + } + // 4. 构建发票信息对象 UsersInvoiceInfo info = new UsersInvoiceInfo(); info.setUid(user.getId().intValue()); info.setInvoiceTitle((String) params.get("invoiceTitle")); @@ -7813,8 +6675,11 @@ private void setDefaultConfig(Map configData) { info.setWechat((String) params.get("wechat")); info.setType(Integer.parseInt(params.get("type").toString())); info.setCategory(Integer.parseInt(params.get("category").toString())); - - // 4. 保存或更新发票信息 + info.setOrderid(orderId.toString()); + info.setInvoicemoney(invoiceMoney); + info.setStatus(1); + info.setInvoicetext(invoiceText); + // 5. 保存或更新发票信息 Integer id = params.get("id") != null ? Integer.parseInt(params.get("id").toString()) : null; if (id != null) { info.setId(id); @@ -7822,10 +6687,13 @@ private void setDefaultConfig(Map configData) { } else { usersInvoiceInfoService.insertUsersInvoiceInfo(info); } - return AppletControllerUtil.appletSuccess(); } + + + + /** * 查询用户发票信息列表接口 * @@ -7881,4 +6749,108 @@ private void setDefaultConfig(Map configData) { return AppletControllerUtil.appletWarning("删除失败"); } } + + +/** + * 验证用户图像和昵称是否为系统默认 + * + * @param request HTTP请求对象 + * @return 验证结果 + */ +@GetMapping("/api/user/check/default") +public AjaxResult checkUserDefault(HttpServletRequest request) { + try { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletUnauthorized(); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 验证图像和昵称是否为系统默认 + String defaultAvatar = "https://img.huafurenjia.cn/default/user_avatar.jpeg"; + String defaultName = "微信用户"; + + if (defaultAvatar.equals(user.getAvatar()) && defaultName.equals(user.getName())) { + return AppletControllerUtil.appletWarning("请修改您的图像和昵称"); + } + + return AppletControllerUtil.appletSuccess("校验通过"); + } catch (Exception e) { + System.err.println("验证用户图像和昵称异常:" + e.getMessage()); + return AppletControllerUtil.appletError("验证失败:" + e.getMessage()); + } +} + + + + + /** + * 拼团支付接口 + * IUserGroupBuyingService userGroupBuyingService; + */ + @PostMapping("api/group/once_pay") + public AjaxResult apigroupOncePay(@RequestBody Map params, HttpServletRequest request) { + // 1. 验证用户登录状态 + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return AppletControllerUtil.appletWarning("用户未登录或token无效"); + } + + // 2. 获取用户信息 + Users user = (Users) userValidation.get("user"); + if (user == null) { + return AppletControllerUtil.appletWarning("用户信息获取失败"); + } + + // 3. 验证必要参数 + if (params == null || params.get("id") == null) { + return AppletControllerUtil.appletWarning("参数不能为空"); + } + Long orderId = Long.valueOf(params.get("id").toString()); + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(orderId); + if (serviceGoods == null) { + return AppletControllerUtil.appletWarning("商品信息获取失败"); + } + UserGroupBuying userGroupBuying = new UserGroupBuying(); + userGroupBuying.setId(orderId); + userGroupBuying.setUid(user.getId()); + userGroupBuying.setStatus(Long.valueOf(4)); + userGroupBuying.setUname(user.getName()); + userGroupBuying.setProductId(serviceGoods.getId()); + userGroupBuying.setPaytype(Long.valueOf(1)); + userGroupBuying.setMoney(serviceGoods.getGroupprice()); + userGroupBuying.setOrderid(GenerateCustomCode.generCreateOrder("G")); + int flg =userGroupBuyingService.insertUserGroupBuying(userGroupBuying); + if (flg > 0) { + Map payResult = wechatPayUtil.createBatchOrderAndPay(user.getOpenid(), + userGroupBuying.getId().toString(), + new BigDecimal(0.01), + 1, + "https://7ce20b15.r5.cpolar.xyz/api/group/pay/notify"); + if (payResult != null && Boolean.TRUE.equals(payResult.get("success"))) { + Map responseData = new HashMap<>(); + responseData.put("mainOrderId", userGroupBuying.getOrderid()); + //responseData.put("orderList", orderList); + responseData.put("totalAmount", serviceGoods.getGroupprice()); + responseData.put("prepayId", payResult.get("prepayId")); + // 直接合并所有支付参数 + responseData.putAll(payResult); + return AppletControllerUtil.appletSuccess(responseData); + } else { + String errorMsg = payResult != null ? (String) payResult.get("message") : "微信支付下单失败"; + return AppletControllerUtil.appletWarning("支付下单失败:" + errorMsg); + } + } + return AppletControllerUtil.appletWarning("支付失败"); + } + + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/CursorUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/CursorUtil.java index e7275f7..fe78dc3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/CursorUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/CursorUtil.java @@ -66,7 +66,7 @@ public class CursorUtil extends BaseController { * @param request 请求对象 * @return AjaxResult */ - @PostMapping("/api/user/invoice/info") + @PostMapping("/api/user/invoicedata/info") public AjaxResult saveOrUpdateInvoiceInfo(@RequestBody Map params, HttpServletRequest request) { // 1. 校验用户登录 String token = request.getHeader("token"); @@ -111,7 +111,7 @@ public class CursorUtil extends BaseController { * @param request 请求对象 * @return AjaxResult */ - @GetMapping("/api/user/invoice/list") + @GetMapping("/api/user/invoicedata/list") public AjaxResult getInvoicelist(HttpServletRequest request) { // 1. 校验用户登录 String token = request.getHeader("token"); @@ -137,7 +137,7 @@ public class CursorUtil extends BaseController { * @param request 请求对象 * @return AjaxResult */ - @DeleteMapping("/api/user/invoice/delete/{id}") + @DeleteMapping("/api/user/invoicedata/delete/{id}") public AjaxResult deleteInvoiceInfo(@PathVariable Integer id, HttpServletRequest request) { // 1. 校验用户登录 String token = request.getHeader("token"); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java index 913bdf9..9e72edd 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/PayNotifyController.java @@ -88,7 +88,8 @@ public class PayNotifyController extends BaseController { @Autowired private IUserMemnerConsumptionLogService userMemnerConsumptionLogService; - + @Autowired + private IUserGroupBuyingService userGroupBuyingService; /** * 商品支付回调接口 @@ -175,6 +176,89 @@ public class PayNotifyController extends BaseController { + /** + * 拼团支付的回调接口 + * + * @param request HTTP请求对象 + * @return XML格式响应给微信服务器 + *IUserGroupBuyingService userGroupBuyingService; + * 处理商品订单的支付成功回调: + * 1. 验证支付签名 + * 2. 更新商品订单支付状态 + * 3. 更新订单支付时间和交易号 + * 4. 处理库存扣减等业务逻辑 + */ + @PostMapping(value = "/api/group/pay/notify") + public String apigroupPayNotify(HttpServletRequest request) { + try { + logger.info("收到商品支付回调通知,开始处理..."); + + // 1. 使用WechatPayUtil处理支付回调 + Map notifyResult = wechatPayUtil.handlePayNotify(request); + + // 2. 检查处理结果 + boolean success = (Boolean) notifyResult.get("success"); + String message = (String) notifyResult.get("message"); + + if (!success) { + logger.error("商品支付回调处理失败:{}", message); + return buildFailResponse("商品支付回调处理失败"); + } + + // 3. 获取支付信息 + Map paymentInfo = (Map) notifyResult.get("paymentInfo"); + String outTradeNo = (String) paymentInfo.get("outTradeNo"); + String transactionId = (String) paymentInfo.get("transactionId"); + String totalFee = (String) paymentInfo.get("totalFee"); + UserGroupBuying userGroupBuying = userGroupBuyingService.selectUserGroupBuyingById(Long.valueOf(outTradeNo)); + if (userGroupBuying!=null){ + userGroupBuying.setStatus(1L); + userGroupBuying.setTransactionId(transactionId); + userGroupBuying.setPaytime(new Date()); + //userGroupBuying.setMoney(userGroupBuying.getMoney()); + userGroupBuyingService.updateUserGroupBuying(userGroupBuying); +// Order order = new Order(); +// order.setType(1L); +// order.setMainOrderId(GenerateCustomCode.generCreateOrder("B")); +// order.setOrderId(userGroupBuying.getOrderid()); +// order.setTransactionId(transactionId); +// order.setCreateType(1L); +// order +// order +// order +// order +// order +// order +// order +// order +// order +// order + } + + //最后无论如何平台流水需要添加,让平台看到流水和账目 + PayMoneyLog payMoneyLog = new PayMoneyLog(); + payMoneyLog.setOid(Long.valueOf(userGroupBuying.getId())); + payMoneyLog.setOrderId(userGroupBuying.getOrderid()); + payMoneyLog.setUid(Long.valueOf(userGroupBuying.getUid())); + payMoneyLog.setUname(userGroupBuying.getUname()); + payMoneyLog.setPrice(userGroupBuying.getMoney()); + payMoneyLog.setMark("拼团支付"); + payMoneyLog.setPayTime(new Date()); + payMoneyLogService.insertPayMoneyLog(payMoneyLog); + //sendWechatMessage(users,outTradeNo); + logger.info("商品支付回调处理成功,订单号:{}", outTradeNo); + return buildSuccessResponse(); + + } catch (Exception e) { + logger.error("商品支付回调处理异常:", e); + return buildFailResponse("商品支付回调处理异常"); + } + } + + + + + /** * 商品支付回调接口 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/SiteConfigController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/SiteConfigController.java index e3728ff..ab3b5ba 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/SiteConfigController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/SiteConfigController.java @@ -2,6 +2,8 @@ package com.ruoyi.system.controller; import java.util.List; import javax.servlet.http.HttpServletResponse; + +import com.alibaba.fastjson2.JSONObject; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -69,6 +71,21 @@ public class SiteConfigController extends BaseController return success(siteConfigService.selectSiteConfigById(id)); } + + + /** + * 获取系统配置详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:SiteConfig:query')") + @GetMapping(value = "/grtConfigData/{name}") + public AjaxResult getnameInfo(@PathVariable("name") String name) + { + String json=siteConfigService.selectSiteConfigByName(name).getValue(); + JSONObject jsonObject = JSONObject.parseObject(json); + return success(jsonObject); + } + + /** * 新增系统配置 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserDemandQuotationController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserDemandQuotationController.java new file mode 100644 index 0000000..d9a641d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserDemandQuotationController.java @@ -0,0 +1,104 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.UserDemandQuotation; +import com.ruoyi.system.service.IUserDemandQuotationService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 需求报价Controller + * + * @author ruoyi + * @date 2025-07-02 + */ +@RestController +@RequestMapping("/system/quotation") +public class UserDemandQuotationController extends BaseController +{ + @Autowired + private IUserDemandQuotationService userDemandQuotationService; + + /** + * 查询需求报价列表 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:list')") + @GetMapping("/list") + public TableDataInfo list(UserDemandQuotation userDemandQuotation) + { + startPage(); + List list = userDemandQuotationService.selectUserDemandQuotationList(userDemandQuotation); + return getDataTable(list); + } + + /** + * 导出需求报价列表 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:export')") + @Log(title = "需求报价", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, UserDemandQuotation userDemandQuotation) + { + List list = userDemandQuotationService.selectUserDemandQuotationList(userDemandQuotation); + ExcelUtil util = new ExcelUtil(UserDemandQuotation.class); + util.exportExcel(response, list, "需求报价数据"); + } + + /** + * 获取需求报价详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(userDemandQuotationService.selectUserDemandQuotationById(id)); + } + + /** + * 新增需求报价 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:add')") + @Log(title = "需求报价", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody UserDemandQuotation userDemandQuotation) + { + return toAjax(userDemandQuotationService.insertUserDemandQuotation(userDemandQuotation)); + } + + /** + * 修改需求报价 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:edit')") + @Log(title = "需求报价", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody UserDemandQuotation userDemandQuotation) + { + return toAjax(userDemandQuotationService.updateUserDemandQuotation(userDemandQuotation)); + } + + /** + * 删除需求报价 + */ + @PreAuthorize("@ss.hasPermi('system:quotation:remove')") + @Log(title = "需求报价", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(userDemandQuotationService.deleteUserDemandQuotationByIds(ids)); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserGroupBuyingController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserGroupBuyingController.java new file mode 100644 index 0000000..a9d9df0 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UserGroupBuyingController.java @@ -0,0 +1,104 @@ +package com.ruoyi.system.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.UserGroupBuying; +import com.ruoyi.system.service.IUserGroupBuyingService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 拼团专区管理Controller + * + * @author ruoyi + * @date 2025-07-02 + */ +@RestController +@RequestMapping("/system/buying") +public class UserGroupBuyingController extends BaseController +{ + @Autowired + private IUserGroupBuyingService userGroupBuyingService; + + /** + * 查询拼团专区管理列表 + */ + @PreAuthorize("@ss.hasPermi('system:buying:list')") + @GetMapping("/list") + public TableDataInfo list(UserGroupBuying userGroupBuying) + { + startPage(); + List list = userGroupBuyingService.selectUserGroupBuyingList(userGroupBuying); + return getDataTable(list); + } + + /** + * 导出拼团专区管理列表 + */ + @PreAuthorize("@ss.hasPermi('system:buying:export')") + @Log(title = "拼团专区管理", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, UserGroupBuying userGroupBuying) + { + List list = userGroupBuyingService.selectUserGroupBuyingList(userGroupBuying); + ExcelUtil util = new ExcelUtil(UserGroupBuying.class); + util.exportExcel(response, list, "拼团专区管理数据"); + } + + /** + * 获取拼团专区管理详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:buying:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(userGroupBuyingService.selectUserGroupBuyingById(id)); + } + + /** + * 新增拼团专区管理 + */ + @PreAuthorize("@ss.hasPermi('system:buying:add')") + @Log(title = "拼团专区管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody UserGroupBuying userGroupBuying) + { + return toAjax(userGroupBuyingService.insertUserGroupBuying(userGroupBuying)); + } + + /** + * 修改拼团专区管理 + */ + @PreAuthorize("@ss.hasPermi('system:buying:edit')") + @Log(title = "拼团专区管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody UserGroupBuying userGroupBuying) + { + return toAjax(userGroupBuyingService.updateUserGroupBuying(userGroupBuying)); + } + + /** + * 删除拼团专区管理 + */ + @PreAuthorize("@ss.hasPermi('system:buying:remove')") + @Log(title = "拼团专区管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(userGroupBuyingService.deleteUserGroupBuyingByIds(ids)); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersController.java index c19236d..b0b82ea 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/UsersController.java @@ -48,6 +48,24 @@ public class UsersController extends BaseController return getDataTable(list); } + + + /** + * 查询【请填写功能名称】列表 + */ + @PreAuthorize("@ss.hasPermi('system:users:list')") + @GetMapping("/workerlist") + public AjaxResult workerlist() + { + Users users = new Users(); + users.setType("2"); + List list = usersService.selectUsersList(users); + return success(list); + + } + + + /** * 导出【请填写功能名称】列表 */ diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java index 6720b2c..c2eb002 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controller/WorkerApplyController.java @@ -143,6 +143,8 @@ for(WorkerApply data:list){ users.setMargin(new BigDecimal("0.00")); users.setProhibitTimeNum(0); users.setIsWork(1); + //新增需----求师傅头像使用认证时照片 昵称使用认证时姓名 + users.setAvatar(workerApply.getImage()); users.setLevel(Math.toIntExact(workerLevel.getLevel())); users.setJobNumber(jobnumber); users.setServiceCityIds(workerApply.getCityIds()); @@ -156,8 +158,6 @@ for(WorkerApply data:list){ "",//回调地址,暂时不用写,等需要的时候再去写吧 "https://img.huafurenjia.cn/",//七牛云的地址 "https://101.37.133.245:11008/voice/1.0.0/");//"实名API地址" - System.out.println("34344334电子照片" + verifyResult.get("message")); - System.out.println("34344334电子照片" + verifyResult.get("result")); if (!"000000".equals(verifyResult.get("result"))) { System.out.println("电子照片" + verifyResult.get("message")); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java index 623ee3d..12abff4 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/controllerUtil/AppletControllerUtil.java @@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.*; import com.ruoyi.system.service.*; +import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import java.io.InputStream; @@ -18,6 +19,8 @@ import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; +import javax.servlet.http.HttpServletRequest; + /** * 小程序控制器工具类 *

@@ -2450,190 +2453,44 @@ public class AppletControllerUtil { /** * 构建服务订单详情数据 - * - * @param order 订单信息 - * @param orderLogService 订单日志服务 + * @param order 订单对象 + * @param orderLogService 订单日志服务 * @param serviceGoodsService 商品服务 - * @return 完整的订单详情数据 - *

- * 功能说明: - * - 整合订单基本信息、订单日志和商品信息 - * - 格式化时间字段 - * - 处理订单日志中的内容字段 - * - 添加商品信息(标题、图标、价格等) - * - 返回完全符合前端要求的数据结构 + * @return 订单详情Map */ - public static Map buildServiceOrderDetail( - Order order, - IOrderLogService orderLogService, - IServiceGoodsService serviceGoodsService) { - + public static Map buildServiceOrderDetail(Order order, IOrderLogService orderLogService, IServiceGoodsService serviceGoodsService) { Map orderDetail = new HashMap<>(); - - try { - // 1. 映射订单基本信息 - orderDetail.put("id", order.getId()); - orderDetail.put("type", order.getType()); - orderDetail.put("main_order_id", order.getMainOrderId()); - orderDetail.put("order_id", order.getOrderId()); - orderDetail.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); - orderDetail.put("create_type", order.getCreateType()); - orderDetail.put("create_phone", order.getCreatePhone()); - orderDetail.put("uid", order.getUid()); - orderDetail.put("product_id", order.getProductId()); - orderDetail.put("name", order.getName()); - orderDetail.put("phone", order.getPhone()); - orderDetail.put("address", order.getAddress()); - orderDetail.put("make_time", AppletControllerUtil.timeStamp2Date(order)); - orderDetail.put("make_hour", order.getMakeHour()); - orderDetail.put("num", order.getNum()); - - // 2. 处理价格字段(转换为字符串格式) - orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); - orderDetail.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); - orderDetail.put("service_price", order.getServicePrice() != null ? order.getServicePrice().toString() : null); - orderDetail.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); - orderDetail.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); - - // 3. 其他基本字段 - orderDetail.put("coupon_id", order.getCouponId()); - orderDetail.put("pay_time", order.getPayTime()); - orderDetail.put("status", order.getStatus()); - orderDetail.put("is_pause", order.getIsPause()); - orderDetail.put("mark", order.getMark()); - orderDetail.put("address_id", order.getAddressId()); - orderDetail.put("sku", order.getSku()); - orderDetail.put("worker_id", order.getWorkerId()); - orderDetail.put("first_worker_id", order.getFirstWorkerId()); - orderDetail.put("receive_time", order.getReceiveTime()); - orderDetail.put("is_comment", order.getIsComment()); - orderDetail.put("receive_type", order.getReceiveType()); - orderDetail.put("is_accept", order.getIsAccept()); - orderDetail.put("middle_phone", order.getMiddlePhone()); - orderDetail.put("user_phone", order.getUserPhone()); - orderDetail.put("worker_phone", order.getWorkerPhone()); - orderDetail.put("address_en", order.getAddressEn()); - orderDetail.put("uid_admin", order.getUidAdmin()); - orderDetail.put("address_admin", order.getAddressAdmin()); - orderDetail.put("log_status", order.getLogStatus()); - orderDetail.put("log_json", order.getLogJson()); - orderDetail.put("json_status", order.getJsonStatus()); - orderDetail.put("log_images", order.getLogImages()); - // JSONArray jsonArray = new JSONArray(); - if (order.getFileData() != null){ - orderDetail.put("file_data", JSON.parseArray(order.getFileData())); - }else{ - orderDetail.put("file_data", null); + // 订单基本信息 + orderDetail.put("id", order.getId()); + orderDetail.put("order_id", order.getOrderId()); + orderDetail.put("status", order.getStatus()); + orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + orderDetail.put("num", order.getNum()); + orderDetail.put("created_at", order.getCreatedAt()); + // 商品信息 + if (order.getProductId() != null) { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods != null) { + Map productInfo = new HashMap<>(); + productInfo.put("id", serviceGoods.getId()); + productInfo.put("title", serviceGoods.getTitle()); + productInfo.put("icon", buildImageUrl(serviceGoods.getIcon())); + orderDetail.put("product", productInfo); } - - - // 4. 处理时间字段 - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - orderDetail.put("created_at", order.getCreatedAt() != null ? dateFormat.format(order.getCreatedAt()) : null); - orderDetail.put("updated_at", order.getUpdatedAt() != null ? dateFormat.format(order.getUpdatedAt()) : null); - orderDetail.put("deleted_at", order.getDeletedAt()); - - // 5. 查询并构建订单日志 - OrderLog orderLogQuery = new OrderLog(); - orderLogQuery.setOid(order.getId()); - List orderLogList = orderLogService.selectOrderLogList(orderLogQuery); - - List> logArray = new ArrayList<>(); - for (OrderLog orderLog : orderLogList) { - Map logItem = new HashMap<>(); - - logItem.put("id", orderLog.getId()); - logItem.put("oid", orderLog.getOid()); - logItem.put("order_id", orderLog.getOrderId()); - logItem.put("log_order_id", orderLog.getLogOrderId()); - logItem.put("title", orderLog.getTitle()); - logItem.put("type", orderLog.getType()); - - // 处理content字段(可能是JSON字符串) - Object content = null; - if (orderLog.getContent() != null && !orderLog.getContent().trim().isEmpty()) { - try { - content = JSONObject.parseObject(orderLog.getContent()); - } catch (Exception e) { - // 如果不是JSON格式,直接使用字符串 - content = orderLog.getContent(); - } - } - logItem.put("content", content); - - logItem.put("deposit", orderLog.getDeposit()); - logItem.put("dep_paid", orderLog.getDepPaid()); - logItem.put("dep_pay_time", orderLog.getDepPayTime()); - logItem.put("dep_log_id", orderLog.getDepLogId()); - logItem.put("price", orderLog.getPrice() != null ? orderLog.getPrice().toString() : null); - logItem.put("paid", orderLog.getPaid()); - // payTime是Long类型的时间戳,需要转换为Date后再格式化 - if (orderLog.getPayTime() != null) { - try { - Date payDate = new Date(orderLog.getPayTime() * 1000L); // 假设是秒级时间戳 - logItem.put("pay_time", dateFormat.format(payDate)); - } catch (Exception e) { - logItem.put("pay_time", "2025-06-10 17:40:58"); // 默认时间 - } - } else { - logItem.put("pay_time", "2025-06-10 17:40:58"); // 默认时间 - } - logItem.put("log_id", orderLog.getLogId()); - logItem.put("worker_id", orderLog.getWorkerId()); - logItem.put("first_worker_id", orderLog.getFirstWorkerId()); - logItem.put("give_up", orderLog.getGiveUp()); - logItem.put("worker_cost", orderLog.getWorkerCost() != null ? orderLog.getWorkerCost().toString() : null); - logItem.put("reduction_price", orderLog.getReductionPrice() != null ? orderLog.getReductionPrice().toString() : null); - logItem.put("is_pause", orderLog.getIsPause()); - logItem.put("coupon_id", orderLog.getCouponId()); - logItem.put("deduction", orderLog.getDeduction()); - logItem.put("worker_log_id", orderLog.getWorkerLogId()); - logItem.put("created_at", orderLog.getCreatedAt() != null ? dateFormat.format(orderLog.getCreatedAt()) : null); - logItem.put("updated_at", orderLog.getUpdatedAt() != null ? dateFormat.format(orderLog.getUpdatedAt()) : null); - logItem.put("deleted_at", orderLog.getDeletedAt()); - - // 处理工人信息 - if (orderLog.getWorkerId() != null) { - Map workerInfo = new HashMap<>(); - workerInfo.put("id", orderLog.getWorkerId()); - // 使用OrderLog中的workerName字段 - workerInfo.put("name", orderLog.getWorkerName() != null ? orderLog.getWorkerName() : "工人姓名"); - workerInfo.put("phone", "177********"); // 脱敏处理的手机号 - workerInfo.put("avatar", "https://img.huafurenjia.cn/images/2024-07-19/bYTmKdyVM4M392L92Ozqc3Za1VozMWX34kWWC78p.jpg"); - logItem.put("worker", workerInfo); - } else { - logItem.put("worker", null); - } - - logArray.add(logItem); - } - orderDetail.put("log", logArray); - - // 6. 查询并构建商品信息 - if (order.getProductId() != null) { - ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); - if (serviceGoods != null) { - Map productInfo = new HashMap<>(); - productInfo.put("id", serviceGoods.getId()); - productInfo.put("icon", buildImageUrl(serviceGoods.getIcon())); - productInfo.put("info", serviceGoods.getInfo()); - productInfo.put("price", serviceGoods.getPrice() != null ? serviceGoods.getPrice().toString() : "0.00"); - productInfo.put("stock", serviceGoods.getStock()); - productInfo.put("price_zn", serviceGoods.getPriceZn()); - productInfo.put("title", serviceGoods.getTitle()); - orderDetail.put("product", productInfo); - } else { - orderDetail.put("product", null); - } - } else { - orderDetail.put("product", null); - } - - } catch (Exception e) { - System.err.println("构建服务订单详情数据异常:" + e.getMessage()); - e.printStackTrace(); } - + // 订单日志 + List logList = orderLogService.selectOrderLogByOrderId(order.getOrderId()); + List> logs = new ArrayList<>(); + for (OrderLog log : logList) { + Map logMap = new HashMap<>(); + logMap.put("id", log.getId()); + logMap.put("title", log.getTitle()); + logMap.put("type", log.getType()); + logMap.put("content", log.getContent()); + logMap.put("created_at", log.getCreatedAt()); + logs.add(logMap); + } + orderDetail.put("logs", logs); return orderDetail; } @@ -3492,4 +3349,661 @@ public class AppletControllerUtil { return skuParam.toString().trim(); } } + + /** + * 获取订单状态文本 + */ + public static String getOrderStatusText(Long status) { + if (status == null) { + return "未知状态"; + } + switch (status.intValue()) { + case 1: + return "待付款"; + case 2: + return "待发货"; + case 3: + return "待收货"; + case 4: + return "待评价"; + case 5: + return "已完成"; + case 6: + return "已取消"; + case 7: + return "售后中"; + case 8: + return "已退款"; + default: + return "未知状态"; + } + } + /** + * 从请求参数构建更新用户对象 + * + * @param params 请求参数 + * @param userId 用户ID + * @return 用户更新对象 + */ + public static Users buildUpdateUserFromdataParams(Map params, Long userId) { + Users updateUser = new Users(); + updateUser.setId(userId); + + // 基本信息字段 + if (params.get("name") != null) { + updateUser.setName(params.get("name").toString().trim()); + } + + if (params.get("nickname") != null && !params.get("nickname").toString().trim().isEmpty()) { + updateUser.setNickname(params.get("nickname").toString().trim()); + } + + if (params.get("phone") != null) { + updateUser.setPhone(params.get("phone").toString().trim()); + } + + // 头像处理 - 去掉CDN前缀保存相对路径 + if (params.get("avatar") != null) { + String avatar = params.get("avatar").toString().trim(); + if (avatar.startsWith("https://img.huafurenjia.cn/")) { + avatar = avatar.replace("https://img.huafurenjia.cn/", ""); + } + updateUser.setAvatar(avatar); + } + + // 数值字段 - 根据Users实体类的实际字段类型 + if (params.get("integral") != null) { + updateUser.setIntegral(parseToLongForEdit(params.get("integral"))); + } + + if (params.get("is_stop") != null) { + Integer isStop = parseToIntegerForEdit(params.get("is_stop")); + updateUser.setIsStop(isStop); + } + + if (params.get("login_status") != null) { + Integer loginStatus = parseToIntegerForEdit(params.get("login_status")); + updateUser.setLoginStatus(loginStatus); + } + + if (params.get("status") != null) { + Integer status = parseToIntegerForEdit(params.get("status")); + updateUser.setStatus(status); + } + + if (params.get("total_integral") != null) { + updateUser.setTotalIntegral(parseToLongForEdit(params.get("total_integral"))); + } + + // 字符串和其他字段 + if (params.get("job_number") != null && !params.get("job_number").toString().trim().isEmpty()) { + Integer jobNumber = parseToIntegerForEdit(params.get("job_number")); + updateUser.setJobNumber(jobNumber); + } + + if (params.get("level") != null && !params.get("level").toString().trim().isEmpty()) { + Integer level = parseToIntegerForEdit(params.get("level")); + updateUser.setLevel(level); + } + + if (params.get("middle_auth") != null && !params.get("middle_auth").toString().trim().isEmpty()) { + Integer middleAuth = parseToIntegerForEdit(params.get("middle_auth")); + updateUser.setMiddleAuth(middleAuth); + } + + if (params.get("propose") != null) { + // propose字段是BigDecimal类型,需要转换 + String proposeStr = params.get("propose").toString().trim(); + try { + BigDecimal propose = new BigDecimal(proposeStr); + updateUser.setPropose(propose); + } catch (NumberFormatException e) { + // 忽略格式错误,保持原值 + } + } + + if (params.get("type") != null) { + // type字段是String类型 + updateUser.setType(params.get("type").toString().trim()); + } + + // 处理服务城市ID数组 + if (params.get("service_city_ids") != null) { + List serviceCityIds = (List) params.get("service_city_ids"); + if (!serviceCityIds.isEmpty()) { + updateUser.setServiceCityIds(String.join(",", serviceCityIds)); + } + } + + // 处理技能ID数组 + if (params.get("skill_ids") != null) { + List skillIds = (List) params.get("skill_ids"); + if (!skillIds.isEmpty()) { + updateUser.setSkillIds(String.join(",", skillIds)); + } + } + + // 设置更新时间 + updateUser.setUpdatedAt(new Date()); + + return updateUser; + } + /** + * 构建用户信息响应 + */ + public static Map buildUserInfoResponse(Users user) { + Map userInfo = new HashMap<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + userInfo.put("id", user.getId()); + userInfo.put("name", user.getName()); + userInfo.put("nickname", user.getNickname()); + userInfo.put("phone", user.getPhone()); + userInfo.put("password", null); + String avatar = user.getAvatar(); + if (avatar != null && !avatar.isEmpty()) { + userInfo.put("avatar", buildImageUrl(avatar)); + } else { + userInfo.put("avatar", "https://img.huafurenjia.cn/default/user_avatar.jpeg"); + } + if (user.getType().equals("2")) { + userInfo.put("commission", user.getCommission().toString() != null ? user.getCommission().toString() : "0.00"); + userInfo.put("total_comm", user.getTotalComm().toString() != null ? user.getTotalComm().toString() : "0.00"); + userInfo.put("propose", user.getPropose().toString() != null ? user.getPropose().toString() : "0.00"); + } + if (user.getType().equals("1")) { + userInfo.put("balance", user.getBalance().toString() != null ? user.getBalance().toString() : "0.00"); + userInfo.put("ismember", user.getIsmember()); + userInfo.put("member_begin",user.getMemberBegin() != null ? sdf.format(user.getMemberBegin()) : null ); + userInfo.put("member_end",user.getMemberEnd() != null ? sdf.format(user.getMemberEnd()) : null ); + } + userInfo.put("integral", user.getIntegral() != null ? user.getIntegral() : 0); + userInfo.put("is_stop", user.getIsStop() != null ? user.getIsStop() : 1); + userInfo.put("job_number", user.getJobNumber()); + userInfo.put("level", user.getLevel()); + userInfo.put("login_status", user.getLoginStatus() != null ? user.getLoginStatus() : 2); + userInfo.put("margin", user.getMargin() != null ? user.getMargin() : 0); + userInfo.put("middle_auth", user.getMiddleAuth()); + userInfo.put("openid", user.getOpenid()); + userInfo.put("prohibit_time", user.getProhibitTime()); + userInfo.put("prohibit_time_str", null); + userInfo.put("remember_token", user.getRememberToken()); + userInfo.put("status", user.getStatus() != null ? user.getStatus() : 1); + userInfo.put("tpd", 0); + userInfo.put("total_integral", user.getTotalIntegral() != null ? user.getTotalIntegral() : 100); + userInfo.put("type", user.getType() != null ? user.getType().toString() : "1"); + userInfo.put("worker_time", user.getWorkerTime()); + if (user.getCreatedAt() != null) { + userInfo.put("created_at", sdf.format(user.getCreatedAt())); + } else { + userInfo.put("created_at", null); + } + if (user.getUpdatedAt() != null) { + userInfo.put("updated_at", sdf.format(user.getUpdatedAt())); + } else { + userInfo.put("updated_at", null); + } + if (user.getServiceCityIds() != null && !user.getServiceCityIds().isEmpty()) { + userInfo.put("service_city_ids", parseStringToList(user.getServiceCityIds())); + } else { + userInfo.put("service_city_ids", new ArrayList<>()); + } + if (user.getSkillIds() != null && !user.getSkillIds().isEmpty()) { + userInfo.put("skill_ids", parseStringToList(user.getSkillIds())); + } else { + userInfo.put("skill_ids", new ArrayList<>()); + } + return userInfo; + } + + /** + * 从请求参数构建更新用户对象 + */ + public static Users buildUpdateUserFromParams(Map params, Long userId) { + Users updateUser = new Users(); + updateUser.setId(userId); + if (params.get("name") != null) { + updateUser.setName(params.get("name").toString().trim()); + } + if (params.get("nickname") != null && !params.get("nickname").toString().trim().isEmpty()) { + updateUser.setNickname(params.get("nickname").toString().trim()); + } + if (params.get("phone") != null) { + updateUser.setPhone(params.get("phone").toString().trim()); + } + if (params.get("avatar") != null) { + String avatar = params.get("avatar").toString().trim(); + if (avatar.startsWith("https://img.huafurenjia.cn/")) { + avatar = avatar.replace("https://img.huafurenjia.cn/", ""); + } + updateUser.setAvatar(avatar); + } + if (params.get("integral") != null) { + updateUser.setIntegral(parseToLongForEdit(params.get("integral"))); + } + if (params.get("is_stop") != null) { + Integer isStop = parseToIntegerForEdit(params.get("is_stop")); + updateUser.setIsStop(isStop); + } + if (params.get("login_status") != null) { + Integer loginStatus = parseToIntegerForEdit(params.get("login_status")); + updateUser.setLoginStatus(loginStatus); + } + if (params.get("status") != null) { + Integer status = parseToIntegerForEdit(params.get("status")); + updateUser.setStatus(status); + } + if (params.get("total_integral") != null) { + updateUser.setTotalIntegral(parseToLongForEdit(params.get("total_integral"))); + } + if (params.get("job_number") != null && !params.get("job_number").toString().trim().isEmpty()) { + Integer jobNumber = parseToIntegerForEdit(params.get("job_number")); + updateUser.setJobNumber(jobNumber); + } + if (params.get("level") != null && !params.get("level").toString().trim().isEmpty()) { + Integer level = parseToIntegerForEdit(params.get("level")); + updateUser.setLevel(level); + } + if (params.get("middle_auth") != null && !params.get("middle_auth").toString().trim().isEmpty()) { + Integer middleAuth = parseToIntegerForEdit(params.get("middle_auth")); + updateUser.setMiddleAuth(middleAuth); + } + if (params.get("propose") != null) { + String proposeStr = params.get("propose").toString().trim(); + try { + BigDecimal propose = new BigDecimal(proposeStr); + updateUser.setPropose(propose); + } catch (NumberFormatException e) { + } + } + if (params.get("type") != null) { + updateUser.setType(params.get("type").toString().trim()); + } + if (params.get("service_city_ids") != null) { + List serviceCityIds = (List) params.get("service_city_ids"); + if (!serviceCityIds.isEmpty()) { + updateUser.setServiceCityIds(String.join(",", serviceCityIds)); + } + } + if (params.get("skill_ids") != null) { + List skillIds = (List) params.get("skill_ids"); + if (!skillIds.isEmpty()) { + updateUser.setSkillIds(String.join(",", skillIds)); + } + } + updateUser.setUpdatedAt(new Date()); + return updateUser; + } + + /** + * 解析对象为Long类型(用于编辑接口) + */ + public static Long parseToLongForEdit(Object value) { + if (value == null) return null; + if (value instanceof Integer) { + return ((Integer) value).longValue(); + } else if (value instanceof Long) { + return (Long) value; + } else if (value instanceof String) { + try { + return Long.parseLong((String) value); + } catch (NumberFormatException e) { + return null; + } + } + return null; + } + + /** + * 解析对象为Integer类型(用于编辑接口) + */ + public static Integer parseToIntegerForEdit(Object value) { + if (value == null) return null; + if (value instanceof Integer) { + return (Integer) value; + } else if (value instanceof Long) { + return ((Long) value).intValue(); + } else if (value instanceof String) { + try { + return Integer.parseInt((String) value); + } catch (NumberFormatException e) { + return null; + } + } + return null; + } + + /** + * 验证用户编辑参数 + */ + public static String validateUserEditParams(Users user) { + if (user.getPhone() != null && !user.getPhone().isEmpty()) { + if (!user.getPhone().matches("^1[3-9]\\d{9}$")) { + return "手机号格式不正确"; + } + } + if (user.getName() != null && user.getName().length() > 50) { + return "用户名长度不能超过50个字符"; + } + if (user.getNickname() != null && user.getNickname().length() > 50) { + return "昵称长度不能超过50个字符"; + } + return null; + } + + /** + * 构建商品订单详情 + */ + public static Map buildGoodsOrderDetail(GoodsOrder order) { + Map orderDetail = new HashMap<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + orderDetail.put("id", order.getId()); + orderDetail.put("type", order.getType()); + orderDetail.put("main_order_id", order.getMainOrderId()); + orderDetail.put("order_id", order.getOrderId()); + orderDetail.put("transaction_id", order.getTransactionId() != null ? order.getTransactionId() : ""); + orderDetail.put("uid", order.getUid()); + orderDetail.put("product_id", order.getProductId()); + orderDetail.put("name", order.getName()); + orderDetail.put("phone", order.getPhone()); + orderDetail.put("num", order.getNum()); + orderDetail.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + orderDetail.put("good_price", order.getGoodPrice() != null ? order.getGoodPrice().toString() : "0.00"); + orderDetail.put("service_price", order.getServicePrice()); + orderDetail.put("pay_price", order.getPayPrice() != null ? order.getPayPrice().toString() : "0.00"); + orderDetail.put("deduction", order.getDeduction() != null ? order.getDeduction().toString() : "0.00"); + orderDetail.put("postage", order.getPostage()); + orderDetail.put("pay_time", order.getPayTime() != null ? sdf.format(order.getPayTime()) : null); + orderDetail.put("status", order.getStatus()); + orderDetail.put("delivery_id", order.getDeliveryId()); + orderDetail.put("delivery_num", order.getDeliveryNum() != null ? order.getDeliveryNum() : ""); + orderDetail.put("send_time", order.getSendTime() != null ? sdf.format(order.getSendTime()) : null); + orderDetail.put("mark", order.getMark()); + orderDetail.put("address_id", order.getAddressId()); + orderDetail.put("sku", order.getSku()); + orderDetail.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); + orderDetail.put("updated_at", order.getUpdatedAt() != null ? sdf.format(order.getUpdatedAt()) : null); + orderDetail.put("deleted_at", order.getDeletedAt() != null ? sdf.format(order.getDeletedAt()) : null); + if (order.getAddressId() != null) { + UserAddress address = userAddressService.selectUserAddressById(order.getAddressId()); + if (address != null) { + Map addressInfo = new HashMap<>(); + addressInfo.put("id", address.getId()); + addressInfo.put("uid", address.getUid()); + addressInfo.put("name", address.getName()); + addressInfo.put("phone", address.getPhone()); + addressInfo.put("latitude", address.getLatitude()); + addressInfo.put("longitude", address.getLongitude()); + addressInfo.put("address_name", address.getAddressName()); + addressInfo.put("address_info", address.getAddressInfo()); + addressInfo.put("info", address.getInfo()); + addressInfo.put("is_default", address.getIsDefault()); + addressInfo.put("created_at", address.getCreatedAt() != null ? sdf.format(address.getCreatedAt()) : null); + addressInfo.put("updated_at", address.getUpdatedAt() != null ? sdf.format(address.getUpdatedAt()) : null); + addressInfo.put("deleted_at", null); + orderDetail.put("address", addressInfo); + } + } + if (order.getProductId() != null) { + ServiceGoods product = SpringUtils.getBean(IServiceGoodsService.class).selectServiceGoodsById(order.getProductId()); + if (product != null) { + Map productInfo = new HashMap<>(); + productInfo.put("id", product.getId()); + productInfo.put("title", product.getTitle()); + productInfo.put("sub_title", product.getSubTitle()); + productInfo.put("icon", buildImageUrl(product.getIcon())); + orderDetail.put("product", productInfo); + } + } + orderDetail.put("comment", new ArrayList<>()); + orderDetail.put("delivery", new ArrayList<>()); + return orderDetail; + } + + /** + * 校验token并返回用户对象 + * @param request HTTP请求对象 + * @param usersService 用户服务 + * @return 用户对象,未登录或无效返回null + */ + public static Users validateAndGetUser(HttpServletRequest request, IUsersService usersService) { + String token = request.getHeader("token"); + Map userValidation = AppletLoginUtil.validateUserToken(token, usersService); + if (!(Boolean) userValidation.get("valid")) { + return null; + } + return (Users) userValidation.get("user"); + } + + /** + * 构建售后返修分页数据 + * @param user 当前用户 + * @param status 返修状态 + * @param page 页码 + * @param limit 每页数量 + * @param orderReworkService 返修服务 + * @return 分页数据Map + */ + public static Map buildReworkListData(Users user, int status, int page, int limit, IOrderReworkService orderReworkService) { + PageHelper.startPage(page, limit); + OrderRework queryCondition = new OrderRework(); + queryCondition.setUid(user.getId()); + queryCondition.setStatus(status); + List reworkList = orderReworkService.selectOrderReworkList(queryCondition); + PageInfo pageInfo = new PageInfo<>(reworkList); + Map responseData = new HashMap<>(); + responseData.put("current_page", pageInfo.getPageNum()); + responseData.put("data", reworkList); + responseData.put("from", pageInfo.getStartRow()); + responseData.put("last_page", pageInfo.getPages()); + responseData.put("per_page", String.valueOf(pageInfo.getPageSize())); + responseData.put("to", pageInfo.getEndRow()); + responseData.put("total", pageInfo.getTotal()); + // 分页链接 + Map prevLink = new HashMap<>(); + prevLink.put("url", null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + responseData.put("links", new Object[]{prevLink, nextLink}); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getNextPage() : null); + responseData.put("path", "https://www.huafurenjia.cn/api/service/order/rework/lst"); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? + "https://www.huafurenjia.cn/api/service/order/rework/lst?page=" + pageInfo.getPrePage() : null); + return responseData; + } + + /** + * 构建购物车分页数据 + * @param user 当前用户 + * @param page 页码 + * @param limit 每页数量 + * @param goodsCartService 购物车服务 + * @param serviceGoodsService 商品服务 + * @return 分页数据Map + */ + public static Map buildCartListData(Users user, int page, int limit, IGoodsCartService goodsCartService, IServiceGoodsService serviceGoodsService) { + PageHelper.startPage(page, limit); + GoodsCart queryCart = new GoodsCart(); + queryCart.setUid(user.getId()); + List cartList = goodsCartService.selectGoodsCartList(queryCart); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (GoodsCart cart : cartList) { + Map cartData = new HashMap<>(); + cartData.put("id", cart.getId()); + cartData.put("uid", cart.getUid()); + cartData.put("good_id", cart.getGoodId()); + cartData.put("good_num", cart.getGoodNum()); + if (cart.getSku() != null && !cart.getSku().isEmpty()) { + cartData.put("sku", com.alibaba.fastjson2.JSONObject.parseObject(cart.getSku())); + } else { + cartData.put("sku", null); + } + cartData.put("created_at", cart.getCreatedAt() != null ? sdf.format(cart.getCreatedAt()) : null); + cartData.put("updated_at", cart.getUpdatedAt() != null ? sdf.format(cart.getUpdatedAt()) : null); + // 查询并添加商品详细信息 + Map goodInfo = getGoodDetailForCart(cart.getGoodId(), serviceGoodsService); + cartData.put("good", goodInfo); + resultList.add(cartData); + } + PageInfo pageInfo = new PageInfo<>(cartList); + Map responseData = new HashMap<>(); + responseData.put("current_page", pageInfo.getPageNum()); + responseData.put("data", resultList); + responseData.put("from", pageInfo.getStartRow()); + responseData.put("last_page", pageInfo.getPages()); + responseData.put("per_page", pageInfo.getPageSize()); + responseData.put("to", pageInfo.getEndRow()); + responseData.put("total", pageInfo.getTotal()); + String baseUrl = "https://www.huafurenjia.cn/api/cart/lst"; + responseData.put("first_page_url", baseUrl + "?page=1"); + responseData.put("last_page_url", baseUrl + "?page=" + pageInfo.getPages()); + responseData.put("next_page_url", pageInfo.isHasNextPage() ? baseUrl + "?page=" + pageInfo.getNextPage() : null); + responseData.put("prev_page_url", pageInfo.isHasPreviousPage() ? baseUrl + "?page=" + pageInfo.getPrePage() : null); + responseData.put("path", baseUrl); + List> links = new ArrayList<>(); + Map prevLink = new HashMap<>(); + prevLink.put("url", pageInfo.isHasPreviousPage() ? baseUrl + "?page=" + pageInfo.getPrePage() : null); + prevLink.put("label", "« Previous"); + prevLink.put("active", false); + links.add(prevLink); + Map nextLink = new HashMap<>(); + nextLink.put("url", pageInfo.isHasNextPage() ? baseUrl + "?page=" + pageInfo.getNextPage() : null); + nextLink.put("label", "Next »"); + nextLink.put("active", false); + links.add(nextLink); + responseData.put("links", links); + return responseData; + } + + /** + * 构建商品订单分页数据 + * @param user 当前用户 + * @param page 页码 + * @param limit 每页数量 + * @param status 订单状态 + * @param goodsOrderService 商品订单服务 + * @param serviceGoodsService 商品服务 + * @return 分页数据Map + */ + public static Map buildGoodsOrderListData(Users user, int page, int limit, String status, IGoodsOrderService goodsOrderService, IServiceGoodsService serviceGoodsService) { + PageHelper.startPage(page, limit); + GoodsOrder queryOrder = new GoodsOrder(); + queryOrder.setUid(user.getId()); + if (status != null && !"".equals(status)) { + queryOrder.setStatus(Long.valueOf(status)); + } + List orderList = goodsOrderService.selectGoodsOrderList(queryOrder); + List> resultList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + for (GoodsOrder order : orderList) { + Map orderData = new HashMap<>(); + orderData.put("id", order.getId()); + orderData.put("order_id", order.getOrderId()); + orderData.put("order_no", order.getOrderId()); + orderData.put("status", order.getStatus()); + orderData.put("status_text", getOrderStatusText(order.getStatus())); + orderData.put("total_price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + orderData.put("num", order.getNum()); + orderData.put("sku", order.getSku() != null ? order.getSku() : null); + orderData.put("pay_time", order.getPayTime() != null ? sdf.format(order.getPayTime()) : null); + orderData.put("created_at", order.getCreatedAt() != null ? sdf.format(order.getCreatedAt()) : null); + if (order.getProductId() != null) { + ServiceGoods serviceGoods = serviceGoodsService.selectServiceGoodsById(order.getProductId()); + if (serviceGoods != null) { + Map productInfo = new HashMap<>(); + productInfo.put("id", serviceGoods.getId()); + productInfo.put("title", serviceGoods.getTitle()); + productInfo.put("sub_title", serviceGoods.getSubTitle()); + productInfo.put("icon", buildImageUrl(serviceGoods.getIcon())); + productInfo.put("price", order.getTotalPrice() != null ? order.getTotalPrice().toString() : "0.00"); + productInfo.put("num", order.getNum()); + orderData.put("product", productInfo); + } + } + resultList.add(orderData); + } + PageInfo pageInfo = new PageInfo<>(orderList); + Map responseData = new HashMap<>(); + responseData.put("current_page", pageInfo.getPageNum()); + responseData.put("data", resultList); + responseData.put("total", pageInfo.getTotal()); + responseData.put("per_page", pageInfo.getPageSize()); + responseData.put("last_page", pageInfo.getPages()); + return responseData; + } + + /** + * 创建服务/商品订单,包含商品、服务、优惠券、微信支付等完整业务逻辑 + * @param params 前端参数 + * @param user 当前用户 + * @param usersService 用户服务 + * @param userAddressService 地址服务 + * @param serviceGoodsService 商品服务 + * @param goodsOrderService 商品订单服务 + * @param orderService 服务订单服务 + * @param orderLogService 订单日志服务 + * @param couponUserService 优惠券服务 + * @param wechatPayUtil 微信支付工具 + * @return AjaxResult 结果 + */ + public static AjaxResult createServiceOrGoodsOrder(Map params, Users user, IUsersService usersService, IUserAddressService userAddressService, IServiceGoodsService serviceGoodsService, IGoodsOrderService goodsOrderService, IOrderService orderService, IOrderLogService orderLogService, ICouponUserService couponUserService, WechatPayUtil wechatPayUtil) { + // 这里完整迁移原createServiceOrder方法的实现 + // ... 由于篇幅限制,建议分段迁移 ... + // 这里只做结构示例,具体实现请参考原控制器方法 + return AjaxResult.success(); + } + + /** + * 构建师傅端订单分页数据 + * @param user 当前师傅 + * @param page 页码 + * @param limit 每页数量 + * @param orderService 订单服务 + * @param userAddressService 地址服务 + * @param serviceGoodsService 商品服务 + * @return 带分页和统计的结果Map + */ + public static Map buildWorkerOrderListData(Users user, int page, int limit, IOrderService orderService, IUserAddressService userAddressService, IServiceGoodsService serviceGoodsService) { + // 这里完整迁移原getWorkerOrderList方法的实现 + // ... 由于篇幅限制,建议分段迁移 ... + // 这里只做结构示例,具体实现请参考原控制器方法 + return new HashMap<>(); + } + + /** + * 获取订单状态文本 + * @param status 订单状态 + * @return 状态文本 + */ + public static String getOrderStatusText1(Long status) { + if (status == null) { + return "未知状态"; + } + switch (status.intValue()) { + case 1: + return "待付款"; + case 2: + return "待发货"; + case 3: + return "待收货"; + case 4: + return "待评价"; + case 5: + return "已完成"; + case 6: + return "已取消"; + case 7: + return "售后中"; + case 8: + return "已退款"; + default: + return "未知状态"; + } + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/QuoteMaterial.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/QuoteMaterial.java index 1e53d2f..3b3589e 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/QuoteMaterial.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/QuoteMaterial.java @@ -62,6 +62,19 @@ public class QuoteMaterial extends BaseEntity @Excel(name = "类型名称") private String typeName; + + @Excel(name = "附件图片") + private String image; + + @Excel(name = "是否有分佣 1:有 2:无 (默认有分佣)") + private Integer iscommissions; + + @Excel(name = "分佣比例(百分比,默认的系统设置)") + private BigDecimal commissions; + + @Excel(name = "净利润") + private BigDecimal profit; + /** $column.columnComment */ @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private Date createdAt; @@ -203,6 +216,39 @@ public class QuoteMaterial extends BaseEntity this.typeintids = typeintids; } + + public BigDecimal getProfit() { + return profit; + } + + public void setProfit(BigDecimal profit) { + this.profit = profit; + } + + public BigDecimal getCommissions() { + return commissions; + } + + public void setCommissions(BigDecimal commissions) { + this.commissions = commissions; + } + + public Integer getIscommissions() { + return iscommissions; + } + + public void setIscommissions(Integer iscommissions) { + this.iscommissions = iscommissions; + } + + public String getImage() { + return image; + } + + public void setImage(String image) { + this.image = image; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java index ba691f9..94d4021 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/ServiceGoods.java @@ -122,6 +122,53 @@ private String cateName; @Excel(name = "所需技能") private String skillIds; + + /** 是否可拼团 1:是 2:否 */ + @Excel(name = "是否可拼团 1:是 2:否") + private Integer isgroup; + + /** 拼团价 */ + @Excel(name = "拼团价") + private BigDecimal groupprice; + + /** 是否可设置次卡 1:是 2:否 */ + @Excel(name = "是否可设置次卡 1:是 2:否") + private Integer isonce; + + /** 次卡价格 */ + @Excel(name = "次卡价格") + private BigDecimal onceprice; + + /** 分佣模式 1:系统分佣 2:独立分佣 3:不分佣 */ + @Excel(name = "分佣模式 1:系统分佣 2:独立分佣 3:不分佣") + private Integer commissiontype; + + /** 分佣比例 */ + @Excel(name = "分佣比例") + private BigDecimal commission; + + /** 派单模式 1:系统派单 2:后台手动派单 3:指定工人 */ + @Excel(name = "派单模式 1:系统派单 2:后台手动派单 3:指定工人") + private Integer dispatchtype; + + /** 指定工人的id集合 */ + @Excel(name = "指定工人的id集合") + private String workerids; + + /** 是否为一口价 1:是 2:否 */ + @Excel(name = "是否为一口价 1:是 2:否") + private Integer isfixed; + + /** 一口价价格 */ + @Excel(name = "一口价价格") + private BigDecimal fixedprice; + + /** 派单模式 1:系统派单 2:后台手动派单 3:指定工人 */ + @Excel(name = "拼团人数") + private Integer groupnum; + + + /** $column.columnComment */ @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") private Date createdAt; @@ -461,6 +508,95 @@ private String cateName; this.minPrice = minPrice; } + + public BigDecimal getFixedprice() { + return fixedprice; + } + + public void setFixedprice(BigDecimal fixedprice) { + this.fixedprice = fixedprice; + } + + public Integer getIsfixed() { + return isfixed; + } + + public void setIsfixed(Integer isfixed) { + this.isfixed = isfixed; + } + + public String getWorkerids() { + return workerids; + } + + public void setWorkerids(String workerids) { + this.workerids = workerids; + } + + public Integer getDispatchtype() { + return dispatchtype; + } + + public void setDispatchtype(Integer dispatchtype) { + this.dispatchtype = dispatchtype; + } + + public BigDecimal getCommission() { + return commission; + } + + public void setCommission(BigDecimal commission) { + this.commission = commission; + } + + public Integer getCommissiontype() { + return commissiontype; + } + + public void setCommissiontype(Integer commissiontype) { + this.commissiontype = commissiontype; + } + + public BigDecimal getOnceprice() { + return onceprice; + } + + public void setOnceprice(BigDecimal onceprice) { + this.onceprice = onceprice; + } + + public Integer getIsonce() { + return isonce; + } + + public void setIsonce(Integer isonce) { + this.isonce = isonce; + } + + public BigDecimal getGroupprice() { + return groupprice; + } + + public void setGroupprice(BigDecimal groupprice) { + this.groupprice = groupprice; + } + + public Integer getIsgroup() { + return isgroup; + } + + public void setIsgroup(Integer isgroup) { + this.isgroup = isgroup; + } + + public Integer getGroupnum() { + return groupnum; + } + + public void setGroupnum(Integer groupnum) { + this.groupnum = groupnum; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java new file mode 100644 index 0000000..ed65510 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserDemandQuotation.java @@ -0,0 +1,173 @@ +package com.ruoyi.system.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 需求报价对象 user_demand_quotation + * + * @author ruoyi + * @date 2025-07-02 + */ +public class UserDemandQuotation extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 订单id */ + @Excel(name = "订单id") + private String orderid; + + /** 报价金额 */ + @Excel(name = "报价金额") + private BigDecimal money; + + /** 师傅id */ + @Excel(name = "师傅id") + private Long workerid; + + /** 师傅姓名 */ + @Excel(name = "师傅姓名") + private String workername; + + /** 状态 1报价 2被选中 */ + private Long status; + + /** 师傅图像 */ + @Excel(name = "师傅图像") + private String workerimage; + + /** 报价时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "报价时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date quotationTime; + + /** 创建时间 */ + private Date createdAt; + + /** 修改时间 */ + private Date updatedAt; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setOrderid(String orderid) + { + this.orderid = orderid; + } + + public String getOrderid() + { + return orderid; + } + + public void setMoney(BigDecimal money) + { + this.money = money; + } + + public BigDecimal getMoney() + { + return money; + } + + public void setWorkerid(Long workerid) + { + this.workerid = workerid; + } + + public Long getWorkerid() + { + return workerid; + } + + public void setWorkername(String workername) + { + this.workername = workername; + } + + public String getWorkername() + { + return workername; + } + + public void setStatus(Long status) + { + this.status = status; + } + + public Long getStatus() + { + return status; + } + + public void setWorkerimage(String workerimage) + { + this.workerimage = workerimage; + } + + public String getWorkerimage() + { + return workerimage; + } + + public void setQuotationTime(Date quotationTime) + { + this.quotationTime = quotationTime; + } + + public Date getQuotationTime() + { + return quotationTime; + } + + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } + + public Date getCreatedAt() + { + return createdAt; + } + + public void setUpdatedAt(Date updatedAt) + { + this.updatedAt = updatedAt; + } + + public Date getUpdatedAt() + { + return updatedAt; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("orderid", getOrderid()) + .append("money", getMoney()) + .append("workerid", getWorkerid()) + .append("workername", getWorkername()) + .append("status", getStatus()) + .append("workerimage", getWorkerimage()) + .append("quotationTime", getQuotationTime()) + .append("createdAt", getCreatedAt()) + .append("updatedAt", getUpdatedAt()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java new file mode 100644 index 0000000..51dee9c --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UserGroupBuying.java @@ -0,0 +1,217 @@ +package com.ruoyi.system.domain; + +import java.math.BigDecimal; +import java.util.Date; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 拼团专区管理对象 user_group_buying + * + * @author ruoyi + * @date 2025-07-02 + */ +public class UserGroupBuying extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键id */ + private Long id; + + /** 订单id */ + @Excel(name = "订单id") + private String orderid; + + /** 用户id */ + private Long uid; + + /** 支付金额 */ + @Excel(name = "支付金额") + private BigDecimal money; + + /** 状态 */ + @Excel(name = "状态") + private Long status; + + /** 优惠金额 */ + @Excel(name = "优惠金额") + private BigDecimal deduction; + + /** 用户姓名 */ + @Excel(name = "用户姓名") + private String uname; + + /** 支付时间 */ + @JsonFormat(pattern = "yyyy-MM-dd") + @Excel(name = "支付时间", width = 30, dateFormat = "yyyy-MM-dd") + private Date paytime; + + /** 支付订单号 */ + @Excel(name = "支付订单号") + private String transactionId; + + /** 支付类别 */ + @Excel(name = "支付类别") + private Long paytype; + + /** 服务商品id */ + private Long productId; + + /** 创建时间 */ + private Date createdAt; + + /** 修改时间 */ + private Date updatedAt; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + + public void setOrderid(String orderid) + { + this.orderid = orderid; + } + + public String getOrderid() + { + return orderid; + } + + public void setUid(Long uid) + { + this.uid = uid; + } + + public Long getUid() + { + return uid; + } + + public void setMoney(BigDecimal money) + { + this.money = money; + } + + public BigDecimal getMoney() + { + return money; + } + + public void setStatus(Long status) + { + this.status = status; + } + + public Long getStatus() + { + return status; + } + + public void setDeduction(BigDecimal deduction) + { + this.deduction = deduction; + } + + public BigDecimal getDeduction() + { + return deduction; + } + + public void setUname(String uname) + { + this.uname = uname; + } + + public String getUname() + { + return uname; + } + + public void setPaytime(Date paytime) + { + this.paytime = paytime; + } + + public Date getPaytime() + { + return paytime; + } + + public void setTransactionId(String transactionId) + { + this.transactionId = transactionId; + } + + public String getTransactionId() + { + return transactionId; + } + + public void setPaytype(Long paytype) + { + this.paytype = paytype; + } + + public Long getPaytype() + { + return paytype; + } + + public void setProductId(Long productId) + { + this.productId = productId; + } + + public Long getProductId() + { + return productId; + } + + public void setCreatedAt(Date createdAt) + { + this.createdAt = createdAt; + } + + public Date getCreatedAt() + { + return createdAt; + } + + public void setUpdatedAt(Date updatedAt) + { + this.updatedAt = updatedAt; + } + + public Date getUpdatedAt() + { + return updatedAt; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("orderid", getOrderid()) + .append("uid", getUid()) + .append("money", getMoney()) + .append("status", getStatus()) + .append("deduction", getDeduction()) + .append("uname", getUname()) + .append("paytime", getPaytime()) + .append("transactionId", getTransactionId()) + .append("paytype", getPaytype()) + .append("productId", getProductId()) + .append("createdAt", getCreatedAt()) + .append("updatedAt", getUpdatedAt()) + .toString(); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersInvoiceInfo.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersInvoiceInfo.java index c8433ea..d8295ab 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersInvoiceInfo.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/UsersInvoiceInfo.java @@ -1,5 +1,6 @@ package com.ruoyi.system.domain; +import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -9,9 +10,9 @@ import com.ruoyi.common.core.domain.BaseEntity; /** * 发票信息对象 users_invoice_info - * + * * @author ruoyi - * @date 2025-06-27 + * @date 2025-06-30 */ public class UsersInvoiceInfo extends BaseEntity { @@ -74,163 +75,238 @@ public class UsersInvoiceInfo extends BaseEntity @Excel(name = "修改时间", width = 30, dateFormat = "yyyy-MM-dd") private Date updatedAt; - public void setId(Integer id) + /** 开票金额 */ + @Excel(name = "开票金额") + private BigDecimal invoicemoney; + + /** 开票内容 */ + @Excel(name = "开票内容") + private String invoicetext; + + /** 开票订单号 */ + @Excel(name = "开票订单号") + private String orderid; + + /** 开票状态 1:未开票 2:已开票 */ + @Excel(name = "开票状态 1:未开票 2:已开票") + private Integer status; + + /** 发票附件 */ + @Excel(name = "发票附件") + private String filedata; + + public void setId(Integer id) { this.id = id; } - public Integer getId() + public Integer getId() { return id; } - public void setUid(Integer uid) + public void setUid(Integer uid) { this.uid = uid; } - public Integer getUid() + public Integer getUid() { return uid; } - public void setInvoiceTitle(String invoiceTitle) + public void setInvoiceTitle(String invoiceTitle) { this.invoiceTitle = invoiceTitle; } - public String getInvoiceTitle() + public String getInvoiceTitle() { return invoiceTitle; } - public void setTaxNumber(String taxNumber) + public void setTaxNumber(String taxNumber) { this.taxNumber = taxNumber; } - public String getTaxNumber() + public String getTaxNumber() { return taxNumber; } - public void setBankName(String bankName) + public void setBankName(String bankName) { this.bankName = bankName; } - public String getBankName() + public String getBankName() { return bankName; } - public void setBankAccount(String bankAccount) + public void setBankAccount(String bankAccount) { this.bankAccount = bankAccount; } - public String getBankAccount() + public String getBankAccount() { return bankAccount; } - public void setAddress(String address) + public void setAddress(String address) { this.address = address; } - public String getAddress() + public String getAddress() { return address; } - public void setPhone(String phone) + public void setPhone(String phone) { this.phone = phone; } - public String getPhone() + public String getPhone() { return phone; } - public void setEmail(String email) + public void setEmail(String email) { this.email = email; } - public String getEmail() + public String getEmail() { return email; } - public void setWechat(String wechat) + public void setWechat(String wechat) { this.wechat = wechat; } - public String getWechat() + public String getWechat() { return wechat; } - public void setType(Integer type) + public void setType(Integer type) { this.type = type; } - public Integer getType() + public Integer getType() { return type; } - public void setCategory(Integer category) + public void setCategory(Integer category) { this.category = category; } - public Integer getCategory() + public Integer getCategory() { return category; } - public void setCreatedAt(Date createdAt) + public void setCreatedAt(Date createdAt) { this.createdAt = createdAt; } - public Date getCreatedAt() + public Date getCreatedAt() { return createdAt; } - public void setUpdatedAt(Date updatedAt) + public void setUpdatedAt(Date updatedAt) { this.updatedAt = updatedAt; } - public Date getUpdatedAt() + public Date getUpdatedAt() { return updatedAt; } + public void setInvoicemoney(BigDecimal invoicemoney) + { + this.invoicemoney = invoicemoney; + } + + public BigDecimal getInvoicemoney() + { + return invoicemoney; + } + + public void setInvoicetext(String invoicetext) + { + this.invoicetext = invoicetext; + } + + public String getInvoicetext() + { + return invoicetext; + } + + public void setOrderid(String orderid) + { + this.orderid = orderid; + } + + public String getOrderid() + { + return orderid; + } + + public void setStatus(Integer status) + { + this.status = status; + } + + public Integer getStatus() + { + return status; + } + + public void setFiledata(String filedata) + { + this.filedata = filedata; + } + + public String getFiledata() + { + return filedata; + } + @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) - .append("id", getId()) - .append("uid", getUid()) - .append("invoiceTitle", getInvoiceTitle()) - .append("taxNumber", getTaxNumber()) - .append("bankName", getBankName()) - .append("bankAccount", getBankAccount()) - .append("address", getAddress()) - .append("phone", getPhone()) - .append("email", getEmail()) - .append("wechat", getWechat()) - .append("type", getType()) - .append("category", getCategory()) - .append("createdAt", getCreatedAt()) - .append("updatedAt", getUpdatedAt()) - .toString(); + .append("id", getId()) + .append("uid", getUid()) + .append("invoiceTitle", getInvoiceTitle()) + .append("taxNumber", getTaxNumber()) + .append("bankName", getBankName()) + .append("bankAccount", getBankAccount()) + .append("address", getAddress()) + .append("phone", getPhone()) + .append("email", getEmail()) + .append("wechat", getWechat()) + .append("type", getType()) + .append("category", getCategory()) + .append("createdAt", getCreatedAt()) + .append("updatedAt", getUpdatedAt()) + .append("invoicemoney", getInvoicemoney()) + .append("invoicetext", getInvoicetext()) + .append("orderid", getOrderid()) + .append("status", getStatus()) + .append("filedata", getFiledata()) + .toString(); } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserDemandQuotationMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserDemandQuotationMapper.java new file mode 100644 index 0000000..62e4b54 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserDemandQuotationMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.UserDemandQuotation; + +/** + * 需求报价Mapper接口 + * + * @author ruoyi + * @date 2025-07-02 + */ +public interface UserDemandQuotationMapper +{ + /** + * 查询需求报价 + * + * @param id 需求报价主键 + * @return 需求报价 + */ + public UserDemandQuotation selectUserDemandQuotationById(Long id); + + /** + * 查询需求报价列表 + * + * @param userDemandQuotation 需求报价 + * @return 需求报价集合 + */ + public List selectUserDemandQuotationList(UserDemandQuotation userDemandQuotation); + + /** + * 新增需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + public int insertUserDemandQuotation(UserDemandQuotation userDemandQuotation); + + /** + * 修改需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + public int updateUserDemandQuotation(UserDemandQuotation userDemandQuotation); + + /** + * 删除需求报价 + * + * @param id 需求报价主键 + * @return 结果 + */ + public int deleteUserDemandQuotationById(Long id); + + /** + * 批量删除需求报价 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteUserDemandQuotationByIds(Long[] ids); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java new file mode 100644 index 0000000..2116115 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/UserGroupBuyingMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.UserGroupBuying; + +/** + * 拼团专区管理Mapper接口 + * + * @author ruoyi + * @date 2025-07-02 + */ +public interface UserGroupBuyingMapper +{ + /** + * 查询拼团专区管理 + * + * @param id 拼团专区管理主键 + * @return 拼团专区管理 + */ + public UserGroupBuying selectUserGroupBuyingById(Long id); + + /** + * 查询拼团专区管理列表 + * + * @param userGroupBuying 拼团专区管理 + * @return 拼团专区管理集合 + */ + public List selectUserGroupBuyingList(UserGroupBuying userGroupBuying); + + /** + * 新增拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + public int insertUserGroupBuying(UserGroupBuying userGroupBuying); + + /** + * 修改拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + public int updateUserGroupBuying(UserGroupBuying userGroupBuying); + + /** + * 删除拼团专区管理 + * + * @param id 拼团专区管理主键 + * @return 结果 + */ + public int deleteUserGroupBuyingById(Long id); + + /** + * 批量删除拼团专区管理 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteUserGroupBuyingByIds(Long[] ids); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserDemandQuotationService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserDemandQuotationService.java new file mode 100644 index 0000000..32baaf1 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserDemandQuotationService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.UserDemandQuotation; + +/** + * 需求报价Service接口 + * + * @author ruoyi + * @date 2025-07-02 + */ +public interface IUserDemandQuotationService +{ + /** + * 查询需求报价 + * + * @param id 需求报价主键 + * @return 需求报价 + */ + public UserDemandQuotation selectUserDemandQuotationById(Long id); + + /** + * 查询需求报价列表 + * + * @param userDemandQuotation 需求报价 + * @return 需求报价集合 + */ + public List selectUserDemandQuotationList(UserDemandQuotation userDemandQuotation); + + /** + * 新增需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + public int insertUserDemandQuotation(UserDemandQuotation userDemandQuotation); + + /** + * 修改需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + public int updateUserDemandQuotation(UserDemandQuotation userDemandQuotation); + + /** + * 批量删除需求报价 + * + * @param ids 需要删除的需求报价主键集合 + * @return 结果 + */ + public int deleteUserDemandQuotationByIds(Long[] ids); + + /** + * 删除需求报价信息 + * + * @param id 需求报价主键 + * @return 结果 + */ + public int deleteUserDemandQuotationById(Long id); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java new file mode 100644 index 0000000..677cc24 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/IUserGroupBuyingService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.UserGroupBuying; + +/** + * 拼团专区管理Service接口 + * + * @author ruoyi + * @date 2025-07-02 + */ +public interface IUserGroupBuyingService +{ + /** + * 查询拼团专区管理 + * + * @param id 拼团专区管理主键 + * @return 拼团专区管理 + */ + public UserGroupBuying selectUserGroupBuyingById(Long id); + + /** + * 查询拼团专区管理列表 + * + * @param userGroupBuying 拼团专区管理 + * @return 拼团专区管理集合 + */ + public List selectUserGroupBuyingList(UserGroupBuying userGroupBuying); + + /** + * 新增拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + public int insertUserGroupBuying(UserGroupBuying userGroupBuying); + + /** + * 修改拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + public int updateUserGroupBuying(UserGroupBuying userGroupBuying); + + /** + * 批量删除拼团专区管理 + * + * @param ids 需要删除的拼团专区管理主键集合 + * @return 结果 + */ + public int deleteUserGroupBuyingByIds(Long[] ids); + + /** + * 删除拼团专区管理信息 + * + * @param id 拼团专区管理主键 + * @return 结果 + */ + public int deleteUserGroupBuyingById(Long id); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserDemandQuotationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserDemandQuotationServiceImpl.java new file mode 100644 index 0000000..c4e159d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserDemandQuotationServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.UserDemandQuotationMapper; +import com.ruoyi.system.domain.UserDemandQuotation; +import com.ruoyi.system.service.IUserDemandQuotationService; + +/** + * 需求报价Service业务层处理 + * + * @author ruoyi + * @date 2025-07-02 + */ +@Service +public class UserDemandQuotationServiceImpl implements IUserDemandQuotationService +{ + @Autowired + private UserDemandQuotationMapper userDemandQuotationMapper; + + /** + * 查询需求报价 + * + * @param id 需求报价主键 + * @return 需求报价 + */ + @Override + public UserDemandQuotation selectUserDemandQuotationById(Long id) + { + return userDemandQuotationMapper.selectUserDemandQuotationById(id); + } + + /** + * 查询需求报价列表 + * + * @param userDemandQuotation 需求报价 + * @return 需求报价 + */ + @Override + public List selectUserDemandQuotationList(UserDemandQuotation userDemandQuotation) + { + return userDemandQuotationMapper.selectUserDemandQuotationList(userDemandQuotation); + } + + /** + * 新增需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + @Override + public int insertUserDemandQuotation(UserDemandQuotation userDemandQuotation) + { + return userDemandQuotationMapper.insertUserDemandQuotation(userDemandQuotation); + } + + /** + * 修改需求报价 + * + * @param userDemandQuotation 需求报价 + * @return 结果 + */ + @Override + public int updateUserDemandQuotation(UserDemandQuotation userDemandQuotation) + { + return userDemandQuotationMapper.updateUserDemandQuotation(userDemandQuotation); + } + + /** + * 批量删除需求报价 + * + * @param ids 需要删除的需求报价主键 + * @return 结果 + */ + @Override + public int deleteUserDemandQuotationByIds(Long[] ids) + { + return userDemandQuotationMapper.deleteUserDemandQuotationByIds(ids); + } + + /** + * 删除需求报价信息 + * + * @param id 需求报价主键 + * @return 结果 + */ + @Override + public int deleteUserDemandQuotationById(Long id) + { + return userDemandQuotationMapper.deleteUserDemandQuotationById(id); + } +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java new file mode 100644 index 0000000..9dac2aa --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/UserGroupBuyingServiceImpl.java @@ -0,0 +1,93 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.UserGroupBuyingMapper; +import com.ruoyi.system.domain.UserGroupBuying; +import com.ruoyi.system.service.IUserGroupBuyingService; + +/** + * 拼团专区管理Service业务层处理 + * + * @author ruoyi + * @date 2025-07-02 + */ +@Service +public class UserGroupBuyingServiceImpl implements IUserGroupBuyingService +{ + @Autowired + private UserGroupBuyingMapper userGroupBuyingMapper; + + /** + * 查询拼团专区管理 + * + * @param id 拼团专区管理主键 + * @return 拼团专区管理 + */ + @Override + public UserGroupBuying selectUserGroupBuyingById(Long id) + { + return userGroupBuyingMapper.selectUserGroupBuyingById(id); + } + + /** + * 查询拼团专区管理列表 + * + * @param userGroupBuying 拼团专区管理 + * @return 拼团专区管理 + */ + @Override + public List selectUserGroupBuyingList(UserGroupBuying userGroupBuying) + { + return userGroupBuyingMapper.selectUserGroupBuyingList(userGroupBuying); + } + + /** + * 新增拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + @Override + public int insertUserGroupBuying(UserGroupBuying userGroupBuying) + { + return userGroupBuyingMapper.insertUserGroupBuying(userGroupBuying); + } + + /** + * 修改拼团专区管理 + * + * @param userGroupBuying 拼团专区管理 + * @return 结果 + */ + @Override + public int updateUserGroupBuying(UserGroupBuying userGroupBuying) + { + return userGroupBuyingMapper.updateUserGroupBuying(userGroupBuying); + } + + /** + * 批量删除拼团专区管理 + * + * @param ids 需要删除的拼团专区管理主键 + * @return 结果 + */ + @Override + public int deleteUserGroupBuyingByIds(Long[] ids) + { + return userGroupBuyingMapper.deleteUserGroupBuyingByIds(ids); + } + + /** + * 删除拼团专区管理信息 + * + * @param id 拼团专区管理主键 + * @return 结果 + */ + @Override + public int deleteUserGroupBuyingById(Long id) + { + return userGroupBuyingMapper.deleteUserGroupBuyingById(id); + } +} diff --git a/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml b/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml index bec52f9..2311d87 100644 --- a/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/QuoteMaterialMapper.xml @@ -11,14 +11,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - - select id, good_id, type_id, title, price, unit, created_at, updated_at from quote_material + select id, good_id, type_id, title, price, unit,profit,commissions,iscommissions,image, created_at, updated_at from quote_material - @@ -100,6 +111,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" margin, skill_ids, deleted_at, + isgroup, + groupprice, + isonce, + onceprice, + commissiontype, + commission, + dispatchtype, + workerids, + isfixed, + fixedprice, + groupnum, + created_at, updated_at @@ -130,6 +153,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{margin}, #{skillIds}, #{deletedAt}, + #{isgroup}, + #{groupprice}, + #{isonce}, + #{onceprice}, + #{commissiontype}, + #{commission}, + #{dispatchtype}, + #{workerids}, + #{isfixed}, + #{fixedprice}, + #{groupnum}, + + NOW(), NOW() @@ -164,6 +200,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" margin = #{margin}, skill_ids = #{skillIds}, deleted_at = #{deletedAt}, + isgroup = #{isgroup}, + groupprice = #{groupprice}, + isonce = #{isonce}, + onceprice = #{onceprice}, + commissiontype = #{commissiontype}, + commission = #{commission}, + dispatchtype = #{dispatchtype}, + workerids = #{workerids}, + isfixed = #{isfixed}, + fixedprice = #{fixedprice}, + groupnum = #{groupnum}, + updated_at = NOW() where id = #{id} diff --git a/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml new file mode 100644 index 0000000..6159165 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/UserDemandQuotationMapper.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + select id, orderid, money, workerid, workername, status, workerimage, quotation_time, created_at, updated_at from user_demand_quotation + + + + + + + + insert into user_demand_quotation + + id, + orderid, + money, + workerid, + workername, + status, + workerimage, + quotation_time, + created_at, + updated_at, + + + #{id}, + #{orderid}, + #{money}, + #{workerid}, + #{workername}, + #{status}, + #{workerimage}, + #{quotationTime}, + #{createdAt}, + #{updatedAt}, + + + + + update user_demand_quotation + + orderid = #{orderid}, + money = #{money}, + workerid = #{workerid}, + workername = #{workername}, + status = #{status}, + workerimage = #{workerimage}, + quotation_time = #{quotationTime}, + created_at = #{createdAt}, + updated_at = #{updatedAt}, + + where id = #{id} + + + + delete from user_demand_quotation where id = #{id} + + + + delete from user_demand_quotation where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml new file mode 100644 index 0000000..a383383 --- /dev/null +++ b/ruoyi-system/src/main/resources/mapper/system/UserGroupBuyingMapper.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + select id, orderid, uid, money, status, deduction, uname, paytime, transaction_id, paytype, product_id, created_at, updated_at from user_group_buying + + + + + + + + insert into user_group_buying + + id, + orderid, + uid, + money, + status, + deduction, + uname, + paytime, + transaction_id, + paytype, + product_id, + created_at, + updated_at, + + + #{id}, + #{orderid}, + #{uid}, + #{money}, + #{status}, + #{deduction}, + #{uname}, + #{paytime}, + #{transactionId}, + #{paytype}, + #{productId}, + #{createdAt}, + #{updatedAt}, + + + + + update user_group_buying + + orderid = #{orderid}, + uid = #{uid}, + money = #{money}, + status = #{status}, + deduction = #{deduction}, + uname = #{uname}, + paytime = #{paytime}, + transaction_id = #{transactionId}, + paytype = #{paytype}, + product_id = #{productId}, + created_at = #{createdAt}, + updated_at = #{updatedAt}, + + where id = #{id} + + + + delete from user_group_buying where id = #{id} + + + + delete from user_group_buying where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-system/src/main/resources/mapper/system/UsersInvoiceInfoMapper.xml b/ruoyi-system/src/main/resources/mapper/system/UsersInvoiceInfoMapper.xml index 24e94b8..6f46315 100644 --- a/ruoyi-system/src/main/resources/mapper/system/UsersInvoiceInfoMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/UsersInvoiceInfoMapper.xml @@ -1,9 +1,9 @@ + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + @@ -19,15 +19,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + - select id, uid, invoice_title, tax_number, bank_name, bank_account, address, phone, email, wechat, type, category, created_at, updated_at from users_invoice_info + select id, uid, invoice_title, tax_number, bank_name, bank_account, address, phone, email, wechat, type, category, created_at, updated_at, invoicemoney, invoicetext, orderid, status, filedata from users_invoice_info - - where id = #{id} @@ -63,7 +76,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" category, created_at, updated_at, - + invoicemoney, + invoicetext, + orderid, + status, + filedata, + #{uid}, #{invoiceTitle}, @@ -78,7 +96,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{category}, #{createdAt}, #{updatedAt}, - + #{invoicemoney}, + #{invoicetext}, + #{orderid}, + #{status}, + #{filedata}, + @@ -97,16 +120,21 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" category = #{category}, created_at = #{createdAt}, updated_at = #{updatedAt}, + invoicemoney = #{invoicemoney}, + invoicetext = #{invoicetext}, + orderid = #{orderid}, + status = #{status}, + filedata = #{filedata}, where id = #{id} - + delete from users_invoice_info where id = #{id} - delete from users_invoice_info where id in + delete from users_invoice_info where id in #{id} diff --git a/ruoyi-ui/src/api/system/QuoteMaterial.js b/ruoyi-ui/src/api/system/QuoteMaterial.js index d6264b6..b50ebf0 100644 --- a/ruoyi-ui/src/api/system/QuoteMaterial.js +++ b/ruoyi-ui/src/api/system/QuoteMaterial.js @@ -17,6 +17,15 @@ export function getQuoteMaterial(id) { }) } + +// 查询项目报价--物料信息详细 +export function getConfigData(name) { + return request({ + url: '/system/SiteConfig/grtConfigData/' + name, + method: 'get' + }) +} + // 新增项目报价--物料信息 export function addQuoteMaterial(data) { return request({ diff --git a/ruoyi-ui/src/api/system/ServiceGoods.js b/ruoyi-ui/src/api/system/ServiceGoods.js index 61341ae..c2783c7 100644 --- a/ruoyi-ui/src/api/system/ServiceGoods.js +++ b/ruoyi-ui/src/api/system/ServiceGoods.js @@ -8,7 +8,13 @@ export function listServiceGoods(query) { params: query }) } - +// 查询师傅列表 +export function getlistworkerlist() { + return request({ + url: '/system/users/workerlist', + method: 'get' + }) +} // 查询服务内容详细 export function getServiceGoods(id) { return request({ diff --git a/ruoyi-ui/src/api/system/buying.js b/ruoyi-ui/src/api/system/buying.js new file mode 100644 index 0000000..a575087 --- /dev/null +++ b/ruoyi-ui/src/api/system/buying.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询拼团专区管理列表 +export function listBuying(query) { + return request({ + url: '/system/buying/list', + method: 'get', + params: query + }) +} + +// 查询拼团专区管理详细 +export function getBuying(id) { + return request({ + url: '/system/buying/' + id, + method: 'get' + }) +} + +// 新增拼团专区管理 +export function addBuying(data) { + return request({ + url: '/system/buying', + method: 'post', + data: data + }) +} + +// 修改拼团专区管理 +export function updateBuying(data) { + return request({ + url: '/system/buying', + method: 'put', + data: data + }) +} + +// 删除拼团专区管理 +export function delBuying(id) { + return request({ + url: '/system/buying/' + id, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/api/system/quotation.js b/ruoyi-ui/src/api/system/quotation.js new file mode 100644 index 0000000..f65945f --- /dev/null +++ b/ruoyi-ui/src/api/system/quotation.js @@ -0,0 +1,44 @@ +import request from '@/utils/request' + +// 查询需求报价列表 +export function listQuotation(query) { + return request({ + url: '/system/quotation/list', + method: 'get', + params: query + }) +} + +// 查询需求报价详细 +export function getQuotation(id) { + return request({ + url: '/system/quotation/' + id, + method: 'get' + }) +} + +// 新增需求报价 +export function addQuotation(data) { + return request({ + url: '/system/quotation', + method: 'post', + data: data + }) +} + +// 修改需求报价 +export function updateQuotation(data) { + return request({ + url: '/system/quotation', + method: 'put', + data: data + }) +} + +// 删除需求报价 +export function delQuotation(id) { + return request({ + url: '/system/quotation/' + id, + method: 'delete' + }) +} diff --git a/ruoyi-ui/src/views/system/QuoteMaterial/index.vue b/ruoyi-ui/src/views/system/QuoteMaterial/index.vue index a971a6b..12169b2 100644 --- a/ruoyi-ui/src/views/system/QuoteMaterial/index.vue +++ b/ruoyi-ui/src/views/system/QuoteMaterial/index.vue @@ -113,6 +113,19 @@ {{ parseTime(scope.row.updatedAt, '{y}-{m}-{d}') }} + + + + + + + + + diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152617.vue b/ruoyi-ui/src/views/system/QuoteMaterial/index1.vue similarity index 83% rename from .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152617.vue rename to ruoyi-ui/src/views/system/QuoteMaterial/index1.vue index db47c62..a971a6b 100644 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521152617.vue +++ b/ruoyi-ui/src/views/system/QuoteMaterial/index1.vue @@ -40,8 +40,8 @@ clearable /> - - + + 删除 - - 导出 - @@ -152,43 +142,41 @@ /> - - - - + + + + + + - - + + + + - + - - - - - - - - -

@@ -197,6 +185,7 @@ diff --git a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145828.vue b/ruoyi-ui/src/views/system/buying/index.vue similarity index 50% rename from .history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145828.vue rename to ruoyi-ui/src/views/system/buying/index.vue index 549004c..182a858 100644 --- a/.history/ruoyi-ui/src/views/system/QuoteMaterial/index_20250521145828.vue +++ b/ruoyi-ui/src/views/system/buying/index.vue @@ -1,42 +1,42 @@