Your Name 2 years ago
parent
commit
212cd85464

+ 14 - 0
service/agent/database/member.php

@@ -736,10 +736,24 @@ return array
             (
                 'id' => 'yes',
                 'role' => 'yes',
+                'prize_type' => 'yes',
                 'state' => 1,
             ),
             'type' => 'count',
             'col' => '*',
         ),
+        'getOutAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'id' => 'yes',
+                'role' => 'yes',
+                'prize_type' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
     ),
 );

+ 66 - 7
service/bill/database/shop_stat.php

@@ -73,22 +73,44 @@ $config = array
         'dl_num'        => array
         (
             'type'      => 'int-11',
-            'name'      => '代理商数量-除掉创v的数量',
+            'name'      => '代理商<br/>数量-除掉创v的数量',
             'default'   => '0',
             'desc'      => '代理商数量',
             'match'     => 'is_numeric',
-            'search'    => 'order',
+            // 'search'    => 'order',
             'list'      => true,
         ),
 
         'v_num'        => array
         (
             'type'      => 'int-11',
-            'name'      => '创V数量',
+            'name'      => '创V数量',
             'default'   => '0',
-            'desc'      => '创V数量',
+            'desc'      => '创V数量',
             'match'     => 'is_numeric',
-            'search'    => 'order',
+            // 'search'    => 'order',
+            // 'list'      => true,
+        ),
+
+        'out_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创V名额<br/>外数量',
+            'default'   => '0',
+            'desc'      => '创V名额外数量',
+            'match'     => 'is_numeric',
+            // 'search'    => 'order',
+            'list'      => true,
+        ),
+
+        'nei_num'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创V名额<br/>内数量',
+            'default'   => '0',
+            'desc'      => '创V名额内数量',
+            'match'     => 'is_numeric',
+            // 'search'    => 'order',
             'list'      => true,
         ),
 
@@ -106,7 +128,7 @@ $config = array
         'dl_money'      => array
         (
             'type'      => 'decimal-11,2',
-            'name'      => '代理商业绩',
+            'name'      => '代理商<br/>业绩',
             'default'   => '0',
             'desc'      => '代理商业绩',
             'match'     => 'is_numeric',
@@ -122,6 +144,28 @@ $config = array
             'desc'      => '创V总业绩',
             'match'     => 'is_numeric',
             'update'    => 'text',
+            // 'list'      => true,
+        ),
+
+        'out_money'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '创V名额<br/>外业绩',
+            'default'   => '0',
+            'desc'      => '创V名额外业绩',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'nei_money'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '创V名额<br/>内业绩',
+            'default'   => '0',
+            'desc'      => '创V名额内业绩',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
             'list'      => true,
         ),
 
@@ -154,12 +198,27 @@ $config = array
         'delete' => false,
         'num' => false,
         // 'excel' => $excel,
+        'button' => array
+        (
+            '数据导出' => array('excel','bill/lib/manage.out_shop_stat'),
+        ),
     ),
 
     # request 请求接口定义
     'request' => array
     (
-        
+        'getExcelAll' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-month', '>='),
+                'end' => array('yes-month', '<='),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'col' => '*',
+        ),
     ),
 );
 

+ 29 - 2
service/bill/lib/Cron.php

@@ -470,24 +470,40 @@ class Cron
         foreach($shop as $k => $v){
             #代理商总数量
             $shop[$k]['num'] = Dever::db('agent/member_shop_log')->getAll(array('start'=>$start,'end'=>$end,'new_shop_id'=>$v['id'],'state'=>1));
-            $log = Dever::db('agent/member_shop_log')->getGui(array('start'=>$start,'end'=>$end,'new_shop_id'=>$v['id'],'state'=>1));
-            // print_R($shop);
+            $log = Dever::db('agent/member_shop_log')->getGui(array('start'=>$start,'end'=>$end,'new_shop_id'=>$v['id'],'state'=>1));   
             foreach($log as $k1 => $v1){
                 if($v['id'] == $v1['new_shop_id']){
                     #创V数量
                     $v_num[] = Dever::db('agent/member')->getCount(array('id'=>$v1['mid'],'role'=>8,'state'=>1));
+                    #创V名额外数量
+                    $out_num[] = Dever::db('agent/member')->getCount(array('id'=>$v1['id'],'role'=>8,'prize_type'=>1,'state'=>1));
                     #代理商业绩
                     $shop[$k]['money'][] = Dever::db('agent/order')->getCount(array('start'=>$start,'end'=>$end,'mid'=>$v1['mid'],'state'=>1));
                     #创V业绩
                     $shop[$k]['v_money'][] = Dever::db('agent/order')->getVCount(array('start'=>$start,'end'=>$end,'mid'=>$v1['mid'],'role'=>8,'state'=>1));
+                    #创V名额外业绩
+                    $out[] = Dever::db('agent/member')->find(array('id'=>$v1['mid'],'role'=>8,'prize_type'=>1,'state'=>1));
                 } 
             }
+            foreach($out as $a => $b){
+                if(isset($b['id']) && $b['id']){
+                    $shop[$k]['out_money'][] = Dever::db('agent/order')->getVCount(array('start'=>$start,'end'=>$end,'mid'=>$b['id'],'role'=>8,'state'=>1));
+                }
+            }
             #创V总数量
             if(isset($v_num) && $v_num){
                 $shop[$k]['v_num'] = array_sum($v_num);
             }else{
                 $shop[$k]['v_num'] = 0;
             }
+            #创V名额内外的数量
+            if(isset($out_num) && $out_num){
+                $shop[$k]['out_num'] = array_sum($out_num);
+                $shop[$k]['nei_num'] = $shop[$k]['v_num'] - $shop[$k]['out_num'];
+            }else{
+                $shop[$k]['out_num'] = 0;
+                $shop[$k]['nei_num'] = 0;
+            }
             #除去创V的代理商总数量
             $shop[$k]['dl_num'] = $shop[$k]['num'] - $shop[$k]['v_num'];
             
@@ -506,6 +522,13 @@ class Cron
             }else{
                 $shop[$key]['v_money'] = 0;
             }
+            if(isset($val['out_money']) && $val['out_money']){
+                $shop[$key]['out_money'] = array_sum(array_map(function($val){return $val['total'];}, $val['out_money']));
+                $shop[$key]['nei_money'] = $shop[$key]['v_money'] - $shop[$key]['out_money'];
+            }else{
+                $shop[$key]['out_money'] = 0;
+                $shop[$key]['nei_money'] = 0;
+            }
             
             $shop[$key]['dl_money'] = $shop[$key]['money']-$shop[$key]['v_money'];
             $insert['shop_id'] = $val['id'];
@@ -516,6 +539,10 @@ class Cron
             $insert['dl_money'] = $shop[$key]['dl_money'];
             $insert['v_money'] = $shop[$key]['v_money'];
             $insert['month'] = $start;
+            $insert['out_num'] = $val['out_num'];
+            $insert['nei_num'] = $val['nei_num'];
+            $insert['out_money'] = $shop[$key]['out_money'];
+            $insert['nei_money'] = $shop[$key]['nei_money'];
 
             $res = Dever::db('bill/shop_stat')->find(array('month'=>$start));
             if($res){

+ 42 - 11
service/bill/lib/Manage.php

@@ -198,22 +198,18 @@ class Manage
         $status = Dever::input('search_option_status');
         $start = Dever::input('search_option_start_cdate');
         $end = Dever::input('search_option_end_cdate');
+        $where = array();
+        $where['state'] = 1;
         if($start){
-            $starts=strtotime($start);
+            $where['start']=strtotime($start);
         }
         if($end){
-            $ends=strtotime($end);
+            $where['end']=strtotime($end);
         }
+        $where['status'] = $status;
         $header = array('提现单号', '姓名', '手机号', '身份证号', '会员角色', '提现金额', '到账金额', '手续费金额', '申请时间', '审核时间', '审核状态','发放状态','审核人', '来源');
-        if($status && isset($starts) &&  $starts && isset($ends) && $ends){
-            $data = Dever::db('bill/tixian')->getExcelAll(array('start'=>$starts,'end'=>$ends,'status'=>$status,'state'=>1));
-        }elseif($status){
-            $data = Dever::db('bill/tixian')->getExcelAll(array('status'=>$status,'state'=>1));
-        }elseif(isset($starts) && $starts && isset($ends) && $ends){
-            $data = Dever::db('bill/tixian')->getExcelAll(array('start'=>$starts,'end'=>$ends,'state'=>1));
-        }else{
-            $data = Dever::db('bill/tixian')->getExcelAll(array('state'=>1));
-        }
+
+        $data = Dever::db('bill/tixian')->getExcelAll($where);
         
         $body = array();
         foreach($data as $k => $v){
@@ -274,4 +270,39 @@ class Manage
         $file = '每日提现';
         Dever::excelExport($body, $header, $file);
     }
+
+    #归店统计导出
+    public function out_shop_stat_api(){
+        $start = Dever::input('search_option_start_month');
+        $end = Dever::input('search_option_end_month');
+        $where = array();
+        $where['state'] = 1;
+        if($start){
+            $where['start'] = strtotime($start);
+        }
+        if($end){
+            $where['end'] = strtotime($end);
+        }
+        $data = Dever::db('bill/shop_stat')->getExcelAll($where);
+        $header = array('月份', '店铺名称', '代理商数量', '创V名额外数量', '创V名额内数量', '代理商业绩', '创V名额外业绩', '创V名额内业绩');
+        $body = array();
+        foreach($data as $k => $v){
+            $month = date('Y-m',$v['month'])."\t";
+            $shop = Dever::db('shop/info')->find(array('id'=>$v['shop_id']));
+            $d = array
+            (
+                $month,
+                $shop['name'],
+                $v['dl_num'],
+                $v['out_num'],
+                $v['nei_num'],
+                $v['dl_money'],
+                $v['out_money'],
+                $v['nei_money'],
+            );
+            $body[] = $d;
+        }
+        $file = '归店统计';
+        Dever::excelExport($body, $header, $file);
+    }
 }