From eaa20cb58afc80e3612fd6e93d6f27e181a027e7 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 07 四月 2023 17:38:29 +0800
Subject: [PATCH] 提交用户端开发版本

---
 user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java |  355 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 352 insertions(+), 3 deletions(-)

diff --git a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java
index 4215feb..facf287 100644
--- a/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java
+++ b/user/guns-admin/src/main/java/com/supersavedriving/user/modular/api/AppUserController.java
@@ -1,13 +1,19 @@
 package com.supersavedriving.user.modular.api;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.supersavedriving.user.core.common.annotion.ServiceLog;
 import com.supersavedriving.user.core.util.ToolUtil;
 import com.supersavedriving.user.modular.system.model.AppUser;
-import com.supersavedriving.user.modular.system.service.IAppUserService;
-import com.supersavedriving.user.modular.system.service.IDriverService;
+import com.supersavedriving.user.modular.system.model.SystemConfig;
+import com.supersavedriving.user.modular.system.service.*;
+import com.supersavedriving.user.modular.system.util.PayMoneyUtil;
+import com.supersavedriving.user.modular.system.util.RedisUtil;
 import com.supersavedriving.user.modular.system.util.ResultUtil;
 import com.supersavedriving.user.modular.system.util.UUIDUtil;
 import com.supersavedriving.user.modular.system.util.huawei.OBSUtil;
+import com.supersavedriving.user.modular.system.util.huawei.SMSUtil;
 import com.supersavedriving.user.modular.system.warpper.*;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -21,8 +27,11 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.InputStream;
+import java.io.PrintWriter;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 用户控制器
@@ -36,6 +45,24 @@
 
     @Autowired
     private IDriverService driverService;
+
+    @Autowired
+    private ISystemConfigService systemConfigService;
+
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
+    @Autowired
+    private IUserToCouponService userToCouponService;
+
+    @Autowired
+    private IAccountChangeDetailService accountChangeDetailService;
+
+    @Autowired
+    private IComplaintService complaintService;
+
+    @Autowired
+    private RedisUtil redisUtil;
 
 
 
@@ -155,6 +182,11 @@
             AppUser appUser = appUserService.selectById(uid);
             UserInfoWarpper userInfoWarpper = new UserInfoWarpper();
             BeanUtils.copyProperties(appUser, userInfoWarpper);
+            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 7));
+            if(null != systemConfig){
+                JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
+                userInfoWarpper.setServiceCell(jsonObject.getString("num1"));
+            }
             return ResponseWarpper.success(userInfoWarpper);
         }catch (Exception e){
             e.printStackTrace();
@@ -174,7 +206,7 @@
     public ResponseWarpper<String> uploadImg(MultipartFile file){
         try {
             InputStream inputStream = file.getInputStream();
-            String name = file.getName();
+            String name = file.getOriginalFilename();
             name = UUIDUtil.getRandomCode() + name.substring(name.lastIndexOf("."));
             String s = OBSUtil.putObjectToBucket(inputStream, name);
             return ResponseWarpper.success(s);
@@ -183,4 +215,321 @@
             return new ResponseWarpper(500, e.getMessage());
         }
     }
+
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/updateUserInfo")
+//    @ServiceLog(name = "修改个人信息", url = "/api/appUser/updateUserInfo")
+    @ApiOperation(value = "修改个人信息", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper updateUserInfo(UserInfo userInfo){
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            ResultUtil resultUtil = appUserService.updateUserInfo(uid, userInfo);
+            return ResponseWarpper.success(resultUtil);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/queryPriceRules")
+//    @ServiceLog(name = "获取价格表", url = "/api/appUser/queryPriceRules")
+    @ApiOperation(value = "获取价格表", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<PriceRulesWarpper> queryPriceRules(){
+        try {
+            PriceRulesWarpper priceRulesWarpper = systemConfigService.queryPriceRules();
+            return ResponseWarpper.success(priceRulesWarpper);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/queryTopUpPrompt")
+//    @ServiceLog(name = "获取充值优惠提示", url = "/api/appUser/queryTopUpPrompt")
+    @ApiOperation(value = "获取充值优惠提示", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<String> queryTopUpPrompt(){
+        try {
+            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 6));
+            if(null != systemConfig){
+                JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
+                return ResponseWarpper.success("充值满" + jsonObject.getDouble("num2") + "元,下单享9折优惠!");
+            }
+            return ResponseWarpper.success();
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/rechargeBalance")
+//    @ServiceLog(name = "充值操作", url = "/api/appUser/rechargeBalance")
+    @ApiOperation(value = "充值操作", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "充值金额", name = "amount", required = true, dataType = "double"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper rechargeBalance(Double amount){
+        if(null == amount){
+            return ResponseWarpper.success(ResultUtil.paranErr("amount"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            ResultUtil resultUtil = appUserService.rechargeBalance(uid, amount);
+            return ResponseWarpper.success(resultUtil);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/base/appUser/rechargeBalanceCallback")
+//    @ServiceLog(name = "余额充值回调", url = "/base/appUser/rechargeBalanceCallback")
+    public void rechargeBalanceCallback(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");
+                String orderId = out_trade_no.substring(17);
+                appUserService.rechargeBalanceCallback(out_trade_no, transaction_id);
+                PrintWriter out = response.getWriter();
+                out.print(result);
+                out.flush();
+                out.close();
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/queryMyCoupons")
+//    @ServiceLog(name = "获取优惠券列表", url = "/api/appUser/queryMyCoupons")
+    @ApiOperation(value = "获取优惠券列表", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "状态(1=未使用,2=已使用,3=已过期)", name = "state", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<List<CouponsWarpper>> queryMyCoupons(Integer state, Integer pageNum, Integer pageSize){
+        if(null == state){
+            return ResponseWarpper.success(ResultUtil.paranErr("state"));
+        }
+        if(null == pageNum){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
+        }
+        if(null == pageSize){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            List<CouponsWarpper> couponsWarppers = userToCouponService.queryMyCoupons(uid, state, pageNum, pageSize);
+            return ResponseWarpper.success(couponsWarppers);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/queryUsedCouponNum")
+//    @ServiceLog(name = "获取已使用优惠券数量", url = "/api/appUser/queryUsedCouponNum")
+    @ApiOperation(value = "获取已使用优惠券数量", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<Integer> queryUsedCouponNum(){
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            Integer integer = userToCouponService.queryUsedCouponNum(uid);
+            return ResponseWarpper.success(integer);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/queryBalanceDetails")
+//    @ServiceLog(name = "获取余额明细", url = "/api/appUser/queryBalanceDetails")
+    @ApiOperation(value = "获取余额明细", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "统计时间", name = "time", required = true, dataType = "string"),
+            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
+            @ApiImplicitParam(value = "页条数", name = "pageSize", required = true, dataType = "int"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper<List<BalanceDetailsWarpper>> queryBalanceDetails(String time, Integer pageNum, Integer pageSize){
+        if(ToolUtil.isEmpty(time)){
+            return ResponseWarpper.success(ResultUtil.paranErr("time"));
+        }
+        if(null == pageNum){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageNum"));
+        }
+        if(null == pageSize){
+            return ResponseWarpper.success(ResultUtil.paranErr("pageSize"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            List<BalanceDetailsWarpper> balanceDetailsWarppers = accountChangeDetailService.queryBalanceDetails(uid, time, pageNum, pageSize);
+            return ResponseWarpper.success(balanceDetailsWarppers);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/cancelAccount")
+//    @ServiceLog(name = "注销账号", url = "/api/appUser/cancelAccount")
+    @ApiOperation(value = "注销账号", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper cancelAccount(){
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            AppUser appUser = appUserService.selectById(uid);
+            appUser.setStatus(3);
+            appUserService.updateById(appUser);
+            return ResponseWarpper.success();
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/api/appUser/feedback")
+//    @ServiceLog(name = "投诉反馈", url = "/api/appUser/feedback")
+    @ApiOperation(value = "投诉反馈", tags = {"用户端-首页", "用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "订单id", name = "orderId", required = false, dataType = "int"),
+            @ApiImplicitParam(value = "反馈内容", name = "content", required = true, dataType = "string"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper feedback(Integer orderId, String content){
+        if(null == content){
+            return ResponseWarpper.success(ResultUtil.paranErr("content"));
+        }
+        try {
+            Integer uid = appUserService.getUserByRequest();
+            if(null == uid){
+                return ResponseWarpper.success(ResultUtil.tokenErr());
+            }
+            complaintService.feedback(uid, orderId, content);
+            return ResponseWarpper.success();
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+
+    @ResponseBody
+    @PostMapping("/base/appUser/getVerificationCode")
+//    @ServiceLog(name = "获取短信验证码", url = "/base/appUser/getVerificationCode")
+    @ApiOperation(value = "获取短信验证码", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "国家代码+86", name = "receiver", required = true, dataType = "string"),
+            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"),
+    })
+    public ResponseWarpper getVerificationCode(String receiver, String phone){
+        if(ToolUtil.isEmpty(receiver)){
+            return ResponseWarpper.success(ResultUtil.paranErr("receiver"));
+        }
+        if(ToolUtil.isEmpty(phone)){
+            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
+        }
+        try {
+            String numberRandom = UUIDUtil.getNumberRandom(5);
+            SMSUtil.send(phone, "1d0f0cbe5b214b0d8efa891730eb532a", "[\"" + numberRandom + "\"]");
+            redisUtil.setStrValue(receiver + phone, numberRandom, 300);//5分钟有效期
+            return ResponseWarpper.success(ResultUtil.success());
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
+
+    @ResponseBody
+    @PostMapping("/base/appUser/verifySMSCode")
+//    @ServiceLog(name = "验证短信验证码", url = "/base/appUser/verifySMSCode")
+    @ApiOperation(value = "验证短信验证码", tags = {"用户端-个人中心"}, notes = "")
+    @ApiImplicitParams({
+            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
+            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
+            @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
+    })
+    public ResponseWarpper verifySMSCode(String phone, String code){
+        if(ToolUtil.isEmpty(phone)){
+            return ResponseWarpper.success(ResultUtil.paranErr("phone"));
+        }
+        if(ToolUtil.isEmpty(phone)){
+            return ResponseWarpper.success(ResultUtil.paranErr("code"));
+        }
+        try {
+            ResultUtil resultUtil = ResultUtil.success();
+            phone = phone.indexOf("+86") < 0 ? "+86" + phone : phone;
+            String value = redisUtil.getValue(phone);
+            if(ToolUtil.isEmpty(value) || !value.equals(code)){
+                resultUtil = ResultUtil.error("验证码无效");
+            }
+            redisUtil.remove(phone);
+            return ResponseWarpper.success(resultUtil);
+        }catch (Exception e){
+            e.printStackTrace();
+            return new ResponseWarpper(500, e.getMessage());
+        }
+    }
+
 }

--
Gitblit v1.7.1