WIN-2308041133\Administrator 1 hónapja
szülő
commit
e09e67006f

+ 365 - 0
app/admin/controller/user/UserDealerLevel.php

@@ -0,0 +1,365 @@
+<?php
+/**
+ * 经销商等级管理控制器
+ * 管理经销商等级配置(名称、折扣、佣金比例等)以及用户经销商等级分配
+ */
+
+namespace app\admin\controller\user;
+
+use app\admin\controller\AuthController;
+use think\facade\Route as Url;
+use crmeb\traits\CurdControllerTrait;
+use app\admin\model\system\SystemDealerLevel;
+use app\admin\model\user\UserDealer;
+use app\admin\model\user\User;
+use crmeb\services\{UtilService, JsonService, FormBuilder as Form};
+
+class UserDealerLevel extends AuthController
+{
+    use CurdControllerTrait;
+
+    /**
+     * 经销商等级列表页面
+     * @return \think\response\View
+     */
+    public function index()
+    {
+        return $this->fetch();
+    }
+
+    /**
+     * 创建/编辑经销商等级表单
+     * @param int $id 经销商等级ID(编辑时传递)
+     * @return \think\response\View
+     */
+    public function create($id = 0)
+    {
+        $dealerLevel = $id ? SystemDealerLevel::get($id) : null;
+        if ($id && !$dealerLevel) {
+            return JsonService::fail('经销商等级不存在');
+        }
+
+        $field = [];
+        // 等级名称
+        $field[] = Form::input('name', '经销商等级名称', $dealerLevel ? $dealerLevel->name : '')
+            ->col(Form::col(24))
+            ->required('请输入经销商等级名称');
+        // 等级排序
+        $field[] = Form::number('grade', '等级排序', $dealerLevel ? $dealerLevel->grade : 0)
+            ->min(0)
+            ->col(Form::col(8))
+            ->required('请输入等级排序');
+        // 进货折扣
+        $field[] = Form::number('discount', '进货折扣(%)', $dealerLevel ? $dealerLevel->discount : 100)
+            ->min(0)->max(100)
+            ->col(Form::col(8));
+        // 佣金比例
+        $field[] = Form::number('commission_rate', '佣金比例(%)', $dealerLevel ? $dealerLevel->commission_rate : 0)
+            ->min(0)->max(100)
+            ->col(Form::col(8));
+        // 是否可见特供规格
+        $field[] = Form::radio('can_see_special', '可见特供规格', $dealerLevel ? $dealerLevel->can_see_special : 0)
+            ->options([
+                ['label' => '可见', 'value' => 1],
+                ['label' => '不可见', 'value' => 0]
+            ])
+            ->col(Form::col(12));
+        // 是否显示
+        $field[] = Form::radio('is_show', '是否显示', $dealerLevel ? $dealerLevel->is_show : 1)
+            ->options([
+                ['label' => '显示', 'value' => 1],
+                ['label' => '隐藏', 'value' => 0]
+            ])
+            ->col(Form::col(12));
+        // 等级图标
+        $field[] = Form::frameImageOne('icon', '等级图标', Url::buildUrl('admin/widget.images/index', ['fodder' => 'icon']), $dealerLevel ? $dealerLevel->icon : '')
+            ->icon('image')
+            ->width('100%')
+            ->height('500px');
+        // 等级大图
+        $field[] = Form::frameImageOne('image', '等级大图', Url::buildUrl('admin/widget.images/index', ['fodder' => 'image']), $dealerLevel ? $dealerLevel->image : '')
+            ->icon('image')
+            ->width('100%')
+            ->height('500px');
+        // 等级说明
+        $field[] = Form::textarea('explain', '等级说明', $dealerLevel ? $dealerLevel->explain : '')
+            ->col(Form::col(24));
+
+        $formTitle = $id ? '编辑经销商等级' : '添加经销商等级';
+        $formUrl = Url::buildUrl('save', ['id' => $id]);
+        $form = Form::make_post_form($formTitle, $field, $formUrl, 2);
+
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 保存/编辑经销商等级
+     * @param int $id 经销商等级ID(编辑时传递)
+     * @return \crmeb\services\JsonService
+     */
+    public function save($id = 0)
+    {
+        $data = UtilService::postMore([
+            ['name', ''],
+            ['grade', 0],
+            ['discount', 100],
+            ['commission_rate', 0],
+            ['can_see_special', 0],
+            ['is_show', 1],
+            ['icon', ''],
+            ['image', ''],
+            ['explain', ''],
+        ]);
+
+        // 参数验证
+        if (empty($data['name'])) return JsonService::fail('请输入经销商等级名称');
+        if ($data['discount'] < 0 || $data['discount'] > 100) return JsonService::fail('进货折扣请输入0-100之间的数值');
+        if ($data['commission_rate'] < 0 || $data['commission_rate'] > 100) return JsonService::fail('佣金比例请输入0-100之间的数值');
+        if (empty($data['grade']) && $data['grade'] !== 0) return JsonService::fail('请输入等级排序');
+
+        // 等级排序唯一性校验
+        $exists = SystemDealerLevel::where('is_del', 0)
+            ->where('grade', $data['grade'])
+            ->when($id, function ($query) use ($id) {
+                $query->where('id', '<>', $id);
+            })
+            ->find();
+        if ($exists) return JsonService::fail('该等级排序已存在,请更换');
+
+        SystemDealerLevel::startTrans();
+        try {
+            if ($id) {
+                $result = SystemDealerLevel::update($data, ['id' => $id]);
+            } else {
+                $data['add_time'] = time();
+                $result = SystemDealerLevel::create($data);
+            }
+
+            if ($result) {
+                SystemDealerLevel::commit();
+                return JsonService::successful($id ? '修改成功' : '添加成功');
+            } else {
+                SystemDealerLevel::rollback();
+                return JsonService::fail($id ? '修改失败' : '添加失败');
+            }
+        } catch (\Exception $e) {
+            SystemDealerLevel::rollback();
+            return JsonService::fail($e->getMessage());
+        }
+    }
+
+    /**
+     * 获取经销商等级列表(分页+搜索)
+     * @return \crmeb\services\JsonService
+     */
+    public function get_list()
+    {
+        $where = UtilService::getMore([
+            ['page', 1],
+            ['limit', 10],
+            ['name', ''],
+            ['is_show', ''],
+        ]);
+
+        $query = SystemDealerLevel::where('is_del', 0);
+        if ($where['name']) $query->where('name', 'like', "%{$where['name']}%");
+        if ($where['is_show'] !== '') $query->where('is_show', $where['is_show']);
+
+        $list = $query->order('grade asc')
+            ->paginate([
+                'page' => $where['page'],
+                'list_rows' => $where['limit'],
+            ]);
+
+        return JsonService::successlayui([
+            'count' => $list->total(),
+            'data' => $list->items(),
+        ]);
+    }
+
+    /**
+     * 删除经销商等级(软删除)
+     * @param int $id 经销商等级ID
+     * @return \crmeb\services\JsonService
+     */
+    public function delete($id = 0)
+    {
+        if (empty($id)) return JsonService::fail('缺少参数ID');
+
+        if (SystemDealerLevel::update(['is_del' => 1], ['id' => $id])) {
+            return JsonService::successful('删除成功');
+        } else {
+            return JsonService::fail('删除失败');
+        }
+    }
+
+    /**
+     * 设置经销商等级显示状态
+     * @param int $is_show 显示状态(1=显示,0=隐藏)
+     * @param int $id 经销商等级ID
+     * @return \crmeb\services\JsonService
+     */
+    public function set_show($is_show = '', $id = '')
+    {
+        if ($is_show === '' || empty($id)) return JsonService::fail('缺少参数');
+
+        $result = SystemDealerLevel::where('id', $id)->update(['is_show' => (int)$is_show]);
+        return $result ?
+            JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功') :
+            JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败');
+    }
+
+    /**
+     * 快速编辑经销商等级字段
+     * @param string $field 字段名
+     * @param int $id 经销商等级ID
+     * @param mixed $value 字段值
+     * @return \crmeb\services\JsonService
+     */
+    public function set_value($field = '', $id = '', $value = '')
+    {
+        if (empty($field) || empty($id) || $value === '') return JsonService::fail('缺少参数');
+
+        $allowFields = ['grade', 'discount', 'commission_rate'];
+        if (!in_array($field, $allowFields)) return JsonService::fail('不允许修改的字段');
+
+        if (SystemDealerLevel::where('id', $id)->update([$field => $value])) {
+            return JsonService::successful('保存成功');
+        } else {
+            return JsonService::fail('保存失败');
+        }
+    }
+
+    // ==================== 用户经销商管理 ====================
+
+    /**
+     * 用户经销商列表页面
+     * @return \think\response\View
+     */
+    public function user_dealer_list()
+    {
+        $dealerLevels = SystemDealerLevel::where('is_del', 0)
+            ->where('is_show', 1)
+            ->order('grade asc')
+            ->field('id, name')
+            ->select();
+        $this->assign('dealerLevels', $dealerLevels);
+        return $this->fetch();
+    }
+
+    /**
+     * 获取用户经销商列表(分页+关联用户信息)
+     * @return \crmeb\services\JsonService
+     */
+    public function get_user_dealer_list()
+    {
+        $where = UtilService::getMore([
+            ['page', 1],
+            ['limit', 10],
+            ['nickname', ''],
+            ['level_id', ''],
+        ]);
+
+        $result = UserDealer::getUserDealerList($where);
+
+        return JsonService::successlayui([
+            'count' => $result['count'],
+            'data' => $result['data'],
+        ]);
+    }
+
+    /**
+     * 赠送经销商等级表单
+     * @param int $uid 用户ID
+     * @return \think\response\View
+     */
+    public function give_dealer_level($uid = 0)
+    {
+        if (!$uid) return $this->failed('缺少参数');
+
+        $dealerLevels = SystemDealerLevel::where('is_del', 0)
+            ->where('is_show', 1)
+            ->order('grade asc')
+            ->field('id, name')
+            ->select();
+
+        if ($dealerLevels->isEmpty()) {
+            return $this->failed('暂无经销商等级,请先添加');
+        }
+
+        $field[] = Form::select('dealer_level_id', '经销商等级')->setOptions(function () use ($dealerLevels) {
+            $menus = [];
+            foreach ($dealerLevels as $menu) {
+                $menus[] = ['value' => $menu['id'], 'label' => $menu['name']];
+            }
+            return $menus;
+        })->filterable(1)->required('请选择经销商等级');
+
+        $form = Form::make_post_form('赠送经销商等级', $field, Url::buildUrl('save_give_dealer_level', ['uid' => $uid]), 2);
+        $this->assign(compact('form'));
+        return $this->fetch('public/form-builder');
+    }
+
+    /**
+     * 保存赠送经销商等级
+     * @param int $uid 用户ID
+     * @return \crmeb\services\JsonService
+     */
+    public function save_give_dealer_level($uid = 0)
+    {
+        if (!$uid) return JsonService::fail('缺少参数');
+        list($dealer_level_id) = UtilService::postMore([
+            ['dealer_level_id', 0],
+        ], $this->request, true);
+
+        $systemLevel = SystemDealerLevel::where(['is_show' => 1, 'is_del' => 0, 'id' => $dealer_level_id])->find();
+        if (!$systemLevel) return JsonService::fail('您选择的经销商等级不存在!');
+
+        // 检查是否已有该等级
+        $exist = UserDealer::where(['uid' => $uid, 'level_id' => $dealer_level_id, 'is_del' => 0])->find();
+        if ($exist) return JsonService::fail('此用户已有该经销商等级,请勿重复赠送');
+
+        UserDealer::startTrans();
+        try {
+            $res = UserDealer::create([
+                'uid' => $uid,
+                'level_id' => $dealer_level_id,
+                'grade' => $systemLevel->grade,
+                'status' => 1,
+                'is_del' => 0,
+                'add_time' => time(),
+                'spread_code' => '',
+                'mark' => '后台管理员于' . date('Y-m-d H:i:s') . '赠送【' . $systemLevel->name . '】经销商等级',
+            ]);
+
+            // 更新用户表中的经销商等级
+            $res = $res && User::where('uid', $uid)->update(['dealer' => $systemLevel->grade]);
+
+            if ($res) {
+                UserDealer::commit();
+                return JsonService::successful('赠送成功');
+            } else {
+                UserDealer::rollback();
+                return JsonService::fail('赠送失败');
+            }
+        } catch (\Exception $e) {
+            UserDealer::rollback();
+            return JsonService::fail('赠送失败:' . $e->getMessage());
+        }
+    }
+
+    /**
+     * 清除用户经销商等级
+     * @param int $uid 用户ID
+     * @return \crmeb\services\JsonService
+     */
+    public function del_dealer_level($uid = 0)
+    {
+        if (!$uid) return JsonService::fail('缺少参数');
+        if (UserDealer::cleanUpDealerLevel($uid))
+            return JsonService::successful('清除成功');
+        else
+            return JsonService::fail('清除失败');
+    }
+}

+ 46 - 0
app/admin/model/system/SystemDealerLevel.php

@@ -0,0 +1,46 @@
+<?php
+/**
+ * 经销商等级配置模型(对应表:system_dealer_level)
+ * 作用:管理经销商等级的基础配置(名称、折扣、佣金比例等)
+ */
+
+namespace app\admin\model\system;
+
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class SystemDealerLevel extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型关联的数据表名
+     * @var string
+     */
+    protected $name = 'system_dealer_level';
+
+    use ModelTrait;
+
+    /**
+     * add_time 字段修改器:新增时自动填充当前时间戳
+     * @return int
+     */
+    public static function setAddTimeAttr()
+    {
+        return time();
+    }
+
+    /**
+     * add_time 字段获取器:时间戳转格式化时间
+     * @param int $value 时间戳
+     * @return string 格式化时间(Y-m-d H:i:s)
+     */
+    public static function getAddTimeAttr($value)
+    {
+        return $value ? date('Y-m-d H:i:s', $value) : '';
+    }
+}

+ 110 - 0
app/admin/model/user/UserDealer.php

@@ -0,0 +1,110 @@
+<?php
+/**
+ * 用户经销商关联模型(对应表:user_dealer)
+ * 作用:管理用户与经销商等级的关联数据查询、等级操作等
+ */
+
+namespace app\admin\model\user;
+
+use app\admin\model\system\SystemDealerLevel;
+use app\admin\model\user\User;
+use crmeb\traits\ModelTrait;
+use crmeb\basic\BaseModel;
+
+class UserDealer extends BaseModel
+{
+    /**
+     * 数据表主键
+     * @var string
+     */
+    protected $pk = 'id';
+
+    /**
+     * 模型关联的数据表名
+     * @var string
+     */
+    protected $name = 'user_dealer';
+
+    use ModelTrait;
+
+    /**
+     * add_time 字段获取器:时间戳转格式化时间
+     * @param int $value 时间戳
+     * @return string 格式化时间
+     */
+    public static function getAddTimeAttr($value)
+    {
+        return $value ? date('Y-m-d H:i:s', $value) : '';
+    }
+
+    /**
+     * 查询用户经销商列表(带分页、关联用户信息)
+     * @param array $where 分页及筛选条件
+     * @return array
+     */
+    public static function getUserDealerList($where)
+    {
+        $query = self::alias('ud')
+            ->join('eb_user u', 'ud.uid = u.uid')
+            ->where('ud.is_del', 0)
+            ->when(isset($where['nickname']) && $where['nickname'], function ($query) use ($where) {
+                $query->where('u.nickname', 'like', "%{$where['nickname']}%");
+            })
+            ->when(isset($where['level_id']) && $where['level_id'] !== '', function ($query) use ($where) {
+                $query->where('ud.level_id', $where['level_id']);
+            })
+            ->field('ud.*, u.nickname, u.avatar')
+            ->order('ud.add_time desc');
+
+        $data = $query->page((int)$where['page'], (int)$where['limit'])->select();
+        $data = $data ? $data->toArray() : [];
+
+        // 补充经销商等级名称
+        foreach ($data as &$item) {
+            $levelInfo = SystemDealerLevel::where('id', $item['level_id'])->find();
+            if ($levelInfo) {
+                $item['level_name'] = $levelInfo['name'];
+            } else {
+                $item['level_name'] = '未知';
+            }
+        }
+
+        $count = self::alias('ud')
+            ->join('eb_user u', 'ud.uid = u.uid')
+            ->where('ud.is_del', 0)
+            ->when(isset($where['nickname']) && $where['nickname'], function ($query) use ($where) {
+                $query->where('u.nickname', 'like', "%{$where['nickname']}%");
+            })
+            ->when(isset($where['level_id']) && $where['level_id'] !== '', function ($query) use ($where) {
+                $query->where('ud.level_id', $where['level_id']);
+            })
+            ->count();
+
+        return compact('data', 'count');
+    }
+
+    /**
+     * 清除用户经销商等级(软删除 + 更新用户表标识)
+     * @param int $uid 用户ID
+     * @return bool
+     */
+    public static function cleanUpDealerLevel($uid)
+    {
+        self::startTrans();
+        try {
+            $delRes = self::where('uid', $uid)->update(['is_del' => 1]);
+
+            if ($delRes !== false) {
+                User::where('uid', $uid)->update(['dealer' => 0]);
+                self::commit();
+                return true;
+            } else {
+                self::rollback();
+                return false;
+            }
+        } catch (\Exception $e) {
+            self::rollback();
+            return false;
+        }
+    }
+}

+ 208 - 0
app/admin/view/user/user_dealer_level/index.php

@@ -0,0 +1,208 @@
+{extend name="public/container"}
+{block name="content"}
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15"  id="app">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">搜索条件</div>
+                <div class="layui-card-body">
+                    <form class="layui-form layui-form-pane" action="">
+                        <div class="layui-form-item">
+                            <div class="layui-inline">
+                                <label class="layui-form-label">是否显示</label>
+                                <div class="layui-input-block">
+                                    <select name="is_show">
+                                        <option value="">是否显示</option>
+                                        <option value="1">显示</option>
+                                        <option value="0">不显示</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <label class="layui-form-label">等级名称</label>
+                                <div class="layui-input-block">
+                                    <input type="text" name="name" class="layui-input" placeholder="请输入经销商等级名称">
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <div class="layui-input-inline">
+                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
+                                        <i class="layui-icon layui-icon-search"></i>搜索</button>
+                                </div>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        <!-- 经销商等级列表 -->
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">经销商等级列表</div>
+                <div class="layui-card-body">
+                    <div class="layui-btn-container">
+                        <button class="layui-btn layui-btn-sm" onclick="$eb.createModalFrame(this.innerText,'{:Url(\'create\')}')">添加经销商等级</button>
+                        <button class="layui-btn layui-btn-sm layui-btn-warm" onclick="$eb.createModalFrame(this.innerText,'{:Url(\'user_dealer_list\')}')">用户经销商列表</button>
+                    </div>
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+                    <script type="text/html" id="icon">
+                        {{# if(d.icon){ }}
+                        <img style="cursor: pointer;max-width: 50px;" lay-event='open_image' src="{{d.icon}}">
+                        {{# } else { }}
+                        <span>-</span>
+                        {{# } }}
+                    </script>
+                    <script type="text/html" id="can_see_special">
+                        {{# if(d.can_see_special == 1){ }}
+                        <span class="layui-badge layui-bg-green">可见</span>
+                        {{# } else { }}
+                        <span class="layui-badge">不可见</span>
+                        {{# } }}
+                    </script>
+                    <script type="text/html" id="is_show">
+                        <input type='checkbox' name='id' lay-skin='switch' value="{{d.id}}" lay-filter='is_show' lay-text='开启|关闭'  {{ d.is_show == 1 ? 'checked' : '' }}>
+                    </script>
+                    <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span class="caret"></span></button>
+                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
+                            <li>
+                                <a href="javascript:void(0)" onclick="$eb.createModalFrame(this.innerText,'{:Url(\'create\')}?id={{d.id}}')">
+                                    <i class="fa fa-edit"></i> 编辑等级
+                                </a>
+                            </li>
+                            <li>
+                                <a lay-event='delete' href="javascript:void(0)" >
+                                    <i class="fa fa-times"></i> 删除等级
+                                </a>
+                            </li>
+                        </ul>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    // 实例化form
+    layList.form.render();
+    // 加载列表
+    layList.tableList('List',"{:Url('get_list')}",function (){
+        return [
+            {field: 'id', title: '编号', sort: true, event:'id', width:'6%', align:"center"},
+            {field: 'icon', title: '等级图标', templet:'#icon', align:"center", width:'8%'},
+            {field: 'name', title: '等级名称', edit:'name', width:'10%', align:"center"},
+            {field: 'grade', title: '等级排序', edit:'grade', width:'6%', align:"center"},
+            {field: 'discount', title: '进货折扣(%)', edit:'discount', width:'8%', align:"center"},
+            {field: 'commission_rate', title: '佣金比例(%)', edit:'commission_rate', width:'8%', align:"center"},
+            {field: 'can_see_special', title: '特供规格', templet:'#can_see_special', width:'8%', align:"center"},
+            {field: 'is_show', title: '是否显示', templet:'#is_show', width:'8%', align:"center"},
+            {field: 'add_time', title: '添加时间', align:"center", width:'12%'},
+            {field: 'right', title: '操作', align:'center', toolbar:'#act', width:'8%'},
+        ];
+    });
+    // 自定义方法:快速编辑字段
+    var action= {
+        set_value: function (field, id, value) {
+            layList.baseGet(layList.Url({
+                a: 'set_value',
+                q: {field: field, id: id, value: value}
+            }), function (res) {
+                layList.msg(res.msg);
+            });
+        },
+    }
+    // 搜索回调
+    layList.search('search',function(where){
+        layList.reload(where,true);
+    });
+    // 开关-显示状态
+    layList.switch('is_show',function (odj,value) {
+        if(odj.elem.checked==true){
+            layList.baseGet(layList.Url({a:'set_show',p:{is_show:1,id:value}}),function (res) {
+                layList.msg(res.msg);
+            });
+        }else{
+            layList.baseGet(layList.Url({a:'set_show',p:{is_show:0,id:value}}),function (res) {
+                layList.msg(res.msg);
+            });
+        }
+    });
+    // 快速编辑回调
+    layList.edit(function (obj) {
+        var id=obj.data.id,value=obj.value;
+        switch (obj.field) {
+            case 'name':
+                action.set_value('name',id,value);
+                break;
+            case 'grade':
+                action.set_value('grade',id,value);
+                break;
+            case 'discount':
+                action.set_value('discount',id,value);
+                break;
+            case 'commission_rate':
+                action.set_value('commission_rate',id,value);
+                break;
+        }
+    });
+    // 排序监听
+    layList.sort(['id','grade'],true);
+    // 行工具事件
+    layList.tool(function (event,data,obj) {
+        switch (event) {
+            case 'delete':
+                var url=layList.U({a:'delete',q:{id:data.id}});
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                        }else
+                            return Promise.reject(res.data.msg || '删除失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                })
+                break;
+            case 'open_image':
+                $eb.openImage(data.icon);
+                break;
+        }
+    })
+    // 下拉操作框-点击收起
+    $(document).click(function (e) {
+        $('.layui-nav-child').hide();
+    })
+    // 下拉操作框-位置计算
+    function dropdown(that){
+        var oEvent = arguments.callee.caller.arguments[0] || event;
+        oEvent.stopPropagation();
+        var offset = $(that).offset();
+        var top=offset.top-$(window).scrollTop();
+        var index = $(that).parents('tr').data('index');
+        $('.layui-nav-child').each(function (key) {
+            if (key != index) {
+                $(this).hide();
+            }
+        })
+        if($(document).height() < top+$(that).next('ul').height()){
+            $(that).next('ul').css({
+                'padding': 10,
+                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }else{
+            $(that).next('ul').css({
+                'padding': 10,
+                'top':$(that).parent('td').height() / 2 + $(that).height(),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }
+    }
+</script>
+{/block}

+ 138 - 0
app/admin/view/user/user_dealer_level/user_dealer_list.php

@@ -0,0 +1,138 @@
+{extend name="public/container"}
+{block name="content"}
+<div class="layui-fluid">
+    <div class="layui-row layui-col-space15"  id="app">
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">搜索条件</div>
+                <div class="layui-card-body">
+                    <form class="layui-form layui-form-pane" action="">
+                        <div class="layui-form-item">
+                            <div class="layui-inline">
+                                <label class="layui-form-label">用户昵称</label>
+                                <div class="layui-input-block">
+                                    <input type="text" name="nickname" class="layui-input" placeholder="请输入用户昵称">
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <label class="layui-form-label">经销商等级</label>
+                                <div class="layui-input-block">
+                                    <select name="level_id">
+                                        <option value="">全部等级</option>
+                                        {volist name="dealerLevels" id="level"}
+                                        <option value="{$level.id}">{$level.name}</option>
+                                        {/volist}
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="layui-inline">
+                                <div class="layui-input-inline">
+                                    <button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="search" lay-filter="search">
+                                        <i class="layui-icon layui-icon-search"></i>搜索</button>
+                                </div>
+                            </div>
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+        <!-- 用户经销商列表 -->
+        <div class="layui-col-md12">
+            <div class="layui-card">
+                <div class="layui-card-header">用户经销商列表</div>
+                <div class="layui-card-body">
+                    <table class="layui-hide" id="List" lay-filter="List"></table>
+                    <script type="text/html" id="act">
+                        <button type="button" class="layui-btn layui-btn-xs" onclick="dropdown(this)">操作 <span class="caret"></span></button>
+                        <ul class="layui-nav-child layui-anim layui-anim-upbit">
+                            <li>
+                                <a lay-event='del_dealer' href="javascript:void(0)" >
+                                    <i class="fa fa-times"></i> 清除经销商等级
+                                </a>
+                            </li>
+                        </ul>
+                    </script>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<script src="{__ADMIN_PATH}js/layuiList.js"></script>
+{/block}
+{block name="script"}
+<script>
+    // 实例化form
+    layList.form.render();
+    // 加载列表
+    layList.tableList('List',"{:Url('get_user_dealer_list')}",function (){
+        return [
+            {field: 'id', title: '编号', sort: true, event:'id', width:'6%', align:"center"},
+            {field: 'uid', title: '用户ID', width:'8%', align:"center"},
+            {field: 'nickname', title: '用户昵称', width:'12%', align:"center"},
+            {field: 'level_name', title: '经销商等级', width:'10%', align:"center"},
+            {field: 'grade', title: '等级排序', width:'8%', align:"center"},
+            {field: 'add_time', title: '成为经销商时间', align:"center", width:'14%'},
+            {field: 'mark', title: '备注', align:"center"},
+            {field: 'right', title: '操作', align:'center', toolbar:'#act', width:'10%'},
+        ];
+    });
+    // 搜索回调
+    layList.search('search',function(where){
+        layList.reload(where,true);
+    });
+    // 行工具事件
+    layList.tool(function (event,data,obj) {
+        switch (event) {
+            case 'del_dealer':
+                var url=layList.U({a:'del_dealer_level',q:{uid:data.uid}});
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            obj.del();
+                        }else
+                            return Promise.reject(res.data.msg || '清除失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },{
+                    title: '确认清除',
+                    text: '确定要清除该用户的经销商等级吗?',
+                })
+                break;
+        }
+    })
+    // 下拉操作框-点击收起
+    $(document).click(function (e) {
+        $('.layui-nav-child').hide();
+    })
+    // 下拉操作框-位置计算
+    function dropdown(that){
+        var oEvent = arguments.callee.caller.arguments[0] || event;
+        oEvent.stopPropagation();
+        var offset = $(that).offset();
+        var top=offset.top-$(window).scrollTop();
+        var index = $(that).parents('tr').data('index');
+        $('.layui-nav-child').each(function (key) {
+            if (key != index) {
+                $(this).hide();
+            }
+        })
+        if($(document).height() < top+$(that).next('ul').height()){
+            $(that).next('ul').css({
+                'padding': 10,
+                'top': - ($(that).parent('td').height() / 2 + $(that).height() + $(that).next('ul').height()/2),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }else{
+            $(that).next('ul').css({
+                'padding': 10,
+                'top':$(that).parent('td').height() / 2 + $(that).height(),
+                'min-width': 'inherit',
+                'position': 'absolute'
+            }).toggle();
+        }
+    }
+</script>
+{/block}