Browse Source

fix:分销商我的团队

super-yimizi 1 day ago
parent
commit
14dbee52e5

+ 320 - 290
application/admin/controller/commission/Agent.php

@@ -1,290 +1,320 @@
-<?php
-
-namespace app\admin\controller\commission;
-
-use app\common\controller\Backend;
-use app\common\model\commission\Agent as AgentModel;
-use app\common\model\User as UserModel;
-use app\common\model\commission\Log as LogModel;
-use app\common\model\commission\Level as LevelModel;
-use app\common\Service\Commission\Agent as AgentService;
-use think\Db;
-
-class Agent extends Backend
-{
-    protected $noNeedRight = ['select'];
-
-    protected $model = null;
-    
-    /**
-     * 快速搜索时执行查找的字段
-     */
-    protected $searchFields = 'user_id,user.nickname,user.mobile';
-    
-    /**
-     * 是否是关联查询
-     */
-    protected $relationSearch = true;
-
-    public function _initialize()
-    {
-        parent::_initialize();
-        $this->model = new AgentModel();
-    }
-
-    /**
-     * 查看
-     */
-    public function index()
-    {
-        if (!$this->request->isAjax()) {
-            return $this->view->fetch();
-        }
-
-        //如果发送的来源是 Selectpage,则转发到 Selectpage
-        if ($this->request->request('keyField')) {
-            return $this->selectpage();
-        }
-        
-        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        
-        // 处理特殊筛选条件
-        $filter = $this->request->get("filter", '');
-        if ($filter) {
-            $filter = json_decode($filter, true);
-            if (isset($filter['tabActive'])) {
-                if ($filter['tabActive'] === 'pending') {
-                    $where['status'] = 'pending';
-                } elseif ($filter['tabActive'] === '0') {
-                    $where['level_status'] = ['>', 0];
-                }
-            }
-        }
-        
-        $list = $this->model
-            ->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])
-            ->where($where)
-            ->order($sort, $order)
-            ->paginate($limit);
-        
-        $result = ['total' => $list->total(), 'rows' => $list->items()];
-        return json($result);
-    }
-
-    /**
-     * 详情
-     *
-     * @param  $id
-     */
-    public function detail($ids = null)
-    {
-    
-        $row = $this->model->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])
-        ->where('user_id', $ids)
-        ->find();
-        if (!$row) {
-            $this->error(__('No Results were found'));
-        }       
-        $this->view->assign('row', $row);
-        return $this->view->fetch();
-    }
-
-
-    /**
-     * 团队
-     *
-     * @param  $id
-     */
-    public function team($ids = null)
-    {
-        if (!$this->request->isAjax()) {
-            return $this->view->fetch();
-        }
-
-        $detail = $this->model->with(['user.parent_user', 'level_info'])->where('user_id', $ids)->find();
-        if (!$detail) {
-            $this->error(__('No Results were found'));
-        }
-        
-        $detail->agent_team = AgentModel::hasWhere('user', function ($query) use ($detail) {
-            return $query->where('parent_user_id', $detail->user_id);
-        })->with(['user', 'level_info'])->select();
-        $this->success('分销商详情', null, $detail);
-    }
-
-    // 选择分销商
-    public function select()
-    {
-        if (!$this->request->isAjax()) {
-            return $this->view->fetch();
-        }
-
-        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
-        
-        $data = $this->model
-            ->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])
-            ->where($where)
-            ->order($sort, $order)
-            ->paginate($limit);
-        
-        $result = ['total' => $data->total(), 'rows' => $data->items()];
-        return json($result);
-    }
-
-    /**
-     * 编辑
-     *
-     * @param  $id
-     */
-    public function edit($id = null)
-    {
-        $params = $this->request->only(['status', 'upgrade_lock', 'level_status', 'level']);
-
-        $result = Db::transaction(function () use ($id, $params) {
-            $row = $this->model->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])->where('user_id', $id)->find();
-            if (!$row) {
-                $this->error('未找到该分销商');
-            }
-
-            foreach ($params as $field => $value) {
-                switch ($field) {
-                    case 'status':  // 修改状态
-                        return $this->changeStatus($row, $value);
-                        break;
-                    case 'level_status':    // 审核等级
-                        return $this->changeLevelStatus($row, $value);
-                        break;
-                    case 'level':           // 修改等级
-                        return $this->changeLevel($row, $value);
-                        break;
-                    default:
-                        return $row->save([$field => $value]);
-                }
-            }
-        });
-        if ($result) {
-            $this->success('更新成功', null, $result);
-        } else {
-            $this->error('更新失败');
-        }
-    }
-
-
-    // 修改状态
-    private function changeStatus($row, $value)
-    {
-        $result = $row->save(['status' => $value]);
-        if ($result) {
-            LogModel::add($row->user_id, 'agent', ['type' => 'status', 'value' => $value]);
-            (new AgentService($row->user_id))->createAsyncAgentUpgrade();
-        }
-        return $result;
-    }
-
-    // 审核等级
-    private function changeLevelStatus($row, $value)
-    {
-        if ($row->level_status == 0 && $value > 0) {
-            $this->error('非法操作');
-        }
-
-        if ($value == 0) {  // 拒绝操作
-            return $row->save(['level_status' => 0]);
-        } else {            // 同意操作
-            if ($row->upgrade_level) {
-                $result = $row->save(['level_status' => 0, 'level' => $row->upgrade_level->level]);
-                if ($result) {
-                    LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $row->upgrade_level]);
-                    (new AgentService($row->user_id))->createAsyncAgentUpgrade();
-                }
-                return $result;
-            }
-        }
-        return false;
-    }
-
-    // 修改等级
-    private function changeLevel($row, $value)
-    {
-        $level = LevelModel::find($value);
-        if ($level) {
-            $result = $row->save(['level' => $level->level]);
-            if ($result) {
-                LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $level]);
-                (new AgentService($row->user_id))->createAsyncAgentUpgrade();
-            }
-            return $result;
-        } else {
-            $this->error('未找到该等级');
-        }
-    }
-
-    // 更换推荐人
-    public function changeParentUser($id)
-    {
-        $userAgent = new AgentService($id);
-
-        if (!$userAgent->user) {
-            $this->error('未找到该用户');
-        }
-
-        $parentUserId = $this->request->param('parent_user_id', 0);
-
-        // 更换推荐人检查
-        if ($parentUserId != 0) {
-            $parentAgent = new AgentService($parentUserId);
-            if (!$parentAgent->isAgentAvaliable()) {
-                $this->error('选中用户暂未成为分销商,不能成为推荐人');
-            }
-            if (!$this->checkChangeParentAgent($id, $parentUserId)) {
-                $this->error('不能绑定该上级');
-            }
-            LogModel::add($parentUserId, 'share', ['user' => $userAgent->user]);
-
-            if ($userAgent->isAgentAvaliable()) {
-                LogModel::add($id, 'bind', ['user' => $parentAgent->user ?? NULL]);
-            }
-        }
-
-        $lastParentUserId = $userAgent->user->parent_user_id;
-
-        $userAgent->user->parent_user_id = $parentUserId;
-        $userAgent->user->save();
-
-        if ($lastParentUserId > 0) {
-            $userAgent->createAsyncAgentUpgrade($lastParentUserId);
-        }
-
-        if ($parentUserId > 0) {
-            $userAgent->createAsyncAgentUpgrade($parentUserId);
-        }
-        $this->success('绑定成功');
-    }
-
-    // 递归往上找推荐人,防止出现推荐循环
-    private function checkChangeParentAgent($userId, $parentUserId)
-    {
-        if ($userId == $parentUserId) {
-
-            $this->error('推荐人不能是本人');
-        }
-        if ($parentUserId == 0) {
-            return true;
-        }
-
-        $parentAgent = UserModel::find($parentUserId);
-
-        if ($parentAgent) {
-            if ($parentAgent->parent_user_id == $userId) {
-                $this->error("已选中分销商的上级团队中已存在该用户");
-            }
-            if ($parentAgent->parent_user_id == 0) {
-                return true;
-            } else {
-                return $this->checkChangeParentAgent($userId, $parentAgent->parent_user_id);
-            }
-        }
-
-        return false;
-    }
-}
+<?php
+
+namespace app\admin\controller\commission;
+
+use app\common\controller\Backend;
+use app\common\model\commission\Agent as AgentModel;
+use app\common\model\User as UserModel;
+use app\common\model\commission\Log as LogModel;
+use app\common\model\commission\Level as LevelModel;
+use app\common\Service\Commission\Agent as AgentService;
+use EasyWeChat\OfficialAccount\Server\Handlers\EchoStrHandler;
+use think\Db;
+
+class Agent extends Backend
+{
+    protected $noNeedRight = ['select'];
+
+    protected $model = null;
+    
+    /**
+     * 快速搜索时执行查找的字段
+     */
+    protected $searchFields = 'user_id,user.nickname,user.mobile';
+    
+    /**
+     * 是否是关联查询
+     */
+    protected $relationSearch = true;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new AgentModel();
+    }
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        if (!$this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+
+        //如果发送的来源是 Selectpage,则转发到 Selectpage
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+        
+        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
+        
+        // 处理特殊筛选条件
+        $filter = $this->request->get("filter", '');
+        if ($filter) {
+            $filter = json_decode($filter, true);
+            if (isset($filter['tabActive'])) {
+                if ($filter['tabActive'] === 'pending') {
+                    $where['status'] = 'pending';
+                } elseif ($filter['tabActive'] === '0') {
+                    $where['level_status'] = ['>', 0];
+                }
+            }
+        }
+        
+        $list = $this->model
+            ->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])
+            ->where($where)
+            ->order($sort, $order)
+            ->paginate($limit);
+        
+        $result = ['total' => $list->total(), 'rows' => $list->items()];
+        return json($result);
+    }
+
+    /**
+     * 详情
+     *
+     * @param  $id
+     */
+    public function detail($ids = null)
+    {
+    
+        $row = $this->model->with(['user.parent_user', 'level_info', 'level_status_info', 'upgrade_level'])
+        ->where('user_id', $ids)
+        ->find();
+        if (!$row) {
+            $this->error(__('No Results were found'));
+        }       
+        $this->view->assign('row', $row);
+        return $this->view->fetch();
+    }
+
+
+    /**
+     * 团队
+     *
+     * @param  $id
+     */
+    public function team($ids = null)
+    {
+        // 获取ID参数,优先使用URL中的id参数
+        $ids = $ids ?: $this->request->param('id');
+        
+        // 将当前分销商ID传递给前端
+        $this->assignconfig('current_agent_id', $ids);
+        
+        if (!$this->request->isAjax()) {
+            // 获取当前分销商详细信息用于模板渲染
+            $currentAgent = $this->model->with(['user.parent_user', 'level_info'])
+                ->where('user_id', $ids)
+                ->find();
+            
+            if (!$currentAgent) {
+                $this->error(__('No Results were found'));
+            }
+            
+            $this->view->assign('currentAgent', $currentAgent);
+            return $this->view->fetch();
+        }
+
+        //如果发送的来源是 Selectpage,则转发到 Selectpage
+        if ($this->request->request('keyField')) {
+            return $this->selectpage();
+        }
+
+        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
+
+        // 以分销商表为主表查询团队成员
+        // 安全的排序字段处理
+        // $allowedSorts = ['user_id', 'status', 'level', 'total_income', 'pending_reward', 'become_time'];
+        // $safeSort = in_array($sort, $allowedSorts) ? $sort : 'user_id';
+        
+        $list = $this->model
+            ->hasWhere('user', function ($query) use ($ids) {
+                return $query->where('parent_user_id', $ids);
+            })
+            ->with(['user', 'level_info'])
+            // ->order($safeSort, $order ?: 'desc')
+            ->paginate($limit);
+
+        $result = array("total" => $list->total(), "rows" => $list->items());
+        return json($result);
+    }
+
+    // 选择分销商
+    public function select()
+    {
+        if (!$this->request->isAjax()) {
+            return $this->view->fetch();
+        }
+
+        [$where, $sort, $order, $offset, $limit] = $this->buildparams();
+        
+        $data = $this->model
+            ->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])
+            ->where($where)
+            ->order($sort, $order)
+            ->paginate($limit);
+        
+        $result = ['total' => $data->total(), 'rows' => $data->items()];
+        return json($result);
+    }
+
+    /**
+     * 编辑
+     *
+     * @param  $id
+     */
+    public function edit($id = null)
+    {
+        $params = $this->request->only(['status', 'upgrade_lock', 'level_status', 'level']);
+
+        $result = Db::transaction(function () use ($id, $params) {
+            $row = $this->model->with(['user', 'level_info', 'level_status_info', 'upgrade_level'])->where('user_id', $id)->find();
+            if (!$row) {
+                $this->error('未找到该分销商');
+            }
+
+            foreach ($params as $field => $value) {
+                switch ($field) {
+                    case 'status':  // 修改状态
+                        return $this->changeStatus($row, $value);
+                        break;
+                    case 'level_status':    // 审核等级
+                        return $this->changeLevelStatus($row, $value);
+                        break;
+                    case 'level':           // 修改等级
+                        return $this->changeLevel($row, $value);
+                        break;
+                    default:
+                        return $row->save([$field => $value]);
+                }
+            }
+        });
+        if ($result) {
+            $this->success('更新成功', null, $result);
+        } else {
+            $this->error('更新失败');
+        }
+    }
+
+
+    // 修改状态
+    private function changeStatus($row, $value)
+    {
+        $result = $row->save(['status' => $value]);
+        if ($result) {
+            LogModel::add($row->user_id, 'agent', ['type' => 'status', 'value' => $value]);
+            (new AgentService($row->user_id))->createAsyncAgentUpgrade();
+        }
+        return $result;
+    }
+
+    // 审核等级
+    private function changeLevelStatus($row, $value)
+    {
+        if ($row->level_status == 0 && $value > 0) {
+            $this->error('非法操作');
+        }
+
+        if ($value == 0) {  // 拒绝操作
+            return $row->save(['level_status' => 0]);
+        } else {            // 同意操作
+            if ($row->upgrade_level) {
+                $result = $row->save(['level_status' => 0, 'level' => $row->upgrade_level->level]);
+                if ($result) {
+                    LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $row->upgrade_level]);
+                    (new AgentService($row->user_id))->createAsyncAgentUpgrade();
+                }
+                return $result;
+            }
+        }
+        return false;
+    }
+
+    // 修改等级
+    private function changeLevel($row, $value)
+    {
+        $level = LevelModel::find($value);
+        if ($level) {
+            $result = $row->save(['level' => $level->level]);
+            if ($result) {
+                LogModel::add($row->user_id, 'agent', ['type' => 'level', 'level' => $level]);
+                (new AgentService($row->user_id))->createAsyncAgentUpgrade();
+            }
+            return $result;
+        } else {
+            $this->error('未找到该等级');
+        }
+    }
+
+    // 更换推荐人
+    public function changeParentUser($id)
+    {
+        $userAgent = new AgentService($id);
+
+        if (!$userAgent->user) {
+            $this->error('未找到该用户');
+        }
+
+        $parentUserId = $this->request->param('parent_user_id', 0);
+
+        // 更换推荐人检查
+        if ($parentUserId != 0) {
+            $parentAgent = new AgentService($parentUserId);
+            if (!$parentAgent->isAgentAvaliable()) {
+                $this->error('选中用户暂未成为分销商,不能成为推荐人');
+            }
+            if (!$this->checkChangeParentAgent($id, $parentUserId)) {
+                $this->error('不能绑定该上级');
+            }
+            LogModel::add($parentUserId, 'share', ['user' => $userAgent->user]);
+
+            if ($userAgent->isAgentAvaliable()) {
+                LogModel::add($id, 'bind', ['user' => $parentAgent->user ?? NULL]);
+            }
+        }
+
+        $lastParentUserId = $userAgent->user->parent_user_id;
+
+        $userAgent->user->parent_user_id = $parentUserId;
+        $userAgent->user->save();
+
+        if ($lastParentUserId > 0) {
+            $userAgent->createAsyncAgentUpgrade($lastParentUserId);
+        }
+
+        if ($parentUserId > 0) {
+            $userAgent->createAsyncAgentUpgrade($parentUserId);
+        }
+        $this->success('绑定成功');
+    }
+
+    // 递归往上找推荐人,防止出现推荐循环
+    private function checkChangeParentAgent($userId, $parentUserId)
+    {
+        if ($userId == $parentUserId) {
+
+            $this->error('推荐人不能是本人');
+        }
+        if ($parentUserId == 0) {
+            return true;
+        }
+
+        $parentAgent = UserModel::find($parentUserId);
+
+        if ($parentAgent) {
+            if ($parentAgent->parent_user_id == $userId) {
+                $this->error("已选中分销商的上级团队中已存在该用户");
+            }
+            if ($parentAgent->parent_user_id == 0) {
+                return true;
+            } else {
+                return $this->checkChangeParentAgent($userId, $parentAgent->parent_user_id);
+            }
+        }
+
+        return false;
+    }
+}

+ 0 - 2
application/admin/controller/commission/Reward.php

@@ -31,8 +31,6 @@ class Reward extends Backend
     public function index()
     {
         if (!$this->request->isAjax()) {
-            $exportConfig = (new \addons\shopro\library\Export())->getConfig();
-            $this->assignconfig("save_type", $exportConfig['save_type'] ?? 'download');
             return $this->view->fetch();
         }
 

+ 87 - 158
application/admin/view/commission/agent/team.html

@@ -1,159 +1,88 @@
-{include file="/shopro/common/script" /}
-
-<div id="team" class="agent-team" v-cloak>
-    <el-container class="panel-block">
-        <el-header class="sa-header sa-flex sa-flex-wrap mt-4">
-            <template v-if="state.data.user?.parent_user">
-                推荐人:
-                <sa-user-profile class="cursor-pointer" type="agent" :user="state.data.user?.parent_user" :id="state.data.user?.parent_user_id"
-                    :isHover="false" @click="getTeam(state.data.user.parent_user_id)"></sa-user-profile>
-            </template>
-        </el-header>
-        <el-main>
-            <el-table class="sa-table mb-4" :data="[state.data]">
-                <el-table-column prop="user_id" label="ID" min-width="90"></el-table-column>
-                <el-table-column label="当前用户" min-width="150">
-                    <template #default="scope">
-                        <sa-user-profile :user="scope.row.user" :id="scope.row.user_id" :isHover="false">
-                        </sa-user-profile>
-                    </template>
-                </el-table-column>
-                <el-table-column label="等级" min-width="150">
-                    <template #default="scope">
-                        <div v-if="scope.row.level_info" class="sa-flex">
-                            <sa-image :url="scope.row.level_info.image" size="32"></sa-image>
-                            <span class="ml-2">{{ scope.row.level_info.name }}</span>
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+    
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <!-- 当前用户信息 -->
+                <div class="row" style="margin-bottom: 20px;">
+                    <div class="col-xs-12">
+                        <div class="panel panel-info">
+                            <div class="panel-heading">
+                                <h4 class="panel-title">当前分销商信息</h4>
+                            </div>
+                            <div class="panel-body">
+                                <table class="table table-bordered table-hover" id="current-agent-table">
+                                    <thead>
+                                        <tr>
+                                            <th>ID</th>
+                                            <th>用户信息</th>
+                                            <th>等级</th>
+                                            <th>状态</th>
+                                            <th>团队人数</th>
+                                            <th>直推分销商</th>
+                                            <th>团队分销商</th>
+                                            <th>累计佣金</th>
+                                            <th>待结算佣金</th>
+                                            <th>加入时间</th>
+                                        </tr>
+                                    </thead>
+                                    <tbody id="current-agent-info">
+                                        <tr>
+                                            <td>{$currentAgent.user_id}</td>
+                                            <td>
+                                                {if condition="$currentAgent.user"}
+                                                <div style="display:flex;align-items:center;">
+                                                    <img src="{$currentAgent.user.avatar|default='/assets/img/avatar.png'}" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />
+                                                    <div>
+                                                        <div style="font-weight:bold;">{$currentAgent.user.nickname|default=$currentAgent.user_id}</div>
+                                                        <div style="font-size:12px;color:#666;">{$currentAgent.user.mobile|default=''}</div>
+                                                    </div>
+                                                </div>
+                                                {else /}
+                                                {$currentAgent.user_id}
+                                                {/if}
+                                            </td>
+                                            <td>
+                                                {if condition="$currentAgent.level_info"}
+                                                {$currentAgent.level_info.name}<br><small>等级{$currentAgent.level_info.level}</small>
+                                                {else /}
+                                                等级{$currentAgent.level|default='-'}
+                                                {/if}
+                                            </td>
+                                            <td>
+                                                {switch name="$currentAgent.status"}
+                                                    {case value="normal"}<span class="label label-success">正常</span>{/case}
+                                                    {case value="pending"}<span class="label label-warning">审核中</span>{/case}
+                                                    {case value="freeze"}<span class="label label-info">冻结</span>{/case}
+                                                    {case value="forbidden"}<span class="label label-danger">禁用</span>{/case}
+                                                    {case value="reject"}<span class="label label-danger">拒绝</span>{/case}
+                                                    {default /}<span class="label label-default">{$currentAgent.status}</span>
+                                                {/switch}
+                                            </td>
+                                            <td>{$currentAgent.child_user_count_all|default=0}人</td>
+                                            <td>{$currentAgent.child_agent_count_1|default=0}人</td>
+                                            <td>{$currentAgent.child_agent_count_all|default=0}人</td>
+                                            <td>{$currentAgent.total_income|default=0}元</td>
+                                            <td>{$currentAgent.pending_reward|default=0}元</td>
+                                            <td>{$currentAgent.become_time|default=$currentAgent.createtime|default='-'}</td>
+                                        </tr>
+                                    </tbody>
+                                </table>
+                            </div>
                         </div>
-                        <template v-else>{{ scope.row.level }}</template>
-                    </template>
-                </el-table-column>
-                <el-table-column label="状态" min-width="120" align="center">
-                    <template #default="scope">
-                        <span :style="{ color: statusStyle[scope.row.status]?.color }">
-                            {{ scope.row.status_text }}
-                        </span>
-                    </template>
-                </el-table-column>
-                <el-table-column label="团队人数/分销商人数" min-width="160" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_all }}人/ {{ scope.row.child_agent_count_all }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="一级团队人数/一级分销商人数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_1 }}人/ {{ scope.row.child_agent_count_1 }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="二级团队人数/二级分销商人数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_2 }}人/ {{ scope.row.child_agent_count_2 }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="团队分销总额/团队分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_all }}元/ {{ scope.row.child_order_count_all }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="一级分销总额/一级分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_1 }}元/ {{ scope.row.child_order_count_1 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="二级分销总额/二级分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_2 }}元/ {{ scope.row.child_order_count_2 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="自购分销总金额/订单数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_0 }}元/ {{ scope.row.child_order_count_0 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="累计佣金" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.total_income }}元 </template>
-                </el-table-column>
-                <el-table-column label="消费金额" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.user?.total_consume || 0 }}元 </template>
-                </el-table-column>
-                <el-table-column label="待入账佣金" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.pending_reward }}元 </template>
-                </el-table-column>
-                <el-table-column label="加入时间" min-width="172" align="center">
-                    <template #default="scope"> {{ scope.row.createtime }} </template>
-                </el-table-column>
-            </el-table>
-            <el-table class="sa-table" :data="state.data.agent_team">
-                <el-table-column prop="user_id" label="ID" min-width="90"></el-table-column>
-                <el-table-column label="团队用户" min-width="150">
-                    <template #default="scope">
-                        <sa-user-profile class="cursor-pointer" :user="scope.row.user" :id="scope.row.user_id" :isHover="false" @click="getTeam(scope.row.user_id)">
-                        </sa-user-profile>
-                    </template>
-                </el-table-column>
-                <el-table-column label="等级" min-width="150">
-                    <template #default="scope">
-                        <div v-if="scope.row.level_info" class="sa-flex">
-                            <sa-image :url="scope.row.level_info.image" size="32"></sa-image>
-                            <span class="ml-2">{{ scope.row.level_info.name }}</span>
-                        </div>
-                        <template v-else>{{ scope.row.level }}</template>
-                    </template>
-                </el-table-column>
-                <el-table-column label="状态" min-width="120" align="center">
-                    <template #default="scope">
-                        <span :style="{ color: statusStyle[scope.row.status]?.color }">
-                            {{ scope.row.status_text }}
-                        </span>
-                    </template>
-                </el-table-column>
-                <el-table-column label="团队人数/分销商人数" min-width="160" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_all }}人/ {{ scope.row.child_agent_count_all }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="一级团队人数/一级分销商人数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_1 }}人/ {{ scope.row.child_agent_count_1 }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="二级团队人数/二级分销商人数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_user_count_2 }}人/ {{ scope.row.child_agent_count_2 }}人
-                    </template>
-                </el-table-column>
-                <el-table-column label="团队分销总额/团队分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_all }}元/ {{ scope.row.child_order_count_all }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="一级分销总额/一级分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_1 }}元/ {{ scope.row.child_order_count_1 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="二级分销总额/二级分销订单" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_2 }}元/ {{ scope.row.child_order_count_2 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="自购分销总金额/订单数" min-width="220" align="center">
-                    <template #default="scope">
-                        {{ scope.row.child_order_money_0 }}元/ {{ scope.row.child_order_count_0 }}单
-                    </template>
-                </el-table-column>
-                <el-table-column label="累计佣金" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.total_income }}元 </template>
-                </el-table-column>
-                <el-table-column label="消费金额" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.user?.total_consume || 0 }}元 </template>
-                </el-table-column>
-                <el-table-column label="待入账佣金" min-width="160" align="center">
-                    <template #default="scope"> {{ scope.row.pending_reward }}元 </template>
-                </el-table-column>
-                <el-table-column label="加入时间" min-width="172" align="center">
-                    <template #default="scope"> {{ scope.row.createtime }} </template>
-                </el-table-column>
-            </el-table>
-        </el-main>
-    </el-container>
-</div>
+                    </div>
+                </div>
+                
+                <!-- 团队成员列表 -->
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap" width="100%">
+                    </table>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>

+ 92 - 7
public/assets/js/backend/commission/agent.js

@@ -527,14 +527,99 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             });
         },
         team: function () {
-            // 团队页面特有的全局函数
-            window.viewTeam = function(userId) {
-                Fast.api.open('commission/agent/team?id=' + userId, '查看团队');
-            };
+            // 优先从Config中获取ID,否则从URL参数获取
+            var agentId = Config.current_agent_id || Fast.api.query('id');
+            console.log('agentId:', agentId);
+        
+            // 初始化表格参数
+            Table.api.init({
+                extend: {
+                    index_url: 'commission/agent/team?id=' + agentId,
+                    add_url: '',
+                    edit_url: '',
+                    del_url: '',
+                    multi_url: '',
+                    import_url: '',
+                    table: 'commission_agent',
+                }
+            });
 
-            window.viewDetail = function(userId) {
-                Fast.api.open('commission/agent/detail?id=' + userId, '分销商详情');
-            };
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'user_id',
+                sortName: 'user_id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'user_id', title: __('ID'), width: 60},
+                        {field: 'user.nickname', title: __('团队成员'), operate: 'LIKE', formatter: function(value, row, index) {
+                            if (row.user) {
+                                var avatarUrl = row.user.avatar || '/assets/img/avatar.png';
+                                var html = '<div style="display:flex;align-items:center;">';
+                                html += '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />';
+                                html += '<div>';
+                                html += '<div style="color:#337ab7;font-weight:bold;">' + (row.user.nickname || row.user_id) + '</div>';
+                                html += '<div style="color:#6c757d;font-size:12px;">' + (row.user.mobile || '') + '</div>';
+                                html += '</div></div>';
+                                return html;
+                            }
+                            return row.user_id;
+                        }},
+                        {field: 'level_info.name', title: __('分销等级'), formatter: function(value, row, index) {
+                            if (row.level_info) {
+                                return row.level_info.name + '<br><small>等级' + row.level_info.level + '</small>';
+                            }
+                            return '等级' + (row.level || '-');
+                        }},
+                        {field: 'status', title: __('状态'), searchList: {
+                            "normal": __('正常'),
+                            "pending": __('审核中'),
+                            "freeze": __('冻结'),
+                            "forbidden": __('禁用'),
+                            "reject": __('拒绝')
+                        }, formatter: function(value, row, index) {
+                            var colorMap = {
+                                'normal': 'success',
+                                'pending': 'warning',
+                                'freeze': 'info',
+                                'forbidden': 'danger',
+                                'reject': 'danger'
+                            };
+                            var textMap = {
+                                'normal': '正常',
+                                'pending': '审核中',
+                                'freeze': '冻结',
+                                'forbidden': '禁用',
+                                'reject': '拒绝'
+                            };
+                            var color = colorMap[value] || 'default';
+                            var text = textMap[value] || value;
+                            return '<span class="label label-' + color + '">' + text + '</span>';
+                        }},
+                        {field: 'child_user_count_all', title: __('团队人数'), width: 80},
+                        {field: 'child_agent_count_1', title: __('直推分销商'), width: 80},
+                        {field: 'child_agent_count_all', title: __('团队分销商'), width: 80},
+                        {field: 'total_income', title: __('累计佣金'), operate: 'BETWEEN'},
+                        {field: 'pending_reward', title: __('待结算佣金'), width: 80},
+                        {field: 'become_time', title: __('成为分销商时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+
+            // // 团队页面特有的全局函数
+            // window.viewTeam = function(userId) {
+            //     Fast.api.open('commission/agent/team?id=' + userId, '查看团队');
+            // };
+
+            // window.viewDetail = function(userId) {
+            //     Fast.api.open('commission/agent/detail?id=' + userId, '分销商详情');
+            // };
 
             Controller.api.bindevent();
         },