| package com.dsh.account.controller; | 
|   | 
| import com.dsh.account.entity.TAppUser; | 
| import com.dsh.account.model.AddAppUserVo; | 
| import com.dsh.account.model.JoinPlayPaiVo; | 
| import com.dsh.account.model.LoginSMSCodeVo; | 
| import com.dsh.account.model.LoginWeChatVo; | 
| import com.dsh.account.service.IVipPaymentService; | 
| import com.dsh.account.service.TAppUserService; | 
| import com.dsh.account.util.PayMoneyUtil; | 
| import com.dsh.account.util.ResultUtil; | 
| import com.dsh.account.util.TokenUtil; | 
| import com.dsh.account.util.ToolUtil; | 
| import io.swagger.annotations.ApiImplicitParam; | 
| import io.swagger.annotations.ApiImplicitParams; | 
| import io.swagger.annotations.ApiOperation; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.web.bind.annotation.*; | 
|   | 
| import javax.servlet.http.HttpServletRequest; | 
| import javax.servlet.http.HttpServletResponse; | 
| import java.io.PrintWriter; | 
| import java.util.Map; | 
|   | 
| /** | 
|  * @author zhibing.pu | 
|  * @date 2023/6/14 15:30 | 
|  */ | 
| @RestController | 
| @RequestMapping("") | 
| public class AppUserController { | 
|   | 
|     @Autowired | 
|     private TAppUserService appUserService; | 
|   | 
|     @Autowired | 
|     private PayMoneyUtil payMoneyUtil; | 
|   | 
|     @Autowired | 
|     private IVipPaymentService vipPaymentService; | 
|   | 
|     @Autowired | 
|     private TokenUtil tokenUtil; | 
|   | 
|   | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/getSMSCode") | 
|     @ApiOperation(value = "获取短信验证码", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "类型(1:登录,2:注册,3:修改密码,4:忘记密码)", name = "type", dataType = "int", required = true), | 
|             @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true) | 
|     }) | 
|     public ResultUtil getSMSCode(Integer type, String phone){ | 
|         if(ToolUtil.isEmpty(phone)){ | 
|             return ResultUtil.paranErr("phone"); | 
|         } | 
|         if(ToolUtil.isEmpty(type)){ | 
|             return ResultUtil.paranErr("type"); | 
|         } | 
|         try { | 
|             ResultUtil smsCode = appUserService.getSMSCode(type, phone); | 
|             return smsCode; | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/addAppUser") | 
|     @ApiOperation(value = "注册用户", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|     }) | 
|     public ResultUtil addAppUser(AddAppUserVo addAppUserVo){ | 
|         try { | 
|             return appUserService.addAppUser(addAppUserVo); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/loginPassword") | 
|     @ApiOperation(value = "账号密码登录", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true), | 
|             @ApiImplicitParam(value = "登录密码", name = "password", dataType = "string", required = true) | 
|     }) | 
|     public ResultUtil<String> loginPassword(String phone, String password){ | 
|         if(ToolUtil.isEmpty(phone)){ | 
|             return ResultUtil.paranErr("phone"); | 
|         } | 
|         if(ToolUtil.isEmpty(password)){ | 
|             return ResultUtil.paranErr("password"); | 
|         } | 
|         try { | 
|             return appUserService.loginPassword(phone, password); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/loginSMSCode") | 
|     @ApiOperation(value = "短信验证码登录", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|     }) | 
|     public ResultUtil<String> loginSMSCode(LoginSMSCodeVo loginSMSCodeVo){ | 
|         try { | 
|             return appUserService.loginSMSCode(loginSMSCodeVo); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/loginWeChat") | 
|     @ApiOperation(value = "微信登录", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|     }) | 
|     public ResultUtil<String> loginWeChat(LoginWeChatVo loginWeChatVo){ | 
|         try { | 
|             return appUserService.loginWechat(loginWeChatVo); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/updatePassword") | 
|     @ApiOperation(value = "修改密码", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true), | 
|             @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true), | 
|             @ApiImplicitParam(value = "新密码", name = "password", dataType = "string", required = true) | 
|     }) | 
|     public ResultUtil updatePassword(String phone, String code, String password){ | 
|         if(ToolUtil.isEmpty(phone)){ | 
|             return ResultUtil.paranErr("phone"); | 
|         } | 
|         if(ToolUtil.isEmpty(code)){ | 
|             return ResultUtil.paranErr("code"); | 
|         } | 
|         if(ToolUtil.isEmpty(password)){ | 
|             return ResultUtil.paranErr("password"); | 
|         } | 
|         try { | 
|             return appUserService.updatePassword(phone, code, password); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/forgetPassword") | 
|     @ApiOperation(value = "忘记密码", tags = {"APP-登录注册"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "电话号码", name = "phone", dataType = "string", required = true), | 
|             @ApiImplicitParam(value = "短信验证码", name = "code", dataType = "string", required = true), | 
|             @ApiImplicitParam(value = "新密码", name = "password", dataType = "string", required = true) | 
|     }) | 
|     public ResultUtil forgetPassword(String phone, String code, String password){ | 
|         if(ToolUtil.isEmpty(phone)){ | 
|             return ResultUtil.paranErr("phone"); | 
|         } | 
|         if(ToolUtil.isEmpty(code)){ | 
|             return ResultUtil.paranErr("code"); | 
|         } | 
|         if(ToolUtil.isEmpty(password)){ | 
|             return ResultUtil.paranErr("password"); | 
|         } | 
|         try { | 
|             return appUserService.updatePassword(phone, code, password); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/api/appUser/queryJoinPlayPai") | 
|     @ApiOperation(value = "获取加入玩湃首页数据", tags = {"APP-加入玩湃"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "经度", name = "lon", dataType = "string", required = false), | 
|             @ApiImplicitParam(value = "纬度", name = "lat", dataType = "string", required = false), | 
|             @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") | 
|     }) | 
|     public ResultUtil<JoinPlayPaiVo> queryJoinPlayPai(String lon, String lat){ | 
|         try { | 
|             Integer uid = tokenUtil.getUserIdFormRedis(); | 
|             if(null == uid){ | 
|                 return ResultUtil.tokenErr(); | 
|             } | 
|             JoinPlayPaiVo joinPlayPaiVo = appUserService.queryJoinPlayPai(uid, lon, lat); | 
|             return ResultUtil.success(joinPlayPaiVo); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     @ResponseBody | 
|     @PostMapping("/api/appUser/addVipPayment") | 
|     @ApiOperation(value = "购买年度会员", tags = {"APP-成为会员"}) | 
|     @ApiImplicitParams({ | 
|             @ApiImplicitParam(value = "支付方式(1=微信,2=支付宝)", name = "payType", dataType = "int", required = true), | 
|             @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") | 
|     }) | 
|     public ResultUtil addVipPayment(Integer payType){ | 
|         if(ToolUtil.isEmpty(payType)){ | 
|             return ResultUtil.paranErr("payType"); | 
|         } | 
|         try { | 
|             Integer uid = tokenUtil.getUserIdFormRedis(); | 
|             if(null == uid){ | 
|                 return ResultUtil.tokenErr(); | 
|             } | 
|             return vipPaymentService.addVipPayment(uid, payType); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return ResultUtil.runErr(); | 
|         } | 
|     } | 
|   | 
|   | 
|   | 
|   | 
|   | 
|   | 
|     /** | 
|      * 购买年度会员支付微信回调 | 
|      * @param request | 
|      * @param response | 
|      */ | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/addVipPaymentWeChatCallback") | 
|     public void addVipPaymentWeChatCallback(HttpServletRequest request, HttpServletResponse response){ | 
|         try { | 
|             Map<String, String> map = payMoneyUtil.weixinpayCallback(request); | 
|             if(null != map){ | 
|                 String out_trade_no = map.get("out_trade_no"); | 
|                 String transaction_id = map.get("transaction_id"); | 
|                 String result = map.get("result"); | 
|                 ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, transaction_id); | 
|                 if(resultUtil.getCode() == 200){ | 
|                     PrintWriter out = response.getWriter(); | 
|                     out.write(result); | 
|                     out.flush(); | 
|                     out.close(); | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 购买年度会员支付支付宝回调 | 
|      * @param request | 
|      * @param response | 
|      */ | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/addVipPaymentAliCallback") | 
|     public void addVipPaymentAliCallback(HttpServletRequest request, HttpServletResponse response){ | 
|         try { | 
|             Map<String, String> map = payMoneyUtil.alipayCallback(request); | 
|             if(null != map){ | 
|                 String out_trade_no = map.get("out_trade_no"); | 
|                 String trade_no = map.get("trade_no"); | 
|                 ResultUtil resultUtil = vipPaymentService.addVipPaymentCallback(out_trade_no, trade_no); | 
|                 if(resultUtil.getCode() == 200){ | 
|                     PrintWriter out = response.getWriter(); | 
|                     out.write("success"); | 
|                     out.flush(); | 
|                     out.close(); | 
|                 } | 
|             } | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 根据用户id获取用户信息 | 
|      * @param appUserId | 
|      * @return | 
|      */ | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/queryAppUser") | 
|     public TAppUser queryAppUser(@RequestBody Integer appUserId){ | 
|         try { | 
|             TAppUser appUser = appUserService.getById(appUserId); | 
|             return appUser; | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|             return null; | 
|         } | 
|     } | 
|   | 
|   | 
|     /** | 
|      * 修改用户信息 | 
|      * @param appUser | 
|      */ | 
|     @ResponseBody | 
|     @PostMapping("/base/appUser/updateAppUser") | 
|     public void updateAppUser(@RequestBody TAppUser appUser){ | 
|         try { | 
|             appUserService.updateById(appUser); | 
|         }catch (Exception e){ | 
|             e.printStackTrace(); | 
|         } | 
|     } | 
| } |