chore: 实现服务商的查询与查询密码的关联
This commit is contained in:
@@ -31,7 +31,7 @@ class Project extends Base {
|
||||
/*会员中心数据表*/
|
||||
$this->project_db = Db::name('project'); //
|
||||
$this->service_db = Db::name('service'); //
|
||||
$this->projectQueryPasswordDb = Db::name('project_query_password'); // 查询密码表
|
||||
$this->projectQueryPasswordDb = Db::name('query_password'); // 查询密码表
|
||||
|
||||
// 是否开启支付功能设置
|
||||
$this->userConfig = getUsersConfigData('all');
|
||||
@@ -548,6 +548,8 @@ class Project extends Base {
|
||||
'password' => trim($post['password']),
|
||||
'allow_keywords' => trim($post['allow_keywords']),
|
||||
'deny_keywords' => trim($post['deny_keywords']),
|
||||
'allow_servicer_keywords' => trim($post['allow_servicer_keywords']),
|
||||
'deny_servicer_keywords' => trim($post['deny_servicer_keywords']),
|
||||
'status' => !empty($post['status']) ? 1 : 0,
|
||||
'updatetime' => time()
|
||||
];
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
</dl>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="tit"> <label for="allow_keywords">允许的关键字</label> </dt>
|
||||
<dt class="tit"> <label for="allow_keywords">允许的应用关键字</label> </dt>
|
||||
<dd class="opt">
|
||||
<textarea name="allow_keywords" id="allow_keywords" class="input-txt" rows="4" cols="60">{$info['allow_keywords']|default=''}</textarea>
|
||||
<span class="err"></span>
|
||||
@@ -26,7 +26,7 @@
|
||||
</dl>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="tit"> <label for="deny_keywords">禁止的关键字</label> </dt>
|
||||
<dt class="tit"> <label for="deny_keywords">禁止的应用关键字</label> </dt>
|
||||
<dd class="opt">
|
||||
<textarea name="deny_keywords" id="deny_keywords" class="input-txt" rows="4" cols="60">{$info['deny_keywords']|default=''}</textarea>
|
||||
<span class="err"></span>
|
||||
@@ -34,21 +34,42 @@
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="tit"> <label for="allow_servicer_keywords">允许的服务商关键字</label> </dt>
|
||||
<dd class="opt">
|
||||
<textarea name="allow_servicer_keywords" id="allow_servicer_keywords" class="input-txt" rows="4" cols="60">{$info['allow_servicer_keywords']|default=''}</textarea>
|
||||
<span class="err"></span>
|
||||
<p class="notic2 red" id="allow_servicer_keywords_tips">在此输入允许查询的服务商名称包含的关键字,多个关键字用逗号分隔。留空表示允许查询所有服务商。</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="tit"> <label for="deny_servicer_keywords">禁止的服务商关键字</label> </dt>
|
||||
<dd class="opt">
|
||||
<textarea name="deny_servicer_keywords" id="deny_servicer_keywords" class="input-txt" rows="4" cols="60">{$info['deny_servicer_keywords']|default=''}</textarea>
|
||||
<span class="err"></span>
|
||||
<p class="notic2 red" id="deny_servicer_keywords_tips">在此输入禁止查询的服务商名称包含的关键字,多个关键字用逗号分隔。留空表示不禁止任何服务商查询。</p>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<div class="row" style="margin: 15px 0; padding: 10px; background-color: #f8f9fa; border-radius: 4px;">
|
||||
<div class="tit" style="font-weight: bold; margin-bottom: 10px;">规则说明:</div>
|
||||
<div class="opt">
|
||||
<p>1. 当"允许查询"为空时:可以查询所有应用</p>
|
||||
<p>2. 当"允许查询"有内容时:只能查询应用名称包含这些关键字的应用</p>
|
||||
<p>3. 当"禁止查询"有内容时:不能查询应用名称包含这些关键字的应用</p>
|
||||
<p>1. 当"允许查询"为空时:可以查询所有应用或服务商</p>
|
||||
<p>2. 当"允许查询"有内容时:只能查询应用或服务商名称包含这些关键字的记录</p>
|
||||
<p>3. 当"禁止查询"有内容时:不能查询应用或服务商名称包含这些关键字的记录</p>
|
||||
<p>4. 优先级:禁止查询 > 允许查询</p>
|
||||
<p>5. 应用关键字和对应的服务商关键字分别独立生效</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row" style="margin: 15px 0; padding: 10px; background-color: #f8f9fa; border-radius: 4px;">
|
||||
<div class="tit" style="font-weight: bold; margin-bottom: 10px;">示例说明:</div>
|
||||
<div class="opt">
|
||||
<p>- 设置"允许查询"为"电商,金融,教育":只能查询应用名称包含这些关键字的应用</p>
|
||||
<p>- 设置"禁止查询"为"测试,临时":不能查询应用名称包含这些关键字的应用</p>
|
||||
<p>- 设置应用"允许查询"为"电商,金融,教育":只能查询应用名称包含这些关键字的应用</p>
|
||||
<p>- 设置应用"禁止查询"为"测试,临时":不能查询应用名称包含这些关键字的应用</p>
|
||||
<p>- 设置服务商"允许查询"为"华东,华南":只能查询服务商名称包含这些关键字的服务商</p>
|
||||
<p>- 设置服务商"禁止查询"为"测试中心,临时":不能查询服务商名称包含这些关键字的服务商</p>
|
||||
<p>- 同时设置:允许"正式,生产",禁止"测试":可以查询包含"正式"或"生产"关键字的应用,但排除包含"测试"关键字的应用</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -59,21 +59,21 @@
|
||||
<th abbr="password" axis="col3" style="width: 15%">
|
||||
<div class="tc">查询密码</div>
|
||||
</th>
|
||||
<th abbr="allow_keywords" axis="col4" style="width: 20%">
|
||||
<div class="tc">允许查询的关键字</div>
|
||||
<th abbr="allow_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">允许查询的应用关键字</div>
|
||||
</th>
|
||||
<th abbr="deny_keywords" axis="col4" style="width: 20%">
|
||||
<div class="tc">禁止查询的关键字</div>
|
||||
<th abbr="deny_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">禁止查询的应用关键字</div>
|
||||
</th>
|
||||
<th abbr="status" axis="col4" class="" style="width: 10%">
|
||||
<th abbr="allow_servicer_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">允许查询的服务商关键字</div>
|
||||
</th>
|
||||
<th abbr="deny_servicer_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">禁止查询的服务商关键字</div>
|
||||
</th>
|
||||
<th abbr="status" axis="col4" class="" style="width: 15%">
|
||||
<div class="tc">状态</div>
|
||||
</th>
|
||||
<th abbr="createtime" axis="col4" style="width: 15%">
|
||||
<div class="tc">创建时间</div>
|
||||
</th>
|
||||
<th abbr="updatetime" axis="col4" style="width: 15%">
|
||||
<div class="tc">更新时间</div>
|
||||
</th>
|
||||
<th axis="col1" style="width: 15%">
|
||||
<div class="tc">操作</div>
|
||||
</th>
|
||||
@@ -97,13 +97,19 @@
|
||||
<td abbr="password" axis="col3" style="width: 15%">
|
||||
<div class="tc">{$vo.password}</div>
|
||||
</td>
|
||||
<td abbr="allow_keywords" axis="col4" style="width: 20%">
|
||||
<td abbr="allow_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.allow_keywords|default='所有'}</div>
|
||||
</td>
|
||||
<td abbr="deny_keywords" axis="col4" style="width: 20%">
|
||||
<td abbr="deny_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.deny_keywords|default='无'}</div>
|
||||
</td>
|
||||
<td abbr="status" axis="col4" class="" style="width: 10%">
|
||||
<td abbr="allow_servicer_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.allow_servicer_keywords|default='所有'}</div>
|
||||
</td>
|
||||
<td abbr="deny_servicer_keywords" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.deny_servicer_keywords|default='无'}</div>
|
||||
</td>
|
||||
<td abbr="status" axis="col4" class="" style="width: 15%">
|
||||
<div class="tc">
|
||||
{if condition="$vo.status eq 1"}
|
||||
<span class="yes" onclick="changeStatus(this, {$vo.id}, 0);">启用</span>
|
||||
@@ -112,12 +118,6 @@
|
||||
{/if}
|
||||
</div>
|
||||
</td>
|
||||
<td abbr="createtime" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.createtime|date='Y-m-d H:i:s',###}</div>
|
||||
</td>
|
||||
<td abbr="updatetime" axis="col4" style="width: 15%">
|
||||
<div class="tc">{$vo.updatetime|date='Y-m-d H:i:s',###|default='无'}</div>
|
||||
</td>
|
||||
<td axis="col1" style="width: 15%">
|
||||
<div style="text-align: center">
|
||||
<a data-href="{:url('Project/password_add',array('id'=>$vo['id']))}" data-closereload="1" onclick="openFullframe(this, '编辑', '100%', '100%');" class="btn blue">编辑</a>
|
||||
|
||||
@@ -1138,14 +1138,46 @@ class Ajax extends Base
|
||||
public function projectsearch()
|
||||
{
|
||||
$type = intval(input('type'));
|
||||
if ($type == 1) {//服务商
|
||||
$item = Db::name('service')->where(['name' => input('realname')])->find();
|
||||
$password = input('password'); // 获取密码
|
||||
|
||||
if ($item) {
|
||||
echo json_encode(array('code' => 1, 'msg' => '操作成功', 'img' => $item['qrcode']));
|
||||
// 检查密码是否在数据库中且状态为启用
|
||||
$password_check = Db::name('query_password')->where(['password' => $password, 'status' => 1])->find();
|
||||
if (!$password_check) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '密码无效或无权限'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// ------------------------------------------
|
||||
// ---------------- 服务商查询 ----------------
|
||||
// ------------------------------------------
|
||||
if ($type == 1) {//服务商
|
||||
$keyword = input('realname'); // 关键字
|
||||
// 从查询密码中获得允许的服务商关键字和禁止的服务商关键字, 都转换成数组
|
||||
// 处理空字符串情况,将其转换为空数组
|
||||
$allow_keywords = trim($password_check['allow_servicer_keywords']) === '' ? [] : explode(',', $password_check['allow_servicer_keywords']);
|
||||
$deny_keywords = trim($password_check['deny_servicer_keywords']) === '' ? [] : explode(',', $password_check['deny_servicer_keywords']);
|
||||
|
||||
if (!empty($allow_keywords) && !in_array($keyword, $allow_keywords)) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '您没有该关键词的查询权限,请联系数据安全管理员'));
|
||||
exit;
|
||||
} elseif (!empty($deny_keywords) && in_array($keyword, $deny_keywords)) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '您没有该关键词的查询权限,请联系数据安全管理员'));
|
||||
exit;
|
||||
}
|
||||
|
||||
// SQL 查询
|
||||
$where = [];
|
||||
$where['name'] = ['like', '%' . $keyword . '%'];
|
||||
$item_list = Db::name('service')->where($where)->select();
|
||||
|
||||
if (!empty($item_list)) {
|
||||
// 获得其他服务商的名称
|
||||
$service_names = array_column($item_list, 'name');
|
||||
$item_counts = count($item_list);
|
||||
echo json_encode(array('code' => 1, 'msg' => '操作成功', 'img' => $item_list[0]['qrcode'], 'service_names' => $service_names, 'counts' => $item_counts, 'keyword' => $keyword));
|
||||
} else {
|
||||
echo json_encode(array('code' => 0, 'msg' => '不存在'));
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
@@ -1154,79 +1186,72 @@ class Ajax extends Base
|
||||
// ---------------- 项目/应用查询 ----------------
|
||||
// ------------------------------------------
|
||||
$keyword = input('keyword'); // 关键字
|
||||
$password = input('password'); // 获取密码
|
||||
$matchType = input('match_type', 1); // 匹配类型,默认为完全匹配
|
||||
|
||||
// 检查密码是否在数据库中
|
||||
$password_check = Db::name('project_query_password')->where(['password' => $password])->find();
|
||||
if (!$password_check) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '密码无效或无权限'));
|
||||
// 检查关键字与应用名称是否存在匹配
|
||||
// 应用名称与关键字有几种匹配情况
|
||||
// 1. 完全匹配
|
||||
// 2. 包含匹配
|
||||
// 3. 前缀匹配
|
||||
// 4. 后缀匹配
|
||||
|
||||
// 根据匹配类型构建查询条件
|
||||
$where = [];
|
||||
switch ($matchType) {
|
||||
case 1: // 完全匹配
|
||||
$where['name'] = $keyword;
|
||||
break;
|
||||
case 2: // 包含匹配
|
||||
$where['name'] = ['like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 3: // 前缀匹配
|
||||
$where['name'] = ['like', $keyword . '%'];
|
||||
break;
|
||||
case 4: // 后缀匹配
|
||||
$where['name'] = ['like', '%' . $keyword];
|
||||
break;
|
||||
default: // 默认完全匹配
|
||||
$where['name'] = $keyword;
|
||||
}
|
||||
|
||||
// 查询匹配的应用列表
|
||||
// $item_list = Db::name('project')->where($where)->select();
|
||||
$item_list = Db::name('project')->where($where)->select();
|
||||
$count = count($item_list);
|
||||
|
||||
$infoArray = array('name' => $keyword, 'match_type' => $matchType, 'count' => $count);
|
||||
|
||||
// 如果匹配的应用列表为空
|
||||
if (empty($item_list)) {
|
||||
echo json_encode(array_merge(array('code' => -2, 'msg' => '项目/应用不存在,可以申请'), $infoArray));
|
||||
exit;
|
||||
}
|
||||
|
||||
// 从查询密码中获得允许的关键字和禁止的关键字, 都转换成数组
|
||||
// 处理空字符串情况,将其转换为空数组
|
||||
$allow_keywords = trim($password_check['allow_keywords']) === '' ? [] : explode(',', $password_check['allow_keywords']);
|
||||
$deny_keywords = trim($password_check['deny_keywords']) === '' ? [] : explode(',', $password_check['deny_keywords']);
|
||||
|
||||
// 检查关键字是否在允许列表中,或者是否在禁止列表中
|
||||
$find = true;
|
||||
if (!empty($allow_keywords) && !in_array($keyword, $allow_keywords)) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '您没有该关键词的查询权限,请联系数据安全管理员'));
|
||||
exit;
|
||||
$find = false;
|
||||
} elseif (!empty($deny_keywords) && in_array($keyword, $deny_keywords)) {
|
||||
echo json_encode(array('code' => -1, 'msg' => '您没有该关键词的查询权限,请联系数据安全管理员'));
|
||||
exit;
|
||||
$find = false;
|
||||
}
|
||||
|
||||
// 如果找到匹配的应用
|
||||
if ($find) {
|
||||
$item = $item_list[0];
|
||||
echo json_encode(array_merge(array('code' => 1, 'msg' => '项目/应用存在', 'img' => $item['qrcode']), $infoArray));
|
||||
exit;
|
||||
} else {
|
||||
// 检查关键字与应用名称是否存在匹配
|
||||
// 应用名称与关键字有几种匹配情况
|
||||
// 1. 完全匹配
|
||||
// 2. 包含匹配
|
||||
// 3. 前缀匹配
|
||||
// 4. 后缀匹配
|
||||
|
||||
// 根据匹配类型构建查询条件
|
||||
$where = [];
|
||||
switch ($matchType) {
|
||||
case 1: // 完全匹配
|
||||
$where['name'] = $keyword;
|
||||
break;
|
||||
case 2: // 包含匹配
|
||||
$where['name'] = ['like', '%' . $keyword . '%'];
|
||||
break;
|
||||
case 3: // 前缀匹配
|
||||
$where['name'] = ['like', $keyword . '%'];
|
||||
break;
|
||||
case 4: // 后缀匹配
|
||||
$where['name'] = ['like', '%' . $keyword];
|
||||
break;
|
||||
default: // 默认完全匹配
|
||||
$where['name'] = $keyword;
|
||||
}
|
||||
|
||||
// 查询匹配的应用列表
|
||||
// $item_list = Db::name('project')->where($where)->select();
|
||||
$item_list = Db::name('project')->where($where)->select();
|
||||
$count = count($item_list);
|
||||
|
||||
$infoArray = array('name' => $keyword, 'match_type' => $matchType, 'count' => $count);
|
||||
|
||||
// 如果匹配的应用列表为空
|
||||
if (empty($item_list)) {
|
||||
echo json_encode(array_merge(array('code' => -2, 'msg' => '项目/应用不存在,可以申请'), $infoArray));
|
||||
exit;
|
||||
}
|
||||
|
||||
// 从查询密码中获得允许的关键字和禁止的关键字, 都转换成数组
|
||||
// 处理空字符串情况,将其转换为空数组
|
||||
$allow_keywords = trim($password_check['allow_keywords']) === '' ? [] : explode(',', $password_check['allow_keywords']);
|
||||
$deny_keywords = trim($password_check['deny_keywords']) === '' ? [] : explode(',', $password_check['deny_keywords']);
|
||||
|
||||
// 检查关键字是否在允许列表中,或者是否在禁止列表中
|
||||
$find = true;
|
||||
if (!empty($allow_keywords) && !in_array($keyword, $allow_keywords)) {
|
||||
// echo json_encode(array('code'=>-1,'msg'=>'关键字不在允许列表中'));exit;
|
||||
$find = false;
|
||||
} elseif (!empty($deny_keywords) && in_array($keyword, $deny_keywords)) {
|
||||
// echo json_encode(array('code'=>-1,'msg'=>'关键字在禁止列表中'));exit;
|
||||
$find = false;
|
||||
}
|
||||
|
||||
// 如果找到匹配的应用
|
||||
if ($find) {
|
||||
$item = $item_list[0];
|
||||
echo json_encode(array_merge(array('code' => 1, 'msg' => '项目/应用存在', 'img' => $item['qrcode']), $infoArray));
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode(array_merge(array('code' => -2, 'msg' => '项目/应用不存在,可以申请'), $infoArray));
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(array_merge(array('code' => -2, 'msg' => '项目/应用不存在,可以申请'), $infoArray));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user