Bläddra i källkod

admin/templates/default/js/stats-quota.js

lowkeyman 2 månader sedan
förälder
incheckning
dad70d6cf7
1 ändrade filer med 177 tillägg och 22 borttagningar
  1. 177 22
      admin/templates/default/refill_quota_stats.index.php

+ 177 - 22
admin/templates/default/refill_quota_stats.index.php

@@ -243,24 +243,9 @@
         line-height: 28px;
         display: inline-block;
         vertical-align: middle;
-    }
-
-    .reset-bar button:first-child {
-        margin-left: 1150px;
-        width: 150px;
-    }
-
-    .reset-bar button:nth-child(2) {
-        margin-left: 145px;
         width: 150px;
     }
 
-    .reset-bar button:nth-child(3) {
-        margin-left: 75px;
-        width: 150px;
-        display: none;
-    }
-
     .company-checkbox {
         display: inline-flex;
         align-items: center;
@@ -311,7 +296,28 @@
         color: blue !important;
     }
 
+    .chinese-money {
+        font-size: 12px;
+        color: red;
+        display: block;
+        margin-top: 5px;
+    }
 
+    .btn-badge {
+        position: absolute;
+        top: 5px;
+        right: 5px;
+        width: 16px;
+        height: 16px;
+        background-color: red;
+        color: white;
+        border-radius: 50%;
+        display: flex;
+        align-items: center;
+        justify-content: center;
+        font-size: 10px;
+        font-weight: bold;
+    }
 </style>
 
 <div class="page" id="app">
@@ -346,6 +352,7 @@
     <div class="stats-panel layui-font-14">
         <merchant-set type="KEY_QUOTA_MERCHANT" emit="updateMerchant"></merchant-set>
         <div class="reset-bar">
+            <button type="button" class="layui-btn layui-btn-light-yellow reset-col" data-table="tb-merchant" data-col="total_invoiced">一键清零</button>
             <button type="button" class="layui-btn layui-btn-light-yellow reset-col" data-table="tb-merchant" data-col="actual_invoice_amount">一键清零</button>
             <button type="button" class="layui-btn layui-bg-orange ac-batch-invoice" data-table="tb-merchant">批量提交</button>
             <button type="button" class="layui-btn layui-bg-red ac-approve" data-table="tb-merchant">
@@ -360,6 +367,7 @@
     <div class="stats-panel layui-font-14">
         <channel-set type="KEY_QUOTA_CHANNEL" emit="updateChannel"></channel-set>
         <div class="reset-bar">
+            <button type="button" class="layui-btn layui-btn-light-yellow reset-col" data-table="tb-channel" data-col="total_invoiced">一键清零</button>
             <button type="button" class="layui-btn layui-btn-light-yellow reset-col" data-table="tb-channel" data-col="actual_invoice_amount">一键清零</button>
             <button type="button" class="layui-btn layui-bg-orange ac-batch-invoice" data-table="tb-channel">批量提交</button>
             <button type="button" class="layui-btn layui-bg-red ac-approve" data-table="tb-channel">
@@ -622,6 +630,7 @@
                         that.deltaValue('amounts', 'total_invoiced', 'estimated_invoice_amount');
                         that.updateAvailableInvoiceAmount();
                         that.setValueClass(['total_invoiced', 'available_invoice_amount', 'estimated_invoice_amount', 'actual_invoice_amount']);
+                        that.updateColumnCnMoney(['total_invoiced']);
 
                         trs.each(function (i, tr) {
                             const editNumberColumns = ['total_invoiced', 'actual_invoice_amount'];
@@ -650,9 +659,15 @@
                                         const index = $(this).parent().parent().data('index');
                                         await that.saveEdit(index);
 
+                                        if (col === 'total_invoiced') {
+                                            const subject = $(tr).find('td[data-field="subject"]').find('div').text();
+                                            await that.updateCompanyUsedQuota(subject);
+                                        }
+
                                         that.deltaValue('amounts', 'total_invoiced', 'estimated_invoice_amount');
                                         that.updateAvailableInvoiceAmount();
                                         that.setValueClass(['total_invoiced', 'available_invoice_amount', 'estimated_invoice_amount', 'actual_invoice_amount']);
+                                        that.updateColumnCnMoney(['total_invoiced']);
                                     });
                             }
 
@@ -729,6 +744,27 @@
                 }
             }
 
+            updateColumnCnMoney(columns) {
+                const tableItem = $('#' + this.tableId);
+                const trs = tableItem.next('.layui-table-view').find('.layui-table-body tbody tr');
+
+                trs.each(function(i, tr) {
+                    columns.forEach(column => {
+                        const cell = $(tr).find('td[data-field="' + column + '"]');
+                        let value = cell.find('div').text().trim();
+                        value = parseFloat(value.replace(/[^\d.-]/g, ''));
+
+                        if (!isNaN(value)) {
+                            const chineseMoney = cnMoneyFormat(value);
+                            cell.find('.chinese-money').remove();
+
+                            const content = chineseMoney !== '' ? `(${chineseMoney})` : '';
+                            cell.append('<span class="chinese-money">' + content + '</span>');
+                        }
+                    });
+                });
+            }
+
             mergeCells() {
                 const tbRoot = $('#' + this.tableId);
                 const trs = tbRoot.next('.layui-table-view').find('.layui-table-body tbody tr');
@@ -821,8 +857,22 @@
                 item.remark = remark;
 
                 await dataHelper.addOrUpdateData(CONSTANTS.KEY_QUOTA_MERCHANT, item, 2);
+            }
+
+            async updateCompanyUsedQuota(subject) {
+                const companyList = dataHelper.getCompanyList();
+                const activeCompany = companyList.find(cItem => cItem.name === subject);
+                if (activeCompany !== undefined) {//更新当前编辑的主体已用额度
+                    const merchantDataNew = dataHelper.getMerchantList();
+                    const total = merchantDataNew
+                        .filter(mItem => mItem.subject === subject)
+                        .reduce((sum, item) => sum + parseFloat(item.total_invoiced), 0);
+                    activeCompany.used_quota = total.toString();
+                }
+                await dataHelper.updateAllData(CONSTANTS.KEY_QUOTA_COMPANY, companyList);
 
                 setTimeout(function () {
+                    companyTable.renderTable();
                     summaryTable.renderTable();
                 }, 0);
             }
@@ -878,7 +928,7 @@
                         {field: 'subject', title: '对应主体', width: 150},
                         {field: 'store_id', title: '通道id', width: 100},
                         {field: 'store_name', title: '通道名称', width: 150},
-                        {field: 'amounts', title: '充值总计金额', width: 150},
+                        {field: 'amounts', title: '通道总计金额', width: 150},
                         {field: 'total_invoiced', title: '已开票总金额', width: 150},
                         {field: 'last_invoice_date', title: '上次开票日期', width: 150, templet: function(d){
                                 return '<input type="text" class="layui-input date-input" data-index="' + d.LAY_TABLE_INDEX + '" data-field="last_invoice_date" value="' + d.last_invoice_date + '">';
@@ -906,6 +956,7 @@
                         that.deltaValue('amounts', 'total_invoiced', 'estimated_invoice_amount');
                         that.updateAvailableInvoiceAmount();
                         that.setValueClass(['total_invoiced', 'available_invoice_amount', 'estimated_invoice_amount', 'actual_invoice_amount']);
+                        that.updateColumnCnMoney(['total_invoiced']);
 
                         trs.each(function (i, tr) {
                             const editNumberColumns = ['total_invoiced', 'actual_invoice_amount'];
@@ -965,6 +1016,7 @@
                                         that.deltaValue('amounts', 'total_invoiced', 'estimated_invoice_amount');
                                         that.updateAvailableInvoiceAmount();
                                         that.setValueClass(['total_invoiced', 'available_invoice_amount', 'estimated_invoice_amount', 'actual_invoice_amount']);
+                                        that.updateColumnCnMoney(['total_invoiced']);
                                     });
                             }
                         });
@@ -1013,6 +1065,27 @@
                 }
             }
 
+            updateColumnCnMoney(columns) {
+                const tableItem = $('#' + this.tableId);
+                const trs = tableItem.next('.layui-table-view').find('.layui-table-body tbody tr');
+
+                trs.each(function(i, tr) {
+                    columns.forEach(column => {
+                        const cell = $(tr).find('td[data-field="' + column + '"]');
+                        let value = cell.find('div').text().trim();
+                        value = parseFloat(value.replace(/[^\d.-]/g, ''));
+
+                        if (!isNaN(value)) {
+                            const chineseMoney = cnMoneyFormat(value);
+                            cell.find('.chinese-money').remove();
+
+                            const content = chineseMoney !== '' ? `(${chineseMoney})` : '';
+                            cell.append('<span class="chinese-money">' + content + '</span>');
+                        }
+                    });
+                });
+            }
+
             mergeCells() {
                 const tbRoot = $('#' + this.tableId);
                 const trs = tbRoot.next('.layui-table-view').find('.layui-table-body tbody tr');
@@ -1150,7 +1223,7 @@
                     limit: tableData.length,
                     cols: [[
                         {field: 'subject', title: '对应主体', width: 150},
-                        {field: 'subject_quota', title: '主体额度', width: 100},
+                        {field: 'subject_quota', title: '本月总额度', width: 100},
                         {field: 'channel_amounts', title: '上游本月需开票', width: 150},
                         {field: 'channel_total_invoiced', title: '上游已开票', width: 150},
                         {field: 'channel_invoice_quota', title: '上游需开票', width: 150},
@@ -1762,7 +1835,6 @@
             loadMsgBadge();
 
             layer.close(loadIndex);
-
         }
 
         const batchMchInvoice = new BatchInvoice('mch');
@@ -1794,10 +1866,82 @@
             }
         });
 
-        $('.reset-col').on('click', function () {
+        $('.reset-col').on('click', async function () {
+            const loadIndex = layer.load(2, {shade: [0.2, '#000']});
+
             const tableId = $(this).data('table');
             const col = $(this).data('col');
             setTableColVal(tableId, col, '0');
+
+            const activeData = () => {
+                const data = [];
+                const trs = $('#' + tableId).next('.layui-table-view').find('.layui-table-body tbody tr');
+                trs.each(function (i, tr) {
+                    const subject = $(tr).find('td[data-field="subject"]').find('div').text();
+                    let typeIdField = '';
+                    if (tableId === 'tb-merchant') {
+                        typeIdField = 'mch_id';
+                    } else if (tableId === 'tb-channel') {
+                        typeIdField = 'store_id';
+                    }
+
+                    const type_id = $(tr).find('td[data-field="' + typeIdField + '"]').find('div').text();
+                    data.push({
+                        type_id
+                    });
+                });
+
+                return data;
+            };
+
+
+            if (tableId === 'tb-merchant' && col === 'total_invoiced') {
+                const activeList = activeData();
+                const companyReduce = {};
+                const merchantList = dataHelper.getMerchantList();
+                merchantList.forEach(item => {
+                    const ac = activeList.find(aItem => aItem.type_id === item.mch_id);
+                    if (ac !== undefined) {
+                        if (!companyReduce[item.subject]) {
+                            companyReduce[item.subject] = 0;
+                        }
+                        companyReduce[item.subject] += parseFloat(item.total_invoiced);
+
+                        item.total_invoiced = '0';
+                    }
+                })
+                await dataHelper.updateAllData(CONSTANTS.KEY_QUOTA_MERCHANT, merchantList);
+
+                const companyList = dataHelper.getCompanyList();
+                companyList.forEach(item => {
+                    if (companyReduce[item.name] !== undefined) {
+                        const used_quota_up = parseFloat(item.used_quota) - companyReduce[item.name];
+                        if (item.used_quota < 0) {
+                            item.used_quota = 0;
+                        }
+                        item.used_quota = used_quota_up.toString();
+                    }
+                });
+                await dataHelper.updateAllData(CONSTANTS.KEY_QUOTA_COMPANY, companyList);
+
+                companyTable.renderTable();
+                summaryTable.renderTable();
+            } else if (tableId === 'tb-channel' && col === 'total_invoiced') {
+                const activeList = activeData();
+                const channelList = dataHelper.getChannelList();
+                channelList.forEach(item => {
+                    const ac = activeList.find(aItem => aItem.type_id === item.store_id);
+                    if (ac !== undefined) {
+                        item.total_invoiced = '0';
+                    }
+                })
+                await dataHelper.updateAllData(CONSTANTS.KEY_QUOTA_CHANNEL, channelList);
+
+                await channelTable.renderTable();
+                summaryTable.renderTable();
+            }
+
+            layer.close(loadIndex);
         });
 
         $('#btn-update-all').on('click', function (){
@@ -1805,10 +1949,21 @@
         });
 
         if (isAdmin === false) {
-            $('.reset-bar button:first-child').css('margin-left', '700px');
+            $('.reset-bar button:first-child').hide();
+            $('.reset-bar button:nth-child(2)').css('margin-left', '700px');
+            $('.reset-bar button:nth-child(3)').css('margin-left', '150px');
+            $('.reset-bar button:nth-child(4)').css({
+                'margin-left': '75px',
+                'display': 'inline-block'
+            });
         } else {
-            $('.reset-bar button:first-child').css('margin-left', '1150px');
-            $('.reset-bar button:nth-child(3)').css('display', 'inline-block');
+            $('.reset-bar button:first-child').css('margin-left', '545px');
+            $('.reset-bar button:nth-child(2)').css('margin-left', '445px');
+            $('.reset-bar button:nth-child(3)').css('margin-left', '150px');
+            $('.reset-bar button:nth-child(4)').css({
+                'margin-left': '75px',
+                'display': 'inline-block'
+            });
         }
 
         initPage();