渠道新增用户权限
This commit is contained in:
@@ -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'],
|
||||
|
||||
@@ -43,6 +43,11 @@ class WithdrawalController extends BaseController
|
||||
$where = [];
|
||||
$where[] = ['w.companyId', '=', $companyId];
|
||||
|
||||
// 如果不是管理员,只能查看自己创建的提现申请
|
||||
if (!$this->getUserInfo('isAdmin')) {
|
||||
$where[] = ['w.userId', '=', $this->getUserInfo('id')];
|
||||
}
|
||||
|
||||
// 状态筛选
|
||||
if ($status !== 'all') {
|
||||
$where[] = ['w.status', '=', $status];
|
||||
@@ -89,6 +94,7 @@ class WithdrawalController extends BaseController
|
||||
$list = $query->field([
|
||||
'w.id',
|
||||
'w.channelId',
|
||||
'w.userId',
|
||||
'w.amount',
|
||||
'w.status',
|
||||
'w.payType',
|
||||
@@ -123,6 +129,7 @@ class WithdrawalController extends BaseController
|
||||
'channelId' => (string)$item['channelId'],
|
||||
'channelName' => $item['channelName'] ?? '',
|
||||
'channelCode' => $item['channelCode'] ?? '',
|
||||
'userId' => (int)($item['userId'] ?? 0),
|
||||
'amount' => round($item['amount'] / 100, 2), // 分转元,保留2位小数
|
||||
'status' => $item['status'] ?? DistributionWithdrawal::STATUS_PENDING,
|
||||
'payType' => !empty($item['payType']) ? $item['payType'] : null, // 支付类型
|
||||
@@ -168,6 +175,7 @@ class WithdrawalController extends BaseController
|
||||
$amount = $this->request->param('amount', 0); // 金额单位:元
|
||||
|
||||
$companyId = $this->getUserInfo('companyId');
|
||||
$userId = $this->getUserInfo('id');
|
||||
|
||||
// 参数验证
|
||||
if (empty($channelCode)) {
|
||||
@@ -271,6 +279,7 @@ class WithdrawalController extends BaseController
|
||||
$withdrawalData = [
|
||||
'companyId' => $companyId,
|
||||
'channelId' => $channelId,
|
||||
'userId' => $userId,
|
||||
'amount' => $amountInFen, // 存储为分
|
||||
'status' => DistributionWithdrawal::STATUS_PENDING,
|
||||
'applyTime' => time(),
|
||||
@@ -315,6 +324,7 @@ class WithdrawalController extends BaseController
|
||||
'channelId' => (string)$withdrawal['channelId'],
|
||||
'channelName' => $withdrawal['channelName'] ?? '',
|
||||
'channelCode' => $withdrawal['channelCode'] ?? '',
|
||||
'userId' => (int)($withdrawal['userId'] ?? 0),
|
||||
'amount' => round($withdrawal['amount'] / 100, 2), // 分转元,保留2位小数
|
||||
'status' => $withdrawal['status'],
|
||||
'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')
|
||||
->alias('w')
|
||||
->join('distribution_channel c', 'w.channelId = c.id AND c.deleteTime = 0', 'left')
|
||||
->where([
|
||||
['w.id', '=', $id],
|
||||
['w.companyId', '=', $companyId]
|
||||
])
|
||||
->where($where)
|
||||
->field([
|
||||
'w.id',
|
||||
'w.channelId',
|
||||
'w.userId',
|
||||
'w.amount',
|
||||
'w.status',
|
||||
'w.payType',
|
||||
@@ -641,6 +660,7 @@ class WithdrawalController extends BaseController
|
||||
'channelId' => (string)$withdrawal['channelId'],
|
||||
'channelName' => $withdrawal['channelName'] ?? '',
|
||||
'channelCode' => $withdrawal['channelCode'] ?? '',
|
||||
'userId' => (int)($withdrawal['userId'] ?? 0),
|
||||
'amount' => round($withdrawal['amount'] / 100, 2), // 分转元,保留2位小数
|
||||
'status' => $withdrawal['status'],
|
||||
'payType' => !empty($withdrawal['payType']) ? $withdrawal['payType'] : null, // 支付类型:wechat、alipay、bankcard
|
||||
|
||||
Reference in New Issue
Block a user