|  | @@ -682,15 +682,20 @@ class Manage
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 体验店毛利:采购价-成本价
 | 
	
		
			
				|  |  | -    public function t_buy($where, $shop_id)
 | 
	
		
			
				|  |  | +    public function t_buy($where, $shop_id, $per)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          $where['type_id'] = $shop_id;
 | 
	
		
			
				|  |  |          $where['status'] = '5,6';
 | 
	
		
			
				|  |  |          $order = Dever::db('shop/buy_order')->getNewAll($where);
 | 
	
		
			
				|  |  |          $total = 0;
 | 
	
		
			
				|  |  | +        $shop = array();
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  |          if ($order) {
 | 
	
		
			
				|  |  |              foreach($order as $k => $v) {
 | 
	
		
			
				|  |  | +                if (!isset($shop[$v['shop_id']])) {
 | 
	
		
			
				|  |  | +                    $shop[$v['shop_id']] = 0;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                
 | 
	
		
			
				|  |  |                  $order_goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $v['id']));
 | 
	
		
			
				|  |  |                  $c_price = 0;
 | 
	
		
			
				|  |  |                  foreach($order_goods as $k1 => $v1){
 | 
	
	
		
			
				|  | @@ -699,21 +704,29 @@ class Manage
 | 
	
		
			
				|  |  |                          $c_price += $goods['c_price'] * $v1['num'];
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                $total += ($v['price'] - $c_price);
 | 
	
		
			
				|  |  | +                $price = ($v['price'] - $c_price);
 | 
	
		
			
				|  |  | +                $total += $price;
 | 
	
		
			
				|  |  | +                $shop[$v['shop_id']] += round($price * $per, 2);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          
 | 
	
		
			
				|  |  | -        return $total;
 | 
	
		
			
				|  |  | +        return array(round($total, 2), round($total*$per, 2), $shop);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      # 零售店毛利
 | 
	
		
			
				|  |  | -    public function l_buy($where, $shop_id)
 | 
	
		
			
				|  |  | +    public function l_buy($where, $shop_id, $per)
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          $where['shop_id'] = $shop_id;
 | 
	
		
			
				|  |  |          $data = Dever::db('mail/area_entry')->getBuy($where);
 | 
	
		
			
				|  |  | -        if ($data && $data['total']) {
 | 
	
		
			
				|  |  | -            return $data['total'];
 | 
	
		
			
				|  |  | +        $total = 0;
 | 
	
		
			
				|  |  | +        $shop = array();
 | 
	
		
			
				|  |  | +        if ($data) {
 | 
	
		
			
				|  |  | +            foreach ($data as $k => $v) {
 | 
	
		
			
				|  |  | +                $price = $v['buy'];
 | 
	
		
			
				|  |  | +                $total += $price;
 | 
	
		
			
				|  |  | +                $shop[$v['shop_id']] += round($price * $per, 2);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        return 0;
 | 
	
		
			
				|  |  | +        return array(round($total, 2), round($total*$per, 2), $shop);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 区域分润
 | 
	
	
		
			
				|  | @@ -764,6 +777,7 @@ class Manage
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              $area_id = array();
 | 
	
		
			
				|  |  | +            $shop_data = array();
 | 
	
		
			
				|  |  |              foreach ($area as $k => $v) {
 | 
	
		
			
				|  |  |                  $update = array();
 | 
	
		
			
				|  |  |                  $update['month'] = $month;
 | 
	
	
		
			
				|  | @@ -776,16 +790,16 @@ class Manage
 | 
	
		
			
				|  |  |                      if ($k1 == 1) {
 | 
	
		
			
				|  |  |                          # 体验店
 | 
	
		
			
				|  |  |                          $update['t_num'] = count($v1);
 | 
	
		
			
				|  |  | -                        $update['t_buy'] = $this->t_buy($where, $v1);
 | 
	
		
			
				|  |  | -                        if ($update['t_buy'] > 0) {
 | 
	
		
			
				|  |  | -                            $update['t_cash'] = $update['t_buy'] * $config[$v['type']];
 | 
	
		
			
				|  |  | +                        list($update['t_buy'], $update['t_cash'], $shop_data) = $this->t_buy($where, $v1, $config[$v['type']]);
 | 
	
		
			
				|  |  | +                        if ($shop_data) {
 | 
	
		
			
				|  |  | +                            $update['data'] += $shop_data;
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      } elseif ($k1 == 2) {
 | 
	
		
			
				|  |  |                          # 零售店
 | 
	
		
			
				|  |  |                          $update['l_num'] = count($v1);
 | 
	
		
			
				|  |  | -                        $update['l_buy'] = $this->l_buy($where, $v1);
 | 
	
		
			
				|  |  | -                        if ($update['l_buy'] > 0) {
 | 
	
		
			
				|  |  | -                            $update['l_cash'] = $update['l_buy'] * $config[$v['type']];
 | 
	
		
			
				|  |  | +                        list($update['l_buy'], $update['l_cash'], $shop_data) = $this->l_buy($where, $v1, $config[$v['type']]);
 | 
	
		
			
				|  |  | +                        if ($shop_data) {
 | 
	
		
			
				|  |  | +                            $update['data'] += $shop_data;
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
	
		
			
				|  | @@ -813,6 +827,7 @@ class Manage
 | 
	
		
			
				|  |  |                      $update['mid'] = $member['id'];
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +                $update['data'] = Dever::json_encode($update['data']);
 | 
	
		
			
				|  |  |                  if (!$info) {
 | 
	
		
			
				|  |  |                      $stat_id = Dever::db('mail/area_stat')->insert($update);
 | 
	
		
			
				|  |  |                  } else {
 |