Browse Source

fix:分销商

super-yimizi 20 hours ago
parent
commit
0106c1cbf8

+ 3 - 6
application/admin/controller/commission/Agent.php

@@ -136,12 +136,9 @@ class Agent extends Backend
         // $allowedSorts = ['user_id', 'status', 'level', 'total_income', 'pending_reward', 'become_time'];
         // $allowedSorts = ['user_id', 'status', 'level', 'total_income', 'pending_reward', 'become_time'];
         // $safeSort = in_array($sort, $allowedSorts) ? $sort : 'user_id';
         // $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')
+        // 以用户表为主表,LEFT JOIN 分销商表,这样普通用户也能查到
+        $list = \app\common\model\User::where('parent_user_id', $ids)
+            ->with(['agent', 'agent.level_info'])
             ->paginate($limit);
             ->paginate($limit);
 
 
         $result = array("total" => $list->total(), "rows" => $list->items());
         $result = array("total" => $list->total(), "rows" => $list->items());

+ 1 - 1
application/admin/view/commission/agent/detail.html

@@ -19,7 +19,7 @@
                     <div class="box-body">
                     <div class="box-body">
                         <div class="row">
                         <div class="row">
                             <div class="col-xs-12 text-center" style="margin-bottom: 15px;">
                             <div class="col-xs-12 text-center" style="margin-bottom: 15px;">
-                                <img src="{$row.user.avatar|default='/assets/img/avatar.png'}" 
+                                <img src="{$row.user.avatar|cdnurl}" 
                                      style="width: 80px; height: 80px; border-radius: 50%;" 
                                      style="width: 80px; height: 80px; border-radius: 50%;" 
                                      alt="用户头像">
                                      alt="用户头像">
                                 <h4 style="margin: 10px 0;">{$row.user.nickname|default='用户'.$row.user_id}</h4>
                                 <h4 style="margin: 10px 0;">{$row.user.nickname|default='用户'.$row.user_id}</h4>

+ 1 - 1
application/admin/view/commission/agent/team.html

@@ -33,7 +33,7 @@
                                             <td>
                                             <td>
                                                 {if condition="$currentAgent.user"}
                                                 {if condition="$currentAgent.user"}
                                                 <div style="display:flex;align-items:center;">
                                                 <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;" />
+                                                    <img src="{$currentAgent.user.avatar|cdnurl}" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />
                                                     <div>
                                                     <div>
                                                         <div style="font-weight:bold;">{$currentAgent.user.nickname|default=$currentAgent.user_id}</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 style="font-size:12px;color:#666;">{$currentAgent.user.mobile|default=''}</div>

+ 44 - 29
public/assets/js/backend/commission/agent.js

@@ -637,7 +637,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                     del_url: '',
                     del_url: '',
                     multi_url: '',
                     multi_url: '',
                     import_url: '',
                     import_url: '',
-                    table: 'commission_agent',
+                    table: 'user',
                 }
                 }
             });
             });
 
 
@@ -646,38 +646,41 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
             // 初始化表格
             // 初始化表格
             table.bootstrapTable({
             table.bootstrapTable({
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
                 url: $.fn.bootstrapTable.defaults.extend.index_url,
-                pk: 'user_id',
-                sortName: 'user_id',
+                pk: 'id',
+                sortName: 'id',
                 columns: [
                 columns: [
                     [
                     [
                         {checkbox: true},
                         {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: 'id', title: __('ID'), width: 60},
+                        {field: 'nickname', title: __('团队成员'), operate: 'LIKE', formatter: function(value, row, index) {
+                            var avatarUrl = row.avatar ? Fast.api.cdnurl(row.avatar) : Fast.api.cdnurl('/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.nickname || '用户' + row.id) + '</div>';
+                            html += '<div style="color:#6c757d;font-size:12px;">' + (row.mobile || '') + '</div>';
+                            html += '</div></div>';
+                            return html;
                         }},
                         }},
-                        {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>';
+                        {field: 'agent.level_info.name', title: __('分销等级'), formatter: function(value, row, index) {
+                            if (row.agent && row.agent.level_info) {
+                                return row.agent.level_info.name + '<br><small>等级' + row.agent.level_info.level + '</small>';
+                            } else if (row.agent) {
+                                return '等级' + (row.agent.level || '-');
                             }
                             }
-                            return '等级' + (row.level || '-');
+                            return '<span class="text-muted">非分销商</span>';
                         }},
                         }},
-                        {field: 'status', title: __('状态'), searchList: {
+                        {field: 'agent.status', title: __('状态'), searchList: {
                             "normal": __('正常'),
                             "normal": __('正常'),
                             "pending": __('审核中'),
                             "pending": __('审核中'),
                             "freeze": __('冻结'),
                             "freeze": __('冻结'),
                             "forbidden": __('禁用'),
                             "forbidden": __('禁用'),
                             "reject": __('拒绝')
                             "reject": __('拒绝')
                         }, formatter: function(value, row, index) {
                         }, formatter: function(value, row, index) {
+                            if (!row.agent) {
+                                return '<span class="label label-default">非分销商</span>';
+                            }
+                            var status = row.agent.status;
                             var colorMap = {
                             var colorMap = {
                                 'normal': 'success',
                                 'normal': 'success',
                                 'pending': 'warning',
                                 'pending': 'warning',
@@ -692,16 +695,28 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
                                 'forbidden': '禁用',
                                 'forbidden': '禁用',
                                 'reject': '拒绝'
                                 'reject': '拒绝'
                             };
                             };
-                            var color = colorMap[value] || 'default';
-                            var text = textMap[value] || value;
+                            var color = colorMap[status] || 'default';
+                            var text = textMap[status] || status;
                             return '<span class="label label-' + color + '">' + text + '</span>';
                             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}
+                        {field: 'agent.child_user_count_all', title: __('团队人数'), width: 80, formatter: function(value, row, index) {
+                            return row.agent ? (row.agent.child_user_count_all || 0) : 0;
+                        }},
+                        {field: 'agent.child_agent_count_1', title: __('直推分销商'), width: 80, formatter: function(value, row, index) {
+                            return row.agent ? (row.agent.child_agent_count_1 || 0) : 0;
+                        }},
+                        {field: 'agent.child_agent_count_all', title: __('团队分销商'), width: 80, formatter: function(value, row, index) {
+                            return row.agent ? (row.agent.child_agent_count_all || 0) : 0;
+                        }},
+                        {field: 'agent.total_income', title: __('累计佣金'), operate: 'BETWEEN', formatter: function(value, row, index) {
+                            return row.agent ? ((row.agent.total_income || 0) + '元') : '0元';
+                        }},
+                        {field: 'agent.pending_reward', title: __('待结算佣金'), width: 80, formatter: function(value, row, index) {
+                            return row.agent ? ((row.agent.pending_reward || 0) + '元') : '0元';
+                        }},
+                        {field: 'agent.become_time', title: __('成为分销商时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: function(value, row, index) {
+                            return row.agent && row.agent.become_time ? Table.api.formatter.datetime(row.agent.become_time, row, index) : '<span class="text-muted">-</span>';
+                        }}
                     ]
                     ]
                 ]
                 ]
             });
             });