123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
- var Controller = {
- index: function () {
- // 初始化表格参数
- Table.api.init({
- extend: {
- index_url: 'commission/order/index' + location.search,
- add_url: '',
- edit_url: 'commission/order/edit',
- del_url: 'commission/order/del',
- multi_url: 'commission/order/multi',
- import_url: 'commission/order/import',
- table: 'commission_order',
- }
- });
- var table = $("#table");
-
- // 获取后台配置
- var orderStatusTypes = Controller.api.parseConfigJson('commission_order_status_types', {
- '-2': __('已扣除'),
- '-1': __('已取消'),
- '0': __('不计入'),
- '1': __('已计入')
- });
-
- var rewardStatusTypes = Controller.api.parseConfigJson('commission_reward_status_types', {
- '-2': __('已退回'),
- '-1': __('已取消'),
- '0': __('未结算'),
- '1': __('已结算')
- });
-
- var displayConfig = Controller.api.parseConfigJson('commission_order_user_display_config', {
- showAvatar: true,
- avatarSize: 40,
- showMobile: true,
- showId: true,
- defaultAvatarUrl: '/assets/img/avatar.png'
- });
- // 格式化订单状态
- function formatOrderStatus(value, colorMap) {
- var statusConfig = colorMap[value];
- if (!statusConfig) return value;
- return '<span class="label label-' + statusConfig.color + '">' + statusConfig.text + '</span>';
- }
- // 格式化用户信息(买家或代理商)
- function formatUserInfo(user, userId, userType) {
- if (!user) return '-';
- return Controller.api.formatUserInfo(user, userId || user.id, userType, displayConfig);
- }
- // 统计信息处理
- function updateStats(data) {
- if (data.extend && data.extend.count) {
- var count = data.extend.count;
-
- // 格式化数字显示
- function formatNumber(number) {
- return (number || 0).toFixed(2);
- }
-
- $('#total-count').text(count.total || 0);
- $('#total-amount').text(formatNumber(count.total_amount));
- $('#total-commission').text(formatNumber(count.total_commission));
- $('#total-pending').text(formatNumber(count.total_commission_pending));
- $('#total-accounted').text(formatNumber(count.total_commission_accounted));
- $('#total-back').text(formatNumber(count.total_commission_back));
- $('#total-cancel').text(formatNumber(count.total_commission_cancel));
- }
- }
- // 初始化表格
- table.bootstrapTable({
- url: $.fn.bootstrapTable.defaults.extend.index_url,
- pk: 'id',
- sortName: 'id',
- fixedColumns: true, // 启用固定列功能
- fixedRightNumber: 1, // 固定右侧最后1列(操作列)
- responseHandler: function(res) {
- updateStats(res);
- return res;
- },
- columns: [
- [
- {checkbox: true},
- {field: 'id', title: __('ID'), width: 60},
- {field: 'order.order_sn', title: __('订单号'), operate: 'LIKE', formatter: function(value, row, index) {
- if (row.order && row.order.order_sn) {
- return '<a href="javascript:;" data-order-id="' + row.order_id + '" class="searchit order-detail">' + row.order.order_sn + '</a>';
- }
- return '-';
- }},
- {field: 'order_item.goods_title', title: __('商品信息'), operate: 'LIKE', width: 300, formatter: function(value, row, index) {
- if (row.order_item) {
- var item = row.order_item;
- var html = '<div style="display: flex; align-items: center; padding: 5px 0;">';
-
- // 商品图片
- var imageUrl = item.goods_image || item.image || '/assets/img/goods-default.png';
- if (imageUrl && !imageUrl.startsWith('http') && !imageUrl.startsWith('//')) {
- imageUrl = Fast.api.cdnurl ? Fast.api.cdnurl(imageUrl) : imageUrl;
- }
- html += '<div style="margin-right: 12px; flex-shrink: 0;">';
- html += '<img src="' + imageUrl + '" style="width: 60px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid #e9ecef;" />';
- html += '</div>';
-
- // 商品信息
- html += '<div style="flex: 1; min-width: 0;">';
-
- // 商品标题
- var goodsTitle = item.goods_title || item.title || '-';
- html += '<div style="color: #337ab7; font-weight: bold; margin-bottom: 4px; line-height: 1.4;">';
- html += '<a href="javascript:;" data-goods-id="' + item.goods_id + '" class="searchit goods-detail" style="color: #337ab7; text-decoration: none;">';
- html += goodsTitle;
- html += '</a></div>';
-
- // 商品规格
- if (item.goods_sku || item.sku_name || item.specs) {
- var specs = item.goods_sku || item.sku_name || item.specs;
- html += '<div style="color: #6c757d; font-size: 12px; margin-bottom: 4px;">' + specs + '</div>';
- }
-
- // 商品价格和数量
- var price = item.price || item.goods_price || 0;
- var nums = item.nums || item.quantity || 1;
- html += '<div style="color: #28a745; font-weight: bold; font-size: 14px;">';
- html += '¥' + parseFloat(price).toFixed(2) + ' × ' + nums;
- html += '</div>';
-
- html += '</div></div>';
- return html;
- }
- return '-';
- }},
- {
- field: 'buyer.nickname',
- title: __('下单用户'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- return formatUserInfo(row.buyer, row.user_id, '用户');
- }
- },
- {
- field: 'agent.nickname',
- title: __('推广分销商'),
- operate: 'LIKE',
- formatter: function (value, row, index) {
- return formatUserInfo(row.agent, row.agent_id, '分销商');
- }
- },
- {field: 'amount', title: __('结算金额'), operate: 'BETWEEN'},
- {field: 'commission_order_status', title: __('业绩状态'), searchList: orderStatusTypes, formatter: function(value, row, index) {
- var statusMap = {
- '-2': {text: orderStatusTypes['-2'] || '已扣除', color: 'danger'},
- '-1': {text: orderStatusTypes['-1'] || '已取消', color: 'warning'},
- '0': {text: orderStatusTypes['0'] || '不计入', color: 'info'},
- '1': {text: orderStatusTypes['1'] || '已计入', color: 'success'}
- };
- return formatOrderStatus(value, statusMap);
- }},
- {field: 'commission_reward_status', title: __('佣金状态'), searchList: rewardStatusTypes, formatter: function(value, row, index) {
- var statusMap = {
- '-2': {text: rewardStatusTypes['-2'] || '已退回', color: 'danger'},
- '-1': {text: rewardStatusTypes['-1'] || '已取消', color: 'warning'},
- '0': {text: rewardStatusTypes['0'] || '未结算', color: 'info'},
- '1': {text: rewardStatusTypes['1'] || '已结算', color: 'success'}
- };
- return formatOrderStatus(value, statusMap);
- }},
- {field: 'commission_time', title: __('结算时间'), operate: 'RANGE', addclass: 'datetimerange', autocomplete: false, formatter: Table.api.formatter.datetime},
- {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
- width: 150,
- buttons: [
- {
- name: 'back',
- text: __('手动退回'),
- title: __('手动退回佣金'),
- classname: 'btn btn-xs btn-danger',
- icon: 'fa fa-undo',
- visible: function (row) {
- return row.commission_reward_status == 1;
- },
- click: function (data) {
- Layer.confirm('确认手动退回此订单的佣金?', function(index) {
- Fast.api.ajax({
- url: 'commission/order/back',
- data: {commission_order_id: data.id, deduct_order_money: 1}
- }, function(data, ret) {
- table.bootstrapTable('refresh');
- Layer.close(index);
- });
- });
- }
- },
- {
- name: 'detail',
- text: __('订单详情'),
- title: __('查看订单详情'),
- classname: 'btn btn-xs btn-info',
- icon: 'fa fa-eye',
- visible: function (row) {
- return true; // 始终显示
- },
- click: function (data) {
- if (data.order_id) {
- Fast.api.open('order/order/detail?id=' + data.order_id, '订单详情', {
- area: ['90%', '90%']
- });
- } else {
- Layer.msg('订单ID不存在');
- }
- }
- }
- ],
- formatter: Table.api.formatter.operate}
- ]
- ]
- });
- // 为表格绑定事件
- Table.api.bindevent(table);
- // 绑定订单详情点击事件
- $(document).on('click', '.order-detail', function() {
- var orderId = $(this).data('order-id');
- Fast.api.open('order/order/detail?id=' + orderId, '订单详情');
- });
- // 绑定商品详情点击事件
- $(document).on('click', '.goods-detail', function() {
- var goodsId = $(this).data('goods-id');
- Fast.api.open('goods/goods/detail?id=' + goodsId, '商品详情');
- });
- },
- api: {
- // 解析Config中的JSON字符串的辅助函数
- parseConfigJson: function(configKey, defaultValue) {
- var configValue = Config[configKey] || defaultValue || {};
-
- // 如果是字符串,尝试解析JSON
- if (typeof configValue === 'string') {
- try {
- return JSON.parse(configValue);
- } catch (e) {
- return defaultValue || {};
- }
- }
-
- return configValue;
- },
-
- // 统一的用户信息展示方法
- formatUserInfo: function(user, userId, userType, config) {
- if (!user) return '-';
-
- config = config || {
- showAvatar: true,
- avatarSize: 40,
- showMobile: true,
- showId: true,
- defaultAvatarUrl: '/assets/img/avatar.png'
- };
-
- var avatar = user.avatar ? user.avatar : config.defaultAvatarUrl;
- var nickname = user.nickname || user.username || (userType || '用户');
- var mobile = user.mobile || '';
-
- // 处理头像URL
- var avatarUrl = avatar;
- if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
- avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
- }
-
- var typeColor = userType === '分销商' ? '#28a745' : (userType === '用户' ? '#17a2b8' : '#337ab7');
-
- var html = '<div style="display:flex;align-items:center;">';
-
- if (config.showAvatar) {
- html += '<img src="' + avatarUrl + '" style="width:' + config.avatarSize + 'px;height:' + config.avatarSize + 'px;border-radius:50%;margin-right:10px;" />';
- }
-
- html += '<div>' +
- '<div style="color:#337ab7;font-weight:bold;">' + nickname + '</div>' +
- '<div style="color:' + typeColor + ';font-size:12px;">';
-
- var info = [];
- if (config.showMobile && mobile) {
- info.push(mobile);
- }
- if (config.showId && userId) {
- info.push('ID: ' + userId);
- }
-
- html += info.join(' ') + '</div></div></div>';
- return html;
- },
-
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|