渠道新增用户权限

This commit is contained in:
wong
2025-12-29 15:12:57 +08:00
parent 2c90f6f33c
commit 203e8c8eaf
2 changed files with 66 additions and 9 deletions

View File

@@ -35,6 +35,7 @@ class ChannelController extends BaseController
$createType = $this->request->param('createType', DistributionChannel::CREATE_TYPE_MANUAL); // 默认为手动创建
$companyId = $this->getUserInfo('companyId');
$userId = $this->getUserInfo('id');
// 参数验证
if (empty($name)) {
@@ -87,6 +88,7 @@ class ChannelController extends BaseController
// 准备插入数据
$data = [
'companyId' => $companyId,
'userId' => $userId,
'name' => $name,
'code' => $code,
'phone' => $phone ?: '',
@@ -122,6 +124,7 @@ class ChannelController extends BaseController
'phone' => $channel['phone'] ?: '',
'wechatId' => $channel['wechatId'] ?: '',
'companyId' => (int)$companyId, // 返回companyId方便小程序自动跳转
'userId' => (int)($channel['userId'] ?? 0),
'createType' => $channel['createType'],
'status' => $channel['status'],
'totalCustomers' => (int)$channel['totalCustomers'],
@@ -175,6 +178,11 @@ class ChannelController extends BaseController
$where[] = ['companyId', '=', $companyId];
$where[] = ['deleteTime', '=', 0];
// 如果不是管理员,只能查看自己创建的数据
if (!$this->getUserInfo('isAdmin')) {
$where[] = ['userId', '=', $this->getUserInfo('id')];
}
// 状态筛选
if ($status !== 'all') {
$where[] = ['status', '=', $status];
@@ -208,6 +216,8 @@ class ChannelController extends BaseController
'code' => $item['code'] ?? '',
'phone' => !empty($item['phone']) ? $item['phone'] : null,
'wechatId' => !empty($item['wechatId']) ? $item['wechatId'] : null,
'companyId' => (int)($item['companyId'] ?? 0),
'userId' => (int)($item['userId'] ?? 0),
'createType' => $item['createType'] ?? 'manual',
'status' => $item['status'] ?? 'enabled',
'totalCustomers' => (int)($item['totalCustomers'] ?? 0),
@@ -394,6 +404,8 @@ class ChannelController extends BaseController
'code' => $updatedChannel['code'],
'phone' => !empty($updatedChannel['phone']) ? $updatedChannel['phone'] : null,
'wechatId' => !empty($updatedChannel['wechatId']) ? $updatedChannel['wechatId'] : null,
'companyId' => (int)($updatedChannel['companyId'] ?? 0),
'userId' => (int)($updatedChannel['userId'] ?? 0),
'createType' => $updatedChannel['createType'],
'status' => $updatedChannel['status'],
'totalCustomers' => (int)$updatedChannel['totalCustomers'],
@@ -606,6 +618,11 @@ class ChannelController extends BaseController
['deleteTime', '=', 0]
];
// 如果不是管理员,只能查看自己创建的数据
if (!$this->getUserInfo('isAdmin')) {
$baseWhere[] = ['userId', '=', $this->getUserInfo('id')];
}
// 1. 总渠道数
$totalChannels = Db::name('distribution_channel')
->where($baseWhere)
@@ -667,6 +684,11 @@ class ChannelController extends BaseController
['companyId', '=', $companyId]
];
// 如果不是管理员,只能查看自己创建的提现申请
if (!$this->getUserInfo('isAdmin')) {
$baseWhere[] = ['userId', '=', $this->getUserInfo('id')];
}
// 1. 总支出所有已打款的提现申请金额总和状态为paid
$totalExpenditure = Db::name('distribution_withdrawal')
->where($baseWhere)
@@ -731,6 +753,11 @@ class ChannelController extends BaseController
$where[] = ['companyId', '=', $companyId];
$where[] = ['deleteTime', '=', 0];
// 如果不是管理员,只能查看自己创建的数据
if (!$this->getUserInfo('isAdmin')) {
$where[] = ['userId', '=', $this->getUserInfo('id')];
}
// 关键词搜索(模糊匹配 name、code
if (!empty($keyword)) {
$keyword = trim($keyword);
@@ -753,12 +780,20 @@ class ChannelController extends BaseController
$channelIds = array_column($channels, 'id');
$withdrawalStats = [];
if (!empty($channelIds)) {
// 构建提现查询条件
$withdrawalWhere = [
['companyId', '=', $companyId],
['channelId', 'in', $channelIds]
];
// 如果不是管理员,只能查看自己创建的提现申请
if (!$this->getUserInfo('isAdmin')) {
$withdrawalWhere[] = ['userId', '=', $this->getUserInfo('id')];
}
// 按渠道ID和状态分组统计提现金额
$stats = Db::name('distribution_withdrawal')
->where([
['companyId', '=', $companyId],
['channelId', 'in', $channelIds]
])
->where($withdrawalWhere)
->field([
'channelId',
'status',
@@ -1310,9 +1345,10 @@ class ChannelController extends BaseController
// 生成渠道编码
$code = DistributionChannel::generateChannelCode();
// 准备插入数据
// 准备插入数据(扫码注册时 userId 为 0因为是通过二维码注册没有登录用户
$data = [
'companyId' => $companyId,
'userId' => 0, // 扫码注册时没有登录用户userId 为 0
'name' => $name,
'code' => $code,
'phone' => $phone ?: '',
@@ -1353,6 +1389,7 @@ class ChannelController extends BaseController
'phone' => $channel['phone'] ?: '',
'wechatId' => $channel['wechatId'] ?: '',
'companyId' => (int)$companyId, // 返回companyId方便小程序自动跳转
'userId' => (int)($channel['userId'] ?? 0),
'createType' => $channel['createType'],
'status' => $channel['status'],
'totalCustomers' => (int)$channel['totalCustomers'],