瀏覽代碼

fulu orderstats

xiaoyu 2 年之前
父節點
當前提交
f9b8554535

+ 15 - 0
admin/control/order_search_fulu.php

@@ -87,4 +87,19 @@ class order_search_fuluControl extends SystemControl
         Tpl::output('show_page', $model_refill_order->showpage());
         Tpl::showpage('refill.order.search.fulu');
     }
+
+    public function merchant_dataOp()
+    {
+        global $config;
+        $merchant_list = $this->merchants(['mchid' => ['in', $config['fulu_mchid']]]);
+        $result = [];
+        foreach ($merchant_list as $value) {
+            $data['name'] = $value['company_name'] ?? $value['name'];
+            $data['value'] = $value['mchid'];
+            $data['alpha'] = $value['alpha'];
+            $data['color'] = false;
+            $result[] = $data;
+        }
+        echo json_encode($result);
+    }
 }

+ 86 - 0
admin/control/orderstats_fulu.php

@@ -0,0 +1,86 @@
+<?php
+
+
+class orderstats_fuluControl extends SystemControl
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    public function indexOp()
+    {
+        $type = 'merchant';
+        $_GET['query_start_time'] = $_GET['query_start_time'] ?? date("Y-m-d 00:00:00", strtotime("-1 day"));
+        $model_refill_order = Model('refill_order');
+        $condition = $this->ct_cond($_GET, 'time_stamp');
+        if (!empty($_GET['order_time_type'])) {
+            $condition['order_time_type'] = $_GET['order_time_type'];
+        }
+
+        $stats_list = $model_refill_order->getOrderStatsList($condition, 50, '*', 'time_stamp desc, cname asc');
+        if($type == 'merchant') {
+            foreach ($stats_list as $key => $stats) {
+                $time = date("Y-m-d",$stats['time_stamp']+86400);
+                $mch_cache = rcache("merchant_balance_{$time}", 'refill-');
+                $caches = empty($mch_cache['data']) ? [] : unserialize($mch_cache['data']);
+                if(empty($caches)) continue;
+                $stats_list[$key]['available'] = ncPriceFormat($caches[$stats['cid']]) ?? '';
+            }
+        }
+
+        $total_stats = $this->stats($condition);
+        $order_time_type_text = ['notify_time' => '回调时间', 'order_time' => '下单时间'];
+        Tpl::output('total_stats', $total_stats);
+        Tpl::output('stats_list', $stats_list);
+        Tpl::output('order_time_type_text', $order_time_type_text);
+        Tpl::output('show_page', $model_refill_order->showpage());
+        Tpl::showpage('order.stats.merchant.fulu');
+    }
+
+    private function ct_cond($input, $time_stamp)
+    {
+        global $config;
+        $condition['type'] = $input['type'] ?? 'system';
+        if (!empty($input['cid'])) {
+            $condition['cid'] = ['in', $input['cid']];
+        } else {
+            $condition['cid'] = ['in', ['in', $config['fulu_mchid']]];
+        }
+
+        $start_unixtime = intval(strtotime($input['query_start_time']));
+        $end_unixtime = intval(strtotime($input['query_end_time']));
+
+        if ($start_unixtime > 0 && $end_unixtime > $start_unixtime) {
+            $condition[$time_stamp] = [['egt', $start_unixtime], ['lt', $end_unixtime], 'and'];
+        } elseif ($start_unixtime > 0) {
+            $condition[$time_stamp] = ['egt', $start_unixtime];
+        } elseif ($end_unixtime > 0) {
+            $condition[$time_stamp] = ['lt', $end_unixtime];
+        }
+
+        return $condition;
+    }
+
+    private function stats($condition)
+    {
+        $order_time_type = ['notify_time','order_time'];
+        foreach ($order_time_type as $type){
+            $condition['order_time_type'] = $type;
+            $stats = Model('')->table('refill_stats')
+                ->field('sum(success_count) as success_count,sum(success_refill_amounts) as success_refill_amounts,sum(success_mch_amounts) as success_mch_amounts,
+                sum(success_channel_amounts) as success_channel_amounts,sum(profit_amounts) as profit_amounts,sum(send_count) as send_count')
+                ->where($condition)
+                ->find();
+            $total_stats[$type] = [
+                'success_count_total' => $stats['success_count'],
+                'success_refill_amounts_total' => ncPriceFormat($stats['success_refill_amounts']),
+                'success_mch_amounts_toatl' => ncPriceFormat($stats['success_mch_amounts']),
+                'success_channel_amounts_total' => ncPriceFormat($stats['success_channel_amounts']),
+                'profit_amounts_total' => ncPriceFormat($stats['profit_amounts']),
+                'send_count_total' => $stats['send_count'],
+            ];
+        }
+        return $total_stats;
+    }
+}

+ 1 - 0
admin/include/limit.php

@@ -63,6 +63,7 @@ $_limit =  array(
     array('name' => '充值订单业务', 'child' => array(
         array('name'=> '机构管理', 'op'=>null, 'act'=>'merchant_fulu'),
         array('name'=> '订单查询', 'op'=>null, 'act'=>'order_search_fulu'),
+        array('name'=> '对账管理', 'op'=>null, 'act'=>'orderstats_fulu'),
     )),
 	array('name'=>$lang['nc_store'], 'child'=>array(
 		array('name'=>$lang['nc_store_manage'], 'op'=>null, 'act'=>'store'),

+ 2 - 0
admin/include/menu.php

@@ -153,6 +153,8 @@ $arr = array(
 				'list' => array(
 					array('args'=>'merchant,merchant_fulu,merchant_fulu',		'text'=>'机构管理'),
 					array('args'=>'index,order_search_fulu,merchant_fulu',		'text'=>'订单查询'),
+					array('args'=>'index,orderstats_fulu,merchant_fulu',		'text'=>'对账管理'),
+
 				)
 			],
 			[

+ 393 - 0
admin/templates/default/order.stats.merchant.fulu.php

@@ -0,0 +1,393 @@
+<?php defined('InShopNC') or exit('Access Invalid!'); ?>
+<style>
+    .page .fixed-bar .item-title h3 {
+        margin-top:18px !important;
+        margin-bottom:10px !important;
+        font-weight:700 !important;
+    }
+    .tab-base li span {
+        font-size:12px !important;
+    }
+    .layui-form-select .layui-input {
+        height:26px;
+    }
+    input::placeholder{
+        color:#333;
+    }
+    .row_q ul li {
+        height: 30px;
+        line-height: 30px;
+    }
+    .row_w {
+        float: left;
+        margin-right: 40px;
+    }
+</style>
+<div class="page">
+    <div class="fixed-bar">
+        <div class="item-title">
+            <h3>对账管理</h3>
+            <ul class="tab-base">
+                <li><a href="JavaScript:void(0);" class="current"><span>对账记录</span></a></li>
+            </ul>
+        </div>
+    </div>
+    <div class="fixed-empty"></div>
+    <form method="get" name="formSearch" id="formSearch" class="layui-form">
+        <input type="hidden" value="OrderStats_fulu" name="act">
+        <input type="hidden" value="index" name="op">
+        <input type="hidden" name="cid" value=""/>
+        <input type="hidden" name="default_no_mch" value="<?php echo $_GET['cid']; ?>"/>
+        <table class="tb-type1 noborder search">
+            <tbody>
+            <tr>
+                <th><label for="query_start_time">统计时间</label></th>
+                <td>
+                    <input class="txt date" type="text" value="<?php echo $_GET['query_start_time']; ?>"
+                           id="startTime" name="query_start_time" autocomplete="off" style="width:120px" />
+                    <label for="query_start_time">~</label>
+                    <input class="txt date" type="text" value="<?php echo $_GET['query_end_time']; ?>"
+                           id="endTime" name="query_end_time" autocomplete="off" style="width:120px" />
+                </td>
+                <th><label>统计日期类型</label></th>
+                <td>
+                    <select name="order_time_type" id="order_time_type">
+                        <option value="">请选择...</option>
+                        <option value="notify_time" <?php if($_GET['order_time_type'] == 'notify_time'){ echo 'selected';}?>>回调日期</option>
+                        <option value="order_time" <?php if($_GET['order_time_type'] == 'order_time'){ echo 'selected';}?>>下单日期</option>
+                    </select>
+                </td>
+                <th><label>商户名称</label></th>
+                <td>
+                    <div id="selest_nc"></div>
+                </td>
+                <td>
+                    <a href="javascript:void(0);" id="ncsubmit" class="btn-search "
+                       title="<?php echo $lang['nc_query']; ?>">&nbsp;</a>
+                </td>
+                <td>
+                    <a href="javascript:void(0);" id="ncexport" class="btn">
+                        <span>导出</span>
+                    </a>
+                </td>
+            </tr>
+            </tbody>
+        </table>
+    </form>
+    <table class="table tb-type2" id="prompt">
+        <tbody>
+        <tr class="space odd">
+            <th colspan="12"><div class="title">
+                    <h5>总量统计</h5>
+                    <span class="arrow"></span></div></th>
+        </tr>
+        <tr>
+            <td class="row_q">
+                <ul class="row_w">
+                    <li>回调日期统计</li>
+                    <li class="lineLi" style="color:#000;">总计成功订单量: <?php echo $output['total_stats']['notify_time']['success_count_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计充值中订单量: <?php echo $output['total_stats']['notify_time']['send_count_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计成功订单金额:<?php echo $output['total_stats']['notify_time']['success_refill_amounts_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计下游扣款金额:<?php echo $output['total_stats']['notify_time']['success_mch_amounts_toatl'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计上游扣款金额:<?php echo $output['total_stats']['notify_time']['success_channel_amounts_total'] ?? 0?></li>
+                </ul>
+                <ul>
+                    <li>下单日期统计</li>
+                    <li class="lineLi" style="color:#000;">总计成功订单量: <?php echo $output['total_stats']['order_time']['success_count_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计充值中订单量: <?php echo $output['total_stats']['order_time']['send_count_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计成功订单金额:<?php echo $output['total_stats']['order_time']['success_refill_amounts_total'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计下游扣款金额:<?php echo $output['total_stats']['order_time']['success_mch_amounts_toatl'] ?? 0?></li>
+                    <li class="lineLi" style="color:#000;">总计上游扣款金额:<?php echo $output['total_stats']['order_time']['success_channel_amounts_total'] ?? 0?></li>
+                </ul>
+            </td>
+        </tr>
+        </tbody>
+    </table>
+    <form method="post" id="merchant_name_form">
+        <input type="hidden" name="form_submit" value="ok"/>
+        <table class="table tb-type2">
+            <thead>
+            <tr class="thead">
+                <th>统计日期</th>
+                <th>主体名称</th>
+                <th>主体ID</th>
+                <th class="align-right">成功订单数</th>
+                <th class="align-right">成功金额</th>
+                <th class="align-right">下游金额</th>
+                <th class="align-right">充值中数量</th>
+                <th class="align-right">当日结余</th>
+                <th class="align-right">下游成功单量</th>
+                <th class="align-right">下游成功面值</th>
+                <th class="align-right">下游成功扣款金额</th>
+                <th class="align-right">单量误差</th>
+                <th class="align-right">扣款金额误差</th>
+                <th class="align-right">面值误差</th>
+                <th class="align-right">退款</th>
+                <th class="align-left">备注</th>
+                <th class="align-left">匹配状态</th>
+                <th class="align-left">统计日期类型</th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php if (!empty($output['stats_list']) && is_array($output['stats_list'])) { ?>
+                <?php foreach ($output['stats_list'] as $k => $v) { ?>
+                    <tr class="trFlex">
+                        <td><?php echo $v['time_text']; ?></td>
+                        <td><?php echo $v['cname']; ?></td>
+                        <td><?php echo $v['cid']; ?></td>
+                        <td class="align-right"><?php echo $v['success_count']; ?></td>
+                        <td class="align-right"><?php echo $v['success_refill_amounts']; ?></td>
+                        <td class="align-right"><?php echo $v['success_mch_amounts']; ?></td>
+                        <td class="align-right">
+                            <?php if($v['send_count'] != 0){?>
+                            <span style="color: #f30707">
+                            <?php }?>
+                            <?php echo $v['send_count']; ?>
+                            </span>
+                        </td>
+                        <td class="align-right"><?php echo $v['available']; ?></td>
+                        <td class="align-right"><?php echo $v['corder_success_count']; ?></td>
+                        <td class="align-right"><?php echo $v['corder_success_refill_amounts']; ?></td>
+                        <td class="align-right"><?php echo $v['corder_success_amounts']; ?></td>
+                        <td class="align-right">
+                            <?php if($v['gap_order_count'] != 0){?>
+                            <span style="color: #f30707">
+                            <?php }?>
+                            <?php echo $v['gap_order_count']; ?>
+                            </span>
+                        </td>
+                        <td class="align-right">
+                            <?php if($v['gap_success_amounts'] != 0){?>
+                            <span style="color: #f30707">
+                            <?php }?>
+                            <?php echo $v['gap_success_amounts']; ?>
+                            </span>
+                        </td>
+                        <td class="align-right">
+                            <?php if($v['gap_success_refill_amounts'] != 0){?>
+                            <span style="color: #f30707">
+                            <?php }?>
+                            <?php echo $v['gap_success_refill_amounts']; ?>
+                            </span>
+                        </td>
+                        <td class="align-right"><?php echo $v['refund']; ?></td>
+                        <td class="align-left"><?php echo $v['remark']; ?></td>
+                        <td class="align-left">
+                            <?php if($v['check_status'] == 1){?>
+                                <span style="color: #0bb20c">匹配</span>
+                            <?php }elseif ($v['check_status'] == 2) {?>
+                                <span style="color: #f30707">不匹配</span>
+                            <?php }else{?>
+                                <span style="color: #fd9d0e">未编辑</span>
+                            <?php }?>
+                        </td>
+                        <td class="align-left"><?php echo $output['order_time_type_text'][$v['order_time_type']]; ?></td>
+                    </tr>
+                <?php } ?>
+            <?php } else { ?>
+                <tr class="no_data">
+                    <td colspan="19"><?php echo $lang['nc_no_record']; ?></td>
+                </tr>
+            <?php } ?>
+            </tbody>
+            <tfoot>
+            <tr class="tfoot">
+                <td></td>
+                <td colspan="19">
+                    <div class="pagination"><?php echo $output['show_page']; ?></div>
+                </td>
+            </tr>
+            </tfoot>
+        </table>
+    </form>
+</div>
+<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/js/jquery.edit.js" charset="utf-8"></script>
+<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL; ?>/laydate/laydate.js"></script>
+<script type="text/javascript" src="<?php echo ADMIN_TEMPLATES_URL;?>/js/xm-select.js"></script>
+<script type="text/javascript" src="<?php echo ADMIN_TEMPLATES_URL;?>/layui/layui.js"></script>
+<link rel="stylesheet" type="text/css"
+      href="<?php echo ADMIN_TEMPLATES_URL; ?>/layui/css/layui.css"/>
+<script>
+    $(function () {
+        $("#ncreload").click(function () {
+            $('input[name="reload"]').val('1');
+            select_set()
+            $('#formSearch').submit();
+        })
+        $('#ncsubmit').click(function () {
+            select_set()
+            $('#formSearch').submit();
+        });
+        function select_set(){
+            let selectArr = selest_nc.getValue();
+            let selectStr = ''
+            for (let i = 0; i < selectArr.length; i++) {
+                selectStr += selectArr[i].value+','
+            }
+            selectStr = selectStr.substr(0, selectStr.length-1)
+            $('input[name="cid"]').val(selectStr);
+            console.log("selectStr", selectStr);
+        }
+        // 日期选择器
+        laydate.render({
+            elem: '#startTime',
+            type: 'datetime'
+        });
+        laydate.render({
+            elem: '#endTime',
+            type: 'datetime'
+        });
+        // 表格hover时背景
+        $('.trFlex').each(function () {
+            $(this).hover(function () {
+                $(this)[0].style.backgroundColor = '#cbe9f3'
+            },function() {
+                $(this)[0].style.backgroundColor = '#fff'
+            })
+        })
+        function JSONToExcelConvertor(JSONData, FileName, ShowLabel, headData) {
+            //先转化json
+            let arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
+            let excel = '<table>';
+            // 标题
+            for (const key in headData) {
+                var head = "<tr>";
+                var td = "<td colspan='12' style='font-size:16px;'>"+ headData[key] + '</td>';
+                excel += td + "</tr>";
+            }
+            //设置表头
+            var row = "<tr>";
+            for (var i = 0, l = ShowLabel.length; i < l; i++) {
+                row += "<th style='font-size:14px;'>" + ShowLabel[i].value + '</th>';
+            }
+            //换行
+            excel += row + "</tr>";
+            //设置数据
+            for (var i = 0; i < arrData.length; i++) {
+                var row = "<tr>";
+                let code = i+1
+                row += "<td>" +code+ "</td>"
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].time_text + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].cname + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].cid + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].success_count + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].success_refill_amounts + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].success_mch_amounts + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].success_channel_amounts + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].profit_amounts + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].order_count + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].cancel_count + '</td>';
+                row += '<td style=font-size:14px;'+ 'mso-number-format:"\@"'+ '>' + arrData[i].success_ratio + '</td>';
+                excel += row + "</tr>";
+            }
+            excel += "</table>";
+                var excelFile = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' xmlns='http://www.w3.org/TR/REC-html40'>";
+                excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8">';
+                excelFile += '<meta http-equiv="content-type" content="application/vnd.ms-excel';
+                excelFile += '; charset=UTF-8">';
+                excelFile += "<head>";
+                excelFile += "<!--[if gte mso 9]>";
+                excelFile += "<xml>";
+                excelFile += "<x:ExcelWorkbook>";
+                excelFile += "<x:ExcelWorksheets>";
+                excelFile += "<x:ExcelWorksheet>";
+                excelFile += "<x:Name>";
+                excelFile += "{worksheet}";
+                excelFile += "</x:Name>";
+                excelFile += "<x:WorksheetOptions>";
+                excelFile += "<x:DisplayGridlines/>";
+                excelFile += "</x:WorksheetOptions>";
+                excelFile += "</x:ExcelWorksheet>";
+                excelFile += "</x:ExcelWorksheets>";
+                excelFile += "</x:ExcelWorkbook>";
+                excelFile += "</xml>";
+                excelFile += "<![endif]-->";
+                excelFile += "</head>";
+                excelFile += "<body>";
+                excelFile += excel;
+                excelFile += "</body>";
+                excelFile += "</html>";
+                var uri = 'data:application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelFile);
+                var link = document.createElement("a");
+                link.href = uri;
+                link.style = "visibility:hidden";
+                link.download = FileName + ".xls";
+                document.body.appendChild(link);
+                link.click();
+                document.body.removeChild(link);
+        }
+        $('#ncexport').click(function () {
+            let selectArr = selest_nc.getValue();
+            let selectStr = ''
+            for (let i = 0; i < selectArr.length; i++) {
+                selectStr += selectArr[i].value+','
+            }
+            selectStr = selectStr.substr(0, selectStr.length-1)
+
+            let starTime = new Date($('input[name="query_start_time"]').val()).getTime()/1000;
+            let endTime = new Date($('input[name="query_end_time"]').val()).getTime()/1000;
+            let cid = selectStr
+            let order_time_type = $('#order_time_type').val()
+            $.get('index.php?act=orderstats&op=ExportData&type=merchant', {
+                query_start_time: starTime,
+                query_end_time: endTime,
+                cid: cid,
+                order_time_type:order_time_type
+            }, function (data) {
+                data = JSON.parse(data)
+                if (data && data.data) {
+                    let time = ''
+                    let head = ''
+                    let admin_name = '<?php echo ADMIN_NAME;?>'
+                    if (admin_name === 'YEZI') {
+                        head = ['北京椰子电子商务有限责任公司']
+                    } else {
+                        head = ['北京椰林网络科技有限责任公司']
+                    }
+                    if (starTime && endTime) {
+                        time = '统计时间:'+$('input[name="query_start_time"]').val()+' - '+$('input[name="query_end_time"]').val()
+                    } else if (starTime) {
+                        time = '统计时间:'+$('input[name="query_start_time"]').val()
+                    }
+                    if (time) {
+                        head.push(time)
+                    }
+                    head.push('总计成功订单数量:' + parseInt(data.total_stats.success_count_total))
+                    head.push('总计成功订单金额:' + parseFloat(data.total_stats.success_refill_amounts_total))
+                    head.push('总计下游扣款金额:' + parseFloat(data.total_stats.success_mch_amounts_toatl))
+                    head.push('总计上游扣款金额:' + parseFloat(data.total_stats.success_channel_amounts_total))
+                    head.push('总计利润金额:' + parseFloat(data.total_stats.profit_amounts_total))
+                    let title = [{value: "序号"},{value: "统计日期"},{value: "主体名称"},{value: "主体ID"},{value: "成功订单数"},{value: "成功金额"},{value: "下游金额"},{value: "上游金额"},{value: "利润"},{value: "订单总量"}, {value: "失败订单数量"},{value: "成功占比"}]
+                    JSONToExcelConvertor(data.data, '下游对账记录', title, head)
+                }
+            })
+        })
+        //多选
+    let selest_nc
+    let default_no_mch = $('input[name="default_no_mch"]').val().split(',');
+    $.get('index.php?act=order_search_fulu&op=merchant_data', function (data) {
+        data = JSON.parse(data)
+        if (default_no_mch) {
+            for (let index = 0; index < default_no_mch.length; index++) {
+                for (let j = 0; j < data.length; j++) {
+                    if (default_no_mch[index] === data[j].value) {
+                        data[j].selected = true
+                    }
+                }
+            }
+        }
+        selest_nc = xmSelect.render({
+            el: '#selest_nc',
+            size: 'mini',
+            filterable: true,
+            style: {
+                minHeight: '27px',
+                lineHeight: '27px',
+                marginLeft: '4px',
+                width: '250px'
+            },
+            data: data
+        })
+    })
+    });
+</script>