<?php
namespace App\Controller;
use Common\Controller\HanchaoController;
class ShopLogController extends BaseController {
    public function _initialize(){
            parent::_initialize ();
    }
    public function money_list(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        $list=D('ShopbalanceLog')->money_list($paramdata);
        if($list){$return['status']=1; $return['data'] = $list;}
        else{$return=array('status'=>2,'msg'=>'暂无数据');}
        $this->ajaxReturn($return);
    }
    public function info(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        $id=intval($paramdata['id']);
        if(!$id){
            $return['msg']="无法获取该订单";
            $this->ajaxReturn($return);
        }

        $info=D('ShopbalanceLog')->info($paramdata);
        if($info['status']==1){$return['status']=1; $return['data'] = $info['data'];}
        else{$return=array('status'=>2,'msg'=>$info['msg']);}
        $this->ajaxReturn($return);
    }
    public function bill(){
        $return=array('status'=>3,'msg'=>'');
        $paramdata = I('param.');
        $auth_code='bill_list';
        $return=D("Pad/ShopsRoleAuth")->check_auth_code($auth_code,$paramdata);
        if($return['status']==1) {
            $result=D('ShopbalanceLog')->bill($paramdata);
        }
        if($result['status']){$return=$result;}
        else{$return=array('status'=>2,'msg'=>'暂无数据');}
        $this->ajaxReturn($return);
    }
    public function order_tui(){
        $post = I('post.');
        $map = array();
        if($post['is_root'] == 1){//超级管理员
            $map['id'] = $post['root_id'];
            $shop = M('Shops')->where($map)->field('salt,password')->find();
            // 输入密码
            $msg1 = creatpwd($post['msg'],'HANCHAO'.$shop['salt']);
            if($shop['password'] == $msg1){
                $data = D('ShopLogin')->order_tui();
                if($data['status'] == 1){
                    $return['status'] = 1;
                    $return['msg'] = '退款成功';
                    $return['data'] = $data;
                }else{
                    $return['status'] = 3;
                    $return['msg'] = '退款失败';
                }
            }else{
                $return['status'] = 3;
                $return['msg'] = '密码错误';
            }
        }
        $this->ajaxReturn($return);
    }
    public function explo(){

        $map=array();
        $list = M('shopbalance_log')->where($map)->field(true)->select();
        $title = array('序号', '收银员', '商品名称','收入、支出', '分类', '时间');
        $data = array();
        foreach ($list as $k => $v) {
            $data[$k][] = $v['id'];
            $data[$k][] = idtoname($v['sa_id'],'ShopsAccount','name');
            $data[$k][] = $v['order_id'];
            $data[$k][] = $v['change_type'];
            $data[$k][] = $v['change_num'];
            $data[$k][] = time_format($v['change_time']);
        }
        export_xls($title, $data, 'utf8','excel');
//        unset($title, $data);
        exit;
    }
}
?>