rabin 2 years ago
parent
commit
f0b370319f

+ 6 - 1
service/agent/src/My.php

@@ -1145,7 +1145,12 @@ class My extends Core
     #获取体验店和零售店区域分润
     public function getAreaList()
     {
-        $data = Dever::db('mail/area_stat')->getData(array('mid' => $this->uid));
+        $where = array('mid' => $this->uid);
+        $month = Dever::input('month');
+        if ($month) {
+            $where['month'] = Dever::maketime($month);
+        }
+        $data = Dever::db('mail/area_stat')->getData($where);
         if ($data) {
             foreach ($data as $k => $v) {
                 $data[$k] = $this->getAreaOne($v);

+ 1 - 0
service/bill/database/cash.php

@@ -25,6 +25,7 @@ $type = array
     12 => '消费',
     13 => '区域招商补贴',
     14 => '创V归店补贴',
+    15 => '区域收益',
 );
 
 $role = function()

+ 2 - 0
service/bill/lib/Manage.php

@@ -16,8 +16,10 @@ class Manage
         	$member = Dever::db('agent/member')->find($mid);
         	if ($member && $member['status'] == 2) {
         		Dever::load('bill/lib/cash')->up($mid, 10, $cash, $member['role'], $id, $desc, 2);
+                $where = array();
         		$where['where_id'] = $mid;
         		$where['cash'] = $cash;
+                $where['clear'] = true;
         		Dever::db('agent/member')->upCash($where);
         	} else {
         		Dever::db('bill/push_cash')->update(array('where_id' => $id, 'status' => 2));

+ 41 - 6
service/mail/database/area_stat.php

@@ -12,19 +12,41 @@ $cash_status = array
     2 => '未发放',
 );
 
+$type = array
+(
+    1 => '城市',
+    2 => '区县',
+    3 => '街道',
+);
+
+$desc = '';
+$month = Dever::input('search_option_month', date('Y-m'));
+if ($month) {
+    Dever::setInput('search_option_month', $month);
+}
+
+$button = array();
+
+$button['一键生成区域分润'] = array('oper', 'mail/?l=lib/manage.area&day=' . $month, '确认生成区域分润信息吗?');
+
+$button['对账确认'] = array('oper', 'mail/?l=lib/manage.areaYes_commit&month=' . $month, '确定已完成对账?');
+
+$button['确认发放'] = array('oper', 'mail/?l=lib/manage.areaCash_commit&month=' . $month, '确认发放资金到代理商账户吗?确认后无法手动恢复');
 
 return array
 (
     # 表名
     'name' => 'area_stat',
     # 显示给用户看的名称
-    'lang' => '区域分润管理统计',
+    'lang' => '区域分润处理',
     'order' => 79,
     'menu' => 'agent',
-    // 'end' => array
-    // (
-    //     'insert' => 'mail/lib/manage.updateArea_stat', 
-    // ),
+    'info' => '',
+    'desc' => '满足以下条件才可显示:1.区域下必须有门店;2.区域内代理商分润金额不为0;3.零售店、体验店全部处于合作中状态',
+    'end' => array
+    (
+        'list' => 'mail/lib/manage.getAreaInfo',
+    ),
     # 数据结构
     'struct' => array
     (
@@ -43,13 +65,14 @@ return array
         'month'     => array
         (
             'type'      => 'int-11',
-            'name'      => '月份',
+            'name'      => '选择月份',
             'default'   => '',
             'match'     => 'is_numeric',
             'desc'      => '',
             'update'    => 'month',
             'search'    => 'month_eq',
             'search_default' => '',
+            'list_name' => '月份',
             'list'      => 'date("Y-m", {month})',
         ),
 
@@ -66,6 +89,16 @@ return array
             'option'    => Dever::url('api.get?level_total=4', 'area'),
 	    ),
 
+        'type'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => '区域类型',
+            'default'   => '1',
+            'desc'      => '区域类型',
+            'match'     => 'is_numeric',
+            'option'    => $type,
+        ),
+
         'parent_id'       => array
         (
             'type'      => 'int-11',
@@ -216,6 +249,7 @@ return array
         'edit' => false,
         'excel' => true,
         'list_type' => 'tree',
+        'button' => $button,
     ),
 
     'request' => array
@@ -226,6 +260,7 @@ return array
             'option' => array
             (
                 'mid' => 'yes',
+                'month' => 'yes',
                 'state' => 1,
             ),
             'order' => array('id' => 'desc'),

+ 144 - 478
service/mail/lib/Manage.php

@@ -5,6 +5,75 @@ use Dever;
 
 class Manage
 {
+    public function getAreaInfo($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[] = '确认发放';
+                } else {
+                    if ($v['status'] == 1) {
+                        # 已确认
+                        $delete[] = '对账确认';
+                    } else {
+                        $delete[] = '确认发放';
+                    }
+                }
+                break;
+            }
+            $log = Dever::db('mail/area_stat_log')->find(array('month' => $month));
+            if ($log) {
+                $aduit = 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();
+            $tiyan = Dever::db('shop/info')->total(array('status' => 1, 'type' => 1, 'start' => $start, 'end' => $end));
+            $lingshou = Dever::db('shop/info')->total(array('status' => 1, 'type' => 2, 'start' => $start, 'end' => $end));
+            $total = $tiyan + $lingshou;
+            $manage['info'] = date('Y年m月', $month) . ' 共有店铺 ' . $total . ' 家 体验店 ' . $tiyan . ' 家 零售店 ' . $lingshou . ' 家';
+            $manage['desc'] = '';
+            $manage['deleteButton'] = array('对账确认', '确认发放');
+        }
+        Dever::config('base')->manage = $manage;
+    }
+
     public function getArea($name)
     {
         if (strstr($name, '|—')) {
@@ -763,7 +832,8 @@ class Manage
 
         # 获取区域
         $area = array();
-        $shop = Dever::db('shop/info')->select();
+        $shop = Dever::db('shop/info')->select(array('status' => 1));
+        $num = array();
         if ($shop) {
             foreach ($shop as $k => $v) {
                 if ($v['type'] != 10) {
@@ -830,11 +900,24 @@ class Manage
                     $k2 = $area_value[0] . ',' . $area_value[1] . ',' . $area_value[2];
                     $update['parent_id'] = isset($area_id[$k2]) ? $area_id[$k2] : -1;
                 }
+                $update['type'] = $v['type'];
 
                 # 设置收益代理商
+                $update['mid'] = -1;
                 $member = Dever::db('agent/member')->getAreaAll(array('area' => $k));
                 if ($member) {
-                    $update['mid'] = $member['id'];
+                    $order = Dever::db('agent/order')->find(array('mid' => $member['id'], 'order_type' => 1));
+                    if ($order && $order['price'] > 1) {
+                        $update['mid'] = $member['id'];
+                    }
+                }
+
+                if ($update['mid'] > 0) {
+                    # 记录可分润区域
+                    if (!isset($num[$v['type']])) {
+                        $num[$v['type']] = 0;
+                    }
+                    $num[$v['type']]++;
                 }
 
                 $update['data'] = Dever::json_encode($update['data']);
@@ -852,494 +935,77 @@ class Manage
                 }
             }
         }
-        /*
-        $data = array();
-        $data = Dever::db('shop/info')->getAreaAll(array('state'=>1));
-        foreach($data as $k => $v){
-            $w['month'] = $where['start'];
-            #城市
-            if($v['city']>0){
-                $city_area_stat = -1;
-                $where['area'] = $v['city'];
-                $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
-                $where['parent_type'] = '1,3';
-                // print_R($where);die;
-                $jia = $this->caigou($where);
-                // $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
-                $data[$k]['citys']['price']= $jia['money'] * 0.01;
-                // $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
-                $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['citys']['area'],'role'=>2));
-                $w['citys']['area'] = $v['city'];
-               
-                if($mid && $mid['id']){
-                    $data[$k]['citys']['mid'] = $mid['id'];
-                }else{
-                     $data[$k]['citys']['mid'] = '-1';
-                }
-                
-                $where['city'] = $v['city'];
-                $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
-                #体验店
-                $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
-                $data[$k]['citys']['type'] = array_column($t_shop,'id');
-                $where['type_id'] = implode(',',$data[$k]['citys']['type']);
-                $data[$k]['citys']['t_num'] = count($t_shop);
-                if($data[$k]['citys']['t_num']>0){
-                    $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-                    $data[$k]['citys']['t_fprice'] = $data[$k]['citys']['price'];
-                }else{
-                    $data[$k]['citys']['t_price'] = 0;
-                    $data[$k]['citys']['t_fprice'] = 0;
-                }
-                #零售店
-                $shop_area = $this->ls($where,1);
-                $data[$k]['citys']['l_price'] =$shop_area['price'];
-                $data[$k]['citys']['l_fprice'] =$shop_area['price'] * 0.01;
-                $data[$k]['citys']['l_num'] = $shop_area['num'];
-                $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_fprice'];
-                $w['mid'] = $data[$k]['citys']['mid'];
-                $w['name'] = $data[$k]['citys']['area'];
-                $w['price'] = $data[$k]['citys']['price'];
-                $w['c_price'] = $jia['price'];
-                // $data[$k]['citys']['money']['total'];
-                $w['num'] = $data[$k]['citys']['num'];
-                $w['t_num'] = $data[$k]['citys']['t_num'];
-                $w['t_price'] = $data[$k]['citys']['t_price']['total'];
-                $w['t_fprice'] = $data[$k]['citys']['t_fprice'];
-                $w['l_num'] = $data[$k]['citys']['l_num'];
-                $w['l_price'] = $shop_area['price'];
-                $w['l_fprice'] = $data[$k]['citys']['l_fprice'];
-                $w['parent_id'] = -1;
 
-                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['citys']['area']));
-                if(!$shop){
-                    $city_area_stat = Dever::db('mail/area_stat')->insert($w);
-                }else{
-                    $city_area_stat = $w['where_id'] = $shop['id'];
-                    Dever::db('mail/area_stat')->update($w);
-                }
-            }
-            
-            #区县
-            if($v['county']>0){
-                $county_area_stat = -1;
-                $where['area'] = $v['county'];
-                $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
-                // $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
-                $jia = $this->caigou($where);
-                $data[$k]['countys']['price']= $jia['money'] *0.03;
-                // $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
-                $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['countys']['area'],'role'=>3));
-                if($mid && $mid['id']){
-                    $data[$k]['countys']['mid'] = $mid['id'];
-                }else{
-                    $data[$k]['countys']['mid'] = '-1';
-                }
-                $wh['county'] = $v['county'];
-                $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
-                // #体验店
-                $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
-                $data[$k]['countys']['type'] = array_column($t_shop,'id');
-                $where['type_id'] = implode(',',$data[$k]['countys']['type']);
-                $data[$k]['countys']['t_num'] = count($t_shop);
-                if($data[$k]['countys']['t_num']>0){
-                    $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-                    $data[$k]['countys']['t_fprice'] = $data[$k]['countys']['price'];
-                }else{
-                    $data[$k]['countys']['t_price'] = 0;
-                    $data[$k]['countys']['t_fprice'] = 0;
-                }
-
-                #零售店
-                $where['county'] = $v['county'];
-                $shop_area = $this->ls($where,2);
-                $data[$k]['countys']['l_price'] = $shop_area['price'];
-                $data[$k]['countys']['l_fprice'] = $shop_area['price'] * 0.03;
-                $data[$k]['countys']['l_num'] = $shop_area['num'];
-                $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_fprice'];
-
-                $w['mid'] = $data[$k]['countys']['mid'];
-                $w['name'] = $data[$k]['countys']['area'];
-                $w['price'] = $data[$k]['countys']['price'];
-                $w['num'] = $data[$k]['countys']['num'];
-                $w['c_price'] = $jia['price'];
-                // $data[$k]['countys']['money']['total'];
-                $w['t_num'] = $data[$k]['countys']['t_num'];
-                $w['t_price'] = $data[$k]['countys']['t_price']['total'];
-                $w['t_fprice'] = $data[$k]['countys']['t_fprice'];
-                $w['l_num'] = $data[$k]['countys']['l_num'];
-                $w['l_price'] = $shop_area['price'];
-                $w['l_fprice'] = $data[$k]['countys']['l_fprice'];
-                $w['parent_id'] = $city_area_stat;
-                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['countys']['area']));
-                if(!$shop){
-                    $county_area_stat = Dever::db('mail/area_stat')->insert($w);
-                }else{
-                    $county_area_stat = $w['where_id'] = $shop['id'];
-                    Dever::db('mail/area_stat')->update($w);
-                }
-            }
-            #街道
-            if($v['town']>0){
-                $where['area'] = $v['town'];
-                $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
-                // $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
-                $jia = $this->caigou($where);
-                $data[$k]['towns']['price'] = $jia['money'] * 0.05;
-                // $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
-                $mid = Dever::db('agent/member')->getAreaAll(array('area'=>$data[$k]['towns']['area'],'role'=>4));
-                if($mid && $mid['id']){
-                    $data[$k]['towns']['mid'] = $mid['id'];
-                }else{
-                    $data[$k]['towns']['mid'] = '-1';
-                }
-                
-                $whe['town'] = $v['town'];
-                $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
-                #体验店
-                $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
-                $data[$k]['towns']['type'] = array_column($t_shop,'id');
-                $where['type_id'] = implode(',',$data[$k]['towns']['type']);
-                $data[$k]['towns']['t_num'] = count($t_shop);
-                if($data[$k]['towns']['t_num']>0){
-                    $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-                    $data[$k]['towns']['t_fprice'] = $data[$k]['towns']['price'];
-                }else{
-                    $data[$k]['towns']['t_price'] = 0;
-                    $data[$k]['towns']['t_fprice'] = 0;
-                }
-
-                #零售店
-                $where['town'] = $v['town'];
-                $shop_area = $this->ls($where,3);
-                $data[$k]['towns']['l_price'] =$shop_area['price'];
-                $data[$k]['towns']['l_fprice'] =$shop_area['price'] * 0.05;
-                $data[$k]['towns']['l_num'] = $shop_area['num'];
-                $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_fprice'];
-
-                $w['mid'] = $data[$k]['towns']['mid'];
-                $w['name'] = $data[$k]['towns']['area'];
-                $w['price'] = $data[$k]['towns']['price'];
-                $w['num'] = $data[$k]['towns']['num'];
-                $w['c_price'] = $jia['price'];
-                // $data[$k]['towns']['money']['total'];
-                $w['t_num'] = $data[$k]['towns']['t_num'];
-                $w['t_price'] = $data[$k]['towns']['t_price']['total'];
-                $w['t_fprice'] = $data[$k]['towns']['t_fprice'];
-                $w['l_num'] = $data[$k]['towns']['l_num'];
-                $w['l_price'] = $shop_area['price'];
-                $w['l_fprice'] = $data[$k]['towns']['l_fprice'];
-                $w['parent_id'] = $county_area_stat;
-                $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'name'=>$data[$k]['towns']['area']));
-                if(!$shop){
-                    Dever::db('mail/area_stat')->insert($w);
-                }else{
-                    $w['where_id'] = $shop['id'];
-                    Dever::db('mail/area_stat')->update($w);
-                }
-            }
-        }
-        */
-        return 'ok';
+        $this->addAreaLog('create', $month, $num);
+        return 'reload';
     }
 
-    /*
-    #采购价-成本价
-    public function caigou($where){
-        $data = Dever::db('shop/buy_order')->getNewAll($where);
-        $res = array();
-        $money = 0;
-        $res['money'] = 0;
-        if($data && isset($data['price']) && $data['price']){
-            $res['price'] = $data['price'];
-        }else{
-            $res['price'] = 0;
+    private function addAreaLog($col, $month, $num = array())
+    {
+        $admin = Dever::load('manage/auth.info');
+        $update['month'] = $month;
+        $log = Dever::db('mail/area_stat_log')->find(array('month' => $month));
+        $update[$col . '_date'] = time();
+        $update[$col . '_admin'] = $admin['id'];
+        if ($num) {
+            $update['city_num'] = isset($num[1]) ? $num[1] : 0;
+            $update['county_num'] = isset($num[2]) ? $num[2] : 0;
+            $update['town_num'] = isset($num[3]) ? $num[3] : 0;
         }
-        
-        foreach($data as $k => $v){
-            // $goods_id,$skuid
-            $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
-            $c_price = 0;
-            foreach($order_goods as $k1 => $v1){
-                $goods = Dever::load('goods/lib/info')->getPayInfo($v1['goods_id'], $v1['sku_id']);
-                if($goods['c_price'] && $goods['c_price'] >= 0){
-                    $c_price += $goods['c_price'] * $v1['num'];
-                }
-            }
-            $res['money'] += ($v['price'] - $c_price);
+        if ($log) {
+            $update['where_id'] = $log['id'];
+            Dever::db('mail/area_stat_log')->update($update);
+        } else {
+            Dever::db('mail/area_stat_log')->insert($update);
         }
-        return $res;
     }
-    #零售
-    public function ls($where,$type=false){
-        $shop = Dever::db('mail/area_entry')->getNewAll($where);
-        $data = array();
-        $data['price'] = 0;
-        foreach($shop as $k => $v){
-            if ($type == 1) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('city'=>$where['city'],'id'=>$v['shop_id']));
-            } elseif ($type == 2) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('county'=>$where['county'],'id'=>$v['shop_id']));
-            } elseif ($type == 3) {
-                $shop[$k]['shop'] = Dever::db('shop/info')->find(array('town'=>$where['town'],'id'=>$v['shop_id']));
-            }
-            
-        }
-        foreach($shop as $k => $v){
-            if(!$v['shop']){
-                unset($shop[$k]);
+
+    # 确认对账
+    public function areaYes_commit_api()
+    {
+        $month = Dever::input('month');
+        if ($month) {
+            $month = Dever::maketime($month);
+            $state = Dever::db('mail/area_stat')->updates(array('option_month' => $month, 'option_status' => 2, 'set_status' => 1));
+            if ($state) {
+                $this->addAreaLog('confirm', $month);
             }
         }
-        foreach($shop as $k=>$v){
-            $data['price'] +=$v['cprice'];
-        }
-        $data['num'] = count($shop);
-        return $data;
+        return 'reload';
     }
-    */
-    // public function area_api(){
-    //     #零售店的采购金额*0.4
-    //     $month = Dever::input('month', date('Y-m'));
-    //     $start_time = $month .'-01 00:00:00';
-    //     $where = array();
-    //     $end_time = date('Y-m-d', strtotime($start_time. ' +1 month -1 day')).' 23:59:59';
-    //     $where['start'] = Dever::maketime($start_time);
-    //     $where['end'] = Dever::maketime($end_time);
-    //     $where['state'] = 1;
-        
-    //     $data = array();
-    //     $shop = Dever::db('shop/info')->getAreaAll(array('state'=>1));
-    //     foreach($shop as $k=>$v){
-    //         $data[$v['city']]=$v;
-    //     }
-    //     $shop_area = Dever::db('mail/area_entry')->getAll($where);
-    //     $res = array();
-    //     if($shop_area){
-    //         foreach($shop_area as $k => $v){
-    //             if($v['area']){
-    //                $area = explode(',',$v['area']);
-    //                if($area && isset($area[0])){
-    //                     $res[$k]['province'] = $area[0];
-    //                }
-    //                if ($area && isset($area[1])){
-    //                     $res[$k]['city'] = $area[1];
-    //                }else{
-    //                     $res[$k]['city'] = 0;
-    //                }
-    //                if($area && isset($area[2])){
-    //                     $res[$k]['county'] = $area[2];
-    //                }else{
-    //                     $res[$k]['county'] = 0;
-    //                }
-    //                if($area && isset($area[3])){
-    //                      $res[$k]['town'] = $area[3];
-    //                }else{
-    //                     $res[$k]['town'] = 0;
-    //                }
-    //             }
-    //         }
-    //     }
-        
-    //     $data = array_values($data);
-    //     $data = array_merge($data,$res);
-    //     // print_R($data);die;
-    //     $result=array_unique($data, SORT_REGULAR);
-    //     $rest=array();
-    //     foreach($data as $k=>$v){
-    //         $rest[$v['county']]=$v;
-    //     }
-    //     $data=array_values($rest);
-    //     foreach ($data as $k => $v) {
-    //       $edition[] = $v['province'];
-    //     }
-    //     array_multisort($edition, SORT_ASC, $data);
-    //     foreach($data as $k => $v){
-    //         $w['month'] = $where['start'];
-    //         #城市
-    //         if($v['city']>0){
-    //             $where['area'] = $v['city'];
-    //             $data[$k]['citys']['area'] = $v['province'].','.$v['city'];
-    //             $data[$k]['citys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
-
-    //             $data[$k]['citys']['price']= round($data[$k]['citys']['money']['total']) * 0.3*0.01;
-    //             $mid = Dever::db('agent/member')->getAreaAll($where);
-    //             $w['citys']['area'] = $v['city'];
-               
-    //             if($mid && $mid['id']){
-    //                 $data[$k]['citys']['mid'] = $mid['id'];
-    //             }else{
-    //                  $data[$k]['citys']['mid'] = '';
-    //             }
-                
-    //             $where['city'] = $v['city'];
-    //             $data[$k]['citys']['num'] = Dever::db('shop/info')->getSerachNum($where);
-    //             #体验店
-    //             $t_shop = Dever::db('shop/info')->getAreaAll(array('city'=>$v['city'],'type'=>1,'state'=>1));
-    //             $data[$k]['citys']['type'] = array_column($t_shop,'id');
-    //             $where['type_id'] = implode(',',$data[$k]['citys']['type']);
-    //             $data[$k]['citys']['t_num'] = count($t_shop);
-    //             if($data[$k]['citys']['t_num']>0){
-    //                 $data[$k]['citys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-                    
-    //             }else{
-    //                 $data[$k]['citys']['t_price'] = 0;
-    //             }
-    //             #零售店
-    //             $entry = Dever::db('mail/area_entry')->getNum($where);
-    //             if ($entry && $entry['num']){
-    //                 $data[$k]['citys']['l_num'] = $entry['num'];
-    //                 $data[$k]['citys']['num'] = $data[$k]['citys']['num'] + $data[$k]['citys']['l_num'];
-    //             }else{
-    //                 $data[$k]['citys']['l_num'] = 0;
-    //             }
-    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
-    //             if ($entry_price && $entry_price['cprice'] ){
-    //                 $data[$k]['citys']['l_price'] =  $entry_price['cprice'] * 0.4;
-    //                 $data[$k]['citys']['price'] = $data[$k]['citys']['price'] + $data[$k]['citys']['l_price'];
-    //             }else{
-    //                 $data[$k]['citys']['l_price'] = 0;
-    //             }
-
-    //             $w['mid'] = $data[$k]['citys']['mid'];
-    //             $w['area'] = $data[$k]['citys']['area'];
-    //             $w['price'] = $data[$k]['citys']['price'];
-    //             $w['c_price'] = $data[$k]['citys']['money']['total'];
-    //             $w['num'] = $data[$k]['citys']['num'];
-    //             $w['t_num'] = $data[$k]['citys']['t_num'];
-    //             $w['t_price'] = $data[$k]['citys']['t_price']['total'];
-    //             $w['l_num'] = $data[$k]['citys']['l_num'];
-    //             $w['l_price'] = $data[$k]['citys']['l_price'];
-
-    //             $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['citys']['area']));
-    //             if(!$shop){
-    //                 Dever::db('mail/area_stat')->insert($w);
-    //             }else{
-    //                 $w['where_id'] = $shop['id'];
-    //                 Dever::db('mail/area_stat')->update($w);
-    //             }
-    //         }
-            
-    //         #区县
-    //         if($v['county']>0){
-    //             $where['area'] = $v['county'];
-    //             $data[$k]['countys']['area'] = $v['province'].','.$v['city'].','.$v['county'];
-    //             $data[$k]['countys']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
 
-    //             $data[$k]['countys']['price']= round($data[$k]['countys']['money']['total']) * 0.3*0.03;
-    //             $mid = Dever::db('agent/member')->getAreaAll($where);
-    //             if($mid && $mid['id']){
-    //                 $data[$k]['countys']['mid'] = $mid['id'];
-    //             }else{
-    //                 $data[$k]['countys']['mid'] = '';
-    //             }
-    //             $wh['county'] = $v['county'];
-    //             $data[$k]['countys']['num'] = Dever::db('shop/info')->getSerachNum($wh);
-    //             // #体验店
-    //             $t_shop = Dever::db('shop/info')->getAreaAll(array('county'=>$v['county'],'type'=>1,'state'=>1));
-    //             $data[$k]['countys']['type'] = array_column($t_shop,'id');
-    //             $where['type_id'] = implode(',',$data[$k]['countys']['type']);
-    //             $data[$k]['countys']['t_num'] = count($t_shop);
-    //             if($data[$k]['countys']['t_num']>0){
-    //                 $data[$k]['countys']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-    //             }else{
-    //                 $data[$k]['countys']['t_price'] = 0;
-    //             }
-
-    //             #零售店
-    //             $entry = Dever::db('mail/area_entry')->getNum($where);
-    //             if ($entry && $entry['num']){
-    //                 $data[$k]['countys']['l_num'] = $entry['num'];
-    //                 $data[$k]['countys']['num'] = $data[$k]['countys']['num'] + $data[$k]['countys']['l_num'];
-    //             }else{
-    //                 $data[$k]['countys']['l_num'] = 0;
-    //             }
-    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
-    //             if ($entry_price && $entry_price['cprice'] ){
-    //                 $data[$k]['countys']['l_price'] =  $entry_price['cprice'] * 0.4;
-    //                 $data[$k]['countys']['price'] = $data[$k]['countys']['price'] + $data[$k]['countys']['l_price'];
-    //             }else{
-    //                 $data[$k]['countys']['l_price'] = 0;
-    //             }
-
-    //             $w['mid'] = $data[$k]['countys']['mid'];
-    //             $w['area'] = $data[$k]['countys']['area'];
-    //             $w['price'] = $data[$k]['countys']['price'];
-    //             $w['num'] = $data[$k]['countys']['num'];
-    //             $w['c_price'] = $data[$k]['countys']['money']['total'];
-    //             $w['t_num'] = $data[$k]['countys']['t_num'];
-    //             $w['t_price'] = $data[$k]['countys']['t_price']['total'];
-    //             $w['l_num'] = $data[$k]['countys']['l_num'];
-    //             $w['l_price'] = $data[$k]['countys']['l_price'];
-    //             $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['countys']['area']));
-    //             if(!$shop){
-    //                 Dever::db('mail/area_stat')->insert($w);
-    //             }else{
-    //                 $w['where_id'] = $shop['id'];
-    //                 Dever::db('mail/area_stat')->update($w);
-    //             }
-    //         }
-    //         #街道
-    //         if($v['town']>0){
-    //             $where['area'] = $v['town'];
-    //             $data[$k]['towns']['area'] = $v['province'].','.$v['city'].','.$v['county'].','.$v['town'];
-    //             $data[$k]['towns']['money'] = Dever::db('shop/buy_order')->getSerachMoney($where);
-    //             $data[$k]['towns']['price']= round($data[$k]['towns']['money']['total']) * 0.3*0.05;
-    //             $mid = Dever::db('agent/member')->getAreaAll($where);
-    //             if($mid && $mid['id']){
-    //                 $data[$k]['towns']['mid'] = $mid['id'];
-    //             }else{
-    //                 $data[$k]['towns']['mid'] = '';
-    //             }
-                
-    //             $whe['town'] = $v['town'];
-    //             $data[$k]['towns']['num'] = Dever::db('shop/info')->getSerachNum($whe);
-    //             #体验店
-    //             $t_shop = Dever::db('shop/info')->getAreaAll(array('town'=>$v['town'],'type'=>1,'state'=>1));
-    //             $data[$k]['towns']['type'] = array_column($t_shop,'id');
-    //             $where['type_id'] = implode(',',$data[$k]['towns']['type']);
-    //             $data[$k]['towns']['t_num'] = count($t_shop);
-    //             if($data[$k]['towns']['t_num']>0){
-    //                 $data[$k]['towns']['t_price'] = Dever::db('shop/buy_order')->getSerachTMoney($where);
-    //             }else{
-    //                 $data[$k]['towns']['t_price'] = 0;
-    //             }
+    # 确认发放
+    public function areaCash_commit_api()
+    {
+        $month = Dever::input('month');
+        if ($month) {
+            $month = Dever::maketime($month);
+            $data = Dever::db('mail/area_stat')->select(array('month' => $month, 'cash_status' => 2));
+            if ($data) {
+                $date = date('Y年m月', $month);
+                foreach ($data as $k => $v) {
+                    if ($v['mid']) {
+                        $cash = $v['t_cash'] + $v['l_cash'];
+                        $member = Dever::db('agent/member')->find($v['mid']);
+                        if ($cash > 0 && $member && $member['status'] == 2) {
 
-    //             #零售店
-    //             $entry = Dever::db('mail/area_entry')->getNum($where);
-    //             if ($entry && $entry['num']){
-    //                 $data[$k]['towns']['l_num'] = $entry['num'];
-    //                 $data[$k]['towns']['num'] = $data[$k]['towns']['num'] + $data[$k]['towns']['l_num'];
-    //             }else{
-    //                 $data[$k]['towns']['l_num'] = 0;
-    //             }
-    //             $entry_price = Dever::db('mail/area_entry')->getPrice($where);
-    //             if ($entry_price && $entry_price['cprice'] ){
-    //                 $data[$k]['towns']['l_price'] =  $entry_price['cprice'] * 0.4;
-    //                 $data[$k]['towns']['price'] = $data[$k]['towns']['price'] + $data[$k]['towns']['l_price'];
-    //             }else{
-    //                 $data[$k]['towns']['l_price'] = 0;
-    //             }
+                            $desc = Dever::load("area/api.string", $v['name'], '') . $date . '区域分润';
+                            Dever::load('bill/lib/cash')->up($v['mid'], 15, $cash, $member['role'], $v['id'], $desc, 2);
+                            $where = array();
+                            $where['where_id'] = $v['mid'];
+                            $where['cash'] = $cash;
+                            $where['clear'] = true;
+                            Dever::db('agent/member')->upCash($where);
+                            Dever::db('mail/area_stat')->update(array('where_id' => $v['id'], 'cash_status' => 1));
+                        }
+                    }
+                }
+                $this->addAreaLog('send', $month);
+            }
+        }
+        return 'reload';
+    }
 
-    //             $w['mid'] = $data[$k]['towns']['mid'];
-    //             $w['area'] = $data[$k]['towns']['area'];
-    //             $w['price'] = $data[$k]['towns']['price'];
-    //             $w['num'] = $data[$k]['towns']['num'];
-    //             $w['c_price'] = $data[$k]['towns']['money']['total'];
-    //             $w['t_num'] = $data[$k]['towns']['t_num'];
-    //             $w['t_price'] = $data[$k]['towns']['t_price']['total'];
-    //             $w['l_num'] = $data[$k]['towns']['l_num'];
-    //             $w['l_price'] = $data[$k]['towns']['l_price'];
-    //             $shop = Dever::db('mail/area_stat')->find(array('month'=>$w['month'],'area'=>$data[$k]['towns']['area']));
-    //             if(!$shop){
-    //                 Dever::db('mail/area_stat')->insert($w);
-    //             }else{
-    //                 $w['where_id'] = $shop['id'];
-    //                 Dever::db('mail/area_stat')->update($w);
-    //             }
-    //         }
-    //     }
-    //     return 'ok';
-    // }
     public function area_member($id){
         $info = Dever::db('mail/area_stat')->find($id);
         $res = '-';