|  | @@ -42,6 +42,7 @@ class Cron
 | 
	
		
			
				|  |  |          return 'ok';
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    # 权益使用情况统计:类型、商品名、总发放数量、总使用数量
 | 
	
		
			
				|  |  |      public function goods_api()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          $num = Dever::input('num', 1);
 | 
	
	
		
			
				|  | @@ -127,11 +128,152 @@ class Cron
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    # 权益使用情况统计:类型、商品名、总发放数量、总使用数量
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |      # 营业额报表:日期,订单数,确认订单数,确认订单额度,新增代理商数量
 | 
	
		
			
				|  |  | +    public function order_api()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $num = Dever::input('num', 1);
 | 
	
		
			
				|  |  | +        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
 | 
	
		
			
				|  |  | +        $end = Dever::input('end', date('Y-m-d'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $start = Dever::maketime($start . ' 00:00:00');
 | 
	
		
			
				|  |  | +        $end = Dever::maketime($end . ' 23:59:59');
 | 
	
		
			
				|  |  | +        $day = intval(($end - $start)/86400);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        for($i=0; $i<=$day; $i++) {
 | 
	
		
			
				|  |  | +            $where = array();
 | 
	
		
			
				|  |  | +            $where['start'] = $start + 86400*$i;
 | 
	
		
			
				|  |  | +            $where['end'] = $start + 86400*$i + 86399;
 | 
	
		
			
				|  |  | +            $data = array();
 | 
	
		
			
				|  |  | +            $data['day'] = $where['start'];
 | 
	
		
			
				|  |  | +            $info = Dever::db('bill/order_stat')->find($data);
 | 
	
		
			
				|  |  | +            $data['num'] = Dever::db('agent/order')->getNum($where);
 | 
	
		
			
				|  |  | +            $where['status'] = 4;
 | 
	
		
			
				|  |  | +            $data['yes_num'] = Dever::db('agent/order')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $cash = Dever::db('agent/order')->getCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $data['cash'] = 0;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $where['status'] = 2;
 | 
	
		
			
				|  |  | +            $data['daili_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +            if (!$info) {
 | 
	
		
			
				|  |  | +                Dever::db('bill/order_stat')->insert($data);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $data['where_id'] = $info['id'];
 | 
	
		
			
				|  |  | +                Dever::db('bill/order_stat')->update($data);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 代理商统计:日期,新增代理商,城市代理商,区县代理商,街道代理商,创客,消客
 | 
	
		
			
				|  |  | +    public function member_api()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $num = Dever::input('num', 1);
 | 
	
		
			
				|  |  | +        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
 | 
	
		
			
				|  |  | +        $end = Dever::input('end', date('Y-m-d'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $start = Dever::maketime($start . ' 00:00:00');
 | 
	
		
			
				|  |  | +        $end = Dever::maketime($end . ' 23:59:59');
 | 
	
		
			
				|  |  | +        $day = intval(($end - $start)/86400);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        for($i=0; $i<=$day; $i++) {
 | 
	
		
			
				|  |  | +            $where = array();
 | 
	
		
			
				|  |  | +            $where['status'] = 2;
 | 
	
		
			
				|  |  | +            $where['start'] = $start + 86400*$i;
 | 
	
		
			
				|  |  | +            $where['end'] = $start + 86400*$i + 86399;
 | 
	
		
			
				|  |  | +            $data = array();
 | 
	
		
			
				|  |  | +            $data['day'] = $where['start'];
 | 
	
		
			
				|  |  | +            $info = Dever::db('bill/member_stat')->find($data);
 | 
	
		
			
				|  |  | +            $data['num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +            $where['role'] = 2;
 | 
	
		
			
				|  |  | +            $data['city_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['role'] = 3;
 | 
	
		
			
				|  |  | +            $data['county_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['role'] = 4;
 | 
	
		
			
				|  |  | +            $data['town_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['role'] = 6;
 | 
	
		
			
				|  |  | +            $data['ck_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['role'] = 7;
 | 
	
		
			
				|  |  | +            $data['xk_num'] = Dever::db('agent/member')->getNum($where);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (!$info) {
 | 
	
		
			
				|  |  | +                Dever::db('bill/member_stat')->insert($data);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $data['where_id'] = $info['id'];
 | 
	
		
			
				|  |  | +                Dever::db('bill/member_stat')->update($data);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      # 资金账户统计:日期,总收入,代理费,软件服务费,赠送商品价值,直推佣金,市场培训费
 | 
	
		
			
				|  |  | +    # 总收入金额 = 代理费金额 + 软件服务费 - 赠送商品价值 - 直推分佣 - 市场培训费。
 | 
	
		
			
				|  |  | +    public function cash_in_api()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        $num = Dever::input('num', 1);
 | 
	
		
			
				|  |  | +        $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
 | 
	
		
			
				|  |  | +        $end = Dever::input('end', date('Y-m-d'));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $start = Dever::maketime($start . ' 00:00:00');
 | 
	
		
			
				|  |  | +        $end = Dever::maketime($end . ' 23:59:59');
 | 
	
		
			
				|  |  | +        $day = intval(($end - $start)/86400);
 | 
	
		
			
				|  |  | +        
 | 
	
		
			
				|  |  | +        for($i=0; $i<=$day; $i++) {
 | 
	
		
			
				|  |  | +            $where = array();
 | 
	
		
			
				|  |  | +            $where['start'] = $start + 86400*$i;
 | 
	
		
			
				|  |  | +            $where['end'] = $start + 86400*$i + 86399;
 | 
	
		
			
				|  |  | +            $data = array();
 | 
	
		
			
				|  |  | +            $data['day'] = $where['start'];
 | 
	
		
			
				|  |  | +            $info = Dever::db('bill/cash_in_stat')->find($data);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['status'] = 4;
 | 
	
		
			
				|  |  | +            $data['daili_cash'] = 0;
 | 
	
		
			
				|  |  | +            $cash = Dever::db('agent/order')->getDailiCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['daili_cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $data['soft_cash'] = 0;
 | 
	
		
			
				|  |  | +            $cash = Dever::db('agent/order')->getSoftCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['soft_cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $data['goods_cash'] = 0;
 | 
	
		
			
				|  |  | +            $cash = Dever::db('agent/order')->getGoodsCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['goods_cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            unset($where['status']);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['type'] = 1;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $data['zt_cash'] = 0;
 | 
	
		
			
				|  |  | +            $cash = Dever::db('bill/cash')->getCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['zt_cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $where['type'] = 2;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $data['sc_cash'] = 0;
 | 
	
		
			
				|  |  | +            $cash = Dever::db('bill/cash')->getCash($where);
 | 
	
		
			
				|  |  | +            if ($cash) {
 | 
	
		
			
				|  |  | +                $data['sc_cash'] = $cash['total'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            $data['cash'] = $data['daili_cash'] + $data['soft_cash'] - $data['goods_cash'] - $data['sc_cash'] - $data['zt_cash'];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (!$info) {
 | 
	
		
			
				|  |  | +                Dever::db('bill/cash_in_stat')->insert($data);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                $data['where_id'] = $info['id'];
 | 
	
		
			
				|  |  | +                Dever::db('bill/cash_in_stat')->update($data);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |