This commit is contained in:
邹景立 2021-03-24 15:46:02 +08:00
parent 63bbe7cf08
commit 2b0dea961c
4 changed files with 123 additions and 3 deletions

View File

@ -45,6 +45,46 @@ class User extends Controller
UserAdminService::instance()->buildByUid($data, 'pid1', 'from');
}
/**
* 修改用户上传
* @auth true
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function parent()
{
$data = $this->_vali(['pid.default' => '', 'uid.require' => '待操作UID不能为空']);
if ($data['uid'] === $data['pid']) $this->error('推荐人不能是自己');
if (empty($data['pid'])) {
$map = [['id', '<>', $data['uid']], ['deleted', '=', 0]];
$query = $this->_query($this->table)->where($map)->equal('status,vip_code');
$query->like('phone,username|nickname#username')->dateBetween('create_at')->order('id desc')->page();
} else try {
$user = $this->app->db->name('DataUser')->where(['id' => $data['uid']])->find();
$parent = $this->app->db->name('DataUser')->where(['id' => $data['pid']])->find();
if (empty($user)) $this->error('读取用户信息失败!');
if (empty($parent)) $this->error('推荐人UID不能为空');
$this->app->db->transaction(function () use ($data, $user, $parent) {
if (empty($parent['vip_code'])) $this->error('推荐人无推荐资格');
if (is_numeric(strpos($parent['path'], "-{$data['uid']}-"))) $this->error('推荐人不能绑下属');
// 组装代理数据
$path = rtrim($parent['path'] ?: '-', '-') . "-{$parent['id']}-";
$this->app->db->name('DataUser')->where(['id' => $data['uid']])->update([
'pid0' => $parent['id'], 'pid1' => $parent['id'], 'pid2' => $parent['pid1'],
'path' => $path, 'layer' => substr_count($path, '-'),
]);
$newPath = rtrim($path, '-') . "-{$user['id']}-";
$oldPath = rtrim($user['path'], '-') . "-{$user['id']}-";
$this->app->db->name('DataUser')->whereLike('path', "{$oldPath}%")->ex;
});
$this->success('修改推荐人成功!');
} catch (\think\exception\HttpResponseException $exception) {
throw $exception;
} catch (\Exception $exception) {
$this->error($exception->getMessage());
}
}
/**
* 重新计算用户余额返利

View File

@ -122,7 +122,7 @@ class UserUpgradeService extends Service
if (empty($pid)) return [0, '绑定推荐人不存在'];
if ($uid == $pid) return [0, '推荐人不能是自己'];
$parant = $this->app->db->name('DataUser')->where(['id' => $pid])->find();
if (empty($parant['pids']) || empty($parant['vip_code'])) return [0, '推荐人无推荐资格'];
if (empty($parant['vip_code'])) return [0, '推荐人无推荐资格'];
if (stripos($parant['path'], "-{$uid}-") !== false) return [0, '不能绑定下属'];
// 组装代理数据
$path = rtrim($parant['path'] ?: '-', '-') . "-{$parant['id']}-";

View File

@ -2,7 +2,7 @@
{block name="button"}
<!--{if auth("sync")}-->
<button data-queue="{:url('sync')}" class='layui-btn layui-btn-sm layui-btn-primary'>刷新用户余额返利</button>
<button data-queue="{:url('sync')}" class='layui-btn layui-btn-sm layui-btn-primary'>刷新账户金额</button>
<!--{/if}-->
{/block}
@ -79,12 +79,16 @@
</td>
<td class="nowrap">
<!--{if auth("parent")}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-width="900px" data-iframe="{:url('parent')}?uid={$vo.id}">修改上级</a>
<!--{/if}-->
<!--{if auth("user_balance/add")}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-modal="{:url('user_balance/add')}?uid={$vo.id}">余额充值</a>
<!--{/if}-->
<!--{if auth("state") and $vo.status eq 1}-->
<a class="layui-btn layui-btn-sm layui-btn-danger" data-confirm="账号冻结后将不能下单和提现,确认吗?" data-action="{:url('state')}" data-value="id#{$vo.id};status#0">冻结账号</a>
<a class="layui-btn layui-btn-sm layui-btn-danger" data-action="{:url('state')}" data-value="id#{$vo.id};status#0" data-confirm="账号冻结后将不能下单和提现,确认吗?">冻结账号</a>
<!--{/if}-->
<!--{if auth("state") and $vo.status eq 0}-->

View File

@ -0,0 +1,76 @@
{extend name="../../admin/view/full"}
{block name="content"}
<div class="iframe-pagination">
{include file='user/index_search'}
<table class="layui-table margin-top-10" lay-skin="line">
{notempty name='list'}
<thead>
<tr>
<th class='nowrap'>用户信息</th>
<th class='nowrap'>推荐人信息</th>
<th class='nowrap'>注册时间</th>
<th class='nowrap'></th>
</tr>
</thead>
{/notempty}
<tbody>
{foreach $list as $key=>$vo}
<tr>
<td class="nowrap">
<div class="headimg" data-tips-image data-lazy-src="{$vo.headimg|default='__ROOT__/static/theme/img/headimg.png'}"></div>
<div class="inline-block">
<div>
{notempty name='vo.username'}
姓名:<span class="color-blue">{$vo.username|default='-'}</span>
{else}
昵称:<span class="color-blue">{$vo.nickname|default='-'}</span>
{/notempty}
<span class="margin-left-5">[ <b class="color-red">VIP{$vo.vip_code}</b> ] <b class="color-red">{$vo.vip_name}</b></span>
</div>
<div>手机:<span class="color-blue">{$vo.phone|default='-'}</span></div>
</div>
</td>
<td class="nowrap">
{notempty name='vo.from'}
<div class="headimg" data-tips-image data-lazy-src="{$vo.from.headimg|default='__ROOT__/static/theme/img/headimg.png'}"></div>
<div class="inline-block text-middle">
<!--{notempty name='vo.pids'}-->
<span class="layui-badge layui-badge-middle layui-bg-green">永久</span>
<!--{else}-->
<span class="layui-badge layui-badge-middle layui-bg-red">临时</span>
<!--{/notempty}-->
</div>
<div class="inline-block text-middle">
<div>
{notempty name='vo.from.username'}
姓名:<span class="color-blue">{$vo.from.username|default='-'}</span>
{else}
昵称:<span class="color-blue">{$vo.from.nickname|default='-'}</span>
{/notempty}
<span class="margin-left-5">[ <b class="color-red">VIP{$vo.from.vip_code}</b> ] <b class="color-red">{$vo.from.vip_name}</b></span>
</div>
<div>手机:<span>{$vo.from.phone|default='-'}</span></div>
</div>
{else}
<div class="color-desc">没有推荐人</div>
{/notempty}
</td>
<td class="nowrap">
使用状态:{if $vo.status eq 0}<b class="color-red margin-right-5">已冻结</b>{elseif $vo.status eq 1}<b class="color-green margin-right-5">已激活</b>{/if}<br>
注册时间:{$vo.create_at|format_datetime}
</td>
<td class="nowrap">
<!--{if auth("parent")}-->
<a class="layui-btn layui-btn-sm layui-btn-primary" data-modal="{:url('parent')}?uid={:input('uid')}&pid={$vo.id}">确认选择</a>
<!--{/if}-->
</td>
</tr>
{/foreach}
</tbody>
</table>
{empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
</div>
{/block}