Your Name 2 years ago
parent
commit
efd0d69a95

+ 15 - 0
service/agent/database/member_shop_log.php

@@ -236,5 +236,20 @@ return array
             'order' => array('cdate' => 'asc'),
             'col' => '*',
         ),
+
+        'getLog' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'start' => array('yes-cdate','>='),
+                'end' => array('yes-cdate','<='),
+                'new_shop_id' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('cdate' => 'asc'),
+            'col' => '*',
+        ),
     ),
 );

+ 81 - 3
service/bill/database/shop_stat.php

@@ -14,9 +14,36 @@ $shop = function()
     }
     return $array;
 };
+$cash_status = array
+(
+    1 => '已发放',
+    2 => '未发放',
+);
+$status = array
+(
+    1 => '已确认',
+    2 => '未确认',
+);
 $list_button = array();
 $list_button['list1'] = array('归店明细', 'member_shop_log&project=agent&menu=agent&search_option_state=1&menu_id=306&search_option_new_shop_id={shop_id}&search_option_dever_auth=2');
 $list_button['list2'] = array('直推明细', 'order&project=agent&menu=agent&search_option_state=1&menu_id=306&search_in_parent_mid={mids}');
+$table = Dever::input('table');
+if ($table == 'shop_stat') {
+    $month = Dever::input('search_option_month', date('Y-m'));
+    if ($month) {
+        Dever::setInput('search_option_month', $month);
+    }
+
+    
+    $button['一键生成归店信息'] = array('oper', 'bill/?l=lib/Cron.shop_stat&day=' . $month, '确认生成归店统计信息吗?');
+
+    $button['重新生成归店信息'] = array('oper', 'bill/?l=lib/Cron.shop_stat&day=' . $month, '确认生成归店统计信息吗?');
+// print_R($month);die;
+    $button['对账确认'] = array('oper', 'bill/?l=lib/cron.shopYes_commit&month=' . $month, '确定已完成对账?');
+
+    $button['确认发放'] = array('oper', 'bill/?l=lib/cron.areaCash_commit&month=' . $month, '确认发放资金到代理商账户吗?确认后无法手动恢复');
+
+}
 $config = array
 (
     # 表名
@@ -25,7 +52,10 @@ $config = array
     'lang' => '归店统计',
     'order' => -10,
     'info' => '代理商总数=创V数+代理商数量,创V数包含名额外创V数,创V数减去名额外创V就是名额内创V数,代理商数量包含创客数',
-
+    'end' => array
+    (
+        'list' => 'bill/lib/cron.getShopInfo',
+    ),
     # 数据结构 不同的字段放这里
     'struct' => array
     (
@@ -48,8 +78,9 @@ $config = array
             'desc'      => '',
             'search'    => 'month_eq',
             // 'list_name' => '月份',
-            'list'      => 'date("Y-m", {month})',
-            'list_order' => 1,
+            'search_default' => '',
+            'list_name' => '月份',
+            'list'      => 'is_numeric("{month}") ? date("Y-m", "{month}") : "{month}"',
         ),
 
         'mids'      => array
@@ -95,6 +126,30 @@ $config = array
             'list_order' => 2,
         ),
 
+        'dl_subsidy'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '区域招商补贴',
+            'default'   => '0',
+            'desc'      => '补贴',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+            'list_order' => 3,
+        ),
+
+        'v_subsidy'      => array
+        (
+            'type'      => 'decimal-11,2',
+            'name'      => '名额外创V补贴',
+            'default'   => '0',
+            'desc'      => '补贴',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+            'list_order' => 3,
+        ),
+
         'c_money'      => array
         (
             'type'      => 'decimal-11,2',
@@ -127,6 +182,7 @@ $config = array
             'match'     => 'is_numeric',
             // 'search'    => 'order',
             'list'      => true,
+            'list_order' => 4,
         ),
 
         'ck_num'        => array
@@ -223,6 +279,28 @@ $config = array
             // 'list_order' => 9,
         ),
 
+        'status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '确认状态',
+            'default'   => '2',
+            'desc'      => '确认状态',
+            'match'     => 'is_numeric',
+            'option'    => $status,
+            'list'      => true,
+        ),
+
+        'cash_status'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '发放状态',
+            'default'   => '2',
+            'desc'      => '发放状态',
+            'match'     => 'is_numeric',
+            'option'    => $cash_status,
+            'list'      => true,
+        ),
+
         'state'     => array
         (
             'type'      => 'tinyint-1',

+ 171 - 155
service/bill/lib/Cron.php

@@ -511,26 +511,99 @@ class Cron
             }
         }
     }
+    public function getShopInfo ($data, $name, $param)
+    {
+        $manage = array();
+        $month = Dever::param('month', $param);
+        if ($data) {
+            $delete = array('一键生成归店信息');
+            foreach ($data as $k => $v) {
+                if ($v['cash_status'] == 1) {
+                    # 已发放
+                    $delete[] = '对账确认';
+                    $delete[] = '确认发放';
+                    $delete[] = '重新生成归店信息';
+                    break;
+                } else {
+                    if ($v['status'] == 1) {
+                        # 已确认
+                        $delete[] = '对账确认';
+                        $delete[] = '重新生成归店信息';
+                    } else {
+                        $delete[] = '确认发放';
+                    }
+                }
+            }
+            $log = Dever::db('bill/shop_stat_log')->find(array('month' => $month));
+            if ($log) {
+                $audit = array();
+                if ($log['create_admin']) {
+                    $admin = Dever::db('manage/admin')->find($log['create_admin']);
+                    if ($admin) {
+                        $date = date('Y-m-d H:i', $log['create_date']);
+                        $audit[] = '创建人:' . $admin['username'] . ' 创建时间:' . $date;
+                    }
+                }
+                if ($log['confirm_admin']) {
+                    $admin = Dever::db('manage/admin')->find($log['confirm_admin']);
+                    if ($admin) {
+                        $date = date('Y-m-d H:i', $log['confirm_date']);
+                        $audit[] = '对账人:' . $admin['username'] . ' 对账时间:' . $date;
+                    }
+                }
+                if ($log['send_admin']) {
+                    $admin = Dever::db('manage/admin')->find($log['send_admin']);
+                    if ($admin) {
+                        $date = date('Y-m-d H:i', $log['send_date']);
+                        $audit[] = '发放人:' . $admin['username'] . ' 发放时间:' . $date;
+                    }
+                }
+                if ($audit) {
+                    $audit = '<br />' . implode('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', $audit);
+                } else {
+                    $audit = '';
+                }
+                
+                // $manage['info'] = date('Y年m月', $month) . ' 可分润城市 ' . $log['city_num'] . ' 个 分润区县 ' . $log['county_num'] . ' 个 分润街道 ' . $log['town_num'] . ' 个(不含赠送区域) ' . $audit;
+
+            }
+            
+            $manage['deleteButton'] = $delete;
+        } else {
+            Dever::setInput('day', Dever::input('search_option_month'));
+            list($start, $end) = Dever::month();
+           
+            $manage['deleteButton'] = array('重新生成归店信息', '对账确认', '确认发放');
+        }
+        Dever::config('base')->manage = $manage;
+    }
     #归店统计
     public function shop_stat_api(){
-        $month = Dever::input('month');
-        $y = date('Y');
-        if($month){
-            $month = $month;
-        }else{
-            $m = date('m')-1;
-            if ($m == 0) {
-                $y = $y - 1;
-                $m = 12;
-            }
-            $month = $y.'-'.$m;
-        }
+        // $month = Dever::input('month');
+
+        // $y = date('Y');
+        // if($month){
+        //     $month = $month;
+        // }else{
+        //     $m = date('m')-1;
+        //     if ($m == 0) {
+        //         $y = $y - 1;
+        //         $m = 12;
+        //     }
+        //     $month = $y.'-'.$m;
+        // }
+         # 传入day,获取月开始和月结束日期
+        list($where['start'], $where['end']) = Dever::month();
+        $month = date('Y-m', $where['start']);
+        // print_R($month);die;
         $start_time = $month .'-01 00:00:00';
         $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
         $start = Dever::maketime($start_time);
         $end = Dever::maketime($end_time);
         $shops = Dever::db('shop/info')->getguiAll(array('type'=>2));
         foreach ($shops as $k => $v) {
+            #业绩补贴:除了创V0.02,创V>=10个0.05,创V>=20个0.08
+            // $subsidy = 0;
             $w = array('end' => $end,'new_shop_id'=> $v['id']);
             $member = Dever::db('agent/member_shop_log')->getAllByShop($w);
             if ($member) {
@@ -553,6 +626,10 @@ class Cron
                 $insert['out_money'] = 0;
                 $insert['nei_money'] = 0;
 
+                $insert['subsidy'] = 0;
+                $insert['dl_subsidy'] = 0;
+                $insert['v_subsidy'] = 0;
+
                 $out_member = array();
                 $nei_member = array();
                 if ($cmember) {
@@ -615,7 +692,10 @@ class Cron
                 } else {
                     $insert['dl_money'] = 0;
                 }
-                
+                #除去创V的补贴
+                if ($insert['dl_money']) {
+                    $insert['dl_subsidy'] = $insert['dl_money'] * 0.02;
+                }
                 $where['role'] = 8;
                 unset($where['parent_mid']);
                 if ($out_member) {
@@ -625,7 +705,13 @@ class Cron
                         $insert['out_money'] = $out_money['total'];
                     }
                 }
-
+                if ($insert['out_money']) {
+                    if ($insert['out_money'] >= 100000 && $insert['out_money'] <200000) {
+                        $insert['v_subsidy'] = $insert['out_money'] * 0.05;
+                    } elseif ($insert['out_money'] >=200000) {
+                        $insert['v_subsidy'] = $insert['out_money'] * 0.08;
+                    }
+                }
                 if ($nei_member) {
                     $where['mid'] = $nei_member;
                     $nei_money = Dever::db('agent/order')->getCount($where);
@@ -633,7 +719,7 @@ class Cron
                         $insert['nei_money'] = $nei_money['total'];
                     }
                 }
-                
+                // print_R($insert);die;
 
                 $res = Dever::db('bill/shop_stat')->find(array('month'=>$insert['month'],'shop_id'=>$v['id']));
                 if ($res) {
@@ -656,164 +742,94 @@ class Cron
                 $insert['out_num'] = 0;
                 $insert['out_money'] = 0;
                 $insert['nei_money'] = 0;
+                $insert['subsidy'] = 0;
+                $insert['dl_subsidy'] = 0;
+                $insert['v_subsidy'] = 0;
                 $res = Dever::db('bill/shop_stat')->find(array('month'=>$insert['month'],'shop_id'=>$v['id']));
+                // print_R($res);die;
                 if ($res) {
                     $insert['where_id'] = $res['id'];
                     Dever::db('bill/shop_stat')->update($insert);
                 } else {
                     Dever::db('bill/shop_stat')->insert($insert);
                 }
+                // echo dever::sql();
             }
             
         }
-
-/*
-
-        $logs = Dever::db('agent/member_shop_log')->getGui(array('start'=>$start,'end'=>$end,'state'=>1));
-        foreach($logs as $a => $b){
-            $log[$b['mid']]=$b;
+        $this->addAreaLog('create', $month);
+        return 'reload';
+    }
+    private function addAreaLog($col, $month)
+    {
+        $admin = Dever::load('manage/auth.info');
+        $update['month'] = $month;
+        $log = Dever::db('bill/shop_stat_log')->find(array('month' => $month));
+        $update[$col . '_date'] = time();
+        $update[$col . '_admin'] = $admin['id'];
+        
+        if ($log) {
+            $update['where_id'] = $log['id'];
+            Dever::db('bill/shop_stat_log')->update($update);
+        } else {
+            Dever::db('bill/shop_stat_log')->insert($update);
         }
-        $logs=array_values($log);
-        foreach($shops as $s=>$sv){
-            foreach($logs as $l => $lv){
-                if($lv['new_shop_id'] == $sv['id']){
-                    $sv['mid'][] = $lv['mid'];
-                    $sv['cdate'][] = Dever::maketime(date('Y-m-01', $lv['cdate']) . ' 00:00:00');
-                    // $lv['cdate'];
-                    $shops[] = $sv;
-                }else{
-                    unset($shops[$s]);
-                }
+    }
+    # 确认对账
+    public function shopYes_commit_api()
+    {
+        $month = Dever::input('month');
+        if ($month) {
+            $month = Dever::maketime($month);
+            $state = Dever::db('bill/shop_stat')->updates(array('option_month' => $month, 'option_status' => 2, 'set_status' => 1));
+            if ($state) {
+                $this->addAreaLog('confirm', $month);
             }
         }
-        $data=array_unique($shops, SORT_REGULAR);
-        $rest=array();
-        foreach($data as $a=>$va){
-            $rest[$va['id']]=$va;
-        }
-        $shop=array_values($rest);
-        foreach($shop as $k => $v){
-            // $end = strtotime(date('Y-m-d 23:59:59',strtotime(date('Y-m-01',$v['cdate'][$k1])."+1 month - 1 day")));
-            #采购金额
-            $shop[$k]['c_money'] = Dever::db('shop/buy_order')->getCashNum(array('type'=>1,'type_id'=>$v['id'],'state'=>1));
-            #代理商的总数量
-             $shop[$k]['num'] = Dever::db('agent/member_shop_log')->getAll(array('start'=>$start,'end'=>$end,'new_shop_id'=>$v['id'],'state'=>1));
-             foreach($v['mid'] as $k1 => $v1){
-                $shop[$k]['mids'] = implode(',',$v['mid']);
-                #除去创V的代理数量
-                $shop[$k]['dl_num'][] = Dever::db('agent/member')->getCount(array('id'=>$v1,'role'=>'1,2,3,4,5,6,7','state'=>1));
-                $shop[$k]['ck_num'][] = Dever::db('agent/member')->getCount(array('id'=>$v1,'role'=>'6','state'=>1));
-                #创V数量
-                $shop[$k]['v_num'][] = Dever::db('agent/member')->getCount(array('id'=>$v1,'role'=>8,'state'=>1));
-                #创V名额外数量
-                $shop[$k]['out_num'][] = Dever::db('agent/member')->getCount(array('id'=>$v1,'role'=>8,'prize_type'=>1,'state'=>1));
-                // foreach($v['cdate'][$k1] as $v2){
-                    #代理商业绩
-                    $shop[$k]['money'][] = Dever::db('agent/order')->getCount(array('parent_mid'=>$v1,'start'=>$v['cdate'][$k1],'end'=>$end,'state'=>1));
-                    #除去创V的代理商业绩
-                     $end = strtotime(date('Y-m-d 23:59:59',strtotime(date('Y-m-01',$v['cdate'][$k1])."+1 month - 1 day")));
-                    $shop[$k]['dl_money'][] = Dever::db('agent/order')->getVCount(array('parent_mid'=>$v1,'start'=>$v['cdate'][$k1],'end'=>$end,'role'=>'1,2,3,4,5,6,7'));
-                    
-                    #创V名额外业绩
-                    $out = Dever::db('agent/member')->guidian(array('parent_mid'=>$v1,'role'=>8,'prize_type'=>1));
-                    if(isset($out) && $out){
-                        foreach($out as $v3){
-                            $shop[$k]['out_money'][] = Dever::db('agent/order')->getVCount(array('mid'=>$v3['id'],'start'=>$v['cdate'][$k1],'end'=>$end,'role'=>8,'state'=>1));
-                        }
-                    }
-                    #创V名额内业绩
-                    $nei = Dever::db('agent/member')->guidian(array('parent_mid'=>$v1,'role'=>8,'prize_type'=>2));
-                    if(isset($nei) && $nei){
-                        foreach($nei as $v3){
-                            $shop[$k]['nei_money'][] = Dever::db('agent/order')->getVCount(array('mid'=>$v3['id'],'start'=>$v['cdate'][$k1],'end'=>$end,'role'=>8,'state'=>1));
+        return 'reload';
+    }
+
+    # 确认发放
+    public function areaCash_commit_api()
+    {
+        $month = Dever::input('month');
+        if ($month) {
+            $month = Dever::maketime($month);
+            $data = Dever::db('bill/shop_stat')->select(array('month' => $month, 'cash_status' => 2));
+            if ($data) {
+                $date = date('Y年m月', $month);
+                foreach ($data as $k => $v) {
+                    if ($v['shop_id']) {
+                        $shop = Dever::db('shop/info')->find($v['shop_id']);
+                        if (isset($shop) && $shop && isset($shop['mobile']) && $shop['mobile']) {
+                            $member = Dever::db('agent/member')->find(array('mobile'=>$shop['mobile']));
+                            $cash = $v['dl_subsidy'] + $v['v_subsidy'];
+                            if ($member && $member['status'] == 2) {
+                                if ($v['dl_subsidy'] > 0) {
+                                    $desc = $shop['name'].$date.'区域招商补贴';
+                                    $state = Dever::load('bill/lib/cash')->up($member['id'], 13, $v['dl_subsidy'], $member['role'], $v['id'], $desc, 2, true);
+                                } elseif ($v['v_subsidy'] >0) {
+                                    $desc = $shop['name'].$date.'名额外创V补贴';
+                                    $state = Dever::load('bill/lib/cash')->up($member['id'], 14, $v['v_subsidy'], $member['role'], $v['id'], $desc, 2, true);
+                                }
+                                if (isset($state) && $state) {
+                                    $where = array();
+                                    $where['where_id'] = $shop['id'];
+                                    $where['price'] = $shop['price'] + $cash;
+                                    $where['clear'] = true;
+                                    Dever::db('shop/info')->upCash($where);
+                                    Dever::db('bill/shop_stat')->update(array('where_id' => $v['id'], 'cash_status' => 1));
+                                }
+                            }
                         }
+
                     }
-                // }
-                
-             }
-            #除创V的代理商数量
-            if(isset($shop[$k]['dl_num']) && $shop[$k]['dl_num']){
-                $shop[$k]['dl_num'] = array_sum($shop[$k]['dl_num']);
-            }else{
-                $shop[$k]['dl_num'] = 0;
-            }
-            #创客代理商数量
-            if(isset($shop[$k]['ck_num']) && $shop[$k]['ck_num']){
-                $shop[$k]['ck_num'] = array_sum($shop[$k]['ck_num']);
-            }else{
-                $shop[$k]['ck_num'] = 0;
-            }
-            #创V总数量
-            if(isset($shop[$k]['v_num']) && $shop[$k]['v_num']){
-                $shop[$k]['v_num'] = array_sum($shop[$k]['v_num']);
-            }else{
-                $shop[$k]['v_num'] = 0;
-            }
-            #创V名额外的数量
-            if(isset($shop[$k]['out_num']) && $shop[$k]['out_num']){
-                $shop[$k]['out_num'] = array_sum($shop[$k]['out_num']);
-            }else{
-                $shop[$k]['out_num'] = 0;
+                }
+                $this->addAreaLog('send', $month);
             }
         }
-        // print_R($shop);die;
-        foreach($shop as $key => $val){
-            #代理商的总业绩
-            if(isset($val['money']) && $val['money']){
-                $shop[$key]['money'] = array_sum(array_map(function($val){return $val['total'];}, $val['money']));
-            }else{
-                $shop[$key]['money'] = 0;
-            }
-            #除创V的代理商业绩
-            if(isset($val['dl_money']) && $val['dl_money']){
-                $shop[$key]['dl_money'] = array_sum(array_map(function($val){return $val['total'];}, $val['dl_money']));
-            }else{
-                $shop[$key]['dl_money'] = 0;
-            }
-            #创V名额外业绩
-            if(isset($val['out_money']) && $val['out_money']){
-                $shop[$key]['out_money'] = array_sum(array_map(function($val){return $val['total'];}, $val['out_money']));
-            }else{
-                $shop[$key]['out_money'] = 0;
-            }
-
-            #创V名额内业绩
-            if(isset($val['nei_money']) && $val['nei_money']){
-                $shop[$key]['nei_money'] = array_sum(array_map(function($val){return $val['total'];}, $val['nei_money']));
-            }else{
-                $shop[$key]['nei_money'] = 0;
-            }
-           
-            $insert['shop_id'] = $val['id'];
-            $insert['mids'] = $val['mids'];
-            $insert['num'] = $val['num'];
-            $insert['c_money'] = $val['c_money']['total'];
-            $insert['dl_num'] = $val['dl_num'];
-            $insert['v_num'] = $val['v_num'];
-            $insert['ck_num'] = $val['ck_num'];
-            $insert['money'] = $shop[$key]['money'];
-            $insert['dl_money'] = $shop[$key]['dl_money'];
-            $insert['month'] = $start;
-            $insert['out_num'] = $val['out_num'];
-            $insert['out_money'] = $shop[$key]['out_money'];
-            $insert['nei_money'] = $shop[$key]['nei_money'];
-
-            if($insert){
-                $res = Dever::db('bill/shop_stat')->getState(array('start'=>$start,'end'=>$end,'shop_id'=>$insert['shop_id'],'state'=>1));
-                if($res){
-                    foreach($res as $k2 => $v2){
-                        $insert['where_id'] = $v2['id'];
-                        Dever::db('bill/shop_stat')->update($insert);
-                    } 
-                }else{
-                    Dever::db('bill/shop_stat')->insert($insert);
-                }     
-            }
-        }     
-        */
-        return 'ok';
+        return 'reload';
     }
-
     # 角色统计
     public function role_api()
     {

+ 18 - 1
service/bill/lib/Manage.php

@@ -329,7 +329,7 @@ class Manage
 
     #归店统计导出
     public function out_shop_stat($data){
-        $header = array('月份', '门店名称','门店编号','门店联系人','联系人手机号','联系人身份证','所属代理商', '采购金额','归店业绩(除创V外)','代理商数','创客数','创V数','名额外创V','名额外创V业绩');
+        $header = array('月份', '门店名称','门店编号','门店联系人','联系人手机号','联系人身份证','所属代理商', '区域招商补贴', '名额外创V补贴', '补贴总金额', '采购金额','归店业绩(除创V外)','代理商数','创客数','创V数','名额外创V','名额外创V业绩', '确认状态', '发放状态');
         $body = array();
         foreach($data as $k => $v){
             $month = date('Y-m',$v['month'])."\t";
@@ -359,6 +359,18 @@ class Manage
             if ($shop['idcard']) {
                 $shop_idcard = $shop['idcard'];
             }
+            $status_name = '';
+            if ($v['status'] == 1) {
+                $status_name = '已确认';
+            } elseif ($v['status'] == 2) {
+                $status_name = '未确认';
+            }
+            $cash_status_name = '';
+            if ($v['cash_status'] == 1) {
+                $cash_status_name = '已发放';
+            } elseif ($v['cash_status'] == 2) {
+                $cash_status_name = '未发放';
+            }
             $d = array
             (
                 $month,
@@ -368,6 +380,9 @@ class Manage
                 $shop_mobile,
                 $shop_idcard,
                 $dl_mobile,
+                $v['dl_subsidy'],
+                $v['v_subsidy'],
+                $v['dl_subsidy'] + $v['v_subsidy'],
                 $v['c_money'],
                 $v['dl_money'],
                 $v['dl_num'],
@@ -375,6 +390,8 @@ class Manage
                 $v['v_num'],
                 $v['out_num'],
                 $v['out_money'],
+                $status_name,
+                $cash_status_name,
             );
             $body[] = $d;
         }

+ 40 - 40
tool/stats/lib/Manage.php

@@ -149,11 +149,10 @@ Class Manage
 				if ($v['fdate']) {
 					$fdate = date('Y-m-d H:i',$v['fdate']);
 				}
-				
-				
-				
+				// print_R($v);die;
 				foreach ($goods as $k1 => $v1) {
 					$goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
+					// print_R($goods_info);die;
 					if (isset($goods_info['sku'])) {
 	                    $sku = $goods_info['sku']['string'];
 	                } else {
@@ -161,15 +160,19 @@ Class Manage
 	                }
 	                $goods_price = $v1['price']*$v1['num'];
 	                #代理优惠金额
-	                $discount_cash = round($v['discount_cash'],2);
+	                $dl_discount_cash = round($v1['discount_cash'],2);
+	                // $discount_cash = round($v['discount_cash'],2);
 	                #商品实付金额
-	                $price = round(($goods_price/$v['oprice']*$v['price']),2);
+	                $price = round(($goods_price-$dl_discount_cash),2);
+	                // round(($goods_price/$v['oprice']*$v['price']),2);
 	                //round(($v['price']/$goods_price),2);
 	                #礼品卡金额
 	                $card_code_cash = round($v['card_code_cash'],2);
 	                #钱包金额
 	                $wallet_cash = round($v['wallet_cash'],2);
 	                #商品支付金额
+	                #
+	                
 	                if ($k1 == 0) {
 	                	$total_cash = Dever::load("shop/lib/manage.getTotalCash", $v['id']);
 	                } else {
@@ -211,17 +214,14 @@ Class Manage
 	                    $refund_cash = '0';
 	                    $refund_status = '未退款';
 	                }
-	                if ($v['status'] >=7) {
-	                	$v['price'] = 0;
-	                }
+	                // if ($v['status'] >=7) {
+	                // 	$v['price'] = 0;
+	                // }
 	                
 	                if ($k1 == 0) {
 	                    $v['num'] = $v['num'];
-	                    $v['card_code_cash'] = $v['card_code_cash'];
-	                    $v['price'] = $v['price'];
-	                    $v['wallet_cash'] = $v['wallet_cash'];
-	                    $v['coupon_cash'] = $v['coupon_cash'];
-	                    $v['discount_cash'] = $v['discount_cash'];
+	                    $zhifu = round($v['price'],2);
+	                    $coupon_cash = round($v['coupon_cash'],2);#优惠券金额
 	                    $card_code_cash = round($v['card_code_cash'],2);#礼品卡金额
 						$wallet_cash = round($v['wallet_cash'],2);#钱包金额
 						$discount_cash = round($v['discount_cash'],2);
@@ -229,18 +229,17 @@ Class Manage
 	                    $money = $money;
 	                } else {
 	                    $v['num'] = 0;
-	                    $v['card_code_cash'] = 0;
-	                    $v['price'] = 0;
+	                    
+	                    $zhifu = 0;
 	                    $v['wallet_cash'] = 0;
-	                    $v['coupon_cash'] = 0;
-	                    $v['discount_cash'] = 0;
+	                    $coupon_cash = 0;
 	                    $card_code_cash = 0;
 	                    $wallet_cash = 0;
 	                    $discount_cash = 0;
 	                    $ka = 0;
 	                    $money = 0;
 	                }
-	                // print_R($total_cash);die;
+	                // print_R($v['price']);die;
 	                $d = array
                     (
                         $v['shop_type_name'],
@@ -256,11 +255,11 @@ Class Manage
 						round($v1['price'], 2),//商品单价
 						round($v1['num'],2),//商品数量
 						round($v1['price']*$v1['num'], 2),//商品合计金额
-						$discount_cash,//代理商优惠金额
+						$dl_discount_cash,//代理商优惠金额
 						$price,//商品实付金额
 						$card_code_cash,//礼品卡
 						$wallet_cash, //钱包
-						$price,//商品支付
+						$zhifu,//商品支付
 						$v['card'],
 						$v['card_code']."\t",
 						$zhuce,
@@ -268,13 +267,13 @@ Class Manage
 						$paydate,
 						$operdate,
 						$fdate,
-						$v1['num'],//订单总量
+						$v['num'],//订单总量
 						sprintf('%01.2f',$total_cash),//订单总金额
-	                    round($v['price'], 2),//订单实付
-	                    sprintf('%01.2f',$v['card_code_cash']),//礼品卡
-	                    round($v['wallet_cash'], 2),//钱包
-	                    round($v['coupon_cash'], 2),//优惠券
-	                    round($v['discount_cash'], 2),//代理优惠
+	                    $zhifu,//订单实付
+	                    $card_code_cash,//礼品卡
+	                    $wallet_cash,//钱包
+	                    $coupon_cash,//优惠券
+	                    $discount_cash,//代理优惠
 	                    $status[$v['status']],
 	                    $refund_status,
 	                    $refund_cdate,
@@ -290,6 +289,7 @@ Class Manage
 					if ($goods_info['price_type'] > 2 && isset($goods_info['goods']) && is_array($goods_info['goods'])) {
                     
 	                    foreach ($goods_info['goods'] as $k2 => $v2) {
+
 	                        if ($v2['code']) {
 	                            //$v2['code'] = '-' . $v2['code'];
 	                        }
@@ -311,14 +311,14 @@ Class Manage
 								$sku,
 								$goods_info['tax'],
 
-								round($v2['price'], 2),
-								round($v2['num'],2),
-								$p,
-								$discount_cash,
-								$price,
-								$card_code_cash,
-								$wallet_cash,
-								$price,
+								round($goods_info['price'], 2),#单价
+								round($v['num'],2),#数量
+								round(($goods_info['price']*$v['num']),2),#商品合计金额
+								$dl_discount_cash,//代理商优惠金额
+								$price,#实付金额
+								$card_code_cash,#礼品卡金额
+								$wallet_cash,#钱包金额
+								$zhifu,#商品支付金额
 								$v['card'],
 								$v['card_code']."\t",
 								$zhuce,
@@ -326,13 +326,13 @@ Class Manage
 								$paydate,
 								$operdate,
 								$fdate,
-								$v1['num'],
+								$v['num'],
 								sprintf('%01.2f',$total_cash),
-			                    round($v['price'], 2),
-			                    sprintf('%01.2f',$v['card_code_cash']),
-			                    round($v['wallet_cash'], 2),
-			                    round($v['coupon_cash'], 2),
-			                    round($v['discount_cash'], 2),
+			                    $zhifu,//订单实付
+			                    $card_code_cash,//礼品卡
+			                    $wallet_cash,//钱包
+			                    $coupon_cash,//优惠券
+			                    $discount_cash,//代理优惠
 			                    $status[$v['status']],
 			                    $refund_status,
 			                    $refund_cdate,