<?php
/**
 * 我的发票
 *
 *
 *
 *

 */

//use Shopnc\Tpl;

defined('InShopNC') or exit('Access Invalid!');

class member_invoiceControl extends mbMemberControl
{

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 发票信息列表
     */
    public function invoice_listOp()
    {
        $model_invoice = Model('invoice');
        $condition = array();
        $condition['member_id'] = $_SESSION['member_id'];
        $invoice_list = $model_invoice->getInvList($condition, 10, 'inv_id,inv_title,inv_content');
        
        return self::outsuccess(array('invoice_list' => $invoice_list));
    }

    /**
     * 发票信息删除
     */
    public function invoice_delOp()
    {
        $inv_id = intval($_POST['inv_id']);
        if ($inv_id <= 0) {
            return self::outerr(errcode::ErrInvoice, '参数错误');
        }

        $model_invoice = Model('invoice');
        $result = $model_invoice->delInv(array('inv_id' => $inv_id, 'member_id' => $_SESSION['member_id']));
        if ($result) {
            return self::outsuccess(array('result' => '1'));
        } else {
            return self::outerr(errcode::ErrInvoice, '删除失败');
        }
    }

    /**
     * 发票信息添加
     */
    public function invoice_addOp()
    {
        $model_invoice = Model('invoice');
        $data = array();
        $data['inv_state'] = 1;
        $data['inv_title'] = $_POST['inv_title_select'] == 'person' ? '个人' : urldecode($_POST['inv_title']);
        $data['inv_content'] = urldecode($_POST['inv_content']);
        $data['member_id'] = $_SESSION['member_id'];
        $result = $model_invoice->addInv($data);
        if ($result) {
            return self::outsuccess(array('inv_id' => $result));
        } else {
            return self::outerr(errcode::ErrInvoice, '添加失败');
        }
    }

    /**
     * 发票信息添加
     */
    public function invoice_editOp()
    {
        $model_invoice = Model('invoice');
        $condition = array();
        $condition['inv_id'] = $_POST['inv_id'];
        $data = array();
        $data['inv_title'] = urldecode($_POST['inv_title']);
        $result = $model_invoice->editInv($condition, $data);
        if ($result) {
            return self::outsuccess(array('result' => 1));
        } else {
            return self::outerr(errcode::ErrInvoice, '添加失败');
        }
    }

    /**
     * 发票内容列表
     */
    public function invoice_content_listOp()
    {
        $token = trim($_GET['key']);
        if (false == $this->checkToken($token)) {
            return self::outerr($this->err_code);
        }

        $invoice_content_list = array(
            '明细',
            '酒',
            '食品',
            '饮料',
            '玩具',
            '日用品',
            '装修材料',
            '化妆品',
            '办公用品',
            '学生用品',
            '家居用品',
            '饰品',
            '服装',
            '箱包',
            '精品',
            '家电',
            '劳防用品',
            '耗材',
            '电脑配件'
        );
        return self::outsuccess(array('invoice_content_list' => $invoice_content_list));
    }
}
