渠道新增用户权限

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

View File

@@ -43,6 +43,11 @@ class WithdrawalController extends BaseController
$where = []; $where = [];
$where[] = ['w.companyId', '=', $companyId]; $where[] = ['w.companyId', '=', $companyId];
// 如果不是管理员,只能查看自己创建的提现申请
if (!$this->getUserInfo('isAdmin')) {
$where[] = ['w.userId', '=', $this->getUserInfo('id')];
}
// 状态筛选 // 状态筛选
if ($status !== 'all') { if ($status !== 'all') {
$where[] = ['w.status', '=', $status]; $where[] = ['w.status', '=', $status];
@@ -89,6 +94,7 @@ class WithdrawalController extends BaseController
$list = $query->field([ $list = $query->field([
'w.id', 'w.id',
'w.channelId', 'w.channelId',
'w.userId',
'w.amount', 'w.amount',
'w.status', 'w.status',
'w.payType', 'w.payType',
@@ -123,6 +129,7 @@ class WithdrawalController extends BaseController
'channelId' => (string)$item['channelId'], 'channelId' => (string)$item['channelId'],
'channelName' => $item['channelName'] ?? '', 'channelName' => $item['channelName'] ?? '',
'channelCode' => $item['channelCode'] ?? '', 'channelCode' => $item['channelCode'] ?? '',
'userId' => (int)($item['userId'] ?? 0),
'amount' => round($item['amount'] / 100, 2), // 分转元保留2位小数 'amount' => round($item['amount'] / 100, 2), // 分转元保留2位小数
'status' => $item['status'] ?? DistributionWithdrawal::STATUS_PENDING, 'status' => $item['status'] ?? DistributionWithdrawal::STATUS_PENDING,
'payType' => !empty($item['payType']) ? $item['payType'] : null, // 支付类型 'payType' => !empty($item['payType']) ? $item['payType'] : null, // 支付类型
@@ -168,6 +175,7 @@ class WithdrawalController extends BaseController
$amount = $this->request->param('amount', 0); // 金额单位:元 $amount = $this->request->param('amount', 0); // 金额单位:元
$companyId = $this->getUserInfo('companyId'); $companyId = $this->getUserInfo('companyId');
$userId = $this->getUserInfo('id');
// 参数验证 // 参数验证
if (empty($channelCode)) { if (empty($channelCode)) {
@@ -271,6 +279,7 @@ class WithdrawalController extends BaseController
$withdrawalData = [ $withdrawalData = [
'companyId' => $companyId, 'companyId' => $companyId,
'channelId' => $channelId, 'channelId' => $channelId,
'userId' => $userId,
'amount' => $amountInFen, // 存储为分 'amount' => $amountInFen, // 存储为分
'status' => DistributionWithdrawal::STATUS_PENDING, 'status' => DistributionWithdrawal::STATUS_PENDING,
'applyTime' => time(), 'applyTime' => time(),
@@ -315,6 +324,7 @@ class WithdrawalController extends BaseController
'channelId' => (string)$withdrawal['channelId'], 'channelId' => (string)$withdrawal['channelId'],
'channelName' => $withdrawal['channelName'] ?? '', 'channelName' => $withdrawal['channelName'] ?? '',
'channelCode' => $withdrawal['channelCode'] ?? '', 'channelCode' => $withdrawal['channelCode'] ?? '',
'userId' => (int)($withdrawal['userId'] ?? 0),
'amount' => round($withdrawal['amount'] / 100, 2), // 分转元保留2位小数 'amount' => round($withdrawal['amount'] / 100, 2), // 分转元保留2位小数
'status' => $withdrawal['status'], 'status' => $withdrawal['status'],
'payType' => !empty($withdrawal['payType']) ? $withdrawal['payType'] : null, // 支付类型wechat、alipay、bankcard创建时为null 'payType' => !empty($withdrawal['payType']) ? $withdrawal['payType'] : null, // 支付类型wechat、alipay、bankcard创建时为null
@@ -603,17 +613,26 @@ class WithdrawalController extends BaseController
]); ]);
} }
// 构建查询条件
$where = [
['w.id', '=', $id],
['w.companyId', '=', $companyId]
];
// 如果不是管理员,只能查看自己创建的提现申请
if (!$this->getUserInfo('isAdmin')) {
$where[] = ['w.userId', '=', $this->getUserInfo('id')];
}
// 查询申请详情(关联渠道表) // 查询申请详情(关联渠道表)
$withdrawal = Db::name('distribution_withdrawal') $withdrawal = Db::name('distribution_withdrawal')
->alias('w') ->alias('w')
->join('distribution_channel c', 'w.channelId = c.id AND c.deleteTime = 0', 'left') ->join('distribution_channel c', 'w.channelId = c.id AND c.deleteTime = 0', 'left')
->where([ ->where($where)
['w.id', '=', $id],
['w.companyId', '=', $companyId]
])
->field([ ->field([
'w.id', 'w.id',
'w.channelId', 'w.channelId',
'w.userId',
'w.amount', 'w.amount',
'w.status', 'w.status',
'w.payType', 'w.payType',
@@ -641,6 +660,7 @@ class WithdrawalController extends BaseController
'channelId' => (string)$withdrawal['channelId'], 'channelId' => (string)$withdrawal['channelId'],
'channelName' => $withdrawal['channelName'] ?? '', 'channelName' => $withdrawal['channelName'] ?? '',
'channelCode' => $withdrawal['channelCode'] ?? '', 'channelCode' => $withdrawal['channelCode'] ?? '',
'userId' => (int)($withdrawal['userId'] ?? 0),
'amount' => round($withdrawal['amount'] / 100, 2), // 分转元保留2位小数 'amount' => round($withdrawal['amount'] / 100, 2), // 分转元保留2位小数
'status' => $withdrawal['status'], 'status' => $withdrawal['status'],
'payType' => !empty($withdrawal['payType']) ? $withdrawal['payType'] : null, // 支付类型wechat、alipay、bankcard 'payType' => !empty($withdrawal['payType']) ? $withdrawal['payType'] : null, // 支付类型wechat、alipay、bankcard