<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: huajie <banhuajie@163.com>
// +----------------------------------------------------------------------

namespace Admin\Model;
use Think\Model;

/**
 * 文档基础模型
 */
class CoinPayOrderModel extends Model{
    /**
     * 构造函数
     * @param string $name 模型名称
     * @param string $tablePrefix 表前缀
     * @param mixed $connection 数据库连接信息
     */
    public function __construct($name = '', $tablePrefix = '', $connection = '') {
        /* 设置默认的表前缀 */
        $this->tablePrefix ='tab_';
        /* 执行构造方法 */
        parent::__construct($name, $tablePrefix, $connection);
    }
    public function lists($p=1, $map=array(), $order, $field=true)
    {

	    $page = intval($p);

	    $page = $page ? $page : 1; //默认显示第一页数据

        if(isset($_REQUEST['row'])) {
            $row = $_REQUEST['row'];
        } else {
            $row = 10;
        }

        $list = $this->field($field?:true)
                ->where($map)
                ->page($page, $row)
                ->order($order?$order:'pay_time desc')
                ->select();

        $count = $this->where($map)->count();

        $data['data'] = $list;

        $page = set_pagination($count,$row);

        if($page) {
            $data['page']=$page;
        }

        return $data;
    }
    //获取单个信息
    public function info($id)
    {
        $info = $this->field($field?:true)
        ->where("id = '".$id."'")
        ->find();
        if(!empty($info['voucher_img'])){
            $info['voucher_img'] =  get_cover($info['voucher_img'])['path'];
        }
        
        return $info;
        # code...
    }
    //更新
    public function updateData($save,$id)
    {
        if(!empty($save['id'])){
           return false;
        }
        return $this->where("id = {$id}")->save($save);
        # code...
    }
}