!241 完善分销功能

Merge pull request !241 from 疯狂的世界/brokerage
This commit is contained in:
芋道源码 2023-09-12 15:19:33 +00:00 committed by Gitee
commit de615c2387
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 559 additions and 33 deletions

View File

@ -8,6 +8,9 @@ export interface BrokerageUserVO {
brokerageTime: Date
price: number
frozenPrice: number
nickname: string
avatar: string
}
// 查询分销用户列表
@ -19,3 +22,18 @@ export const getBrokerageUserPage = async (params: any) => {
export const getBrokerageUser = async (id: number) => {
return await request.get({ url: `/trade/brokerage-user/get?id=` + id })
}
// 修改推广员
export const updateBindUser = async (data: any) => {
return await request.put({ url: `/trade/brokerage-user/update-bind-user`, data })
}
// 清除推广员
export const clearBindUser = async (data: any) => {
return await request.put({ url: `/trade/brokerage-user/clear-bind-user`, data })
}
// 修改推广资格
export const updateBrokerageEnabled = async (data: any) => {
return await request.put({ url: `/trade/brokerage-user/update-brokerage-enable`, data })
}

View File

@ -299,3 +299,33 @@ export const BrokerageEnabledConditionEnum = {
name: '指定分销'
}
}
/**
*
*/
export const BrokerageUserTypeEnum = {
ALL: {
type: 0,
name: '全部'
},
FIRST: {
type: 1,
name: '一级推广人'
},
SECOND: {
type: 2,
name: '二级推广人'
}
}
/**
*
*/
export const BrokerageRecordBizTypeEnum = {
ORDER: {
type: 1,
name: '获得推广佣金'
},
WITHDRAW: {
type: 2,
name: '提现申请'
}
}

View File

@ -151,13 +151,6 @@ export enum DICT_TYPE {
// ========== MALL - 会员模块 ==========
MEMBER_POINT_BIZ_TYPE = 'member_point_biz_type', // 积分的业务类型
MEMBER_EXPERIENCE_BIZ_TYPE = 'member_experience_biz_type', // 会员经验业务类型
// TODO @疯狂:这块的枚举,是不是要挪到 TRADE 那啦
BROKERAGE_ENABLED_CONDITION = 'brokerage_enabled_condition', // 分佣模式
BROKERAGE_BIND_MODE = 'brokerage_bind_mode', // 分销关系绑定模式
BROKERAGE_BANK_NAME = 'brokerage_bank_name', // 佣金提现银行
BROKERAGE_WITHDRAW_TYPE = 'brokerage_withdraw_type', // 佣金冻结时间
BROKERAGE_RECORD_BIZ_TYPE = 'brokerage_record_biz_type', // 佣金业务类型
BROKERAGE_RECORD_STATUS = 'brokerage_record_status', // 佣金状态
// ========== MALL - 商品模块 ==========
PRODUCT_UNIT = 'product_unit', // 商品单位
@ -172,6 +165,12 @@ export enum DICT_TYPE {
TRADE_ORDER_STATUS = 'trade_order_status', // 订单 - 状态
TRADE_ORDER_ITEM_AFTER_SALE_STATUS = 'trade_order_item_after_sale_status', // 订单项 - 售后状态
TRADE_DELIVERY_TYPE = 'trade_delivery_type', // 配送方式
BROKERAGE_ENABLED_CONDITION = 'brokerage_enabled_condition', // 分佣模式
BROKERAGE_BIND_MODE = 'brokerage_bind_mode', // 分销关系绑定模式
BROKERAGE_BANK_NAME = 'brokerage_bank_name', // 佣金提现银行
BROKERAGE_WITHDRAW_TYPE = 'brokerage_withdraw_type', // 佣金冻结时间
BROKERAGE_RECORD_BIZ_TYPE = 'brokerage_record_biz_type', // 佣金业务类型
BROKERAGE_RECORD_STATUS = 'brokerage_record_status', // 佣金状态
// ========== MALL - 营销模块 ==========
PROMOTION_DISCOUNT_TYPE = 'promotion_discount_type', // 优惠类型

View File

@ -65,6 +65,12 @@
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="编号" align="center" prop="id" min-width="60" />
<el-table-column label="用户编号" align="center" prop="userId" min-width="80" />
<el-table-column label="头像" align="center" prop="userAvatar" width="70px">
<template #default="scope">
<el-avatar :src="scope.row.userAvatar" />
</template>
</el-table-column>
<el-table-column label="昵称" align="center" prop="userNickname" min-width="80px" />
<el-table-column label="业务类型" align="center" prop="bizType" min-width="85">
<template #default="scope">
<dict-tag :type="DICT_TYPE.BROKERAGE_RECORD_BIZ_TYPE" :value="scope.row.bizType" />
@ -72,7 +78,13 @@
</el-table-column>
<el-table-column label="业务编号" align="center" prop="bizId" min-width="80" />
<el-table-column label="标题" align="center" prop="title" min-width="110" />
<el-table-column label="金额" align="center" prop="price" min-width="60" />
<el-table-column
label="金额"
align="center"
prop="price"
min-width="60"
:formatter="fenToYuanFormat"
/>
<el-table-column label="说明" align="center" prop="description" min-width="120" />
<el-table-column label="状态" align="center" prop="status" min-width="85">
<template #default="scope">
@ -108,6 +120,7 @@
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import * as BrokerageRecordApi from '@/api/mall/trade/brokerage/record'
import { fenToYuanFormat } from '@/utils/formatter'
defineOptions({ name: 'TradeBrokerageRecord' })

View File

@ -0,0 +1,155 @@
<template>
<Dialog v-model="dialogVisible" title="推广人列表" width="75%">
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="85px"
>
<el-form-item label="用户类型" prop="userType">
<el-radio-group v-model="queryParams.userType" @change="handleQuery">
<el-radio-button
v-for="item in BrokerageUserTypeEnum"
:key="item.type"
:label="item.type"
>
{{ item.name }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-select
v-model="queryParams.status"
placeholder="请选择状态"
clearable
class="!w-240px"
>
<el-option
v-for="dict in getIntDictOptions(DICT_TYPE.BROKERAGE_RECORD_STATUS)"
:key="dict.value"
:label="dict.label"
:value="dict.value"
/>
</el-select>
</el-form-item>
<el-form-item label="绑定时间" prop="createTime">
<el-date-picker
v-model="queryParams.createTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="订单编号" align="center" prop="bizId" min-width="80px" />
<el-table-column label="用户编号" align="center" prop="sourceUserId" min-width="80px" />
<el-table-column label="头像" align="center" prop="sourceUserAvatar" width="70px">
<template #default="scope">
<el-avatar :src="scope.row.sourceUserAvatar" />
</template>
</el-table-column>
<el-table-column label="昵称" align="center" prop="sourceUserNickname" min-width="80px" />
<el-table-column
label="佣金"
align="center"
prop="price"
min-width="100px"
:formatter="fenToYuanFormat"
/>
<el-table-column label="状态" align="center" prop="status" min-width="85">
<template #default="scope">
<dict-tag :type="DICT_TYPE.BROKERAGE_RECORD_STATUS" :value="scope.row.status" />
</template>
</el-table-column>
<el-table-column
label="创建时间"
align="center"
prop="createTime"
:formatter="dateFormatter"
width="170px"
/>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
</Dialog>
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import * as BrokerageRecordApi from '@/api/mall/trade/brokerage/record'
import { BrokerageRecordBizTypeEnum, BrokerageUserTypeEnum } from '@/utils/constants'
import { fenToYuanFormat } from '@/utils/formatter'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
/** 推广订单列表 */
defineOptions({ name: 'BrokerageOrderListDialog' })
const message = useMessage() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
userId: null,
bizType: BrokerageRecordBizTypeEnum.ORDER.type,
userType: BrokerageUserTypeEnum.ALL.type,
createTime: []
})
const queryFormRef = ref() //
/** 打开弹窗 */
const dialogVisible = ref(false) //
const open = async (userId: number) => {
dialogVisible.value = true
queryParams.userId = userId
resetQuery()
}
defineExpose({ open }) // open
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await BrokerageRecordApi.getBrokerageRecordPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
handleQuery()
}
</script>

View File

@ -0,0 +1,142 @@
<template>
<Dialog v-model="dialogVisible" title="推广人列表" width="75%">
<ContentWrap>
<!-- 搜索工作栏 -->
<el-form
class="-mb-15px"
:model="queryParams"
ref="queryFormRef"
:inline="true"
label-width="85px"
>
<el-form-item label="用户类型" prop="userType">
<el-radio-group v-model="queryParams.userType" @change="handleQuery">
<el-radio-button
v-for="item in BrokerageUserTypeEnum"
:key="item.type"
:label="item.type"
>
{{ item.name }}
</el-radio-button>
</el-radio-group>
</el-form-item>
<el-form-item label="绑定时间" prop="bindUserTime">
<el-date-picker
v-model="queryParams.bindUserTime"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
class="!w-240px"
/>
</el-form-item>
<el-form-item>
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
</el-form-item>
</el-form>
</ContentWrap>
<!-- 列表 -->
<ContentWrap>
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
<el-table-column label="用户编号" align="center" prop="id" min-width="80px" />
<el-table-column label="头像" align="center" prop="avatar" width="70px">
<template #default="scope">
<el-avatar :src="scope.row.avatar" />
</template>
</el-table-column>
<el-table-column label="昵称" align="center" prop="nickname" min-width="80px" />
<el-table-column
label="推广人数"
align="center"
prop="brokerageUserCount"
min-width="80px"
/>
<el-table-column
label="推广订单数量"
align="center"
prop="brokerageOrderCount"
min-width="110px"
/>
<el-table-column label="推广资格" align="center" prop="brokerageEnabled" min-width="80px">
<template #default="scope">
<el-tag v-if="scope.row.brokerageEnabled"></el-tag>
<el-tag v-else type="info"></el-tag>
</template>
</el-table-column>
<el-table-column
label="绑定时间"
align="center"
prop="bindUserTime"
:formatter="dateFormatter"
width="170px"
/>
</el-table>
<!-- 分页 -->
<Pagination
:total="total"
v-model:page="queryParams.pageNo"
v-model:limit="queryParams.pageSize"
@pagination="getList"
/>
</ContentWrap>
</Dialog>
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import * as BrokerageUserApi from '@/api/mall/trade/brokerage/user'
import { BrokerageUserTypeEnum } from '@/utils/constants'
/** 推广人列表 */
defineOptions({ name: 'BrokerageUserListDialog' })
const message = useMessage() //
const loading = ref(true) //
const total = ref(0) //
const list = ref([]) //
const queryParams = reactive({
pageNo: 1,
pageSize: 10,
bindUserId: null,
userType: BrokerageUserTypeEnum.ALL.type,
bindUserTime: []
})
const queryFormRef = ref() //
/** 打开弹窗 */
const dialogVisible = ref(false) //
const open = async (bindUserId: number) => {
dialogVisible.value = true
queryParams.bindUserId = bindUserId
resetQuery()
}
defineExpose({ open }) // open
/** 查询列表 */
const getList = async () => {
loading.value = true
try {
const data = await BrokerageUserApi.getBrokerageUserPage(queryParams)
list.value = data.list
total.value = data.total
} finally {
loading.value = false
}
}
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.pageNo = 1
getList()
}
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields()
handleQuery()
}
</script>

View File

@ -0,0 +1,127 @@
<template>
<Dialog v-model="dialogVisible" title="修改上级推广人" width="500">
<el-form
ref="formRef"
v-loading="formLoading"
:model="formData"
:rules="formRules"
label-width="80px"
>
<el-form-item label="推广人" prop="bindUserId">
<el-input
v-model="formData.bindUserId"
placeholder="请输入推广员编号"
v-loading="formLoading"
>
<template #append>
<el-button @click="handleGetUser"><Icon icon="ep:search" class="mr-5px" /></el-button>
</template>
</el-input>
</el-form-item>
</el-form>
<el-descriptions v-if="bindUser" :column="1" border>
<el-descriptions-item label="头像">
<el-avatar :src="bindUser.avatar" />
</el-descriptions-item>
<el-descriptions-item label="昵称">{{ bindUser.nickname }}</el-descriptions-item>
<el-descriptions-item label="推广资格">
<el-tag v-if="bindUser.brokerageEnabled"></el-tag>
<el-tag v-else type="info"></el-tag>
</el-descriptions-item>
<el-descriptions-item label="成为推广员的时间">
{{ formatDate(bindUser.brokerageTime) }}
</el-descriptions-item>
</el-descriptions>
<template #footer>
<el-button :disabled="formLoading" type="primary" @click="submitForm"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script lang="ts" setup>
import * as BrokerageUserApi from '@/api/mall/trade/brokerage/user'
import { formatDate } from '@/utils/formatTime'
/** 修改上级推广人表单 */
defineOptions({ name: 'UpdateBindUserForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const formLoading = ref(false) // 12
const formData = ref()
const formRef = ref() // Ref
const formRules = reactive({
bindUserId: [{ required: true, message: '推广员人不能为空', trigger: 'blur' }]
})
/** 打开弹窗 */
const open = async (row: BrokerageUserApi.BrokerageUserVO) => {
resetForm()
//
formData.value.id = row.id
formData.value.bindUserId = row.bindUserId
// 广
if (row.bindUserId) {
await handleGetUser()
}
dialogVisible.value = true
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
/** 修改上级推广人 */
const submitForm = async () => {
if (formLoading.value) return
//
if (!formRef) return
const valid = await formRef.value.validate()
if (!valid) return
if (!bindUser.value) {
message.error('请先查询并确认推广人')
return
}
//
formLoading.value = true
try {
//
await BrokerageUserApi.updateBindUser(formData.value)
message.success(t('common.updateSuccess'))
dialogVisible.value = false
//
emit('success', true)
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: 0,
bindUserId: undefined
}
formRef.value?.resetFields()
bindUser.value = undefined
}
/** 查询推广员 */
const bindUser = ref<BrokerageUserApi.BrokerageUserVO>()
const handleGetUser = async () => {
if (formData.value.bindUserId == formData.value.id) {
message.error('不能绑定自己为推广人')
return
}
formLoading.value = true
bindUser.value = await BrokerageUserApi.getBrokerageUser(formData.value.bindUserId)
if (!bindUser.value) {
message.warning('推广员不存在')
}
formLoading.value = false
}
</script>

View File

@ -56,12 +56,7 @@
</template>
</el-table-column>
<el-table-column label="昵称" align="center" prop="nickname" min-width="80px" />
<el-table-column
label="推广用户数量(一级)"
align="center"
prop="brokerageUserCount"
min-width="110px"
/>
<el-table-column label="推广人数" align="center" prop="brokerageUserCount" width="80px" />
<el-table-column
label="推广订单数量"
align="center"
@ -104,8 +99,8 @@
active-text="有"
inactive-text="无"
inline-prompt
:disabled="!checkPermi(['trade:brokerage-user:update-brokerage-user'])"
@change="handleBrokerageEnabledChange(scope.row.id, !scope.row.brokerageEnabled)"
:disabled="!checkPermi(['trade:brokerage-user:update-bind-user'])"
@change="handleBrokerageEnabledChange(scope.row)"
/>
</template>
</el-table-column>
@ -131,10 +126,14 @@
v-hasPermi="[
'trade:brokerage-user:user-query',
'trade:brokerage-user:order-query',
'trade:brokerage-user:update-brokerage-user',
'trade:brokerage-user:clear-brokerage-user'
'trade:brokerage-user:update-bind-user',
'trade:brokerage-user:clear-bind-user'
]"
>
<el-button link type="primary">
<Icon icon="ep:d-arrow-right" />
更多
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
@ -150,14 +149,16 @@
推广订单
</el-dropdown-item>
<el-dropdown-item
command="openUpdateBindUser"
v-if="checkPermi(['trade:brokerage-user:update-brokerage-user'])"
command="openUpdateBindUserForm"
v-if="checkPermi(['trade:brokerage-user:update-bind-user'])"
>
修改上级推广人
</el-dropdown-item>
<el-dropdown-item
command="openClearBindUser"
v-if="checkPermi(['trade:brokerage-user:clear-brokerage-user'])"
command="handleClearBindUser"
v-if="
scope.row.bindUserId && checkPermi(['trade:brokerage-user:clear-bind-user'])
"
>
清除上级推广人
</el-dropdown-item>
@ -175,6 +176,12 @@
@pagination="getList"
/>
</ContentWrap>
<!-- 修改上级推广人表单 -->
<UpdateBindUserForm ref="updateBindUserFormRef" @success="getList" />
<!-- 推广人列表 -->
<BrokerageUserListDialog ref="brokerageUserListDialogRef" />
<!-- 推广订单列表 -->
<BrokerageOrderListDialog ref="brokerageOrderListDialogRef" />
</template>
<script setup lang="ts">
@ -182,11 +189,13 @@ import { dateFormatter } from '@/utils/formatTime'
import * as BrokerageUserApi from '@/api/mall/trade/brokerage/user'
import { checkPermi } from '@/utils/permission'
import { fenToYuanFormat } from '@/utils/formatter'
import UpdateBindUserForm from '@/views/mall/trade/brokerage/user/UpdateBindUserForm.vue'
import BrokerageUserListDialog from '@/views/mall/trade/brokerage/user/BrokerageUserListDialog.vue'
import BrokerageOrderListDialog from '@/views/mall/trade/brokerage/user/BrokerageOrderListDialog.vue'
defineOptions({ name: 'TradeBrokerageUser' })
const message = useMessage() //
const { t } = useI18n() //
const loading = ref(true) //
const total = ref(0) //
@ -232,29 +241,62 @@ const handleCommand = (command: string, row: BrokerageUserApi.BrokerageUserVO) =
case 'openBrokerageOrderTable':
openBrokerageOrderTable(row.id)
break
case 'openUpdateBindUser':
openUpdateBindUser(row.id)
case 'openUpdateBindUserForm':
openUpdateBindUserForm(row)
break
case 'openClearBindUser':
openClearBindUser(row.id)
case 'handleClearBindUser':
handleClearBindUser(row)
break
}
}
/** 打开推广人列表 */
const openBrokerageUserTable = (id: number) => {}
const brokerageUserListDialogRef = ref()
const openBrokerageUserTable = (id: number) => {
brokerageUserListDialogRef.value.open(id)
}
/** 打开推广订单列表 */
const openBrokerageOrderTable = (id: number) => {}
const brokerageOrderListDialogRef = ref()
const openBrokerageOrderTable = (id: number) => {
brokerageOrderListDialogRef.value.open(id)
}
/** 打开表单:修改上级推广人 */
const openUpdateBindUser = (id: number) => {}
const updateBindUserFormRef = ref()
const openUpdateBindUserForm = (row: BrokerageUserApi.BrokerageUserVO) => {
updateBindUserFormRef.value.open(row)
}
/** 打开表单:清除上级推广人 */
const openClearBindUser = (id: number) => {}
/** 清除上级推广人 */
const handleClearBindUser = async (row: BrokerageUserApi.BrokerageUserVO) => {
try {
//
await message.confirm(`确认要清除"${row.nickname}"的上级推广人吗?`)
//
await BrokerageUserApi.clearBindUser({ id: row.id })
message.success('清除成功')
//
await getList()
} catch {}
}
/** 推广资格 开通/关闭 */
const handleBrokerageEnabledChange = (id: number, enabled: boolean) => {}
const handleBrokerageEnabledChange = async (row: BrokerageUserApi.BrokerageUserVO) => {
try {
//
const text = row.brokerageEnabled ? '开通' : '关闭'
await message.confirm(`确认要${text}"${row.nickname}"的推广资格吗?`)
//
await BrokerageUserApi.updateBrokerageEnabled({ id: row.id, enabled: row.brokerageEnabled })
message.success(text + '成功')
//
await getList()
} catch {
//
row.brokerageEnabled = !row.brokerageEnabled
}
}
/** 初始化 **/
onMounted(() => {