|  | @@ -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('      ', $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, '|—')) {
 | 
	
	
		
			
				|  | @@ -759,7 +828,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) {
 | 
	
	
		
			
				|  | @@ -826,11 +896,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']);
 | 
	
	
		
			
				|  | @@ -848,494 +931,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 = '-';
 |