xiaoyu 3 năm trước cách đây
mục cha
commit
0ffd4c180b

+ 31 - 2
admin/control/orderstats.php

@@ -173,12 +173,41 @@ class orderstatsControl extends SystemControl
         Tpl::showpage($page);
     }
 
+    public function refill_balance_createOp()
+    {
+        $balance_id = $_GET['balance_id'];
+        $mod = Model('refill_balance');
+        $balance = $mod->getBalance(['balance_id' => $balance_id]);
+        if(empty($balance )) {
+            showMessage('记录不存在!');
+        }
+
+        $start_unixtime = intval(strtotime($_GET['query_start_time']));
+        $end_unixtime = intval(strtotime($_GET['query_end_time']));
+
+        $condition = [
+            'type' => $balance['type'], 'cid' => $balance['cid'], 'start' => $start_unixtime,
+            'end'  => $end_unixtime, 'time_type' => $balance['time_type'], 'parent_id' => $balance_id
+        ];
+    }
+
+    public function refill_balance_rebuildOp()
+    {
+
+        showMessage('操作成功!');
+    }
+
+    public function refill_balance_saveOp()
+    {
+        showMessage('操作成功!');
+    }
+
     public function refill_balance_confirmOp()
     {
         $balance_id = $_GET['balance_id'];
         $mod = Model('refill_balance');
-        $balance_item = $mod->getBalance(['balance_id' => $balance_id]);
-        if(empty($balance_item )) {
+        $balance = $mod->getBalance(['balance_id' => $balance_id]);
+        if(empty($balance )) {
             showMessage('记录不存在!');
         }
 

+ 8 - 5
admin/templates/default/system.refill.balance.php

@@ -225,13 +225,15 @@
                                 <td class="align-center"><?php echo $output['order_time_type_text'][$v['time_type']]; ?></td>
                                 <td class="align-left"><?php echo $v['remark']; ?></td>
                                 <td style="color:#069;">
-                                    <a style="color:#0D93BF;" href="javascript:void(0)" data-index="<?php echo $k ?>" class="item_create_btn">新建</a>
+                                    <a style="color:#0D93BF;" href="javascript:void(0)" data-index="<?php echo $k ?>" data-balance_id="<?php echo $v['balance_id']; ?>" class="item_create_btn">新建</a>
                                     <span>|</span>
                                     <a style="color:#0D93BF;" href="javascript:void(0)" data-index="<?php echo $k ?>" class="handleBtn">编辑</a>
                                     <span>|</span>
-                                    <a href="javascript:void(0)" style="margin:0 5px;color:#0D93BF;" data-index="<?php echo $k ?>" class="rebuildBtn">重新生成</a>
-                                    <span>|</span>
-                                    <a style="color:#0D93BF;" href="index.php?act=orderstats&op=refill_balance_confirm&balance_id=<?php echo $v['balance_id']; ?>" data-index="<?php echo $k ?>" class="checkBtn">确认</a>
+                                    <a style="margin:0 5px;color:#0D93BF;" href="index.php?act=orderstats&op=refill_balance_rebuild&balance_id=<?php echo $v['balance_id'];?>" data-index="<?php echo $k ?>" class="rebuildBtn">重新生成</a>
+                                    <?php if($v['confirmed'] == 0){ ?>
+                                        <span>|</span>
+                                        <a style="color:#0D93BF;" href="index.php?act=orderstats&op=refill_balance_confirm&balance_id=<?php echo $v['balance_id'];?>" data-index="<?php echo $k ?>" class="checkBtn">确认</a>
+                                    <?php }?>
                                 </td>
                                 <!--                        <td class="align-center w200">-->
                                 <!--                            <a href="index.php?act=merchant&op=OrderStatsReload&stat_id=--><?php //echo $v['stat_id'];
@@ -298,7 +300,7 @@
         $('.item_create_btn').on('click', function() {
             var selectStartDate = '';
             var selectEndDate = '';
-            var selectIndex = $(this).attr('data-index');
+            var balance_id = $(this).attr('data-balance_id');
             layui.use(['layer', 'laydate'], function() {
                 const selectDateHTML = `<label class="createTaskDate"><span>开始日期:</span><input type="text" class="layui-input" id="createItemStartDate"></label>
                                         <label class="createTaskDate"><span>结束日期:</span><input type="text" class="layui-input" id="createItemEndDate"></label>`
@@ -306,6 +308,7 @@
                     title: '新建'
                 }, function(index) {
                     console.log('确认')
+                    console.log(balance_id,selectStartDate,selectEndDate)
                     layer.close(index);
                 }, function() {
                     console.log('取消')

+ 39 - 22
helper/statistics/refill_balance.php

@@ -89,54 +89,47 @@ class refill_balance
         return intval($item['balance_id']);
     }
 
-    //system,provider,merchant
-    //cid=0,mchid,store_id
-    public function add_balance($type, $cid, $start, $end, $time_type, $parent_balance = 0,$remark = '系统自动生成')
+    private function balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark)
     {
-        $order_stat = $this->order_stat($type,$cid,$start,$end,$time_type);
+        $order_stat = $this->order_stat($type, $cid, $start, $end, $time_type);
 
-        if($type == 'system') {
-            $in = $this->merchant_evidence_stat(0,$start,$end);
-            $out = $this->provider_amount_stat(0,$start,$end);
+        if ($type == 'system') {
+            $in = $this->merchant_evidence_stat(0, $start, $end);
+            $out = $this->provider_amount_stat(0, $start, $end);
             $cname = 'system';
 
             $balance = ncPriceFormat($in - $out);
-        }
-        elseif($type == 'merchant') {
-            $in = $this->merchant_evidence_stat($cid,$start,$end);
+        } elseif ($type == 'merchant') {
+            $in = $this->merchant_evidence_stat($cid, $start, $end);
             $out = "0.0000";
             $cname = $this->mMerchantNames[$cid];
 
             $balance = ncPriceFormat($in - $order_stat['mch_amounts']);
-        }
-        else {
+        } else {
             $in = "0.0000";
             $pid = $this->mStoreidPID[$cid];
-            $out = $this->provider_amount_stat($pid,$start,$end);
+            $out = $this->provider_amount_stat($pid, $start, $end);
             $cname = $this->mProviderNames[$cid];
 
             $balance = ncPriceFormat($in - $order_stat['channel_amounts']);
         }
 
-        $accumuter = function ($parent_id)
-        {
+        $accumuter = function ($parent_id) {
             if ($parent_id > 0) {
                 $item = Model('refill_balance')->getBalance(['balance_id' => $parent_id]);
-            }
-            else {
+            } else {
                 $item = [];
             }
 
-            if(empty($item)) {
+            if (empty($item)) {
                 return 0.00;
-            }
-            else {
+            } else {
                 return $item['accumulate_balance'] + $item['balance'];
             }
         };
 
-        $data = ['parent_id' => $parent_balance, 'type' => $type, 'cid' => $cid, 'cname' => $cname,
-            'start_stamp' => $start,'end_stamp' => $end,'end_text' => date('Y-m-d H:i:s', $end),
+        return ['parent_id' => $parent_balance, 'type' => $type, 'cid' => $cid, 'cname' => $cname,
+            'start_stamp' => $start, 'end_stamp' => $end, 'end_text' => date('Y-m-d H:i:s', $end),
             'success_count' => intval($order_stat['order_counts']),
             'refill_amount' => ncPriceFormat($order_stat['refill_amounts']),
             'mch_amount' => ncPriceFormat($order_stat['mch_amounts']),
@@ -153,11 +146,35 @@ class refill_balance
             'time_type' => $time_type,
             'remark' => $remark,
         ];
+    }
 
+    //system,provider,merchant
+    //cid=0,mchid,store_id
+    public function add_balance($type, $cid, $start, $end, $time_type, $parent_balance = 0, $remark = '系统自动生成')
+    {
+        $data = $this->balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark);
         $ret = Model('refill_balance')->insert($data);
         return $ret != false;
     }
 
+    public function rebuild_balance($balance_id)
+    {
+        $balance = Model('refill_balance')->getBalance(['balance_id' => $balance_id]);
+        if(empty($balance)) return false;
+
+        $type = $balance['type'];
+        $cid = $balance['cid'];
+        $start = $balance['start_stamp'];
+        $end = $balance['end_stamp'];
+        $time_type = $balance['time_type'];
+        $parent_balance = $balance['parent_id'];
+        $remark = '记录重新生成';
+
+        $data = $this->balance_data($type, $cid, $start, $end, $time_type, $parent_balance, $remark);
+        $ret = Model('refill_balance')->where(['balance_id' => $balance_id])->update($data);
+        return $ret != false;
+    }
+
     private function order_stat($type, $cid, $start, $end, $time_type)
     {
         $cond = [

+ 21 - 0
helper/task/handler.php

@@ -2,11 +2,13 @@
 namespace task;
 require_once(BASE_HELPER_PATH . '/stat_helper.php');
 require_once(BASE_HELPER_PATH . '/PHPExcel/PHPExcel.php');
+require_once(BASE_HELPER_PATH . '/statistics/refill_balance.php');
 
 use Exception;
 use mtopcard;
 use PHPExcel;
 use PHPExcel_IOFactory;
+use statistics\refill_balance;
 use statistics\stat_refill;
 
 class handler
@@ -325,4 +327,23 @@ class handler
     {
         return md5("order_stat_reload-".serialize($condition));
     }
+
+    public function refill_balance_create($condition)
+    {
+        $type = $condition['type'];
+        $cid = $condition['cid'];
+        $start = $condition['start'];
+        $end = $condition['end'];
+        $time_type = $condition['time_type'];
+        $parent_balance = $condition['parent_id'];
+
+        $refill_balance = new refill_balance();
+        $refill_balance->add_balance($type, $cid, $start, $end, $time_type, $parent_balance);
+        return [true, 'success'];
+    }
+
+    public function refill_balance_create_title($condition)
+    {
+        return md5("refill_balance_create-".serialize($condition));
+    }
 }