<?php
namespace App\Controller;
use Common\Controller\HanchaoController;
class StatisticsController extends BaseController {
    public function _initialize(){
        parent::_initialize ();
    }
    public function index(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        $auth_code='statistics';
        $ret=D("Pad/ShopsRoleAuth")->check_auth_code($auth_code,$paramdata);
		if($ret['status']!=1) $this->ajaxReturn($ret);
        if(!$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $result=D('Common/Statistics')->index($paramdata);
        if($result){
            $return['status']=1;
            $return['data']=$result;
        }
        $this->ajaxReturn($return);
    }
    // 会员趋势分析
    public function member_trend(){
    	$return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $rows=D('Common/Statistics')->member_trend($paramdata);
        $member_biao=D('Common/Statistics')->member_biao($paramdata);
        if($rows){
        	$return['status']=1;
        	$return['chartData']=array('columns'=>array('日期','粉丝','顾客','会员'),'rows'=>$rows);
            $return['list']=$member_biao;
        }else{
        	$return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
    // 会员复购率
    public function member_buy_rate(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $rows=D('Common/Statistics')->buy_rate($paramdata);
        $buy_rate_biao=D('Common/Statistics')->buy_rate_biao($paramdata);
        if($rows){
            $return['status']=1;
            $return['chartData']=array('columns'=>array('次数','人数'),'rows'=>$rows);
            $return['list']=$buy_rate_biao;
        }else{
            $return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
    // 消费金额/利润
    public function consume(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $rows=D('Common/Statistics')->consume($paramdata);
        $consume_biao=D('Common/Statistics')->consume_biao($paramdata);
        if($rows){
            $return['status']=1;
            $return['chartData']=array('columns'=>array('日期','订单金额','利润'),'rows'=>$rows);
            $return['list']=$consume_biao;
        }else{
            $return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
    // 订单量
    public function order(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $rows=D('Common/Statistics')->order($paramdata);
        $order_biao=D('Common/Statistics')->order_biao($paramdata);
        if($rows){
            $return['status']=1;
            $return['chartData']=array('columns'=>array('日期','订单量'),'rows'=>$rows);
            $return['list']=$order_biao;
        }else{
            $return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
    public function goods_sales(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $goods_sales=D('Common/Statistics')->goods_sales($paramdata);
        if($goods_sales){
            $return['status']=1;
            $return['list']=$goods_sales;
        }else{
            $return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
    public function recharge(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        if(!$paramdata['day'] || !$paramdata['shop_id']){
            $return['msg']='参数错误';
            $this->ajaxReturn($return);
        }
        $rows=D('Common/Statistics')->recharge($paramdata);
        $recharge_biao=D('Common/Statistics')->recharge_biao($paramdata);
        if($rows){
            $return['status']=1;
            $return['chartData']=array('columns'=>array('日期','充值金额'),'rows'=>$rows);
            $return['list']=$recharge_biao;
        }else{
            $return=array('status'=>2,'msg'=>'暂无数据');
        }
        $this->ajaxReturn($return);
    }
}
?>