zouxuan 5 éve
szülő
commit
bb4ef501ef

+ 1 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysUserBankCardDao.java

@@ -14,9 +14,8 @@ public interface SysUserBankCardDao extends BaseDAO<Long, SysUserBankCard> {
 
     /**
      * 获取用户银行卡列表
-     * @param search
      * @param userId
      * @return
      */
-    List<SysUserBankCard> findByUser(@Param("search") String search,@Param("userId") Integer userId);
+    List<SysUserBankCard> findByUser(@Param("userId") Integer userId);
 }

+ 17 - 7
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/StudentWithdraw.java

@@ -13,13 +13,15 @@ import java.math.BigDecimal;
  */
 public class StudentWithdraw {
 
+	private Integer id;
+
 	/** 提现流水号 */
 	@ApiModelProperty(value = "提现流水号",required = false)
-	private String id;
+	private String withdrawNo;
 	
 	/** 用户编号 */
 	@ApiModelProperty(value = "用户编号",required = false)
-	private Long userId;
+	private Integer userId;
 	
 	/** 银行卡号 */
 	@ApiModelProperty(value = "银行卡号",required = false)
@@ -58,20 +60,28 @@ public class StudentWithdraw {
 	
 	/** 修改时间 */
 	private java.util.Date modifyTime;
-	
-	public void setId(String id){
+
+	public String getWithdrawNo() {
+		return withdrawNo;
+	}
+
+	public void setWithdrawNo(String withdrawNo) {
+		this.withdrawNo = withdrawNo;
+	}
+
+	public void setId(Integer id){
 		this.id = id;
 	}
 	
-	public String getId(){
+	public Integer getId(){
 		return this.id;
 	}
 			
-	public void setUserId(Long userId){
+	public void setUserId(Integer userId){
 		this.userId = userId;
 	}
 	
-	public Long getUserId(){
+	public Integer getUserId(){
 		return this.userId;
 	}
 			

+ 5 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/StudentWithdrawService.java

@@ -23,4 +23,9 @@ public interface StudentWithdrawService extends BaseService<String, StudentWithd
      */
     PageInfo<WithdrawInfoDto> queryWithdrawPage(CashAccountDetail cashAccountDetail);
 
+    /**
+     *
+     * @param studentWithdraw
+     */
+    void add(StudentWithdraw studentWithdraw) throws Exception;
 }

+ 1 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/SysUserBankCardService.java

@@ -16,9 +16,8 @@ public interface SysUserBankCardService extends BaseService<Long, SysUserBankCar
 
     /**
      * 获取学员银行卡列表
-     * @param search
      * @param id
      * @return
      */
-    List<SysUserBankCard> findByUser(String search, Integer id);
+    List<SysUserBankCard> findByUser(Integer id);
 }

+ 50 - 12
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentWithdrawServiceImpl.java

@@ -1,34 +1,38 @@
 package com.ym.mec.biz.service.impl;
 
 import com.google.common.collect.Lists;
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dao.StudentWithdrawDao;
+import com.ym.mec.biz.dal.dao.SysUserCashAccountDao;
 import com.ym.mec.biz.dal.dto.CashAccountDetail;
 import com.ym.mec.biz.dal.dto.WithdrawDto;
 import com.ym.mec.biz.dal.dto.WithdrawInfoDto;
+import com.ym.mec.biz.dal.entity.StudentWithdraw;
 import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
+import com.ym.mec.biz.dal.enums.PlatformCashAccountStatusEnum;
+import com.ym.mec.biz.dal.enums.TransTypeEnum;
+import com.ym.mec.biz.service.StudentWithdrawService;
 import com.ym.mec.biz.service.SysUserCashAccountDetailService;
 import com.ym.mec.biz.service.SysUserCashAccountService;
-import com.ym.mec.biz.dal.enums.TransTypeEnum;
+import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.string.IdWorker;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import com.ym.mec.biz.dal.dao.StudentWithdrawDao;
-import com.ym.mec.biz.dal.entity.StudentWithdraw;
-import com.ym.mec.biz.service.StudentWithdrawService;
-import com.ym.mec.common.dal.BaseDAO;
-import com.ym.mec.common.service.impl.BaseServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
+
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -37,6 +41,8 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 
 	@Autowired
 	private StudentWithdrawDao studentWithdrawDao;
+	@Autowired
+	private SysUserCashAccountDao sysUserCashAccountDao;
 
 	@Override
 	public BaseDAO<String, StudentWithdraw> getDAO() {
@@ -97,7 +103,7 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 		accountDetailPageInfo.getRows().forEach(data ->{
 			WithdrawInfoDto withdrawInfoDto = new WithdrawInfoDto();
 			StudentWithdraw studentWithdraw = studentWithdrawDao.getByUserId(data.getUserId().longValue());
-			withdrawInfoDto.setWithdrawId(studentWithdraw.getId());
+			withdrawInfoDto.setWithdrawId(studentWithdraw.getWithdrawNo());
 			withdrawInfoDto.setDateTime(DateUtil.date2ChineseDate(studentWithdraw.getCreateTime()));
 			withdrawInfoDto.setAmount(data.getAmount());
 			withdrawInfoDto.setBalance(data.getBalance());
@@ -112,6 +118,38 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 		return result;
 	}
 
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void add(StudentWithdraw withdraw) throws Exception {
+		SysUserCashAccount account = sysUserCashAccountDao.get(withdraw.getUserId());
+		//账户状态正常
+		if(account != null && account.getStatus() == PlatformCashAccountStatusEnum.NORMAL){
+			//提现金额不大于账户可用余额
+			if(withdraw.getAmount().compareTo(account.getBalance()) < 1){
+				//修改账户余额
+				BigDecimal subtract = account.getBalance().subtract(withdraw.getAmount());
+				account.setBalance(subtract);
+				account.setFrozenAmount(account.getFrozenAmount().add(withdraw.getAmount()));
+				Date date = new Date();
+				account.setUpdateTime(date);
+				sysUserCashAccountDao.update(account);
+				SysUserCashAccountDetail cashAccountDetail = new SysUserCashAccountDetail();
+				cashAccountDetail.setUserId(account.getUserId());
+				cashAccountDetail.setType(PlatformCashAccountDetailTypeEnum.WITHDRAW);
+				cashAccountDetail.setAmount(withdraw.getAmount());
+				cashAccountDetail.setBalance(subtract);
+				cashAccountDetail.setCreateTime(date);
+				cashAccountDetailService.insert(cashAccountDetail);
+				withdraw.setWithdrawNo(RandomStringUtils.random(8));
+				studentWithdrawDao.insert(withdraw);
+			}else {
+				throw new Exception("账户余额不足");
+			}
+		}else {
+			throw new Exception("账户状态异常");
+		}
+	}
+
 	/**
 	 * 修改用户账户余额,保存账户明细
 	 *
@@ -141,8 +179,8 @@ public class StudentWithdrawServiceImpl extends BaseServiceImpl<String, StudentW
 	private void saveStudentWithdraw(WithdrawDto withdrawDto) {
 		IdWorker idWorker = new IdWorker(0, 0);
 		StudentWithdraw studentWithdraw = new StudentWithdraw();
-		studentWithdraw.setId(idWorker.nextId());
-		studentWithdraw.setUserId(withdrawDto.getUserId().longValue());
+		studentWithdraw.setWithdrawNo(idWorker.nextId());
+		studentWithdraw.setUserId(withdrawDto.getUserId());
 		studentWithdraw.setBankCardNo(withdrawDto.getBankCardNo());
 		studentWithdraw.setAmount(withdrawDto.getAmount());
 		studentWithdraw.setCreateTime(new Date());

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysUserBankCardServiceImpl.java

@@ -46,7 +46,7 @@ public class SysUserBankCardServiceImpl extends BaseServiceImpl<Long, SysUserBan
 	}
 
 	@Override
-	public List<SysUserBankCard> findByUser(String search, Integer userId) {
-		return sysUserBankCardDao.findByUser(search,userId);
+	public List<SysUserBankCard> findByUser(Integer userId) {
+		return sysUserBankCardDao.findByUser(userId);
 	}
 }

+ 7 - 7
mec-biz/src/main/resources/config/mybatis/StudentWithdrawMapper.xml

@@ -17,6 +17,7 @@
         <result column="fee_platform_" property="feePlatform"/>
         <result column="description_" property="description"/>
         <result column="comment_" property="comment"/>
+        <result column="withdraw_no_" property="withdrawNo"/>
         <result column="create_time_" property="createTime"/>
         <result column="modify_time_" property="modifyTime"/>
     </resultMap>
@@ -34,14 +35,10 @@
     <!-- 向数据库增加一条记录 -->
     <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.StudentWithdraw" useGeneratedKeys="true" keyColumn="id"
             keyProperty="id">
-        <!--
-        <selectKey resultClass="int" keyProperty="id" >
-        SELECT SEQ_WSDEFINITION_ID.nextval AS ID FROM DUAL
-        </selectKey>
-        -->
         INSERT INTO student_withdraw
-        (id_,user_id_,bank_card_no_,trans_no_,status_,amount_,fee_user_,fee_platform_,description_,comment_,create_time_,modify_time_)
-        VALUES(#{id},#{userId},#{bankCardNo},#{transNo},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{feeUser},#{feePlatform},#{description},#{comment},now(),now())
+        (id_,user_id_,bank_card_no_,trans_no_,status_,amount_,fee_user_,fee_platform_,description_,comment_,create_time_,modify_time_,withdraw_no_)
+        VALUES(#{id},#{userId},#{bankCardNo},#{transNo},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
+        #{amount},#{feeUser},#{feePlatform},#{description},#{comment},now(),now(),#{withdrawNo})
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -78,6 +75,9 @@
             <if test="transNo != null">
                 trans_no_ = #{transNo},
             </if>
+            <if test="withdrawNo != null">
+                withdraw_no_ = #{withdrawNo},
+            </if>
         </set>
         WHERE id_ = #{id}
     </update>

+ 1 - 10
mec-biz/src/main/resources/config/mybatis/SysUserBankCardMapper.xml

@@ -117,10 +117,7 @@
 
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="SysUserBankCard" parameterType="map">
-        SELECT * FROM sys_user_bank_card where status_ != 0 AND user_id_ =
-        <if test="search != null and search != ''">
-           AND create_time_ LIKE CONCAT(#{search},'%')
-        </if>
+        SELECT * FROM sys_user_bank_card where status_ != 0 AND user_id_ = #{userId}
         ORDER BY id_
         <include refid="global.limit"/>
     </select>
@@ -128,15 +125,9 @@
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM sys_user_bank_card where status_ != 0
-        <if test="search != null and search != ''">
-            AND create_time_ LIKE CONCAT(#{search},'%')
-        </if>
 	</select>
 
     <select id="findByUser" resultMap="SysUserBankCard">
         SELECT * FROM sys_user_bank_card where status_ != 0 AND user_id_ = #{userId}
-        <if test="search != null and search != ''">
-            AND create_time_ LIKE CONCAT(#{search},'%')
-        </if>
     </select>
 </mapper>

+ 9 - 4
mec-biz/src/main/resources/config/mybatis/SysUserCashAccountDetailMapper.xml

@@ -40,10 +40,9 @@
         </selectKey>
         -->
         INSERT INTO sys_user_cash_account_detail
-        (id_,user_id_,trans_no_,type_,trans_type_, status_,amount_,balance_,description_,comment_,create_time_,update_time_)
+        (id_,user_id_,trans_no_,type_,trans_type_,amount_,balance_,description_,comment_,create_time_,update_time_)
         VALUES(#{id},#{userId},#{transNo},#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
-        ,#{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
-        #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{balance},#{description},#{comment},now(),now())
+        ,#{transType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{amount},#{balance},#{description},#{comment},now(),now())
     </insert>
 
     <!-- 根据主键查询一条记录 -->
@@ -93,6 +92,9 @@
     <select id="queryPage" resultMap="SysUserCashAccountDetail" parameterType="map">
         SELECT * FROM sys_user_cash_account_detail
         WHERE user_id_ = #{userId}
+        <if test="search != null and search != ''">
+            AND create_time_ LIKE CONCAT(#{search},'%')
+        </if>
         ORDER BY id_
         <include refid="global.limit"/>
     </select>
@@ -101,9 +103,12 @@
     <select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM sys_user_cash_account_detail
 		WHERE user_id_ = #{userId}
+        <if test="search != null and search != ''">
+            AND create_time_ LIKE CONCAT(#{search},'%')
+        </if>
 	</select>
 
     <select id="selectDetailByTransNo" resultMap="SysUserCashAccountDetail">
-		SELECT * FROM sys_user_cash_account_detail WHERE    trans_no_ = #{transNo}
+		SELECT * FROM sys_user_cash_account_detail WHERE  trans_no_ = #{transNo}
 	</select>
 </mapper>

+ 25 - 13
mec-student/src/main/java/com/ym/mec/student/controller/SysMessageController.java

@@ -1,18 +1,5 @@
 package com.ym.mec.student.controller;
 
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiOperation;
-
-import java.io.IOException;
-
-import org.apache.commons.lang.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.entity.SysMessage;
@@ -25,6 +12,17 @@ import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext.MessageSender;
 import com.ym.mec.util.validator.CommonValidator;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
 
 @RestController
 @Api(tags = "消息服务")
@@ -111,6 +109,20 @@ public class SysMessageController extends BaseController {
 		return succeed();
 	}
 
+	@ApiOperation(value = "发送短信验证码")
+	@PostMapping("/noAuth/sendSmsCode")
+	public Object noAuthSendSmsCode(String sendCodeType, String mobileNo) {
+		MessageType messageType = MessageType.getMessageType(sendCodeType);
+		if (messageType == null) {
+			throw new BizException("消息类型参数错误");
+		}
+		if (StringUtils.isBlank(mobileNo) || !CommonValidator.isMobileNo(mobileNo)) {
+			throw new BizException("请输入正确的手机号");
+		}
+//		sysMessageService.sendSecurityCode(MessageSender.YIMEI, userId, MessageSendMode.SMS, messageType, mobileNo);
+		return succeed();
+	}
+
 	@ApiOperation(value = "发送消息")
 	@PostMapping("/sendMessage")
 	public Object sendMessage(MessageSender messageSender, MessageSendMode sendMode, String content, String receiver, int readStatus, String url) {

+ 12 - 3
mec-web/src/main/java/com/ym/mec/web/controller/StudentWithdrawController.java

@@ -1,5 +1,7 @@
 package com.ym.mec.web.controller;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.WithdrawDto;
 import com.ym.mec.biz.dal.entity.CooperationOrgan;
 import com.ym.mec.biz.dal.entity.StudentWithdraw;
@@ -22,11 +24,18 @@ public class StudentWithdrawController extends BaseController {
 
     @Autowired
     private StudentWithdrawService studentWithdrawService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
 
-    @ApiOperation(value = "新增")
+    @ApiOperation(value = "新增提现申请")
     @PostMapping("/add")
-    public Object add(StudentWithdraw studentWithdraw) {
-        studentWithdrawService.insert(studentWithdraw);
+    public Object add(StudentWithdraw studentWithdraw) throws Exception {
+        SysUser sysUser = sysUserFeignService.queryUserInfo();
+        if(sysUser == null && sysUser.getId() == null){
+            return failed("获取用户信息失败");
+        }
+        studentWithdraw.setUserId(sysUser.getId());
+        studentWithdrawService.add(studentWithdraw);
         return succeed();
     }
 

+ 2 - 10
mec-web/src/main/java/com/ym/mec/web/controller/SysUserBankCardController.java

@@ -45,21 +45,13 @@ public class SysUserBankCardController extends BaseController {
         return succeed();
     }
 
-    /*@ApiOperation(value = "修改银行卡信息")
-    @PostMapping("/update")
-    public Object update(SysUserBankCard sysUserBankCard) {
-        sysUserBankCard.setModifyOn(new Date());
-        sysUserBankCardService.update(sysUserBankCard);
-        return succeed();
-    }*/
-
     @ApiOperation(value = "分页查询银行卡信息列表")
     @GetMapping("/queryPage")
-    public Object queryPage(String search) {
+    public Object queryPage() {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if(sysUser == null || sysUser.getId() == null){
             return failed("获取用户失败");
         }
-        return succeed(sysUserBankCardService.findByUser(search,sysUser.getId()));
+        return succeed(sysUserBankCardService.findByUser(sysUser.getId()));
     }
 }

+ 10 - 20
mec-web/src/main/java/com/ym/mec/web/controller/SysUserCashAccountDetailController.java

@@ -1,22 +1,18 @@
 package com.ym.mec.web.controller;
 
+import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.CashAccountDetail;
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
 import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
 import com.ym.mec.biz.service.SysUserCashAccountDetailService;
-import com.ym.mec.biz.service.SysUserCashAccountService;
 import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.page.QueryInfo;
-import com.ym.mec.common.security.AuthUser;
-import com.ym.mec.common.security.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-import io.swagger.annotations.ApiParam;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
-
-import java.util.Date;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
 
 @RequestMapping("userCashAccountDetail")
 @Api(tags = "用户交易明细服务")
@@ -25,6 +21,8 @@ public class SysUserCashAccountDetailController extends BaseController {
 
     @Autowired
     private SysUserCashAccountDetailService sysUserCashAccountDetailService;
+    @Autowired
+    private SysUserFeignService sysUserFeignService;
 
     @ApiOperation(value = "新增用户交易明细")
     @PostMapping("/add")
@@ -33,22 +31,14 @@ public class SysUserCashAccountDetailController extends BaseController {
         return succeed();
     }
 
-//    @ApiOperation(value = "修改用户交易明细")
-//    @PostMapping("/update")
-//    public Object update(SysUserCashAccountDetail sysUserCashAccountDetail) {
-//        sysUserCashAccountDetail.setUpdateTime(new Date());
-//        sysUserCashAccountDetailService.update(sysUserCashAccountDetail);
-//        return succeed();
-//    }
-
     @ApiOperation(value = "分页查询用户交易明细")
     @GetMapping("/queryPage")
     public Object queryPage(CashAccountDetail queryInfo) {
-        AuthUser user = SecurityUtils.getUser();
-        if(user == null){
+        SysUser user = sysUserFeignService.queryUserInfo();
+        if(user == null && user.getId() != null){
             return failed("请重新登录");
         }
-        queryInfo.setUserId(user.getUserId());
+        queryInfo.setUserId(user.getId());
         return succeed(sysUserCashAccountDetailService.queryPage(queryInfo));
     }