门店用户

This commit is contained in:
19173159168
2025-07-29 23:36:11 +08:00
parent 5c99499084
commit 9088c470c3
10 changed files with 203 additions and 59 deletions

View File

@ -1,6 +1,9 @@
package com.ruoyi.baseUser.controller; package com.ruoyi.baseUser.controller;
import java.util.List; import java.util.List;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -124,4 +127,21 @@ public class ZcBaseUserController extends BaseController
{ {
return toAjax(zcBaseUserService.deleteZcBaseUserByIds(ids)); return toAjax(zcBaseUserService.deleteZcBaseUserByIds(ids));
} }
@PostMapping("/removeStore")
@ResponseBody
public AjaxResult removeStore(Long id) {
try {
// 验证参数
if (id == null) {
return AjaxResult.error("参数错误");
}
// 调用Service删除关联记录
zcBaseUserService.deleteZcBaseUserStoreById(id);
return AjaxResult.success("删除成功");
} catch (Exception e) {
logger.error("删除用户门店关联记录失败", e);
return AjaxResult.error("删除失败");
}
}
} }

View File

@ -24,11 +24,9 @@ public class ZcBaseUser extends BaseEntity
private String userName; private String userName;
/** 头像 */ /** 头像 */
@Excel(name = "头像")
private String avatarUrl; private String avatarUrl;
/** 密码 */ /** 密码 */
@Excel(name = "密码")
private String password; private String password;
/** 手机号 */ /** 手机号 */

View File

@ -28,6 +28,9 @@ public interface ZcBaseUserMapper
*/ */
public List<ZcBaseUser> selectZcBaseUserList(ZcBaseUser zcBaseUser); public List<ZcBaseUser> selectZcBaseUserList(ZcBaseUser zcBaseUser);
public List<ZcBaseUser> selectZcBaseUserByStoreId(Long storeId);
public ZcBaseUser selectZcBaseUserByPhone(String phone);
/** /**
* 新增租车用户信息 * 新增租车用户信息
* *
@ -84,4 +87,6 @@ public interface ZcBaseUserMapper
* @return 结果 * @return 结果
*/ */
public int deleteZcBaseUserStoreByUserId(Long id); public int deleteZcBaseUserStoreByUserId(Long id);
public int deleteZcBaseUserStoreById(Long id);
} }

View File

@ -27,6 +27,9 @@ public interface IZcBaseUserService
*/ */
public List<ZcBaseUser> selectZcBaseUserList(ZcBaseUser zcBaseUser); public List<ZcBaseUser> selectZcBaseUserList(ZcBaseUser zcBaseUser);
public List<ZcBaseUser> selectZcBaseUserByStoreId(Long storeId);
/** /**
* 新增租车用户信息 * 新增租车用户信息
* *
@ -58,4 +61,6 @@ public interface IZcBaseUserService
* @return 结果 * @return 结果
*/ */
public int deleteZcBaseUserById(Long id); public int deleteZcBaseUserById(Long id);
public int deleteZcBaseUserStoreById(Long id);
} }

View File

@ -52,6 +52,11 @@ public class ZcBaseUserServiceImpl implements IZcBaseUserService
return zcBaseUserMapper.selectZcBaseUserList(zcBaseUser); return zcBaseUserMapper.selectZcBaseUserList(zcBaseUser);
} }
@Override
public List<ZcBaseUser> selectZcBaseUserByStoreId(Long storeId){
return zcBaseUserMapper.selectZcBaseUserByStoreId(storeId);
}
/** /**
* 新增租车用户信息 * 新增租车用户信息
* *
@ -62,13 +67,28 @@ public class ZcBaseUserServiceImpl implements IZcBaseUserService
@Override @Override
public int insertZcBaseUser(ZcBaseUser zcBaseUser) public int insertZcBaseUser(ZcBaseUser zcBaseUser)
{ {
String md5Hexpwd = DigestUtils.md5Hex(zcBaseUser.getPassword());
zcBaseUser.setPassword(md5Hexpwd); ZcBaseUser oldUser = zcBaseUserMapper.selectZcBaseUserByPhone(zcBaseUser.getPhoneNumber());
zcBaseUser.setIsStore(1L); if(oldUser != null) {
zcBaseUser.setCreateTime(DateUtils.getNowDate()); // 如果用户存在,只修改门店用户标识
int rows = zcBaseUserMapper.insertZcBaseUser(zcBaseUser); ZcBaseUser a = new ZcBaseUser();
insertZcBaseUserStore(zcBaseUser); a.setId(oldUser.getId());
return rows; a.setIsStore(1L);
a.setUpdateTime(DateUtils.getNowDate());
int rows = zcBaseUserMapper.updateZcBaseUser(a);
// 然后绑定与门店的关联
oldUser.setZcBaseUserStoreList(zcBaseUser.getZcBaseUserStoreList());
insertZcBaseUserStore(oldUser);
return rows;
}else{
String md5Hexpwd = DigestUtils.md5Hex(zcBaseUser.getPassword());
zcBaseUser.setPassword(md5Hexpwd);
zcBaseUser.setIsStore(1L);
zcBaseUser.setCreateTime(DateUtils.getNowDate());
int rows = zcBaseUserMapper.insertZcBaseUser(zcBaseUser);
insertZcBaseUserStore(zcBaseUser);
return rows;
}
} }
/** /**
@ -139,4 +159,9 @@ public class ZcBaseUserServiceImpl implements IZcBaseUserService
} }
} }
} }
@Override
public int deleteZcBaseUserStoreById(Long id) {
return zcBaseUserMapper.deleteZcBaseUserStoreById(id);
}
} }

View File

@ -2,6 +2,8 @@ package com.ruoyi.operation.controller;
import java.util.List; import java.util.List;
import com.ruoyi.baseUser.domain.ZcBaseUser;
import com.ruoyi.baseUser.service.IZcBaseUserService;
import com.ruoyi.common.constant.CompanyConstants; import com.ruoyi.common.constant.CompanyConstants;
import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.entity.SysUser;
@ -37,6 +39,9 @@ public class CompanyStoreController extends BaseController
private ICompanyStoreService companyStoreService; private ICompanyStoreService companyStoreService;
@Autowired @Autowired
private ICompanyService companyService; private ICompanyService companyService;
@Autowired
private IZcBaseUserService zcBaseUserService;
@RequiresPermissions("operation:store:view") @RequiresPermissions("operation:store:view")
@GetMapping() @GetMapping()
@ -152,6 +157,8 @@ public class CompanyStoreController extends BaseController
CompanyStore companyStore = companyStoreService.selectCompanyStoreById(id); CompanyStore companyStore = companyStoreService.selectCompanyStoreById(id);
mmap.put("companyStore", companyStore); mmap.put("companyStore", companyStore);
List<ZcBaseUser> zcBaseUserList = zcBaseUserService.selectZcBaseUserByStoreId(id);
mmap.put("zcBaseUserList", zcBaseUserList);
return prefix + "/addStoreUser"; return prefix + "/addStoreUser";
} }

View File

@ -29,6 +29,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="userId" column="sub_user_id" /> <result property="userId" column="sub_user_id" />
<result property="operatorId" column="sub_operator_id" /> <result property="operatorId" column="sub_operator_id" />
<result property="storeId" column="sub_store_id" /> <result property="storeId" column="sub_store_id" />
<result property="operatorName" column="sub_operator_name" />
<result property="storeName" column="sub_store_name" />
<result property="delFlag" column="sub_del_flag" /> <result property="delFlag" column="sub_del_flag" />
<result property="createBy" column="sub_create_by" /> <result property="createBy" column="sub_create_by" />
<result property="createTime" column="sub_create_time" /> <result property="createTime" column="sub_create_time" />
@ -55,15 +57,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="alipayUserid != null and alipayUserid != ''"> and alipay_userid = #{alipayUserid}</if> <if test="alipayUserid != null and alipayUserid != ''"> and alipay_userid = #{alipayUserid}</if>
</where> </where>
</select> </select>
<select id="selectZcBaseUserById" parameterType="Long" resultMap="ZcBaseUserZcBaseUserStoreResult"> <select id="selectZcBaseUserByStoreId" parameterType="Long" resultMap="ZcBaseUserZcBaseUserStoreResult">
select a.id, a.user_name, a.avatar_url, a.password, a.phone_number, a.role_id, a.is_store, a.nick_name, a.wechat_openid, a.alipay_userid, a.del_flag, a.create_time, a.update_time, select a.id, a.user_name, a.avatar_url, a.password, a.phone_number, a.role_id, a.is_store, a.nick_name, a.wechat_openid, a.alipay_userid, a.del_flag, a.create_time, a.update_time,
b.id as sub_id, b.user_id as sub_user_id, b.operator_id as sub_operator_id, b.store_id as sub_store_id b.id as sub_id, b.user_id as sub_user_id, b.operator_id as sub_operator_id, b.store_id as sub_store_id, b.create_time as sub_create_time
from zc_base_user a from zc_base_user a
left join zc_base_user_store b on b.user_id = a.id left join zc_base_user_store b on b.user_id = a.id
where a.del_flag = '0' and b.store_id = #{storeId}
</select>
<select id="selectZcBaseUserById" parameterType="Long" resultMap="ZcBaseUserZcBaseUserStoreResult">
select a.id, a.user_name, a.avatar_url, a.password, a.phone_number, a.role_id, a.is_store, a.nick_name, a.wechat_openid, a.alipay_userid, a.del_flag, a.create_time, a.update_time,
b.id as sub_id, b.user_id as sub_user_id, b.operator_id as sub_operator_id, b.store_id as sub_store_id, b.create_time as sub_create_time,
c.name as sub_store_name, d.company_name as sub_operator_name
from zc_base_user a
left join zc_base_user_store b on b.user_id = a.id
left join zc_company_store c on c.id = b.store_id
left join zc_company d on d.id = b.operator_id
where a.del_flag = '0' and a.id = #{id} where a.del_flag = '0' and a.id = #{id}
</select> </select>
<select id="selectZcBaseUserByPhone" resultMap="ZcBaseUserResult">
select a.id, a.user_name, a.avatar_url, a.password, a.phone_number, a.role_id, a.is_store, a.nick_name, a.wechat_openid, a.alipay_userid, a.del_flag, a.create_time, a.update_time
from zc_base_user a
where a.del_flag = '0' and a.phone_number = #{phoneNumber}
</select>
<insert id="insertZcBaseUser" parameterType="ZcBaseUser" useGeneratedKeys="true" keyProperty="id"> <insert id="insertZcBaseUser" parameterType="ZcBaseUser" useGeneratedKeys="true" keyProperty="id">
insert into zc_base_user insert into zc_base_user
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
@ -137,6 +155,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
delete from zc_base_user_store where user_id = #{userId} delete from zc_base_user_store where user_id = #{userId}
</delete> </delete>
<delete id="deleteZcBaseUserStoreById">
DELETE FROM zc_base_user_store WHERE id = #{id}
</delete>
<insert id="batchZcBaseUserStore"> <insert id="batchZcBaseUserStore">
insert into zc_base_user_store( id, user_id, operator_id, store_id, del_flag, create_by, create_time, update_by, update_time) values insert into zc_base_user_store( id, user_id, operator_id, store_id, del_flag, create_by, create_time, update_by, update_time) values
<foreach item="item" index="index" collection="list" separator=","> <foreach item="item" index="index" collection="list" separator=",">

View File

@ -56,7 +56,8 @@
<input name="alipayUserid" th:field="*{alipayUserid}" class="form-control" type="text"> <input name="alipayUserid" th:field="*{alipayUserid}" class="form-control" type="text">
</div> </div>
</div> </div>
<h4 class="form-header h4">用户门店信息</h4> <br/>
<h4 class="form-header h4">用户归属门店信息</h4>
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<!-- <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>--> <!-- <button type="button" class="btn btn-white btn-sm" onclick="addRow()"><i class="fa fa-plus"> 增加</i></button>-->
@ -107,30 +108,18 @@
{ {
field: 'storeName', field: 'storeName',
align: 'center', align: 'center',
title: '关联门店', title: '关联门店'
formatter: function(value, row, index) {
var html = $.common.sprintf("<input class='form-control' type='text' name='zcBaseUserStoreList[%s].storeId' value='%s'>", index, value);
return html;
}
}, },
{ {
field: 'operatorName', field: 'operatorName',
align: 'center', align: 'center',
title: '门店所属运营商', title: '门店所属运营商'
formatter: function(value, row, index) {
var html = $.common.sprintf("<input class='form-control' type='text' name='zcBaseUserStoreList[%s].operatorId' value='%s'>", index, value);
return html;
}
}, },
{ {
field: 'createTime', field: 'createTime',
align: 'center', align: 'center',
title: '创建时间', title: '创建时间'
formatter: function(value, row, index) {
var html = $.common.sprintf("<input class='form-control' type='text' name='zcBaseUserStoreList[%s].createTime' value='%s'>", index, value);
return html;
}
}, },
{ {
@ -145,20 +134,45 @@
$.table.init(options); $.table.init(options);
}); });
function addRow() { var sub = {
var count = $("#" + table.options.id).bootstrapTable('getData').length;
var row = { delRowByIndex: function(index) {
index: $.table.serialNumber(count), // 获取表格数据
operatorId: "", var data = $("#" + table.options.id).bootstrapTable('getData');
storeId: "", var row = data[index-1]; // 序号从1开始数组索引从0开始
delFlag: "",
createBy: "", // 如果该行数据有ID说明是已存在的记录需要调用后台删除
createTime: "", if (row && row.id) {
updateBy: "", // 调用后台删除接口
updateTime: "", $.ajax({
type: "POST",
url: prefix + "/removeStore",
data: {
"id": row.id,
"userId": $("input[name='id']").val()
},
success: function(result) {
if (result.code == web_status.SUCCESS) {
// 后台删除成功后,移除前端表格行
$("#" + table.options.id).bootstrapTable('removeByUniqueId', row.id);
$.modal.msgSuccess("删除成功");
} else {
$.modal.msgError(result.msg);
}
},
error: function() {
$.modal.msgError("删除失败");
}
});
} else {
// 如果是新增但未保存的行,直接在前端移除
$("#" + table.options.id).bootstrapTable('remove', {
field: 'index',
values: [index]
});
}
} }
sub.addRow(row); };
}
</script> </script>
</body> </body>
</html> </html>

View File

@ -44,9 +44,9 @@
</div> </div>
<div class="btn-group-sm" id="toolbar" role="group"> <div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="baseUser:user:add"> <!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="baseUser:user:add">-->
<i class="fa fa-plus"></i> 添加 <!-- <i class="fa fa-plus"></i> 添加-->
</a> <!-- </a>-->
<!-- <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="baseUser:user:edit">--> <!-- <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="baseUser:user:edit">-->
<!-- <i class="fa fa-edit"></i> 修改--> <!-- <i class="fa fa-edit"></i> 修改-->
<!-- </a>--> <!-- </a>-->
@ -124,8 +124,8 @@
align: 'center', align: 'center',
formatter: function(value, row, index) { formatter: function(value, row, index) {
var actions = []; var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> '); actions.push('<a class="btn btn-success btn-xs ' + editFlag + ' btnOption" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>'); actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + ' btnOption" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
return actions.join(''); return actions.join('');
} }
}] }]

View File

@ -6,8 +6,8 @@
<body class="white-bg"> <body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content"> <div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m" id="form-user-add"> <form class="form-horizontal m" id="form-user-add">
<input class='form-control' type='text' name='zcBaseUserStoreList[0].operatorId' th:value='${companyStore.operatingCompanyId}'> <input class='form-control' type='hidden' name='zcBaseUserStoreList[0].operatorId' th:value='${companyStore.operatingCompanyId}'>
<input class='form-control' type='text' name='zcBaseUserStoreList[0].storeId' th:value="${companyStore.id}" > <input class='form-control' type='hidden' name='zcBaseUserStoreList[0].storeId' th:value="${companyStore.id}" >
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label is-required">用户名:</label> <label class="col-sm-3 control-label is-required">用户名:</label>
<div class="col-sm-8"> <div class="col-sm-8">
@ -33,16 +33,13 @@
<input name="nickName" class="form-control" type="text"> <input name="nickName" class="form-control" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <br/>
<label class="col-sm-3 control-label">微信小程序openid</label> <h4 class="form-header h4">门店用户</h4>
<div class="col-sm-8"> <div class="row">
<input name="wechatOpenid" class="form-control" type="text"> <div class="col-sm-12">
</div> <div class="col-sm-12 select-table table-striped">
</div> <table id="bootstrap-table"></table>
<div class="form-group"> </div>
<label class="col-sm-3 control-label">支付宝小程序userid</label>
<div class="col-sm-8">
<input name="alipayUserid" class="form-control" type="text">
</div> </div>
</div> </div>
</form> </form>
@ -59,6 +56,57 @@
$.operate.save(prefix + "/add", $('#form-user-add').serialize()); $.operate.save(prefix + "/add", $('#form-user-add').serialize());
} }
} }
$(function() {
var options = {
data: [[${zcBaseUserList}]],
pagination: false,
showSearch: false,
showRefresh: false,
showToggle: false,
showColumns: false,
sidePagination: "client",
columns: [{
checkbox: false
},
{
field: 'index',
align: 'center',
title: "序号",
formatter: function (value, row, index) {
var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
return columnIndex + $.table.serialNumber(index);
}
},
{
field: 'userName',
align: 'center',
title: '用户名'
},
{
field: 'phoneNumber',
align: 'center',
title: '手机号'
},
{
field: 'nickName',
align: 'center',
title: '昵称'
},
{
field: 'createTime',
align: 'center',
title: '创建时间'
},
]
};
$.table.init(options);
});
</script> </script>
</body> </body>
</html> </html>