Browse Source

验证码+停车费同步问题+审核扣除预存款时判断是否选了合作伙伴

qzyReal 2 years ago
parent
commit
f18f29c9a2

+ 86 - 19
sp-admin/login.html

@@ -33,6 +33,7 @@
 				margin: 0 auto !important;
 				pointer-events: all;
 				border-radius: 0px;
+				border-radius: 10px;
 			}
 
 			.login-top {
@@ -59,6 +60,7 @@
 				width: 270px;
 				border-radius: 0px;
 				transition: all 0.2s;
+				border-radius: 10px;
 			}
 
 			.login-button:hover {
@@ -73,6 +75,25 @@
 			.login {
 				opacity: 0;
 			}
+
+			.captcha-input {
+				height: 40px;
+				border-radius: 5px;
+				border: 1px solid #e2e2e2;
+				width: 110px;
+				margin-left: 40px;
+				position: relative;
+				right: 10px;
+				font-size: 14px;
+				padding-left: 5px;
+			}
+
+			.captcha-img {
+				height: 30px;
+				border: 1px solid #e2e2e2;
+				border-radius: 5px;
+				cursor: pointer;
+			}
 		</style>
 	</head>
 	<body>
@@ -98,6 +119,16 @@
 							<div class="login-center-input-text">密码</div>
 						</div>
 					</div>
+					<div class="login-center clearfix">
+						<div style="display: flex;">
+							<div>
+								<input class="captcha-input" name="verCode" placeholder="验证码" />
+							</div>
+							<div class="captcha-img"><img id="captcha" />
+							</div>
+						</div>
+					</div>
+					<span style="color: red;margin-left: 70px;" id="notice"></span>
 					<div class="login-button">登录</div>
 				</div>
 			</div>
@@ -120,39 +151,72 @@
 			var page_title = '场站管理系统 后台登录'; // 页面标题
 			var key = ''; // 默认的账号
 			var password = ''; // 默认的password
+			var codeKey = '';
 			var logo = ''; // logo地址,为空字符串则不显示
+			function getCaptcha() {
+				sa.ajaxNoLoading('/AccAdmin/captcha', function(res) {
+					let data = res.data;
+					$('#captcha').attr('src', data.image);
+					codeKey = data.key;
+				})
+			}
+			$(function() {
+				$('#notice').html('')
+				getCaptcha();
+			});
+			$('#captcha').click(function() {
+				getCaptcha()
+			})
 			// 点击登录按钮
 			document.querySelector(".login-button").onclick = function() {
-			
 				// 1、取值
 				var p = {
 					key: $('[name=key]').val(),
-					password: $('[name=password]').val()
+					password: $('[name=password]').val(),
+					verCode: $('[name=verCode]').val(),
+					code: codeKey
 				}
 				// 2、判断
 				if (p.key == '' || p.password == '') {
 					return layer.msg('请输入账号密码');
 				}
+				if (p.verCode == '') {
+					return layer.msg('请输入验证码');
+				}
 				// 3、请求后台
-				sa.ajax('/AccAdmin/doLogin', p, function(res) {
-					// 写入token
-					if (res.data.tokenInfo) {
-						localStorage.tokenName = res.data.tokenInfo.tokenName;
-						localStorage.tokenValue = res.data.tokenInfo.tokenValue;
-					}
-					// 写入权限码
-					sa.setAuth(res.data.per_list);
-					// 打个招呼,进入 index.html
-					sa.msg('登录成功,欢迎你:' + p.key);
-					setTimeout(function() {
-						if (parent == window) {
-							location.href = "index.html";
+				$.ajax({
+					url: sa.cfg.api_url + '/AccAdmin/doLogin',
+					data: p,
+					method: 'post',
+					success: function(res) {
+						let code = res.code;
+						if (code == 200) {
+							$('#notice').html('')
+							// 写入token
+							if (res.data.tokenInfo) {
+								localStorage.tokenName = res.data.tokenInfo.tokenName;
+								localStorage.tokenValue = res.data.tokenInfo.tokenValue;
+							}
+							// 写入权限码
+							sa.setAuth(res.data.per_list);
+							// 打个招呼,进入 index.html
+							sa.msg('登录成功,欢迎你:' + p.key);
+							setTimeout(function() {
+								if (parent == window) {
+									location.href = "index.html";
+								} else {
+									sa.closeCurrIframe();
+									parent.location.reload();
+								}
+							}, 500);
 						} else {
-							sa.closeCurrIframe();
-							parent.location.reload();
+							$('#notice').html(res.msg);
+							getCaptcha();
 						}
-					}, 500);
+					}
 				})
+
+
 			}
 			// 你所有要改的代码全在这里   ↑↑↑↑↑
 		</script>
@@ -178,5 +242,8 @@
 				document.querySelector('.login').style.opacity = '1';
 			}, 0)
 		</script>
+		<script type="text/javascript">
+
+		</script>
 	</body>
-</html>
+</html>

+ 2 - 2
sp-admin/sa-frame/sa-code.js

@@ -89,8 +89,8 @@ sa_admin.dropList = [		// 头像点击处可操作的选项
     {
         name: '切换账号',
         click: function () {
-            // sa.showIframe('切换账号', 'login.html', '70%', '80%');
-            sa.$page.openLogin('login.html');
+            sa.showIframe('切换账号', 'login.html', '70%', '80%');
+            // sa.$page.openLogin('login.html');
         }
     },
     {

+ 1 - 1
sp-admin/static/sa.js

@@ -22,7 +22,7 @@ var sa = {
 		api_url: 'https://dxkaa1.gxbtka.com/pro',
 		web_url: 'http://www.baidu.com'
 	}
-	sa.cfg = cfg_dev; // 最终环境 , 上线前请选择正确的环境
+	sa.cfg = cfg_test; // 最终环境 , 上线前请选择正确的环境
 })();
 
 

+ 5 - 0
sp-server/pom.xml

@@ -189,6 +189,11 @@
 			<scope>system</scope>
 			<systemPath>${project.basedir}/src/main/resources/lib/encrypt-base-1.0.3.jar</systemPath>
 		</dependency>
+		<dependency>
+			<groupId>com.github.whvcse</groupId>
+			<artifactId>easy-captcha</artifactId>
+			<version>1.6.2</version>
+		</dependency>
 	</dependencies>
 
 	<!-- 构建配置 -->

+ 16 - 6
sp-server/src/main/java/com/pj/api/pushfee/task/FeeDetailSyncTask.java

@@ -19,6 +19,7 @@ import com.pj.constants.business.FeeTypeEnum;
 import com.pj.constants.business.PartFeeEnum;
 import com.pj.constants.business.PayEnum;
 import com.pj.current.config.PushfeeConfig;
+import com.pj.current.config.SystemObject;
 import com.pj.current.task.Task;
 import com.pj.project.sync.HelpService;
 import com.pj.project.sync.bo.SyncResultBO;
@@ -79,18 +80,27 @@ public class FeeDetailSyncTask extends Task {
         TbFeeItemService tbFeeItemService = SpringUtil.getBean(TbFeeItemService.class);
         TbItemService tbItemService = SpringUtil.getBean(TbItemService.class);
         TbFeeItem tbFeeItem = tbFeeItemService.getById(tbFeeDetails.getFeeType());
-        TbItem tbItem= tbItemService.getById(tbFeeDetails.getItemId());
+        TbItem tbItem = tbItemService.getById(tbFeeDetails.getItemId());
+        if (tbItem != null) {
+            opd.setBizTypeNo(tbItem.getItemCode())
+                    .setGoodNo(tbItem.getItemCode()).setGoodName(tbItem.getItemName());
+        }else {
+            if (tbFeeDetails.getFeeType()==FeeTypeEnum.PARK_FEE.getCode()){
+                //停车费
+                tbItem=tbItemService.findByAliasName(SystemObject.config.getPartItemAlias());
+                opd.setBizTypeNo(tbItem.getItemCode())
+                        .setGoodNo(tbItem.getItemCode()).setGoodName(tbItem.getItemName());
+            }
+        }
         String subBillNo = StrUtil.isEmpty(tbFeeDetails.getBusinessNo()) ? tbFeeDetails.getBusinessCarNo() : tbFeeDetails.getBusinessNo();
         String classifyPath = tbFeeDetails.getFeeType() + "-" + itemTypeId + "-" + itemId;
         opd.setSyncType(syncType)
                 .setSubjectNo(tbFeeDetails.getCarNo())
                 .setSubjectName(tbFeeDetails.getCarNo())
                 .setSubBillNo(subBillNo).setCalculateId(tbFeeDetails.getCalculateId())
-                .setBizTypeNo(tbItem.getItemCode()).setPayStatus("1")
-                .setPayStatusDesc("已支付")
-                .setGoodNo(tbItem.getItemCode()).setGoodName(tbItem.getItemName())
-                .setBillStatusDesc(tbFeeDetails.getItemTypeName()+tbFeeDetails.getItemName())
-                .setBillDesc(tbFeeDetails.getItemTypeName()+tbFeeDetails.getItemName())
+                .setPayStatusDesc("已支付").setPayStatus("1")
+                .setBillStatusDesc(tbFeeDetails.getItemTypeName() + tbFeeDetails.getItemName())
+                .setBillDesc(tbFeeDetails.getItemTypeName() + tbFeeDetails.getItemName())
                 .setQuantity(tbFeeDetails.getNum())
                 .setBizTypeName(tbFeeDetails.getItemTypeName())
                 .setChargeItemName(tbFeeItem.getName())

+ 1 - 0
sp-server/src/main/java/com/pj/current/satoken/SaTokenConfigure.java

@@ -40,6 +40,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
         add("/TbFeeDetails/feeTypeStatics");
         add("/TbBusinessCar/staticsCar");
         add("/AccAdmin/doLogin");
+        add("/AccAdmin/captcha");
         add("/AccAdmin/checkTimeout");
         add("/AccAdmin/doExit");
         add("/api/checkUserType");

+ 3 - 0
sp-server/src/main/java/com/pj/project/tb_business/TbBusinessService.java

@@ -1743,6 +1743,9 @@ public class TbBusinessService extends ServiceImpl<TbBusinessMapper, TbBusiness>
                     expenses.add(orderItem);
                     IOrderPriceRes res = syncService.orderPriceCal(expenses);
                     BigDecimal price = res.getTotalOrderPrice();
+                    if (StrUtil.isEmpty(customerId)||tbAccount==null){
+                        throw new AjaxError("未选择合作伙伴");
+                    }
                     BigDecimal balance = tbAccount.getTotalMoney();
                     if (price.compareTo(balance) > 0) {
                         throw new AjaxError("[" + tbAccount.getCustomerName() + "]账户余额不足扣除" + item.getItemName());

+ 38 - 4
sp-server/src/main/java/com/pj/project4sp/admin4login/SpAccAdminController.java

@@ -4,6 +4,7 @@ import cn.dev33.satoken.stp.StpUtil;
 import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.extension.api.R;
 import com.pj.current.config.SystemObject;
 import com.pj.project4sp.admin.SpAdmin;
 import com.pj.project4sp.admin.SpAdminUtil;
@@ -14,11 +15,19 @@ import com.pj.utils.sg.AjaxError;
 import com.pj.utils.sg.AjaxJson;
 import com.pj.utils.sg.NbUtil;
 import com.pj.utils.so.SoMap;
+import com.wf.captcha.SpecCaptcha;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
 
 /**
  * admin账号相关的接口
@@ -27,6 +36,7 @@ import javax.servlet.http.HttpServletRequest;
  */
 @RestController
 @RequestMapping("/AccAdmin/")
+@Slf4j
 public class SpAccAdminController {
 
 
@@ -41,21 +51,45 @@ public class SpAccAdminController {
      * 账号、密码登录
      */
     @RequestMapping("doLogin")
-    AjaxJson doLogin(String key, String password) {
+    AjaxJson doLogin(String key, String password, String code, String verCode) {
         // 1、验证参数
         if (NbUtil.isOneNull(key, password)) {
             return AjaxJson.getError("请提供key与password参数");
         }
+        if (NbUtil.isOneNull(verCode, code)) {
+            return AjaxJson.getError("请输入验证码");
+        }
+        String cacheCode = RedisUtil.get(code);
+        if (NbUtil.isNull(cacheCode)) {
+            return AjaxJson.getError("验证码已过期");
+        }
+        if (!StrUtil.equals(cacheCode.toUpperCase(), verCode.toUpperCase())) {
+            return AjaxJson.getError("验证码不正确");
+        }
+        RedisUtil.del(code);
         return spAccAdminService.doLogin(key, password);
     }
 
+    @PostMapping("captcha")
+    public AjaxJson render() {
+        SpecCaptcha captcha = new SpecCaptcha(120, 45, 5);
+        String key = UUID.randomUUID().toString();
+        String verCode = captcha.text().toLowerCase();   // 获取验证码的字符
+        log.info("验证码 Key:{} Vercode:{}", key, verCode);
+        RedisUtil.setBySECONDS(key, verCode, 60);
+        Map<String, String> map = new HashMap<>();
+        map.put("key", key);
+        map.put("image", captcha.toBase64());
+        return AjaxJson.getSuccessData(map);
+    }
+
 
     @RequestMapping("checkTimeout")
     AjaxJson checkTimeout() {
-        if (!StpUtil.isLogin()){
+        if (!StpUtil.isLogin()) {
             return AjaxJson.getSuccess();
         }
-        String key=StpUtil.getLoginIdAsString();
+        String key = StpUtil.getLoginIdAsString();
         String time = RedisUtil.get(key);
         String now = DateUtil.now();
         if (StrUtil.isEmpty(time)) {
@@ -63,7 +97,7 @@ public class SpAccAdminController {
         }
         long min = DateUtil.between(DateUtil.parseDateTime(time), DateUtil.parseDateTime(now), DateUnit.MINUTE);
         if (min > SystemObject.config.getLoginOutMinute()) {
-           return AjaxJson.getError("操作超时",405);
+            return AjaxJson.getError("操作超时", 405);
         }
         return AjaxJson.getSuccess();
     }

+ 20 - 0
sp-server/src/main/java/com/pj/project4sp/admin4login/SpAccAdminService.java

@@ -3,6 +3,8 @@ package com.pj.project4sp.admin4login;
 
 import cn.dev33.satoken.spring.SpringMVCUtil;
 import cn.dev33.satoken.stp.StpUtil;
+import cn.hutool.cache.CacheUtil;
+import cn.hutool.cache.impl.TimedCache;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import com.pj.current.config.SystemObject;
@@ -55,7 +57,22 @@ public class SpAccAdminService {
         return doLogin(key, password, null);
     }
 
+    private TimedCache<String, Integer> TRY_COUNT = CacheUtil.newTimedCache(180000);
+    private TimedCache<String, Integer> LOCK_CACHE = CacheUtil.newTimedCache(600000);
+
     public AjaxJson doLogin(String key, String password, String openid) {
+        Integer lock = LOCK_CACHE.get(key,false);
+        if (lock!=null){
+            return AjaxJson.getError("账户已被锁定,请10分钟后尝试");
+        }
+        Integer count = TRY_COUNT.get(key);
+        if (count == null) {
+            count = 0;
+        }
+        if (count >= 5) {
+            LOCK_CACHE.put(key, 1);
+            return AjaxJson.getError("账户已被锁定,请10分钟后尝试");
+        }
         // 0、判断 way (1=ID, 2=昵称,3=手机号  )
         int way = 2;
         if (NbUtil.isNumber(key)) {
@@ -78,6 +95,7 @@ public class SpAccAdminService {
         }
         // 3、开始验证
         if (admin == null) {
+            TRY_COUNT.put(key, count + 1);
             return AjaxJson.getError("账号或密码错误");
         }
         if (NbUtil.isNull(admin.getPassword2())) {
@@ -85,6 +103,7 @@ public class SpAccAdminService {
         }
         String md5Password = SystemObject.getPasswordMd5(admin.getId(), password);
         if (!admin.getPassword2().equals(md5Password)) {
+            TRY_COUNT.put(key, count + 1);
             return AjaxJson.getError("账号或密码错误");
         }
         // 4、是否禁用
@@ -111,6 +130,7 @@ public class SpAccAdminService {
             admin.setOpenid(openid);
             spAdminMapper.updateOpenid(admin);
         }
+        TRY_COUNT.put(key, 0);
         return AjaxJson.getSuccessData(map);
     }