From b875f09c4814480cb2c4ec4c789fb805800e8776 Mon Sep 17 00:00:00 2001 From: Xia Kaixiang Date: Mon, 20 May 2019 19:19:52 +0800 Subject: [PATCH] =?utf8?q?=E5=95=86=E6=88=B7=E7=9A=84=E5=A2=9E=E5=88=A0?= =?utf8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../dlpay/framework/dao/ShopDao.java | 6 + .../dlpay/framework/dao/ShopaccDao.java | 12 +- .../dlpay/framework/domain/TShopacc.java | 4 + .../system/controller/ShopController.java | 90 ++++++- .../dlpay/system/service/ShopDataService.java | 3 + .../service/impl/ShopDataServiceImpl.java | 65 ++++- .../templates/system/shop/index.html | 251 ++++++++++++++++-- 7 files changed, 401 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java index 968804e0..e7cc15f1 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopDao.java @@ -24,4 +24,10 @@ public interface ShopDao extends JpaRepository { @Query("from TShop where status='normal' and fshopid=?1 ") List getChildShopsByShopid(Integer shopid); + + @Query(value = "select count(t.shopid) from TB_SHOP t where t.status='normal' and t.shopname=?1 and t.fshopid=?2 and t.shopid!=?3", nativeQuery = true) + long checkShopnameExist(String shopname, int fshopid, int oldShopid); + + @Query("from TShop where status='normal' order by shopid asc ") + List getNormalShops(); } diff --git a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java index 4e1f9ef7..73f6bdc7 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java +++ b/src/main/java/com/supwisdom/dlpay/framework/dao/ShopaccDao.java @@ -2,12 +2,11 @@ package com.supwisdom.dlpay.framework.dao; import com.supwisdom.dlpay.framework.data.ExistBean; import com.supwisdom.dlpay.framework.domain.TShopacc; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Lock; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.jpa.repository.QueryHints; +import org.springframework.data.jpa.repository.*; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + import javax.persistence.LockModeType; import javax.persistence.QueryHint; @@ -42,4 +41,9 @@ public interface ShopaccDao extends JpaRepository { TShopacc getByShopaccno(String shopaccno); + @Transactional + @Modifying + @Query("update TShopacc set shopname=?1 where shopaccno=?2") + void updateShopnameByShopaccno(String shopname, String shopaccno); + } diff --git a/src/main/java/com/supwisdom/dlpay/framework/domain/TShopacc.java b/src/main/java/com/supwisdom/dlpay/framework/domain/TShopacc.java index 83aaeb02..71ef3a84 100644 --- a/src/main/java/com/supwisdom/dlpay/framework/domain/TShopacc.java +++ b/src/main/java/com/supwisdom/dlpay/framework/domain/TShopacc.java @@ -105,6 +105,10 @@ public class TShopacc { this.closedate = closedate; } + public void setBalance(Double balance) { + this.balance = balance; + } + public Double getBalance() { return balance; } diff --git a/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java b/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java index 2c8e0882..a94f9068 100644 --- a/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java +++ b/src/main/java/com/supwisdom/dlpay/system/controller/ShopController.java @@ -2,15 +2,14 @@ package com.supwisdom.dlpay.system.controller; import com.supwisdom.dlpay.api.bean.JsonResult; import com.supwisdom.dlpay.framework.domain.TShop; +import com.supwisdom.dlpay.framework.util.StringUtil; +import com.supwisdom.dlpay.framework.util.TradeDict; import com.supwisdom.dlpay.system.service.ShopDataService; import com.supwisdom.dlpay.util.WebCheckException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; @Controller public class ShopController { @@ -50,4 +49,87 @@ public class ShopController { return JsonResult.error("系统处理异常").put("exception", e); } } + + @GetMapping("/shop/getshopinfo") + @PreAuthorize("hasPermission('/shop/getshopinfo','')") + @ResponseBody + public JsonResult getShopInfo(@RequestParam("shopid") Integer shopid) { + TShop shop = shopDataService.getShopByShopid(shopid); + if (null == shop) { + return JsonResult.error("商户不存在,请重新查询"); //商户不存在,请重新查询 + } + return JsonResult.ok("查询成功").put("shop", shop); + } + + @PostMapping("/shop/saveorupdate") + @PreAuthorize("hasPermission('/shop/saveorupdate','')") + @ResponseBody + public JsonResult saveOrUpdateShop(@RequestParam("shopid") Integer shopid, @RequestParam("shopname") String shopname, + @RequestParam("fshopid") Integer fshopid, @RequestParam("shoptype") Integer shoptype, + @RequestParam(value = "contactman", required = false) String contactman, + @RequestParam(value = "idtype", required = false) String idtype, + @RequestParam(value = "idno", required = false) String idno, + @RequestParam(value = "mobile", required = false) String mobile, + @RequestParam(value = "tel", required = false) String tel, + @RequestParam(value = "email", required = false) String email, + @RequestParam(value = "addr", required = false) String addr, + @RequestParam(value = "zipcode", required = false) String zipcode) { + if (null == shopid || StringUtil.isEmpty(shopname) || null == fshopid || (shoptype != 0 && shoptype != 1)) { + return JsonResult.error("参数传递错误"); + } + + TShop shop; + boolean addflag = false; + if (shopid == 0) { + //新增 + addflag = true; + shop = new TShop(); + shop.setFshopid(fshopid); + shop.setShopname(shopname); + shop.setShoptype(shoptype); + shop.setStatus(TradeDict.STATUS_NORMAL); + } else { + //修改 + shop = shopDataService.getShopByShopid(shopid); + if (null == shop) { + return JsonResult.error("商户不存在,修改失败!请重新查询"); + } + shop.setFshopid(fshopid); + shop.setShopname(shopname); +// shop.setShoptype(shoptype); //商户类型不能改 + } + shop.setContactman(contactman == null ? null : contactman.trim()); + shop.setIdno(idno == null ? null : idno.trim()); + shop.setIdtype(idtype == null ? null : idtype.trim()); + if (!StringUtil.isEmpty(shop.getIdno()) && StringUtil.isEmpty(shop.getIdtype())) { + return JsonResult.error("填写证件号时必须制定证件类型!"); + } else if (!StringUtil.isEmpty(shop.getIdno()) && "1".equals(shop.getIdtype()) && !StringUtil.isIdentity(shop.getIdno())) { + return JsonResult.error("身份证格式错误!"); + } + shop.setMobile(mobile == null ? null : mobile); + if (!StringUtil.isEmpty(shop.getMobile()) && !StringUtil.isMobile(shop.getMobile())) { + return JsonResult.error("请正确填写手机号!"); + } + shop.setTel(tel == null ? null : tel.trim()); + shop.setEmail(email == null ? null : email.trim()); + if (!StringUtil.isEmpty(shop.getEmail()) && !StringUtil.isEmail(shop.getEmail())) { + return JsonResult.error("请正确填写邮箱地址!"); + } + shop.setAddr(addr == null ? null : addr.trim()); + shop.setZipcode(zipcode == null ? null : zipcode.trim()); + + try{ + if(shopDataService.saveOrUpdateShop(shop)){ + return JsonResult.ok(addflag?"新增成功":"修改成功").put("shop",shop); + }else{ + return JsonResult.error(addflag?"新增失败":"修改失败"); + } + }catch (WebCheckException ex){ + return JsonResult.error(ex.getMessage()); + }catch (Exception e){ + return JsonResult.error("系统处理异常").put("exception", e); + } + } + + } diff --git a/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java b/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java index 087bec28..9a5dd9ab 100644 --- a/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java +++ b/src/main/java/com/supwisdom/dlpay/system/service/ShopDataService.java @@ -17,4 +17,7 @@ public interface ShopDataService { @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) boolean deleteShop(TShop shop) throws WebCheckException; + + @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) + boolean saveOrUpdateShop(TShop shop) throws WebCheckException; } diff --git a/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java b/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java index 33d227d7..a06e3346 100644 --- a/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java +++ b/src/main/java/com/supwisdom/dlpay/system/service/impl/ShopDataServiceImpl.java @@ -1,13 +1,19 @@ package com.supwisdom.dlpay.system.service.impl; +import com.supwisdom.dlpay.api.dao.ShopPaytypeDao; +import com.supwisdom.dlpay.api.domain.TShopPaytype; import com.supwisdom.dlpay.framework.dao.ShopDao; import com.supwisdom.dlpay.framework.dao.ShopaccDao; +import com.supwisdom.dlpay.framework.data.SystemDateTime; import com.supwisdom.dlpay.framework.domain.TShop; import com.supwisdom.dlpay.framework.domain.TShopacc; +import com.supwisdom.dlpay.framework.service.SystemUtilService; import com.supwisdom.dlpay.framework.util.StringUtil; +import com.supwisdom.dlpay.framework.util.Subject; import com.supwisdom.dlpay.framework.util.TradeDict; import com.supwisdom.dlpay.system.bean.ZTreeNode; import com.supwisdom.dlpay.system.service.ShopDataService; +import com.supwisdom.dlpay.util.ConstantUtil; import com.supwisdom.dlpay.util.WebCheckException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,17 +27,21 @@ public class ShopDataServiceImpl implements ShopDataService { private ShopDao shopDao; @Autowired private ShopaccDao shopaccDao; + @Autowired + private ShopPaytypeDao shopPaytypeDao; + @Autowired + private SystemUtilService systemUtilService; @Override public List getAllShopNodes() { List result = new ArrayList<>(0); - List shoplist = shopDao.findAll(); + List shoplist = shopDao.getNormalShops(); if (!StringUtil.isEmpty(shoplist)) { for (TShop shop : shoplist) { if (null == shop || !TradeDict.STATUS_NORMAL.equals(shop.getStatus())) continue; //跳过注销商户 ZTreeNode node = new ZTreeNode(); node.setId(shop.getShopid().toString()); - node.setName(shop.getShopname()); + node.setName(shop.getShopid()+"_"+shop.getShopname()); node.setpId(shop.getFshopid() == null ? "" : shop.getFshopid().toString()); node.setChecked(false); node.setOpen(true); @@ -57,11 +67,13 @@ public class ShopDataServiceImpl implements ShopDataService { if(!StringUtil.isEmpty(childShops)) throw new WebCheckException("请先删除下级商户"); shop.setStatus(TradeDict.STATUS_CLOSED); + shop.setClosedate(systemUtilService.getSysdatetime().getHostdate()); shopDao.save(shop); if(!StringUtil.isEmpty(shop.getShopaccno())){ TShopacc shopacc=shopaccDao.getByShopaccno(shop.getShopaccno()); if(null==shopacc) throw new WebCheckException("数据异常!对应的商户账户不存在!"); shopacc.setStatus(TradeDict.STATUS_CLOSED); + shopacc.setClosedate(shop.getClosedate()); shopaccDao.save(shopacc); } return true; @@ -69,5 +81,54 @@ public class ShopDataServiceImpl implements ShopDataService { return false; } + @Override + public boolean saveOrUpdateShop(TShop shop) throws WebCheckException { + if (shop.getFshopid() != 0) { + TShop fshop = shopDao.getTShopByShopid(shop.getFshopid()); + if (null == fshop) { + throw new WebCheckException("上级商户不存在!"); + }else if(fshop.getShoptype()==1){ + throw new WebCheckException("上级商户不是商户组!"); + } + } + if (shopDao.checkShopnameExist(shop.getShopname(), shop.getFshopid(), shop.getShopid() == null ? 0 : shop.getShopid()) > 0) { + throw new WebCheckException("商户名称在同级下已经存在!"); + } + if (null != shop.getShopid() && shop.getShopid() > 0) { + //修改 + shopDao.save(shop); + if (!StringUtil.isEmpty(shop.getShopaccno())) { + shopaccDao.updateShopnameByShopaccno(shop.getShopname(), shop.getShopaccno()); //更新商户名 + } + return true; + } else { + //新增 + SystemDateTime dt = systemUtilService.getSysdatetime(); + shop.setOpendate(dt.getHostdate()); + shopDao.save(shop); + if (shop.getShoptype() == 1) { + TShopacc shopacc = new TShopacc(); + shopacc.setShopaccno(String.format("2%09d", shop.getShopid())); + shopacc.setShopid(shop.getShopid()); + shopacc.setShopname(shop.getShopname()); + shopacc.setSubjno(Subject.SUBJNO_MACHANT_INCOME); + shopacc.setStatus(TradeDict.STATUS_NORMAL); + shopacc.setOpendate(dt.getHostdate()); + shopacc.setBalance(0D); + shopaccDao.save(shopacc); + + TShopPaytype shopPaytype = new TShopPaytype(); + shopPaytype.setShopaccno(shopacc.getShopaccno()); + shopPaytype.setPaytype(TradeDict.PAYTYPE_BALANCE); + shopPaytype.setConsumeEnable(ConstantUtil.ENABLE_YES); + shopPaytype.setAnonymousEnable(ConstantUtil.ENABLE_NO); + shopPaytype.setReverseEnable(ConstantUtil.ENABLE_NO); + shopPaytype.setCreatetime(dt.getHostdatetime()); + shopPaytypeDao.save(shopPaytype); //默认增加余额支付方式 + } + return true; + } + } + } diff --git a/src/main/resources/templates/system/shop/index.html b/src/main/resources/templates/system/shop/index.html index 1211547e..558ab568 100644 --- a/src/main/resources/templates/system/shop/index.html +++ b/src/main/resources/templates/system/shop/index.html @@ -17,17 +17,127 @@
-
-
-
- 搜索: -   - - +
+
@@ -40,6 +150,20 @@ var form = layui.form; var table = layui.table; var admin = layui.admin; + form.render('select'); + form.verify({ + "mobile": function (e) { + if (null != e && e.length > 0 && !(/^1\d{10}$/.test(e))) { + return "请输入正确的手机号"; + } + }, + "swEmail": function (e) { + if (null != e && e.length > 0 && !(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(e))) { + return "邮箱格式不正确"; + } + } + }); + var initTree = function (nodes) { var menuSetting = { view: { @@ -95,7 +219,7 @@ shopid: treeNode.id, _csrf: $("meta[name='_csrf_token']").attr("value") }, - success : function(result) { + success: function (result) { console.log(result); layer.closeAll('loading'); if (result.code == 200) { @@ -110,7 +234,7 @@ layer.msg(result.msg, {icon: 2}); } }, - error : function() { + error: function () { console.log(ret); layer.closeAll('loading'); layer.msg("请求服务器失败!", {icon: 2}); @@ -124,7 +248,58 @@ $("#addBtn_" + treeNode.tId).unbind().remove(); } - newCount = 10000 + $('#cancelbtn').click(function () { + $("#shop-info").hide(); + }); + + form.on('submit(form-submit)', function (data) { + layer.load(2); + var vdata = data.field; + vdata["_csrf"] = $("meta[name='_csrf_token']").attr("value"); + $.ajax({ + type: "POST", + dataType: "json", + url: '/shop/saveorupdate', + data: vdata, + success: function (result) { + layer.closeAll('loading'); + debugger + if (result.code == 200) { + var zTree = $.fn.zTree.getZTreeObj("shoptree"); + var treeNode = zTree.getNodeByParam("id", '' + result.shop.shopid, null); + if (undefined != treeNode && null != treeNode) { + treeNode.id = ''+result.shop.shopid; + treeNode.pId = '' + result.shop.fshopid; + treeNode.name = '' + result.shop.shopid + '_' + result.shop.shopname; + zTree.updateNode(treeNode); //修改节点 + } else { + var ftreeNode = zTree.getNodeByParam("id", '' + result.shop.fshopid, null); + zTree.addNodes(ftreeNode, { + id: '' + result.shop.shopid, + pId: '' + result.shop.fshopid, + name: '' + result.shop.shopid + '_' + result.shop.shopname, + shoptype: result.shop.shoptype + }); //新加树节点 + } + layer.msg(result.msg, {icon: 1}); + $("#shop-info").hide(); + } else if (result.code == 401) { + layer.msg(result.msg, {icon: 2, time: 1500}, function () { + location.replace('/login'); + }, 1000); + return; + } else { + console.log('err:' + result.code); + layer.msg(result.msg, {icon: 2}); + } + }, + error: function () { + layer.closeAll('loading'); + layer.msg("请求服务器失败!", {icon: 2}); + } + }); + }); + function addHoverDom(treeId, treeNode) { if (treeNode.shoptype == 0) { var sObj = $("#" + treeNode.tId + "_span"); @@ -134,16 +309,54 @@ sObj.after(addStr); var btn = $("#addBtn_" + treeNode.tId); if (btn) btn.bind("click", function () { - debugger - var zTree = $.fn.zTree.getZTreeObj("shoptree"); - zTree.addNodes(treeNode, {id: (100 + newCount), pId: treeNode.id, shoptype: 0, name: "new node" + (newCount++)}); + form.val("shop-info-form",{ + "shopid":"0", + "shopname": "", + "fshopid":treeNode.id, + "shoptype":"0", + "zipcode":"", + "addr":"", + "contactman":"", + "idtype":"1", + "idno":"", + "mobile":"", + "email":"", + "tel":"" + }); + $("#fshopid").attr("readonly", "readonly"); + $("#shoptype").removeAttr("disabled"); + form.render('select'); + $("#submitbtn").text("新增"); + $("#shop-info").show(); return false; }); } } - function ondblclick(event, treeId, treeNode){ - alert("treeId=["+treeId+"],nodename=["+treeNode.name+"]"); + function ondblclick(event, treeId, treeNode) { + admin.dgo('/shop/getshopinfo', { + "shopid": treeNode.id + }, function (data) { + console.log("getshopinfo返回",data); + if (data.code == 200) { + form.val("shop-info-form",data.shop); + $("#fshopid").removeAttr("readonly"); + $("#shoptype").attr('disabled', 'disabled'); + form.render('select'); + $("#submitbtn").text("保存"); + $("#shop-info").show(); + } else if (data.code == 401) { + layer.msg(data.msg, {icon: 2, time: 1500}, function () { + location.replace('/login'); + }, 1000); + return; + } else { + layer.msg(data.msg, {icon: 2, time: 2000}); + } + }, function (ret) { + console.log(ret); + layer.msg('查询商户失败了,请求服务器异常', {icon: 2}); + }); } admin.dgo('/shop/shoptree', {}, function (data) { @@ -161,7 +374,5 @@ console.log(ret); layer.msg('查询商户树失败了,请稍后再试', {icon: 2}); }); - - }); \ No newline at end of file -- 2.17.1