| package com.matrix.system.shopXcx.api.action; | 
|   | 
| import com.baomidou.mybatisplus.core.metadata.IPage; | 
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
| import com.matrix.biz.bean.BizUser; | 
| import com.matrix.biz.dao.BizUserDao; | 
| import com.matrix.component.redis.RedisUserLoginUtils; | 
| import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil; | 
| import com.matrix.core.constance.MatrixConstance; | 
| import com.matrix.core.pojo.AjaxResult; | 
| import com.matrix.core.pojo.BasePageQueryDto; | 
| import com.matrix.system.fenxiao.dao.ShopRevenueFlowDao; | 
| import com.matrix.system.fenxiao.entity.ShopRevenueFlow; | 
| import com.matrix.system.hive.service.CodeService; | 
| import com.matrix.system.shopXcx.api.dto.RevenueFlowDto; | 
| import com.matrix.system.shopXcx.api.dto.WithdrawalCashDto; | 
| import com.matrix.system.shopXcx.vo.SalesOrderVo; | 
| import io.swagger.annotations.Api; | 
| import io.swagger.annotations.ApiOperation; | 
| import io.swagger.annotations.ApiResponse; | 
| import io.swagger.annotations.ApiResponses; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.validation.annotation.Validated; | 
| 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 java.util.Date; | 
|   | 
| /** | 
|  * @author jyy | 
|  * @date 2021-03-10 | 
|  **/ | 
| @Api(tags = "提现接口类") | 
| @RestController | 
| @RequestMapping(value = "/wxapi/salesWithdrawal") | 
| public class WxSalesWithdrawalAction { | 
|   | 
|   | 
|     @Autowired | 
|     private RedisUserLoginUtils redisUserLoginUtils; | 
|   | 
|     @Autowired | 
|     private BizUserDao bizUserDao; | 
|   | 
|     @Autowired | 
|     private ShopRevenueFlowDao revenueFlowDao; | 
|   | 
|   | 
|     @Autowired | 
|     private ShopRevenueFlowDao shopRevenueFlowDao; | 
|     @Autowired | 
|     WeixinServiceUtil weixinServiceUtil; | 
|   | 
|     @Autowired | 
|     CodeService codeService; | 
|   | 
|     @ApiOperation(value = "获取收支明细", notes = "") | 
|     @PostMapping(value = "/getInvitationuserList") | 
|     @ApiResponses({ | 
|             @ApiResponse(code = 200, message = "ok", response = ShopRevenueFlow.class) | 
|     }) | 
|     AjaxResult getInvitationuserList(@RequestBody @Validated RevenueFlowDto revenueFlowDto) { | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         Page<SalesOrderVo> page=new Page<>(revenueFlowDto.getPageNum(),revenueFlowDto.getPageSize()); | 
|         revenueFlowDto.setUserId(loginUser.getOpenId()); | 
|         IPage<SalesOrderVo> shopSalesmanApplyIPage = revenueFlowDao.selectRevenuFlowList(page,  revenueFlowDto); | 
|         AjaxResult result=AjaxResult.buildSuccessInstance(shopSalesmanApplyIPage.getRecords()); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     @ApiOperation(value = "提现", notes = "") | 
|     @PostMapping(value = "/withdrawalCash") | 
|     @ApiResponses({ | 
|             @ApiResponse(code = 200, message = "ok", response = BasePageQueryDto.class) | 
|     }) | 
|     @Transactional | 
|     AjaxResult withdrawalCash(@RequestBody @Validated WithdrawalCashDto withdrawalCashDto) { | 
|         BizUser loginUser = redisUserLoginUtils.getLoginUser(BizUser.class); | 
|         loginUser=bizUserDao.selectById(loginUser.getUserId()); | 
|         if(withdrawalCashDto.getAmount()<1){ | 
|             return AjaxResult.buildFailInstance("最小提现金额为1元"); | 
|         }else if(withdrawalCashDto.getAmount()>20000){ | 
|             return AjaxResult.buildFailInstance("最大提现金额为2万元"); | 
|         }else{ | 
|             if(loginUser.getWithdrawalCash()==null || loginUser.getWithdrawalCash()<withdrawalCashDto.getAmount()){ | 
|                 return AjaxResult.buildFailInstance("余额不足"); | 
|             }else{ | 
|   | 
|                 String txNo = codeService.get32LenNumberCode(); | 
|   | 
|              /*调试注释 | 
|              weixinServiceUtil.comPay("提现", txNo,Integer.parseInt((withdrawalCashDto.getAmount()*1000)+""), | 
|                         loginUser.getOpenId(),loginUser.getCompanyId()); | 
|                     */ | 
|                 //记录收益流水 | 
|                 ShopRevenueFlow invitationRevenueFlow=new ShopRevenueFlow(); | 
|                 invitationRevenueFlow.setCompanyId(loginUser.getCompanyId()); | 
|                 invitationRevenueFlow.setCreateBy(MatrixConstance.SYSTEM_USER); | 
|                 invitationRevenueFlow.setUpdateBy(txNo); | 
|                 invitationRevenueFlow.setCreateTime(new Date()); | 
|                 invitationRevenueFlow.setUpdateTime(new Date()); | 
|                 invitationRevenueFlow.setAmount(-withdrawalCashDto.getAmount()); | 
|                 invitationRevenueFlow.setUserId(loginUser.getOpenId()); | 
|                 invitationRevenueFlow.setRevenueContent("提现"); | 
|                 shopRevenueFlowDao.insert(invitationRevenueFlow); | 
|                 //扣除用户剩余提现金额 | 
|                 loginUser.setWithdrawalCash(loginUser.getWithdrawalCash()-withdrawalCashDto.getAmount()); | 
|                 bizUserDao.updateByModel(loginUser); | 
|                 redisUserLoginUtils.updateUserInfo(loginUser); | 
|   | 
|   | 
|                 return AjaxResult.buildSuccessInstance("提现成功"); | 
|             } | 
|         } | 
|   | 
|   | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
| } |