src/main/java/com/xcong/excoin/modules/member/controller/MemberController.java
@@ -5,11 +5,7 @@ import com.xcong.excoin.modules.member.parameter.dto.*; import com.xcong.excoin.modules.member.parameter.vo.*; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import com.xcong.excoin.common.response.Result; import com.xcong.excoin.modules.member.service.MemberService; @@ -36,7 +32,7 @@ @Resource MemberService memberService; /** * 获取当前版本号 */ @@ -214,6 +210,12 @@ public Result memberPaymethodDetailList() { return memberService.memberPaymethodDetailList(); } @ApiOperation(value = "设置为默认收款方式") @PostMapping(value = "/setDefaultMethod/{id}") public Result setDefaultMethod(@PathVariable("id") Long id) { return memberService.setDefaultPaymethod(id); } /** * 绑定手机号 src/main/java/com/xcong/excoin/modules/member/dao/MemberPaymentMethodDao.java
@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.xcong.excoin.modules.member.entity.MemberPaymentMethodEntity; import org.apache.ibatis.annotations.Param; public interface MemberPaymentMethodDao extends BaseMapper<MemberPaymentMethodEntity> { public List<MemberPaymentMethodEntity> selectByMemberId(Long memberId); MemberPaymentMethodEntity selectDefualtMethod(@Param("memberId") Long memberId, @Param("type") Integer type, @Param("isDefault") String isDefault); } src/main/java/com/xcong/excoin/modules/member/service/MemberService.java
@@ -41,6 +41,8 @@ public Result memberPaymethodDetailList(); Result setDefaultPaymethod(Long id); public Result memberBindPhone(@Valid MemberBindPhoneDto memberBindPhoneDto); public Result memberBindEmail(@Valid MemberBindEmailDto memberBindEmailDto); src/main/java/com/xcong/excoin/modules/member/service/impl/MemberServiceImpl.java
@@ -539,6 +539,10 @@ Long memberId = LoginUserUtils.getAppLoginUser().getId(); MemberEntity member = memberDao.selectById(memberId); if (!MemberPaymentMethodEntity.PAYMENTTYPE_CARD.equals(memberPaymethodDto.getPaymentType())) { return Result.fail("只能绑定银行卡"); } if (!MemberEntity.CERTIFY_STATUS_Y.equals(member.getCertifyStatus())) { return Result.fail(MessageSourceUtils.getString("member_service_0077")); } @@ -552,6 +556,12 @@ return Result.fail(MessageSourceUtils.getString("member_service_0097")); } } } String isDefault = "1"; MemberPaymentMethodEntity defaultMethod = memberPaymentMethodDao.selectDefualtMethod(memberId, MemberPaymentMethodEntity.PAYMENTTYPE_CARD, ""); if (defaultMethod != null) { isDefault = "2"; } String account = memberPaymethodDto.getAccount(); String bank = memberPaymethodDto.getBank(); @@ -567,6 +577,7 @@ memberPaymentMethodEntity.setPaymentQrcode(paymentQrcode); memberPaymentMethodEntity.setPaymentType(paymentType); memberPaymentMethodEntity.setSubBank(subBank); memberPaymentMethodEntity.setIsDefualt(isDefault); memberPaymentMethodDao.insert(memberPaymentMethodEntity); return Result.ok(MessageSourceUtils.getString("member_service_0024")); } @@ -631,6 +642,23 @@ } @Override public Result setDefaultPaymethod(Long id) { MemberEntity member = LoginUserUtils.getAppLoginUser(); MemberPaymentMethodEntity defualtMethod = this.memberPaymentMethodDao.selectDefualtMethod(member.getId(), MemberPaymentMethodEntity.PAYMENTTYPE_CARD, "1"); MemberPaymentMethodEntity paymentMethodEntity = new MemberPaymentMethodEntity(); paymentMethodEntity.setId(id); paymentMethodEntity.setIsDefualt("1"); this.memberPaymentMethodDao.updateById(paymentMethodEntity); if (defualtMethod != null) { defualtMethod.setIsDefualt("2"); this.memberPaymentMethodDao.updateById(defualtMethod); } return Result.ok("操作成功"); } @Override @Transactional public Result memberBindPhone(@Valid MemberBindPhoneDto memberBindPhoneDto) { //获取用户ID src/main/resources/mapper/member/MemberPaymentMethodDao.xml
@@ -5,4 +5,19 @@ <select id="selectByMemberId" resultType="com.xcong.excoin.modules.member.entity.MemberPaymentMethodEntity"> SELECT a.* FROM member_payment_method a WHERE a.member_id = #{memberId} </select> <select id="selectDefualtMethod" resultType="com.xcong.excoin.modules.member.entity.MemberPaymentMethodEntity"> select * from member_payment_method <where> <if test="memberId != null"> and member_id=#{memberId} </if> <if test="isDefault != null and isDefault != ''"> and is_defualt = #{isDefault} </if> <if test="type != null"> and payment_type = #{type} </if> </where> </select> </mapper>