diff --git a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareSelectionSituationController.java b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareSelectionSituationController.java index c682e76..ee09672 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareSelectionSituationController.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareSelectionSituationController.java @@ -8,6 +8,7 @@ import com.budwk.app.base.page.Pagination; import com.budwk.app.base.result.Result; import com.budwk.app.sys.models.Sys_user; import com.budwk.app.zhgh.welfare.model.WelfareList; +import com.budwk.app.zhgh.welfare.model.WelfareProject; import com.budwk.app.zhgh.welfare.model.WelfareUserSelection; import com.budwk.app.zhgh.welfare.param.WelfareSelectionSituationPageForm; import com.budwk.app.zhgh.welfare.service.WelfareListService; @@ -89,6 +90,15 @@ public class WelfareSelectionSituationController { return Result.error("此用户没有选择的权限"); } + WelfareProject project = dao.fetch(WelfareProject.class, projectId); + if (project == null) { + return Result.error("福利项目不存在"); + } + String deliveryValidationMessage = project.validateDeliveryMethod(selections); + if (deliveryValidationMessage != null) { + return Result.error(deliveryValidationMessage); + } + String defaultOptionValidationMessage = welfareProjectService.validateSystemDefaultOptionSelection(projectId, selections); if (defaultOptionValidationMessage != null) { return Result.error(defaultOptionValidationMessage); diff --git a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserChooseController.java b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserChooseController.java index 356f3e0..822056e 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserChooseController.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserChooseController.java @@ -8,6 +8,7 @@ import com.budwk.app.base.result.Result; import com.budwk.app.base.service.BaseService; import com.budwk.app.web.commons.auth.utils.SecurityUtil; import com.budwk.app.zhgh.welfare.model.WelfareList; +import com.budwk.app.zhgh.welfare.model.WelfareProject; import com.budwk.app.zhgh.welfare.model.WelfareUserSelection; import io.swagger.annotations.ApiOperation; import org.nutz.aop.interceptor.ioc.TransAop; @@ -71,7 +72,8 @@ public class WelfareUserChooseController { sql.setParam("selectUserId", SecurityUtil.getUserId()); Cnd cnd = Cnd.NEW(); - cnd.and("wp.provideMode", "in", "2,3"); + cnd.and("wp.provideMode", "in", "1,2,3,5"); + cnd.and(Cnd.exps("wp.provideMode", "!=", 1).or("wp.flexible", "=", true)); cnd.andEX("YEAR(wp.choiceTimeStart)", "in", year); cnd.and("wp.isDisabled", "=", 0); cnd.groupBy("wp.id"); @@ -87,6 +89,15 @@ public class WelfareUserChooseController { @SLog(type = "welfare", tag = "选择福利", msg = "福利") @SaCheckPermission("welfare.user.choose") public Result confirmSelect(@Param("welfareUserSelections") WelfareUserSelection[] welfareUserSelections, String projectId) { + WelfareProject project = baseService.dao().fetch(WelfareProject.class, projectId); + if (project == null) { + return Result.error("福利项目不存在"); + } + String deliveryValidationMessage = project.validateDeliveryMethod(welfareUserSelections); + if (deliveryValidationMessage != null) { + return Result.error(deliveryValidationMessage); + } + //删除上次选择的 baseService.dao().clear(WelfareUserSelection.class, Cnd.where("welfareId", "=", projectId) diff --git a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserSelectController.java b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserSelectController.java index 36e814a..b95c28a 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserSelectController.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/controller/WelfareUserSelectController.java @@ -69,7 +69,7 @@ public class WelfareUserSelectController { sql.setParam("selectUserId", SecurityUtil.getUserId()); Cnd cnd = Cnd.NEW(); - cnd.and("wp.provideMode", "in", "2,3"); + cnd.and("wp.provideMode", "in", "1,2,3,5"); cnd.and("wp.flexible", "=", true); cnd.andEX("YEAR(wp.choiceTimeStart)", "in", year); cnd.and("wp.isDisabled", "=", 0); @@ -94,6 +94,14 @@ public class WelfareUserSelectController { } WelfareProject project = dao.fetch(WelfareProject.class, projectId); + if (project == null) { + return Result.error("福利项目不存在"); + } + String deliveryValidationMessage = project.validateDeliveryMethod(selections); + if (deliveryValidationMessage != null) { + return Result.error(deliveryValidationMessage); + } + String defaultOptionValidationMessage = welfareProjectService.validateSystemDefaultOptionSelection(projectId, selections); if (defaultOptionValidationMessage != null) { return Result.error(defaultOptionValidationMessage); diff --git a/src/main/java/com/budwk/app/zhgh/welfare/model/WelfareProject.java b/src/main/java/com/budwk/app/zhgh/welfare/model/WelfareProject.java index fd7fa49..4c5f506 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/model/WelfareProject.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/model/WelfareProject.java @@ -1,5 +1,6 @@ package com.budwk.app.zhgh.welfare.model; +import cn.hutool.core.util.StrUtil; import com.budwk.app.base.model.BaseModel; import com.budwk.app.sys.models.Sys_home_activity; import com.budwk.app.sys.services.SysHomeConvert; @@ -26,6 +27,10 @@ import java.util.List; @Comment("福利项目") public class WelfareProject extends BaseModel implements SysHomeConvert { + private static final int PICKUP_ONLY = 1; + private static final int PICKUP_OR_MAIL = 3; + private static final int MAIL_ONLY = 5; + @Column @Name @Comment("ID") @@ -94,6 +99,30 @@ public class WelfareProject extends BaseModel implements SysHomeConvert { @ColDefine(type = ColType.INT, width = 1) private Integer provideMode; + public boolean allowsMailDelivery() { + return Integer.valueOf(PICKUP_OR_MAIL).equals(provideMode) || Integer.valueOf(MAIL_ONLY).equals(provideMode); + } + + public String validateDeliveryMethod(WelfareUserSelection[] selections) { + if (selections == null) { + return null; + } + for (WelfareUserSelection selection : selections) { + String address = selection.getReceiveAddress(); + boolean pickup = "学校自提".equals(address); + if (Integer.valueOf(PICKUP_ONLY).equals(provideMode) && !pickup && StrUtil.isNotBlank(address)) { + return "该福利仅支持实物发放"; + } + if (Integer.valueOf(MAIL_ONLY).equals(provideMode) && pickup) { + return "该福利仅支持邮寄到家"; + } + if (allowsMailDelivery() && StrUtil.isBlank(address)) { + return "请选择领取方式并填写所需的收货地址"; + } + } + return null; + } + @Column @Comment("签收形式") @@ -214,7 +243,7 @@ public class WelfareProject extends BaseModel implements SysHomeConvert { sysHomeActivity.setH5Url("/platform/h5/welfare/userSelect/index?id=" + this.getId()); sysHomeActivity.setStartDate(this.getChoiceTimeStart()); sysHomeActivity.setEndDate(this.getChoiceTimeEnd()); - sysHomeActivity.setAllowUserSql("select userId from welfare_list where projectId = (select id from welfare_project where id='" + this.getId() + "' and provideMode!=1) and userId = @userId "); + sysHomeActivity.setAllowUserSql("select userId from welfare_list where projectId = (select id from welfare_project where id='" + this.getId() + "' and (provideMode!=1 or flexible=1)) and userId = @userId "); sysHomeActivity.setEnable(true); sysHomeActivity.setClassPath(this.getClass().getPackageName() + this.getClass().getName()); return sysHomeActivity; diff --git a/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java b/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java index b5b5ba2..710a23e 100644 --- a/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java +++ b/src/main/java/com/budwk/app/zhgh/welfare/service/impl/WelfareSelectionSituationServiceImpl.java @@ -194,7 +194,7 @@ public class WelfareSelectionSituationServiceImpl extends BaseServiceImpl - - - {{item.name}} - + + + + {{item.name}} + + @@ -265,6 +268,7 @@ layout("/layouts/platform.html"){ return { festival: [], welfareProvideMode: [], + formData: { provideModes: [] }, welfareSignMode: [], pageForm: { year: moment().format("YYYY") @@ -284,7 +288,7 @@ layout("/layouts/platform.html"){ provideTime: [{ required: true, message: "必选", trigger: ["blur", "change"] }], choiceTime: [{ required: true, message: "必选", trigger: ["blur", "change"] }], provideAddress: [{ required: true, message: "必选", trigger: ["blur", "change"] }], - provideMode: [{ required: true, message: "必选", trigger: ["blur", "change"] }], + provideModes: [{ type: "array", required: true, message: "必选", trigger: ["blur", "change"] }], signMode: [{ required: true, message: "必选", trigger: ["blur", "change"] }], noticePushMode: [{ required: true, message: "必选", trigger: ["blur", "change"] }], gift: [{ required: true, message: "必填", trigger: ["blur", "change"] }], @@ -324,6 +328,10 @@ layout("/layouts/platform.html"){ if (this.formData.flexible) { } const formData = clone(this.formData) + const modes = formData.provideModes + // 旧版邮寄项目使用 3,原有领取方式包括自提和邮寄。 + formData.provideMode = modes.length === 2 ? 3 : modes[0] === 3 ? 5 : modes[0] + delete formData.provideModes formData.provideAddress = "工会" try { @@ -391,6 +399,7 @@ layout("/layouts/platform.html"){ this.$set(this, "formData", { isPushHome: false, signMode: 4, + provideModes: [], isRoutine: true, isCheckBox: "radio", defaultFlexibleGifts: 0, @@ -437,6 +446,7 @@ layout("/layouts/platform.html"){ } const projectData = clone(resp.data) this.clearReuseProjectIdentifiers(projectData) + projectData.provideModes = this.getProvideModes(projectData.provideMode) this.$set(projectData, "choiceTime", [projectData.choiceTimeStart, projectData.choiceTimeEnd]) this.$set(projectData, "provideTime", [projectData.provideTimeStart, projectData.provideTimeEnd]) this.$set(this, "formData", projectData) @@ -481,12 +491,23 @@ layout("/layouts/platform.html"){ }) }, + isProvideModeDisabled(mode) { + const selected = this.formData.provideModes || [] + if (!selected.length || selected.includes(mode)) return false + return ![1, 3].includes(mode) || !selected.every(value => [1, 3].includes(value)) + }, + getProvideModes(provideMode) { + if (provideMode === 3) return [1, 3] + if (provideMode === 5) return [3] + return provideMode == null ? [] : [provideMode] + }, async openEdit(row) { this.submitLoading = true const resp = await this.$axios.post(loc() + "/findOne", { id: row.id }) this.submitLoading = false if (resp.code === 0) { const data = resp.data + data.provideModes = this.getProvideModes(data.provideMode) data.provideTime = [data.provideTimeStart, data.provideTimeEnd] data.choiceTime = [data.choiceTimeStart, data.choiceTimeEnd] this.formData = data diff --git a/src/main/resources/views/platform/zhgh/welfare/select/optionSelect.js b/src/main/resources/views/platform/zhgh/welfare/select/optionSelect.js index 3443528..9f429e6 100644 --- a/src/main/resources/views/platform/zhgh/welfare/select/optionSelect.js +++ b/src/main/resources/views/platform/zhgh/welfare/select/optionSelect.js @@ -141,19 +141,22 @@ const optionSelect = { append-to-body custom-class="welfare-confirm-dialog">
-
-
联系信息
+
{{ hasDeliveryOptions ? '领取方式' : '联系信息' }}
- - - 学校自提 - 邮寄 + + + 实物发放 + 邮寄到家 -
超出江浙沪不包邮,超出部分自理,具体金额联系供应商。
+
邮寄到家
+
+ {{ projectInfo.provideMode === 1 ? '实物发放 · ' : '' }}学校自提,请在学校指定地点领取 +
+
超出江浙沪不包邮,超出部分自理,具体金额联系供应商。
- + @@ -167,10 +170,10 @@ const optionSelect = { - + 添加地址 - + - + { if (res.code === 0) { this.projectInfo = res.data + this.deliveryMethod = res.data.provideMode === 1 ? "pickup" : res.data.provideMode === 5 ? "mail" : "" this.deadlineTime = this.projectInfo.choiceTimeEnd // 获取收货地址 - if (this.projectInfo.provideMode === 3) { + if ([3, 5].includes(this.projectInfo.provideMode)) { this.getAddress() } @@ -488,17 +500,19 @@ const optionSelect = { }) } // 首次确认选择且没有历史记录时,尝试自动带出默认收货地址。 - if (this.projectInfo.provideMode === 3) { + if ([3, 5].includes(this.projectInfo.provideMode)) { this.applyDefaultAddressIfNeeded() } } // 地址回显 - if (this.projectInfo.provideMode === 3) { + if ([3, 5].includes(this.projectInfo.provideMode)) { if (this.userSelection.length > 0 && this.userSelection[0].receiveAddress) { const receiveAddress = this.userSelection[0].receiveAddress - this.deliveryMethod = receiveAddress === "学校自提" ? "pickup" : "mail" - this.contactForm.receiveAddress = this.deliveryMethod === "mail" ? receiveAddress : "" + if (this.projectInfo.provideMode === 3) { + this.deliveryMethod = receiveAddress === "学校自提" ? "pickup" : "mail" + } + this.contactForm.receiveAddress = receiveAddress === "学校自提" ? "" : receiveAddress // this.contactForm.userName = this.userSelection[0].userName; // this.contactForm.mobile = this.userSelection[0].mobile; this.$set(this.contactForm, "userName", this.userSelection[0].userName) @@ -543,7 +557,6 @@ const optionSelect = { this.$message.warning("请选择领取方式") return } - // 验证手机号 this.$refs.contactForm.validate((valid) => { if (!valid) { return @@ -561,8 +574,8 @@ const optionSelect = { { selectOptionId: this.selectedRadioId, selectNum: 1, - mobile: this.contactForm.mobile, - userName: this.contactForm.userName, + mobile: this.requiresContactInfo ? this.contactForm.mobile : undefined, + userName: this.requiresContactInfo ? this.contactForm.userName : undefined, userSign: this.contactForm.userSign, receiveAddress: this.deliveryMethod === "pickup" ? "学校自提" : this.contactForm.receiveAddress } @@ -574,8 +587,8 @@ const optionSelect = { selections = this.selectedOptions.map((option) => ({ selectOptionId: option.id, selectNum: option.selectNum, - mobile: this.contactForm.mobile, - userName: this.contactForm.userName, + mobile: this.requiresContactInfo ? this.contactForm.mobile : undefined, + userName: this.requiresContactInfo ? this.contactForm.userName : undefined, userSign: this.contactForm.userSign, receiveAddress: this.deliveryMethod === "pickup" ? "学校自提" : this.contactForm.receiveAddress })) diff --git a/src/main/resources/views/platform/zhgh/welfare/selectionSituation/index.html b/src/main/resources/views/platform/zhgh/welfare/selectionSituation/index.html index 1e5c54e..b4494f6 100644 --- a/src/main/resources/views/platform/zhgh/welfare/selectionSituation/index.html +++ b/src/main/resources/views/platform/zhgh/welfare/selectionSituation/index.html @@ -115,7 +115,7 @@ layout("/layouts/platform.html"){ v-for="column in tableColumns" > - +