Commit a61eaaf8 authored by 刘小敏's avatar 刘小敏

用户标签后台展示修改

parent 113b0263
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace app\admin\controller\shopro\user; namespace app\admin\controller\shopro\user;
use app\admin\model\shopro\ShoproUserTag;
use think\Db; use think\Db;
use app\admin\controller\shopro\Common; use app\admin\controller\shopro\Common;
use addons\shopro\service\Wallet as WalletService; use addons\shopro\service\Wallet as WalletService;
...@@ -30,7 +31,7 @@ class User extends Common ...@@ -30,7 +31,7 @@ class User extends Common
return $this->view->fetch(); return $this->view->fetch();
} }
$data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10)); $data = $this->model::with(['shopro_user_tag'])->sheepFilter()->paginate($this->request->param('list_rows', 10));
$this->success('获取成功', null, $data); $this->success('获取成功', null, $data);
} }
...@@ -46,7 +47,7 @@ class User extends Common ...@@ -46,7 +47,7 @@ class User extends Common
return $this->view->fetch(); return $this->view->fetch();
} }
$user = $this->model->with(['third_oauth', 'parent_user'])->where('id', $id)->find(); $user = $this->model->with(['third_oauth', 'parent_user', 'shopro_user_tag'])->where('id', $id)->find();
if (!$user) { if (!$user) {
$this->error(__('No Results were found')); $this->error(__('No Results were found'));
} }
...@@ -151,7 +152,52 @@ class User extends Common ...@@ -151,7 +152,52 @@ class User extends Common
} }
$data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10)); $data = $this->model->sheepFilter()->paginate($this->request->param('list_rows', 10));
$this->success('获取成功', null, $data); $this->success('获取成功', null, $data);
} }
/**
* 保存用户标签
*/
public function saveTags()
{
operate_filter();
$userId = $this->request->param('user_id');
$tags = $this->request->param('tags/a', []);
if (!$userId) {
$this->error('用户ID不能为空');
}
// 删除旧标签
Db::name('shopro_user_tag')->where('user_id', $userId)->delete();
// 插入新标签
if (!empty($tags)) {
$tagMap = [
'active' => '活跃用户',
'valuable' => '高价值用户',
'silent' => '沉默用户',
'new' => '新用户',
'vip' => 'VIP用户',
'wholesale' => '批发客户',
];
$data = [];
$now = time();
foreach ($tags as $tagCode) {
if (isset($tagMap[$tagCode])) {
$data[] = [
'user_id' => $userId,
'tag_code' => $tagCode,
'tag_name' => $tagMap[$tagCode],
'create_time' => $now,
'update_time' => $now,
];
}
}
if (!empty($data)) {
Db::name('shopro_user_tag')->insertAll($data);
}
}
$this->success('保存成功');
}
} }
<?php
namespace app\admin\model\shopro;
use app\admin\model\shopro\Common;
class ShoproUserTag extends Common
{
protected $name = 'shopro_user_tag';
}
...@@ -4,6 +4,7 @@ namespace app\admin\model\shopro\user; ...@@ -4,6 +4,7 @@ namespace app\admin\model\shopro\user;
use app\admin\model\shopro\Common; use app\admin\model\shopro\Common;
use app\admin\model\shopro\Coupon as CouponModel; use app\admin\model\shopro\Coupon as CouponModel;
use app\admin\model\shopro\ShoproUserTag;
use app\admin\model\shopro\ThirdOauth; use app\admin\model\shopro\ThirdOauth;
use addons\shopro\library\notify\traits\Notifiable; use addons\shopro\library\notify\traits\Notifiable;
use fast\Random; use fast\Random;
...@@ -136,4 +137,9 @@ class User extends Common ...@@ -136,4 +137,9 @@ class User extends Common
return $this->hasOne(\app\admin\model\shopro\commission\Agent::class, 'user_id', 'id'); return $this->hasOne(\app\admin\model\shopro\commission\Agent::class, 'user_id', 'id');
} }
// -- commission code end -- // -- commission code end --
public function shoproUserTag()
{
return $this->hasMany(ShoproUserTag::class, 'user_id', 'id');
}
} }
...@@ -64,6 +64,15 @@ ...@@ -64,6 +64,15 @@
.user-detail .third-oauth .provider-item:last-of-type { .user-detail .third-oauth .provider-item:last-of-type {
margin-bottom: 0; margin-bottom: 0;
} }
/* 新增标签选择器样式 */
.user-detail .tag-selector {
width: 100%;
}
.user-detail .tag-selector .el-select__tags {
flex-wrap: wrap;
}
</style> </style>
<div id="detail" class="user-detail" v-cloak> <div id="detail" class="user-detail" v-cloak>
...@@ -144,6 +153,28 @@ ...@@ -144,6 +153,28 @@
</el-input> </el-input>
</div> </div>
</el-col> </el-col>
<!-- 新增用户标签选择器 -->
<el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24">
<div class="left">用户标签</div>
<div class="right">
<el-select
v-model="state.tags"
multiple
class="tag-selector"
placeholder="请选择用户标签"
@change="onTagsChange"
>
<el-option
v-for="tag in state.tagOptions"
:key="tag.code"
:label="tag.name"
:value="tag.code"
></el-option>
</el-select>
</div>
</el-col>
<el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24"> <el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24">
<div class="left">状态</div> <div class="left">状态</div>
<div class="right"> <div class="right">
......
...@@ -37,6 +37,15 @@ ...@@ -37,6 +37,15 @@
</el-table-column> </el-table-column>
<el-table-column sortable="custom" prop="createtime" label="注册时间" min-width="172"></el-table-column> <el-table-column sortable="custom" prop="createtime" label="注册时间" min-width="172"></el-table-column>
<el-table-column sortable="custom" prop="logintime" label="上次登录" min-width="172"></el-table-column> <el-table-column sortable="custom" prop="logintime" label="上次登录" min-width="172"></el-table-column>
<el-table-column label="用户标签" min-width="100">
<template #default="scope">
<div v-for="item in scope.row.shopro_user_tag" :key="item.tag_code">
<span v-if="item.tag_code == 'active'" class="label label-success">{{item.tag_name}}</span>
<span v-if="item.tag_code == 'valuable'" class="label label-danger">{{item.tag_name}}</span>
<span v-if="item.tag_code == 'silent'" class="label label-primary" >{{item.tag_name}}</span>
</div>
</template>
</el-table-column>
<el-table-column fixed="right" label="操作" min-width="120"> <el-table-column fixed="right" label="操作" min-width="120">
<template #default="scope"> <template #default="scope">
{if $auth->check('shopro/user/user/detail')} {if $auth->check('shopro/user/user/detail')}
......
...@@ -175,7 +175,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -175,7 +175,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
const state = reactive({ const state = reactive({
type: new URLSearchParams(location.search).get('type'), type: new URLSearchParams(location.search).get('type'),
id: new URLSearchParams(location.search).get('id'), id: new URLSearchParams(location.search).get('id'),
detail: {} detail: {},
tags: [],
tagOptions: [
{ code: 'active', name: '活跃用户' },
{ code: 'valuable', name: '高价值用户' },
{ code: 'silent', name: '沉默用户' }
],
}) })
function getDetail() { function getDetail() {
...@@ -184,6 +190,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -184,6 +190,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
type: 'GET', type: 'GET',
}, function (ret, res) { }, function (ret, res) {
state.detail = res.data; state.detail = res.data;
state.tags = res.data?.shopro_user_tag?.map(item => item.tag_code)
console.log(state.tags)
return false
}, function (ret, res) { })
}
function onTagsChange() {
Fast.api.ajax({
url: `shopro/user/user/saveTags`,
type: 'POST',
data: {
user_id: state.id,
tags: state.tags
},
}, function (ret, res) {
return false return false
}, function (ret, res) { }) }, function (ret, res) { })
} }
...@@ -314,6 +335,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin ...@@ -314,6 +335,8 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
getLog, getLog,
pagination, pagination,
onChangeTab, onChangeTab,
// getTags,
onTagsChange,
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment